Skip to content

Commit e50a0ff

Browse files
author
okarpenko
committed
MAGETWO-37818: Customer invalid email message is not displayed
1 parent 9a97b7f commit e50a0ff

File tree

1 file changed

+47
-163
lines changed

1 file changed

+47
-163
lines changed

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

Lines changed: 47 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright © 2015 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
// @codingStandardsIgnoreFile
6+
// @codingStandardsIgnoreFile
77

88
namespace Magento\Customer\Test\Unit\Controller\Adminhtml\Index;
99

@@ -70,9 +70,7 @@ public function testExecute()
7070
true,
7171
true
7272
);
73-
$this->customer->expects($this->once())
74-
->method('getWebsiteId')
75-
->willReturn(2);
73+
$this->customer->expects($this->once())->method('getWebsiteId')->willReturn(2);
7674

7775
$this->customerDataFactory = $this->getMock(
7876
'Magento\Customer\Api\Data\CustomerInterfaceFactory',
@@ -81,10 +79,7 @@ public function testExecute()
8179
'',
8280
false
8381
);
84-
$this->customerDataFactory
85-
->expects($this->once())
86-
->method('create')
87-
->willReturn($this->customer);
82+
$this->customerDataFactory->expects($this->once())->method('create')->willReturn($this->customer);
8883

8984
$this->request = $this->getMockForAbstractClass(
9085
'Magento\Framework\App\RequestInterface',
@@ -101,34 +96,16 @@ public function testExecute()
10196
'_template_' => null,
10297
'address_index' => null
10398
]);
104-
$this->response = $this->getMockForAbstractClass(
105-
'Magento\Framework\App\ResponseInterface',
106-
[],
107-
'',
108-
false
109-
);
110-
$this->form = $this->getMock(
111-
'Magento\Customer\Model\Metadata\Form',
112-
[],
113-
[],
114-
'',
115-
false
116-
);
117-
$this->form->expects($this->once())
118-
->method('setInvisibleIgnored');
119-
$this->form->expects($this->atLeastOnce())
120-
->method('extractData')
121-
->willReturn([]);
99+
$this->response = $this->getMockForAbstractClass('Magento\Framework\App\ResponseInterface', [], '', false);
100+
$this->form = $this->getMock('Magento\Customer\Model\Metadata\Form', [], [], '', false);
101+
$this->form->expects($this->once())->method('setInvisibleIgnored');
102+
$this->form->expects($this->atLeastOnce())->method('extractData')->willReturn([]);
122103

123104
$error = $this->getMock('Magento\Framework\Message\Error', [], [], '', false);
124-
$this->form->expects($this->once())
125-
->method('validateData')
126-
->willReturn([$error]);
105+
$this->form->expects($this->once())->method('validateData')->willReturn([$error]);
127106

128107
$this->formFactory = $this->getMock('Magento\Customer\Model\Metadata\FormFactory', ['create'], [], '', false);
129-
$this->formFactory->expects($this->atLeastOnce())
130-
->method('create')
131-
->willReturn($this->form);
108+
$this->formFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->form);
132109

133110
$this->extensibleDataObjectConverter = $this->getMock(
134111
'Magento\Framework\Api\ExtensibleDataObjectConverter',
@@ -137,14 +114,10 @@ public function testExecute()
137114
'',
138115
false
139116
);
140-
$this->extensibleDataObjectConverter->expects($this->once())
141-
->method('toFlatArray')
142-
->willReturn([]);
117+
$this->extensibleDataObjectConverter->expects($this->once())->method('toFlatArray')->willReturn([]);
143118

144119
$this->dataObjectHelper = $this->getMock('Magento\Framework\Api\DataObjectHelper', [], [], '', false);
145-
$this->dataObjectHelper
146-
->expects($this->once())
147-
->method('populateWithArray');
120+
$this->dataObjectHelper->expects($this->once())->method('populateWithArray');
148121

149122
$this->customerAccountManagement = $this->getMockForAbstractClass(
150123
'Magento\Customer\Api\AccountManagementInterface',
@@ -163,29 +136,20 @@ public function testExecute()
163136
true,
164137
true
165138
);
166-
$validationResult->expects($this->once())
167-
->method('getMessages')
168-
->willReturn(['Error message']);
139+
$validationResult->expects($this->once())->method('getMessages')->willReturn(['Error message']);
169140

170-
$this->customerAccountManagement->expects($this->once())
171-
->method('validate')
172-
->willReturn($validationResult);
141+
$this->customerAccountManagement->expects($this->once())->method('validate')->willReturn($validationResult);
173142

174143
$this->resultJson = $this->getMock('Magento\Framework\Controller\Result\Json', [], [], '', false);
175-
$this->resultJson->expects($this->once())
176-
->method('setData');
144+
$this->resultJson->expects($this->once())->method('setData');
177145
$this->resultJsonFactory = $this->getMock(
178146
'Magento\Framework\Controller\Result\JsonFactory',
179147
['create'],
180148
[],
181149
'',
182150
false
183151
);
184-
$this->resultJsonFactory
185-
->expects($this->once())
186-
->method('create')
187-
->willReturn($this->resultJson);
188-
152+
$this->resultJsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
189153
$this->getController()->execute();
190154
}
191155

@@ -199,9 +163,7 @@ public function testExecuteWithoutAddresses()
199163
true,
200164
true
201165
);
202-
$this->customer->expects($this->once())
203-
->method('getWebsiteId')
204-
->willReturn(2);
166+
$this->customer->expects($this->once())->method('getWebsiteId')->willReturn(2);
205167

206168
$this->customerDataFactory = $this->getMock(
207169
'Magento\Customer\Api\Data\CustomerInterfaceFactory',
@@ -210,10 +172,7 @@ public function testExecuteWithoutAddresses()
210172
'',
211173
false
212174
);
213-
$this->customerDataFactory
214-
->expects($this->once())
215-
->method('create')
216-
->willReturn($this->customer);
175+
$this->customerDataFactory->expects($this->once())->method('create')->willReturn($this->customer);
217176

218177
$this->request = $this->getMockForAbstractClass(
219178
'Magento\Framework\App\RequestInterface',
@@ -224,37 +183,17 @@ public function testExecuteWithoutAddresses()
224183
true,
225184
['getPost']
226185
);
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([]);
186+
$this->request->expects($this->once())->method('getPost')->willReturn(null);
187+
$this->response = $this->getMockForAbstractClass('Magento\Framework\App\ResponseInterface', [], '', false);
188+
$this->form = $this->getMock('Magento\Customer\Model\Metadata\Form', [], [], '', false);
189+
$this->form->expects($this->once())->method('setInvisibleIgnored');
190+
$this->form->expects($this->atLeastOnce())->method('extractData')->willReturn([]);
248191

249192
$error = $this->getMock('Magento\Framework\Message\Error', [], [], '', false);
250-
$this->form->expects($this->never())
251-
->method('validateData')
252-
->willReturn([$error]);
193+
$this->form->expects($this->never())->method('validateData')->willReturn([$error]);
253194

254195
$this->formFactory = $this->getMock('Magento\Customer\Model\Metadata\FormFactory', ['create'], [], '', false);
255-
$this->formFactory->expects($this->atLeastOnce())
256-
->method('create')
257-
->willReturn($this->form);
196+
$this->formFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->form);
258197

259198
$this->extensibleDataObjectConverter = $this->getMock(
260199
'Magento\Framework\Api\ExtensibleDataObjectConverter',
@@ -263,14 +202,10 @@ public function testExecuteWithoutAddresses()
263202
'',
264203
false
265204
);
266-
$this->extensibleDataObjectConverter->expects($this->once())
267-
->method('toFlatArray')
268-
->willReturn([]);
205+
$this->extensibleDataObjectConverter->expects($this->once())->method('toFlatArray')->willReturn([]);
269206

270207
$this->dataObjectHelper = $this->getMock('Magento\Framework\Api\DataObjectHelper', [], [], '', false);
271-
$this->dataObjectHelper
272-
->expects($this->once())
273-
->method('populateWithArray');
208+
$this->dataObjectHelper->expects($this->once())->method('populateWithArray');
274209

275210
$this->customerAccountManagement = $this->getMockForAbstractClass(
276211
'Magento\Customer\Api\AccountManagementInterface',
@@ -289,29 +224,20 @@ public function testExecuteWithoutAddresses()
289224
true,
290225
true
291226
);
292-
$validationResult->expects($this->once())
293-
->method('getMessages')
294-
->willReturn(['Error message']);
227+
$validationResult->expects($this->once())->method('getMessages')->willReturn(['Error message']);
295228

296-
$this->customerAccountManagement->expects($this->once())
297-
->method('validate')
298-
->willReturn($validationResult);
229+
$this->customerAccountManagement->expects($this->once())->method('validate')->willReturn($validationResult);
299230

300231
$this->resultJson = $this->getMock('Magento\Framework\Controller\Result\Json', [], [], '', false);
301-
$this->resultJson->expects($this->once())
302-
->method('setData');
232+
$this->resultJson->expects($this->once())->method('setData');
303233
$this->resultJsonFactory = $this->getMock(
304234
'Magento\Framework\Controller\Result\JsonFactory',
305235
['create'],
306236
[],
307237
'',
308238
false
309239
);
310-
$this->resultJsonFactory
311-
->expects($this->once())
312-
->method('create')
313-
->willReturn($this->resultJson);
314-
240+
$this->resultJsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
315241
$this->getController()->execute();
316242
}
317243

@@ -325,9 +251,7 @@ public function testExecuteWithException()
325251
true,
326252
true
327253
);
328-
$this->customer->expects($this->once())
329-
->method('getWebsiteId')
330-
->willReturn(2);
254+
$this->customer->expects($this->once())->method('getWebsiteId')->willReturn(2);
331255

332256
$this->customerDataFactory = $this->getMock(
333257
'Magento\Customer\Api\Data\CustomerInterfaceFactory',
@@ -336,11 +260,7 @@ public function testExecuteWithException()
336260
'',
337261
false
338262
);
339-
$this->customerDataFactory
340-
->expects($this->once())
341-
->method('create')
342-
->willReturn($this->customer);
343-
263+
$this->customerDataFactory->expects($this->once())->method('create')->willReturn($this->customer);
344264
$this->request = $this->getMockForAbstractClass(
345265
'Magento\Framework\App\RequestInterface',
346266
[],
@@ -350,35 +270,16 @@ public function testExecuteWithException()
350270
true,
351271
['getPost']
352272
);
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([]);
273+
$this->request->expects($this->once())->method('getPost')->willReturn(null);
274+
$this->response = $this->getMockForAbstractClass('Magento\Framework\App\ResponseInterface', [], '',false);
275+
$this->form = $this->getMock('Magento\Customer\Model\Metadata\Form', [], [], '', false);
276+
$this->form->expects($this->once())->method('setInvisibleIgnored');
277+
$this->form->expects($this->atLeastOnce())->method('extractData')->willReturn([]);
374278

375-
$this->form->expects($this->never())
376-
->method('validateData');
279+
$this->form->expects($this->never())->method('validateData');
377280

378281
$this->formFactory = $this->getMock('Magento\Customer\Model\Metadata\FormFactory', ['create'], [], '', false);
379-
$this->formFactory->expects($this->atLeastOnce())
380-
->method('create')
381-
->willReturn($this->form);
282+
$this->formFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->form);
382283

383284
$this->extensibleDataObjectConverter = $this->getMock(
384285
'Magento\Framework\Api\ExtensibleDataObjectConverter',
@@ -387,14 +288,10 @@ public function testExecuteWithException()
387288
'',
388289
false
389290
);
390-
$this->extensibleDataObjectConverter->expects($this->once())
391-
->method('toFlatArray')
392-
->willReturn([]);
291+
$this->extensibleDataObjectConverter->expects($this->once())->method('toFlatArray')->willReturn([]);
393292

394293
$this->dataObjectHelper = $this->getMock('Magento\Framework\Api\DataObjectHelper', [], [], '', false);
395-
$this->dataObjectHelper
396-
->expects($this->once())
397-
->method('populateWithArray');
294+
$this->dataObjectHelper->expects($this->once())->method('populateWithArray');
398295

399296
$this->customerAccountManagement = $this->getMockForAbstractClass(
400297
'Magento\Customer\Api\AccountManagementInterface',
@@ -414,37 +311,24 @@ public function testExecuteWithException()
414311
true
415312
);
416313
$error = $this->getMock('Magento\Framework\Message\Error', [], [], '', false);
417-
$error->expects($this->once())
418-
->method('getText')
419-
->willReturn('Error text');
314+
$error->expects($this->once())->method('getText')->willReturn('Error text');
420315

421316
$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);
317+
$exception->expects($this->once())->method('getMessages')->willReturn([$error]);
318+
$validationResult->expects($this->once())->method('getMessages')->willThrowException($exception);
428319

429-
$this->customerAccountManagement->expects($this->once())
430-
->method('validate')
431-
->willReturn($validationResult);
320+
$this->customerAccountManagement->expects($this->once())->method('validate')->willReturn($validationResult);
432321

433322
$this->resultJson = $this->getMock('Magento\Framework\Controller\Result\Json', [], [], '', false);
434-
$this->resultJson->expects($this->once())
435-
->method('setData');
323+
$this->resultJson->expects($this->once())->method('setData');
436324
$this->resultJsonFactory = $this->getMock(
437325
'Magento\Framework\Controller\Result\JsonFactory',
438326
['create'],
439327
[],
440328
'',
441329
false
442330
);
443-
$this->resultJsonFactory
444-
->expects($this->once())
445-
->method('create')
446-
->willReturn($this->resultJson);
447-
331+
$this->resultJsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
448332
$this->getController()->execute();
449333
}
450334

0 commit comments

Comments
 (0)