@@ -297,4 +297,46 @@ public function testInvalidPermissions(): void
297297 $ this ->assertFalse ($ object ->isValid ($ permissions ));
298298 $ this ->assertEquals ('You can only provide up to 100 permissions. ' , $ object ->getDescription ());
299299 }
300+
301+ /*
302+ * Test for checking duplicate methods input. The getPermissions should return an a list array
303+ */
304+ public function testDuplicateMethods (): void
305+ {
306+ $ validator = new Permissions ();
307+
308+ $ user = ID ::unique ();
309+
310+ $ document = new Document ([
311+ '$id ' => uniqid (),
312+ '$collection ' => uniqid (),
313+ '$permissions ' => [
314+ Permission::read (Role::any ()),
315+ Permission::read (Role::user ($ user )),
316+ Permission::read (Role::user ($ user )),
317+ Permission::write (Role::user ($ user )),
318+ Permission::update (Role::user ($ user )),
319+ Permission::delete (Role::user ($ user )),
320+ ],
321+ 'title ' => 'This is a test. ' ,
322+ 'list ' => [
323+ 'one '
324+ ],
325+ 'children ' => [
326+ new Document (['name ' => 'x ' ]),
327+ new Document (['name ' => 'y ' ]),
328+ new Document (['name ' => 'z ' ]),
329+ ]
330+ ]);
331+ $ this ->assertTrue ($ validator ->isValid ($ document ->getPermissions ()));
332+ $ permissions = $ document ->getPermissions ();
333+ $ this ->assertEquals (5 , count ($ permissions ));
334+ $ this ->assertEquals ([
335+ 'read("any") ' ,
336+ 'read("user: ' . $ user . '") ' ,
337+ 'write("user: ' . $ user . '") ' ,
338+ 'update("user: ' . $ user . '") ' ,
339+ 'delete("user: ' . $ user . '") ' ,
340+ ], $ permissions );
341+ }
300342}
0 commit comments