diff options
author | Morris Jobke <hey@morrisjobke.de> | 2020-10-29 11:18:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-29 11:18:01 +0100 |
commit | 7ed11b6dfafb8793751f80a55f38e6242805386d (patch) | |
tree | 047de0138349c09a73b622ac55679b4060521d8d /tests | |
parent | 28e2551313062e04748b32433648bc0177c4a54b (diff) | |
parent | 765ee60eeacc8f9f41cb145b67821a192330daea (diff) | |
download | nextcloud-server-7ed11b6dfafb8793751f80a55f38e6242805386d.tar.gz nextcloud-server-7ed11b6dfafb8793751f80a55f38e6242805386d.zip |
Merge pull request #23765 from nextcloud/techdebt/noid/sudadmin-events-into-typed-events
Add typed events for adding and removing a subadmin
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/SubAdminTest.php | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/tests/lib/SubAdminTest.php b/tests/lib/SubAdminTest.php index 06c319d1f48..a3a795ce392 100644 --- a/tests/lib/SubAdminTest.php +++ b/tests/lib/SubAdminTest.php @@ -21,6 +21,10 @@ namespace Test; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Group\Events\SubAdminAddedEvent; +use OCP\Group\Events\SubAdminRemovedEvent; + /** * @group DB */ @@ -35,12 +39,15 @@ class SubAdminTest extends \Test\TestCase { /** @var \OCP\IDBConnection */ private $dbConn; + /** @var IEventDispatcher */ + private $eventDispatcher; + /** @var \OCP\IUser[] */ private $users; /** @var \OCP\IGroup[] */ private $groups; - + protected function setUp(): void { $this->users = []; $this->groups = []; @@ -48,6 +55,7 @@ class SubAdminTest extends \Test\TestCase { $this->userManager = \OC::$server->getUserManager(); $this->groupManager = \OC::$server->getGroupManager(); $this->dbConn = \OC::$server->getDatabaseConnection(); + $this->eventDispatcher = \OC::$server->get(IEventDispatcher::class); // Create 3 users and 3 groups for ($i = 0; $i < 3; $i++) { @@ -100,7 +108,7 @@ class SubAdminTest extends \Test\TestCase { } public function testCreateSubAdmin() { - $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn); + $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $subAdmin->createSubAdmin($this->users[0], $this->groups[0]); // Look for subadmin in the database @@ -125,7 +133,7 @@ class SubAdminTest extends \Test\TestCase { } public function testDeleteSubAdmin() { - $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn); + $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $subAdmin->createSubAdmin($this->users[0], $this->groups[0]); $subAdmin->deleteSubAdmin($this->users[0], $this->groups[0]); @@ -141,12 +149,12 @@ class SubAdminTest extends \Test\TestCase { } public function testGetSubAdminsGroups() { - $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn); + $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $subAdmin->createSubAdmin($this->users[0], $this->groups[0]); $subAdmin->createSubAdmin($this->users[0], $this->groups[1]); $result = $subAdmin->getSubAdminsGroups($this->users[0]); - + $this->assertContains($this->groups[0], $result); $this->assertContains($this->groups[1], $result); $this->assertNotContains($this->groups[2], $result); @@ -157,12 +165,12 @@ class SubAdminTest extends \Test\TestCase { } public function testGetGroupsSubAdmins() { - $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn); + $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $subAdmin->createSubAdmin($this->users[0], $this->groups[0]); $subAdmin->createSubAdmin($this->users[1], $this->groups[0]); $result = $subAdmin->getGroupsSubAdmins($this->groups[0]); - + $this->assertContains($this->users[0], $result); $this->assertContains($this->users[1], $result); $this->assertNotContains($this->users[2], $result); @@ -173,7 +181,7 @@ class SubAdminTest extends \Test\TestCase { } public function testGetAllSubAdmin() { - $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn); + $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $subAdmin->createSubAdmin($this->users[0], $this->groups[0]); $subAdmin->createSubAdmin($this->users[1], $this->groups[1]); @@ -188,7 +196,7 @@ class SubAdminTest extends \Test\TestCase { } public function testIsSubAdminofGroup() { - $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn); + $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $subAdmin->createSubAdmin($this->users[0], $this->groups[0]); $this->assertTrue($subAdmin->isSubAdminOfGroup($this->users[0], $this->groups[0])); @@ -199,7 +207,7 @@ class SubAdminTest extends \Test\TestCase { } public function testIsSubAdmin() { - $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn); + $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $subAdmin->createSubAdmin($this->users[0], $this->groups[0]); $this->assertTrue($subAdmin->isSubAdmin($this->users[0])); @@ -209,14 +217,14 @@ class SubAdminTest extends \Test\TestCase { } public function testIsSubAdminAsAdmin() { - $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn); + $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $this->groupManager->get('admin')->addUser($this->users[0]); $this->assertTrue($subAdmin->isSubAdmin($this->users[0])); } public function testIsUserAccessible() { - $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn); + $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $this->groups[0]->addUser($this->users[1]); $this->groups[1]->addUser($this->users[1]); $this->groups[1]->addUser($this->users[2]); @@ -232,12 +240,12 @@ class SubAdminTest extends \Test\TestCase { } public function testIsUserAccessibleAsUser() { - $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn); + $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $this->assertFalse($subAdmin->isUserAccessible($this->users[0], $this->users[1])); } public function testIsUserAccessibleAdmin() { - $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn); + $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $subAdmin->createSubAdmin($this->users[0], $this->groups[0]); $this->groupManager->get('admin')->addUser($this->users[1]); @@ -245,7 +253,7 @@ class SubAdminTest extends \Test\TestCase { } public function testPostDeleteUser() { - $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn); + $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $user = array_shift($this->users); foreach ($this->groups as $group) { @@ -257,7 +265,7 @@ class SubAdminTest extends \Test\TestCase { } public function testPostDeleteGroup() { - $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn); + $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $group = array_shift($this->groups); foreach ($this->users as $user) { @@ -269,22 +277,22 @@ class SubAdminTest extends \Test\TestCase { } public function testHooks() { - $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn); + $subAdmin = new \OC\SubAdmin($this->userManager, $this->groupManager, $this->dbConn, $this->eventDispatcher); $test = $this; $u = $this->users[0]; $g = $this->groups[0]; $count = 0; - $subAdmin->listen('\OC\SubAdmin', 'postCreateSubAdmin', function ($user, $group) use ($test, $u, $g, &$count) { - $test->assertEquals($u->getUID(), $user->getUID()); - $test->assertEquals($g->getGID(), $group->getGID()); + $this->eventDispatcher->addListener(SubAdminAddedEvent::class, function (SubAdminAddedEvent $event) use ($test, $u, $g, &$count) { + $test->assertEquals($u->getUID(), $event->getUser()->getUID()); + $test->assertEquals($g->getGID(), $event->getGroup()->getGID()); $count++; }); - $subAdmin->listen('\OC\SubAdmin', 'postDeleteSubAdmin', function ($user, $group) use ($test, $u, $g, &$count) { - $test->assertEquals($u->getUID(), $user->getUID()); - $test->assertEquals($g->getGID(), $group->getGID()); + $this->eventDispatcher->addListener(SubAdminRemovedEvent::class, function ($event) use ($test, $u, $g, &$count) { + $test->assertEquals($u->getUID(), $event->getUser()->getUID()); + $test->assertEquals($g->getGID(), $event->getGroup()->getGID()); $count++; }); |