Skip to content

Commit aeef4f8

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-97952' into 2.3-develop-pr41
2 parents 772257e + 2bb00c2 commit aeef4f8

7 files changed

+266
-54
lines changed

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

Lines changed: 110 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,35 @@
1717
use Magento\Framework\App\Http;
1818
use Magento\Framework\Data\Form\FormKey;
1919
use Magento\Framework\Message\MessageInterface;
20-
use Magento\Store\Model\ScopeInterface;
2120
use Magento\TestFramework\Helper\Bootstrap;
2221
use Magento\TestFramework\Request;
2322
use Magento\TestFramework\Response;
2423
use Zend\Stdlib\Parameters;
2524
use Magento\Framework\App\Request\Http as HttpRequest;
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

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

136-
/** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */
137-
$transportBuilder = $this->_objectManager->get(
138-
\Magento\TestFramework\Mail\Template\TransportBuilderMock::class
139-
);
140-
$subject = $transportBuilder->getSentMessage()->getSubject();
153+
$subject = $this->transportBuilderMock->getSentMessage()->getSubject();
141154
$this->assertContains(
142155
'Test special\' characters',
143156
$subject
@@ -260,65 +273,26 @@ public function testNoFormKeyCreatePostAction()
260273
/**
261274
* @magentoDbIsolation enabled
262275
* @magentoAppIsolation enabled
276+
* @magentoDataFixture Magento/Customer/_files/customer_confirmation_config_disable.php
263277
*/
264278
public function testNoConfirmCreatePostAction()
265279
{
266-
/** @var \Magento\Framework\App\Config\MutableScopeConfigInterface $mutableScopeConfig */
267-
$mutableScopeConfig = Bootstrap::getObjectManager()
268-
->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class);
269-
270-
$scopeValue = $mutableScopeConfig->getValue(
271-
'customer/create_account/confirm',
272-
ScopeInterface::SCOPE_WEBSITES,
273-
null
274-
);
275-
276-
$mutableScopeConfig->setValue(
277-
'customer/create_account/confirm',
278-
0,
279-
ScopeInterface::SCOPE_WEBSITES,
280-
null
281-
);
282-
283280
$this->fillRequestWithAccountDataAndFormKey('test1@email.com');
284281
$this->dispatch('customer/account/createPost');
285282
$this->assertRedirect($this->stringEndsWith('customer/account/'));
286283
$this->assertSessionMessages(
287284
$this->equalTo(['Thank you for registering with Main Website Store.']),
288285
MessageInterface::TYPE_SUCCESS
289286
);
290-
291-
$mutableScopeConfig->setValue(
292-
'customer/create_account/confirm',
293-
$scopeValue,
294-
ScopeInterface::SCOPE_WEBSITES,
295-
null
296-
);
297287
}
298288

299289
/**
300290
* @magentoDbIsolation enabled
301291
* @magentoAppIsolation enabled
292+
* @magentoDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php
302293
*/
303294
public function testWithConfirmCreatePostAction()
304295
{
305-
/** @var \Magento\Framework\App\Config\MutableScopeConfigInterface $mutableScopeConfig */
306-
$mutableScopeConfig = Bootstrap::getObjectManager()
307-
->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class);
308-
309-
$scopeValue = $mutableScopeConfig->getValue(
310-
'customer/create_account/confirm',
311-
ScopeInterface::SCOPE_WEBSITES,
312-
null
313-
);
314-
315-
$mutableScopeConfig->setValue(
316-
'customer/create_account/confirm',
317-
1,
318-
ScopeInterface::SCOPE_WEBSITES,
319-
null
320-
);
321-
322296
$this->fillRequestWithAccountDataAndFormKey('test2@email.com');
323297
$this->dispatch('customer/account/createPost');
324298
$this->assertRedirect($this->stringContains('customer/account/index/'));
@@ -330,13 +304,6 @@ public function testWithConfirmCreatePostAction()
330304
]),
331305
MessageInterface::TYPE_SUCCESS
332306
);
333-
334-
$mutableScopeConfig->setValue(
335-
'customer/create_account/confirm',
336-
$scopeValue,
337-
ScopeInterface::SCOPE_WEBSITES,
338-
null
339-
);
340307
}
341308

342309
/**
@@ -730,6 +697,46 @@ public function testLoginPostRedirect($redirectDashboard, string $redirectUrl)
730697
$this->assertTrue($this->_objectManager->get(Session::class)->isLoggedIn());
731698
}
732699

700+
/**
701+
* Test that confirmation email address displays special characters correctly.
702+
*
703+
* @magentoDbIsolation enabled
704+
* @magentoDataFixture Magento/Customer/_files/customer_confirmation_email_address_with_special_chars.php
705+
*
706+
* @return void
707+
*/
708+
public function testConfirmationEmailWithSpecialCharacters(): void
709+
{
710+
$email = 'customer+confirmation@example.com';
711+
$this->dispatch('customer/account/confirmation/email/customer%2Bconfirmation%40email.com');
712+
$this->getRequest()->setPostValue('email', $email);
713+
$this->dispatch('customer/account/confirmation/email/customer%2Bconfirmation%40email.com');
714+
715+
$this->assertRedirect($this->stringContains('customer/account/index'));
716+
$this->assertSessionMessages(
717+
$this->equalTo(['Please check your email for confirmation key.']),
718+
MessageInterface::TYPE_SUCCESS
719+
);
720+
721+
/** @var $message \Magento\Framework\Mail\Message */
722+
$message = $this->transportBuilderMock->getSentMessage();
723+
$rawMessage = $message->getRawMessage();
724+
725+
$this->assertContains('To: ' . $email, $rawMessage);
726+
727+
$content = $message->getBody()->getPartContent(0);
728+
$confirmationUrl = $this->getConfirmationUrlFromMessageContent($content);
729+
$this->setRequestInfo($confirmationUrl, 'confirm');
730+
$this->clearCookieMessagesList();
731+
$this->dispatch($confirmationUrl);
732+
733+
$this->assertRedirect($this->stringContains('customer/account/index'));
734+
$this->assertSessionMessages(
735+
$this->equalTo(['Thank you for registering with Main Website Store.']),
736+
MessageInterface::TYPE_SUCCESS
737+
);
738+
}
739+
733740
/**
734741
* Data provider for testLoginPostRedirect.
735742
*
@@ -847,4 +854,53 @@ private function assertResponseRedirect(Response $response, string $redirectUrl)
847854
$this->assertTrue($response->isRedirect());
848855
$this->assertSame($redirectUrl, $response->getHeader('Location')->getUri());
849856
}
857+
858+
/**
859+
* Add new request info (request uri, path info, action name).
860+
*
861+
* @param string $uri
862+
* @param string $actionName
863+
* @return void
864+
*/
865+
private function setRequestInfo(string $uri, string $actionName): void
866+
{
867+
$this->getRequest()
868+
->setRequestUri($uri)
869+
->setPathInfo()
870+
->setActionName($actionName);
871+
}
872+
873+
/**
874+
* Clear cookie messages list.
875+
*
876+
* @return void
877+
*/
878+
private function clearCookieMessagesList(): void
879+
{
880+
$cookieManager = $this->_objectManager->get(CookieManagerInterface::class);
881+
$jsonSerializer = $this->_objectManager->get(Json::class);
882+
$cookieManager->setPublicCookie(
883+
MessagePlugin::MESSAGES_COOKIES_NAME,
884+
$jsonSerializer->serialize([])
885+
);
886+
}
887+
888+
/**
889+
* Get confirmation URL from message content.
890+
*
891+
* @param string $content
892+
* @return string
893+
*/
894+
private function getConfirmationUrlFromMessageContent(string $content): string
895+
{
896+
$confirmationUrl = '';
897+
898+
if (preg_match('<a\s*href="(?<url>.*?)".*>', $content, $matches)) {
899+
$confirmationUrl = $matches['url'];
900+
$confirmationUrl = str_replace('http://localhost/index.php/', '', $confirmationUrl);
901+
$confirmationUrl = html_entity_decode($confirmationUrl);
902+
}
903+
904+
return $confirmationUrl;
905+
}
850906
}
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');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
include __DIR__ . '/customer_confirmation_config_enable_rollback.php';
10+
11+
use Magento\Customer\Api\CustomerRepositoryInterface;
12+
use Magento\Framework\Registry;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
15+
/** @var Registry $registry */
16+
$registry = Bootstrap::getObjectManager()->get(Registry::class);
17+
$registry->unregister('isSecureArea');
18+
$registry->register('isSecureArea', true);
19+
20+
/** @var CustomerRepositoryInterface $customerRepository */
21+
$customerRepository = Bootstrap::getObjectManager()->create(CustomerRepositoryInterface::class);
22+
23+
try {
24+
$customer = $customerRepository->get('customer+confirmation@example.com');
25+
$customerRepository->delete($customer);
26+
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
27+
// Customer with the specified email does not exist
28+
}
29+
30+
$registry->unregister('isSecureArea');
31+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)