|
20 | 20 | use Magento\Framework\Message\MessageInterface;
|
21 | 21 | use Magento\Framework\Serialize\Serializer\Json;
|
22 | 22 | use Magento\Framework\Stdlib\CookieManagerInterface;
|
| 23 | +use Magento\Store\Model\StoreManager; |
| 24 | +use Magento\Store\Model\StoreManagerInterface; |
23 | 25 | use Magento\TestFramework\Helper\Bootstrap;
|
24 | 26 | use Magento\TestFramework\Mail\Template\TransportBuilderMock;
|
25 | 27 | use Magento\TestFramework\Request;
|
26 | 28 | use Magento\TestFramework\Response;
|
27 | 29 | use Magento\Theme\Controller\Result\MessagePlugin;
|
| 30 | +use PHPUnit\Framework\Constraint\StringContains; |
28 | 31 | use Zend\Stdlib\Parameters;
|
29 | 32 |
|
30 | 33 | /**
|
@@ -744,6 +747,63 @@ public function testLoginPostRedirect($redirectDashboard, string $redirectUrl)
|
744 | 747 | $this->assertTrue($this->_objectManager->get(Session::class)->isLoggedIn());
|
745 | 748 | }
|
746 | 749 |
|
| 750 | + /** |
| 751 | + * Register Customer with email confirmation. |
| 752 | + * |
| 753 | + * @magentoDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php |
| 754 | + * @return void |
| 755 | + */ |
| 756 | + public function testRegisterCustomerWithEmailConfirmation(): void |
| 757 | + { |
| 758 | + $email = 'test_example@email.com'; |
| 759 | + $this->fillRequestWithAccountDataAndFormKey($email); |
| 760 | + $this->dispatch('customer/account/createPost'); |
| 761 | + $this->assertRedirect($this->stringContains('customer/account/index/')); |
| 762 | + $this->assertSessionMessages( |
| 763 | + $this->equalTo( |
| 764 | + [ |
| 765 | + 'You must confirm your account. Please check your email for the confirmation link or ' |
| 766 | + . '<a href="http://localhost/index.php/customer/account/confirmation/' |
| 767 | + . '?email=test_example%40email.com">click here</a> for a new link.' |
| 768 | + ] |
| 769 | + ), |
| 770 | + MessageInterface::TYPE_SUCCESS |
| 771 | + ); |
| 772 | + /** @var CustomerRepositoryInterface $customerRepository */ |
| 773 | + $customerRepository = $this->_objectManager->create(CustomerRepositoryInterface::class); |
| 774 | + /** @var CustomerInterface $customer */ |
| 775 | + $customer = $customerRepository->get($email); |
| 776 | + $confirmation = $customer->getConfirmation(); |
| 777 | + $message = $this->transportBuilderMock->getSentMessage(); |
| 778 | + $rawMessage = $message->getBody()->getParts()[0]->getRawContent(); |
| 779 | + $messageConstraint = $this->logicalAnd( |
| 780 | + new StringContains("You must confirm your {$email} email before you can sign in (link is only valid once"), |
| 781 | + new StringContains("customer/account/confirm/?id={$customer->getId()}&key={$confirmation}") |
| 782 | + ); |
| 783 | + $this->assertThat($rawMessage, $messageConstraint); |
| 784 | + |
| 785 | + /** @var CookieManagerInterface $cookieManager */ |
| 786 | + $cookieManager = $this->_objectManager->get(CookieManagerInterface::class); |
| 787 | + $cookieManager->deleteCookie(MessagePlugin::MESSAGES_COOKIES_NAME); |
| 788 | + $this->_objectManager->removeSharedInstance(Http::class); |
| 789 | + $this->_objectManager->removeSharedInstance(Request::class); |
| 790 | + $this->_request = null; |
| 791 | + |
| 792 | + $this->getRequest()->setParam('id', $customer->getId()); |
| 793 | + $this->getRequest()->setParam('key', $confirmation); |
| 794 | + $this->dispatch('customer/account/confirm'); |
| 795 | + |
| 796 | + /** @var StoreManager $store */ |
| 797 | + $store = $this->_objectManager->get(StoreManagerInterface::class); |
| 798 | + $name = $store->getStore()->getFrontendName(); |
| 799 | + |
| 800 | + $this->assertRedirect($this->stringContains('customer/account/index/')); |
| 801 | + $this->assertSessionMessages( |
| 802 | + $this->equalTo(["Thank you for registering with {$name}."]), |
| 803 | + MessageInterface::TYPE_SUCCESS |
| 804 | + ); |
| 805 | + } |
| 806 | + |
747 | 807 | /**
|
748 | 808 | * Test that confirmation email address displays special characters correctly.
|
749 | 809 | *
|
|
0 commit comments