@@ -200,7 +200,7 @@ class ProductTest extends \PHPUnit\Framework\TestCase
200
200
/**
201
201
* @var ProductExtensionInterface|\PHPUnit_Framework_MockObject_MockObject
202
202
*/
203
- private $ extensionAttributes ;
203
+ private $ productExtAttributes ;
204
204
205
205
/**
206
206
* @var \Magento\Eav\Model\Config|\PHPUnit_Framework_MockObject_MockObject
@@ -372,13 +372,13 @@ protected function setUp()
372
372
$ this ->mediaConfig = $ this ->createMock (\Magento \Catalog \Model \Product \Media \Config::class);
373
373
$ this ->eavConfig = $ this ->createMock (\Magento \Eav \Model \Config::class);
374
374
375
- $ this ->extensionAttributes = $ this ->getMockBuilder (ProductExtensionInterface::class)
375
+ $ this ->productExtAttributes = $ this ->getMockBuilder (ProductExtensionInterface::class)
376
376
->setMethods (['getStockItem ' ])
377
377
->getMockForAbstractClass ();
378
378
$ this ->extensionAttributesFactory
379
379
->expects ($ this ->any ())
380
380
->method ('create ' )
381
- ->willReturn ($ this ->extensionAttributes );
381
+ ->willReturn ($ this ->productExtAttributes );
382
382
383
383
$ this ->filterCustomAttribute = $ this ->createTestProxy (
384
384
\Magento \Catalog \Model \FilterProductCustomAttribute::class
@@ -549,6 +549,7 @@ public function testSetCategoryCollection()
549
549
550
550
public function testGetCategory ()
551
551
{
552
+ $ this ->model ->setData ('category_ids ' , [10 ]);
552
553
$ this ->category ->expects ($ this ->any ())->method ('getId ' )->will ($ this ->returnValue (10 ));
553
554
$ this ->registry ->expects ($ this ->any ())->method ('registry ' )->will ($ this ->returnValue ($ this ->category ));
554
555
$ this ->categoryRepository ->expects ($ this ->any ())->method ('get ' )->will ($ this ->returnValue ($ this ->category ));
@@ -557,14 +558,23 @@ public function testGetCategory()
557
558
558
559
public function testGetCategoryId ()
559
560
{
560
- $ this ->category ->expects ($ this ->once ())->method ('getId ' )->will ($ this ->returnValue (10 ));
561
+ $ this ->model ->setData ('category_ids ' , [10 ]);
562
+ $ this ->category ->expects ($ this ->any ())->method ('getId ' )->will ($ this ->returnValue (10 ));
561
563
562
564
$ this ->registry ->expects ($ this ->at (0 ))->method ('registry ' );
563
565
$ this ->registry ->expects ($ this ->at (1 ))->method ('registry ' )->will ($ this ->returnValue ($ this ->category ));
564
566
$ this ->assertFalse ($ this ->model ->getCategoryId ());
565
567
$ this ->assertEquals (10 , $ this ->model ->getCategoryId ());
566
568
}
567
569
570
+ public function testGetCategoryIdWhenProductNotInCurrentCategory ()
571
+ {
572
+ $ this ->model ->setData ('category_ids ' , [12 ]);
573
+ $ this ->category ->expects ($ this ->once ())->method ('getId ' )->will ($ this ->returnValue (10 ));
574
+ $ this ->registry ->expects ($ this ->any ())->method ('registry ' )->will ($ this ->returnValue ($ this ->category ));
575
+ $ this ->assertFalse ($ this ->model ->getCategoryId ());
576
+ }
577
+
568
578
public function testGetIdBySku ()
569
579
{
570
580
$ this ->resource ->expects ($ this ->once ())->method ('getIdBySku ' )->will ($ this ->returnValue (5 ));
0 commit comments