Skip to content

Commit d764163

Browse files
committed
MAGETWO-97195: Automate with Integration test Confirmation email should be delivered to the customer when address contains '+' symbol
1 parent 6b109f4 commit d764163

7 files changed

+275
-57
lines changed

dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php

Lines changed: 104 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,35 @@
2323
use Magento\TestFramework\Helper\Bootstrap;
2424
use Magento\TestFramework\Request;
2525
use Magento\TestFramework\Response;
26+
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
27+
use Magento\Framework\App\Config\MutableScopeConfigInterface;
28+
use Magento\Framework\Serialize\Serializer\Json;
29+
use Magento\Framework\Stdlib\CookieManagerInterface;
30+
use Magento\Theme\Controller\Result\MessagePlugin;
2631
use Zend\Stdlib\Parameters;
2732

2833
/**
2934
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3035
*/
3136
class AccountTest extends \Magento\TestFramework\TestCase\AbstractController
3237
{
38+
/**
39+
* @var MutableScopeConfigInterface
40+
*/
41+
private $mutableScopeConfig;
42+
43+
/**
44+
* @var TransportBuilderMock
45+
*/
46+
private $transportBuilderMock;
47+
48+
protected function setUp()
49+
{
50+
parent::setUp();
51+
$this->mutableScopeConfig = $this->_objectManager->get(MutableScopeConfigInterface::class);
52+
$this->transportBuilderMock = $this->_objectManager->get(TransportBuilderMock::class);
53+
}
54+
3355
/**
3456
* Login the user
3557
*
@@ -102,11 +124,7 @@ public function testForgotPasswordEmailMessageWithSpecialCharacters()
102124
$this->dispatch('customer/account/forgotPasswordPost');
103125
$this->assertRedirect($this->stringContains('customer/account/'));
104126

105-
/** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */
106-
$transportBuilder = $this->_objectManager->get(
107-
\Magento\TestFramework\Mail\Template\TransportBuilderMock::class
108-
);
109-
$subject = $transportBuilder->getSentMessage()->getSubject();
127+
$subject = $this->transportBuilderMock->getSentMessage()->getSubject();
110128
$this->assertContains(
111129
'Test special\' characters',
112130
$subject
@@ -228,65 +246,26 @@ public function testNoFormKeyCreatePostAction()
228246
/**
229247
* @magentoDbIsolation enabled
230248
* @magentoAppIsolation enabled
249+
* @magentoDataFixture Magento/Customer/_files/customer_confirmation_config_disable.php
231250
*/
232251
public function testNoConfirmCreatePostAction()
233252
{
234-
/** @var \Magento\Framework\App\Config\MutableScopeConfigInterface $mutableScopeConfig */
235-
$mutableScopeConfig = Bootstrap::getObjectManager()
236-
->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class);
237-
238-
$scopeValue = $mutableScopeConfig->getValue(
239-
'customer/create_account/confirm',
240-
ScopeInterface::SCOPE_WEBSITES,
241-
null
242-
);
243-
244-
$mutableScopeConfig->setValue(
245-
'customer/create_account/confirm',
246-
0,
247-
ScopeInterface::SCOPE_WEBSITES,
248-
null
249-
);
250-
251253
$this->fillRequestWithAccountDataAndFormKey();
252254
$this->dispatch('customer/account/createPost');
253255
$this->assertRedirect($this->stringEndsWith('customer/account/'));
254256
$this->assertSessionMessages(
255257
$this->equalTo(['Thank you for registering with Main Website Store.']),
256258
MessageInterface::TYPE_SUCCESS
257259
);
258-
259-
$mutableScopeConfig->setValue(
260-
'customer/create_account/confirm',
261-
$scopeValue,
262-
ScopeInterface::SCOPE_WEBSITES,
263-
null
264-
);
265260
}
266261

267262
/**
268263
* @magentoDbIsolation enabled
269264
* @magentoAppIsolation enabled
265+
* @magentoDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php
270266
*/
271267
public function testWithConfirmCreatePostAction()
272268
{
273-
/** @var \Magento\Framework\App\Config\MutableScopeConfigInterface $mutableScopeConfig */
274-
$mutableScopeConfig = Bootstrap::getObjectManager()
275-
->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class);
276-
277-
$scopeValue = $mutableScopeConfig->getValue(
278-
'customer/create_account/confirm',
279-
ScopeInterface::SCOPE_WEBSITES,
280-
null
281-
);
282-
283-
$mutableScopeConfig->setValue(
284-
'customer/create_account/confirm',
285-
1,
286-
ScopeInterface::SCOPE_WEBSITES,
287-
null
288-
);
289-
290269
$this->fillRequestWithAccountDataAndFormKey();
291270
$this->dispatch('customer/account/createPost');
292271
$this->assertRedirect($this->stringContains('customer/account/index/'));
@@ -298,13 +277,6 @@ public function testWithConfirmCreatePostAction()
298277
]),
299278
MessageInterface::TYPE_SUCCESS
300279
);
301-
302-
$mutableScopeConfig->setValue(
303-
'customer/create_account/confirm',
304-
$scopeValue,
305-
ScopeInterface::SCOPE_WEBSITES,
306-
null
307-
);
308280
}
309281

310282
/**
@@ -690,6 +662,49 @@ public function testLoginPostRedirect($redirectDashboard, string $redirectUrl)
690662
$this->assertTrue($this->_objectManager->get(Session::class)->isLoggedIn());
691663
}
692664

665+
/**
666+
* Test that confirmation email address displays special characters correctly.
667+
*
668+
* @magentoDbIsolation enabled
669+
* @magentoDataFixture Magento/Customer/_files/customer_confirmation_email_address_with_special_chars.php
670+
*
671+
* @return void
672+
*/
673+
public function testConfirmationEmailWithSpecialCharacters()
674+
{
675+
$email = 'customer+confirmation@example.com';
676+
$this->dispatch('customer/account/confirmation/email/customer%2Bconfirmation%40email.com');
677+
$this->getRequest()->setPostValue('email', $email);
678+
$this->dispatch('customer/account/confirmation/email/customer%2Bconfirmation%40email.com');
679+
680+
$this->assertRedirect($this->stringContains('customer/account/index'));
681+
$this->assertSessionMessages(
682+
$this->equalTo(['Please check your email for confirmation key.']),
683+
MessageInterface::TYPE_SUCCESS
684+
);
685+
686+
/** @var $message \Magento\Framework\Mail\Message */
687+
$message = $this->transportBuilderMock->getSentMessage();
688+
$rawMessage = $message->getRawMessage();
689+
690+
$this->assertContains('To: ' . $email, $rawMessage);
691+
692+
$content = $message->getBody()->getPartContent(0);
693+
preg_match('<a\s*href="(?<url>.*?)".*>', $content, $matches);
694+
$confirmationUrl = $matches['url'];
695+
$confirmationUrl = str_replace('http://localhost/index.php/','',$confirmationUrl);
696+
$confirmationUrl = html_entity_decode($confirmationUrl);
697+
$this->setRequestInfo($confirmationUrl, 'confirm');
698+
$this->clearCookieMessagesList();
699+
$this->dispatch($confirmationUrl);
700+
701+
$this->assertRedirect($this->stringContains('customer/account/index'));
702+
$this->assertSessionMessages(
703+
$this->equalTo(['Thank you for registering with Main Website Store.']),
704+
MessageInterface::TYPE_SUCCESS
705+
);
706+
}
707+
693708
/**
694709
* Data provider for testLoginPostRedirect.
695710
*
@@ -705,16 +720,17 @@ public function loginPostRedirectDataProvider()
705720
}
706721

707722
/**
723+
* @param string $email
708724
* @return void
709725
*/
710-
private function fillRequestWithAccountData()
726+
private function fillRequestWithAccountData(string $email = 'test1@email.com')
711727
{
712728
$this->getRequest()
713729
->setMethod('POST')
714730
->setParam('firstname', 'firstname1')
715731
->setParam('lastname', 'lastname1')
716732
->setParam('company', '')
717-
->setParam('email', 'test1@email.com')
733+
->setParam('email', $email)
718734
->setParam('password', '_Password1')
719735
->setParam('password_confirmation', '_Password1')
720736
->setParam('telephone', '5123334444')
@@ -731,11 +747,12 @@ private function fillRequestWithAccountData()
731747
}
732748

733749
/**
750+
* @param string $email
734751
* @return void
735752
*/
736-
private function fillRequestWithAccountDataAndFormKey()
753+
private function fillRequestWithAccountDataAndFormKey(string $email = 'test1@email.com')
737754
{
738-
$this->fillRequestWithAccountData();
755+
$this->fillRequestWithAccountData($email);
739756
$formKey = $this->_objectManager->get(FormKey::class);
740757
$this->getRequest()->setParam('form_key', $formKey->getFormKey());
741758
}
@@ -805,4 +822,34 @@ private function assertResponseRedirect(Response $response, string $redirectUrl)
805822
$this->assertTrue($response->isRedirect());
806823
$this->assertSame($redirectUrl, $response->getHeader('Location')->getUri());
807824
}
825+
826+
/**
827+
* Add new request info (request uri, path info, action name).
828+
*
829+
* @param string $uri
830+
* @param string $actionName
831+
* @return void
832+
*/
833+
private function setRequestInfo(string $uri, string $actionName)
834+
{
835+
$this->getRequest()
836+
->setRequestUri($uri)
837+
->setPathInfo()
838+
->setActionName($actionName);
839+
}
840+
841+
/**
842+
* Clear cookie messages list.
843+
*
844+
* @return void
845+
*/
846+
private function clearCookieMessagesList()
847+
{
848+
$cookieManager = $this->_objectManager->get(CookieManagerInterface::class);
849+
$jsonSerializer = $this->_objectManager->get(Json::class);
850+
$cookieManager->setPublicCookie(
851+
MessagePlugin::MESSAGES_COOKIES_NAME,
852+
$jsonSerializer->serialize([])
853+
);
854+
}
808855
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
use Magento\Store\Model\ScopeInterface;
10+
use Magento\Framework\App\Config\MutableScopeConfigInterface;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
13+
$objectManager = Bootstrap::getObjectManager();
14+
$mutableScopeConfig = $objectManager->create(MutableScopeConfigInterface::class);
15+
16+
$this->confirmationConfigScopeValue = $mutableScopeConfig->getValue(
17+
'customer/create_account/confirm',
18+
ScopeInterface::SCOPE_WEBSITES,
19+
null
20+
);
21+
22+
$mutableScopeConfig->setValue(
23+
'customer/create_account/confirm',
24+
0,
25+
ScopeInterface::SCOPE_WEBSITES,
26+
null
27+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
use Magento\Framework\App\Config\MutableScopeConfigInterface;
10+
use Magento\Framework\Registry;
11+
use Magento\Store\Model\ScopeInterface;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
14+
/** @var Registry $registry */
15+
$registry = Bootstrap::getObjectManager()->get(Registry::class);
16+
$registry->unregister('isSecureArea');
17+
$registry->register('isSecureArea', true);
18+
19+
$mutableScopeConfig = Bootstrap::getObjectManager()->create(MutableScopeConfigInterface::class);
20+
$mutableScopeConfig->setValue(
21+
'customer/create_account/confirm',
22+
$this->confirmationConfigScopeValue,
23+
ScopeInterface::SCOPE_WEBSITES,
24+
null
25+
);
26+
27+
$registry->unregister('isSecureArea');
28+
$registry->register('isSecureArea', false);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
use Magento\Store\Model\ScopeInterface;
10+
use Magento\Framework\App\Config\MutableScopeConfigInterface;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
13+
$objectManager = Bootstrap::getObjectManager();
14+
$mutableScopeConfig = $objectManager->create(MutableScopeConfigInterface::class);
15+
16+
$this->confirmationConfigScopeValue = $mutableScopeConfig->getValue(
17+
'customer/create_account/confirm',
18+
ScopeInterface::SCOPE_WEBSITES,
19+
null
20+
);
21+
22+
$mutableScopeConfig->setValue(
23+
'customer/create_account/confirm',
24+
1,
25+
ScopeInterface::SCOPE_WEBSITES,
26+
null
27+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
use Magento\Framework\App\Config\MutableScopeConfigInterface;
10+
use Magento\Framework\Registry;
11+
use Magento\Store\Model\ScopeInterface;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
14+
/** @var Registry $registry */
15+
$registry = Bootstrap::getObjectManager()->get(Registry::class);
16+
$registry->unregister('isSecureArea');
17+
$registry->register('isSecureArea', true);
18+
19+
$mutableScopeConfig = Bootstrap::getObjectManager()->create(MutableScopeConfigInterface::class);
20+
$mutableScopeConfig->setValue(
21+
'customer/create_account/confirm',
22+
$this->confirmationConfigScopeValue,
23+
ScopeInterface::SCOPE_WEBSITES,
24+
null
25+
);
26+
27+
$registry->unregister('isSecureArea');
28+
$registry->register('isSecureArea', false);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
use Magento\Customer\Model\Customer;
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
12+
include __DIR__ . '/customer_confirmation_config_enable.php';
13+
14+
$objectManager = Bootstrap::getObjectManager();
15+
/** @var Customer $customer */
16+
$customer = $objectManager->create(Customer::class);
17+
$customer->setWebsiteId(1)
18+
->setId(1)
19+
->setEmail('customer+confirmation@example.com')
20+
->setPassword('password')
21+
->setConfirmation($customer->getRandomConfirmationKey())
22+
->setGroupId(1)
23+
->setStoreId(1)
24+
->setIsActive(1)
25+
->setFirstname('John')
26+
->setLastname('Smith')
27+
->setDefaultBilling(1)
28+
->setDefaultShipping(1)
29+
->setTaxvat('12')
30+
->setGender(0);
31+
32+
$customer->isObjectNew(true);
33+
$customer->save();

0 commit comments

Comments
 (0)