/** * @magentoDataFixture Magento/Customer/_files/customer.php */ public function testToHtml() { $this->coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, 1); $html = $this->block->initForm()->toHtml(); $this->assertStringStartsWith("<div class=\"entry-edit\">", $html); $this->assertContains("<span>Newsletter Information</span>", $html); $this->assertContains("type=\"checkbox\"", $html); $this->assertNotContains("checked=\"checked\"", $html); $this->assertContains("<span>Subscribed to Newsletter</span>", $html); $this->assertContains(">No Newsletter Found<", $html); }
public function testInitForm() { $subscriberMock = $this->getMock('\\Magento\\Newsletter\\Model\\Subscriber', [], [], '', false); $fieldsetMock = $this->getMock('\\Magento\\Framework\\Data\\Form\\Element\\Fieldset', [], [], '', false); $elementMock = $this->getMock('\\Magento\\Framework\\Data\\Form\\Element\\AbstractElement', [], [], '', false); $formMock = $this->getMock('\\Magento\\Framework\\Data\\Form', ['setHtmlIdPrefix', 'addFieldset', 'setValues', 'getElement', 'setForm', 'setParent', 'setBaseUrl'], [], '', false); $this->registryMock->expects($this->atLeastOnce())->method('registry')->willReturn($subscriberMock); $this->formFactoryMock->expects($this->once())->method('create')->willReturn($formMock); $formMock->expects($this->once())->method('setHtmlIdPrefix')->with('_newsletter'); $this->subscriberFactoryMock->expects($this->once())->method('create')->willReturn($subscriberMock); $subscriberMock->expects($this->once())->method('loadByCustomerId')->with($subscriberMock)->willReturnSelf(); $this->registryMock->expects($this->once())->method('register')->with('subscriber', $subscriberMock); $formMock->expects($this->once())->method('addFieldset')->willReturn($fieldsetMock); $this->accountManagementMock->expects($this->once())->method('isReadOnly')->with($subscriberMock)->willReturn(false); $subscriberMock->expects($this->once())->method('isSubscribed')->willReturn(true); $formMock->expects($this->once())->method('getElement')->willReturn($elementMock); $this->urlBuilderMock->expects($this->once())->method('getBaseUrl')->willReturn('domain.com'); $this->assertSame($this->model, $this->model->initForm()); }
public function testInitFormWithCustomerFormData() { $customerId = 1; $subscriberMock = $this->getMock('\\Magento\\Newsletter\\Model\\Subscriber', [], [], '', false); $fieldsetMock = $this->getMock('\\Magento\\Framework\\Data\\Form\\Element\\Fieldset', [], [], '', false); $elementMock = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Checkbox', ['setIsChecked'], [], '', false); $formMock = $this->getMock('\\Magento\\Framework\\Data\\Form', ['setHtmlIdPrefix', 'addFieldset', 'setValues', 'getElement', 'setForm', 'setParent', 'setBaseUrl'], [], '', false); $this->registryMock->expects($this->exactly(3))->method('registry')->willReturnMap([[RegistryConstants::CURRENT_CUSTOMER_ID, $customerId], ['subscriber', $subscriberMock]]); $this->formFactoryMock->expects($this->once())->method('create')->willReturn($formMock); $formMock->expects($this->once())->method('setHtmlIdPrefix')->with('_newsletter'); $this->subscriberFactoryMock->expects($this->once())->method('create')->willReturn($subscriberMock); $subscriberMock->expects($this->once())->method('loadByCustomerId')->with($customerId)->willReturnSelf(); $formMock->expects($this->once())->method('addFieldset')->willReturn($fieldsetMock); $fieldsetMock->expects($this->once())->method('addField')->willReturn($elementMock); $this->accountManagementMock->expects($this->once())->method('isReadOnly')->with($customerId)->willReturn(false); $subscriberMock->expects($this->once())->method('isSubscribed')->willReturn(false); $this->urlBuilderMock->expects($this->once())->method('getBaseUrl')->willReturn('domain.com'); $this->backendSessionMock->expects($this->once())->method('getCustomerFormData')->willReturn(['customer' => ['entity_id' => $customerId], 'subscription' => true]); $formMock->expects($this->exactly(2))->method('getElement')->willReturnMap([['subscription', $elementMock]]); $elementMock->expects($this->exactly(2))->method('setIsChecked')->willReturnMap([[false], [true]]); $this->assertSame($this->model, $this->model->initForm()); }