/** * Run test prepare method * * @return void */ public function testPrepare() { /** * @var \Magento\Framework\View\Element\UiComponent\ConfigInterface * |\PHPUnit_Framework_MockObject_MockObject $configurationMock */ $configurationMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\ConfigInterface', [], '', false); /** * @var \Magento\Framework\View\Element\UiComponent\ConfigStorageInterface * |\PHPUnit_Framework_MockObject_MockObject $configStorageMock */ $configStorageMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\ConfigStorageInterface', ['addComponentsData', 'getDataCollection'], '', false); $dataCollectionMock = $this->getMockForAbstractClass('Magento\\Framework\\Api\\CriteriaInterface', ['addOrder'], '', false); $this->renderContextMock->expects($this->at(0))->method('getNamespace')->will($this->returnValue('namespace')); $this->renderContextMock->expects($this->at(1))->method('getNamespace')->will($this->returnValue('namespace')); $this->configFactoryMock->expects($this->any())->method('create')->will($this->returnValue($configurationMock)); $this->renderContextMock->expects($this->any())->method('getStorage')->will($this->returnValue($configStorageMock)); $configStorageMock->expects($this->once())->method('addComponentsData')->with($configurationMock); $configurationMock->expects($this->at(0))->method('getData')->with('field')->will($this->returnValue('field')); $configurationMock->expects($this->at(1))->method('getData')->with('direction')->will($this->returnValue('direction')); $this->renderContextMock->expects($this->any())->method('getStorage')->will($this->returnValue($configStorageMock)); $configStorageMock->expects($this->once())->method('getDataCollection')->will($this->returnValue($dataCollectionMock)); $dataCollectionMock->expects($this->once())->method('addOrder')->with('field', 'FIELD'); $this->renderContextMock->expects($this->any())->method('getRequestParam')->will($this->returnValue('field')); $this->renderContextMock->expects($this->any())->method('getRequestParam')->will($this->returnValue('direction')); $this->assertNull($this->view->prepare()); }
/** * Run test prepare method * * @return void * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function testPrepare() { /** * @var \Magento\Framework\View\Element\UiComponent\ConfigInterface * |\PHPUnit_Framework_MockObject_MockObject $configurationMock */ $configurationMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\ConfigInterface', ['getParentName'], '', false); /** * @var \Magento\Framework\View\Element\UiComponent\ConfigStorageInterface * |\PHPUnit_Framework_MockObject_MockObject $configStorageMock */ $configStorageMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\ConfigStorageInterface', ['addComponentsData', 'getDataCollection', 'getMeta'], '', false); /** * @var \Magento\Framework\Data\Collection|\PHPUnit_Framework_MockObject_MockObject $dataCollectionMock */ $dataCollectionMock = $this->getMock('Magento\\Framework\\Data\\Collection', ['setOrder'], [], '', false); $this->renderContextMock->expects($this->at(0))->method('getNamespace')->will($this->returnValue('namespace')); $this->renderContextMock->expects($this->at(1))->method('getNamespace')->will($this->returnValue('namespace')); $this->configFactoryMock->expects($this->any())->method('create')->will($this->returnValue($configurationMock)); $this->renderContextMock->expects($this->any())->method('getStorage')->will($this->returnValue($configStorageMock)); $configStorageMock->expects($this->at(0))->method('getDataCollection')->will($this->returnValue($dataCollectionMock)); $configStorageMock->expects($this->at(1))->method('getDataCollection')->will($this->returnValue($dataCollectionMock)); $metaData = ['field-1' => 'value-1', 'field-2' => 'value-2', 'field-3' => 'value-3', 'field-4' => 'value-4']; $meta = ['fields' => $metaData]; $filters = $metaData; $configStorageMock->expects($this->any())->method('getMeta')->will($this->returnValue($meta)); $this->renderContextMock->expects($this->once())->method('getRequestParam')->with(static::FILTER_VAR); $filterMock = $this->getMockForAbstractClass('Magento\\Ui\\Component\\Filter\\FilterInterface', ['getCondition'], '', false); $this->filterPoolProviderMock->expects($this->any())->method('getFilter')->will($this->returnValue($filterMock)); $filterMock->expects($this->any())->method('getCondition')->will($this->returnValue(true)); $dataCollectionMock->expects($this->any())->method('addFieldToFilter'); $this->assertNull($this->filterPool->prepare()); }
public function testPrepare() { $paramsSize = 20; $paramsPage = 1; $nameSpace = 'namespace'; $configurationMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\ConfigInterface', ['getData'], '', false); $this->renderContextMock->expects($this->any())->method('getNamespace')->willReturn($nameSpace); $this->configFactoryMock->expects($this->once())->method('create')->willReturn($configurationMock); $storageMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\ConfigStorageInterface'); $dataCollectionMock = $this->getMockForAbstractClass('\\Magento\\Framework\\Data\\CollectionDataSourceInterface', [], '', false, true, true, ['setLimit']); $this->renderContextMock->expects($this->any())->method('getStorage')->willReturn($storageMock); $storageMock->expects($this->once())->method('getDataCollection')->willReturn($dataCollectionMock); $configurationMock->expects($this->at(0))->method('getData')->with('current')->willReturn($paramsPage); $configurationMock->expects($this->at(1))->method('getData')->with('pageSize')->willReturn($paramsSize); $this->renderContextMock->expects($this->atLeastOnce())->method('getRequestParam')->willReturnMap([['page', $paramsPage, $paramsPage], ['limit', $paramsSize, $paramsSize]]); $dataCollectionMock->expects($this->any())->method('setLimit')->with($paramsPage, $paramsSize)->willReturnSelf(); $this->assertNull($this->view->prepare()); }
/** * Set component configuration * * @param null $configData * @param null $name * @param null $parentName * @return void */ public function prepareConfiguration($configData = null, $name = null, $parentName = null) { $arguments = []; $arguments['name'] = $name ?: $this->renderContext->getNamespace() . '_' . $this->getNameInLayout(); $arguments['parentName'] = $parentName ?: $this->renderContext->getNamespace(); if ($configData) { $arguments['configuration'] = $configData; } $this->config = $this->configFactory->create($arguments); $this->renderContext->getStorage()->addComponentsData($this->config); }
public function testPrepare() { $this->prepareMeta(); $config = ['page_actions' => ['add' => ['name' => 'add', 'label' => __('Add New'), 'class' => 'primary', 'url' => 'http://some.url']]]; $this->urlBuilder->expects($this->at(0))->method('getUrl')->with('*/*/new')->willReturn('http://mage.local/category/new'); $dataCollection = $this->getMock('Magento\\Framework\\Data\\CollectionDataSourceInterface', [], [], '', false); $this->listingView->setData('configuration', $config); $this->listingView->setData('name', 'someName'); $this->listingView->setData('dataSource', $dataCollection); $this->actionPool->expects($this->once())->method('add')->with('add', $config['page_actions']['add'], $this->listingView); $this->configurationFactory->expects($this->once())->method('create')->willReturn($this->configuration); $this->assertNull($this->listingView->prepare()); }