/** * @magentoConfigFixture current_store persistent/options/enabled 1 * @magentoConfigFixture current_store persistent/options/remember_enabled 1 * @magentoConfigFixture current_store persistent/options/remember_default 1 * @magentoAppArea frontend * @magentoAppIsolation enabled */ public function testEmulateWelcomeBlock() { $this->_customerSession->loginById(1); $httpContext = new \Magento\Framework\App\Http\Context(); $httpContext->setValue(Context::CONTEXT_AUTH, 1, 1); $block = $this->_objectManager->create('Magento\\Sales\\Block\\Reorder\\Sidebar', ['httpContext' => $httpContext]); $this->_observer->emulateWelcomeBlock($block); $customerName = $this->_escaper->escapeHtml($this->_customerViewHelper->getCustomerName($this->customerRepository->getById($this->_persistentSessionHelper->getSession()->getCustomerId()))); $translation = __('Welcome, %1!', $customerName); $this->assertStringMatchesFormat('%A' . $translation . '%A', $block->getWelcome()); $this->_customerSession->logout(); }
public function testGetUserName() { $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(true); $customerDataObject = $this->getMockBuilder('\\Magento\\Customer\\Model\\Data\\Customer')->disableOriginalConstructor()->getMock(); $this->customerSessionMock->expects($this->once())->method('getCustomerDataObject')->willReturn($customerDataObject); $this->customerViewHelperMock->expects($this->once())->method('getCustomerName')->willReturn(' customer name '); $this->assertEquals('customer name', $this->helper->getUserName()); }
/** * Emulate 'welcome' block with persistent data * * @param \Magento\Framework\View\Element\AbstractBlock $block * @return $this */ public function emulateWelcomeBlock($block) { $escapedName = $this->_escaper->escapeHtml($this->_customerViewHelper->getCustomerName($this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId())), null); $this->_applyAccountLinksPersistentData(); $welcomeMessage = __('Welcome, %1!', $escapedName) . ' ' . $this->_layout->getBlock('header.additional')->toHtml(); $block->setWelcome($welcomeMessage); return $this; }
/** * @param \Magento\Customer\Api\Data\CustomerInterface $customerData * @param string $expectedCustomerName * @param bool $isPrefixAllowed * @param bool $isMiddleNameAllowed * @param bool $isSuffixAllowed * @dataProvider getCustomerNameDataProvider */ public function testGetCustomerName($customerData, $expectedCustomerName, $isPrefixAllowed = false, $isMiddleNameAllowed = false, $isSuffixAllowed = false) { $visibleAttribute = $this->getMock('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface'); $visibleAttribute->expects($this->any())->method('isVisible')->will($this->returnValue(true)); $invisibleAttribute = $this->getMock('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface'); $invisibleAttribute->expects($this->any())->method('isVisible')->will($this->returnValue(false)); $this->_customerMetadataService->expects($this->any())->method('getAttributeMetadata')->will($this->returnValueMap([['prefix', $isPrefixAllowed ? $visibleAttribute : $invisibleAttribute], ['middlename', $isMiddleNameAllowed ? $visibleAttribute : $invisibleAttribute], ['suffix', $isSuffixAllowed ? $visibleAttribute : $invisibleAttribute]])); $this->assertEquals($expectedCustomerName, $this->_helper->getCustomerName($customerData), 'Full customer name is invalid'); }
public function testGetUserName() { $this->_customerSession->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true)); $objectBuilder = $this->getMockForAbstractClass('\\Magento\\Framework\\Service\\Data\\AbstractSimpleObjectBuilder', ['getData'], '', false); $customerDataObject = new \Magento\Customer\Service\V1\Data\Customer($objectBuilder); $this->_customerSession->expects($this->once())->method('getCustomerDataObject')->will($this->returnValue($customerDataObject)); $this->_customerViewHelper->expects($this->once())->method('getCustomerName')->will($this->returnValue(' customer name ')); $this->assertEquals('customer name', $this->_helper->getUserName()); }
/** * Return the full name of the customer currently logged in * * @return string|null */ public function getCustomerName() { try { $customer = $this->customerRepository->getById($this->currentCustomer->getCustomerId()); return $this->escapeHtml($this->_viewHelper->getCustomerName($customer)); } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { return null; } }
/** * @dataProvider getCustomerServiceDataProvider */ public function testGetCustomerName($prefix, $firstName, $middleName, $lastName, $suffix, $result) { $customerData = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock(); $customerData->expects($this->any())->method('getPrefix')->will($this->returnValue($prefix)); $customerData->expects($this->any())->method('getFirstname')->will($this->returnValue($firstName)); $customerData->expects($this->any())->method('getMiddlename')->will($this->returnValue($middleName)); $customerData->expects($this->any())->method('getLastname')->will($this->returnValue($lastName)); $customerData->expects($this->any())->method('getSuffix')->will($this->returnValue($suffix)); $this->assertEquals($result, $this->object->getCustomerName($customerData)); }
/** * @magentoConfigFixture current_store catalog/productalert/allow_price 1 * * @magentoDataFixture Magento/ProductAlert/_files/product_alert.php */ public function testProcess() { $this->_objectManager->configure(['Magento\\ProductAlert\\Model\\Observer' => ['arguments' => ['transportBuilder' => ['instance' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]], 'Magento\\ProductAlert\\Model\\Email' => ['arguments' => ['transportBuilder' => ['instance' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]], 'preferences' => ['Magento\\Framework\\Mail\\TransportInterface' => 'Magento\\TestFramework\\Mail\\TransportInterfaceMock', 'Magento\\TestFramework\\Mail\\Template\\TransportBuilder' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]); \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND); $observer = $this->_objectManager->get('Magento\\ProductAlert\\Model\\Observer'); $observer->process(); /** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */ $transportBuilder = $this->_objectManager->get('Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock'); $this->assertStringMatchesFormat('%AHello %A' . $this->_customerViewHelper->getCustomerName($this->_customerSession->getCustomerDataObject()) . ',%A', $transportBuilder->getSentMessage()->getBodyHtml()->getContent()); }
/** * Get user name * * @return string */ public function getUserName() { if (!$this->_customerSession->isLoggedIn()) { return ''; } /** * @var \Magento\Customer\Api\Data\CustomerInterface $customer */ $customer = $this->_customerSession->getCustomerDataObject(); return trim($this->_customerViewHelper->getCustomerName($customer)); }
/** * Retrieve welcome text * * @return string */ public function getWelcome() { if (empty($this->_data['welcome'])) { if ($this->httpContext->getValue(Context::CONTEXT_AUTH)) { $customerName = $this->_customerViewHelper->getCustomerName($this->_customerSession->getCustomerDataObject()); $this->_data['welcome'] = __('Welcome, %1!', $this->escapeHtml($customerName)); } else { $this->_data['welcome'] = $this->_scopeConfig->getValue('design/header/welcome', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); } } return $this->_data['welcome']; }
public function testConstruct() { $this->customerRepository = $this->getMockForAbstractClass('Magento\\Customer\\Api\\CustomerRepositoryInterface'); $this->customerViewHelper = $this->getMock('Magento\\Customer\\Helper\\View', [], [], '', false); $dummyCustomer = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface'); $this->customerRepository->expects($this->once())->method('getById')->with('customer id')->will($this->returnValue($dummyCustomer)); $this->customerViewHelper->expects($this->once())->method('getCustomerName')->with($dummyCustomer)->will($this->returnValue(new \Magento\Framework\Object())); $this->request = $this->getMockForAbstractClass('Magento\\Framework\\App\\RequestInterface'); $this->request->expects($this->at(0))->method('getParam')->with('customerId', false)->will($this->returnValue('customer id')); $this->request->expects($this->at(1))->method('getParam')->with('productId', false)->will($this->returnValue(false)); $objectManagerHelper = new ObjectManagerHelper($this); $this->model = $objectManagerHelper->getObject('Magento\\Review\\Block\\Adminhtml\\Main', ['request' => $this->request, 'customerRepository' => $this->customerRepository, 'customerViewHelper' => $this->customerViewHelper]); }
/** * Retrieve username for form field * * @return string */ public function getUserName() { $name = $this->getFormData()->getData('sender/name'); if (!empty($name)) { return trim($name); } /* @var $session \Magento\Customer\Model\Session */ $session = $this->_customerSession; if ($this->httpContext->getValue(Context::CONTEXT_AUTH)) { return $this->_customerViewHelper->getCustomerName($session->getCustomerDataObject()); } return ''; }
/** * @param string $email * @param string $templateIdentifier * @param string $sender * @param int $storeId * @param int $customerId * @param string $hash */ protected function prepareInitiatePasswordReset($email, $templateIdentifier, $sender, $storeId, $customerId, $hash) { $websiteId = 1; $dateTime = date(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT); $customerData = ['key' => 'value']; $customerName = 'Customer Name'; $this->store->expects($this->once())->method('getWebsiteId')->willReturn($websiteId); $this->store->expects($this->any())->method('getId')->willReturn($storeId); $this->storeManager->expects($this->any())->method('getStore')->willReturn($this->store); $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock(); $customer->expects($this->any())->method('getEmail')->willReturn($email); $customer->expects($this->any())->method('getId')->willReturn($customerId); $customer->expects($this->any())->method('getStoreId')->willReturn($storeId); $this->customerRepository->expects($this->once())->method('get')->with($email, $websiteId)->willReturn($customer); $this->customerRepository->expects($this->once())->method('save')->with($customer)->willReturnSelf(); $this->random->expects($this->once())->method('getUniqueHash')->willReturn($hash); $this->customerViewHelper->expects($this->any())->method('getCustomerName')->with($customer)->willReturn($customerName); $this->customerSecure->expects($this->any())->method('setRpToken')->with($hash)->willReturnSelf(); $this->customerSecure->expects($this->any())->method('setRpTokenCreatedAt')->with($dateTime)->willReturnSelf(); $this->customerSecure->expects($this->any())->method('addData')->with($customerData)->willReturnSelf(); $this->customerSecure->expects($this->any())->method('setData')->with('name', $customerName)->willReturnSelf(); $this->customerRegistry->expects($this->any())->method('retrieveSecureData')->with($customerId)->willReturn($this->customerSecure); $this->dataObjectProcessor->expects($this->any())->method('buildOutputDataArray')->with($customer, '\\Magento\\Customer\\Api\\Data\\CustomerInterface')->willReturn($customerData); $this->prepareEmailSend($email, $templateIdentifier, $sender, $storeId, $customerName); }
/** * Load search results * * @return $this */ public function load() { $result = []; if (!$this->hasStart() || !$this->hasLimit() || !$this->hasQuery()) { $this->setResults($result); return $this; } $this->searchCriteriaBuilder->setCurrentPage($this->getStart()); $this->searchCriteriaBuilder->setPageSize($this->getLimit()); $searchFields = ['firstname', 'lastname', 'company']; $filters = []; foreach ($searchFields as $field) { $filters[] = $this->filterBuilder->setField($field)->setConditionType('like')->setValue($this->getQuery() . '%')->create(); } $this->searchCriteriaBuilder->addFilters($filters); $searchCriteria = $this->searchCriteriaBuilder->create(); $searchResults = $this->customerRepository->getList($searchCriteria); foreach ($searchResults->getItems() as $customer) { $customerAddresses = $customer->getAddresses(); /** Look for a company name defined in default billing address */ $company = null; foreach ($customerAddresses as $customerAddress) { if ($customerAddress->getId() == $customer->getDefaultBilling()) { $company = $customerAddress->getCompany(); break; } } $result[] = ['id' => 'customer/1/' . $customer->getId(), 'type' => __('Customer'), 'name' => $this->_customerViewHelper->getCustomerName($customer), 'description' => $company, 'url' => $this->_adminhtmlData->getUrl('customer/index/edit', ['id' => $customer->getId()])]; } $this->setResults($result); return $this; }
/** * @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); }
/** * Retrieve the header text, either the name of an existing customer or 'New Customer'. * * @return string */ public function getHeaderText() { $customerId = $this->getCustomerId(); if ($customerId) { $customerData = $this->_customerAccountService->getCustomer($customerId); return $this->escapeHtml($this->_viewHelper->getCustomerName($customerData)); } else { return __('New Customer'); } }
/** * Create an object with data merged from Customer and CustomerSecure * * @param CustomerInterface $customer * @return \Magento\Customer\Model\Data\CustomerSecure */ private function getFullCustomerObject($customer) { // No need to flatten the custom attributes or nested objects since the only usage is for email templates and // object passed for events $mergedCustomerData = $this->customerRegistry->retrieveSecureData($customer->getId()); $customerData = $this->dataProcessor->buildOutputDataArray($customer, \Magento\Customer\Api\Data\CustomerInterface::class); $mergedCustomerData->addData($customerData); $mergedCustomerData->setData('name', $this->customerViewHelper->getCustomerName($customer)); return $mergedCustomerData; }
/** * Retrieve the header text, either the name of an existing customer or 'New Customer'. * * @return \Magento\Framework\Phrase|string */ public function getHeaderText() { $customerId = $this->getCustomerId(); if ($customerId) { $customerData = $this->customerRepository->getById($customerId); return $this->escapeHtml($this->_viewHelper->getCustomerName($customerData)); } else { return __('New Customer'); } }
/** * Get user name * * @return string */ public function getUserName() { if (!$this->_customerSession->isLoggedIn()) { return ''; } /** * @var Customer $customer */ $customer = $this->_customerSession->getCustomerDataObject(); return trim($this->_customerViewHelper->getCustomerName($customer)); }
/** * @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)); }
/** * @magentoDataFixture Magento/Customer/_files/customer.php * @magentoDataFixture Magento/Catalog/_files/product_simple.php */ public function testSend() { $this->_objectManager->configure(['Magento\\ProductAlert\\Model\\Email' => ['arguments' => ['transportBuilder' => ['instance' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]], 'preferences' => ['Magento\\Framework\\Mail\\TransportInterface' => 'Magento\\TestFramework\\Mail\\TransportInterfaceMock']]); \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND); $this->_emailModel = $this->_objectManager->create('Magento\\ProductAlert\\Model\\Email'); /** @var \Magento\Store\Model\Website $website */ $website = $this->_objectManager->create('Magento\\Store\\Model\\Website'); $website->load(1); $this->_emailModel->setWebsite($website); /** @var \Magento\Customer\Service\V1\Data\Customer $customer */ $customer = $this->_customerAccountService->getCustomer(1); $this->_emailModel->setCustomerData($customer); /** @var \Magento\Catalog\Model\Product $product */ $product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product'); $product->load(1); $this->_emailModel->addPriceProduct($product); $this->_emailModel->send(); /** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */ $transportBuilder = $this->_objectManager->get('Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock'); $this->assertStringMatchesFormat('%AHello ' . $this->_customerViewHelper->getCustomerName($customer) . '%A', $transportBuilder->getSentMessage()->getBodyHtml()->getContent()); }
/** * @magentoDataFixture Magento/Wishlist/_files/wishlist.php */ public function testSendAction() { \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND); $request = ['form_key' => $this->_objectManager->get('Magento\\Framework\\Data\\Form\\FormKey')->getFormKey(), 'emails' => '*****@*****.**', 'message' => 'message', 'rss_url' => null]; $this->getRequest()->setPostValue($request); $this->_objectManager->get('Magento\\Framework\\Registry')->register('wishlist', $this->_objectManager->get('Magento\\Wishlist\\Model\\Wishlist')->loadByCustomerId(1)); $this->dispatch('wishlist/index/send'); /** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */ $transportBuilder = $this->_objectManager->get('Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock'); $actualResult = \Zend_Mime_Decode::decodeQuotedPrintable($transportBuilder->getSentMessage()->getBodyHtml()->getContent()); $this->assertStringMatchesFormat('%A' . $this->_customerViewHelper->getCustomerName($this->_customerSession->getCustomerDataObject()) . ' wants to share this Wish List%A', $actualResult); }
/** * @magentoDataFixture Magento/Wishlist/_files/wishlist.php */ public function testSendAction() { $this->_objectManager->configure(['Magento\\Wishlist\\Controller\\Index\\Send' => ['arguments' => ['transportBuilder' => ['instance' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]], 'preferences' => ['Magento\\Framework\\Mail\\TransportInterface' => 'Magento\\TestFramework\\Mail\\TransportInterfaceMock']]); \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND); $request = ['form_key' => $this->_objectManager->get('Magento\\Framework\\Data\\Form\\FormKey')->getFormKey(), 'emails' => '*****@*****.**', 'message' => 'message', 'rss_url' => null]; $this->getRequest()->setPost($request); $this->_objectManager->get('Magento\\Framework\\Registry')->register('wishlist', $this->_objectManager->get('Magento\\Wishlist\\Model\\Wishlist')->loadByCustomerId(1)); $this->dispatch('wishlist/index/send'); /** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */ $transportBuilder = $this->_objectManager->get('Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock'); $this->assertStringMatchesFormat('%AThank you, %A' . $this->_customerViewHelper->getCustomerName($this->_customerSession->getCustomerDataObject()) . '%A', $transportBuilder->getSentMessage()->getBodyHtml()->getContent()); }
/** * Initialize add new review * * @return void */ protected function _construct() { $this->_addButtonLabel = __('New Review'); parent::_construct(); $this->_blockGroup = 'Magento_Review'; $this->_controller = 'adminhtml'; // lookup customer, if id is specified $customerId = $this->getRequest()->getParam('customerId', false); $customerName = ''; if ($customerId) { $customer = $this->customerRepository->getById($customerId); $customerName = $this->escapeHtml($this->_customerViewHelper->getCustomerName($customer)); } $productId = $this->getRequest()->getParam('productId', false); $productName = null; if ($productId) { $product = $this->_productFactory->create()->load($productId); $productName = $this->escapeHtml($product->getName()); } if ($this->_coreRegistry->registry('usePendingFilter') === true) { if ($customerName) { $this->_headerText = __('Pending Reviews of Customer `%1`', $customerName); } else { $this->_headerText = __('Pending Reviews'); } $this->buttonList->remove('add'); } else { if ($customerName) { $this->_headerText = __('All Reviews of Customer `%1`', $customerName); } elseif ($productName) { $this->_headerText = __('All Reviews of Product `%1`', $productName); } else { $this->_headerText = __('All Reviews'); } } }
/** * Retrieve default value for giftmessage sender * * @return string */ public function getDefaultSender() { if (!$this->getEntity()) { return ''; } if ($this->_getSession()->hasCustomerId() && $this->_getSession()->getCustomerId()) { $customerData = $this->_customerService->getCustomer($this->_getSession()->getCustomerId()); return $this->_customerViewHelper->getCustomerName($customerData); } $object = $this->getEntity(); if ($this->getEntity()->getQuote()) { $object = $this->getEntity()->getQuote(); } return $object->getBillingAddress()->getName(); }
/** * Retrieve default value for giftmessage sender * * @return string */ public function getDefaultSender() { if (!$this->getEntity()) { return ''; } if ($this->_getSession()->hasCustomerId() && $this->_getSession()->getCustomerId()) { // TODO to change email on id $customer = $this->customerRepository->getById($this->_getSession()->getCustomerId()); return $this->_customerViewHelper->getCustomerName($customer); } $object = $this->getEntity(); if ($this->getEntity()->getQuote()) { $object = $this->getEntity()->getQuote(); } return $object->getBillingAddress()->getName(); }
/** * Loads customers info to collection * * @return void */ protected function _addCustomersData() { if ($this->_loadCustomersDataFlag) { return; } $this->_loadCustomersDataFlag = true; foreach ($this->getItems() as $item) { if ($item->getCustomerId()) { $customerId = $item->getCustomerId(); try { $customer = $this->customerRepository->getById($customerId); $problems = $this->getItemsByColumnValue('customer_id', $customerId); $customerName = $this->_customerView->getCustomerName($customer); foreach ($problems as $problem) { $problem->setCustomerName($customerName)->setCustomerFirstName($customer->getFirstName())->setCustomerLastName($customer->getLastName()); } } catch (NoSuchEntityException $e) { // do nothing if customer is not found by id } } } }
/** * @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)); }
/** * Retrieve customer name * * @return string|void */ public function getCustomerName() { return $this->getCustomer() ? $this->_customerViewHelper->getCustomerName($this->getCustomer()) : null; }
/** * Share wishlist * * @return \Magento\Framework\Controller\Result\Redirect * @throws NotFoundException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function execute() { /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); if (!$this->_formKeyValidator->validate($this->getRequest())) { $resultRedirect->setPath('*/*/'); return $resultRedirect; } $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { throw new NotFoundException(__('Page not found.')); } $sharingLimit = $this->_wishlistConfig->getSharingEmailLimit(); $textLimit = $this->_wishlistConfig->getSharingTextLimit(); $emailsLeft = $sharingLimit - $wishlist->getShared(); $emails = $this->getRequest()->getPost('emails'); $emails = empty($emails) ? $emails : explode(',', $emails); $error = false; $message = (string) $this->getRequest()->getPost('message'); if (strlen($message) > $textLimit) { $error = __('Message length must not exceed %1 symbols', $textLimit); } else { $message = nl2br(htmlspecialchars($message)); if (empty($emails)) { $error = __('Please enter an email address.'); } else { if (count($emails) > $emailsLeft) { $error = __('This wish list can be shared %1 more times.', $emailsLeft); } else { foreach ($emails as $index => $email) { $email = trim($email); if (!\Zend_Validate::is($email, 'EmailAddress')) { $error = __('Please input a valid email address.'); break; } $emails[$index] = $email; } } } } if ($error) { $this->messageManager->addError($error); $this->wishlistSession->setSharingForm($this->getRequest()->getPostValue()); $resultRedirect->setPath('*/*/share'); return $resultRedirect; } /** @var \Magento\Framework\View\Result\Layout $resultLayout */ $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT); $this->addLayoutHandles($resultLayout); $this->inlineTranslation->suspend(); $sent = 0; try { $customer = $this->_customerSession->getCustomerDataObject(); $customerName = $this->_customerHelperView->getCustomerName($customer); $message .= $this->getRssLink($wishlist->getId(), $resultLayout); $emails = array_unique($emails); $sharingCode = $wishlist->getSharingCode(); try { foreach ($emails as $email) { $transport = $this->_transportBuilder->setTemplateIdentifier($this->scopeConfig->getValue('wishlist/email/email_template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $this->storeManager->getStore()->getStoreId()])->setTemplateVars(['customer' => $customer, 'customerName' => $customerName, 'salable' => $wishlist->isSalable() ? 'yes' : '', 'items' => $this->getWishlistItems($resultLayout), 'viewOnSiteLink' => $this->_url->getUrl('*/shared/index', ['code' => $sharingCode]), 'message' => $message, 'store' => $this->storeManager->getStore()])->setFrom($this->scopeConfig->getValue('wishlist/email/email_identity', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($email)->getTransport(); $transport->sendMessage(); $sent++; } } catch (\Exception $e) { $wishlist->setShared($wishlist->getShared() + $sent); $wishlist->save(); throw $e; } $wishlist->setShared($wishlist->getShared() + $sent); $wishlist->save(); $this->inlineTranslation->resume(); $this->_eventManager->dispatch('wishlist_share', ['wishlist' => $wishlist]); $this->messageManager->addSuccess(__('Your wish list has been shared.')); $resultRedirect->setPath('*/*', ['wishlist_id' => $wishlist->getId()]); return $resultRedirect; } catch (\Exception $e) { $this->inlineTranslation->resume(); $this->messageManager->addError($e->getMessage()); $this->wishlistSession->setSharingForm($this->getRequest()->getPostValue()); $resultRedirect->setPath('*/*/share'); return $resultRedirect; } }