/** * 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()); }
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()); }
/** * Run test getActiveFilters method * * @return void */ public function _testGetActiveFilters() { $result = ['field-1' => ['title' => 'title-1', 'current_display_value' => 'value-1'], 'field-2' => ['title' => 'title-2', 'current_display_value' => 'value-2'], 'field-3' => ['title' => 'title-3', 'current_display_value' => 'value-3'], 'field-4' => ['title' => 'title-4', 'current_display_value' => 'value-4']]; $meta = ['fields' => ['field-1' => ['filter_type' => true, 'title' => 'title-1'], 'field-2' => ['filter_type' => true, 'title' => 'title-2'], 'field-3' => ['filter_type' => true, 'title' => 'title-3'], 'field-4' => ['filter_type' => true, 'title' => 'title-4']]]; $filters = ['field-1' => 'value-1', 'field-2' => 'value-2', 'field-3' => 'value-3', 'field-4' => 'value-4']; /** * @var \Magento\Framework\View\Element\UiComponent\ConfigInterface * |\PHPUnit_Framework_MockObject_MockObject $configurationMock */ $configMock = $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', 'getMeta'], '', false); $this->filterPool->setConfig($configMock); $this->renderContextMock->expects($this->any())->method('getStorage')->will($this->returnValue($configStorageMock)); $configStorageMock->expects($this->any())->method('getMeta')->will($this->returnValue($meta)); $this->dataHelperMock->expects($this->once())->method('prepareFilterString')->will($this->returnValue($filters)); $this->renderContextMock->expects($this->once())->method('getRequestParam')->with(static::FILTER_VAR); $this->assertEquals($result, $this->filterPool->getActiveFilters()); }
public function testGetUrl() { $this->contextMock->expects($this->once())->method('getUrl')->willReturn('http://example.com'); $this->assertSame('http://example.com', $this->getModel()->getUrl()); }