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
@@ -523,12 +535,12 @@ public function testGetIdentities($expected, $origData, $data, $isDeleted = fals
523
535
public function getIdentitiesProvider ()
524
536
{
525
537
return [
526
- [
538
+ ' no changes ' => [
527
539
['catalog_product_1 ' ],
528
540
['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [1 ]],
529
541
['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [1 ]],
530
542
],
531
- [
543
+ ' new product ' => [
532
544
['catalog_product_1 ' , 'catalog_category_product_1 ' ],
533
545
null ,
534
546
[
@@ -539,24 +551,57 @@ public function getIdentitiesProvider()
539
551
'is_changed_categories ' => true
540
552
]
541
553
],
542
- [
543
- [0 => 'catalog_product_1 ' , 1 => 'catalog_category_product_1 ' ],
554
+ ' status and category change ' => [
555
+ [0 => 'catalog_product_1 ' , 1 => 'catalog_category_product_1 ' , 2 => ' catalog_category_product_2 ' ],
544
556
['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [1 ], 'status ' => 2 ],
545
- ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [1 ], 'status ' => 1 ],
557
+ [
558
+ 'id ' => 1 ,
559
+ 'name ' => 'value ' ,
560
+ 'category_ids ' => [2 ],
561
+ 'status ' => 1 ,
562
+ 'affected_category_ids ' => [1 , 2 ],
563
+ 'is_changed_categories ' => true
564
+ ],
546
565
],
547
- [
548
- [0 => 'catalog_product_1 ' ],
549
- ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [1 ], 'status ' => 1 ],
550
- ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [1 ], 'status ' => 2 ],
566
+ ' status change only ' => [
567
+ [0 => 'catalog_product_1 ' , 1 => ' catalog_category_product_7 ' ],
568
+ ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [7 ], 'status ' => 1 ],
569
+ ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [7 ], 'status ' => 2 ],
551
570
],
552
- [
571
+ 'status changed, category unassigned ' => [
572
+ [0 => 'catalog_product_1 ' , 1 => 'catalog_category_product_5 ' ],
573
+ ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [5 ], 'status ' => 2 ],
574
+ [
575
+ 'id ' => 1 ,
576
+ 'name ' => 'value ' ,
577
+ 'category_ids ' => [],
578
+ 'status ' => 1 ,
579
+ 'is_changed_categories ' => true ,
580
+ 'affected_category_ids ' => [5 ]
581
+ ],
582
+ ],
583
+ 'no status changes ' => [
553
584
[0 => 'catalog_product_1 ' ],
554
- ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [1 ], 'status ' => 2 ],
555
- ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [], 'status ' => 1 ],
585
+ ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [1 ], 'status ' => 1 ],
586
+ ['id ' => 1 , 'name ' => 'value ' , 'category_ids ' => [1 ], 'status ' => 1 ],
556
587
]
557
588
];
558
589
}
559
590
591
+ public function testStatusAfterLoad ()
592
+ {
593
+ $ this ->resource ->expects ($ this ->once ())->method ('load ' )->with ($ this ->model , 1 , null );
594
+ $ this ->eventManagerMock ->expects ($ this ->exactly (4 ))->method ('dispatch ' );
595
+ $ this ->model ->load (1 );
596
+ $ this ->assertEquals (
597
+ Status::STATUS_ENABLED ,
598
+ $ this ->model ->getData (\Magento \Catalog \Model \Product::STATUS )
599
+ );
600
+ $ this ->assertFalse ($ this ->model ->hasDataChanges ());
601
+ $ this ->model ->setStatus (Status::STATUS_DISABLED );
602
+ $ this ->assertTrue ($ this ->model ->hasDataChanges ());
603
+ }
604
+
560
605
/**
561
606
* Test retrieving price Info
562
607
*/
0 commit comments