-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge forwardport of #11878 to 2.3-develop branch
Applied pull request patch https://github.com/magento/magento2/pull/11878.patch (created by @dheesbeen) based on commit(s): 1. 8573467 2. 7ad5db6 3. 6227a14 4. 0a545eb 5. 880dd9f
- Loading branch information
Showing
8 changed files
with
301 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\Model; | ||
|
||
use Magento\Store\Model\ScopeInterface; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\Registry; | ||
|
||
/** | ||
* Class AccountConfirmation. | ||
* Checks if email confirmation required for customer. | ||
*/ | ||
class AccountConfirmation | ||
{ | ||
/** | ||
* Configuration path for email confirmation. | ||
*/ | ||
const XML_PATH_IS_CONFIRM = 'customer/create_account/confirm'; | ||
|
||
/** | ||
* @var ScopeConfigInterface | ||
*/ | ||
private $scopeConfig; | ||
|
||
/** | ||
* @var Registry | ||
*/ | ||
private $registry; | ||
|
||
/** | ||
* @param ScopeConfigInterface $scopeConfig | ||
* @param Registry $registry | ||
*/ | ||
public function __construct( | ||
ScopeConfigInterface $scopeConfig, | ||
Registry $registry | ||
) { | ||
$this->scopeConfig = $scopeConfig; | ||
$this->registry = $registry; | ||
} | ||
|
||
/** | ||
* Check if accounts confirmation is required. | ||
* | ||
* @param int|null $websiteId | ||
* @param int|null $customerId | ||
* @param string $customerEmail | ||
* @return bool | ||
*/ | ||
public function isConfirmationRequired($websiteId, $customerId, $customerEmail): bool | ||
{ | ||
if ($this->canSkipConfirmation($customerId, $customerEmail)) { | ||
return false; | ||
} | ||
|
||
return (bool)$this->scopeConfig->getValue( | ||
self::XML_PATH_IS_CONFIRM, | ||
ScopeInterface::SCOPE_WEBSITES, | ||
$websiteId | ||
); | ||
} | ||
|
||
/** | ||
* Check whether confirmation may be skipped when registering using certain email address. | ||
* | ||
* @param int|null $customerId | ||
* @param string $customerEmail | ||
* @return bool | ||
*/ | ||
private function canSkipConfirmation($customerId, $customerEmail): bool | ||
{ | ||
if (!$customerId) { | ||
return false; | ||
} | ||
|
||
/* If an email was used to start the registration process and it is the same email as the one | ||
used to register, then this can skip confirmation. | ||
*/ | ||
$skipConfirmationIfEmail = $this->registry->registry("skip_confirmation_if_email"); | ||
if (!$skipConfirmationIfEmail) { | ||
return false; | ||
} | ||
|
||
return strtolower($skipConfirmationIfEmail) === strtolower($customerEmail); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
app/code/Magento/Customer/Test/Unit/Model/AccountConfirmationTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\Test\Unit\Model; | ||
|
||
use Magento\Customer\Model\AccountConfirmation; | ||
use Magento\Store\Model\ScopeInterface; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\Registry; | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) | ||
*/ | ||
class AccountConfirmationTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var AccountConfirmation|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $accountConfirmation; | ||
|
||
/** | ||
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $scopeConfig; | ||
|
||
/** | ||
* @var Registry|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $registry; | ||
|
||
protected function setUp() | ||
{ | ||
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class); | ||
$this->registry = $this->createMock(Registry::class); | ||
|
||
$this->accountConfirmation = new AccountConfirmation( | ||
$this->scopeConfig, | ||
$this->registry | ||
); | ||
} | ||
|
||
/** | ||
* @param $customerId | ||
* @param $customerEmail | ||
* @param $skipConfirmationIfEmail | ||
* @param $isConfirmationEnabled | ||
* @param $expected | ||
* @dataProvider dataProviderIsConfirmationRequired | ||
*/ | ||
public function testIsConfirmationRequired( | ||
$customerId, | ||
$customerEmail, | ||
$skipConfirmationIfEmail, | ||
$isConfirmationEnabled, | ||
$expected | ||
) { | ||
$websiteId = 1; | ||
|
||
$this->scopeConfig->expects($this->any()) | ||
->method('getValue') | ||
->with( | ||
$this->accountConfirmation::XML_PATH_IS_CONFIRM, | ||
ScopeInterface::SCOPE_WEBSITES, | ||
$websiteId | ||
)->willReturn($isConfirmationEnabled); | ||
|
||
$this->registry->expects($this->any()) | ||
->method('registry') | ||
->with('skip_confirmation_if_email') | ||
->willReturn($skipConfirmationIfEmail); | ||
|
||
self::assertEquals( | ||
$expected, | ||
$this->accountConfirmation->isConfirmationRequired($websiteId, $customerId, $customerEmail) | ||
); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function dataProviderIsConfirmationRequired() | ||
{ | ||
return [ | ||
[null, 'customer@example.com', null, true, true], | ||
[null, 'customer@example.com', null, false, false], | ||
[1, 'customer@example.com', 'customer@example.com', true, false], | ||
[1, 'customer@example.com', 'customer1@example.com', false, false], | ||
[1, 'customer@example.com', 'customer1@example.com', true, true], | ||
]; | ||
} | ||
} |
Oops, something went wrong.