Skip to content

Commit 01307c7

Browse files
committed
MC-32709: Customer configuration: Account sharing options
1 parent 70cf0c2 commit 01307c7

File tree

5 files changed

+280
-82
lines changed

5 files changed

+280
-82
lines changed

dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagement/CreateAccountTest.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magento\Framework\Encryption\EncryptorInterface;
2020
use Magento\Framework\Exception\InputException;
2121
use Magento\Framework\Exception\LocalizedException;
22+
use Magento\Framework\Exception\State\InputMismatchException;
2223
use Magento\Framework\Math\Random;
2324
use Magento\Framework\ObjectManagerInterface;
2425
use Magento\Framework\Validator\Exception;
@@ -496,9 +497,33 @@ public function testCreateNewCustomerFromClone(): void
496497
$this->assertCustomerData($customer, $expectedCustomerData);
497498
$this->accountManagement->authenticate(
498499
$customer->getEmail(),
499-
'_aPassword1',
500-
true
500+
'_aPassword1'
501+
);
502+
}
503+
504+
/**
505+
* Test for create customer account for second website (with existing email for default website)
506+
* with global account scope config.
507+
*
508+
* @magentoConfigFixture current_store customer/account_share/scope 0
509+
* @magentoDataFixture Magento/Customer/_files/customer.php
510+
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
511+
*
512+
* @return void
513+
*/
514+
public function testCreateAccountInGlobalScope(): void
515+
{
516+
$customerEntity = $this->customerFactory->create();
517+
$this->dataObjectHelper->populateWithArray(
518+
$customerEntity,
519+
$this->defaultCustomerData,
520+
CustomerInterface::class
501521
);
522+
$storeId = $this->storeManager->getStore('fixture_second_store')->getStoreId();
523+
$customerEntity->setStoreId($storeId);
524+
$message = 'A customer with the same email address already exists in an associated website.';
525+
$this->expectExceptionObject(new InputMismatchException(__($message)));
526+
$this->accountManagement->createAccount($customerEntity, '_aPassword1');
502527
}
503528

504529
/**

dev/tests/integration/testsuite/Magento/Customer/Model/Config/ShareTest.php

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,80 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Customer\Model\Config;
79

10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Store\Api\WebsiteRepositoryInterface;
813
use Magento\TestFramework\Helper\Bootstrap;
14+
use PHPUnit\Framework\TestCase;
915

1016
/**
1117
* Test \Magento\Customer\Model\Config\Share
1218
*/
13-
class ShareTest extends \PHPUnit\Framework\TestCase
19+
class ShareTest extends TestCase
1420
{
15-
public function testGetSharedWebsiteIds()
21+
/** @var ObjectManagerInterface */
22+
private $objectManager;
23+
24+
/** @var Share */
25+
private $share;
26+
27+
/** @var WebsiteRepositoryInterface */
28+
private $websiteRepository;
29+
30+
/**
31+
* @inheritdoc
32+
*/
33+
protected function setUp()
1634
{
17-
/** @var Share $share */
18-
$share = Bootstrap::getObjectManager()->get(\Magento\Customer\Model\Config\Share::class);
35+
parent::setUp();
1936

20-
$websiteIds = $share->getSharedWebsiteIds(42);
37+
$this->objectManager = Bootstrap::getObjectManager();
38+
$this->share = $this->objectManager->get(Share::class);
39+
$this->websiteRepository = $this->objectManager->create(WebsiteRepositoryInterface::class);
40+
}
2141

42+
/**
43+
* @return void
44+
*/
45+
public function testGetSharedWebsiteIds(): void
46+
{
47+
$websiteIds = $this->share->getSharedWebsiteIds(42);
2248
$this->assertEquals([42], $websiteIds);
2349
}
2450

2551
/**
2652
* @magentoDataFixture Magento/Store/_files/core_second_third_fixturestore.php
2753
* @magentoConfigFixture current_store customer/account_share/scope 0
54+
*
55+
* @return void
2856
*/
29-
public function testGetSharedWebsiteIdsMultipleSites()
57+
public function testGetSharedWebsiteIdsMultipleSites(): void
3058
{
31-
/** @var Share $share */
32-
$share = Bootstrap::getObjectManager()->get(\Magento\Customer\Model\Config\Share::class);
33-
$expectedIds = [1];
34-
/** @var \Magento\Store\Model\Website $website */
35-
$website = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
36-
\Magento\Store\Model\Website::class
37-
);
38-
$expectedIds[] = $website->load('secondwebsite')->getId();
39-
$expectedIds[] = $website->load('thirdwebsite')->getId();
40-
41-
$websiteIds = $share->getSharedWebsiteIds(42);
42-
59+
$expectedIds[] = $this->websiteRepository->get('base')->getId();
60+
$expectedIds[] = $this->websiteRepository->get('secondwebsite')->getId();
61+
$expectedIds[] = $this->websiteRepository->get('thirdwebsite')->getId();
62+
$websiteIds = $this->share->getSharedWebsiteIds(42);
4363
$this->assertEquals($expectedIds, $websiteIds);
4464
}
65+
66+
/**
67+
* @magentoConfigFixture current_store customer/account_share/scope 1
68+
* @magentoDataFixture Magento/Customer/_files/customer.php
69+
* @magentoDataFixture Magento/Customer/_files/customer_for_second_website.php
70+
* @magentoDbIsolation enabled
71+
*
72+
* @return void
73+
*/
74+
public function testEnableGlobalAccountShareScope(): void
75+
{
76+
$message = 'We can\'t share customer accounts globally when the accounts share'
77+
. ' identical email addresses on more than one website.';
78+
$this->expectExceptionObject(new LocalizedException(__($message)));
79+
$this->share->setPath(Share::XML_PATH_CUSTOMER_ACCOUNT_SHARE)->setValue((string)Share::SHARE_GLOBAL)
80+
->beforeSave();
81+
}
4582
}

0 commit comments

Comments
 (0)