14
14
use Magento \Framework \UrlInterface ;
15
15
use Magento \Store \Model \Store ;
16
16
use Magento \Framework \AuthorizationInterface ;
17
+ use Magento \Backend \Model \Auth \Session ;
18
+ use Magento \Authorization \Model \Role ;
19
+ use Magento \User \Model \User ;
17
20
18
21
/**
19
22
* Class CategoriesTest
@@ -52,6 +55,11 @@ class CategoriesTest extends AbstractModifierTest
52
55
*/
53
56
private $ authorizationMock ;
54
57
58
+ /**
59
+ * @var \Magento\Backend\Model\Auth\Session|\PHPUnit_Framework_MockObject_MockObject
60
+ */
61
+ private $ sessionMock ;
62
+
55
63
protected function setUp ()
56
64
{
57
65
parent ::setUp ();
@@ -73,6 +81,10 @@ protected function setUp()
73
81
$ this ->authorizationMock = $ this ->getMockBuilder (AuthorizationInterface::class)
74
82
->disableOriginalConstructor ()
75
83
->getMock ();
84
+ $ this ->sessionMock = $ this ->getMockBuilder (Session::class)
85
+ ->setMethods (['getUser ' ])
86
+ ->disableOriginalConstructor ()
87
+ ->getMock ();
76
88
77
89
$ this ->categoryCollectionFactoryMock ->expects ($ this ->any ())
78
90
->method ('create ' )
@@ -89,6 +101,26 @@ protected function setUp()
89
101
$ this ->categoryCollectionMock ->expects ($ this ->any ())
90
102
->method ('getIterator ' )
91
103
->willReturn (new \ArrayIterator ([]));
104
+
105
+ $ roleAdmin = $ this ->getMockBuilder (Role::class)
106
+ ->setMethods (['getId ' ])
107
+ ->disableOriginalConstructor ()
108
+ ->getMock ();
109
+ $ roleAdmin ->expects ($ this ->any ())
110
+ ->method ('getId ' )
111
+ ->willReturn (0 );
112
+
113
+ $ userAdmin = $ this ->getMockBuilder (User::class)
114
+ ->setMethods (['getRole ' ])
115
+ ->disableOriginalConstructor ()
116
+ ->getMock ();
117
+ $ userAdmin ->expects ($ this ->any ())
118
+ ->method ('getRole ' )
119
+ ->willReturn ($ roleAdmin );
120
+
121
+ $ this ->sessionMock ->expects ($ this ->any ())
122
+ ->method ('getUser ' )
123
+ ->willReturn ($ userAdmin );
92
124
}
93
125
94
126
/**
@@ -102,11 +134,28 @@ protected function createModel()
102
134
'locator ' => $ this ->locatorMock ,
103
135
'categoryCollectionFactory ' => $ this ->categoryCollectionFactoryMock ,
104
136
'arrayManager ' => $ this ->arrayManagerMock ,
105
- 'authorization ' => $ this ->authorizationMock
137
+ 'authorization ' => $ this ->authorizationMock ,
138
+ 'session ' => $ this ->sessionMock
106
139
]
107
140
);
108
141
}
109
142
143
+ /**
144
+ * @param object $object
145
+ * @param string $method
146
+ * @param array $args
147
+ * @return mixed
148
+ * @throws \ReflectionException
149
+ */
150
+ private function invokeMethod ($ object , $ method , $ args = [])
151
+ {
152
+ $ class = new \ReflectionClass (Categories::class);
153
+ $ method = $ class ->getMethod ($ method );
154
+ $ method ->setAccessible (true );
155
+
156
+ return $ method ->invokeArgs ($ object , $ args );
157
+ }
158
+
110
159
public function testModifyData ()
111
160
{
112
161
$ this ->assertSame ([], $ this ->getModel ()->modifyData ([]));
@@ -177,4 +226,44 @@ public function modifyMetaLockedDataProvider()
177
226
{
178
227
return [[true ], [false ]];
179
228
}
229
+
230
+ /**
231
+ * Asserts that a user with an ACL role ID of 0 and a user with an ACL role ID of 1 do not have the same cache IDs
232
+ * Assumes a store ID of 0
233
+ *
234
+ * @throws \ReflectionException
235
+ */
236
+ public function testAclCacheIds ()
237
+ {
238
+ $ categoriesAdmin = $ this ->createModel ();
239
+ $ cacheIdAdmin = $ this ->invokeMethod ($ categoriesAdmin , 'getCategoriesTreeCacheId ' , [0 ]);
240
+
241
+ $ roleAclUser = $ this ->getMockBuilder (Role::class)
242
+ ->disableOriginalConstructor ()
243
+ ->getMock ();
244
+ $ roleAclUser ->expects ($ this ->any ())
245
+ ->method ('getId ' )
246
+ ->willReturn (1 );
247
+
248
+ $ userAclUser = $ this ->getMockBuilder (User::class)
249
+ ->disableOriginalConstructor ()
250
+ ->getMock ();
251
+ $ userAclUser ->expects ($ this ->any ())
252
+ ->method ('getRole ' )
253
+ ->will ($ this ->returnValue ($ roleAclUser ));
254
+
255
+ $ this ->sessionMock = $ this ->getMockBuilder (Session::class)
256
+ ->setMethods (['getUser ' ])
257
+ ->disableOriginalConstructor ()
258
+ ->getMock ();
259
+
260
+ $ this ->sessionMock ->expects ($ this ->any ())
261
+ ->method ('getUser ' )
262
+ ->will ($ this ->returnValue ($ userAclUser ));
263
+
264
+ $ categoriesAclUser = $ this ->createModel ();
265
+ $ cacheIdAclUser = $ this ->invokeMethod ($ categoriesAclUser , 'getCategoriesTreeCacheId ' , [0 ]);
266
+
267
+ $ this ->assertNotEquals ($ cacheIdAdmin , $ cacheIdAclUser );
268
+ }
180
269
}
0 commit comments