@@ -36,6 +36,9 @@ class IndexTest extends \Magento\TestFramework\TestCase\AbstractBackendControlle
36
36
/** @var \Magento\Framework\Data\Form\FormKey */
37
37
protected $ formKey ;
38
38
39
+ /** @var \Magento\TestFramework\ObjectManager */
40
+ protected $ objectManager ;
41
+
39
42
protected function setUp ()
40
43
{
41
44
parent ::setUp ();
@@ -53,6 +56,8 @@ protected function setUp()
53
56
$ this ->formKey = Bootstrap::getObjectManager ()->get (
54
57
'Magento\Framework\Data\Form\FormKey '
55
58
);
59
+
60
+ $ this ->objectManager = Bootstrap::getObjectManager ();
56
61
}
57
62
58
63
protected function tearDown ()
@@ -98,7 +103,7 @@ public function testSaveActionWithInvalidFormData()
98
103
*/
99
104
$ this ->assertEquals (
100
105
$ post ,
101
- Bootstrap:: getObjectManager () ->get ('Magento\Backend\Model\Session ' )->getCustomerData ()
106
+ $ this -> objectManager ->get ('Magento\Backend\Model\Session ' )->getCustomerData ()
102
107
);
103
108
$ this ->assertRedirect ($ this ->stringStartsWith ($ this ->_baseControllerUrl . 'new ' ));
104
109
}
@@ -134,7 +139,7 @@ public function testSaveActionWithInvalidCustomerAddressData()
134
139
*/
135
140
$ this ->assertEquals (
136
141
$ post ,
137
- Bootstrap:: getObjectManager () ->get ('Magento\Backend\Model\Session ' )->getCustomerData ()
142
+ $ this -> objectManager ->get ('Magento\Backend\Model\Session ' )->getCustomerData ()
138
143
);
139
144
$ this ->assertRedirect ($ this ->stringStartsWith ($ this ->_baseControllerUrl . 'new ' ));
140
145
}
@@ -144,9 +149,6 @@ public function testSaveActionWithInvalidCustomerAddressData()
144
149
*/
145
150
public function testSaveActionWithValidCustomerDataAndValidAddressData ()
146
151
{
147
- /** @var $objectManager \Magento\TestFramework\ObjectManager */
148
- $ objectManager = Bootstrap::getObjectManager ();
149
-
150
152
$ post = [
151
153
'customer ' => [
152
154
'middlename ' => 'test middlename ' ,
@@ -176,7 +178,7 @@ public function testSaveActionWithValidCustomerDataAndValidAddressData()
176
178
$ this ->getRequest ()->setParam ('back ' , '1 ' );
177
179
178
180
// Emulate setting customer data to session in editAction
179
- $ objectManager ->get ('Magento\Backend\Model\Session ' )->setCustomerData ($ post );
181
+ $ this -> objectManager ->get ('Magento\Backend\Model\Session ' )->setCustomerData ($ post );
180
182
181
183
$ this ->dispatch ('backend/customer/index/save ' );
182
184
/**
@@ -187,7 +189,7 @@ public function testSaveActionWithValidCustomerDataAndValidAddressData()
187
189
/**
188
190
* Check that customer data were cleaned after it was saved successfully
189
191
*/
190
- $ this ->assertEmpty ($ objectManager ->get ('Magento\Backend\Model\Session ' )->getCustomerData ());
192
+ $ this ->assertEmpty ($ this -> objectManager ->get ('Magento\Backend\Model\Session ' )->getCustomerData ());
191
193
192
194
/**
193
195
* Check that success message is set
@@ -200,7 +202,7 @@ public function testSaveActionWithValidCustomerDataAndValidAddressData()
200
202
/**
201
203
* Check that customer id set and addresses saved
202
204
*/
203
- $ registry = $ objectManager ->get ('Magento\Framework\Registry ' );
205
+ $ registry = $ this -> objectManager ->get ('Magento\Framework\Registry ' );
204
206
$ customerId = $ registry ->registry (RegistryConstants::CURRENT_CUSTOMER_ID );
205
207
$ customer = $ this ->customerRepository ->getById ($ customerId );
206
208
$ this ->assertEquals ('test firstname ' , $ customer ->getFirstname ());
@@ -214,7 +216,7 @@ public function testSaveActionWithValidCustomerDataAndValidAddressData()
214
216
);
215
217
216
218
/** @var \Magento\Newsletter\Model\Subscriber $subscriber */
217
- $ subscriber = $ objectManager ->get ('Magento\Newsletter\Model\SubscriberFactory ' )->create ();
219
+ $ subscriber = $ this -> objectManager ->get ('Magento\Newsletter\Model\SubscriberFactory ' )->create ();
218
220
$ this ->assertEmpty ($ subscriber ->getId ());
219
221
$ subscriber ->loadByCustomerId ($ customerId );
220
222
$ this ->assertEmpty ($ subscriber ->getId ());
@@ -280,21 +282,15 @@ public function testSaveActionExistingCustomerAndExistingAddressData()
280
282
$ this ->getRequest ()->setPostValue ($ post );
281
283
$ this ->getRequest ()->setParam ('id ' , 1 );
282
284
$ this ->dispatch ('backend/customer/index/save ' );
283
- /**
284
- * Check that success message is set
285
- */
285
+
286
+ /** Check that success message is set */
286
287
$ this ->assertSessionMessages (
287
288
$ this ->equalTo (['You saved the customer. ' ]),
288
289
\Magento \Framework \Message \MessageInterface::TYPE_SUCCESS
289
290
);
290
291
291
- /** @var $objectManager \Magento\TestFramework\ObjectManager */
292
- $ objectManager = Bootstrap::getObjectManager ();
293
-
294
- /**
295
- * Check that customer id set and addresses saved
296
- */
297
- $ registry = $ objectManager ->get ('Magento\Framework\Registry ' );
292
+ /** Check that customer id set and addresses saved */
293
+ $ registry = $ this ->objectManager ->get ('Magento\Framework\Registry ' );
298
294
$ customerId = $ registry ->registry (RegistryConstants::CURRENT_CUSTOMER_ID );
299
295
$ customer = $ this ->customerRepository ->getById ($ customerId );
300
296
$ this ->assertEquals ('test firstname ' , $ customer ->getFirstname ());
@@ -315,12 +311,11 @@ public function testSaveActionExistingCustomerAndExistingAddressData()
315
311
$ this ->assertEquals ('new firstname ' , $ newAddress ->getFirstname ());
316
312
317
313
/** @var \Magento\Newsletter\Model\Subscriber $subscriber */
318
- $ subscriber = $ objectManager ->get ('Magento\Newsletter\Model\SubscriberFactory ' )->create ();
314
+ $ subscriber = $ this -> objectManager ->get ('Magento\Newsletter\Model\SubscriberFactory ' )->create ();
319
315
$ this ->assertEmpty ($ subscriber ->getId ());
320
316
$ subscriber ->loadByCustomerId ($ customerId );
321
317
$ this ->assertNotEmpty ($ subscriber ->getId ());
322
318
$ this ->assertEquals (1 , $ subscriber ->getStatus ());
323
-
324
319
$ this ->assertRedirect ($ this ->stringStartsWith ($ this ->_baseControllerUrl . 'index/key/ ' ));
325
320
}
326
321
@@ -330,11 +325,9 @@ public function testSaveActionExistingCustomerAndExistingAddressData()
330
325
public function testSaveActionExistingCustomerUnsubscribeNewsletter ()
331
326
{
332
327
$ customerId = 1 ;
333
- /** @var $objectManager \Magento\TestFramework\ObjectManager */
334
- $ objectManager = Bootstrap::getObjectManager ();
335
328
336
329
/** @var \Magento\Newsletter\Model\Subscriber $subscriber */
337
- $ subscriber = $ objectManager ->get ('Magento\Newsletter\Model\SubscriberFactory ' )->create ();
330
+ $ subscriber = $ this -> objectManager ->get ('Magento\Newsletter\Model\SubscriberFactory ' )->create ();
338
331
$ this ->assertEmpty ($ subscriber ->getId ());
339
332
$ subscriber ->loadByCustomerId ($ customerId );
340
333
$ this ->assertNotEmpty ($ subscriber ->getId ());
@@ -349,7 +342,7 @@ public function testSaveActionExistingCustomerUnsubscribeNewsletter()
349
342
$ this ->dispatch ('backend/customer/index/save ' );
350
343
351
344
/** @var \Magento\Newsletter\Model\Subscriber $subscriber */
352
- $ subscriber = $ objectManager ->get ('Magento\Newsletter\Model\SubscriberFactory ' )->create ();
345
+ $ subscriber = $ this -> objectManager ->get ('Magento\Newsletter\Model\SubscriberFactory ' )->create ();
353
346
$ this ->assertEmpty ($ subscriber ->getId ());
354
347
$ subscriber ->loadByCustomerId ($ customerId );
355
348
$ this ->assertNotEmpty ($ subscriber ->getId ());
0 commit comments