1111use Ibexa \Contracts \Core \Persistence \Content \Location \Trash \Handler as TrashHandler ;
1212use Ibexa \Contracts \Core \Persistence \Content \Location \Trashed ;
1313use Ibexa \Contracts \Core \Persistence \Content \Relation ;
14+ use Ibexa \Contracts \Core \Persistence \User \Handler as PersistenceUserHandler ;
15+ use Ibexa \Contracts \Core \Persistence \User \RoleAssignment ;
1416use Ibexa \Contracts \Core \Repository \Values \Content \Trash \TrashItemDeleteResult ;
1517use Ibexa \Core \Persistence \Cache \ContentHandler ;
1618use Ibexa \Core \Persistence \Cache \LocationHandler ;
@@ -57,72 +59,51 @@ public function testRecover()
5759 $ originalLocationId = 6 ;
5860 $ targetLocationId = 2 ;
5961 $ contentId = 42 ;
60-
61- $ tags = [
62- 'c- ' . $ contentId ,
63- 'lp- ' . $ originalLocationId ,
64- ];
65-
66- $ handlerMethodName = $ this ->getHandlerMethodName ();
62+ $ roleId = 1 ;
6763
6864 $ this ->loggerMock ->expects (self ::once ())->method ('logCall ' );
6965
70- $ innerHandler = $ this ->createMock ($ this ->getHandlerClassName ());
71- $ contentHandlerMock = $ this ->createMock (ContentHandler::class);
72- $ locationHandlerMock = $ this ->createMock (LocationHandler::class);
73-
74- $ locationHandlerMock
75- ->method ('load ' )
76- ->willReturn (new Location (['id ' => $ originalLocationId , 'contentId ' => $ contentId ]));
77-
78- $ this ->persistenceHandlerMock
79- ->method ('contentHandler ' )
80- ->willReturn ($ contentHandlerMock );
81-
82- $ this ->persistenceHandlerMock
83- ->method ('locationHandler ' )
84- ->willReturn ($ locationHandlerMock );
85-
86- $ this ->persistenceHandlerMock
87- ->expects (self ::once ())
88- ->method ($ handlerMethodName )
89- ->willReturn ($ innerHandler );
66+ $ innerHandler = $ this ->setUpRoleAssignmentInvalidation ($ originalLocationId , $ contentId , $ roleId );
9067
9168 $ innerHandler
9269 ->expects (self ::once ())
9370 ->method ('recover ' )
9471 ->with ($ originalLocationId , $ targetLocationId )
9572 ->willReturn (null );
9673
97- $ this ->cacheIdentifierGeneratorMock
98- ->expects (self ::exactly (2 ))
99- ->method ('generateTag ' )
100- ->withConsecutive (
101- ['content ' , [$ contentId ], false ],
102- ['location_path ' , [$ originalLocationId ], false ]
103- )
104- ->willReturnOnConsecutiveCalls (
105- 'c- ' . $ contentId ,
106- 'lp- ' . $ originalLocationId
107- );
108-
109- $ this ->cacheMock
110- ->expects (self ::once ())
111- ->method ('invalidateTags ' )
112- ->with ($ tags );
113-
114- $ handler = $ this ->persistenceCacheHandler ->$ handlerMethodName ();
74+ $ handler = $ this ->persistenceCacheHandler ->{$ this ->getHandlerMethodName ()}();
11575 $ handler ->recover ($ originalLocationId , $ targetLocationId );
11676 }
11777
11878 public function testTrashSubtree ()
11979 {
12080 $ locationId = 6 ;
12181 $ contentId = 42 ;
82+ $ roleId = 1 ;
83+
84+ $ this ->loggerMock ->expects ($ this ->once ())->method ('logCall ' );
85+
86+ $ innerHandler = $ this ->setUpRoleAssignmentInvalidation ($ locationId , $ contentId , $ roleId );
87+
88+ $ innerHandler
89+ ->expects (self ::once ())
90+ ->method ('trashSubtree ' )
91+ ->with ($ locationId )
92+ ->willReturn (null );
12293
94+ $ handler = $ this ->persistenceCacheHandler ->{$ this ->getHandlerMethodName ()}();
95+ $ handler ->trashSubtree ($ locationId );
96+ }
97+
98+ /**
99+ * @return \PHPUnit\Framework\MockObject\MockObject
100+ */
101+ private function setUpRoleAssignmentInvalidation (int $ locationId , int $ contentId , int $ roleId ): object
102+ {
123103 $ tags = [
124104 'c- ' . $ contentId ,
125105 'lp- ' . $ locationId ,
106+ 'rarl- ' . $ roleId ,
126107 ];
127108
128109 $ handlerMethodName = $ this ->getHandlerMethodName ();
@@ -132,11 +113,17 @@ public function testTrashSubtree()
132113 $ innerHandler = $ this ->createMock ($ this ->getHandlerClassName ());
133114 $ contentHandlerMock = $ this ->createMock (ContentHandler::class);
134115 $ locationHandlerMock = $ this ->createMock (LocationHandler::class);
116+ $ userHandlerMock = $ this ->createMock (PersistenceUserHandler::class);
135117
136118 $ locationHandlerMock
137119 ->method ('load ' )
138120 ->willReturn (new Location (['id ' => $ locationId , 'contentId ' => $ contentId ]));
139121
122+ $ userHandlerMock
123+ ->method ('loadRoleAssignmentsByGroupId ' )
124+ ->with ($ contentId )
125+ ->willReturn ([new RoleAssignment (['roleId ' => $ roleId , 'contentId ' => $ contentId ])]);
126+
140127 $ this ->persistenceHandlerMock
141128 ->method ('contentHandler ' )
142129 ->willReturn ($ contentHandlerMock );
@@ -146,32 +133,34 @@ public function testTrashSubtree()
146133 ->willReturn ($ locationHandlerMock );
147134
148135 $ this ->persistenceHandlerMock
149- ->expects (self ::once ())
150- ->method ($ handlerMethodName )
151- ->willReturn ($ innerHandler );
136+ ->method ('userHandler ' )
137+ ->willReturn ($ userHandlerMock );
152138
153- $ innerHandler
139+ $ this -> persistenceHandlerMock
154140 ->expects (self ::once ())
155- ->method ('trashSubtree ' )
156- ->with ($ locationId )
157- ->willReturn (null );
141+ ->method ($ this ->getHandlerMethodName ())
142+ ->willReturn ($ innerHandler );
158143
159144 $ this ->cacheIdentifierGeneratorMock
160- ->expects (self ::exactly (2 ))
145+ ->expects (self ::exactly (3 ))
161146 ->method ('generateTag ' )
162147 ->withConsecutive (
148+ ['role_assignment_role_list ' , [$ roleId ], false ],
163149 ['content ' , [$ contentId ], false ],
164150 ['location_path ' , [$ locationId ], false ]
165151 )
166- ->willReturnOnConsecutiveCalls (...$ tags );
152+ ->willReturnOnConsecutiveCalls (
153+ 'rarl- ' . $ roleId ,
154+ 'c- ' . $ contentId ,
155+ 'lp- ' . $ locationId
156+ );
167157
168158 $ this ->cacheMock
169159 ->expects (self ::once ())
170160 ->method ('invalidateTags ' )
171161 ->with ($ tags );
172162
173- $ handler = $ this ->persistenceCacheHandler ->$ handlerMethodName ();
174- $ handler ->trashSubtree ($ locationId );
163+ return $ innerHandler ;
175164 }
176165
177166 public function testDeleteTrashItem ()
0 commit comments