Skip to content

Commit c172837

Browse files
author
Alexander Paliarush
committed
Merge remote-tracking branch 'remotes/mainline/develop' into MAGETWO-35999-Join-Directives
2 parents fd0a380 + 16d73f7 commit c172837

File tree

2 files changed

+69
-23
lines changed

2 files changed

+69
-23
lines changed

app/code/Magento/Catalog/Model/Product.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,8 @@ public function getTypeId()
586586
*/
587587
public function getStatus()
588588
{
589-
if ($this->_getData(self::STATUS) === null) {
590-
$this->setData(self::STATUS, \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
591-
}
592-
return $this->_getData(self::STATUS);
589+
$status = $this->_getData(self::STATUS);
590+
return $status !== null ? $status : \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED;
593591
}
594592

595593
/**
@@ -974,6 +972,9 @@ public function afterDeleteCommit()
974972
*/
975973
protected function _afterLoad()
976974
{
975+
if (!$this->hasData(self::STATUS)) {
976+
$this->setData(self::STATUS, \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
977+
}
977978
parent::_afterLoad();
978979
/**
979980
* Load product options
@@ -2277,8 +2278,8 @@ public function getIdentities()
22772278
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
22782279
}
22792280
}
2280-
if ($this->getOrigData('status') > $this->getData('status')) {
2281-
foreach ($this->getData('category_ids') as $categoryId) {
2281+
if ($this->getOrigData('status') != $this->getData('status')) {
2282+
foreach ($this->getCategoryIds() as $categoryId) {
22822283
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
22832284
}
22842285
}

app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Catalog\Model\Product;
1212
use Magento\Framework\Api\Data\ImageContentInterface;
1313
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
14+
use Magento\Catalog\Model\Product\Attribute\Source\Status as Status;
1415

1516
/**
1617
* Product Test
@@ -156,6 +157,11 @@ class ProductTest extends \PHPUnit_Framework_TestCase
156157
*/
157158
protected $entityCollectionProviderMock;
158159

160+
/**
161+
* @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
162+
*/
163+
protected $eventManagerMock;
164+
159165
/**
160166
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
161167
*/
@@ -203,7 +209,7 @@ public function setUp()
203209
->method('getAreaCode')
204210
->will($this->returnValue(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE));
205211

206-
$eventManagerMock = $this->getMock('Magento\Framework\Event\ManagerInterface');
212+
$this->eventManagerMock = $this->getMock('Magento\Framework\Event\ManagerInterface');
207213
$actionValidatorMock = $this->getMock(
208214
'\Magento\Framework\Model\ActionValidator\RemoveAction',
209215
[],
@@ -219,7 +225,9 @@ public function setUp()
219225
['getEventDispatcher', 'getCacheManager', 'getAppState', 'getActionValidator'], [], '', false
220226
);
221227
$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));
223231
$contextMock->expects($this->any())
224232
->method('getCacheManager')
225233
->will($this->returnValue($cacheInterfaceMock));
@@ -415,16 +423,20 @@ public function testGetCategoryIds()
415423
$this->assertEquals([], $this->model->getCategoryIds());
416424
}
417425

426+
public function testGetStatusInitial()
427+
{
428+
$this->assertEquals(Status::STATUS_ENABLED, $this->model->getStatus());
429+
}
430+
418431
public function testGetStatus()
419432
{
420433
$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());
423435
}
424436

425437
public function testIsInStock()
426438
{
427-
$this->model->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
439+
$this->model->setStatus(Status::STATUS_ENABLED);
428440
$this->assertTrue($this->model->isInStock());
429441
}
430442

@@ -523,12 +535,12 @@ public function testGetIdentities($expected, $origData, $data, $isDeleted = fals
523535
public function getIdentitiesProvider()
524536
{
525537
return [
526-
[
538+
'no changes' => [
527539
['catalog_product_1'],
528540
['id' => 1, 'name' => 'value', 'category_ids' => [1]],
529541
['id' => 1, 'name' => 'value', 'category_ids' => [1]],
530542
],
531-
[
543+
'new product' => [
532544
['catalog_product_1', 'catalog_category_product_1'],
533545
null,
534546
[
@@ -539,24 +551,57 @@ public function getIdentitiesProvider()
539551
'is_changed_categories' => true
540552
]
541553
],
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'],
544556
['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+
],
546565
],
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],
551570
],
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' => [
553584
[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],
556587
]
557588
];
558589
}
559590

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+
560605
/**
561606
* Test retrieving price Info
562607
*/

0 commit comments

Comments
 (0)