2828use OCA \GroupFolders \ACL \RuleManager ;
2929use OCA \GroupFolders \ACL \UserMapping \IUserMappingManager ;
3030use OCA \GroupFolders \ACL \UserMapping \UserMapping ;
31+ use OCP \EventDispatcher \IEventDispatcher ;
32+ use OCP \Log \Audit \CriticalActionPerformedEvent ;
3133use OCP \IUser ;
3234use Test \TestCase ;
3335
@@ -42,6 +44,9 @@ class RuleManagerTest extends TestCase {
4244 /** @var \PHPUnit_Framework_MockObject_MockObject | IUser */
4345 private $ user ;
4446
47+ /** @var \PHPUnit_Framework_MockObject_MockObject | IEventDispatcher */
48+ private $ eventDispatcher ;
49+
4550 protected function setUp (): void {
4651 parent ::setUp ();
4752
@@ -53,18 +58,51 @@ protected function setUp(): void {
5358 $ this ->userMappingManager ->expects ($ this ->any ())
5459 ->method ('mappingFromId ' )
5560 ->willReturnCallback (function ($ type , $ id ) {
56- return new UserMapping ($ type , $ id );
61+ if ($ type === 'user ' ) {
62+ return new UserMapping ($ type , $ id , 'The User ' );
63+ } else {
64+ return new UserMapping ($ type , $ id );
65+ }
5766 });
58- $ this ->ruleManager = new RuleManager (\OC ::$ server ->getDatabaseConnection (), $ this ->userMappingManager );
67+
68+ $ this ->eventDispatcher = $ this ->createMock (IEventDispatcher::class);
69+ $ this ->ruleManager = new RuleManager (\OC ::$ server ->getDatabaseConnection (), $ this ->userMappingManager , $ this ->eventDispatcher );
5970 }
6071
6172 public function testGetSetRule () {
62- $ mapping = new UserMapping ('test ' , '1 ' );
73+ $ mapping = new UserMapping ('user ' , '1 ' , ' The User ' );
6374 $ this ->userMappingManager ->expects ($ this ->any ())
6475 ->method ('getMappingsForUser ' )
6576 ->with ($ this ->user )
6677 ->willReturn ([$ mapping ]);
6778
79+ $ this ->eventDispatcher ->expects ($ this ->any ())
80+ ->method ('dispatchTyped ' )
81+ ->withConsecutive (
82+ [$ this ->callback (function (CriticalActionPerformedEvent $ event ): bool {
83+ return $ event ->getParameters () === [
84+ 'permissions ' => 0b00001001 ,
85+ 'mask ' => 0b00001111 ,
86+ 'fileId ' => 10 ,
87+ 'user ' => 'The User (1) ' ,
88+ ];
89+ })],
90+ [$ this ->callback (function (CriticalActionPerformedEvent $ event ): bool {
91+ return $ event ->getParameters () === [
92+ 'permissions ' => 0b00001000 ,
93+ 'mask ' => 0b00001111 ,
94+ 'fileId ' => 10 ,
95+ 'user ' => 'The User (1) ' ,
96+ ];
97+ })],
98+ [$ this ->callback (function (CriticalActionPerformedEvent $ event ): bool {
99+ return $ event ->getParameters () === [
100+ 'fileId ' => 10 ,
101+ 'user ' => 'The User (1) ' ,
102+ ];
103+ })],
104+ );
105+
68106 $ rule = new Rule ($ mapping , 10 , 0b00001111 , 0b00001001 );
69107 $ this ->ruleManager ->saveRule ($ rule );
70108
@@ -89,6 +127,9 @@ public function testGetMultiple() {
89127 ->with ($ this ->user )
90128 ->willReturn ([$ mapping1 , $ mapping2 ]);
91129
130+ $ this ->eventDispatcher ->expects ($ this ->any ())
131+ ->method ('dispatchTyped ' );
132+
92133 $ rule1 = new Rule ($ mapping1 , 10 , 0b00001111 , 0b00001001 );
93134 $ rule2 = new Rule ($ mapping2 , 10 , 0b00001111 , 0b00001000 );
94135 $ rule3 = new Rule ($ mapping2 , 11 , 0b00001111 , 0b00001000 );
@@ -121,6 +162,9 @@ public function testGetByPath() {
121162 ->with ($ this ->user )
122163 ->willReturn ([$ mapping ]);
123164
165+ $ this ->eventDispatcher ->expects ($ this ->any ())
166+ ->method ('dispatchTyped ' );
167+
124168 $ rule1 = new Rule ($ mapping , $ id1 , 0b00001111 , 0b00001001 );
125169 $ rule2 = new Rule ($ mapping , $ id2 , 0b00001111 , 0b00001000 );
126170 $ this ->ruleManager ->saveRule ($ rule1 );
@@ -160,6 +204,8 @@ public function testGetByPathMore() {
160204 $ rule = new Rule ($ mapping , $ id1 , 0b00001111 , 0b00001001 );
161205 $ this ->ruleManager ->saveRule ($ rule );
162206
207+ $ this ->eventDispatcher ->expects ($ this ->any ())
208+ ->method ('dispatchTyped ' );
163209
164210 $ result = $ this ->ruleManager ->getRulesForFilesByPath ($ this ->user , $ storageId , array_merge (['foo ' ], $ paths ));
165211
0 commit comments