public function testSubscribe() { $email = '*****@*****.**'; $this->resource->expects($this->any())->method('loadByEmail')->willReturn(['subscriber_status' => 3, 'subscriber_email' => $email, 'name' => 'subscriber_name']); $this->resource->expects($this->any())->method('getIdFieldName')->willReturn('id_field'); $this->scopeConfig->expects($this->any())->method('getValue')->willReturn(true); $this->customerSession->expects($this->any())->method('isLoggedIn')->willReturn(true); $customerDataModel = $this->getMock('\\Magento\\Customer\\Api\\Data\\CustomerInterface'); $this->customerSession->expects($this->any())->method('getCustomerDataObject')->willReturn($customerDataModel); $this->customerSession->expects($this->any())->method('getCustomerId')->willReturn(1); $customerDataModel->expects($this->any())->method('getEmail')->willReturn($email); $this->customerRepository->expects($this->any())->method('getById')->willReturn($customerDataModel); $customerDataModel->expects($this->any())->method('getStoreId')->willReturn(1); $customerDataModel->expects($this->any())->method('getId')->willReturn(1); $this->transportBuilder->expects($this->any())->method('setTemplateIdentifier')->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('setTemplateOptions')->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('setTemplateVars')->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('setFrom')->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('addTo')->willReturnSelf(); $storeModel = $this->getMock('\\Magento\\Store\\Model\\Store', ['getId'], [], '', false); $this->scopeConfig->expects($this->any())->method('getValue')->willReturn('*****@*****.**'); $this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel); $storeModel->expects($this->any())->method('getId')->willReturn(1); $transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface'); $this->transportBuilder->expects($this->any())->method('getTransport')->willReturn($transport); $transport->expects($this->any())->method('sendMessage')->willReturnSelf(); $inlineTranslation = $this->getMock('Magento\\Framework\\Translate\\Inline\\StateInterface'); $inlineTranslation->expects($this->any())->method('resume')->willReturnSelf(); $this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf(); $this->assertEquals(1, $this->subscriber->subscribe($email)); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testNewAccount() { $customerId = 1; $customerStoreId = 2; $customerEmail = '*****@*****.**'; $customerData = ['key' => 'value']; $customerName = 'Customer Name'; $templateIdentifier = 'Template Identifier'; $sender = 'Sender'; $customer = $this->getMock(\Magento\Customer\Api\Data\CustomerInterface::class, [], [], '', false); $customer->expects($this->any())->method('getStoreId')->willReturn($customerStoreId); $customer->expects($this->any())->method('getId')->willReturn($customerId); $customer->expects($this->any())->method('getEmail')->willReturn($customerEmail); $this->storeMock->expects($this->any())->method('getId')->willReturn($customerStoreId); $this->storeManagerMock->expects($this->once())->method('getStore')->with($customerStoreId)->willReturn($this->storeMock); $this->customerRegistryMock->expects($this->once())->method('retrieveSecureData')->with($customerId)->willReturn($this->customerSecureMock); $this->dataProcessorMock->expects($this->once())->method('buildOutputDataArray')->with($customer, \Magento\Customer\Api\Data\CustomerInterface::class)->willReturn($customerData); $this->customerViewHelperMock->expects($this->any())->method('getCustomerName')->with($customer)->willReturn($customerName); $this->customerSecureMock->expects($this->once())->method('addData')->with($customerData)->willReturnSelf(); $this->customerSecureMock->expects($this->once())->method('setData')->with('name', $customerName)->willReturnSelf(); $this->scopeConfigMock->expects($this->at(0))->method('getValue')->with(EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, $customerStoreId)->willReturn($templateIdentifier); $this->scopeConfigMock->expects($this->at(1))->method('getValue')->with(EmailNotification::XML_PATH_REGISTER_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, $customerStoreId)->willReturn($sender); $transport = $this->getMock(\Magento\Framework\Mail\TransportInterface::class, [], [], '', false); $this->transportBuilderMock->expects($this->once())->method('setTemplateIdentifier')->with($templateIdentifier)->willReturnSelf(); $this->transportBuilderMock->expects($this->once())->method('setTemplateOptions')->with(['area' => Area::AREA_FRONTEND, 'store' => $customerStoreId])->willReturnSelf(); $this->transportBuilderMock->expects($this->once())->method('setTemplateVars')->with(['customer' => $this->customerSecureMock, 'back_url' => '', 'store' => $this->storeMock])->willReturnSelf(); $this->transportBuilderMock->expects($this->once())->method('setFrom')->with($sender)->willReturnSelf(); $this->transportBuilderMock->expects($this->once())->method('addTo')->with($customerEmail, $customerName)->willReturnSelf(); $this->transportBuilderMock->expects($this->once())->method('getTransport')->willReturn($transport); $transport->expects($this->once())->method('sendMessage'); $this->model->newAccount($customer, EmailNotification::NEW_ACCOUNT_EMAIL_REGISTERED, '', $customerStoreId); }
/** * @param $email * @param $templateIdentifier * @param $sender * @param $storeId * @param $customerName */ protected function prepareEmailSend($email, $templateIdentifier, $sender, $storeId, $customerName) { $transport = $this->getMockBuilder('Magento\\Framework\\Mail\\TransportInterface')->getMock(); $this->transportBuilder->expects($this->any())->method('setTemplateIdentifier')->with($templateIdentifier)->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('setTemplateOptions')->with(['area' => Area::AREA_FRONTEND, 'store' => $storeId])->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('setTemplateVars')->with(['customer' => $this->customerSecure, 'store' => $this->store])->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('setFrom')->with($sender)->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('addTo')->with($email, $customerName)->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('getTransport')->willReturn($transport); $transport->expects($this->any())->method('sendMessage'); }
/** * @return void */ public function testSendPasswordResetConfirmationEmail() { $storeId = 0; $email = '*****@*****.**'; $firstName = 'Foo'; $lastName = 'Bar'; $this->model->setEmail($email); $this->model->setFirstname($firstName); $this->model->setLastname($lastName); $this->configMock->expects($this->at(0)) ->method('getValue') ->with(\Magento\User\Model\User::XML_PATH_FORGOT_EMAIL_TEMPLATE) ->willReturn('templateId'); $this->configMock->expects($this->at(1)) ->method('getValue') ->with(\Magento\User\Model\User::XML_PATH_FORGOT_EMAIL_IDENTITY) ->willReturn('sender'); $this->transportBuilderMock->expects($this->once()) ->method('setTemplateModel') ->with($this->equalTo('Magento\Email\Model\BackendTemplate')) ->willReturnSelf(); $this->transportBuilderMock->expects($this->once()) ->method('setTemplateOptions') ->willReturnSelf(); $this->transportBuilderMock->expects($this->once()) ->method('setTemplateVars') ->with(['user' => $this->model, 'store' => $this->storetMock]) ->willReturnSelf(); $this->transportBuilderMock->expects($this->once()) ->method('addTo') ->with($this->equalTo($email), $this->equalTo($firstName . ' ' . $lastName)) ->willReturnSelf(); $this->transportBuilderMock->expects($this->once()) ->method('setFrom') ->with('sender') ->willReturnSelf(); $this->transportBuilderMock->expects($this->once()) ->method('setTemplateIdentifier') ->with('templateId') ->willReturnSelf(); $this->transportBuilderMock->expects($this->once()) ->method('getTransport') ->willReturn($this->transportMock); $this->transportMock->expects($this->once())->method('sendMessage'); $this->storeManagerMock->expects($this->once()) ->method('getStore') ->with($storeId) ->willReturn($this->storetMock); $this->assertInstanceOf('\Magento\User\Model\User', $this->model->sendPasswordResetConfirmationEmail()); }
/** * @param int $testNumber * @param string $oldEmail * @param string $newEmail * @param bool $isPasswordChanged * * @dataProvider sendNotificationEmailsDataProvider * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testSendNotificationEmailsIfRequired($testNumber, $oldEmail, $newEmail, $isPasswordChanged) { $customerId = 1; $customerStoreId = 2; $customerWebsiteId = 1; $customerData = ['key' => 'value']; $customerName = 'Customer Name'; $templateIdentifier = 'Template Identifier'; $sender = 'Sender'; switch ($testNumber) { case 1: $xmlPathTemplate = EmailNotification::XML_PATH_RESET_PASSWORD_TEMPLATE; $expects = $this->once(); break; case 2: $xmlPathTemplate = EmailNotification::XML_PATH_CHANGE_EMAIL_TEMPLATE; $expects = $this->exactly(2); break; case 3: $xmlPathTemplate = EmailNotification::XML_PATH_CHANGE_EMAIL_AND_PASSWORD_TEMPLATE; $expects = $this->exactly(2); break; } $origCustomer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock(); $origCustomer->expects($this->any())->method('getStoreId')->willReturn(0); $origCustomer->expects($this->any())->method('getId')->willReturn($customerId); $origCustomer->expects($this->any())->method('getWebsiteId')->willReturn($customerWebsiteId); $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $storeMock->expects($this->any())->method('getId')->willReturn($customerStoreId); $this->storeManagerMock->expects(clone $expects)->method('getStore')->willReturn($storeMock); $websiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->setMethods(['getStoreIds'])->getMock(); $websiteMock->expects($this->any())->method('getStoreIds')->willReturn([$customerStoreId]); $this->storeManagerMock->expects(clone $expects)->method('getWebsite')->with($customerWebsiteId)->willReturn($websiteMock); $customerSecureMock = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->disableOriginalConstructor()->getMock(); $this->customerRegistryMock->expects(clone $expects)->method('retrieveSecureData')->with($customerId)->willReturn($customerSecureMock); $this->dataProcessorMock->expects(clone $expects)->method('buildOutputDataArray')->with($origCustomer, '\\Magento\\Customer\\Api\\Data\\CustomerInterface')->willReturn($customerData); $this->customerViewHelperMock->expects($this->any())->method('getCustomerName')->with($origCustomer)->willReturn($customerName); $customerSecureMock->expects(clone $expects)->method('addData')->with($customerData)->willReturnSelf(); $customerSecureMock->expects(clone $expects)->method('setData')->with('name', $customerName)->willReturnSelf(); $savedCustomer = clone $origCustomer; $origCustomer->expects($this->any())->method('getEmail')->willReturn($oldEmail); $savedCustomer->expects($this->any())->method('getEmail')->willReturn($newEmail); $this->scopeConfigMock->expects($this->any())->method('getValue')->withConsecutive([$xmlPathTemplate, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $customerStoreId], [\Magento\Customer\Helper\EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $customerStoreId], [$xmlPathTemplate, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $customerStoreId], [\Magento\Customer\Helper\EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $customerStoreId])->willReturnOnConsecutiveCalls($templateIdentifier, $sender, $templateIdentifier, $sender); $this->transportBuilderMock->expects(clone $expects)->method('setTemplateIdentifier')->with($templateIdentifier)->willReturnSelf(); $this->transportBuilderMock->expects(clone $expects)->method('setTemplateOptions')->with(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $customerStoreId])->willReturnSelf(); $this->transportBuilderMock->expects(clone $expects)->method('setTemplateVars')->with(['customer' => $customerSecureMock, 'store' => $storeMock])->willReturnSelf(); $this->transportBuilderMock->expects(clone $expects)->method('setFrom')->with($sender)->willReturnSelf(); $this->transportBuilderMock->expects(clone $expects)->method('addTo')->withConsecutive([$oldEmail, $customerName], [$newEmail, $customerName])->willReturnSelf(); $transport = $this->getMockBuilder('Magento\\Framework\\Mail\\TransportInterface')->getMock(); $this->transportBuilderMock->expects(clone $expects)->method('getTransport')->willReturn($transport); $transport->expects(clone $expects)->method('sendMessage'); $this->assertEquals($this->helper, $this->helper->sendNotificationEmailsIfRequired($origCustomer, $savedCustomer, $isPasswordChanged)); }
public function testExecuteValidPost() { $post = ['name' => 'Name', 'comment' => 'Comment', 'email' => '*****@*****.**', 'hideit' => null]; $this->_request->expects($this->any())->method('getPostValue')->will($this->returnValue($post)); $transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface', [], [], '', false); $this->_transportBuilder->expects($this->once())->method('setTemplateIdentifier')->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('setTemplateOptions')->with(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('setTemplateVars')->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('setFrom')->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('addTo')->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('setReplyTo')->with($post['email'])->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('getTransport')->will($this->returnValue($transport)); $transport->expects($this->once())->method('sendMessage'); $this->_inlineTranslation->expects($this->once())->method('resume'); $this->_inlineTranslation->expects($this->once())->method('suspend'); $this->_controller->execute(); }
protected function sendEmailCheck() { $storeModel = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['getId'])->getMock(); $transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface'); $this->scopeConfig->expects($this->any())->method('getValue')->willReturn(true); $this->transportBuilder->expects($this->once())->method('setTemplateIdentifier')->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('setTemplateOptions')->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('setTemplateVars')->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('setFrom')->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('addTo')->willReturnSelf(); $this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel); $storeModel->expects($this->any())->method('getId')->willReturn(1); $this->transportBuilder->expects($this->once())->method('getTransport')->willReturn($transport); $transport->expects($this->once())->method('sendMessage')->willReturnSelf(); $this->inlineTranslation->expects($this->once())->method('suspend')->willReturnSelf(); $this->inlineTranslation->expects($this->once())->method('resume')->willReturnSelf(); return $this; }
public function testSendNewAccountEmailWithoutStoreId() { $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); $website = $this->getMock('Magento\\Store\\Model\\Website', [], [], '', false); $website->expects($this->once())->method('getStoreIds')->will($this->returnValue([1, 2, 3, 4])); $this->_storeManager->expects($this->once())->method('getWebsite')->with(1)->will($this->returnValue($website)); $this->_storeManager->expects($this->once())->method('getStore')->with(1)->will($this->returnValue($store)); $this->_config->expects($this->exactly(3))->method('getAttribute')->will($this->returnValue($this->_attribute)); $this->_attribute->expects($this->exactly(3))->method('getIsVisible')->will($this->returnValue(true)); $methods = ['setTemplateIdentifier', 'setTemplateOptions', 'setTemplateVars', 'setFrom', 'addTo']; foreach ($methods as $method) { $this->_transportBuilderMock->expects($this->once())->method($method)->will($this->returnSelf()); } $transportMock = $this->getMock('Magento\\Framework\\Mail\\TransportInterface', [], [], '', false); $transportMock->expects($this->once())->method('sendMessage')->will($this->returnSelf()); $this->_transportBuilderMock->expects($this->once())->method('getTransport')->will($this->returnValue($transportMock)); $this->_model->setData(['website_id' => 1, 'store_id' => 1, 'email' => '*****@*****.**', 'firstname' => 'FirstName', 'lastname' => 'LastName', 'middlename' => 'MiddleName', 'prefix' => 'Prefix']); $this->_model->sendNewAccountEmail('registered'); }
public function testExecuteValidPost() { $post = ['name' => 'Name', 'comment' => 'Comment', 'email' => '*****@*****.**', 'hideit' => null]; $this->_request->expects($this->any())->method('getPost')->will($this->returnValue($post)); $store = $this->getMock('\\Magento\\Store\\Model\\Store', ['getId', '__sleep', '__wakeup'], [], '', false); $store->expects($this->once())->method('getId')->will($this->returnValue(1)); $this->_storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store)); $transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface', [], [], '', false); $this->_transportBuilder->expects($this->once())->method('setTemplateIdentifier')->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('setTemplateOptions')->with(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => 1])->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('setTemplateVars')->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('setFrom')->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('addTo')->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('setReplyTo')->with($post['email'])->will($this->returnSelf()); $this->_transportBuilder->expects($this->once())->method('getTransport')->will($this->returnValue($transport)); $transport->expects($this->once())->method('sendMessage'); $this->_inlineTranslation->expects($this->once())->method('resume'); $this->_inlineTranslation->expects($this->once())->method('suspend'); $this->_controller->execute(); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testSendPasswordReminderEmail() { $customerId = 1; $customerStoreId = 2; $customerEmail = '*****@*****.**'; $passwordToken = 'token'; $isFrontendSecure = true; $resetUrl = 'reset url'; $customerData = ['key' => 'value']; $customerName = 'Customer Name'; $templateIdentifier = 'Template Identifier'; $sender = 'Sender'; $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock(); $customer->expects($this->any())->method('getStoreId')->willReturn($customerStoreId); $customer->expects($this->any())->method('getId')->willReturn($customerId); $customer->expects($this->any())->method('getEmail')->willReturn($customerEmail); $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->storeManager->expects($this->any())->method('getStore')->with($customerStoreId)->willReturn($store); $store->expects($this->any())->method('isFrontUrlSecure')->willReturn($isFrontendSecure); $this->url->expects($this->once())->method('getUrl')->with('customer/account/createPassword', ['_query' => ['id' => $customerId, 'token' => $passwordToken], '_store' => $customerStoreId, '_secure' => $isFrontendSecure])->willReturn($resetUrl); $customerSecure = $this->getMockBuilder('\\Magento\\Customer\\Model\\Data\\CustomerSecure')->disableOriginalConstructor()->setMethods(['addData', 'setData', 'setResetPasswordUrl'])->getMock(); $this->customerRegistry->expects($this->once())->method('retrieveSecureData')->with($customerId)->willReturn($customerSecure); $this->dataObjectProcessor->expects($this->once())->method('buildOutputDataArray')->with($customer, '\\Magento\\Customer\\Api\\Data\\CustomerInterface')->willReturn($customerData); $this->customerViewHelper->expects($this->any())->method('getCustomerName')->with($customer)->willReturn($customerName); $customerSecure->expects($this->once())->method('addData')->with($customerData)->willReturnSelf(); $customerSecure->expects($this->once())->method('setData')->with('name', $customerName)->willReturnSelf(); $customerSecure->expects($this->once())->method('setResetPasswordUrl')->with($resetUrl); $this->scopeConfig->expects($this->at(0))->method('getValue')->with(AccountManagement::XML_PATH_REMIND_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, $customerStoreId)->willReturn($templateIdentifier); $this->scopeConfig->expects($this->at(1))->method('getValue')->with(AccountManagement::XML_PATH_FORGOT_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, $customerStoreId)->willReturn($sender); $transport = $this->getMockBuilder('Magento\\Framework\\Mail\\TransportInterface')->getMock(); $this->transportBuilder->expects($this->once())->method('setTemplateIdentifier')->with($templateIdentifier)->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('setTemplateOptions')->with(['area' => Area::AREA_FRONTEND, 'store' => $customerStoreId])->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('setTemplateVars')->with(['customer' => $customerSecure, 'store' => $store])->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('setFrom')->with($sender)->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('addTo')->with($customerEmail, $customerName)->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('getTransport')->willReturn($transport); $transport->expects($this->once())->method('sendMessage'); $this->assertEquals($this->accountManagement, $this->accountManagement->sendPasswordReminderEmail($customer, $passwordToken)); }