Skip to content

Commit d191526

Browse files
LYNX-441 (#260)
1 parent ed4b17e commit d191526

File tree

18 files changed

+392
-519
lines changed

18 files changed

+392
-519
lines changed

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,14 @@ public function getConfirmationStatus($customerId)
847847
*/
848848
public function createAccount(CustomerInterface $customer, $password = null, $redirectUrl = '')
849849
{
850+
$customerEmail = $customer->getEmail();
851+
if ($customerEmail === null) {
852+
throw new LocalizedException(
853+
__("The email address is required to create a customer account.")
854+
);
855+
}
850856
if ($password !== null) {
851857
$this->checkPasswordStrength($password);
852-
$customerEmail = $customer->getEmail();
853858
try {
854859
$this->credentialsValidator->checkPasswordDifferentFromEmail($customerEmail, $password);
855860
} catch (InputException $e) {

app/code/Magento/Customer/Test/Fixture/CustomerAttributeDefaultData.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class CustomerAttributeDefaultData
1616
'default_frontend_label' => 'Attribute%uniqid%',
1717
'frontend_labels' => [],
1818
'frontend_input' => 'text',
19+
'frontend_label' => null,
1920
'backend_type' => 'varchar',
2021
'is_required' => false,
2122
'is_user_defined' => true,

app/code/Magento/Customer/Test/Unit/Model/AccountManagementApiTest.php

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
*/
66
declare(strict_types=1);
77

8-
98
namespace Magento\Customer\Test\Unit\Model;
109

11-
1210
use Magento\Customer\Api\AddressRepositoryInterface;
1311
use Magento\Customer\Api\CustomerMetadataInterface;
1412
use Magento\Customer\Api\CustomerRepositoryInterface;
@@ -59,7 +57,6 @@
5957
use PHPUnit\Framework\TestCase;
6058
use Psr\Log\LoggerInterface;
6159

62-
6360
/**
6461
* Test for validating anonymous request for synchronous operations containing group id.
6562
*
@@ -73,223 +70,186 @@ class AccountManagementApiTest extends TestCase
7370
*/
7471
private $accountManagementMock;
7572

76-
7773
/**
7874
* @var AccountManagementApi
7975
*/
8076
private $accountManagement;
8177

82-
8378
/**
8479
* @var ObjectManagerHelper
8580
*/
8681
private $objectManagerHelper;
8782

88-
8983
/**
9084
* @var CustomerFactory|MockObject
9185
*/
9286
private $customerFactory;
9387

94-
9588
/**
9689
* @var ManagerInterface|MockObject
9790
*/
9891
private $manager;
9992

100-
10193
/**
10294
* @var StoreManagerInterface|MockObject
10395
*/
10496
private $storeManager;
10597

106-
10798
/**
10899
* @var Random|MockObject
109100
*/
110101
private $random;
111102

112-
113103
/**
114104
* @var Validator|MockObject
115105
*/
116106
private $validator;
117107

118-
119108
/**
120109
* @var ValidationResultsInterfaceFactory|MockObject
121110
*/
122111
private $validationResultsInterfaceFactory;
123112

124-
125113
/**
126114
* @var AddressRepositoryInterface|MockObject
127115
*/
128116
private $addressRepository;
129117

130-
131118
/**
132119
* @var CustomerMetadataInterface|MockObject
133120
*/
134121
private $customerMetadata;
135122

136-
137123
/**
138124
* @var CustomerRegistry|MockObject
139125
*/
140126
private $customerRegistry;
141127

142-
143128
/**
144129
* @var LoggerInterface|MockObject
145130
*/
146131
private $logger;
147132

148-
149133
/**
150134
* @var EncryptorInterface|MockObject
151135
*/
152136
private $encryptor;
153137

154-
155138
/**
156139
* @var Share|MockObject
157140
*/
158141
private $share;
159142

160-
161143
/**
162144
* @var StringUtils|MockObject
163145
*/
164146
private $string;
165147

166-
167148
/**
168149
* @var CustomerRepositoryInterface|MockObject
169150
*/
170151
private $customerRepository;
171152

172-
173153
/**
174154
* @var ScopeConfigInterface|MockObject
175155
*/
176156
private $scopeConfig;
177157

178-
179158
/**
180159
* @var TransportBuilder|MockObject
181160
*/
182161
private $transportBuilder;
183162

184-
185163
/**
186164
* @var DataObjectProcessor|MockObject
187165
*/
188166
private $dataObjectProcessor;
189167

190-
191168
/**
192169
* @var Registry|MockObject
193170
*/
194171
private $registry;
195172

196-
197173
/**
198174
* @var View|MockObject
199175
*/
200176
private $customerViewHelper;
201177

202-
203178
/**
204179
* @var \Magento\Framework\Stdlib\DateTime|MockObject
205180
*/
206181
private $dateTime;
207182

208-
209183
/**
210184
* @var \Magento\Customer\Model\Customer|MockObject
211185
*/
212186
private $customer;
213187

214-
215188
/**
216189
* @var DataObjectFactory|MockObject
217190
*/
218191
private $objectFactory;
219192

220-
221193
/**
222194
* @var ExtensibleDataObjectConverter|MockObject
223195
*/
224196
private $extensibleDataObjectConverter;
225197

226-
227198
/**
228199
* @var DateTimeFactory|MockObject
229200
*/
230201
private $dateTimeFactory;
231202

232-
233203
/**
234204
* @var AccountConfirmation|MockObject
235205
*/
236206
private $accountConfirmation;
237207

238-
239208
/**
240209
* @var MockObject|SessionManagerInterface
241210
*/
242211
private $sessionManager;
243212

244-
245213
/**
246214
* @var MockObject|CollectionFactory
247215
*/
248216
private $visitorCollectionFactory;
249217

250-
251218
/**
252219
* @var MockObject|SaveHandlerInterface
253220
*/
254221
private $saveHandler;
255222

256-
257223
/**
258224
* @var MockObject|AddressRegistry
259225
*/
260226
private $addressRegistryMock;
261227

262-
263228
/**
264229
* @var MockObject|SearchCriteriaBuilder
265230
*/
266231
private $searchCriteriaBuilderMock;
267232

268-
269233
/**
270234
* @var AllowedCountries|MockObject
271235
*/
272236
private $allowedCountriesReader;
273237

274-
275238
/**
276239
* @var Authorization|MockObject
277240
*/
278241
private $authorizationMock;
279242

280-
281243
/**
282244
* @var CustomerSecure|MockObject
283245
*/
284246
private $customerSecure;
285247

286-
287248
/**
288249
* @var StoreInterface|MockObject
289250
*/
290251
private $storeMock;
291252

292-
293253
/**
294254
* @inheritDoc
295255
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -308,7 +268,6 @@ protected function setUp(): void
308268
$this->customerMetadata = $this->getMockForAbstractClass(CustomerMetadataInterface::class);
309269
$this->customerRegistry = $this->createMock(CustomerRegistry::class);
310270

311-
312271
$this->logger = $this->getMockForAbstractClass(LoggerInterface::class);
313272
$this->encryptor = $this->getMockForAbstractClass(EncryptorInterface::class);
314273
$this->share = $this->createMock(Share::class);
@@ -338,7 +297,6 @@ protected function setUp(): void
338297
$this->accountConfirmation = $this->createMock(AccountConfirmation::class);
339298
$this->searchCriteriaBuilderMock = $this->createMock(SearchCriteriaBuilder::class);
340299

341-
342300
$this->visitorCollectionFactory = $this->getMockBuilder(CollectionFactory::class)
343301
->disableOriginalConstructor()
344302
->onlyMethods(['create'])
@@ -449,14 +407,12 @@ protected function setUp(): void
449407
);
450408
$this->accountManagementMock = $this->createMock(AccountManagement::class);
451409

452-
453410
$this->storeMock = $this->getMockBuilder(
454411
StoreInterface::class
455412
)->disableOriginalConstructor()
456413
->getMock();
457414
}
458415

459-
460416
/**
461417
* Verify that only authorized request will be able to change groupId
462418
*
@@ -486,7 +442,6 @@ public function testBeforeCreateAccount(
486442
->with('Magento_Customer::manage')
487443
->willReturn($isAllowed);
488444

489-
490445
$customer = $this->getMockBuilder(CustomerInterface::class)
491446
->addMethods(['setData'])
492447
->getMockForAbstractClass();
@@ -495,13 +450,12 @@ public function testBeforeCreateAccount(
495450
$customer->method('getWebsiteId')->willReturn(2);
496451
$customer->method('getStoreId')->willReturn(1);
497452
$customer->method('setData')->willReturn(1);
498-
453+
$customer->method('getEmail')->willReturn('email@email.com');
499454

500455
$this->customerRepository->method('get')->willReturn($customer);
501456
$this->customerRepository->method('getById')->with($customerId)->willReturn($customer);
502457
$this->customerRepository->method('save')->willReturn($customer);
503458

504-
505459
if (!$willThrowException) {
506460
$this->accountManagementMock->method('createAccountWithPasswordHash')->willReturn($customer);
507461
$this->storeMock->expects($this->any())->method('getId')->willReturnOnConsecutiveCalls(2, 1);
@@ -523,7 +477,6 @@ public function testBeforeCreateAccount(
523477
$this->accountManagement->createAccount($customer);
524478
}
525479

526-
527480
/**
528481
* @return array
529482
*/

app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,9 @@ public function testCreateAccountWithPasswordInputException(
998998
$customer = $this->getMockBuilder(Customer::class)
999999
->disableOriginalConstructor()
10001000
->getMock();
1001+
$customer->expects($this->atLeastOnce())
1002+
->method('getEmail')
1003+
->willReturn('email@email.com');
10011004
$this->accountManagement->createAccount($customer, $password);
10021005
}
10031006

@@ -1021,6 +1024,9 @@ public function testCreateAccountInputExceptionExtraLongPassword(): void
10211024
$customer = $this->getMockBuilder(Customer::class)
10221025
->disableOriginalConstructor()
10231026
->getMock();
1027+
$customer->expects($this->atLeastOnce())
1028+
->method('getEmail')
1029+
->willReturn('email@email.com');
10241030
$this->accountManagement->createAccount($customer, $password);
10251031
}
10261032

0 commit comments

Comments
 (0)