|
3 | 3 | * Copyright © Magento, Inc. All rights reserved.
|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
| 6 | +declare(strict_types=1); |
| 7 | + |
6 | 8 | namespace Magento\Customer\Model\Config;
|
7 | 9 |
|
| 10 | +use Magento\Framework\Exception\LocalizedException; |
| 11 | +use Magento\Framework\ObjectManagerInterface; |
| 12 | +use Magento\Store\Api\WebsiteRepositoryInterface; |
8 | 13 | use Magento\TestFramework\Helper\Bootstrap;
|
| 14 | +use PHPUnit\Framework\TestCase; |
9 | 15 |
|
10 | 16 | /**
|
11 | 17 | * Test \Magento\Customer\Model\Config\Share
|
12 | 18 | */
|
13 |
| -class ShareTest extends \PHPUnit\Framework\TestCase |
| 19 | +class ShareTest extends TestCase |
14 | 20 | {
|
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() |
16 | 34 | {
|
17 |
| - /** @var Share $share */ |
18 |
| - $share = Bootstrap::getObjectManager()->get(\Magento\Customer\Model\Config\Share::class); |
| 35 | + parent::setUp(); |
19 | 36 |
|
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 | + } |
21 | 41 |
|
| 42 | + /** |
| 43 | + * @return void |
| 44 | + */ |
| 45 | + public function testGetSharedWebsiteIds(): void |
| 46 | + { |
| 47 | + $websiteIds = $this->share->getSharedWebsiteIds(42); |
22 | 48 | $this->assertEquals([42], $websiteIds);
|
23 | 49 | }
|
24 | 50 |
|
25 | 51 | /**
|
26 | 52 | * @magentoDataFixture Magento/Store/_files/core_second_third_fixturestore.php
|
27 | 53 | * @magentoConfigFixture current_store customer/account_share/scope 0
|
| 54 | + * |
| 55 | + * @return void |
28 | 56 | */
|
29 |
| - public function testGetSharedWebsiteIdsMultipleSites() |
| 57 | + public function testGetSharedWebsiteIdsMultipleSites(): void |
30 | 58 | {
|
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); |
43 | 63 | $this->assertEquals($expectedIds, $websiteIds);
|
44 | 64 | }
|
| 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 | + } |
45 | 82 | }
|
0 commit comments