public function testToHtml() { $fieldSet = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Fieldset', [], [], '', false); $form = $this->getMock('Magento\\Framework\\Data\\Form', [], [], '', false); $attributeModel = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false); $entityType = $this->getMock('Magento\\Eav\\Model\\Entity\\Type', [], [], '', false); $formElement = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Text', ['setDisabled'], [], '', false); $directoryReadInterface = $this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface'); $this->registry->expects($this->any())->method('registry')->with('entity_attribute')->willReturn($attributeModel); $this->formFactory->expects($this->any())->method('create')->willReturn($form); $form->expects($this->any())->method('addFieldset')->willReturn($fieldSet); $form->expects($this->any())->method('getElement')->willReturn($formElement); $fieldSet->expects($this->any())->method('addField')->willReturnSelf(); $attributeModel->expects($this->any())->method('getDefaultValue')->willReturn('default_value'); $attributeModel->expects($this->any())->method('setDisabled')->willReturnSelf(); $attributeModel->expects($this->any())->method('getId')->willReturn(1); $attributeModel->expects($this->any())->method('getEntityType')->willReturn($entityType); $attributeModel->expects($this->any())->method('getIsUserDefined')->willReturn(false); $attributeModel->expects($this->any())->method('getAttributeCode')->willReturn('attribute_code'); $this->localeDate->expects($this->any())->method('getDateFormat')->willReturn('mm/dd/yy'); $entityType->expects($this->any())->method('getEntityTypeCode')->willReturn('entity_type_code'); $this->eavData->expects($this->any())->method('getFrontendClasses')->willReturn([]); $formElement->expects($this->exactly(3))->method('setDisabled')->willReturnSelf(); $this->yesNo->expects($this->any())->method('toOptionArray')->willReturn(['yes', 'no']); $this->filesystem->expects($this->any())->method('getDirectoryRead')->willReturn($directoryReadInterface); $directoryReadInterface->expects($this->any())->method('getRelativePath')->willReturn('relative_path'); $this->block->setData(['action' => 'save']); $this->block->toHtml(); }
public function testBeforeToHtml() { $formMock = $this->getMockBuilder('Magento\\Framework\\Data\\Form')->disableOriginalConstructor()->setMethods([])->getMock(); $fieldsetMock = $this->getMockBuilder('Magento\\Framework\\Data\\Form\\Element\\Fieldset')->disableOriginalConstructor()->setMethods([])->getMock(); $this->formFactoryMock->expects($this->any())->method('create')->willReturn($formMock); $formMock->expects($this->any())->method('addFieldSet')->willReturn($fieldsetMock); $fieldsetMock->expects($this->exactly(4))->method('addField')->withConsecutive(['role_name'], ['role_id'], ['in_role_user'], ['in_role_user_old']); $this->assertInstanceOf('Magento\\User\\Block\\Role\\Tab\\Info', $this->model->_beforeToHtml()); }
protected function setUp() { parent::setUp(); $this->formFactoryMock = $this->getMockBuilder(FormFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->formMock = $this->getMockBuilder(Form::class)->disableOriginalConstructor()->getMock(); $this->wysiwygConfig = $this->getMockBuilder(ConfigInterface::class)->getMockForAbstractClass(); $this->editorMock = $this->getMockBuilder(Editor::class)->disableOriginalConstructor()->getMock(); $this->formFactoryMock->expects($this->any())->method('create')->willReturn($this->formMock); $this->formMock->expects($this->once())->method('addField')->willReturn($this->editorMock); $this->editorMock->expects($this->once())->method('getElementHtml'); }
public function testGetExtendedElement() { $switchAttributeCode = 'test_code'; $form = $this->getMockBuilder(\Magento\Framework\Data\Form::class)->disableOriginalConstructor()->getMock(); $and = new \PHPUnit_Framework_Constraint_And(); $and->setConstraints([new \PHPUnit_Framework_Constraint_ArrayHasKey('value')]); $form->expects($this->once())->method('addField')->with($switchAttributeCode, 'select', $and); $this->formFactory->expects($this->once())->method('create')->with()->will($this->returnValue($form)); $product = $this->getProduct(); $product->expects($this->once())->method('getData')->with($switchAttributeCode)->will($this->returnValue(123)); $this->object->setIsDisabledField(true); $this->object->getExtendedElement($switchAttributeCode); }
public function testToHtmlWithoutRatingData() { $this->registry->expects($this->any())->method('registry')->will($this->returnValue(false)); $this->systemStore->expects($this->any())->method('getStoreCollection')->will($this->returnValue(['0' => $this->store])); $this->formFactory->expects($this->any())->method('create')->will($this->returnValue($this->form)); $this->viewFileSystem->expects($this->any())->method('getTemplateFileName')->will($this->returnValue('template_file_name.html')); $this->fileSystem->expects($this->any())->method('getDirectoryRead')->will($this->returnValue($this->directoryReadInterface)); $this->block->toHtml(); }
public function testAddErrorMessageWhenProductWithoutStores() { $form = $this->getMock('Magento\\Framework\\Data\\Form', [], [], '', false); $form->expects($this->any())->method('getElement')->will($this->returnValue($this->getMockForAbstractClass('\\Magento\\Framework\\Data\\Form\\Element\\AbstractElement', [], '', false))); $this->formFactory->expects($this->once())->method('create')->will($this->returnValue($form)); $fieldset = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Fieldset', [], [], '', false); $form->expects($this->once())->method('addFieldset')->will($this->returnValue($fieldset)); $storeElement = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\AbstractElement', ['setAfterElementHtml', 'setValues'], [], '', false); $fieldset->expects($this->at(2))->method('addField')->with('store_id', 'select', ['label' => 'Store', 'title' => 'Store', 'name' => 'store_id', 'required' => true, 'value' => 0])->willReturn($storeElement); $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false); $product->expects($this->any())->method('getId')->willReturn('product_id'); $product->expects($this->once())->method('getStoreIds')->willReturn([]); $this->productFactory->expects($this->once())->method('create')->willReturn($product); $this->categoryFactory->expects($this->once())->method('create')->willReturn($this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false)); $storeElement->expects($this->once())->method('setAfterElementHtml'); $storeElement->expects($this->once())->method('setValues')->with([]); $this->layout->expects($this->once())->method('createBlock')->willReturn($this->getMock('Magento\\Framework\\Data\\Form\\Element\\Renderer\\RendererInterface')); $this->form->toHtml(); }
/** * @param $customerData * @param $isSingleStoreMode * @param $canModifyCustomer * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ private function _setupStoreMode($customerData, $isSingleStoreMode, $canModifyCustomer) { $backendSessionMock = $this->getMock('\\Magento\\Backend\\Model\\Session', ['getCustomerData'], [], '', false); $backendSessionMock->expects($this->any())->method('getCustomerData')->will($this->returnValue([])); $layoutMock = $this->getMock('\\Magento\\Framework\\View\\Layout\\Element\\Layout', ['createBlock'], [], '', false); $layoutMock->expects($this->at(0))->method('createBlock')->with('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Group')->will($this->returnValue($this->objectManagerHelper->getObject('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Group'))); $layoutMock->expects($this->at(1))->method('createBlock')->with('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element')->will($this->returnValue($this->objectManagerHelper->getObject('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element'))); if (empty($customerData['id'])) { $layoutMock->expects($this->at(2))->method('createBlock')->with('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Sendemail')->will($this->returnValue($this->objectManagerHelper->getObject('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Sendemail'))); } $urlBuilderMock = $this->getMock('\\Magento\\Backend\\Model\\Url', ['getBaseUrl'], [], '', false); $urlBuilderMock->expects($this->once())->method('getBaseUrl')->will($this->returnValue('someUrl')); $storeManagerMock = $this->getMock('Magento\\Store\\Model\\StoreManager', [], [], '', false); $storeManagerMock->expects($this->any())->method('isSingleStoreMode')->will($this->returnValue($isSingleStoreMode)); $customerObject = $this->getMock('\\Magento\\Customer\\Api\\Data\\CustomerInterface'); if (!empty($customerData['id'])) { $customerObject->expects($this->any())->method('getId')->will($this->returnValue($customerData['id'])); } $fieldset = $this->getMockBuilder('\\Magento\\Framework\\Data\\Form\\Element\\Fieldset')->setMethods(['getForm', 'addField', 'removeField'])->disableOriginalConstructor()->getMock(); $accountForm = $this->getMockBuilder('Magento\\Framework\\Data\\Form')->setMethods(['create', 'addFieldset', 'getElement', 'setValues'])->disableOriginalConstructor()->getMock(); $accountForm->expects($this->any())->method('addFieldset')->with('base_fieldset')->will($this->returnValue($fieldset)); $accountForm->expects($this->any())->method('setValues')->will($this->returnValue($accountForm)); $fieldset->expects($this->any())->method('getForm')->will($this->returnValue($accountForm)); $formElement = $this->getMockBuilder('\\Magento\\Framework\\Data\\Form\\Element\\Select')->setMethods(['setRenderer', 'addClass', 'setDisabled'])->disableOriginalConstructor()->getMock(); $formElement->expects($this->any())->method('setRenderer')->will($this->returnValue(null)); $formElement->expects($this->any())->method('addClass')->will($this->returnValue(null)); $formElement->expects($this->any())->method('setDisabled')->will($this->returnValue(null)); $accountForm->expects($this->any())->method('getElement')->withAnyParameters()->will($this->returnValue($formElement)); $fieldset->expects($this->any())->method('addField')->will($this->returnValue($formElement)); $customerForm = $this->getMock('\\Magento\\Customer\\Model\\Metadata\\Form', ['getAttributes'], [], '', false); $customerForm->expects($this->any())->method('getAttributes')->will($this->returnValue([])); $this->contextMock->expects($this->any())->method('getBackendSession')->will($this->returnValue($backendSessionMock)); $this->contextMock->expects($this->any())->method('getLayout')->will($this->returnValue($layoutMock)); $this->contextMock->expects($this->any())->method('getUrlBuilder')->will($this->returnValue($urlBuilderMock)); $this->contextMock->expects($this->any())->method('getStoreManager')->will($this->returnValue($storeManagerMock)); $this->customerFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerObject)); $this->dataObjectHelperMock->expects($this->once())->method('populateWithArray'); $this->options->expects($this->any())->method('getNamePrefixOptions')->will($this->returnValue(['Pref1', 'Pref2'])); $this->options->expects($this->any())->method('getNameSuffixOptions')->will($this->returnValue(['Suf1', 'Suf2'])); $this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($accountForm)); $this->extensibleDataObjectConverterMock->expects($this->any())->method('toFlatArray')->will($this->returnValue($customerData)); $this->customerFormFactoryMock->expects($this->any())->method('create')->with('customer', 'adminhtml_customer', $this->extensibleDataObjectConverterMock->toFlatArray($customerObject, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface'))->will($this->returnValue($customerForm)); $this->accountManagementMock->expects($this->any())->method('isReadOnly')->withAnyParameters()->will($this->returnValue(!$canModifyCustomer)); $this->accountManagementMock->expects($this->any())->method('getConfirmationStatus')->withAnyParameters()->will($this->returnValue(AccountManagementInterface::ACCOUNT_CONFIRMED)); }