7
7
8
8
namespace Magento \Catalog \Test \Unit \Ui \DataProvider \Product \Form \Modifier ;
9
9
10
- use Magento \Catalog \Model \ResourceModel \Category \Collection as CategoryCollection ;
11
- use Magento \Catalog \Model \ResourceModel \Category \CollectionFactory as CategoryCollectionFactory ;
12
10
use Magento \Catalog \Ui \DataProvider \Product \Form \Modifier \Categories ;
11
+ use Magento \Catalog \Model \ResourceModel \Category \CollectionFactory as CategoryCollectionFactory ;
12
+ use Magento \Catalog \Model \ResourceModel \Category \Collection as CategoryCollection ;
13
13
use Magento \Framework \AuthorizationInterface ;
14
14
use Magento \Framework \DB \Helper as DbHelper ;
15
15
use Magento \Framework \UrlInterface ;
16
16
use Magento \Store \Model \Store ;
17
+ use Magento \Backend \Model \Auth \Session ;
18
+ use Magento \Authorization \Model \Role ;
19
+ use Magento \User \Model \User ;
17
20
use PHPUnit \Framework \MockObject \MockObject ;
18
21
19
22
/**
@@ -51,6 +54,11 @@ class CategoriesTest extends AbstractModifierTest
51
54
*/
52
55
private $ authorizationMock ;
53
56
57
+ /**
58
+ * @var Session|MockObject
59
+ */
60
+ private $ sessionMock ;
61
+
54
62
protected function setUp (): void
55
63
{
56
64
parent ::setUp ();
@@ -72,7 +80,10 @@ protected function setUp(): void
72
80
$ this ->authorizationMock = $ this ->getMockBuilder (AuthorizationInterface::class)
73
81
->disableOriginalConstructor ()
74
82
->getMockForAbstractClass ();
75
-
83
+ $ this ->sessionMock = $ this ->getMockBuilder (Session::class)
84
+ ->setMethods (['getUser ' ])
85
+ ->disableOriginalConstructor ()
86
+ ->getMock ();
76
87
$ this ->categoryCollectionFactoryMock ->expects ($ this ->any ())
77
88
->method ('create ' )
78
89
->willReturn ($ this ->categoryCollectionMock );
@@ -88,6 +99,26 @@ protected function setUp(): void
88
99
$ this ->categoryCollectionMock ->expects ($ this ->any ())
89
100
->method ('getIterator ' )
90
101
->willReturn (new \ArrayIterator ([]));
102
+
103
+ $ roleAdmin = $ this ->getMockBuilder (Role::class)
104
+ ->setMethods (['getId ' ])
105
+ ->disableOriginalConstructor ()
106
+ ->getMock ();
107
+ $ roleAdmin ->expects ($ this ->any ())
108
+ ->method ('getId ' )
109
+ ->willReturn (0 );
110
+
111
+ $ userAdmin = $ this ->getMockBuilder (User::class)
112
+ ->setMethods (['getRole ' ])
113
+ ->disableOriginalConstructor ()
114
+ ->getMock ();
115
+ $ userAdmin ->expects ($ this ->any ())
116
+ ->method ('getRole ' )
117
+ ->willReturn ($ roleAdmin );
118
+
119
+ $ this ->sessionMock ->expects ($ this ->any ())
120
+ ->method ('getUser ' )
121
+ ->willReturn ($ userAdmin );
91
122
}
92
123
93
124
/**
@@ -101,11 +132,28 @@ protected function createModel()
101
132
'locator ' => $ this ->locatorMock ,
102
133
'categoryCollectionFactory ' => $ this ->categoryCollectionFactoryMock ,
103
134
'arrayManager ' => $ this ->arrayManagerMock ,
104
- 'authorization ' => $ this ->authorizationMock
135
+ 'authorization ' => $ this ->authorizationMock ,
136
+ 'session ' => $ this ->sessionMock
105
137
]
106
138
);
107
139
}
108
140
141
+ /**
142
+ * @param object $object
143
+ * @param string $method
144
+ * @param array $args
145
+ * @return mixed
146
+ * @throws \ReflectionException
147
+ */
148
+ private function invokeMethod ($ object , $ method , $ args = [])
149
+ {
150
+ $ class = new \ReflectionClass (Categories::class);
151
+ $ method = $ class ->getMethod ($ method );
152
+ $ method ->setAccessible (true );
153
+
154
+ return $ method ->invokeArgs ($ object , $ args );
155
+ }
156
+
109
157
public function testModifyData ()
110
158
{
111
159
$ this ->assertSame ([], $ this ->getModel ()->modifyData ([]));
@@ -176,4 +224,44 @@ public function modifyMetaLockedDataProvider()
176
224
{
177
225
return [[true ], [false ]];
178
226
}
227
+
228
+ /**
229
+ * 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
230
+ * Assumes a store ID of 0
231
+ *
232
+ * @throws \ReflectionException
233
+ */
234
+ public function testAclCacheIds ()
235
+ {
236
+ $ categoriesAdmin = $ this ->createModel ();
237
+ $ cacheIdAdmin = $ this ->invokeMethod ($ categoriesAdmin , 'getCategoriesTreeCacheId ' , [0 ]);
238
+
239
+ $ roleAclUser = $ this ->getMockBuilder (Role::class)
240
+ ->disableOriginalConstructor ()
241
+ ->getMock ();
242
+ $ roleAclUser ->expects ($ this ->any ())
243
+ ->method ('getId ' )
244
+ ->willReturn (1 );
245
+
246
+ $ userAclUser = $ this ->getMockBuilder (User::class)
247
+ ->disableOriginalConstructor ()
248
+ ->getMock ();
249
+ $ userAclUser ->expects ($ this ->any ())
250
+ ->method ('getRole ' )
251
+ ->will ($ this ->returnValue ($ roleAclUser ));
252
+
253
+ $ this ->sessionMock = $ this ->getMockBuilder (Session::class)
254
+ ->setMethods (['getUser ' ])
255
+ ->disableOriginalConstructor ()
256
+ ->getMock ();
257
+
258
+ $ this ->sessionMock ->expects ($ this ->any ())
259
+ ->method ('getUser ' )
260
+ ->will ($ this ->returnValue ($ userAclUser ));
261
+
262
+ $ categoriesAclUser = $ this ->createModel ();
263
+ $ cacheIdAclUser = $ this ->invokeMethod ($ categoriesAclUser , 'getCategoriesTreeCacheId ' , [0 ]);
264
+
265
+ $ this ->assertNotEquals ($ cacheIdAdmin , $ cacheIdAclUser );
266
+ }
179
267
}
0 commit comments