/** * @covers \Magento\Framework\Data\Form\Element\Checkbox::getElementHtml */ public function testGetElementHtml() { $this->_model->setIsChecked(false); $html = $this->_model->getElementHtml(); $this->assertContains('type="checkbox"', $html); $this->assertNotContains('checked="checked"', $html); $this->_model->setIsChecked(true); $html = $this->_model->getElementHtml(); $this->assertContains('checked="checked"', $html); }
public function testSetForm() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $factory = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Factory', [], [], '', false); $collectionFactory = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\CollectionFactory', ['create'], [], '', false); $formKey = $this->getMock('Magento\\Framework\\Data\\Form\\FormKey', [], [], '', false); $form = new \Magento\Framework\Data\Form($factory, $collectionFactory, $formKey); $helper = $this->getMock('Magento\\Catalog\\Helper\\Product', ['getTypeSwitcherControlLabel'], [], '', false, false); $helper->expects($this->any())->method('getTypeSwitcherControlLabel')->will($this->returnValue('Virtual / Downloadable')); $this->_virtual = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Checkbox', ['setId', 'setName', 'setLabel', 'setForm'], [], '', false, false); $this->_virtual->expects($this->any())->method('setId')->will($this->returnSelf()); $this->_virtual->expects($this->any())->method('setName')->will($this->returnSelf()); $this->_virtual->expects($this->any())->method('setLabel')->will($this->returnSelf()); $this->_virtual->expects($this->any())->method('setForm')->with($this->equalTo($form))->will($this->returnSelf()); $factory = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Factory', [], [], '', false); $factory->expects($this->once())->method('create')->with($this->equalTo('checkbox'))->will($this->returnValue($this->_virtual)); $this->_model = $objectManager->getObject('Magento\\Catalog\\Block\\Adminhtml\\Product\\Helper\\Form\\Weight', ['factoryElement' => $factory, 'factoryCollection' => $collectionFactory, 'helper' => $helper]); $this->_model->setForm($form); }
public function testGetEscapedValue() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $collectionFactory = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\CollectionFactory', ['create'], [], '', false); $localeFormat = $this->getMock('\\Magento\\Framework\\Locale\\Format', [], [], '', false); $localeFormat->expects($this->any())->method('getPriceFormat')->willReturn(['precision' => 2, 'decimalSymbol' => ',', 'groupSymbol' => '.']); $helper = $this->getMock('Magento\\Catalog\\Helper\\Product', ['getTypeSwitcherControlLabel'], [], '', false, false); $helper->expects($this->any())->method('getTypeSwitcherControlLabel')->will($this->returnValue('Virtual / Downloadable')); $this->_virtual = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Checkbox', ['setId', 'setName', 'setLabel'], [], '', false, false); $this->_virtual->expects($this->any())->method('setId')->will($this->returnSelf()); $this->_virtual->expects($this->any())->method('setName')->will($this->returnSelf()); $this->_virtual->expects($this->any())->method('setLabel')->will($this->returnSelf()); $factory = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Factory', [], [], '', false); $factory->expects($this->once())->method('create')->with($this->equalTo('checkbox'))->will($this->returnValue($this->_virtual)); $this->_model = $objectManager->getObject('Magento\\Catalog\\Block\\Adminhtml\\Product\\Helper\\Form\\Weight', ['factoryElement' => $factory, 'factoryCollection' => $collectionFactory, 'helper' => $helper, 'localeFormat' => $localeFormat]); $this->_model->setValue('30000.4'); $this->_model->setEntityAttribute(true); $return = $this->_model->getEscapedValue('30000.4'); $this->assertEquals('30.000,40', $return); }
/** * Set form for both fields * * @param Form $form * @return $this */ public function setForm($form) { $this->weightSwitcher->setForm($form); return parent::setForm($form); }
/** * Set form for both fields * * @param Form $form * @return $this */ public function setForm($form) { $this->_virtual->setForm($form); return parent::setForm($form); }