/** * To option array * * @return array */ public function toOptionArray() { if (!$this->options) { $this->options = $this->collectionFactory->create()->toOptionIdArray(); } return $this->options; }
/** * @param string $name * @param string $primaryFieldName * @param string $requestFieldName * @param CollectionFactory $collectionFactory * @param FilterPool $filterPool * @param array $meta * @param array $data */ public function __construct($name, $primaryFieldName, $requestFieldName, CollectionFactory $collectionFactory, FilterPool $filterPool, array $meta = [], array $data = []) { parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data); $this->filterPool = $filterPool; $this->collection = $collectionFactory->create(); $this->collection->setFirstStoreFlag(true); }
/** * Run test toOptionArray method * * @return void */ public function testToOptionArray() { $pageCollectionMock = $this->getMock('Magento\\Cms\\Model\\Resource\\Page\\Collection', [], [], '', false); $this->collectionFactory->expects($this->once())->method('create')->will($this->returnValue($pageCollectionMock)); $pageCollectionMock->expects($this->once())->method('toOptionIdArray')->will($this->returnValue('return-value')); $this->assertEquals('return-value', $this->page->toOptionArray()); }
/** * Prepare collection * * @return \Magento\Backend\Block\Widget\Grid */ protected function _prepareCollection() { $collection = $this->_collectionFactory->create(); /* @var $collection \Magento\Cms\Model\Resource\Page\Collection */ $collection->setFirstStoreFlag(true); $this->setCollection($collection); return parent::_prepareCollection(); }
/** * @param string $primaryFieldName * @param string $requestFieldName * @param CollectionFactory $collectionFactory * @param array $meta * @param array $data */ public function __construct($primaryFieldName, $requestFieldName, CollectionFactory $collectionFactory, array $meta = [], array $data = []) { $this->primaryFieldName = $primaryFieldName; $this->requestFieldName = $requestFieldName; $this->collection = $collectionFactory->create(); $this->collection->setFirstStoreFlag(true); $this->meta = $meta; $this->data = $data; }
/** * Run test getList method * * @return void */ public function testGetList() { $criteriaMock = $this->getMock('Magento\\Cms\\Model\\Resource\\PageCriteria', [], [], '', false); $queryBuilderMock = $this->getMock('Magento\\Framework\\DB\\QueryBuilder', ['setCriteria', 'setResource', 'create'], [], '', false); $queryMock = $this->getMockForAbstractClass('Magento\\Framework\\DB\\QueryInterface', [], '', false); $collectionMock = $this->getMock('Magento\\Cms\\Model\\Resource\\Page\\Collection', [], [], '', false); $this->queryBuilderFactoryMock->expects($this->once())->method('create')->will($this->returnValue($queryBuilderMock)); $queryBuilderMock->expects($this->once())->method('setCriteria')->with($criteriaMock); $queryBuilderMock->expects($this->once())->method('setResource')->with($this->resourceMock); $queryBuilderMock->expects($this->once())->method('create')->will($this->returnValue($queryMock)); $this->pageCollectionFactoryMock->expects($this->once())->method('create')->with(['query' => $queryMock])->will($this->returnValue($collectionMock)); $this->assertEquals($collectionMock, $this->pageRepository->getList($criteriaMock)); }