Skip to content

Commit 9b451a0

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

File tree

1 file changed

+44
-235
lines changed

1 file changed

+44
-235
lines changed

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

Lines changed: 44 additions & 235 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ValidateTest extends \PHPUnit_Framework_TestCase
6060
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Controller\Result\Json */
6161
protected $resultJson;
6262

63-
public function testExecute()
63+
public function setUp()
6464
{
6565
$this->customer = $this->getMockForAbstractClass(
6666
'Magento\Customer\Api\Data\CustomerInterface',
@@ -70,22 +70,22 @@ public function testExecute()
7070
true,
7171
true
7272
);
73-
$this->customer->expects($this->once())
74-
->method('getWebsiteId')
75-
->willReturn(2);
76-
73+
$this->customer->expects($this->once())->method('getWebsiteId')->willReturn(2);
7774
$this->customerDataFactory = $this->getMock(
7875
'Magento\Customer\Api\Data\CustomerInterfaceFactory',
7976
['create'],
8077
[],
8178
'',
8279
false
8380
);
84-
$this->customerDataFactory
85-
->expects($this->once())
86-
->method('create')
87-
->willReturn($this->customer);
88-
81+
$this->customerDataFactory->expects($this->once())->method('create')->willReturn($this->customer);
82+
$this->form = $this->getMock(
83+
'Magento\Customer\Model\Metadata\Form',
84+
[],
85+
[],
86+
'',
87+
false
88+
);
8989
$this->request = $this->getMockForAbstractClass(
9090
'Magento\Framework\App\RequestInterface',
9191
[],
@@ -95,57 +95,23 @@ public function testExecute()
9595
true,
9696
['getPost']
9797
);
98-
$this->request->expects($this->once())
99-
->method('getPost')
100-
->willReturn([
101-
'_template_' => null,
102-
'address_index' => null
103-
]);
10498
$this->response = $this->getMockForAbstractClass(
10599
'Magento\Framework\App\ResponseInterface',
106100
[],
107101
'',
108102
false
109103
);
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([]);
122-
123-
$error = $this->getMock('Magento\Framework\Message\Error', [], [], '', false);
124-
$this->form->expects($this->once())
125-
->method('validateData')
126-
->willReturn([$error]);
127-
128104
$this->formFactory = $this->getMock('Magento\Customer\Model\Metadata\FormFactory', ['create'], [], '', false);
129-
$this->formFactory->expects($this->atLeastOnce())
130-
->method('create')
131-
->willReturn($this->form);
132-
105+
$this->formFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->form);
133106
$this->extensibleDataObjectConverter = $this->getMock(
134107
'Magento\Framework\Api\ExtensibleDataObjectConverter',
135108
[],
136109
[],
137110
'',
138111
false
139112
);
140-
$this->extensibleDataObjectConverter->expects($this->once())
141-
->method('toFlatArray')
142-
->willReturn([]);
143-
144113
$this->dataObjectHelper = $this->getMock('Magento\Framework\Api\DataObjectHelper', [], [], '', false);
145-
$this->dataObjectHelper
146-
->expects($this->once())
147-
->method('populateWithArray');
148-
114+
$this->dataObjectHelper->expects($this->once())->method('populateWithArray');
149115
$this->customerAccountManagement = $this->getMockForAbstractClass(
150116
'Magento\Customer\Api\AccountManagementInterface',
151117
[],
@@ -154,6 +120,38 @@ public function testExecute()
154120
true,
155121
true
156122
);
123+
$this->resultJson = $this->getMock('Magento\Framework\Controller\Result\Json', [], [], '', false);
124+
$this->resultJson->expects($this->once())->method('setData');
125+
$this->resultJsonFactory = $this->getMock(
126+
'Magento\Framework\Controller\Result\JsonFactory',
127+
['create'],
128+
[],
129+
'',
130+
false
131+
);
132+
$this->resultJsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
133+
}
134+
135+
public function testExecute()
136+
{
137+
$this->request->expects($this->once())
138+
->method('getPost')
139+
->willReturn([
140+
'_template_' => null,
141+
'address_index' => null
142+
]);
143+
144+
$this->form->expects($this->once())->method('setInvisibleIgnored');
145+
$this->form->expects($this->atLeastOnce())->method('extractData')->willReturn([]);
146+
147+
$error = $this->getMock('Magento\Framework\Message\Error', [], [], '', false);
148+
$this->form->expects($this->once())
149+
->method('validateData')
150+
->willReturn([$error]);
151+
152+
$this->extensibleDataObjectConverter->expects($this->once())
153+
->method('toFlatArray')
154+
->willReturn([]);
157155

158156
$validationResult = $this->getMockForAbstractClass(
159157
'Magento\Customer\Api\Data\ValidationResultsInterface',
@@ -171,75 +169,14 @@ public function testExecute()
171169
->method('validate')
172170
->willReturn($validationResult);
173171

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-
189172
$this->getController()->execute();
190173
}
191174

192175
public function testExecuteWithoutAddresses()
193176
{
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-
);
227177
$this->request->expects($this->once())
228178
->method('getPost')
229179
->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-
);
243180
$this->form->expects($this->once())
244181
->method('setInvisibleIgnored');
245182
$this->form->expects($this->atLeastOnce())
@@ -251,36 +188,10 @@ public function testExecuteWithoutAddresses()
251188
->method('validateData')
252189
->willReturn([$error]);
253190

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-
);
266191
$this->extensibleDataObjectConverter->expects($this->once())
267192
->method('toFlatArray')
268193
->willReturn([]);
269194

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-
284195
$validationResult = $this->getMockForAbstractClass(
285196
'Magento\Customer\Api\Data\ValidationResultsInterface',
286197
[],
@@ -297,75 +208,14 @@ public function testExecuteWithoutAddresses()
297208
->method('validate')
298209
->willReturn($validationResult);
299210

300-
$this->resultJson = $this->getMock('Magento\Framework\Controller\Result\Json', [], [], '', false);
301-
$this->resultJson->expects($this->once())
302-
->method('setData');
303-
$this->resultJsonFactory = $this->getMock(
304-
'Magento\Framework\Controller\Result\JsonFactory',
305-
['create'],
306-
[],
307-
'',
308-
false
309-
);
310-
$this->resultJsonFactory
311-
->expects($this->once())
312-
->method('create')
313-
->willReturn($this->resultJson);
314-
315211
$this->getController()->execute();
316212
}
317213

318214
public function testExecuteWithException()
319215
{
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-
);
353216
$this->request->expects($this->once())
354217
->method('getPost')
355218
->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-
);
369219
$this->form->expects($this->once())
370220
->method('setInvisibleIgnored');
371221
$this->form->expects($this->atLeastOnce())
@@ -375,36 +225,10 @@ public function testExecuteWithException()
375225
$this->form->expects($this->never())
376226
->method('validateData');
377227

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-
);
390228
$this->extensibleDataObjectConverter->expects($this->once())
391229
->method('toFlatArray')
392230
->willReturn([]);
393231

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-
408232
$validationResult = $this->getMockForAbstractClass(
409233
'Magento\Customer\Api\Data\ValidationResultsInterface',
410234
[],
@@ -430,21 +254,6 @@ public function testExecuteWithException()
430254
->method('validate')
431255
->willReturn($validationResult);
432256

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-
448257
$this->getController()->execute();
449258
}
450259

0 commit comments

Comments
 (0)