diff --git a/tests/phpunit/auth_plugin_test.php b/tests/auth_plugin_test.php similarity index 97% rename from tests/phpunit/auth_plugin_test.php rename to tests/auth_plugin_test.php index 28a15b9..c17493d 100644 --- a/tests/phpunit/auth_plugin_test.php +++ b/tests/auth_plugin_test.php @@ -14,6 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace auth_userkey; + +use advanced_testcase; +use auth_plugin_userkey; +use stdClass; +use invalid_parameter_exception; +use moodle_exception; +use external_value; + /** * Tests for auth_plugin_userkey class. * @@ -21,14 +30,7 @@ * @copyright 2016 Dmitrii Metelkin (dmitriim@catalyst-au.net) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -/** - * Tests for auth_plugin_userkey class. - * - * @copyright 2016 Dmitrii Metelkin (dmitriim@catalyst-au.net) - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class auth_plugin_userkey_testcase extends advanced_testcase { +class auth_plugin_test extends advanced_testcase { /** * An instance of auth_plugin_userkey class. * @var auth_plugin_userkey @@ -48,7 +50,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase { global $CFG; require_once($CFG->libdir . "/externallib.php"); - require_once($CFG->dirroot . '/auth/userkey/tests/phpunit/fake_userkey_manager.php'); + require_once($CFG->dirroot . '/auth/userkey/tests/fake_userkey_manager.php'); require_once($CFG->dirroot . '/auth/userkey/auth.php'); require_once($CFG->dirroot . '/user/lib.php'); @@ -262,7 +264,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase { self::getDataGenerator()->create_user($user); - $userkeymanager = new \auth_userkey\fake_userkey_manager(); + $userkeymanager = new fake_userkey_manager(); $this->auth->set_userkey_manager($userkeymanager); $expected = $CFG->wwwroot . '/auth/userkey/login.php?key=FaKeKeyFoRtEsTiNg'; @@ -283,7 +285,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase { self::getDataGenerator()->create_user($user); - $userkeymanager = new \auth_userkey\fake_userkey_manager(); + $userkeymanager = new fake_userkey_manager(); $this->auth->set_userkey_manager($userkeymanager); $expected = $CFG->wwwroot . '/auth/userkey/login.php?key=FaKeKeyFoRtEsTiNg'; @@ -305,7 +307,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase { self::getDataGenerator()->create_user($user); - $userkeymanager = new \auth_userkey\fake_userkey_manager(); + $userkeymanager = new fake_userkey_manager(); $this->auth->set_userkey_manager($userkeymanager); $expected = $CFG->wwwroot . '/auth/userkey/login.php?key=FaKeKeyFoRtEsTiNg'; @@ -323,7 +325,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase { set_config('createuser', true, 'auth_userkey'); $this->auth = new auth_plugin_userkey(); - $userkeymanager = new \auth_userkey\fake_userkey_manager(); + $userkeymanager = new fake_userkey_manager(); $this->auth->set_userkey_manager($userkeymanager); $user = new stdClass(); @@ -355,7 +357,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase { set_config('createuser', true, 'auth_userkey'); $this->auth = new auth_plugin_userkey(); - $userkeymanager = new \auth_userkey\fake_userkey_manager(); + $userkeymanager = new fake_userkey_manager(); $this->auth->set_userkey_manager($userkeymanager); $user = new stdClass(); @@ -375,7 +377,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase { set_config('createuser', true, 'auth_userkey'); $this->auth = new auth_plugin_userkey(); - $userkeymanager = new \auth_userkey\fake_userkey_manager(); + $userkeymanager = new fake_userkey_manager(); $this->auth->set_userkey_manager($userkeymanager); $originaluser = new stdClass(); @@ -405,7 +407,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase { set_config('mappingfield', 'username', 'auth_userkey'); $this->auth = new auth_plugin_userkey(); - $userkeymanager = new \auth_userkey\fake_userkey_manager(); + $userkeymanager = new fake_userkey_manager(); $this->auth->set_userkey_manager($userkeymanager); $originaluser = new stdClass(); @@ -436,7 +438,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase { set_config('updateuser', true, 'auth_userkey'); $this->auth = new auth_plugin_userkey(); - $userkeymanager = new \auth_userkey\fake_userkey_manager(); + $userkeymanager = new fake_userkey_manager(); $this->auth->set_userkey_manager($userkeymanager); $originaluser = new stdClass(); @@ -477,7 +479,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase { set_config('mappingfield', 'username', 'auth_userkey'); $this->auth = new auth_plugin_userkey(); - $userkeymanager = new \auth_userkey\fake_userkey_manager(); + $userkeymanager = new fake_userkey_manager(); $this->auth->set_userkey_manager($userkeymanager); self::getDataGenerator()->create_user(['email' => 'trytoduplicate@test.com']); @@ -504,7 +506,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase { set_config('updateuser', true, 'auth_userkey'); $this->auth = new auth_plugin_userkey(); - $userkeymanager = new \auth_userkey\fake_userkey_manager(); + $userkeymanager = new fake_userkey_manager(); $this->auth->set_userkey_manager($userkeymanager); self::getDataGenerator()->create_user(['username' => 'trytoduplicate']); diff --git a/tests/phpunit/core_userkey_manager_test.php b/tests/core_userkey_manager_test.php similarity index 97% rename from tests/phpunit/core_userkey_manager_test.php rename to tests/core_userkey_manager_test.php index cadc3f0..fa113a7 100644 --- a/tests/phpunit/core_userkey_manager_test.php +++ b/tests/core_userkey_manager_test.php @@ -14,15 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Tests for core_userkey_manager class. - * - * @package auth_userkey - * @copyright 2016 Dmitrii Metelkin (dmitriim@catalyst-au.net) - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -use auth_userkey\core_userkey_manager; +namespace auth_userkey; /** * Tests for core_userkey_manager class. @@ -30,10 +22,11 @@ use auth_userkey\core_userkey_manager; * Key validation is fully covered in auth_plugin_test.php file. * TODO: write tests for validate_key() function. * + * @package auth_userkey * @copyright 2016 Dmitrii Metelkin (dmitriim@catalyst-au.net) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_userkey_manager_testcase extends advanced_testcase { +class core_userkey_manager_test extends \advanced_testcase { /** * Test user object. * @var @@ -57,7 +50,7 @@ class core_userkey_manager_testcase extends advanced_testcase { $this->resetAfterTest(); $CFG->getremoteaddrconf = GETREMOTEADDR_SKIP_HTTP_X_FORWARDED_FOR; $this->user = self::getDataGenerator()->create_user(); - $this->config = new stdClass(); + $this->config = new \stdClass(); } /** @@ -166,7 +159,7 @@ class core_userkey_manager_testcase extends advanced_testcase { $_SERVER['HTTP_CLIENT_IP'] = '193.168.1.2'; - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $this->expectExceptionMessage('Client IP address mismatch'); $manager->validate_key($value); diff --git a/tests/phpunit/externallib_test.php b/tests/externallib_test.php similarity index 97% rename from tests/phpunit/externallib_test.php rename to tests/externallib_test.php index 28aa256..1148b2b 100644 --- a/tests/phpunit/externallib_test.php +++ b/tests/externallib_test.php @@ -14,6 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace auth_userkey; + +use advanced_testcase; +use webservice_access_exception; +use auth_userkey_external; +use external_api; +use invalid_parameter_exception; +use required_capability_exception; +use context_system; + /** * Tests for externallib.php. * @@ -21,7 +31,7 @@ * @copyright 2016 Dmitrii Metelkin (dmitriim@catalyst-au.net) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class auth_userkey_externallib_testcase extends advanced_testcase { +class externallib_test extends advanced_testcase { /** * User object. * diff --git a/tests/phpunit/fake_userkey_manager.php b/tests/fake_userkey_manager.php similarity index 100% rename from tests/phpunit/fake_userkey_manager.php rename to tests/fake_userkey_manager.php