Skip to content

Commit 9e4001b

Browse files
committed
MC-39189: Exception on Admin Customers page when website is deleted.
1 parent 1c3837c commit 9e4001b

File tree

2 files changed

+153
-8
lines changed

2 files changed

+153
-8
lines changed

app/code/Magento/Customer/Ui/Component/Listing/Column/Confirmation.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Customer\Ui\Component\Listing\Column;
77

88
use Magento\Framework\App\Config\ScopeConfigInterface;
9+
use Magento\Framework\Exception\NoSuchEntityException;
910
use Magento\Framework\View\Element\UiComponent\ContextInterface;
1011
use Magento\Framework\View\Element\UiComponentFactory;
1112
use Magento\Ui\Component\Listing\Columns\Column;
@@ -28,7 +29,7 @@ class Confirmation extends Column
2829
* @param ScopeConfigInterface $scopeConfig @deprecated
2930
* @param array $components
3031
* @param array $data
31-
* @param AccountConfirmation $accountConfirmation
32+
* @param AccountConfirmation|null $accountConfirmation
3233
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3334
*/
3435
public function __construct(
@@ -65,18 +66,35 @@ public function prepareDataSource(array $dataSource)
6566
*/
6667
private function getFieldLabel(array $item)
6768
{
68-
$isConfirmationRequired = $this->accountConfirmation->isConfirmationRequired(
69-
$item['website_id'][0] ?? null,
70-
$item[$item['id_field_name']],
71-
$item['email']
72-
);
73-
74-
if ($isConfirmationRequired) {
69+
if ($this->getIsConfirmationRequired($item)) {
7570
if ($item[$this->getData('name')] === null) {
7671
return __('Confirmed');
7772
}
7873
return __('Confirmation Required');
7974
}
8075
return __('Confirmation Not Required');
8176
}
77+
78+
/**
79+
* Retrieve is confirmation required flag for customer considering requested website may not exist.
80+
*
81+
* @param array $customer
82+
* @return bool
83+
*/
84+
private function getIsConfirmationRequired(array $customer): bool
85+
{
86+
try {
87+
return $this->accountConfirmation->isConfirmationRequired(
88+
$customer['website_id'][0] ?? null,
89+
$customer[$customer['id_field_name']],
90+
$customer['email']
91+
);
92+
} catch (NoSuchEntityException $e) {
93+
return $this->accountConfirmation->isConfirmationRequired(
94+
null,
95+
$customer[$customer['id_field_name']],
96+
$customer['email']
97+
);
98+
}
99+
}
82100
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\Customer\Ui\Component\Listing\Column;
10+
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use PHPUnit\Framework\TestCase;
13+
14+
/**
15+
* Tests for \Magento\Customer\Ui\Component\Listing\Column\Confirmation.
16+
*/
17+
class ConfirmationTest extends TestCase
18+
{
19+
/**
20+
* Test subject.
21+
*
22+
* @var Confirmation
23+
*/
24+
private $confirmation;
25+
26+
/**
27+
* @inheritdoc
28+
*/
29+
protected function setUp(): void
30+
{
31+
$this->confirmation = Bootstrap::getObjectManager()->create(
32+
Confirmation::class,
33+
[
34+
'components' => [],
35+
'data' => ['name' => 'confirmation'],
36+
]
37+
);
38+
}
39+
40+
/**
41+
* Verify Confirmation::prepareDataSource() won't throw exception in case requested website doesn't exist.
42+
*
43+
* @param array $customerDataSource
44+
* @param array $expectedResult
45+
* @magentoConfigFixture base_website customer/create_account/confirm 1
46+
* @dataProvider customersDataProvider
47+
*
48+
* @return void
49+
*/
50+
public function testPrepareDataSource(array $customerDataSource, array $expectedResult): void
51+
{
52+
$result = $this->confirmation->prepareDataSource($customerDataSource);
53+
54+
self::assertEquals($expectedResult, $result);
55+
}
56+
57+
/**
58+
* CustomerDataSource data provider.
59+
*
60+
* @return array
61+
*/
62+
public function customersDataProvider(): array
63+
{
64+
return [
65+
[
66+
'customerDataSource' => [
67+
'data' => [
68+
'items' => [
69+
[
70+
'id_field_name' => 'entity_id',
71+
'entity_id' => '1',
72+
'name' => 'John Doe',
73+
'email' => 'john.doe@example.com',
74+
'group_id' => ['1'],
75+
'created_at' => '2020-12-28 07:05:50',
76+
'website_id' => ['1'],
77+
'confirmation' => false,
78+
'created_in' => 'Default Store View',
79+
],
80+
[
81+
'id_field_name' => 'entity_id',
82+
'entity_id' => '2',
83+
'name' => 'Jane Doe',
84+
'email' => 'jane.doe@example.com',
85+
'group_id' => ['1'],
86+
'created_at' => '2020-12-28 07:06:17',
87+
'website_id' => ['999999999'],
88+
'confirmation' => null,
89+
'created_in' => 'CustomStoreViewWhichDoesNotExistAnymore',
90+
],
91+
],
92+
'totalRecords' => 2,
93+
],
94+
],
95+
'expectedResult' => [
96+
'data' => [
97+
'items' => [
98+
[
99+
'id_field_name' => 'entity_id',
100+
'entity_id' => '1',
101+
'name' => 'John Doe',
102+
'email' => 'john.doe@example.com',
103+
'group_id' => ['1'],
104+
'created_at' => '2020-12-28 07:05:50',
105+
'website_id' => ['1'],
106+
'confirmation' => __('Confirmation Required'),
107+
'created_in' => 'Default Store View',
108+
],
109+
[
110+
'id_field_name' => 'entity_id',
111+
'entity_id' => '2',
112+
'name' => 'Jane Doe',
113+
'email' => 'jane.doe@example.com',
114+
'group_id' => ['1'],
115+
'created_at' => '2020-12-28 07:06:17',
116+
'website_id' => ['999999999'],
117+
'confirmation' => __('Confirmed'),
118+
'created_in' => 'CustomStoreViewWhichDoesNotExistAnymore',
119+
],
120+
],
121+
'totalRecords' => 2,
122+
],
123+
],
124+
],
125+
];
126+
}
127+
}

0 commit comments

Comments
 (0)