Skip to content

Commit b046944

Browse files
committed
MAGETWO-58849: Error in Product Edit Page after Disable Review Module
1 parent b5f7a9d commit b046944

File tree

2 files changed

+66
-5
lines changed
  • app/code/Magento/Review

2 files changed

+66
-5
lines changed

app/code/Magento/Review/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ReviewTest.php

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier\AbstractModifierTest;
99
use Magento\Framework\UrlInterface;
1010
use Magento\Review\Ui\DataProvider\Product\Form\Modifier\Review;
11+
use Magento\Framework\Module\Manager as ModuleManager;
12+
use Magento\Ui\DataProvider\Modifier\ModifierInterface;
1113

1214
/**
1315
* Class ReviewTest
@@ -19,36 +21,73 @@ class ReviewTest extends AbstractModifierTest
1921
*/
2022
protected $urlBuilderMock;
2123

24+
/**
25+
* @var \PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
private $moduleManagerMock;
28+
2229
protected function setUp()
2330
{
2431
parent::setUp();
2532
$this->urlBuilderMock = $this->getMockBuilder(UrlInterface::class)
2633
->getMockForAbstractClass();
34+
$this->moduleManagerMock = $this->getMock(ModuleManager::class, [], [], '', false);
2735
}
2836

37+
/**
38+
* @return ModifierInterface
39+
*/
2940
protected function createModel()
3041
{
31-
return $this->objectManager->getObject(Review::class, [
42+
$model = $this->objectManager->getObject(Review::class, [
3243
'locator' => $this->locatorMock,
3344
'urlBuilder' => $this->urlBuilderMock,
3445
]);
46+
47+
$reviewClass = new \ReflectionClass(Review::class);
48+
$moduleManagerProperty = $reviewClass->getProperty('moduleManager');
49+
$moduleManagerProperty->setAccessible(true);
50+
$moduleManagerProperty->setValue(
51+
$model,
52+
$this->moduleManagerMock
53+
);
54+
55+
return $model;
3556
}
3657

37-
public function testModifyMetaToBeEmpty()
58+
public function testModifyMetaDoesNotAddReviewSectionForNewProduct()
59+
{
60+
$this->productMock->expects($this->once())
61+
->method('getId');
62+
63+
$this->assertSame([], $this->getModel()->modifyMeta([]));
64+
}
65+
66+
public function testModifyMetaDoesNotAddReviewSectionIfReviewModuleOutputIsDisabled()
3867
{
3968
$this->productMock->expects($this->once())
4069
->method('getId')
41-
->willReturn(0);
70+
->willReturn(1);
71+
72+
$this->moduleManagerMock->expects($this->any())
73+
->method('isOutputEnabled')
74+
->with('Magento_Review')
75+
->willReturn(false);
4276

4377
$this->assertSame([], $this->getModel()->modifyMeta([]));
4478
}
4579

46-
public function testModifyMeta()
80+
public function testModifyMetaAddsReviewSectionForExistingProductIfReviewModuleOutputIsEnabled()
4781
{
4882
$this->productMock->expects($this->once())
4983
->method('getId')
5084
->willReturn(1);
5185

86+
$this->moduleManagerMock->expects($this->any())
87+
->method('isOutputEnabled')
88+
->with('Magento_Review')
89+
->willReturn(true);
90+
5291
$this->assertArrayHasKey(Review::GROUP_REVIEW, $this->getModel()->modifyMeta([]));
5392
}
5493

app/code/Magento/Review/Ui/DataProvider/Product/Form/Modifier/Review.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
1313
use Magento\Ui\Component\Form;
1414
use Magento\Framework\UrlInterface;
15+
use Magento\Framework\Module\Manager as ModuleManager;
16+
use Magento\Framework\App\ObjectManager;
1517

1618
/**
1719
* Class Review
@@ -34,6 +36,11 @@ class Review extends AbstractModifier
3436
*/
3537
protected $urlBuilder;
3638

39+
/**
40+
* @var ModuleManager
41+
*/
42+
private $moduleManager;
43+
3744
/**
3845
* @param LocatorInterface $locator
3946
* @param UrlInterface $urlBuilder
@@ -51,7 +58,7 @@ public function __construct(
5158
*/
5259
public function modifyMeta(array $meta)
5360
{
54-
if (!$this->locator->getProduct()->getId()) {
61+
if (!$this->locator->getProduct()->getId() || !$this->getModuleManager()->isOutputEnabled('Magento_Review')) {
5562
return $meta;
5663
}
5764

@@ -114,4 +121,19 @@ public function modifyData(array $data)
114121

115122
return $data;
116123
}
124+
125+
/**
126+
* Retrieve module manager instance using dependency lookup to keep this class backward compatible.
127+
*
128+
* @return ModuleManager
129+
*
130+
* @deprecated
131+
*/
132+
private function getModuleManager()
133+
{
134+
if ($this->moduleManager === null) {
135+
$this->moduleManager = ObjectManager::getInstance()->get(ModuleManager::class);
136+
}
137+
return $this->moduleManager;
138+
}
117139
}

0 commit comments

Comments
 (0)