/** * 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()); }
/** * Update data collection * * @return void */ protected function updateDataCollection() { $collection = $this->renderContext->getStorage()->getDataCollection($this->getParentName()); $metaData = $this->renderContext->getStorage()->getMeta($this->getParentName()); $metaData = $metaData['fields']; $filterData = $this->prepareFilterString($this->renderContext->getRequestParam(FilterAbstract::FILTER_VAR)); foreach ($filterData as $field => $value) { if (!isset($metaData[$field]['filter_type'])) { continue; } $condition = $this->filterPoolProvider->getFilter($metaData[$field]['filter_type'])->getCondition($value); if ($condition !== null) { $collection->addFieldToFilter($field, $condition); } } }