aboutsummaryrefslogtreecommitdiff
path: root/tests/api_test.php
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2018-06-07 04:56:09 +0300
committerValentin Popov <info@valentineus.link>2018-06-07 04:56:09 +0300
commit6b3130d1d5cb56b7345dc3fd61756defbc021c39 (patch)
tree2e63ee8c55ba66c6edd15f75797aab3b77d87c32 /tests/api_test.php
parent50f9e3831c9d87534ac39fdb38378ab9ffdd48f5 (diff)
downloadtool_apisiteadmins-6b3130d1d5cb56b7345dc3fd61756defbc021c39.tar.xz
tool_apisiteadmins-6b3130d1d5cb56b7345dc3fd61756defbc021c39.zip
Function transfer
Signed-off-by: Valentin Popov <info@valentineus.link>
Diffstat (limited to 'tests/api_test.php')
-rw-r--r--tests/api_test.php54
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);
}
}