public function testAdd() { $blockName = 'testName'; $blockClass = '\\Magento\\Framework\\View\\BlockPoolTestBlock'; $arguments = ['key' => 'value']; $block = $this->getMock('Magento\\Framework\\View\\BlockPoolTestBlock'); $this->blockFactory->expects($this->atLeastOnce())->method('createBlock')->with($blockClass, $arguments)->will($this->returnValue($block)); $this->assertEquals($this->blockPool, $this->blockPool->add($blockName, $blockClass, $arguments)); $this->assertEquals([$blockName => $block], $this->blockPool->get()); $this->assertEquals($block, $this->blockPool->get($blockName)); $this->assertNull($this->blockPool->get('someWrongName')); }
public function testRenderRecurringPaymentForm() { $blockMock = $this->getMock('Magento\\Framework\\View\\Element\\BlockInterface', array('setNameInLayout', 'setParentElement', 'setProductEntity', 'toHtml', 'addFieldMap', 'addFieldDependence', 'addConfigOptions')); $map = array(array('Magento\\RecurringPayment\\Block\\Adminhtml\\Payment\\Edit\\Form', array(), $blockMock), array('Magento\\Backend\\Block\\Widget\\Form\\Element\\Dependence', array(), $blockMock)); $paymentElement = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\AbstractElement', array(), array(), '', false); $this->_scopeConfig->expects($this->any())->method('getValue')->will($this->returnValue(true)); $this->_testModel->render($paymentElement); $product = $this->getMock('Magento\\Catalog\\Model\\Product', array(), array(), '', false); $this->_registry->expects($this->once())->method('registry')->will($this->returnValue($product)); $this->_blockFactory->expects($this->any())->method('createBlock')->will($this->returnValueMap($map)); $blockMock->expects($this->any())->method('setNameInLayout'); $blockMock->expects($this->once())->method('setProductEntity')->with($product); $blockMock->expects($this->exactly(2))->method('toHtml')->will($this->returnValue('html')); $blockMock->expects($this->once())->method('addConfigOptions')->with(array('levels_up' => 2)); $this->assertEquals('htmlhtml', $this->_testModel->getElementHtml()); }
public function testProcess() { $this->prepareScheduledStructure(); $this->readerContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Reader\\Context')->disableOriginalConstructor()->getMock(); $this->readerContextMock->expects($this->any())->method('getScheduledStructure')->willReturn($this->scheduledStructureMock); $generatorContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Generator\\Context')->disableOriginalConstructor()->getMock(); $structureMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout\\Data\\Structure')->disableOriginalConstructor()->getMock(); $structureMock->expects($this->once())->method('addToParentGroup')->with(UiComponent::TYPE, 'new_group')->willReturnSelf(); $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\LayoutInterface')->getMockForAbstractClass(); $generatorContextMock->expects($this->any())->method('getStructure')->willReturn($structureMock); $generatorContextMock->expects($this->any())->method('getLayout')->willReturn($layoutMock); $this->uiComponentFactoryMock->expects($this->any())->method('setLayout')->with($layoutMock)->willReturnSelf(); $componentMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponentInterface', [], '', false, true, true, []); $contextMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponent\\ContextInterface', [], '', false); $blockMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\BlockInterface', [], '', false); $this->contextFactoryMock->expects($this->once())->method('create')->with(['namespace' => 'uiComponent', 'pageLayout' => $layoutMock])->willReturn($contextMock); $this->uiComponentFactoryMock->expects($this->any())->method('create')->with('uiComponent', null, ['context' => $contextMock])->willReturn($componentMock); $this->blockFactoryMock->expects($this->once())->method('createBlock')->with(UiComponent::CONTAINER, ['component' => $componentMock])->willReturn($blockMock); $this->argumentInterpreterMock->expects($this->any())->method('evaluate')->will($this->returnValueMap([[['key_1' => 'value_1'], 'value_1'], [['key_2' => 'value_2'], 'value_2']])); $layoutMock->expects($this->any())->method('setBlock')->with(UiComponent::TYPE, $blockMock)->willReturnSelf(); $this->uiComponent->process($this->readerContextMock, $generatorContextMock); }
protected function createBlock($blockClass) { $block = $this->getMock('Magento\\Framework\\View\\Element\\BlockInterface'); $this->blockFactory->expects($this->once())->method('createBlock')->with($blockClass)->will($this->returnValue($block)); return $block; }