11
11
use Magento \Catalog \Model \Product ;
12
12
use Magento \Framework \Api \Data \ImageContentInterface ;
13
13
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
14
+ use Magento \Catalog \Model \Product \Attribute \Source \Status as Status ;
14
15
15
16
/**
16
17
* Product Test
@@ -156,6 +157,11 @@ class ProductTest extends \PHPUnit_Framework_TestCase
156
157
*/
157
158
protected $ entityCollectionProviderMock ;
158
159
160
+ /**
161
+ * @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
162
+ */
163
+ protected $ eventManagerMock ;
164
+
159
165
/**
160
166
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
161
167
*/
@@ -203,7 +209,7 @@ public function setUp()
203
209
->method ('getAreaCode ' )
204
210
->will ($ this ->returnValue (\Magento \Backend \App \Area \FrontNameResolver::AREA_CODE ));
205
211
206
- $ eventManagerMock = $ this ->getMock ('Magento\Framework\Event\ManagerInterface ' );
212
+ $ this -> eventManagerMock = $ this ->getMock ('Magento\Framework\Event\ManagerInterface ' );
207
213
$ actionValidatorMock = $ this ->getMock (
208
214
'\Magento\Framework\Model\ActionValidator\RemoveAction ' ,
209
215
[],
@@ -219,7 +225,9 @@ public function setUp()
219
225
['getEventDispatcher ' , 'getCacheManager ' , 'getAppState ' , 'getActionValidator ' ], [], '' , false
220
226
);
221
227
$ contextMock ->expects ($ this ->any ())->method ('getAppState ' )->will ($ this ->returnValue ($ stateMock ));
222
- $ contextMock ->expects ($ this ->any ())->method ('getEventDispatcher ' )->will ($ this ->returnValue ($ eventManagerMock ));
228
+ $ contextMock ->expects ($ this ->any ())
229
+ ->method ('getEventDispatcher ' )
230
+ ->will ($ this ->returnValue ($ this ->eventManagerMock ));
223
231
$ contextMock ->expects ($ this ->any ())
224
232
->method ('getCacheManager ' )
225
233
->will ($ this ->returnValue ($ cacheInterfaceMock ));
@@ -415,16 +423,20 @@ public function testGetCategoryIds()
415
423
$ this ->assertEquals ([], $ this ->model ->getCategoryIds ());
416
424
}
417
425
426
+ public function testGetStatusInitial ()
427
+ {
428
+ $ this ->assertEquals (Status::STATUS_ENABLED , $ this ->model ->getStatus ());
429
+ }
430
+
418
431
public function testGetStatus ()
419
432
{
420
433
$ this ->model ->setStatus (null );
421
- $ expected = \Magento \Catalog \Model \Product \Attribute \Source \Status::STATUS_ENABLED ;
422
- $ this ->assertEquals ($ expected , $ this ->model ->getStatus ());
434
+ $ this ->assertEquals (Status::STATUS_ENABLED , $ this ->model ->getStatus ());
423
435
}
424
436
425
437
public function testIsInStock ()
426
438
{
427
- $ this ->model ->setStatus (\ Magento \ Catalog \ Model \ Product \ Attribute \ Source \ Status::STATUS_ENABLED );
439
+ $ this ->model ->setStatus (Status::STATUS_ENABLED );
428
440
$ this ->assertTrue ($ this ->model ->isInStock ());
429
441
}
430
442
@@ -521,12 +533,12 @@ public function testGetIdentities($expected, $origData, $data, $isDeleted = fals
521
533
public function getIdentitiesProvider ()
522
534
{
523
535
return [
524
- [
536
+ ' no changes ' => [
525
537
['catalog_product_1 ' ],
526
538
['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [1 ]],
527
539
['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [1 ]],
528
540
],
529
- [
541
+ ' new product ' => [
530
542
['catalog_product_1 ' , 'catalog_category_product_1 ' ],
531
543
null ,
532
544
[
@@ -537,24 +549,57 @@ public function getIdentitiesProvider()
537
549
'is_changed_categories ' => true
538
550
]
539
551
],
540
- [
541
- [0 => 'catalog_product_1 ' , 1 => 'catalog_category_product_1 ' ],
552
+ ' status and category change ' => [
553
+ [0 => 'catalog_product_1 ' , 1 => 'catalog_category_product_1 ' , 2 => ' catalog_category_product_2 ' ],
542
554
['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [1 ], 'status ' => 2 ],
543
- ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [1 ], 'status ' => 1 ],
555
+ [
556
+ 'id ' => 1 ,
557
+ 'name ' => 'value ' ,
558
+ 'category_ids ' => [2 ],
559
+ 'status ' => 1 ,
560
+ 'affected_category_ids ' => [1 , 2 ],
561
+ 'is_changed_categories ' => true
562
+ ],
544
563
],
545
- [
546
- [0 => 'catalog_product_1 ' ],
547
- ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [1 ], 'status ' => 1 ],
548
- ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [1 ], 'status ' => 2 ],
564
+ ' status change only ' => [
565
+ [0 => 'catalog_product_1 ' , 1 => ' catalog_category_product_7 ' ],
566
+ ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [7 ], 'status ' => 1 ],
567
+ ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [7 ], 'status ' => 2 ],
549
568
],
550
- [
569
+ 'status changed, category unassigned ' => [
570
+ [0 => 'catalog_product_1 ' , 1 => 'catalog_category_product_5 ' ],
571
+ ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [5 ], 'status ' => 2 ],
572
+ [
573
+ 'id ' => 1 ,
574
+ 'name ' => 'value ' ,
575
+ 'category_ids ' => [],
576
+ 'status ' => 1 ,
577
+ 'is_changed_categories ' => true ,
578
+ 'affected_category_ids ' => [5 ]
579
+ ],
580
+ ],
581
+ 'no status changes ' => [
551
582
[0 => 'catalog_product_1 ' ],
552
- ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [1 ], 'status ' => 2 ],
553
- ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [], 'status ' => 1 ],
583
+ ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [1 ], 'status ' => 1 ],
584
+ ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [1 ], 'status ' => 1 ],
554
585
]
555
586
];
556
587
}
557
588
589
+ public function testStatusAfterLoad ()
590
+ {
591
+ $ this ->resource ->expects ($ this ->once ())->method ('load ' )->with ($ this ->model , 1 , null );
592
+ $ this ->eventManagerMock ->expects ($ this ->exactly (4 ))->method ('dispatch ' );
593
+ $ this ->model ->load (1 );
594
+ $ this ->assertEquals (
595
+ Status::STATUS_ENABLED ,
596
+ $ this ->model ->getData (\Magento \Catalog \Model \Product::STATUS )
597
+ );
598
+ $ this ->assertFalse ($ this ->model ->hasDataChanges ());
599
+ $ this ->model ->setStatus (Status::STATUS_DISABLED );
600
+ $ this ->assertTrue ($ this ->model ->hasDataChanges ());
601
+ }
602
+
558
603
/**
559
604
* Test retrieving price Info
560
605
*/
0 commit comments