コード例 #1
0
 /**
  * Run test toOptionArray method
  *
  * @return void
  */
 public function testToOptionArray()
 {
     $pageCollectionMock = $this->getMock('Magento\\Cms\\Model\\Resource\\Page\\Collection', [], [], '', false);
     $pageCriteriaMock = $this->getMock('Magento\\Cms\\Model\\Resource\\PageCriteria', [], [], '', false);
     $this->pageRepositoryMock->expects($this->once())->method('getList')->with($pageCriteriaMock)->will($this->returnValue($pageCollectionMock));
     $this->pageCriteriaFactoryMock->expects($this->once())->method('create')->will($this->returnValue($pageCriteriaMock));
     $pageCollectionMock->expects($this->once())->method('toOptionIdArray')->will($this->returnValue('return-value'));
     $this->assertEquals('return-value', $this->page->toOptionArray());
 }
コード例 #2
0
 /**
  * Run test deleteById method
  *
  * @return void
  */
 public function testDeleteById()
 {
     $id = 20;
     $pageMock = $this->getMockForAbstractClass('Magento\\Cms\\Model\\Page', [], '', false, true, true, ['getId']);
     $this->pageFactoryMock->expects($this->once())->method('create')->will($this->returnValue($pageMock));
     $this->resourceMock->expects($this->once())->method('load')->with($pageMock, $id);
     $pageMock->expects($this->once())->method('getId')->will($this->returnValue($id));
     $this->resourceMock->expects($this->once())->method('delete')->with($pageMock);
     $this->assertTrue($this->pageRepository->deleteById($id));
 }
コード例 #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(SortOrder::SORT_DESC);
     /** @var \Magento\Framework\Api\SearchCriteriaInterface $criteria */
     $this->collection->addItem($this->page);
     $this->pageSearchResult->expects($this->once())->method('setSearchCriteria')->with($criteria)->willReturnSelf();
     $this->collection->expects($this->once())->method('addFieldToFilter')->with($field, [$condition => $value])->willReturnSelf();
     $this->pageSearchResult->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->page->expects($this->once())->method('getData')->willReturn(['data']);
     $this->pageSearchResult->expects($this->once())->method('setItems')->with(['someData'])->willReturnSelf();
     $this->dataHelper->expects($this->once())->method('populateWithArray')->with($this->pageData, ['data'], 'Magento\\Cms\\Api\\Data\\PageInterface');
     $this->dataObjectProcessor->expects($this->once())->method('buildOutputDataArray')->with($this->pageData, 'Magento\\Cms\\Api\\Data\\PageInterface')->willReturn('someData');
     $this->assertEquals($this->pageSearchResult, $this->repository->getList($criteria));
 }
コード例 #4
0
 /**
  * @return \Magento\Cms\Model\Resource\Page\Collection
  */
 public function getResultCollection()
 {
     return $this->repository->getList($this);
 }
コード例 #5
0
 /**
  * Run test getResultCollection method
  *
  * @return void
  */
 public function testGetResultCollection()
 {
     $this->repositoryMock->expects($this->once())->method('getList')->with($this->pageCollection)->will($this->returnValue('return-value'));
     $this->assertEquals('return-value', $this->pageCollection->getResultCollection());
 }