Skip to content

Commit b472bf8

Browse files
author
okarpenko
committed
MAGETWO-37818: Customer invalid email message is not displayed
1 parent a33da51 commit b472bf8

File tree

2 files changed

+262
-6
lines changed

2 files changed

+262
-6
lines changed

app/code/Magento/Customer/Controller/Adminhtml/Index/Validate.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Validate extends \Magento\Customer\Controller\Adminhtml\Index
1919
protected function _validateCustomer($response)
2020
{
2121
$customer = null;
22-
$errors = null;
22+
$errors = [];
2323

2424
try {
2525
/** @var CustomerInterface $customer */
@@ -48,17 +48,17 @@ protected function _validateCustomer($response)
4848
$data,
4949
'\Magento\Customer\Api\Data\CustomerInterface'
5050
);
51-
$errors = $this->customerAccountManagement->validate($customer);
51+
$errors = $this->customerAccountManagement->validate($customer)->getMessages();
5252
} catch (\Magento\Framework\Validator\Exception $exception) {
5353
/* @var $error Error */
5454
foreach ($exception->getMessages(\Magento\Framework\Message\MessageInterface::TYPE_ERROR) as $error) {
5555
$errors[] = $error->getText();
5656
}
5757
}
5858

59-
if (!$errors->isValid()) {
59+
if ($errors) {
6060
$messages = [];
61-
foreach ($errors->getMessages() as $error) {
61+
foreach ($errors as $error) {
6262
$messages[] = $error;
6363
}
6464
$response->setMessages($messages);

app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ValidateTest.php

Lines changed: 258 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,131 @@ public function testExecute()
164164
true
165165
);
166166
$validationResult->expects($this->once())
167-
->method('isValid')
168-
->willReturn(false);
167+
->method('getMessages')
168+
->willReturn(['Error message']);
169+
170+
$this->customerAccountManagement->expects($this->once())
171+
->method('validate')
172+
->willReturn($validationResult);
173+
174+
$this->resultJson = $this->getMock('Magento\Framework\Controller\Result\Json', [], [], '', false);
175+
$this->resultJson->expects($this->once())
176+
->method('setData');
177+
$this->resultJsonFactory = $this->getMock(
178+
'Magento\Framework\Controller\Result\JsonFactory',
179+
['create'],
180+
[],
181+
'',
182+
false
183+
);
184+
$this->resultJsonFactory
185+
->expects($this->once())
186+
->method('create')
187+
->willReturn($this->resultJson);
188+
189+
$this->getController()->execute();
190+
}
191+
192+
public function testExecuteWithoutAddresses()
193+
{
194+
$this->customer = $this->getMockForAbstractClass(
195+
'Magento\Customer\Api\Data\CustomerInterface',
196+
[],
197+
'',
198+
false,
199+
true,
200+
true
201+
);
202+
$this->customer->expects($this->once())
203+
->method('getWebsiteId')
204+
->willReturn(2);
205+
206+
$this->customerDataFactory = $this->getMock(
207+
'Magento\Customer\Api\Data\CustomerInterfaceFactory',
208+
['create'],
209+
[],
210+
'',
211+
false
212+
);
213+
$this->customerDataFactory
214+
->expects($this->once())
215+
->method('create')
216+
->willReturn($this->customer);
217+
218+
$this->request = $this->getMockForAbstractClass(
219+
'Magento\Framework\App\RequestInterface',
220+
[],
221+
'',
222+
false,
223+
true,
224+
true,
225+
['getPost']
226+
);
227+
$this->request->expects($this->once())
228+
->method('getPost')
229+
->willReturn(null);
230+
$this->response = $this->getMockForAbstractClass(
231+
'Magento\Framework\App\ResponseInterface',
232+
[],
233+
'',
234+
false
235+
);
236+
$this->form = $this->getMock(
237+
'Magento\Customer\Model\Metadata\Form',
238+
[],
239+
[],
240+
'',
241+
false
242+
);
243+
$this->form->expects($this->once())
244+
->method('setInvisibleIgnored');
245+
$this->form->expects($this->atLeastOnce())
246+
->method('extractData')
247+
->willReturn([]);
248+
249+
$error = $this->getMock('Magento\Framework\Message\Error', [], [], '', false);
250+
$this->form->expects($this->never())
251+
->method('validateData')
252+
->willReturn([$error]);
253+
254+
$this->formFactory = $this->getMock('Magento\Customer\Model\Metadata\FormFactory', ['create'], [], '', false);
255+
$this->formFactory->expects($this->atLeastOnce())
256+
->method('create')
257+
->willReturn($this->form);
258+
259+
$this->extensibleDataObjectConverter = $this->getMock(
260+
'Magento\Framework\Api\ExtensibleDataObjectConverter',
261+
[],
262+
[],
263+
'',
264+
false
265+
);
266+
$this->extensibleDataObjectConverter->expects($this->once())
267+
->method('toFlatArray')
268+
->willReturn([]);
269+
270+
$this->dataObjectHelper = $this->getMock('Magento\Framework\Api\DataObjectHelper', [], [], '', false);
271+
$this->dataObjectHelper
272+
->expects($this->once())
273+
->method('populateWithArray');
274+
275+
$this->customerAccountManagement = $this->getMockForAbstractClass(
276+
'Magento\Customer\Api\AccountManagementInterface',
277+
[],
278+
'',
279+
false,
280+
true,
281+
true
282+
);
283+
284+
$validationResult = $this->getMockForAbstractClass(
285+
'Magento\Customer\Api\Data\ValidationResultsInterface',
286+
[],
287+
'',
288+
false,
289+
true,
290+
true
291+
);
169292
$validationResult->expects($this->once())
170293
->method('getMessages')
171294
->willReturn(['Error message']);
@@ -192,6 +315,139 @@ public function testExecute()
192315
$this->getController()->execute();
193316
}
194317

318+
public function testExecuteWithException()
319+
{
320+
$this->customer = $this->getMockForAbstractClass(
321+
'Magento\Customer\Api\Data\CustomerInterface',
322+
[],
323+
'',
324+
false,
325+
true,
326+
true
327+
);
328+
$this->customer->expects($this->once())
329+
->method('getWebsiteId')
330+
->willReturn(2);
331+
332+
$this->customerDataFactory = $this->getMock(
333+
'Magento\Customer\Api\Data\CustomerInterfaceFactory',
334+
['create'],
335+
[],
336+
'',
337+
false
338+
);
339+
$this->customerDataFactory
340+
->expects($this->once())
341+
->method('create')
342+
->willReturn($this->customer);
343+
344+
$this->request = $this->getMockForAbstractClass(
345+
'Magento\Framework\App\RequestInterface',
346+
[],
347+
'',
348+
false,
349+
true,
350+
true,
351+
['getPost']
352+
);
353+
$this->request->expects($this->once())
354+
->method('getPost')
355+
->willReturn(null);
356+
$this->response = $this->getMockForAbstractClass(
357+
'Magento\Framework\App\ResponseInterface',
358+
[],
359+
'',
360+
false
361+
);
362+
$this->form = $this->getMock(
363+
'Magento\Customer\Model\Metadata\Form',
364+
[],
365+
[],
366+
'',
367+
false
368+
);
369+
$this->form->expects($this->once())
370+
->method('setInvisibleIgnored');
371+
$this->form->expects($this->atLeastOnce())
372+
->method('extractData')
373+
->willReturn([]);
374+
375+
$this->form->expects($this->never())
376+
->method('validateData');
377+
378+
$this->formFactory = $this->getMock('Magento\Customer\Model\Metadata\FormFactory', ['create'], [], '', false);
379+
$this->formFactory->expects($this->atLeastOnce())
380+
->method('create')
381+
->willReturn($this->form);
382+
383+
$this->extensibleDataObjectConverter = $this->getMock(
384+
'Magento\Framework\Api\ExtensibleDataObjectConverter',
385+
[],
386+
[],
387+
'',
388+
false
389+
);
390+
$this->extensibleDataObjectConverter->expects($this->once())
391+
->method('toFlatArray')
392+
->willReturn([]);
393+
394+
$this->dataObjectHelper = $this->getMock('Magento\Framework\Api\DataObjectHelper', [], [], '', false);
395+
$this->dataObjectHelper
396+
->expects($this->once())
397+
->method('populateWithArray');
398+
399+
$this->customerAccountManagement = $this->getMockForAbstractClass(
400+
'Magento\Customer\Api\AccountManagementInterface',
401+
[],
402+
'',
403+
false,
404+
true,
405+
true
406+
);
407+
408+
$validationResult = $this->getMockForAbstractClass(
409+
'Magento\Customer\Api\Data\ValidationResultsInterface',
410+
[],
411+
'',
412+
false,
413+
true,
414+
true
415+
);
416+
$error = $this->getMock('Magento\Framework\Message\Error', [], [], '', false);
417+
$error->expects($this->once())
418+
->method('getText')
419+
->willReturn('Error text');
420+
421+
$exception = $this->getMock('Magento\Framework\Validator\Exception', [], [], '', false);
422+
$exception->expects($this->once())
423+
->method('getMessages')
424+
->willReturn([$error]);
425+
$validationResult->expects($this->once())
426+
->method('getMessages')
427+
->willThrowException($exception);
428+
429+
$this->customerAccountManagement->expects($this->once())
430+
->method('validate')
431+
->willReturn($validationResult);
432+
433+
$this->resultJson = $this->getMock('Magento\Framework\Controller\Result\Json', [], [], '', false);
434+
$this->resultJson->expects($this->once())
435+
->method('setData');
436+
$this->resultJsonFactory = $this->getMock(
437+
'Magento\Framework\Controller\Result\JsonFactory',
438+
['create'],
439+
[],
440+
'',
441+
false
442+
);
443+
$this->resultJsonFactory
444+
->expects($this->once())
445+
->method('create')
446+
->willReturn($this->resultJson);
447+
448+
$this->getController()->execute();
449+
}
450+
195451
public function getController()
196452
{
197453
$objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);

0 commit comments

Comments
 (0)