8
8
use Magento \Catalog \Test \Unit \Ui \DataProvider \Product \Form \Modifier \AbstractModifierTest ;
9
9
use Magento \Framework \UrlInterface ;
10
10
use Magento \Review \Ui \DataProvider \Product \Form \Modifier \Review ;
11
+ use Magento \Framework \Module \Manager as ModuleManager ;
12
+ use Magento \Ui \DataProvider \Modifier \ModifierInterface ;
11
13
12
14
/**
13
15
* Class ReviewTest
@@ -19,36 +21,73 @@ class ReviewTest extends AbstractModifierTest
19
21
*/
20
22
protected $ urlBuilderMock ;
21
23
24
+ /**
25
+ * @var \PHPUnit_Framework_MockObject_MockObject
26
+ */
27
+ private $ moduleManagerMock ;
28
+
22
29
protected function setUp ()
23
30
{
24
31
parent ::setUp ();
25
32
$ this ->urlBuilderMock = $ this ->getMockBuilder (UrlInterface::class)
26
33
->getMockForAbstractClass ();
34
+ $ this ->moduleManagerMock = $ this ->getMock (ModuleManager::class, [], [], '' , false );
27
35
}
28
36
37
+ /**
38
+ * @return ModifierInterface
39
+ */
29
40
protected function createModel ()
30
41
{
31
- return $ this ->objectManager ->getObject (Review::class, [
42
+ $ model = $ this ->objectManager ->getObject (Review::class, [
32
43
'locator ' => $ this ->locatorMock ,
33
44
'urlBuilder ' => $ this ->urlBuilderMock ,
34
45
]);
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 ;
35
56
}
36
57
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 ()
38
67
{
39
68
$ this ->productMock ->expects ($ this ->once ())
40
69
->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 );
42
76
43
77
$ this ->assertSame ([], $ this ->getModel ()->modifyMeta ([]));
44
78
}
45
79
46
- public function testModifyMeta ()
80
+ public function testModifyMetaAddsReviewSectionForExistingProductIfReviewModuleOutputIsEnabled ()
47
81
{
48
82
$ this ->productMock ->expects ($ this ->once ())
49
83
->method ('getId ' )
50
84
->willReturn (1 );
51
85
86
+ $ this ->moduleManagerMock ->expects ($ this ->any ())
87
+ ->method ('isOutputEnabled ' )
88
+ ->with ('Magento_Review ' )
89
+ ->willReturn (true );
90
+
52
91
$ this ->assertArrayHasKey (Review::GROUP_REVIEW , $ this ->getModel ()->modifyMeta ([]));
53
92
}
54
93
0 commit comments