public function testAddFieldToFilter()
 {
     $field = 'title';
     $value = 'test_filter';
     $searchSql = 'sql query';
     $this->collection->expects($this->once())->method('_translateCondition')->with($field, $value)->will($this->returnValue($searchSql));
     $this->select->expects($this->once())->method('where')->with($this->equalTo($searchSql), $this->equalTo(null), $this->equalTo(\Magento\Framework\DB\Select::TYPE_CONDITION));
     $this->collection->addFieldToFilter($field, $value);
 }
Example #2
0
 /**
  * @param string|array $field
  * @param string|int|array|null $condition
  * @return \Magento\Cms\Model\Resource\Block\Grid\Collection
  */
 public function addFieldToFilter($field, $condition = null)
 {
     if ($field == 'store_id') {
         return $this->addStoreFilter($condition, false);
     }
     return parent::addFieldToFilter($field, $condition);
 }
Example #3
0
 /**
  * @test
  */
 public function testGetList()
 {
     $field = 'name';
     $value = 'magento';
     $condition = 'eq';
     $total = 10;
     $currentPage = 3;
     $pageSize = 2;
     $sortField = 'id';
     $criteria = $this->getMockBuilder('Magento\\Framework\\Api\\SearchCriteriaInterface')->getMock();
     $filterGroup = $this->getMockBuilder('Magento\\Framework\\Api\\Search\\FilterGroup')->getMock();
     $filter = $this->getMockBuilder('Magento\\Framework\\Api\\Filter')->getMock();
     $storeFilter = $this->getMockBuilder('Magento\\Framework\\Api\\Filter')->getMock();
     $sortOrder = $this->getMockBuilder('Magento\\Framework\\Api\\SortOrder')->getMock();
     $criteria->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroup]);
     $criteria->expects($this->once())->method('getSortOrders')->willReturn([$sortOrder]);
     $criteria->expects($this->once())->method('getCurrentPage')->willReturn($currentPage);
     $criteria->expects($this->once())->method('getPageSize')->willReturn($pageSize);
     $filterGroup->expects($this->once())->method('getFilters')->willReturn([$storeFilter, $filter]);
     $filter->expects($this->once())->method('getConditionType')->willReturn($condition);
     $filter->expects($this->any())->method('getField')->willReturn($field);
     $filter->expects($this->once())->method('getValue')->willReturn($value);
     $storeFilter->expects($this->any())->method('getField')->willReturn('store_id');
     $storeFilter->expects($this->once())->method('getValue')->willReturn(1);
     $sortOrder->expects($this->once())->method('getField')->willReturn($sortField);
     $sortOrder->expects($this->once())->method('getDirection')->willReturn(SearchCriteriaInterface::SORT_DESC);
     /** @var \Magento\Framework\Api\SearchCriteriaInterface $criteria */
     $this->collection->addItem($this->block);
     $this->blockSearchResult->expects($this->once())->method('setSearchCriteria')->with($criteria)->willReturnSelf();
     $this->collection->expects($this->once())->method('addFieldToFilter')->with($field, [$condition => $value])->willReturnSelf();
     $this->blockSearchResult->expects($this->once())->method('setTotalCount')->with($total)->willReturnSelf();
     $this->collection->expects($this->once())->method('getSize')->willReturn($total);
     $this->collection->expects($this->once())->method('setCurPage')->with($currentPage)->willReturnSelf();
     $this->collection->expects($this->once())->method('setPageSize')->with($pageSize)->willReturnSelf();
     $this->collection->expects($this->once())->method('addOrder')->with($sortField, 'DESC')->willReturnSelf();
     $this->block->expects($this->once())->method('getData')->willReturn(['data']);
     $this->blockSearchResult->expects($this->once())->method('setItems')->with(['someData'])->willReturnSelf();
     $this->dataHelper->expects($this->once())->method('populateWithArray')->with($this->blockData, ['data'], 'Magento\\Cms\\Api\\Data\\BlockInterface');
     $this->dataObjectProcessor->expects($this->once())->method('buildOutputDataArray')->with($this->blockData, 'Magento\\Cms\\Api\\Data\\BlockInterface')->willReturn('someData');
     $this->assertEquals($this->blockSearchResult, $this->repository->getList($criteria));
 }
Example #4
0
 /**
  * @return \Magento\Cms\Model\Resource\Block\Grid\Collection
  */
 protected function _afterLoad()
 {
     $this->walk('afterLoad');
     parent::_afterLoad();
 }
Example #5
0
 /**
  * Retrieve count of loaded items
  *
  * @return int
  */
 public function count()
 {
     $this->filterPool->applyFilters($this->collection);
     return $this->collection->count();
 }
Example #6
0
 /**
  * Retrieve count of loaded items
  *
  * @return int
  */
 public function count()
 {
     return $this->collection->count();
 }