/** * @param $expanded * @param $nested * @param $extra * @dataProvider testRenderWithStoredElementsDataProvider */ public function testRenderWithStoredElements($expanded, $nested, $extra) { $this->userMock->expects($this->any())->method('getExtra')->willReturn($extra); $this->_helperMock->expects($this->any())->method('getScript')->will($this->returnArgument(0)); $fieldMock = $this->getMockBuilder('Magento\\Framework\\Data\\Form\\Element\\Text')->setMethods(['getId', 'getTooltip', 'toHtml', 'getHtmlId', 'getIsNested', 'getExpanded'])->disableOriginalConstructor()->getMock(); $fieldMock->expects($this->any())->method('getId')->will($this->returnValue('test_field_id')); $fieldMock->expects($this->any())->method('getTooltip')->will($this->returnValue('test_field_tootip')); $fieldMock->expects($this->any())->method('toHtml')->will($this->returnValue('test_field_toHTML')); $fieldMock->expects($this->any())->method('getHtmlId')->willReturn('test_field_HTML_id'); $fieldSetMock = $this->getMockBuilder('Magento\\Framework\\Data\\Form\\Element\\Fieldset')->setMethods(['getId', 'getTooltip', 'toHtml', 'getHtmlId', 'getIsNested', 'getExpanded'])->disableOriginalConstructor()->getMock(); $fieldSetMock->expects($this->any())->method('getId')->will($this->returnValue('test_fieldset_id')); $fieldSetMock->expects($this->any())->method('getTooltip')->will($this->returnValue('test_fieldset_tootip')); $fieldSetMock->expects($this->any())->method('toHtml')->will($this->returnValue('test_fieldset_toHTML')); $fieldSetMock->expects($this->any())->method('getHtmlId')->willReturn('test_fieldset_HTML_id'); $factory = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Factory', [], [], '', false); $factoryColl = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\CollectionFactory', [], [], '', false); $formMock = $this->getMock('Magento\\Framework\\Data\\Form\\AbstractForm', [], [$factory, $factoryColl]); $collection = $this->_testHelper->getObject('Magento\\Framework\\Data\\Form\\Element\\Collection', ['container' => $formMock]); $collection->add($fieldMock); $collection->add($fieldSetMock); $this->_elementMock->expects($this->any())->method('getElements')->will($this->returnValue($collection)); $this->_elementMock->expects($this->any())->method('getIsNested')->will($this->returnValue($nested)); $this->_elementMock->expects($this->any())->method('getExpanded')->will($this->returnValue($expanded)); $actual = $this->_object->render($this->_elementMock); $this->assertContains('test_field_toHTML', $actual); $expected = '<div id="row_test_field_id_comment" class="system-tooltip-box"' . ' style="display:none;">test_field_tootip</div>'; $this->assertContains($expected, $actual); if ($nested) { $this->assertContains('nested', $actual); } }
/** * @param AbstractElement $element * @return string */ public function render(AbstractElement $element) { $childrenHtml = $this->_getChildrenElementsHtml($element); if (empty($childrenHtml)) { return ''; } return parent::render($element); }
public function testRenderWithStoredElements() { $this->_helperMock->expects($this->any())->method('getScript')->will($this->returnArgument(0)); $fieldMock = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Text', ['getId', 'getTooltip', 'toHtml'], [], '', false, false, true); $fieldMock->expects($this->any())->method('getId')->will($this->returnValue('test_field_id')); $fieldMock->expects($this->any())->method('getTooltip')->will($this->returnValue('test_field_tootip')); $fieldMock->expects($this->any())->method('toHtml')->will($this->returnValue('test_field_toHTML')); $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $factory = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Factory', [], [], '', false); $factoryColl = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\CollectionFactory', [], [], '', false); $formMock = $this->getMock('Magento\\Framework\\Data\\Form\\AbstractForm', [], [$factory, $factoryColl]); $collection = $helper->getObject('Magento\\Framework\\Data\\Form\\Element\\Collection', ['container' => $formMock]); $collection->add($fieldMock); $this->_elementMock->expects($this->any())->method('getElements')->will($this->returnValue($collection)); $actual = $this->_object->render($this->_elementMock); $this->assertContains('test_field_toHTML', $actual); $expected = '<div id="row_test_field_id_comment" class="system-tooltip-box"' . ' style="display:none;">test_field_tootip</div>'; $this->assertContains($expected, $actual); }