Skip to content

Commit 33a26e6

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-97195' into 2.2-develop-pr70
2 parents ce220a2 + dc39129 commit 33a26e6

7 files changed

+272
-58
lines changed

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

Lines changed: 116 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,34 @@
1919
use Magento\Framework\App\Http;
2020
use Magento\Framework\Data\Form\FormKey;
2121
use Magento\Framework\Message\MessageInterface;
22-
use Magento\Store\Model\ScopeInterface;
2322
use Magento\TestFramework\Helper\Bootstrap;
2423
use Magento\TestFramework\Request;
2524
use Magento\TestFramework\Response;
25+
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
26+
use Magento\Framework\Serialize\Serializer\Json;
27+
use Magento\Framework\Stdlib\CookieManagerInterface;
28+
use Magento\Theme\Controller\Result\MessagePlugin;
2629
use Zend\Stdlib\Parameters;
2730

2831
/**
2932
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3033
*/
3134
class AccountTest extends \Magento\TestFramework\TestCase\AbstractController
3235
{
36+
/**
37+
* @var TransportBuilderMock
38+
*/
39+
private $transportBuilderMock;
40+
41+
/**
42+
* @inheritdoc
43+
*/
44+
protected function setUp()
45+
{
46+
parent::setUp();
47+
$this->transportBuilderMock = $this->_objectManager->get(TransportBuilderMock::class);
48+
}
49+
3350
/**
3451
* Login the user
3552
*
@@ -102,11 +119,7 @@ public function testForgotPasswordEmailMessageWithSpecialCharacters()
102119
$this->dispatch('customer/account/forgotPasswordPost');
103120
$this->assertRedirect($this->stringContains('customer/account/'));
104121

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();
122+
$subject = $this->transportBuilderMock->getSentMessage()->getSubject();
110123
$this->assertContains(
111124
'Test special\' characters',
112125
$subject
@@ -228,65 +241,26 @@ public function testNoFormKeyCreatePostAction()
228241
/**
229242
* @magentoDbIsolation enabled
230243
* @magentoAppIsolation enabled
244+
* @magentoDataFixture Magento/Customer/_files/customer_confirmation_config_disable.php
231245
*/
232246
public function testNoConfirmCreatePostAction()
233247
{
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-
251248
$this->fillRequestWithAccountDataAndFormKey();
252249
$this->dispatch('customer/account/createPost');
253250
$this->assertRedirect($this->stringEndsWith('customer/account/'));
254251
$this->assertSessionMessages(
255252
$this->equalTo(['Thank you for registering with Main Website Store.']),
256253
MessageInterface::TYPE_SUCCESS
257254
);
258-
259-
$mutableScopeConfig->setValue(
260-
'customer/create_account/confirm',
261-
$scopeValue,
262-
ScopeInterface::SCOPE_WEBSITES,
263-
null
264-
);
265255
}
266256

267257
/**
268258
* @magentoDbIsolation enabled
269259
* @magentoAppIsolation enabled
260+
* @magentoDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php
270261
*/
271262
public function testWithConfirmCreatePostAction()
272263
{
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-
290264
$this->fillRequestWithAccountDataAndFormKey();
291265
$this->dispatch('customer/account/createPost');
292266
$this->assertRedirect($this->stringContains('customer/account/index/'));
@@ -298,13 +272,6 @@ public function testWithConfirmCreatePostAction()
298272
]),
299273
MessageInterface::TYPE_SUCCESS
300274
);
301-
302-
$mutableScopeConfig->setValue(
303-
'customer/create_account/confirm',
304-
$scopeValue,
305-
ScopeInterface::SCOPE_WEBSITES,
306-
null
307-
);
308275
}
309276

310277
/**
@@ -690,6 +657,46 @@ public function testLoginPostRedirect($redirectDashboard, string $redirectUrl)
690657
$this->assertTrue($this->_objectManager->get(Session::class)->isLoggedIn());
691658
}
692659

660+
/**
661+
* Test that confirmation email address displays special characters correctly.
662+
*
663+
* @magentoDbIsolation enabled
664+
* @magentoDataFixture Magento/Customer/_files/customer_confirmation_email_address_with_special_chars.php
665+
*
666+
* @return void
667+
*/
668+
public function testConfirmationEmailWithSpecialCharacters()
669+
{
670+
$email = 'customer+confirmation@example.com';
671+
$this->dispatch('customer/account/confirmation/email/customer%2Bconfirmation%40email.com');
672+
$this->getRequest()->setPostValue('email', $email);
673+
$this->dispatch('customer/account/confirmation/email/customer%2Bconfirmation%40email.com');
674+
675+
$this->assertRedirect($this->stringContains('customer/account/index'));
676+
$this->assertSessionMessages(
677+
$this->equalTo(['Please check your email for confirmation key.']),
678+
MessageInterface::TYPE_SUCCESS
679+
);
680+
681+
/** @var $message \Magento\Framework\Mail\Message */
682+
$message = $this->transportBuilderMock->getSentMessage();
683+
$rawMessage = $message->getRawMessage();
684+
685+
$this->assertContains('To: ' . $email, $rawMessage);
686+
687+
$content = $message->getBody()->getPartContent(0);
688+
$confirmationUrl = $this->getConfirmationUrlFromMessageContent($content);
689+
$this->setRequestInfo($confirmationUrl, 'confirm');
690+
$this->clearCookieMessagesList();
691+
$this->dispatch($confirmationUrl);
692+
693+
$this->assertRedirect($this->stringContains('customer/account/index'));
694+
$this->assertSessionMessages(
695+
$this->equalTo(['Thank you for registering with Main Website Store.']),
696+
MessageInterface::TYPE_SUCCESS
697+
);
698+
}
699+
693700
/**
694701
* Data provider for testLoginPostRedirect.
695702
*
@@ -705,16 +712,17 @@ public function loginPostRedirectDataProvider()
705712
}
706713

707714
/**
715+
* @param string $email
708716
* @return void
709717
*/
710-
private function fillRequestWithAccountData()
718+
private function fillRequestWithAccountData(string $email = 'test1@email.com')
711719
{
712720
$this->getRequest()
713721
->setMethod('POST')
714722
->setParam('firstname', 'firstname1')
715723
->setParam('lastname', 'lastname1')
716724
->setParam('company', '')
717-
->setParam('email', 'test1@email.com')
725+
->setParam('email', $email)
718726
->setParam('password', '_Password1')
719727
->setParam('password_confirmation', '_Password1')
720728
->setParam('telephone', '5123334444')
@@ -731,11 +739,12 @@ private function fillRequestWithAccountData()
731739
}
732740

733741
/**
742+
* @param string $email
734743
* @return void
735744
*/
736-
private function fillRequestWithAccountDataAndFormKey()
745+
private function fillRequestWithAccountDataAndFormKey(string $email = 'test1@email.com')
737746
{
738-
$this->fillRequestWithAccountData();
747+
$this->fillRequestWithAccountData($email);
739748
$formKey = $this->_objectManager->get(FormKey::class);
740749
$this->getRequest()->setParam('form_key', $formKey->getFormKey());
741750
}
@@ -805,4 +814,53 @@ private function assertResponseRedirect(Response $response, string $redirectUrl)
805814
$this->assertTrue($response->isRedirect());
806815
$this->assertSame($redirectUrl, $response->getHeader('Location')->getUri());
807816
}
817+
818+
/**
819+
* Add new request info (request uri, path info, action name).
820+
*
821+
* @param string $uri
822+
* @param string $actionName
823+
* @return void
824+
*/
825+
private function setRequestInfo(string $uri, string $actionName)
826+
{
827+
$this->getRequest()
828+
->setRequestUri($uri)
829+
->setPathInfo()
830+
->setActionName($actionName);
831+
}
832+
833+
/**
834+
* Clear cookie messages list.
835+
*
836+
* @return void
837+
*/
838+
private function clearCookieMessagesList()
839+
{
840+
$cookieManager = $this->_objectManager->get(CookieManagerInterface::class);
841+
$jsonSerializer = $this->_objectManager->get(Json::class);
842+
$cookieManager->setPublicCookie(
843+
MessagePlugin::MESSAGES_COOKIES_NAME,
844+
$jsonSerializer->serialize([])
845+
);
846+
}
847+
848+
/**
849+
* Get confirmation URL from message content.
850+
*
851+
* @param string $content
852+
* @return string
853+
*/
854+
private function getConfirmationUrlFromMessageContent(string $content): string
855+
{
856+
$confirmationUrl = '';
857+
858+
if (preg_match('<a\s*href="(?<url>.*?)".*>', $content, $matches)) {
859+
$confirmationUrl = $matches['url'];
860+
$confirmationUrl = str_replace('http://localhost/index.php/', '', $confirmationUrl);
861+
$confirmationUrl = html_entity_decode($confirmationUrl);
862+
}
863+
864+
return $confirmationUrl;
865+
}
808866
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
$mutableScopeConfig->setValue(
17+
'customer/create_account/confirm',
18+
0,
19+
ScopeInterface::SCOPE_WEBSITES,
20+
null
21+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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\Config\Model\ResourceModel\Config;
10+
use Magento\Framework\Registry;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
13+
/** @var Registry $registry */
14+
$registry = Bootstrap::getObjectManager()->get(Registry::class);
15+
$registry->unregister('isSecureArea');
16+
$registry->register('isSecureArea', true);
17+
18+
/** @var Config $config */
19+
$config = Bootstrap::getObjectManager()->create(Config::class);
20+
$config->deleteConfig('customer/create_account/confirm');
21+
22+
$registry->unregister('isSecureArea');
23+
$registry->register('isSecureArea', false);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
$mutableScopeConfig->setValue(
17+
'customer/create_account/confirm',
18+
1,
19+
ScopeInterface::SCOPE_WEBSITES,
20+
null
21+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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\Config\Model\ResourceModel\Config;
10+
use Magento\Framework\Registry;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
13+
/** @var Registry $registry */
14+
$registry = Bootstrap::getObjectManager()->get(Registry::class);
15+
$registry->unregister('isSecureArea');
16+
$registry->register('isSecureArea', true);
17+
18+
/** @var Config $config */
19+
$config = Bootstrap::getObjectManager()->create(Config::class);
20+
$config->deleteConfig('customer/create_account/confirm');
21+
22+
$registry->unregister('isSecureArea');
23+
$registry->register('isSecureArea', false);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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\Api\CustomerRepositoryInterface;
10+
use Magento\Customer\Api\Data\CustomerInterface;
11+
use Magento\Customer\Model\Customer;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
14+
include __DIR__ . '/customer_confirmation_config_enable.php';
15+
16+
$objectManager = Bootstrap::getObjectManager();
17+
18+
/** @var Customer $customer */
19+
$customer = $objectManager->create(Customer::class);
20+
/** @var CustomerRepositoryInterface $customerRepository */
21+
$customerRepository = $objectManager->create(CustomerRepositoryInterface::class);
22+
/** @var CustomerInterface $customerInterface */
23+
$customerInterface = $objectManager->create(CustomerInterface::class);
24+
25+
$customerInterface->setWebsiteId(1)
26+
->setEmail('customer+confirmation@example.com')
27+
->setConfirmation($customer->getRandomConfirmationKey())
28+
->setGroupId(1)
29+
->setStoreId(1)
30+
->setFirstname('John')
31+
->setLastname('Smith')
32+
->setDefaultBilling(1)
33+
->setDefaultShipping(1)
34+
->setTaxvat('12')
35+
->setGender(0);
36+
37+
$customerRepository->save($customerInterface, 'password');

0 commit comments

Comments
 (0)