Skip to content

Commit 926e6f6

Browse files
author
okarpenko
committed
Merge branch 'MAGETWO-37818' into BUGS
Conflicts: app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ValidateTest.php
2 parents c13c360 + fc02741 commit 926e6f6

File tree

1 file changed

+111
-187
lines changed

1 file changed

+111
-187
lines changed

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

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

87
namespace Magento\Customer\Test\Unit\Controller\Adminhtml\Index;
98

@@ -60,7 +59,10 @@ class ValidateTest extends \PHPUnit_Framework_TestCase
6059
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Controller\Result\Json */
6160
protected $resultJson;
6261

63-
public function testExecute()
62+
/** @var \Magento\Customer\Controller\Adminhtml\Index\Validate */
63+
protected $controller;
64+
65+
public function setUp()
6466
{
6567
$this->customer = $this->getMockForAbstractClass(
6668
'Magento\Customer\Api\Data\CustomerInterface',
@@ -71,7 +73,6 @@ public function testExecute()
7173
true
7274
);
7375
$this->customer->expects($this->once())->method('getWebsiteId')->willReturn(2);
74-
7576
$this->customerDataFactory = $this->getMock(
7677
'Magento\Customer\Api\Data\CustomerInterfaceFactory',
7778
['create'],
@@ -80,7 +81,13 @@ public function testExecute()
8081
false
8182
);
8283
$this->customerDataFactory->expects($this->once())->method('create')->willReturn($this->customer);
83-
84+
$this->form = $this->getMock(
85+
'Magento\Customer\Model\Metadata\Form',
86+
[],
87+
[],
88+
'',
89+
false
90+
);
8491
$this->request = $this->getMockForAbstractClass(
8592
'Magento\Framework\App\RequestInterface',
8693
[],
@@ -90,35 +97,23 @@ public function testExecute()
9097
true,
9198
['getPost']
9299
);
93-
$this->request->expects($this->once())
94-
->method('getPost')
95-
->willReturn([
96-
'_template_' => null,
97-
'address_index' => null
98-
]);
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([]);
103-
104-
$error = $this->getMock('Magento\Framework\Message\Error', [], [], '', false);
105-
$this->form->expects($this->once())->method('validateData')->willReturn([$error]);
106-
100+
$this->response = $this->getMockForAbstractClass(
101+
'Magento\Framework\App\ResponseInterface',
102+
[],
103+
'',
104+
false
105+
);
107106
$this->formFactory = $this->getMock('Magento\Customer\Model\Metadata\FormFactory', ['create'], [], '', false);
108107
$this->formFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->form);
109-
110108
$this->extensibleDataObjectConverter = $this->getMock(
111109
'Magento\Framework\Api\ExtensibleDataObjectConverter',
112110
[],
113111
[],
114112
'',
115113
false
116114
);
117-
$this->extensibleDataObjectConverter->expects($this->once())->method('toFlatArray')->willReturn([]);
118-
119115
$this->dataObjectHelper = $this->getMock('Magento\Framework\Api\DataObjectHelper', [], [], '', false);
120116
$this->dataObjectHelper->expects($this->once())->method('populateWithArray');
121-
122117
$this->customerAccountManagement = $this->getMockForAbstractClass(
123118
'Magento\Customer\Api\AccountManagementInterface',
124119
[],
@@ -127,19 +122,6 @@ public function testExecute()
127122
true,
128123
true
129124
);
130-
131-
$validationResult = $this->getMockForAbstractClass(
132-
'Magento\Customer\Api\Data\ValidationResultsInterface',
133-
[],
134-
'',
135-
false,
136-
true,
137-
true
138-
);
139-
$validationResult->expects($this->once())->method('getMessages')->willReturn(['Error message']);
140-
141-
$this->customerAccountManagement->expects($this->once())->method('validate')->willReturn($validationResult);
142-
143125
$this->resultJson = $this->getMock('Magento\Framework\Controller\Result\Json', [], [], '', false);
144126
$this->resultJson->expects($this->once())->method('setData');
145127
$this->resultJsonFactory = $this->getMock(
@@ -150,71 +132,43 @@ public function testExecute()
150132
false
151133
);
152134
$this->resultJsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
153-
$this->getController()->execute();
154-
}
155135

156-
public function testExecuteWithoutAddresses()
157-
{
158-
$this->customer = $this->getMockForAbstractClass(
159-
'Magento\Customer\Api\Data\CustomerInterface',
160-
[],
161-
'',
162-
false,
163-
true,
164-
true
136+
$objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
137+
$this->controller = $objectHelper->getObject(
138+
'Magento\Customer\Controller\Adminhtml\Index\Validate',
139+
[
140+
'request' => $this->request,
141+
'response' => $this->response,
142+
'customerDataFactory' => $this->customerDataFactory,
143+
'formFactory' => $this->formFactory,
144+
'extensibleDataObjectConverter' => $this->extensibleDataObjectConverter,
145+
'customerAccountManagement' => $this->customerAccountManagement,
146+
'resultJsonFactory' => $this->resultJsonFactory,
147+
'dataObjectHelper' => $this->dataObjectHelper,
148+
]
165149
);
166-
$this->customer->expects($this->once())->method('getWebsiteId')->willReturn(2);
150+
}
167151

168-
$this->customerDataFactory = $this->getMock(
169-
'Magento\Customer\Api\Data\CustomerInterfaceFactory',
170-
['create'],
171-
[],
172-
'',
173-
false
174-
);
175-
$this->customerDataFactory->expects($this->once())->method('create')->willReturn($this->customer);
152+
public function testExecute()
153+
{
154+
$this->request->expects($this->once())
155+
->method('getPost')
156+
->willReturn([
157+
'_template_' => null,
158+
'address_index' => null
159+
]);
176160

177-
$this->request = $this->getMockForAbstractClass(
178-
'Magento\Framework\App\RequestInterface',
179-
[],
180-
'',
181-
false,
182-
true,
183-
true,
184-
['getPost']
185-
);
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);
189161
$this->form->expects($this->once())->method('setInvisibleIgnored');
190162
$this->form->expects($this->atLeastOnce())->method('extractData')->willReturn([]);
191163

192164
$error = $this->getMock('Magento\Framework\Message\Error', [], [], '', false);
193-
$this->form->expects($this->never())->method('validateData')->willReturn([$error]);
194-
195-
$this->formFactory = $this->getMock('Magento\Customer\Model\Metadata\FormFactory', ['create'], [], '', false);
196-
$this->formFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->form);
165+
$this->form->expects($this->once())
166+
->method('validateData')
167+
->willReturn([$error]);
197168

198-
$this->extensibleDataObjectConverter = $this->getMock(
199-
'Magento\Framework\Api\ExtensibleDataObjectConverter',
200-
[],
201-
[],
202-
'',
203-
false
204-
);
205-
$this->extensibleDataObjectConverter->expects($this->once())->method('toFlatArray')->willReturn([]);
206-
207-
$this->dataObjectHelper = $this->getMock('Magento\Framework\Api\DataObjectHelper', [], [], '', false);
208-
$this->dataObjectHelper->expects($this->once())->method('populateWithArray');
209-
210-
$this->customerAccountManagement = $this->getMockForAbstractClass(
211-
'Magento\Customer\Api\AccountManagementInterface',
212-
[],
213-
'',
214-
false,
215-
true,
216-
true
217-
);
169+
$this->extensibleDataObjectConverter->expects($this->once())
170+
->method('toFlatArray')
171+
->willReturn([]);
218172

219173
$validationResult = $this->getMockForAbstractClass(
220174
'Magento\Customer\Api\Data\ValidationResultsInterface',
@@ -224,83 +178,73 @@ public function testExecuteWithoutAddresses()
224178
true,
225179
true
226180
);
227-
$validationResult->expects($this->once())->method('getMessages')->willReturn(['Error message']);
181+
$validationResult->expects($this->once())
182+
->method('getMessages')
183+
->willReturn(['Error message']);
228184

229-
$this->customerAccountManagement->expects($this->once())->method('validate')->willReturn($validationResult);
185+
$this->customerAccountManagement->expects($this->once())
186+
->method('validate')
187+
->willReturn($validationResult);
230188

231-
$this->resultJson = $this->getMock('Magento\Framework\Controller\Result\Json', [], [], '', false);
232-
$this->resultJson->expects($this->once())->method('setData');
233-
$this->resultJsonFactory = $this->getMock(
234-
'Magento\Framework\Controller\Result\JsonFactory',
235-
['create'],
236-
[],
237-
'',
238-
false
239-
);
240-
$this->resultJsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
241-
$this->getController()->execute();
189+
$this->controller->execute();
242190
}
243191

244-
public function testExecuteWithException()
192+
public function testExecuteWithoutAddresses()
245193
{
246-
$this->customer = $this->getMockForAbstractClass(
247-
'Magento\Customer\Api\Data\CustomerInterface',
248-
[],
249-
'',
250-
false,
251-
true,
252-
true
253-
);
254-
$this->customer->expects($this->once())->method('getWebsiteId')->willReturn(2);
194+
$this->request->expects($this->once())
195+
->method('getPost')
196+
->willReturn(null);
197+
$this->form->expects($this->once())
198+
->method('setInvisibleIgnored');
199+
$this->form->expects($this->atLeastOnce())
200+
->method('extractData')
201+
->willReturn([]);
255202

256-
$this->customerDataFactory = $this->getMock(
257-
'Magento\Customer\Api\Data\CustomerInterfaceFactory',
258-
['create'],
259-
[],
260-
'',
261-
false
262-
);
263-
$this->customerDataFactory->expects($this->once())->method('create')->willReturn($this->customer);
264-
$this->request = $this->getMockForAbstractClass(
265-
'Magento\Framework\App\RequestInterface',
203+
$error = $this->getMock('Magento\Framework\Message\Error', [], [], '', false);
204+
$this->form->expects($this->never())
205+
->method('validateData')
206+
->willReturn([$error]);
207+
208+
$this->extensibleDataObjectConverter->expects($this->once())
209+
->method('toFlatArray')
210+
->willReturn([]);
211+
212+
$validationResult = $this->getMockForAbstractClass(
213+
'Magento\Customer\Api\Data\ValidationResultsInterface',
266214
[],
267215
'',
268216
false,
269217
true,
270-
true,
271-
['getPost']
218+
true
272219
);
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([]);
220+
$validationResult->expects($this->once())
221+
->method('getMessages')
222+
->willReturn(['Error message']);
278223

279-
$this->form->expects($this->never())->method('validateData');
224+
$this->customerAccountManagement->expects($this->once())
225+
->method('validate')
226+
->willReturn($validationResult);
280227

281-
$this->formFactory = $this->getMock('Magento\Customer\Model\Metadata\FormFactory', ['create'], [], '', false);
282-
$this->formFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->form);
228+
$this->controller->execute();
229+
}
283230

284-
$this->extensibleDataObjectConverter = $this->getMock(
285-
'Magento\Framework\Api\ExtensibleDataObjectConverter',
286-
[],
287-
[],
288-
'',
289-
false
290-
);
291-
$this->extensibleDataObjectConverter->expects($this->once())->method('toFlatArray')->willReturn([]);
231+
public function testExecuteWithException()
232+
{
233+
$this->request->expects($this->once())
234+
->method('getPost')
235+
->willReturn(null);
236+
$this->form->expects($this->once())
237+
->method('setInvisibleIgnored');
238+
$this->form->expects($this->atLeastOnce())
239+
->method('extractData')
240+
->willReturn([]);
292241

293-
$this->dataObjectHelper = $this->getMock('Magento\Framework\Api\DataObjectHelper', [], [], '', false);
294-
$this->dataObjectHelper->expects($this->once())->method('populateWithArray');
242+
$this->form->expects($this->never())
243+
->method('validateData');
295244

296-
$this->customerAccountManagement = $this->getMockForAbstractClass(
297-
'Magento\Customer\Api\AccountManagementInterface',
298-
[],
299-
'',
300-
false,
301-
true,
302-
true
303-
);
245+
$this->extensibleDataObjectConverter->expects($this->once())
246+
->method('toFlatArray')
247+
->willReturn([]);
304248

305249
$validationResult = $this->getMockForAbstractClass(
306250
'Magento\Customer\Api\Data\ValidationResultsInterface',
@@ -311,42 +255,22 @@ public function testExecuteWithException()
311255
true
312256
);
313257
$error = $this->getMock('Magento\Framework\Message\Error', [], [], '', false);
314-
$error->expects($this->once())->method('getText')->willReturn('Error text');
258+
$error->expects($this->once())
259+
->method('getText')
260+
->willReturn('Error text');
315261

316262
$exception = $this->getMock('Magento\Framework\Validator\Exception', [], [], '', false);
317-
$exception->expects($this->once())->method('getMessages')->willReturn([$error]);
318-
$validationResult->expects($this->once())->method('getMessages')->willThrowException($exception);
319-
320-
$this->customerAccountManagement->expects($this->once())->method('validate')->willReturn($validationResult);
321-
322-
$this->resultJson = $this->getMock('Magento\Framework\Controller\Result\Json', [], [], '', false);
323-
$this->resultJson->expects($this->once())->method('setData');
324-
$this->resultJsonFactory = $this->getMock(
325-
'Magento\Framework\Controller\Result\JsonFactory',
326-
['create'],
327-
[],
328-
'',
329-
false
330-
);
331-
$this->resultJsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
332-
$this->getController()->execute();
333-
}
334-
335-
public function getController()
336-
{
337-
$objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
338-
return $objectHelper->getObject(
339-
'Magento\Customer\Controller\Adminhtml\Index\Validate',
340-
[
341-
'request' => $this->request,
342-
'response' => $this->response,
343-
'customerDataFactory' => $this->customerDataFactory,
344-
'formFactory' => $this->formFactory,
345-
'extensibleDataObjectConverter' => $this->extensibleDataObjectConverter,
346-
'customerAccountManagement' => $this->customerAccountManagement,
347-
'resultJsonFactory' => $this->resultJsonFactory,
348-
'dataObjectHelper' => $this->dataObjectHelper,
349-
]
350-
);
263+
$exception->expects($this->once())
264+
->method('getMessages')
265+
->willReturn([$error]);
266+
$validationResult->expects($this->once())
267+
->method('getMessages')
268+
->willThrowException($exception);
269+
270+
$this->customerAccountManagement->expects($this->once())
271+
->method('validate')
272+
->willReturn($validationResult);
273+
274+
$this->controller->execute();
351275
}
352276
}

0 commit comments

Comments
 (0)