diff options
author | Valentin Popov <info@valentineus.link> | 2018-06-07 04:56:09 +0300 |
---|---|---|
committer | Valentin Popov <info@valentineus.link> | 2018-06-07 04:56:09 +0300 |
commit | 6b3130d1d5cb56b7345dc3fd61756defbc021c39 (patch) | |
tree | 2e63ee8c55ba66c6edd15f75797aab3b77d87c32 | |
parent | 50f9e3831c9d87534ac39fdb38378ab9ffdd48f5 (diff) | |
download | tool_apisiteadmins-6b3130d1d5cb56b7345dc3fd61756defbc021c39.tar.xz tool_apisiteadmins-6b3130d1d5cb56b7345dc3fd61756defbc021c39.zip |
Function transfer
Signed-off-by: Valentin Popov <info@valentineus.link>
-rw-r--r-- | tests/api_test.php | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/tests/api_test.php b/tests/api_test.php index d8ed961..d7b9f4b 100644 --- a/tests/api_test.php +++ b/tests/api_test.php @@ -66,22 +66,35 @@ class tool_apisiteadmins_api_testcase extends advanced_testcase { /** * @depends test_adding_and_deleting_administrator */ - public function test_exception_adding_check() { + public function test_changing_main_administrator() { global $CFG; - $this->expectException(moodle_exception::class); $this->resetAfterTest(true); - $userid = mt_rand(99, 999); + $user1 = $this->getDataGenerator()->create_user(); + $user2 = $this->getDataGenerator()->create_user(); - /* Adds a non-existent user */ - tool_apisiteadmins::add_user($userid); + /* Adds users to the list */ + tool_apisiteadmins::add_user($user1->id); + tool_apisiteadmins::add_user($user2->id); + $this->assertArrayHasKey($user1->id, get_admins()); + $this->assertArrayHasKey($user2->id, get_admins()); + + /* Sets first user main */ + tool_apisiteadmins::set_main($user1->id); + $this->assertCount(3, get_admins()); + $this->assertEquals($user1, get_admin()); + + /* Sets second user main */ + tool_apisiteadmins::set_main($user2->id); + $this->assertCount(3, get_admins()); + $this->assertEquals($user2, get_admin()); } /** * @depends test_adding_and_deleting_administrator */ - public function test_exception_removal_check() { + public function test_exception_adding_check() { global $CFG; $this->expectException(moodle_exception::class); @@ -89,37 +102,22 @@ class tool_apisiteadmins_api_testcase extends advanced_testcase { $userid = mt_rand(99, 999); - /* Removes a non-existent user */ - tool_apisiteadmins::remove_user($userid); + /* Adds a non-existent user */ + tool_apisiteadmins::add_user($userid); } /** * @depends test_adding_and_deleting_administrator - * @depends test_exception_adding_check - * @depends test_exception_removal_check */ - public function test_changing_main_administrator() { + public function test_exception_removal_check() { global $CFG; + $this->expectException(moodle_exception::class); $this->resetAfterTest(true); - $user1 = $this->getDataGenerator()->create_user(); - $user2 = $this->getDataGenerator()->create_user(); - - /* Adds users to the list */ - tool_apisiteadmins::add_user($user1->id); - tool_apisiteadmins::add_user($user2->id); - $this->assertArrayHasKey($user1->id, get_admins()); - $this->assertArrayHasKey($user2->id, get_admins()); - - /* Sets first user main */ - tool_apisiteadmins::set_main($user1->id); - $this->assertCount(3, get_admins()); - $this->assertEquals($user1, get_admin()); + $userid = mt_rand(99, 999); - /* Sets second user main */ - tool_apisiteadmins::set_main($user2->id); - $this->assertCount(3, get_admins()); - $this->assertEquals($user2, get_admin()); + /* Removes a non-existent user */ + tool_apisiteadmins::remove_user($userid); } } |