From eb0c520ad6a4ee7b8f78bbae3a130f782f2d198b Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sat, 5 Feb 2022 10:30:50 +0100 Subject: [PATCH] MDL-73785 phpunit: Move more tests to use correct names and namespaces Applied the following changes to various testcase classes: - Namespaced with component[\level2-API] - Moved to level2-API subdirectory when required. - Fixed incorrect use statements with leading backslash. - Remove file phpdoc block - Remove MOODLE_INTERNAL if not needed. - Changed code to point to global scope when needed. - Fix some relative paths and comments here and there. - All them passing individually. - Complete runs passing too. Special mention to: - When belonging to other components and being valid api: - analytics related tests have been moved to tests/analytics subdir. - backup & restore related tests have been moved to tests/backup subdir. - events related tests have been moved to tests/event subdir. - privacy related tests have been moved to tests/privacy. - task related tests have been moved to tests/task subdir. - Some simple renames, not including the component part anymore (not needed now that they are namespaced): - some xxxlib_test.php have been renamed lib_test.php (when they where testing the corresponding lib.php). - cache stores tests have been all renamed store_test, originally each one had its own name (file_test, apcu_test, redis_test...) - assign feedback tests have been all renamed feedback_test, originally each one had its own name (file_test, editpdf_test...) --- .../tests/{ => task}/task_test.php | 16 +- .../log/store/database/tests/store_test.php | 47 ++-- .../log/store/legacy/tests/store_test.php | 19 +- .../log/store/standard/tests/store_test.php | 75 +++---- admin/tool/lpimportcsv/tests/import_test.php | 13 +- admin/tool/lpmigrate/tests/processor_test.php | 37 ++-- admin/tool/uploadcourse/tests/course_test.php | 39 ++-- .../uploadcourse/tests/processor_test.php | 44 ++-- admin/tool/usertours/tests/cache_test.php | 14 +- admin/tool/usertours/tests/step_test.php | 10 +- analytics/tests/course_test.php | 12 +- .../completion/tests/condition_test.php | 54 ++--- .../condition/date/tests/condition_test.php | 21 +- .../condition/grade/tests/condition_test.php | 28 +-- .../condition/group/tests/condition_test.php | 16 +- .../grouping/tests/condition_test.php | 24 +-- .../profile/tests/condition_test.php | 34 ++- backup/util/plan/tests/plan_test.php | 37 ++-- backup/util/plan/tests/step_test.php | 113 +++++----- backup/util/plan/tests/task_test.php | 45 ++-- .../util/structure/tests/structure_test.php | 88 ++++---- .../tests/observer_test.php | 27 +-- .../tests/{apcu_test.php => store_test.php} | 14 +- .../tests/{file_test.php => store_test.php} | 14 +- .../{memcached_test.php => store_test.php} | 48 ++--- .../{mongodb_test.php => store_test.php} | 26 ++- cache/stores/redis/tests/compressor_test.php | 60 +++--- .../tests/{redis_test.php => store_test.php} | 26 ++- .../{session_test.php => store_test.php} | 24 +-- .../tests/{static_test.php => store_test.php} | 20 +- cache/tests/cache_test.php | 202 ++++++++++-------- calendar/tests/event_test.php | 17 +- .../{cohortlib_test.php => lib_test.php} | 103 +++++---- .../{event_test.php => event/events_test.php} | 85 ++++---- competency/tests/plan_test.php | 86 ++++---- competency/tests/{ => task}/task_test.php | 39 ++-- competency/tests/template_test.php | 15 +- completion/tests/progress_test.php | 17 +- course/format/weeks/tests/observer_test.php | 12 +- .../tests/{ => analytics}/indicators_test.php | 23 +- course/tests/{ => backup}/restore_test.php | 17 +- course/tests/customfield_test.php | 24 +-- .../{cohortlib_test.php => lib_test.php} | 20 +- enrol/cohort/tests/sync_test.php | 105 +++++---- enrol/database/tests/sync_test.php | 29 +-- filter/displayh5p/tests/upgradelib_test.php | 15 +- .../events_test.php} | 20 +- .../events_test.php} | 20 +- .../events_test.php} | 20 +- .../events_test.php} | 20 +- .../legacy_polyfill_test.php} | 17 +- grade/report/history/tests/report_test.php | 56 +++-- lib/form/tests/course_test.php | 17 +- lib/mlbackend/python/tests/processor_test.php | 15 +- lib/tests/{ => analytics}/indicators_test.php | 19 +- lib/tests/datalib_test.php | 72 +++---- .../{event_test.php => event/base_test.php} | 75 +++---- lib/tests/messagelib_test.php | 51 +++-- lib/tests/progress_test.php | 44 ++-- lib/tests/rsslib_test.php | 31 +-- lib/tests/scss_test.php | 17 +- media/player/html5audio/tests/player_test.php | 27 +-- media/player/html5video/tests/player_test.php | 27 +-- media/player/vimeo/tests/player_test.php | 38 ++-- media/player/youtube/tests/player_test.php | 46 ++-- .../{comments_test.php => feedback_test.php} | 13 +- .../{editpdf_test.php => feedback_test.php} | 30 +-- .../{file_test.php => feedback_test.php} | 29 ++- mod/assign/tests/base_test.php | 18 +- mod/assign/tests/portfolio_caller_test.php | 46 ++-- mod/assign/tests/upgradelib_test.php | 20 +- mod/data/tests/import_test.php | 22 +- mod/forum/tests/portfolio_caller_test.php | 24 +-- mod/forum/tests/rsslib_test.php | 13 +- mod/label/tests/lib_test.php | 11 - .../{ => backup}/restore_override_test.php | 17 +- .../{event_test.php => event/events_test.php} | 30 ++- mod/workshop/tests/portfolio_caller_test.php | 34 ++- .../legacy_polyfill_test.php} | 17 +- .../legacy_polyfill_test.php} | 17 +- search/engine/simpledb/tests/engine_test.php | 25 +-- search/engine/solr/tests/engine_test.php | 99 ++++----- search/tests/base_test.php | 16 +- search/tests/engine_test.php | 15 +- theme/boost/tests/scss_test.php | 14 +- theme/classic/tests/scss_test.php | 15 +- 86 files changed, 1304 insertions(+), 1707 deletions(-) rename admin/tool/dataprivacy/tests/{ => task}/task_test.php (96%) rename cache/stores/apcu/tests/{apcu_test.php => store_test.php} (93%) rename cache/stores/file/tests/{file_test.php => store_test.php} (91%) rename cache/stores/memcached/tests/{memcached_test.php => store_test.php} (94%) rename cache/stores/mongodb/tests/{mongodb_test.php => store_test.php} (91%) rename cache/stores/redis/tests/{redis_test.php => store_test.php} (93%) rename cache/stores/session/tests/{session_test.php => store_test.php} (93%) rename cache/stores/static/tests/{static_test.php => store_test.php} (93%) rename cohort/tests/{cohortlib_test.php => lib_test.php} (88%) rename competency/tests/{event_test.php => event/events_test.php} (97%) rename competency/tests/{ => task}/task_test.php (90%) rename course/tests/{ => analytics}/indicators_test.php (95%) rename course/tests/{ => backup}/restore_test.php (98%) rename enrol/cohort/tests/{cohortlib_test.php => lib_test.php} (91%) rename grade/export/ods/tests/{logging_test.php => event/events_test.php} (80%) rename grade/export/txt/tests/{logging_test.php => event/events_test.php} (80%) rename grade/export/xls/tests/{logging_test.php => event/events_test.php} (80%) rename grade/export/xml/tests/{logging_test.php => event/events_test.php} (80%) rename grade/grading/tests/{privacy_legacy_polyfill_test.php => privacy/legacy_polyfill_test.php} (92%) rename lib/tests/{ => analytics}/indicators_test.php (96%) rename lib/tests/{event_test.php => event/base_test.php} (95%) rename mod/assign/feedback/comments/tests/{comments_test.php => feedback_test.php} (91%) rename mod/assign/feedback/editpdf/tests/{editpdf_test.php => feedback_test.php} (96%) rename mod/assign/feedback/file/tests/{file_test.php => feedback_test.php} (92%) rename mod/lesson/tests/{ => backup}/restore_override_test.php (88%) rename mod/quiz/accessrule/seb/tests/{event_test.php => event/events_test.php} (89%) rename plagiarism/tests/{privacy_legacy_polyfill_test.php => privacy/legacy_polyfill_test.php} (93%) rename portfolio/tests/{privacy_legacy_polyfill_test.php => privacy/legacy_polyfill_test.php} (93%) diff --git a/admin/tool/dataprivacy/tests/task_test.php b/admin/tool/dataprivacy/tests/task/task_test.php similarity index 96% rename from admin/tool/dataprivacy/tests/task_test.php rename to admin/tool/dataprivacy/tests/task/task_test.php index 8ab89199632..a418bce74ba 100644 --- a/admin/tool/dataprivacy/tests/task_test.php +++ b/admin/tool/dataprivacy/tests/task/task_test.php @@ -14,19 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Tests for scheduled tasks. - * - * @package tool_dataprivacy - * @copyright 2018 Mihail Geshoski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); -require_once('data_privacy_testcase.php'); +namespace tool_dataprivacy\task; use tool_dataprivacy\api; +defined('MOODLE_INTERNAL') || die(); +require_once(__DIR__ . '/../data_privacy_testcase.php'); + /** * Tests for scheduled tasks. * @@ -34,7 +28,7 @@ use tool_dataprivacy\api; * @copyright 2018 Mihail Geshoski * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class tool_dataprivacy_task_testcase extends data_privacy_testcase { +class task_test extends \data_privacy_testcase { /** * Test tearDown. diff --git a/admin/tool/log/store/database/tests/store_test.php b/admin/tool/log/store/database/tests/store_test.php index 10dab29ce41..8c24a294801 100644 --- a/admin/tool/log/store/database/tests/store_test.php +++ b/admin/tool/log/store/database/tests/store_test.php @@ -14,6 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace logstore_database; + +defined('MOODLE_INTERNAL') || die(); + +require_once(__DIR__ . '/fixtures/event.php'); +require_once(__DIR__ . '/fixtures/store.php'); + /** * External database log store tests. * @@ -21,13 +28,7 @@ * @copyright 2014 Petr Skoda {@link http://skodak.org/} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -require_once(__DIR__ . '/fixtures/event.php'); -require_once(__DIR__ . '/fixtures/store.php'); - -class logstore_database_store_testcase extends advanced_testcase { +class store_test extends \advanced_testcase { /** * Tests log writing. * @@ -120,7 +121,7 @@ class logstore_database_store_testcase extends advanced_testcase { $this->setUser(0); $event1 = \logstore_database\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10))); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10))); $event1->trigger(); $logs = $DB->get_records('logstore_standard_log', array(), 'id ASC'); @@ -141,11 +142,11 @@ class logstore_database_store_testcase extends advanced_testcase { $this->assertEquals($data, $log1); $this->setAdminUser(); - \core\session\manager::loginas($user1->id, context_system::instance()); + \core\session\manager::loginas($user1->id, \context_system::instance()); $this->assertEquals(2, $DB->count_records('logstore_standard_log')); $event2 = \logstore_database\event\unittest_executed::create( - array('context' => context_module::instance($module2->cmid), 'other' => array('sample' => 6, 'xx' => 9))); + array('context' => \context_module::instance($module2->cmid), 'other' => array('sample' => 6, 'xx' => 9))); $event2->trigger(); \core\session\manager::init_empty_session(); @@ -190,30 +191,30 @@ class logstore_database_store_testcase extends advanced_testcase { $DB->delete_records('logstore_standard_log'); \logstore_database\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(0, $DB->count_records('logstore_standard_log')); \logstore_database\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(0, $DB->count_records('logstore_standard_log')); $store->flush(); $this->assertEquals(2, $DB->count_records('logstore_standard_log')); \logstore_database\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(2, $DB->count_records('logstore_standard_log')); \logstore_database\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(2, $DB->count_records('logstore_standard_log')); \logstore_database\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(5, $DB->count_records('logstore_standard_log')); \logstore_database\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(5, $DB->count_records('logstore_standard_log')); \logstore_database\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(5, $DB->count_records('logstore_standard_log')); \logstore_database\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(8, $DB->count_records('logstore_standard_log')); // Test guest logging setting. @@ -225,22 +226,22 @@ class logstore_database_store_testcase extends advanced_testcase { $this->setUser(null); \logstore_database\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(0, $DB->count_records('logstore_standard_log')); $this->setGuestUser(); \logstore_database\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(0, $DB->count_records('logstore_standard_log')); $this->setUser($user1); \logstore_database\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(1, $DB->count_records('logstore_standard_log')); $this->setUser($user2); \logstore_database\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(2, $DB->count_records('logstore_standard_log')); set_config('enabled_stores', '', 'tool_log'); @@ -270,7 +271,7 @@ class logstore_database_store_testcase extends advanced_testcase { set_config('logguests', 0, 'logstore_database'); $this->setGuestUser(); $event = \logstore_database\event\unittest_executed::create( - array('context' => context_system::instance(), 'other' => array('sample' => 5, 'xx' => 10))); + array('context' => \context_system::instance(), 'other' => array('sample' => 5, 'xx' => 10))); $logmanager = get_log_manager(); $store = new \logstore_database\test\store($logmanager); $this->assertTrue($store->is_event_ignored($event)); diff --git a/admin/tool/log/store/legacy/tests/store_test.php b/admin/tool/log/store/legacy/tests/store_test.php index f0a95a3849d..c55121ff75e 100644 --- a/admin/tool/log/store/legacy/tests/store_test.php +++ b/admin/tool/log/store/legacy/tests/store_test.php @@ -14,6 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace logstore_legacy; + +defined('MOODLE_INTERNAL') || die(); + +require_once(__DIR__ . '/fixtures/event.php'); +require_once(__DIR__ . '/fixtures/store.php'); + /** * Legacy log store tests. * @@ -21,13 +28,7 @@ * @copyright 2014 Petr Skoda {@link http://skodak.org/} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -require_once(__DIR__ . '/fixtures/event.php'); -require_once(__DIR__ . '/fixtures/store.php'); - -class logstore_legacy_store_testcase extends advanced_testcase { +class store_test extends \advanced_testcase { public function test_log_writing() { global $DB; $this->resetAfterTest(); @@ -58,12 +59,12 @@ class logstore_legacy_store_testcase extends advanced_testcase { $this->setUser(0); $event1 = \logstore_legacy\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10))); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10))); $event1->trigger(); $this->setUser($user1); $event2 = \logstore_legacy\event\unittest_executed::create( - array('context' => context_course::instance($course2->id), 'other' => array('sample' => 6, 'xx' => 11))); + array('context' => \context_course::instance($course2->id), 'other' => array('sample' => 6, 'xx' => 11))); $event2->trigger(); $logs = $DB->get_records('log', array(), 'id ASC'); diff --git a/admin/tool/log/store/standard/tests/store_test.php b/admin/tool/log/store/standard/tests/store_test.php index aeb15c6b61e..c0154c02829 100644 --- a/admin/tool/log/store/standard/tests/store_test.php +++ b/admin/tool/log/store/standard/tests/store_test.php @@ -14,6 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace logstore_standard; + +defined('MOODLE_INTERNAL') || die(); + +require_once(__DIR__ . '/fixtures/event.php'); +require_once(__DIR__ . '/fixtures/restore_hack.php'); + /** * Standard log store tests. * @@ -21,13 +28,7 @@ * @copyright 2014 Petr Skoda {@link http://skodak.org/} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -require_once(__DIR__ . '/fixtures/event.php'); -require_once(__DIR__ . '/fixtures/restore_hack.php'); - -class logstore_standard_store_testcase extends advanced_testcase { +class store_test extends \advanced_testcase { /** * @var bool Determine if we disabled the GC, so it can be re-enabled in tearDown. */ @@ -84,7 +85,7 @@ class logstore_standard_store_testcase extends advanced_testcase { $this->setUser(0); $event1 = \logstore_standard\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10))); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10))); $event1->trigger(); $logs = $DB->get_records('logstore_standard_log', array(), 'id ASC'); @@ -105,14 +106,14 @@ class logstore_standard_store_testcase extends advanced_testcase { $this->assertEquals($data, $log1); $this->setAdminUser(); - \core\session\manager::loginas($user1->id, context_system::instance()); + \core\session\manager::loginas($user1->id, \context_system::instance()); $this->assertEquals(2, $DB->count_records('logstore_standard_log')); - logstore_standard_restore::hack_executing(1); + \logstore_standard_restore::hack_executing(1); $event2 = \logstore_standard\event\unittest_executed::create( - array('context' => context_module::instance($module2->cmid), 'other' => array('sample' => 6, 'xx' => 9))); + array('context' => \context_module::instance($module2->cmid), 'other' => array('sample' => 6, 'xx' => 9))); $event2->trigger(); - logstore_standard_restore::hack_executing(0); + \logstore_standard_restore::hack_executing(0); \core\session\manager::init_empty_session(); $this->assertFalse(\core\session\manager::is_loggedinas()); @@ -161,30 +162,30 @@ class logstore_standard_store_testcase extends advanced_testcase { $DB->delete_records('logstore_standard_log'); \logstore_standard\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(0, $DB->count_records('logstore_standard_log')); \logstore_standard\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(0, $DB->count_records('logstore_standard_log')); $store->flush(); $this->assertEquals(2, $DB->count_records('logstore_standard_log')); \logstore_standard\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(2, $DB->count_records('logstore_standard_log')); \logstore_standard\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(2, $DB->count_records('logstore_standard_log')); \logstore_standard\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(5, $DB->count_records('logstore_standard_log')); \logstore_standard\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(5, $DB->count_records('logstore_standard_log')); \logstore_standard\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(5, $DB->count_records('logstore_standard_log')); \logstore_standard\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(8, $DB->count_records('logstore_standard_log')); // Test guest logging setting. @@ -196,22 +197,22 @@ class logstore_standard_store_testcase extends advanced_testcase { $this->setUser(null); \logstore_standard\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(0, $DB->count_records('logstore_standard_log')); $this->setGuestUser(); \logstore_standard\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(0, $DB->count_records('logstore_standard_log')); $this->setUser($user1); \logstore_standard\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(1, $DB->count_records('logstore_standard_log')); $this->setUser($user2); \logstore_standard\event\unittest_executed::create( - array('context' => context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); + array('context' => \context_module::instance($module1->cmid), 'other' => array('sample' => 5, 'xx' => 10)))->trigger(); $this->assertEquals(2, $DB->count_records('logstore_standard_log')); set_config('enabled_stores', '', 'tool_log'); @@ -335,7 +336,7 @@ class logstore_standard_store_testcase extends advanced_testcase { $this->resetAfterTest(); // Create some records spread over various days; test multiple iterations in cleanup. - $ctx = context_course::instance(1); + $ctx = \context_course::instance(1); $record = (object) array( 'edulevel' => 0, 'contextid' => $ctx->id, @@ -424,11 +425,11 @@ class logstore_standard_store_testcase extends advanced_testcase { // Create some log data in a course - one with other data, one without. \logstore_standard\event\unittest_executed::create([ - 'context' => context_course::instance($course->id), + 'context' => \context_course::instance($course->id), 'other' => ['sample' => 5, 'xx' => 10]])->trigger(); $this->waitForSecond(); \logstore_standard\event\unittest_executed::create([ - 'context' => context_course::instance($course->id)])->trigger(); + 'context' => \context_course::instance($course->id)])->trigger(); $records = array_values($DB->get_records('logstore_standard_log', ['courseid' => $course->id, 'target' => 'unittest'], 'timecreated')); @@ -473,7 +474,7 @@ class logstore_standard_store_testcase extends advanced_testcase { /** * Backs a course up to temp directory. * - * @param stdClass $course Course object to backup + * @param \stdClass $course Course object to backup * @return string ID of backup */ protected function backup($course): string { @@ -481,14 +482,14 @@ class logstore_standard_store_testcase extends advanced_testcase { require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php'); // Turn off file logging, otherwise it can't delete the file (Windows). - $CFG->backup_file_logger_level = backup::LOG_NONE; + $CFG->backup_file_logger_level = \backup::LOG_NONE; // Do backup with default settings. MODE_IMPORT means it will just // create the directory and not zip it. - $bc = new backup_controller(backup::TYPE_1COURSE, $course->id, - backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_IMPORT, + $bc = new \backup_controller(\backup::TYPE_1COURSE, $course->id, + \backup::FORMAT_MOODLE, \backup::INTERACTIVE_NO, \backup::MODE_IMPORT, $USER->id); - $bc->get_plan()->get_setting('users')->set_status(backup_setting::NOT_LOCKED); + $bc->get_plan()->get_setting('users')->set_status(\backup_setting::NOT_LOCKED); $bc->get_plan()->get_setting('users')->set_value(true); $bc->get_plan()->get_setting('logs')->set_value(true); $backupid = $bc->get_backupid(); @@ -505,18 +506,18 @@ class logstore_standard_store_testcase extends advanced_testcase { * @param \stdClass $course Original course object * @param string $suffix Suffix to add after original course shortname and fullname * @return int New course id - * @throws restore_controller_exception + * @throws \restore_controller_exception */ protected function restore(string $backupid, $course, string $suffix): int { global $USER, $CFG; require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php'); // Do restore to new course with default settings. - $newcourseid = restore_dbops::create_new_course( + $newcourseid = \restore_dbops::create_new_course( $course->fullname . $suffix, $course->shortname . $suffix, $course->category); - $rc = new restore_controller($backupid, $newcourseid, - backup::INTERACTIVE_NO, backup::MODE_GENERAL, $USER->id, - backup::TARGET_NEW_COURSE); + $rc = new \restore_controller($backupid, $newcourseid, + \backup::INTERACTIVE_NO, \backup::MODE_GENERAL, $USER->id, + \backup::TARGET_NEW_COURSE); $rc->get_plan()->get_setting('logs')->set_value(true); $rc->get_plan()->get_setting('users')->set_value(true); diff --git a/admin/tool/lpimportcsv/tests/import_test.php b/admin/tool/lpimportcsv/tests/import_test.php index b0d8d0948c2..976381df63f 100644 --- a/admin/tool/lpimportcsv/tests/import_test.php +++ b/admin/tool/lpimportcsv/tests/import_test.php @@ -13,18 +13,9 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * External learning plans webservice API tests. - * - * @package tool_lpimportcsv - * @copyright 2015 Damyon Wiese - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -defined('MOODLE_INTERNAL') || die(); +namespace tool_lpimportcsv; -use tool_lpimportcsv\framework_importer; -use tool_lpimportcsv\framework_exporter; use core_competency\api; /** @@ -34,7 +25,7 @@ use core_competency\api; * @copyright 2015 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class tool_lpimportcsv_import_testcase extends advanced_testcase { +class import_test extends \advanced_testcase { public function test_import_framework() { $this->resetAfterTest(true); diff --git a/admin/tool/lpmigrate/tests/processor_test.php b/admin/tool/lpmigrate/tests/processor_test.php index 83b93148aea..fb2eda42cd4 100644 --- a/admin/tool/lpmigrate/tests/processor_test.php +++ b/admin/tool/lpmigrate/tests/processor_test.php @@ -14,21 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Framework processor tests. - * - * @package tool_lpmigrate - * @copyright 2016 Frédéric Massart - FMCorz.net - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); -global $CFG; +namespace tool_lpmigrate; use core_competency\course_competency; use core_competency\course_module_competency; -use tool_lpmigrate\framework_mapper; -use tool_lpmigrate\framework_processor; /** * Framework processor testcase. @@ -37,7 +26,7 @@ use tool_lpmigrate\framework_processor; * @copyright 2016 Frédéric Massart - FMCorz.net * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class tool_lpmigrate_framework_processor_testcase extends advanced_testcase { +class processor_test extends \advanced_testcase { /** * This sets up a few things, and assign class variables. @@ -402,13 +391,13 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase { $dg = $this->getDataGenerator(); $u = $dg->create_user(); $role = $dg->create_role(); - $sysctx = context_system::instance(); + $sysctx = \context_system::instance(); $dg->enrol_user($u->id, $this->c1->id, 'editingteacher'); $dg->enrol_user($u->id, $this->c2->id, 'editingteacher'); assign_capability('moodle/competency:coursecompetencymanage', CAP_PROHIBIT, $role, $sysctx->id); - role_assign($role, $u->id, context_course::instance($this->c1->id)->id); - role_assign($role, $u->id, context_module::instance($this->cms[$this->c2->id]['F1']->cmid)->id); + role_assign($role, $u->id, \context_course::instance($this->c1->id)->id); + role_assign($role, $u->id, \context_module::instance($this->cms[$this->c2->id]['F1']->cmid)->id); accesslib_clear_all_caches_for_unit_testing(); $this->setUser($u); @@ -484,7 +473,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase { /** * Assert that the course competency exists. * - * @param stdClass $course The course. + * @param \stdClass $course The course. * @param competency $competency The competency. */ protected function assertCourseCompetencyExists($course, $competency) { @@ -495,7 +484,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase { /** * Assert that the course competency does not exist. * - * @param stdClass $course The course. + * @param \stdClass $course The course. * @param competency $competency The competency. */ protected function assertCourseCompetencyNotExists($course, $competency) { @@ -506,7 +495,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase { /** * Assert that the course competency was migrated. * - * @param stdClass $course The course. + * @param \stdClass $course The course. * @param competency $compfrom The competency from. * @param competency $compto The competency to. */ @@ -531,7 +520,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase { /** * Assert that the course competency was not migrated. * - * @param stdClass $course The course. + * @param \stdClass $course The course. * @param competency $compfrom The competency from. * @param competency $compto The competency to. */ @@ -553,7 +542,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase { /** * Assert that the course module competency exists. * - * @param stdClass $cm The CM. + * @param \stdClass $cm The CM. * @param competency $competency The competency. */ protected function assertModuleCompetencyExists($cm, $competency) { @@ -564,7 +553,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase { /** * Assert that the course module competency does not exist. * - * @param stdClass $cm The CM. + * @param \stdClass $cm The CM. * @param competency $competency The competency. */ protected function assertModuleCompetencyNotExists($cm, $competency) { @@ -575,7 +564,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase { /** * Assert that the course module competency was migrated. * - * @param stdClass $cm The CM. + * @param \stdClass $cm The CM. * @param competency $compfrom The competency from. * @param competency $compto The competency to. */ @@ -600,7 +589,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase { /** * Assert that the course module competency was not migrated. * - * @param stdClass $cm The CM. + * @param \stdClass $cm The CM. * @param competency $compfrom The competency from. * @param competency $compto The competency to. */ diff --git a/admin/tool/uploadcourse/tests/course_test.php b/admin/tool/uploadcourse/tests/course_test.php index 7a2108e205d..cf77b2762af 100644 --- a/admin/tool/uploadcourse/tests/course_test.php +++ b/admin/tool/uploadcourse/tests/course_test.php @@ -14,17 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * File containing tests for the course class. - * - * @package tool_uploadcourse - * @copyright 2013 Frédéric Massart - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace tool_uploadcourse; -defined('MOODLE_INTERNAL') || die(); - -global $CFG; +use tool_uploadcourse_processor; +use tool_uploadcourse_course; /** * Course test case. @@ -33,7 +26,7 @@ global $CFG; * @copyright 2013 Frédéric Massart * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late */ -class tool_uploadcourse_course_testcase extends advanced_testcase { +class course_test extends \advanced_testcase { public function test_proceed_without_prepare() { $this->resetAfterTest(true); @@ -41,7 +34,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase { $updatemode = tool_uploadcourse_processor::UPDATE_NOTHING; $data = array(); $co = new tool_uploadcourse_course($mode, $updatemode, $data); - $this->expectException(coding_exception::class); + $this->expectException(\coding_exception::class); $co->proceed(); } @@ -52,7 +45,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase { $data = array(); $co = new tool_uploadcourse_course($mode, $updatemode, $data); $this->assertFalse($co->prepare()); - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $co->proceed(); } @@ -154,7 +147,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase { // Create category in which to create the new course. $category = $this->getDataGenerator()->create_category(); - $categorycontext = context_coursecat::instance($category->id); + $categorycontext = \context_coursecat::instance($category->id); $user = $this->getDataGenerator()->create_user(); $this->setUser($user); @@ -464,7 +457,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase { $co->proceed(); $this->assertTrue($DB->record_exists('course', array('shortname' => 'c1'))); $course = $DB->get_record('course', array('shortname' => 'c1')); - $ctx = context_course::instance($course->id); + $ctx = \context_course::instance($course->id); $this->assertEquals($data['fullname'], $course->fullname); $this->assertEquals($data['category'], $course->category); @@ -485,7 +478,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase { $this->assertEquals($data['groupmode'], $course->groupmode); $this->assertEquals($data['groupmodeforce'], $course->groupmodeforce); $this->assertEquals($data['enablecompletion'], $course->enablecompletion); - $this->assertEquals($data['tags'], join(', ', core_tag_tag::get_item_tags_array('core', 'course', $course->id))); + $this->assertEquals($data['tags'], join(', ', \core_tag_tag::get_item_tags_array('core', 'course', $course->id))); // Roles. $roleids = array(); @@ -569,7 +562,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase { $this->assertTrue($co->prepare()); $co->proceed(); $course = $DB->get_record('course', array('shortname' => 'c1')); - $ctx = context_course::instance($course->id); + $ctx = \context_course::instance($course->id); $this->assertEquals($data['fullname'], $course->fullname); $this->assertEquals($data['category'], $course->category); @@ -659,7 +652,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase { $co->proceed(); $this->assertTrue($DB->record_exists('course', array('shortname' => 'c1'))); $course = $DB->get_record('course', array('shortname' => 'c1')); - $ctx = context_course::instance($course->id); + $ctx = \context_course::instance($course->id); $this->assertEquals($defaultdata['fullname'], $course->fullname); $this->assertEquals($defaultdata['category'], $course->category); @@ -716,7 +709,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase { $co->proceed(); $this->assertTrue($DB->record_exists('course', array('shortname' => 'c1'))); $course = $DB->get_record('course', array('shortname' => 'c1')); - $ctx = context_course::instance($course->id); + $ctx = \context_course::instance($course->id); $this->assertEquals($defaultdata['fullname'], $course->fullname); $this->assertEquals($defaultdata['category'], $course->category); @@ -1002,7 +995,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase { $this->resetAfterTest(true); $c1 = $this->getDataGenerator()->create_course(); - $c1ctx = context_course::instance($c1->id); + $c1ctx = \context_course::instance($c1->id); $studentrole = $DB->get_record('role', array('shortname' => 'student')); $teacherrole = $DB->get_record('role', array('shortname' => 'teacher')); @@ -1215,7 +1208,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase { // Create category in which to create the new course. $category = $this->getDataGenerator()->create_category(); - $categorycontext = context_coursecat::instance($category->id); + $categorycontext = \context_coursecat::instance($category->id); $user = $this->getDataGenerator()->create_user(); $this->setUser($user); @@ -1259,7 +1252,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase { // Create category in which to create the new course. $category = $this->getDataGenerator()->create_category(); - $categorycontext = context_coursecat::instance($category->id); + $categorycontext = \context_coursecat::instance($category->id); $course = $this->getDataGenerator()->create_course([ 'category' => $category->id, @@ -1573,7 +1566,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase { * * @return core_customfield_generator */ - protected function get_customfield_generator() : core_customfield_generator { + protected function get_customfield_generator() : \core_customfield_generator { return $this->getDataGenerator()->get_plugin_generator('core_customfield'); } diff --git a/admin/tool/uploadcourse/tests/processor_test.php b/admin/tool/uploadcourse/tests/processor_test.php index b23c035a3aa..c18218b875e 100644 --- a/admin/tool/uploadcourse/tests/processor_test.php +++ b/admin/tool/uploadcourse/tests/processor_test.php @@ -14,13 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * File containing tests for the processor. - * - * @package tool_uploadcourse - * @copyright 2013 Frédéric Massart - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace tool_uploadcourse; + +use tool_uploadcourse_processor; defined('MOODLE_INTERNAL') || die(); @@ -34,7 +30,7 @@ require_once($CFG->libdir . '/csvlib.class.php'); * @copyright 2013 Frédéric Massart * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class tool_uploadcourse_processor_testcase extends advanced_testcase { +class processor_test extends \advanced_testcase { public function test_basic() { global $DB; @@ -46,8 +42,8 @@ class tool_uploadcourse_processor_testcase extends advanced_testcase { "c2,Course 2,Course 2 summary", ); $content = implode("\n", $content); - $iid = csv_import_reader::get_new_iid('uploadcourse'); - $cir = new csv_import_reader($iid, 'uploadcourse'); + $iid = \csv_import_reader::get_new_iid('uploadcourse'); + $cir = new \csv_import_reader($iid, 'uploadcourse'); $cir->load_csv_content($content, 'utf-8', 'comma'); $cir->init(); @@ -75,8 +71,8 @@ class tool_uploadcourse_processor_testcase extends advanced_testcase { "c2,Course 2,Course 2 summary", ); $content = implode("\n", $content); - $iid = csv_import_reader::get_new_iid('uploadcourse'); - $cir = new csv_import_reader($iid, 'uploadcourse'); + $iid = \csv_import_reader::get_new_iid('uploadcourse'); + $cir = new \csv_import_reader($iid, 'uploadcourse'); $cir->load_csv_content($content, 'utf-8', 'comma'); $cir->init(); @@ -108,8 +104,8 @@ class tool_uploadcourse_processor_testcase extends advanced_testcase { "c1,Course 1,Course 1 summary", ); $content = implode("\n", $content); - $iid = csv_import_reader::get_new_iid('uploadcourse'); - $cir = new csv_import_reader($iid, 'uploadcourse'); + $iid = \csv_import_reader::get_new_iid('uploadcourse'); + $cir = new \csv_import_reader($iid, 'uploadcourse'); $cir->load_csv_content($content, 'utf-8', 'comma'); $cir->init(); @@ -144,8 +140,8 @@ class tool_uploadcourse_processor_testcase extends advanced_testcase { ",Course 1,C1 Summary,ID123", ); $content = implode("\n", $content); - $iid = csv_import_reader::get_new_iid('uploadcourse'); - $cir = new csv_import_reader($iid, 'uploadcourse'); + $iid = \csv_import_reader::get_new_iid('uploadcourse'); + $cir = new \csv_import_reader($iid, 'uploadcourse'); $cir->load_csv_content($content, 'utf-8', 'comma'); $cir->init(); @@ -165,13 +161,13 @@ class tool_uploadcourse_processor_testcase extends advanced_testcase { $content = array(); $content = implode("\n", $content); - $iid = csv_import_reader::get_new_iid('uploadcourse'); - $cir = new csv_import_reader($iid, 'uploadcourse'); + $iid = \csv_import_reader::get_new_iid('uploadcourse'); + $cir = new \csv_import_reader($iid, 'uploadcourse'); $cir->load_csv_content($content, 'utf-8', 'comma'); $cir->init(); $options = array('mode' => tool_uploadcourse_processor::MODE_CREATE_NEW); - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $p = new tool_uploadcourse_processor($cir, $options, array()); } @@ -183,13 +179,13 @@ class tool_uploadcourse_processor_testcase extends advanced_testcase { "c1", ); $content = implode("\n", $content); - $iid = csv_import_reader::get_new_iid('uploadcourse'); - $cir = new csv_import_reader($iid, 'uploadcourse'); + $iid = \csv_import_reader::get_new_iid('uploadcourse'); + $cir = new \csv_import_reader($iid, 'uploadcourse'); $cir->load_csv_content($content, 'utf-8', 'comma'); $cir->init(); $options = array('mode' => tool_uploadcourse_processor::MODE_CREATE_NEW); - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $p = new tool_uploadcourse_processor($cir, $options, array()); } @@ -203,8 +199,8 @@ class tool_uploadcourse_processor_testcase extends advanced_testcase { "c2,Course 2,Course 2 summary", ); $content = implode("\n", $content); - $iid = csv_import_reader::get_new_iid('uploadcourse'); - $cir = new csv_import_reader($iid, 'uploadcourse'); + $iid = \csv_import_reader::get_new_iid('uploadcourse'); + $cir = new \csv_import_reader($iid, 'uploadcourse'); $cir->load_csv_content($content, 'utf-8', 'comma'); $cir->init(); diff --git a/admin/tool/usertours/tests/cache_test.php b/admin/tool/usertours/tests/cache_test.php index 557e0755e29..27f96008d12 100644 --- a/admin/tool/usertours/tests/cache_test.php +++ b/admin/tool/usertours/tests/cache_test.php @@ -14,13 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Tests for cache. - * - * @package tool_usertours - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace tool_usertours; defined('MOODLE_INTERNAL') || die(); @@ -34,9 +28,9 @@ require_once(__DIR__ . '/helper_trait.php'); * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class cache_testcase extends advanced_testcase { +class cache_test extends \advanced_testcase { // There are shared helpers for these tests in the helper trait. - use tool_usertours_helper_trait; + use \tool_usertours_helper_trait; /** * Test that get_enabled_tourdata does not return disabled tours. @@ -199,7 +193,7 @@ class cache_testcase extends advanced_testcase { $this->helper_create_step((object) ['tourid' => $tour->get_id()]); } - $matches = \tool_usertours\cache::get_matching_tourdata(new moodle_url($targetmatch)); + $matches = \tool_usertours\cache::get_matching_tourdata(new \moodle_url($targetmatch)); $this->assertCount(count($expected), $matches); for ($i = 0; $i < count($matches); $i++) { diff --git a/admin/tool/usertours/tests/step_test.php b/admin/tool/usertours/tests/step_test.php index 70538b289a0..5dd09e42d44 100644 --- a/admin/tool/usertours/tests/step_test.php +++ b/admin/tool/usertours/tests/step_test.php @@ -14,13 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Tests for step. - * - * @package tool_usertours - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace tool_usertours; defined('MOODLE_INTERNAL') || die(); @@ -34,7 +28,7 @@ require_once($CFG->libdir . '/formslib.php'); * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class step_testcase extends advanced_testcase { +class step_test extends \advanced_testcase { /** * @var moodle_database diff --git a/analytics/tests/course_test.php b/analytics/tests/course_test.php index 13010f96645..d351908ae4c 100644 --- a/analytics/tests/course_test.php +++ b/analytics/tests/course_test.php @@ -14,15 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for course. - * - * @package core_analytics - * @copyright 2016 David Monllaó {@link http://www.davidmonllao.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); +namespace core_analytics; /** * Unit tests for course. @@ -31,7 +23,7 @@ defined('MOODLE_INTERNAL') || die(); * @copyright 2016 David Monllaó {@link http://www.davidmonllao.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_analytics_course_testcase extends advanced_testcase { +class course_test extends \advanced_testcase { public function setUp(): void { global $DB; diff --git a/availability/condition/completion/tests/condition_test.php b/availability/condition/completion/tests/condition_test.php index c37940bbdd7..6e299556ba5 100644 --- a/availability/condition/completion/tests/condition_test.php +++ b/availability/condition/completion/tests/condition_test.php @@ -14,18 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the completion condition. - * - * @package availability_completion - * @copyright 2014 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace availability_completion; defined('MOODLE_INTERNAL') || die(); -use availability_completion\condition; - global $CFG; require_once($CFG->libdir . '/completionlib.php'); @@ -36,7 +28,7 @@ require_once($CFG->libdir . '/completionlib.php'); * @copyright 2014 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class availability_completion_condition_testcase extends advanced_testcase { +class condition_test extends \advanced_testcase { /** * Setup to ensure that fixtures are loaded. @@ -53,7 +45,7 @@ class availability_completion_condition_testcase extends advanced_testcase { * Load required classes. */ public function setUp(): void { - availability_completion\condition::wipe_static_cache(); + condition::wipe_static_cache(); } /** @@ -97,7 +89,7 @@ class availability_completion_condition_testcase extends advanced_testcase { $this->assertFalse($result->is_available()); // Mark activity complete. - $completion = new completion_info($course); + $completion = new \completion_info($course); $completion->update_state($cm, COMPLETION_COMPLETE); // Now it's true! @@ -111,11 +103,11 @@ class availability_completion_condition_testcase extends advanced_testcase { */ public function test_constructor() { // No parameters. - $structure = new stdClass(); + $structure = new \stdClass(); try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Missing or invalid ->cm', $e->getMessage()); } @@ -124,7 +116,7 @@ class availability_completion_condition_testcase extends advanced_testcase { try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Missing or invalid ->cm', $e->getMessage()); } @@ -133,7 +125,7 @@ class availability_completion_condition_testcase extends advanced_testcase { try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Missing or invalid ->e', $e->getMessage()); } @@ -142,7 +134,7 @@ class availability_completion_condition_testcase extends advanced_testcase { try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Missing or invalid ->e', $e->getMessage()); } @@ -210,7 +202,7 @@ class availability_completion_condition_testcase extends advanced_testcase { 'completion' => COMPLETION_TRACKING_AUTOMATIC]); $DB->set_field('course_modules', 'completiongradeitemnumber', 0, ['id' => $assignrow->cmid]); - $assign = new assign(context_module::instance($assignrow->cmid), false, false); + $assign = new \assign(\context_module::instance($assignrow->cmid), false, false); // Get basic details. $modinfo = get_fast_modinfo($course); @@ -239,7 +231,7 @@ class availability_completion_condition_testcase extends advanced_testcase { $this->assertMatchesRegularExpression('~Page!.*is marked complete~', $information); // Mark page complete. - $completion = new completion_info($course); + $completion = new \completion_info($course); $completion->update_state($pagecm, COMPLETION_COMPLETE); // COMPLETE state (true). @@ -265,7 +257,7 @@ class availability_completion_condition_testcase extends advanced_testcase { // We are going to need the grade item so that we can get pass/fails. $gradeitem = $assign->get_grade_item(); - grade_object::set_properties($gradeitem, ['gradepass' => 50.0]); + \grade_object::set_properties($gradeitem, ['gradepass' => 50.0]); $gradeitem->update(); // With no grade, it should return true for INCOMPLETE and false for @@ -433,7 +425,7 @@ class availability_completion_condition_testcase extends advanced_testcase { ]); $DB->set_field('course_modules', 'completiongradeitemnumber', 0, ['id' => $assignrow->cmid]); - $assign = new assign(context_module::instance($assignrow->cmid), false, false); + $assign = new \assign(\context_module::instance($assignrow->cmid), false, false); // Page 3 (manual completion). $page3 = $generator->get_plugin_generator('mod_page')->create_instance( @@ -452,12 +444,12 @@ class availability_completion_condition_testcase extends advanced_testcase { // Setup gradings and completion. if ($grade) { $gradeitem = $assign->get_grade_item(); - grade_object::set_properties($gradeitem, ['gradepass' => 50.0]); + \grade_object::set_properties($gradeitem, ['gradepass' => 50.0]); $gradeitem->update(); self::set_grade($assignrow, $user->id, $grade); } if ($mark) { - $completion = new completion_info($course); + $completion = new \completion_info($course); $completion->update_state($activities[$mark], COMPLETION_COMPLETE); } @@ -624,7 +616,7 @@ class availability_completion_condition_testcase extends advanced_testcase { if ($mark) { // Mark page1 complete. - $completion = new completion_info($course); + $completion = new \completion_info($course); $completion->update_state($page1cm, COMPLETION_COMPLETE); } @@ -741,24 +733,24 @@ class availability_completion_condition_testcase extends advanced_testcase { ['id' => $page6->cmid]); // Check 1: nothing depends on page3 and page6 but something does on the others. - $this->assertTrue(availability_completion\condition::completion_value_used( + $this->assertTrue(condition::completion_value_used( $course, $page1->cmid)); - $this->assertTrue(availability_completion\condition::completion_value_used( + $this->assertTrue(condition::completion_value_used( $course, $page2->cmid)); - $this->assertFalse(availability_completion\condition::completion_value_used( + $this->assertFalse(condition::completion_value_used( $course, $page3->cmid)); - $this->assertTrue(availability_completion\condition::completion_value_used( + $this->assertTrue(condition::completion_value_used( $course, $page4->cmid)); - $this->assertTrue(availability_completion\condition::completion_value_used( + $this->assertTrue(condition::completion_value_used( $course, $page5->cmid)); - $this->assertFalse(availability_completion\condition::completion_value_used( + $this->assertFalse(condition::completion_value_used( $course, $page6->cmid)); } /** * Updates the grade of a user in the given assign module instance. * - * @param stdClass $assignrow Assignment row from database + * @param \stdClass $assignrow Assignment row from database * @param int $userid User id * @param float $grade Grade */ diff --git a/availability/condition/date/tests/condition_test.php b/availability/condition/date/tests/condition_test.php index cbb2b1b5079..e34f6681feb 100644 --- a/availability/condition/date/tests/condition_test.php +++ b/availability/condition/date/tests/condition_test.php @@ -14,17 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the date condition. - * - * @package availability_date - * @copyright 2014 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace availability_date; -defined('MOODLE_INTERNAL') || die(); - -use availability_date\condition; use core_availability\tree; /** @@ -34,7 +25,7 @@ use core_availability\tree; * @copyright 2014 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class availability_date_condition_testcase extends advanced_testcase { +class condition_test extends \advanced_testcase { /** * Load required classes. */ @@ -95,7 +86,7 @@ class availability_date_condition_testcase extends advanced_testcase { try { $date = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Missing or invalid ->d', $e->getMessage()); } @@ -104,7 +95,7 @@ class availability_date_condition_testcase extends advanced_testcase { try { $date = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Missing or invalid ->d', $e->getMessage()); } @@ -113,7 +104,7 @@ class availability_date_condition_testcase extends advanced_testcase { try { $date = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Missing or invalid ->t', $e->getMessage()); } @@ -122,7 +113,7 @@ class availability_date_condition_testcase extends advanced_testcase { try { $date = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Missing or invalid ->t', $e->getMessage()); } diff --git a/availability/condition/grade/tests/condition_test.php b/availability/condition/grade/tests/condition_test.php index 3bcbc860e95..0cf0cd27a2e 100644 --- a/availability/condition/grade/tests/condition_test.php +++ b/availability/condition/grade/tests/condition_test.php @@ -14,17 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the grade condition. - * - * @package availability_grade - * @copyright 2014 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -use availability_grade\condition; +namespace availability_grade; /** * Unit tests for the grade condition. @@ -33,7 +23,7 @@ use availability_grade\condition; * @copyright 2014 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class availability_grade_condition_testcase extends advanced_testcase { +class condition_test extends \advanced_testcase { /** * Tests constructing and using grade condition. */ @@ -52,7 +42,7 @@ class availability_grade_condition_testcase extends advanced_testcase { // Make assign module. $assignrow = $this->getDataGenerator()->create_module('assign', array( 'course' => $course->id, 'name' => 'Test!')); - $assign = new assign(context_module::instance($assignrow->cmid), false, false); + $assign = new \assign(\context_module::instance($assignrow->cmid), false, false); $modinfo = get_fast_modinfo($course); $cm = $modinfo->get_cm($assignrow->cmid); @@ -153,11 +143,11 @@ class availability_grade_condition_testcase extends advanced_testcase { */ public function test_constructor() { // No parameters. - $structure = new stdClass(); + $structure = new \stdClass(); try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Missing or invalid ->id', $e->getMessage()); } @@ -166,7 +156,7 @@ class availability_grade_condition_testcase extends advanced_testcase { try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Missing or invalid ->id', $e->getMessage()); } @@ -176,7 +166,7 @@ class availability_grade_condition_testcase extends advanced_testcase { try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Missing or invalid ->min', $e->getMessage()); } @@ -186,7 +176,7 @@ class availability_grade_condition_testcase extends advanced_testcase { try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Missing or invalid ->max', $e->getMessage()); } @@ -230,7 +220,7 @@ class availability_grade_condition_testcase extends advanced_testcase { /** * Updates the grade of a user in the given assign module instance. * - * @param stdClass $assignrow Assignment row from database + * @param \stdClass $assignrow Assignment row from database * @param int $userid User id * @param float $grade Grade */ diff --git a/availability/condition/group/tests/condition_test.php b/availability/condition/group/tests/condition_test.php index c7a3453052e..eb221ea9234 100644 --- a/availability/condition/group/tests/condition_test.php +++ b/availability/condition/group/tests/condition_test.php @@ -14,17 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the condition. - * - * @package availability_group - * @copyright 2014 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -use availability_group\condition; +namespace availability_group; /** * Unit tests for the condition. @@ -33,7 +23,7 @@ use availability_group\condition; * @copyright 2014 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class availability_group_condition_testcase extends advanced_testcase { +class condition_test extends \advanced_testcase { /** * Load required classes. */ @@ -125,7 +115,7 @@ class availability_group_condition_testcase extends advanced_testcase { try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Invalid ->id', $e->getMessage()); } diff --git a/availability/condition/grouping/tests/condition_test.php b/availability/condition/grouping/tests/condition_test.php index c5beb4b8a30..0de2be5aa28 100644 --- a/availability/condition/grouping/tests/condition_test.php +++ b/availability/condition/grouping/tests/condition_test.php @@ -14,17 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the condition. - * - * @package availability_grouping - * @copyright 2014 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -use availability_grouping\condition; +namespace availability_grouping; /** * Unit tests for the condition. @@ -33,7 +23,7 @@ use availability_grouping\condition; * @copyright 2014 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class availability_grouping_condition_testcase extends advanced_testcase { +class condition_test extends \advanced_testcase { /** * Load required classes. */ @@ -127,11 +117,11 @@ class availability_grouping_condition_testcase extends advanced_testcase { */ public function test_constructor() { // No parameters. - $structure = new stdClass(); + $structure = new \stdClass(); try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Missing ->id / ->activity', $e->getMessage()); } @@ -140,7 +130,7 @@ class availability_grouping_condition_testcase extends advanced_testcase { try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Invalid ->id', $e->getMessage()); } @@ -150,7 +140,7 @@ class availability_grouping_condition_testcase extends advanced_testcase { try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Invalid ->activity', $e->getMessage()); } @@ -159,7 +149,7 @@ class availability_grouping_condition_testcase extends advanced_testcase { try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Invalid ->activity', $e->getMessage()); } diff --git a/availability/condition/profile/tests/condition_test.php b/availability/condition/profile/tests/condition_test.php index 5a987c252b7..e8a61f4bb8c 100644 --- a/availability/condition/profile/tests/condition_test.php +++ b/availability/condition/profile/tests/condition_test.php @@ -14,17 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the user profile condition. - * - * @package availability_profile - * @copyright 2014 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -use availability_profile\condition; +namespace availability_profile; /** * Unit tests for the user profile condition. @@ -33,7 +23,7 @@ use availability_profile\condition; * @copyright 2014 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class availability_profile_condition_testcase extends advanced_testcase { +class condition_test extends \advanced_testcase { /** @var profile_define_text Profile field for testing */ protected $profilefield; @@ -96,11 +86,11 @@ class availability_profile_condition_testcase extends advanced_testcase { */ public function test_constructor() { // No parameters. - $structure = new stdClass(); + $structure = new \stdClass(); try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Missing or invalid ->op', $e->getMessage()); } @@ -109,7 +99,7 @@ class availability_profile_condition_testcase extends advanced_testcase { try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Missing or invalid ->op', $e->getMessage()); } @@ -118,7 +108,7 @@ class availability_profile_condition_testcase extends advanced_testcase { try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Missing or invalid ->v', $e->getMessage()); } @@ -127,7 +117,7 @@ class availability_profile_condition_testcase extends advanced_testcase { try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Missing or invalid ->v', $e->getMessage()); } @@ -136,7 +126,7 @@ class availability_profile_condition_testcase extends advanced_testcase { try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Unexpected ->v', $e->getMessage()); } @@ -146,7 +136,7 @@ class availability_profile_condition_testcase extends advanced_testcase { try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Missing ->sf or ->cf', $e->getMessage()); } @@ -155,7 +145,7 @@ class availability_profile_condition_testcase extends advanced_testcase { try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Invalid ->sf', $e->getMessage()); } @@ -165,7 +155,7 @@ class availability_profile_condition_testcase extends advanced_testcase { try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Both ->sf and ->cf', $e->getMessage()); } @@ -175,7 +165,7 @@ class availability_profile_condition_testcase extends advanced_testcase { try { $cond = new condition($structure); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString('Invalid ->cf', $e->getMessage()); } diff --git a/backup/util/plan/tests/plan_test.php b/backup/util/plan/tests/plan_test.php index a02573689b7..8c9c9c9bbec 100644 --- a/backup/util/plan/tests/plan_test.php +++ b/backup/util/plan/tests/plan_test.php @@ -14,22 +14,27 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * @package core_backup - * @category phpunit - * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_backup; + +use backup; +use backup_controller; +use backup_controller_exception; +use backup_plan; +use backup_plan_exception; +use base_plan; +use base_plan_exception; defined('MOODLE_INTERNAL') || die(); require_once(__DIR__.'/fixtures/plan_fixtures.php'); - /** - * plan tests (all) + * @package core_backup + * @category test + * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class backup_plan_testcase extends advanced_testcase { +class plan_test extends \advanced_testcase { protected $moduleid; // course_modules id used for testing protected $sectionid; // course_sections id used for testing @@ -64,7 +69,7 @@ class backup_plan_testcase extends advanced_testcase { function test_base_plan() { // Instantiate - $bp = new mock_base_plan('name'); + $bp = new \mock_base_plan('name'); $this->assertTrue($bp instanceof base_plan); $this->assertEquals($bp->get_name(), 'name'); $this->assertTrue(is_array($bp->get_settings())); @@ -105,9 +110,9 @@ class backup_plan_testcase extends advanced_testcase { $bp = new backup_plan($bc); // Add wrong task try { - $bp->add_task(new stdclass()); + $bp->add_task(new \stdClass()); $this->assertTrue(false, 'base_plan_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_plan_exception); $this->assertEquals($e->errorcode, 'wrong_base_task_specified'); } @@ -120,16 +125,16 @@ class backup_plan_testcase extends advanced_testcase { // Try to pass one wrong controller try { - $bp = new backup_plan(new stdclass()); + $bp = new backup_plan(new \stdClass()); $this->assertTrue(false, 'backup_plan_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof backup_plan_exception); $this->assertEquals($e->errorcode, 'wrong_backup_controller_specified'); } try { $bp = new backup_plan(null); $this->assertTrue(false, 'backup_plan_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof backup_plan_exception); $this->assertEquals($e->errorcode, 'wrong_backup_controller_specified'); } @@ -140,7 +145,7 @@ class backup_plan_testcase extends advanced_testcase { $bc = new backup_controller(backup::TYPE_1ACTIVITY, $this->moduleid, 'non_existing_format', backup::INTERACTIVE_NO, backup::MODE_GENERAL, $this->userid); $this->assertTrue(false, 'backup_controller_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof backup_controller_exception); $this->assertEquals($e->errorcode, 'backup_check_unsupported_format'); $this->assertEquals($e->a, 'non_existing_format'); diff --git a/backup/util/plan/tests/step_test.php b/backup/util/plan/tests/step_test.php index 78d1a0c1804..81c62b3c3fc 100644 --- a/backup/util/plan/tests/step_test.php +++ b/backup/util/plan/tests/step_test.php @@ -14,22 +14,35 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * @package core_backup - * @category phpunit - * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_backup; + +use backup; +use backup_controller; +use backup_nested_element; +use backup_optigroup; +use backup_plan; +use backup_plugin_element; +use backup_step; +use backup_step_exception; +use backup_subplugin_element; +use base_step; +use base_step_exception; +use restore_path_element; +use restore_plugin; +use restore_step_exception; +use restore_subplugin; defined('MOODLE_INTERNAL') || die(); require_once(__DIR__.'/fixtures/plan_fixtures.php'); - -/* - * step tests (all) +/** + * @package core_backup + * @category test + * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class backup_step_testcase extends advanced_testcase { +class step_test extends \advanced_testcase { protected $moduleid; // course_modules id used for testing protected $sectionid; // course_sections id used for testing @@ -63,10 +76,10 @@ class backup_step_testcase extends advanced_testcase { */ function test_base_step() { - $bp = new mock_base_plan('planname'); // We need one plan - $bt = new mock_base_task('taskname', $bp); // We need one task + $bp = new \mock_base_plan('planname'); // We need one plan + $bt = new \mock_base_task('taskname', $bp); // We need one task // Instantiate - $bs = new mock_base_step('stepname', $bt); + $bs = new \mock_base_step('stepname', $bt); $this->assertTrue($bs instanceof base_step); $this->assertEquals($bs->get_name(), 'stepname'); } @@ -82,9 +95,9 @@ class backup_step_testcase extends advanced_testcase { // We need one plan $bp = new backup_plan($bc); // We need one task - $bt = new mock_backup_task('taskname', $bp); + $bt = new \mock_backup_task('taskname', $bp); // Instantiate step - $bs = new mock_backup_step('stepname', $bt); + $bs = new \mock_backup_step('stepname', $bt); $this->assertTrue($bs instanceof backup_step); $this->assertEquals($bs->get_name(), 'stepname'); @@ -108,8 +121,8 @@ class backup_step_testcase extends advanced_testcase { $this->markTestSkipped('Expected cipher not available: ' . backup::CIPHER); } - $bt = new mock_restore_task_basepath('taskname'); - $bs = new mock_restore_structure_step('steptest', null, $bt); + $bt = new \mock_restore_task_basepath('taskname'); + $bs = new \mock_restore_structure_step('steptest', null, $bt); $this->assertTrue(method_exists($bs, 'decrypt')); // Let's prepare a string for being decrypted. @@ -148,7 +161,7 @@ class backup_step_testcase extends advanced_testcase { @remove_dir(dirname($file)); // Recreate test dir if (!check_dir_exists(dirname($file), true, true)) { - throw new moodle_exception('error_creating_temp_dir', 'error', dirname($file)); + throw new \moodle_exception('error_creating_temp_dir', 'error', dirname($file)); } // We need one (non interactive) controller for instatiating plan @@ -157,10 +170,10 @@ class backup_step_testcase extends advanced_testcase { // We need one plan $bp = new backup_plan($bc); // We need one task with mocked basepath - $bt = new mock_backup_task_basepath('taskname'); + $bt = new \mock_backup_task_basepath('taskname'); $bp->add_task($bt); // Instantiate backup_structure_step (and add it to task) - $bs = new mock_backup_structure_step('steptest', basename($file), $bt); + $bs = new \mock_backup_structure_step('steptest', basename($file), $bt); // Execute backup_structure_step $bs->execute(); @@ -189,14 +202,14 @@ class backup_step_testcase extends advanced_testcase { */ public function test_backup_structure_step_add_plugin_structure() { // Create mocked task, step and element. - $bt = new mock_backup_task_basepath('taskname'); - $bs = new mock_backup_structure_step('steptest', null, $bt); + $bt = new \mock_backup_task_basepath('taskname'); + $bs = new \mock_backup_structure_step('steptest', null, $bt); $el = new backup_nested_element('question', array('id'), array('one', 'two', 'qtype')); // Wrong plugintype. try { $bs->add_plugin_structure('fakeplugin', $el, true); $this->assertTrue(false, 'base_step_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof backup_step_exception); $this->assertEquals('incorrect_plugin_type', $e->errorcode); } @@ -216,14 +229,14 @@ class backup_step_testcase extends advanced_testcase { */ public function test_backup_structure_step_add_subplugin_structure() { // Create mocked task, step and element. - $bt = new mock_backup_task_basepath('taskname'); - $bs = new mock_backup_structure_step('steptest', null, $bt); + $bt = new \mock_backup_task_basepath('taskname'); + $bs = new \mock_backup_structure_step('steptest', null, $bt); $el = new backup_nested_element('workshop', array('id'), array('one', 'two', 'qtype')); // Wrong plugin type. try { $bs->add_subplugin_structure('fakesubplugin', $el, true, 'fakeplugintype', 'fakepluginname'); $this->assertTrue(false, 'base_step_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof backup_step_exception); $this->assertEquals('incorrect_plugin_type', $e->errorcode); } @@ -231,7 +244,7 @@ class backup_step_testcase extends advanced_testcase { try { $bs->add_subplugin_structure('fakesubplugin', $el, true, 'mod', 'fakepluginname'); $this->assertTrue(false, 'base_step_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof backup_step_exception); $this->assertEquals('incorrect_plugin_name', $e->errorcode); } @@ -239,7 +252,7 @@ class backup_step_testcase extends advanced_testcase { try { $bs->add_subplugin_structure('fakesubplugin', $el, true, 'mod', 'page'); $this->assertTrue(false, 'base_step_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof backup_step_exception); $this->assertEquals('plugin_missing_subplugins_configuration', $e->errorcode); } @@ -248,7 +261,7 @@ class backup_step_testcase extends advanced_testcase { $bt->set_modulename('page'); $bs->add_subplugin_structure('fakesubplugin', $el, true); $this->assertTrue(false, 'base_step_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof backup_step_exception); $this->assertEquals('plugin_missing_subplugins_configuration', $e->errorcode); } @@ -256,7 +269,7 @@ class backup_step_testcase extends advanced_testcase { try { $bs->add_subplugin_structure('fakesubplugin', $el, true, 'mod', 'workshop'); $this->assertTrue(false, 'base_step_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof backup_step_exception); $this->assertEquals('incorrect_subplugin_type', $e->errorcode); } @@ -265,7 +278,7 @@ class backup_step_testcase extends advanced_testcase { $bt->set_modulename('workshop'); $bs->add_subplugin_structure('fakesubplugin', $el, true); $this->assertTrue(false, 'base_step_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof backup_step_exception); $this->assertEquals('incorrect_subplugin_type', $e->errorcode); } @@ -299,14 +312,14 @@ class backup_step_testcase extends advanced_testcase { */ public function test_restore_structure_step_add_plugin_structure() { // Create mocked task, step and element. - $bt = new mock_restore_task_basepath('taskname'); - $bs = new mock_restore_structure_step('steptest', null, $bt); + $bt = new \mock_restore_task_basepath('taskname'); + $bs = new \mock_restore_structure_step('steptest', null, $bt); $el = new restore_path_element('question', '/some/path/to/question'); // Wrong plugintype. try { $bs->add_plugin_structure('fakeplugin', $el); $this->assertTrue(false, 'base_step_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof restore_step_exception); $this->assertEquals('incorrect_plugin_type', $e->errorcode); } @@ -337,14 +350,14 @@ class backup_step_testcase extends advanced_testcase { */ public function test_restore_structure_step_add_subplugin_structure() { // Create mocked task, step and element. - $bt = new mock_restore_task_basepath('taskname'); - $bs = new mock_restore_structure_step('steptest', null, $bt); + $bt = new \mock_restore_task_basepath('taskname'); + $bs = new \mock_restore_structure_step('steptest', null, $bt); $el = new restore_path_element('workshop', '/path/to/workshop'); // Wrong plugin type. try { $bs->add_subplugin_structure('fakesubplugin', $el, 'fakeplugintype', 'fakepluginname'); $this->assertTrue(false, 'base_step_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof restore_step_exception); $this->assertEquals('incorrect_plugin_type', $e->errorcode); } @@ -352,7 +365,7 @@ class backup_step_testcase extends advanced_testcase { try { $bs->add_subplugin_structure('fakesubplugin', $el, 'mod', 'fakepluginname'); $this->assertTrue(false, 'base_step_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof restore_step_exception); $this->assertEquals('incorrect_plugin_name', $e->errorcode); } @@ -360,7 +373,7 @@ class backup_step_testcase extends advanced_testcase { try { $bs->add_subplugin_structure('fakesubplugin', $el, 'mod', 'page'); $this->assertTrue(false, 'base_step_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof restore_step_exception); $this->assertEquals('plugin_missing_subplugins_configuration', $e->errorcode); } @@ -369,7 +382,7 @@ class backup_step_testcase extends advanced_testcase { $bt->set_modulename('page'); $bs->add_subplugin_structure('fakesubplugin', $el); $this->assertTrue(false, 'base_step_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof restore_step_exception); $this->assertEquals('plugin_missing_subplugins_configuration', $e->errorcode); } @@ -377,7 +390,7 @@ class backup_step_testcase extends advanced_testcase { try { $bs->add_subplugin_structure('fakesubplugin', $el, 'mod', 'workshop'); $this->assertTrue(false, 'base_step_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof restore_step_exception); $this->assertEquals('incorrect_subplugin_type', $e->errorcode); } @@ -386,13 +399,13 @@ class backup_step_testcase extends advanced_testcase { $bt->set_modulename('workshop'); $bs->add_subplugin_structure('fakesubplugin', $el); $this->assertTrue(false, 'base_step_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof restore_step_exception); $this->assertEquals('incorrect_subplugin_type', $e->errorcode); } // Correct call to workshopform subplugin (@ 'workshop' level). - $bt = new mock_restore_task_basepath('taskname'); - $bs = new mock_restore_structure_step('steptest', null, $bt); + $bt = new \mock_restore_task_basepath('taskname'); + $bs = new \mock_restore_structure_step('steptest', null, $bt); $el = new restore_path_element('workshop', '/path/to/workshop'); $bs->add_subplugin_structure('workshopform', $el, 'mod', 'workshop'); $patheles = $bs->get_pathelements(); @@ -413,8 +426,8 @@ class backup_step_testcase extends advanced_testcase { } // Correct BC call to workshopform subplugin (@ 'assessment' level). - $bt = new mock_restore_task_basepath('taskname'); - $bs = new mock_restore_structure_step('steptest', null, $bt); + $bt = new \mock_restore_task_basepath('taskname'); + $bs = new \mock_restore_structure_step('steptest', null, $bt); $el = new restore_path_element('assessment', '/a/assessment'); $bt->set_modulename('workshop'); $bs->add_subplugin_structure('workshopform', $el); @@ -445,9 +458,9 @@ class backup_step_testcase extends advanced_testcase { // Try to pass one wrong task try { - $bt = new mock_base_step('teststep', new stdclass()); + $bt = new \mock_base_step('teststep', new \stdClass()); $this->assertTrue(false, 'base_step_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_step_exception); $this->assertEquals($e->errorcode, 'wrong_base_task_specified'); } @@ -460,9 +473,9 @@ class backup_step_testcase extends advanced_testcase { // Try to pass one wrong task try { - $bt = new mock_backup_step('teststep', new stdclass()); + $bt = new \mock_backup_step('teststep', new \stdClass()); $this->assertTrue(false, 'backup_step_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof backup_step_exception); $this->assertEquals($e->errorcode, 'wrong_backup_task_specified'); } diff --git a/backup/util/plan/tests/task_test.php b/backup/util/plan/tests/task_test.php index 3cb0bef732f..b928222e90b 100644 --- a/backup/util/plan/tests/task_test.php +++ b/backup/util/plan/tests/task_test.php @@ -14,22 +14,27 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * @package core_backup - * @category phpunit - * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_backup; + +use backup; +use base_task; +use base_task_exception; +use backup_controller; +use backup_plan; +use backup_task; +use backup_task_exception; defined('MOODLE_INTERNAL') || die(); require_once(__DIR__.'/fixtures/plan_fixtures.php'); - /** - * task tests (all) + * @package core_backup + * @category test + * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class backup_task_testcase extends advanced_testcase { +class task_test extends \advanced_testcase { protected $moduleid; // course_modules id used for testing protected $sectionid; // course_sections id used for testing @@ -63,9 +68,9 @@ class backup_task_testcase extends advanced_testcase { */ function test_base_task() { - $bp = new mock_base_plan('planname'); // We need one plan + $bp = new \mock_base_plan('planname'); // We need one plan // Instantiate - $bt = new mock_base_task('taskname', $bp); + $bt = new \mock_base_task('taskname', $bp); $this->assertTrue($bt instanceof base_task); $this->assertEquals($bt->get_name(), 'taskname'); $this->assertTrue(is_array($bt->get_settings())); @@ -85,7 +90,7 @@ class backup_task_testcase extends advanced_testcase { // We need one plan $bp = new backup_plan($bc); // Instantiate task - $bt = new mock_backup_task('taskname', $bp); + $bt = new \mock_backup_task('taskname', $bp); $this->assertTrue($bt instanceof backup_task); $this->assertEquals($bt->get_name(), 'taskname'); @@ -103,21 +108,21 @@ class backup_task_testcase extends advanced_testcase { // Try to pass one wrong plan try { - $bt = new mock_base_task('tasktest', new stdclass()); + $bt = new \mock_base_task('tasktest', new \stdClass()); $this->assertTrue(false, 'base_task_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_task_exception); $this->assertEquals($e->errorcode, 'wrong_base_plan_specified'); } // Add wrong step to task - $bp = new mock_base_plan('planname'); // We need one plan + $bp = new \mock_base_plan('planname'); // We need one plan // Instantiate - $bt = new mock_base_task('taskname', $bp); + $bt = new \mock_base_task('taskname', $bp); try { - $bt->add_step(new stdclass()); + $bt->add_step(new \stdClass()); $this->assertTrue(false, 'base_task_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_task_exception); $this->assertEquals($e->errorcode, 'wrong_base_step_specified'); } @@ -131,9 +136,9 @@ class backup_task_testcase extends advanced_testcase { // Try to pass one wrong plan try { - $bt = new mock_backup_task('tasktest', new stdclass()); + $bt = new \mock_backup_task('tasktest', new \stdClass()); $this->assertTrue(false, 'backup_task_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof backup_task_exception); $this->assertEquals($e->errorcode, 'wrong_backup_plan_specified'); } diff --git a/backup/util/structure/tests/structure_test.php b/backup/util/structure/tests/structure_test.php index 3b9b807bcea..4b2a8b1b37e 100644 --- a/backup/util/structure/tests/structure_test.php +++ b/backup/util/structure/tests/structure_test.php @@ -14,26 +14,40 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * @package core_backup - * @category phpunit - * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_backup; + +use backup; +use backup_attribute; +use backup_controller_dbops; +use backup_final_element; +use backup_nested_element; +use backup_optigroup; +use backup_optigroup_element; +use backup_processor_exception; +use backup_structure_processor; +use base_element_struct_exception; +use base_optigroup_exception; +use base_processor; +use memory_xml_output; +use xml_writer; defined('MOODLE_INTERNAL') || die(); -// Include all the needed stuff +// Include all the needed stuff. require_once(__DIR__.'/fixtures/structure_fixtures.php'); global $CFG; require_once($CFG->dirroot . '/backup/util/xml/output/memory_xml_output.class.php'); - /** * Unit test case the all the backup structure classes. Note: Uses database + * + * @package core_backup + * @category test + * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class backup_structure_testcase extends advanced_testcase { +class structure_test extends \advanced_testcase { /** @var int Store the inserted forum->id for use in test functions */ protected $forumid; @@ -148,9 +162,9 @@ class backup_structure_testcase extends advanced_testcase { 'rsstype', 'rssarticles', 'timemodified', 'warnafter', 'blockafter', new backup_final_element('blockperiod'), - new mock_skip_final_element('completiondiscussions'), - new mock_modify_final_element('completionreplies'), - new mock_final_element_interceptor('completionposts')) + new \mock_skip_final_element('completiondiscussions'), + new \mock_modify_final_element('completionreplies'), + new \mock_final_element_interceptor('completionposts')) ); $discussions = new backup_nested_element('discussions'); $discussion = new backup_nested_element('discussion', @@ -326,9 +340,9 @@ class backup_structure_testcase extends advanced_testcase { $this->assertEquals($inventeds->get_counter(), 2); // Array // Perform some validations with the generated XML - $dom = new DomDocument(); + $dom = new \DomDocument(); $dom->loadXML($xo->get_allcontents()); - $xpath = new DOMXPath($dom); + $xpath = new \DOMXPath($dom); // Some more counters $query = '/forum/discussions/discussion/posts/post'; $posts = $xpath->query($query); @@ -468,7 +482,7 @@ class backup_structure_testcase extends advanced_testcase { try { $processor->set_var('onenewvariable', 999); $this->assertTrue(false, 'backup_processor_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof backup_processor_exception); $this->assertEquals($e->errorcode, 'processorvariablealreadyset'); $this->assertEquals($e->a, 'onenewvariable'); @@ -478,7 +492,7 @@ class backup_structure_testcase extends advanced_testcase { try { $var = $processor->get_var('nonexistingvar'); $this->assertTrue(false, 'backup_processor_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof backup_processor_exception); $this->assertEquals($e->errorcode, 'processorvariablenotfound'); $this->assertEquals($e->a, 'nonexistingvar'); @@ -490,7 +504,7 @@ class backup_structure_testcase extends advanced_testcase { $ne->set_source_table('forum', array('id' => backup::VAR_PARENTID)); $ne->process($processor); $this->assertTrue(false, 'base_element_struct_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_element_struct_exception); $this->assertEquals($e->errorcode, 'cannotfindparentidforelement'); } @@ -498,25 +512,25 @@ class backup_structure_testcase extends advanced_testcase { // Try to process one nested/final/attribute elements without processor $ne = new backup_nested_element('test', 'one', 'two', 'three'); try { - $ne->process(new stdclass()); + $ne->process(new \stdClass()); $this->assertTrue(false, 'base_element_struct_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_element_struct_exception); $this->assertEquals($e->errorcode, 'incorrect_processor'); } $fe = new backup_final_element('test'); try { - $fe->process(new stdclass()); + $fe->process(new \stdClass()); $this->assertTrue(false, 'base_element_struct_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_element_struct_exception); $this->assertEquals($e->errorcode, 'incorrect_processor'); } $at = new backup_attribute('test'); try { - $at->process(new stdclass()); + $at->process(new \stdClass()); $this->assertTrue(false, 'base_element_struct_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_element_struct_exception); $this->assertEquals($e->errorcode, 'incorrect_processor'); } @@ -526,7 +540,7 @@ class backup_structure_testcase extends advanced_testcase { try { $ne->set_source_alias('last', 'nonexisting'); $this->assertTrue(false, 'base_element_struct_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_element_struct_exception); $this->assertEquals($e->errorcode, 'incorrectaliasfinalnamenotfound'); $this->assertEquals($e->a, 'nonexisting'); @@ -537,7 +551,7 @@ class backup_structure_testcase extends advanced_testcase { try { $ne->set_source_table('forum', array('/test/subtest')); $this->assertTrue(false, 'base_element_struct_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_element_struct_exception); $this->assertEquals($e->errorcode, 'baseelementincorrectfinalorattribute'); $this->assertEquals($e->a, 'subtest'); @@ -545,7 +559,7 @@ class backup_structure_testcase extends advanced_testcase { try { $ne->set_source_table('forum', array('/wrongtest')); $this->assertTrue(false, 'base_element_struct_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_element_struct_exception); $this->assertEquals($e->errorcode, 'baseelementincorrectgrandparent'); $this->assertEquals($e->a, 'wrongtest'); @@ -553,7 +567,7 @@ class backup_structure_testcase extends advanced_testcase { try { $ne->set_source_table('forum', array('../nonexisting')); $this->assertTrue(false, 'base_element_struct_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_element_struct_exception); $this->assertEquals($e->errorcode, 'baseelementincorrectparent'); $this->assertEquals($e->a, '..'); @@ -566,7 +580,7 @@ class backup_structure_testcase extends advanced_testcase { try { $ne->annotate_files('test', 'filearea', null); // Try to add annotations twice $this->assertTrue(false, 'base_element_struct_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_element_struct_exception); $this->assertEquals($e->errorcode, 'annotate_files_duplicate_annotation'); $this->assertEquals($e->a, 'test/filearea/'); @@ -576,7 +590,7 @@ class backup_structure_testcase extends advanced_testcase { try { $ne->annotate_files('test', 'filearea', 'four'); // Incorrect element $this->assertTrue(false, 'base_element_struct_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_element_struct_exception); $this->assertEquals($e->errorcode, 'baseelementincorrectfinalorattribute'); $this->assertEquals($e->a, 'four'); @@ -587,7 +601,7 @@ class backup_structure_testcase extends advanced_testcase { try { $bog->add_child(new backup_nested_element('test2')); $this->assertTrue(false, 'base_optigroup_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_optigroup_exception); $this->assertEquals($e->errorcode, 'optigroup_element_incorrect'); $this->assertEquals($e->a, 'backup_nested_element'); @@ -597,16 +611,16 @@ class backup_structure_testcase extends advanced_testcase { try { $bog->add_child('test2'); $this->assertTrue(false, 'base_optigroup_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_optigroup_exception); $this->assertEquals($e->errorcode, 'optigroup_element_incorrect'); $this->assertEquals($e->a, 'non object'); } try { - $bog = new backup_optigroup('test', new stdclass()); + $bog = new backup_optigroup('test', new \stdClass()); $this->assertTrue(false, 'base_optigroup_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_optigroup_exception); $this->assertEquals($e->errorcode, 'optigroup_elements_incorrect'); } @@ -614,9 +628,9 @@ class backup_structure_testcase extends advanced_testcase { // Try a wrong processor with backup_optigroup $bog = new backup_optigroup('test'); try { - $bog->process(new stdclass()); + $bog->process(new \stdClass()); $this->assertTrue(false, 'base_element_struct_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_element_struct_exception); $this->assertEquals($e->errorcode, 'incorrect_processor'); } @@ -634,7 +648,7 @@ class backup_structure_testcase extends advanced_testcase { try { $boge2->add_child($ne2); $this->assertTrue(false, 'base_optigroup_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_optigroup_exception); $this->assertEquals($e->errorcode, 'multiple_optigroup_duplicate_element'); $this->assertEquals($e->a, 'ne1'); @@ -651,7 +665,7 @@ class backup_structure_testcase extends advanced_testcase { try { $bog->add_child($boge2); $this->assertTrue(false, 'base_element_struct_exception expected'); - } catch (exception $e) { + } catch (\Exception $e) { $this->assertTrue($e instanceof base_element_struct_exception); $this->assertEquals($e->errorcode, 'baseelementexisting'); $this->assertEquals($e->a, 'ne1'); diff --git a/blocks/recentlyaccesseditems/tests/observer_test.php b/blocks/recentlyaccesseditems/tests/observer_test.php index 6600709b20c..6b1b30e56dd 100644 --- a/blocks/recentlyaccesseditems/tests/observer_test.php +++ b/blocks/recentlyaccesseditems/tests/observer_test.php @@ -14,14 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Block recentlyaccesseditems observer tests. - * - * @package block_recentlyaccesseditems - * @copyright 2018 Victor Deniz - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since Moodle 3.6 - */ +namespace block_recentlyaccesseditems; defined('MOODLE_INTERNAL') || die(); @@ -36,8 +29,8 @@ require_once($CFG->dirroot . '/mod/assign/tests/generator.php'); * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 3.6 */ -class block_recentlyaccesseditems_observer_testcase extends advanced_testcase { - use mod_assign_test_generator; +class observer_test extends \advanced_testcase { + use \mod_assign_test_generator; /** * Set up for every test @@ -84,13 +77,13 @@ class block_recentlyaccesseditems_observer_testcase extends advanced_testcase { // Teacher access forum activity. $this->setUser($this->teacher); - $event = \mod_forum\event\course_module_viewed::create(array('context' => context_module::instance($this->forum->cmid), + $event = \mod_forum\event\course_module_viewed::create(array('context' => \context_module::instance($this->forum->cmid), 'objectid' => $this->forum->id)); $event->trigger(); // Student access chat activity. $this->setUser($this->student); - $event1 = \mod_chat\event\course_module_viewed::create(array('context' => context_module::instance($this->chat->cmid), + $event1 = \mod_chat\event\course_module_viewed::create(array('context' => \context_module::instance($this->chat->cmid), 'objectid' => $this->chat->id)); $event1->trigger(); @@ -104,7 +97,7 @@ class block_recentlyaccesseditems_observer_testcase extends advanced_testcase { $this->waitForSecond(); // Student access chat activity again after 1 second (no new record created, timeaccess updated). - $event2 = \mod_chat\event\course_module_viewed::create(array('context' => context_module::instance($this->chat->cmid), + $event2 = \mod_chat\event\course_module_viewed::create(array('context' => \context_module::instance($this->chat->cmid), 'objectid' => $this->chat->id)); $event2->trigger(); @@ -129,23 +122,23 @@ class block_recentlyaccesseditems_observer_testcase extends advanced_testcase { // Teacher access forum activity. $this->setUser($this->teacher); - $event = \mod_forum\event\course_module_viewed::create(array('context' => context_module::instance($this->forum->cmid), + $event = \mod_forum\event\course_module_viewed::create(array('context' => \context_module::instance($this->forum->cmid), 'objectid' => $this->forum->id)); $event->trigger(); // Teacher access chat activity. - $event = \mod_chat\event\course_module_viewed::create(array('context' => context_module::instance($this->chat->cmid), + $event = \mod_chat\event\course_module_viewed::create(array('context' => \context_module::instance($this->chat->cmid), 'objectid' => $this->chat->id)); $event->trigger(); // Student access chat activity. $this->setUser($this->student); - $event = \mod_chat\event\course_module_viewed::create(array('context' => context_module::instance($this->chat->cmid), + $event = \mod_chat\event\course_module_viewed::create(array('context' => \context_module::instance($this->chat->cmid), 'objectid' => $this->chat->id)); $event->trigger(); // Student access forum activity. - $event = \mod_forum\event\course_module_viewed::create(array('context' => context_module::instance($this->forum->cmid), + $event = \mod_forum\event\course_module_viewed::create(array('context' => \context_module::instance($this->forum->cmid), 'objectid' => $this->forum->id)); $event->trigger(); diff --git a/cache/stores/apcu/tests/apcu_test.php b/cache/stores/apcu/tests/store_test.php similarity index 93% rename from cache/stores/apcu/tests/apcu_test.php rename to cache/stores/apcu/tests/store_test.php index 108015b68e9..975ac673897 100644 --- a/cache/stores/apcu/tests/apcu_test.php +++ b/cache/stores/apcu/tests/store_test.php @@ -14,13 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * APCu unit tests. - * - * @package cachestore_apcu - * @copyright 2014 Sam Hemelryk - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace cachestore_apcu; + +use cache_store; +use cache_definition; +use cachestore_apcu; defined('MOODLE_INTERNAL') || die(); @@ -36,7 +34,7 @@ require_once($CFG->dirroot.'/cache/stores/apcu/lib.php'); * @copyright 2014 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class cachestore_apcu_test extends cachestore_tests { +class store_test extends \cachestore_tests { /** * Returns the apcu class name * @return string diff --git a/cache/stores/file/tests/file_test.php b/cache/stores/file/tests/store_test.php similarity index 91% rename from cache/stores/file/tests/file_test.php rename to cache/stores/file/tests/store_test.php index 887c5454f7c..ee2c4f3e806 100644 --- a/cache/stores/file/tests/file_test.php +++ b/cache/stores/file/tests/store_test.php @@ -14,13 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * File unit tests - * - * @package cachestore_file - * @copyright 2013 Sam Hemelryk - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace cachestore_file; + +use cache_definition; +use cache_store; +use cachestore_file; defined('MOODLE_INTERNAL') || die(); @@ -36,7 +34,7 @@ require_once($CFG->dirroot.'/cache/stores/file/lib.php'); * @copyright 2013 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class cachestore_file_test extends cachestore_tests { +class store_test extends \cachestore_tests { /** * Returns the file class name * @return string diff --git a/cache/stores/memcached/tests/memcached_test.php b/cache/stores/memcached/tests/store_test.php similarity index 94% rename from cache/stores/memcached/tests/memcached_test.php rename to cache/stores/memcached/tests/store_test.php index db41269cd74..cfc32228971 100644 --- a/cache/stores/memcached/tests/memcached_test.php +++ b/cache/stores/memcached/tests/store_test.php @@ -14,18 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Memcached unit tests. - * - * If you wish to use these unit tests all you need to do is add the following definition to - * your config.php file. - * - * define('TEST_CACHESTORE_MEMCACHED_TESTSERVERS', '127.0.0.1:11211'); - * - * @package cachestore_memcached - * @copyright 2013 Sam Hemelryk - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace cachestore_memcached; + +use cache_definition; +use cache_store; +use cachestore_memcached; defined('MOODLE_INTERNAL') || die(); @@ -37,11 +30,16 @@ require_once($CFG->dirroot.'/cache/stores/memcached/lib.php'); /** * Memcached unit test class. * + * If you wish to use these unit tests all you need to do is add the following definition to + * your config.php file. + * + * define('TEST_CACHESTORE_MEMCACHED_TESTSERVERS', '127.0.0.1:11211'); + * * @package cachestore_memcached * @copyright 2013 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class cachestore_memcached_test extends cachestore_tests { +class store_test extends \cachestore_tests { /** * Returns the memcached class name * @return string @@ -292,13 +290,13 @@ class cachestore_memcached_test extends cachestore_tests { $this->markTestSkipped('Could not test cachestore_memcached. Connection is not ready.'); } - $connection = new Memcached(crc32(__METHOD__)); + $connection = new \Memcached(crc32(__METHOD__)); $connection->addServers($this->get_servers(TEST_CACHESTORE_MEMCACHED_TESTSERVERS)); $connection->setOptions(array( - Memcached::OPT_COMPRESSION => true, - Memcached::OPT_SERIALIZER => Memcached::SERIALIZER_PHP, - Memcached::OPT_PREFIX_KEY => 'phpunit_', - Memcached::OPT_BUFFER_WRITES => false + \Memcached::OPT_COMPRESSION => true, + \Memcached::OPT_SERIALIZER => \Memcached::SERIALIZER_PHP, + \Memcached::OPT_PREFIX_KEY => 'phpunit_', + \Memcached::OPT_BUFFER_WRITES => false )); // We must flush first to make sure nothing is there. @@ -311,7 +309,7 @@ class cachestore_memcached_test extends cachestore_tests { // Test the connection. $this->assertFalse($connection->get('test')); - $this->assertEquals(Memcached::RES_NOTFOUND, $connection->getResultCode()); + $this->assertEquals(\Memcached::RES_NOTFOUND, $connection->getResultCode()); $this->assertTrue($connection->set('test', 'connection')); $this->assertSame('connection', $connection->get('test')); @@ -335,13 +333,13 @@ class cachestore_memcached_test extends cachestore_tests { $definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_memcached', 'phpunit_test'); $cachestore = $this->create_test_cache_with_config($definition, array('isshared' => false)); - $connection = new Memcached(crc32(__METHOD__)); + $connection = new \Memcached(crc32(__METHOD__)); $connection->addServers($this->get_servers(TEST_CACHESTORE_MEMCACHED_TESTSERVERS)); $connection->setOptions(array( - Memcached::OPT_COMPRESSION => true, - Memcached::OPT_SERIALIZER => Memcached::SERIALIZER_PHP, - Memcached::OPT_PREFIX_KEY => 'phpunit_', - Memcached::OPT_BUFFER_WRITES => false + \Memcached::OPT_COMPRESSION => true, + \Memcached::OPT_SERIALIZER => \Memcached::SERIALIZER_PHP, + \Memcached::OPT_PREFIX_KEY => 'phpunit_', + \Memcached::OPT_BUFFER_WRITES => false )); // We must flush first to make sure nothing is there. @@ -354,7 +352,7 @@ class cachestore_memcached_test extends cachestore_tests { // Test the connection. $this->assertFalse($connection->get('test')); - $this->assertEquals(Memcached::RES_NOTFOUND, $connection->getResultCode()); + $this->assertEquals(\Memcached::RES_NOTFOUND, $connection->getResultCode()); $this->assertTrue($connection->set('test', 'connection')); $this->assertSame('connection', $connection->get('test')); diff --git a/cache/stores/mongodb/tests/mongodb_test.php b/cache/stores/mongodb/tests/store_test.php similarity index 91% rename from cache/stores/mongodb/tests/mongodb_test.php rename to cache/stores/mongodb/tests/store_test.php index 8e97822f2fa..1cccfd6290a 100644 --- a/cache/stores/mongodb/tests/mongodb_test.php +++ b/cache/stores/mongodb/tests/store_test.php @@ -14,18 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * MongoDB unit tests. - * - * If you wish to use these unit tests all you need to do is add the following definition to - * your config.php file. - * - * define('TEST_CACHESTORE_MONGODB_TESTSERVER', 'mongodb://localhost:27017'); - * - * @package cachestore_mongodb - * @copyright 2013 Sam Hemelryk - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace cachestore_mongodb; + +use cache_store; +use cache_definition; +use cachestore_mongodb; defined('MOODLE_INTERNAL') || die(); @@ -37,11 +30,16 @@ require_once($CFG->dirroot.'/cache/stores/mongodb/lib.php'); /** * MongoDB unit test class. * + * If you wish to use these unit tests all you need to do is add the following definition to + * your config.php file. + * + * define('TEST_CACHESTORE_MONGODB_TESTSERVER', 'mongodb://localhost:27017'); + * * @package cachestore_mongodb * @copyright 2013 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class cachestore_mongodb_test extends cachestore_tests { +class store_test extends \cachestore_tests { /** * Returns the MongoDB class name * @return string @@ -72,4 +70,4 @@ class cachestore_mongodb_test extends cachestore_tests { 2 => 'beta' ), $instance->get_many(array(1, 2))); } -} \ No newline at end of file +} diff --git a/cache/stores/redis/tests/compressor_test.php b/cache/stores/redis/tests/compressor_test.php index b7178b3c336..f12377d0e6e 100644 --- a/cache/stores/redis/tests/compressor_test.php +++ b/cache/stores/redis/tests/compressor_test.php @@ -14,20 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Redis cache test. - * - * If you wish to use these unit tests all you need to do is add the following definition to - * your config.php file. - * - * define('TEST_CACHESTORE_REDIS_TESTSERVERS', '127.0.0.1'); - * - * @package cachestore_redis - * @copyright 2018 Catalyst IT Australia {@link http://www.catalyst-au.net} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace cachestore_redis; -defined('MOODLE_INTERNAL') || die(); +use cache_definition; +use cache_store; +use cachestore_redis; require_once(__DIR__.'/../../../tests/fixtures/stores.php'); require_once(__DIR__.'/../lib.php'); @@ -35,12 +26,17 @@ require_once(__DIR__.'/../lib.php'); /** * Redis cache test - compressor settings. * + * If you wish to use these unit tests all you need to do is add the following definition to + * your config.php file. + * + * define('TEST_CACHESTORE_REDIS_TESTSERVERS', '127.0.0.1'); + * * @package cachestore_redis * @author Daniel Thee Roperto * @copyright 2018 Catalyst IT Australia {@link http://www.catalyst-au.net} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class cachestore_redis_compressor_test extends advanced_testcase { +class compressor_test extends \advanced_testcase { /** * Test set up @@ -76,7 +72,7 @@ class cachestore_redis_compressor_test extends advanced_testcase { * It misses a value. */ public function test_it_can_miss_one() { - $store = $this->create_store(cachestore_redis::COMPRESSOR_PHP_GZIP, Redis::SERIALIZER_PHP); + $store = $this->create_store(cachestore_redis::COMPRESSOR_PHP_GZIP, \Redis::SERIALIZER_PHP); self::assertFalse($store->get('missme')); } @@ -85,7 +81,7 @@ class cachestore_redis_compressor_test extends advanced_testcase { * It misses many values. */ public function test_it_can_miss_many() { - $store = $this->create_store(cachestore_redis::COMPRESSOR_PHP_GZIP, Redis::SERIALIZER_PHP); + $store = $this->create_store(cachestore_redis::COMPRESSOR_PHP_GZIP, \Redis::SERIALIZER_PHP); $expected = ['missme' => false, 'missmetoo' => false]; $actual = $store->get_many(array_keys($expected)); @@ -96,7 +92,7 @@ class cachestore_redis_compressor_test extends advanced_testcase { * It misses some values. */ public function test_it_can_miss_some() { - $store = $this->create_store(cachestore_redis::COMPRESSOR_PHP_GZIP, Redis::SERIALIZER_PHP); + $store = $this->create_store(cachestore_redis::COMPRESSOR_PHP_GZIP, \Redis::SERIALIZER_PHP); $store->set('iamhere', 'youfoundme'); $expected = ['missme' => false, 'missmetoo' => false, 'iamhere' => 'youfoundme']; @@ -110,7 +106,7 @@ class cachestore_redis_compressor_test extends advanced_testcase { * @return array */ public function provider_for_test_it_works_with_different_types() { - $object = new stdClass(); + $object = new \stdClass(); $object->field = 'value'; return [ @@ -139,7 +135,7 @@ class cachestore_redis_compressor_test extends advanced_testcase { * @param mixed $value */ public function test_it_works_with_different_types($key, $value) { - $store = $this->create_store(cachestore_redis::COMPRESSOR_PHP_GZIP, Redis::SERIALIZER_PHP); + $store = $this->create_store(cachestore_redis::COMPRESSOR_PHP_GZIP, \Redis::SERIALIZER_PHP); $store->set($key, $value); self::assertEquals($value, $store->get($key), "Failed set/get for: {$key}"); @@ -149,7 +145,7 @@ class cachestore_redis_compressor_test extends advanced_testcase { * Test it works with different types for many. */ public function test_it_works_with_different_types_for_many() { - $store = $this->create_store(cachestore_redis::COMPRESSOR_PHP_GZIP, Redis::SERIALIZER_PHP); + $store = $this->create_store(cachestore_redis::COMPRESSOR_PHP_GZIP, \Redis::SERIALIZER_PHP); $provider = $this->provider_for_test_it_works_with_different_types(); $keys = []; @@ -178,28 +174,28 @@ class cachestore_redis_compressor_test extends advanced_testcase { $data = [ ['none, none', - Redis::SERIALIZER_NONE, cachestore_redis::COMPRESSOR_NONE, + \Redis::SERIALIZER_NONE, cachestore_redis::COMPRESSOR_NONE, 'value1', 'value2'], ['none, gzip', - Redis::SERIALIZER_NONE, cachestore_redis::COMPRESSOR_PHP_GZIP, + \Redis::SERIALIZER_NONE, cachestore_redis::COMPRESSOR_PHP_GZIP, gzencode('value1'), gzencode('value2')], ['php, none', - Redis::SERIALIZER_PHP, cachestore_redis::COMPRESSOR_NONE, + \Redis::SERIALIZER_PHP, cachestore_redis::COMPRESSOR_NONE, serialize('value1'), serialize('value2')], ['php, gzip', - Redis::SERIALIZER_PHP, cachestore_redis::COMPRESSOR_PHP_GZIP, + \Redis::SERIALIZER_PHP, cachestore_redis::COMPRESSOR_PHP_GZIP, gzencode(serialize('value1')), gzencode(serialize('value2'))], ]; if (defined('Redis::SERIALIZER_IGBINARY')) { $data[] = [ 'igbinary, none', - Redis::SERIALIZER_IGBINARY, cachestore_redis::COMPRESSOR_NONE, + \Redis::SERIALIZER_IGBINARY, cachestore_redis::COMPRESSOR_NONE, igbinary_serialize('value1'), igbinary_serialize('value2'), ]; $data[] = [ 'igbinary, gzip', - Redis::SERIALIZER_IGBINARY, cachestore_redis::COMPRESSOR_PHP_GZIP, + \Redis::SERIALIZER_IGBINARY, cachestore_redis::COMPRESSOR_PHP_GZIP, gzencode(igbinary_serialize('value1')), gzencode(igbinary_serialize('value2')), ]; } @@ -207,19 +203,19 @@ class cachestore_redis_compressor_test extends advanced_testcase { if (extension_loaded('zstd')) { $data[] = [ 'none, zstd', - Redis::SERIALIZER_NONE, cachestore_redis::COMPRESSOR_PHP_ZSTD, + \Redis::SERIALIZER_NONE, cachestore_redis::COMPRESSOR_PHP_ZSTD, zstd_compress('value1'), zstd_compress('value2'), ]; $data[] = [ 'php, zstd', - Redis::SERIALIZER_PHP, cachestore_redis::COMPRESSOR_PHP_ZSTD, + \Redis::SERIALIZER_PHP, cachestore_redis::COMPRESSOR_PHP_ZSTD, zstd_compress(serialize('value1')), zstd_compress(serialize('value2')), ]; - if (defined('Redis::SERIALIZER_IGBINARY')) { + if (defined('\Redis::SERIALIZER_IGBINARY')) { $data[] = [ 'igbinary, zstd', - Redis::SERIALIZER_IGBINARY, cachestore_redis::COMPRESSOR_PHP_ZSTD, + \Redis::SERIALIZER_IGBINARY, cachestore_redis::COMPRESSOR_PHP_ZSTD, zstd_compress(igbinary_serialize('value1')), zstd_compress(igbinary_serialize('value2')), ]; } @@ -244,7 +240,7 @@ class cachestore_redis_compressor_test extends advanced_testcase { $store->set('key', 'value1'); // Disable compressor and serializer to check the actual stored value. - $rawstore = $this->create_store(cachestore_redis::COMPRESSOR_NONE, Redis::SERIALIZER_NONE); + $rawstore = $this->create_store(cachestore_redis::COMPRESSOR_NONE, \Redis::SERIALIZER_NONE); $data = $store->get('key'); $rawdata = $rawstore->get('key'); @@ -276,7 +272,7 @@ class cachestore_redis_compressor_test extends advanced_testcase { $store->set_many($many); // Disable compressor and serializer to check the actual stored value. - $rawstore = $this->create_store(cachestore_redis::COMPRESSOR_NONE, Redis::SERIALIZER_NONE); + $rawstore = $this->create_store(cachestore_redis::COMPRESSOR_NONE, \Redis::SERIALIZER_NONE); $data = $store->get_many($keys); $rawdata = $rawstore->get_many($keys); diff --git a/cache/stores/redis/tests/redis_test.php b/cache/stores/redis/tests/store_test.php similarity index 93% rename from cache/stores/redis/tests/redis_test.php rename to cache/stores/redis/tests/store_test.php index a4bd9f79425..14a38a4ca37 100644 --- a/cache/stores/redis/tests/redis_test.php +++ b/cache/stores/redis/tests/store_test.php @@ -14,6 +14,17 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace cachestore_redis; + +use cache_store; +use cache_definition; +use cachestore_redis; + +defined('MOODLE_INTERNAL') || die(); + +require_once(__DIR__.'/../../../tests/fixtures/stores.php'); +require_once(__DIR__.'/../lib.php'); + /** * Redis cache test. * @@ -26,20 +37,7 @@ * @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -require_once(__DIR__.'/../../../tests/fixtures/stores.php'); -require_once(__DIR__.'/../lib.php'); - -/** - * Redis cache test. - * - * @package cachestore_redis - * @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com) - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class cachestore_redis_test extends cachestore_tests { +class store_test extends \cachestore_tests { /** * @var cachestore_redis */ diff --git a/cache/stores/session/tests/session_test.php b/cache/stores/session/tests/store_test.php similarity index 93% rename from cache/stores/session/tests/session_test.php rename to cache/stores/session/tests/store_test.php index 8e7528ae448..0c9ec4a1e13 100644 --- a/cache/stores/session/tests/session_test.php +++ b/cache/stores/session/tests/store_test.php @@ -14,13 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Session unit tests - * - * @package cachestore_session - * @copyright 2013 Sam Hemelryk - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace cachestore_session; + +use cache_store; defined('MOODLE_INTERNAL') || die(); @@ -36,7 +32,7 @@ require_once($CFG->dirroot.'/cache/stores/session/lib.php'); * @copyright 2013 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class cachestore_session_test extends cachestore_tests { +class store_test extends \cachestore_tests { /** * Returns the session class name * @return string @@ -49,7 +45,7 @@ class cachestore_session_test extends cachestore_tests { * Test the maxsize option. */ public function test_maxsize() { - $config = cache_config_testing::instance(); + $config = \cache_config_testing::instance(); $config->phpunit_add_definition('phpunit/one', array( 'mode' => cache_store::MODE_SESSION, 'component' => 'phpunit', @@ -64,7 +60,7 @@ class cachestore_session_test extends cachestore_tests { 'maxsize' => 3 )); - $cacheone = cache::make('phpunit', 'one'); + $cacheone = \cache::make('phpunit', 'one'); $this->assertTrue($cacheone->set('key1', 'value1')); $this->assertTrue($cacheone->set('key2', 'value2')); @@ -122,7 +118,7 @@ class cachestore_session_test extends cachestore_tests { 'key4', 'key5', 'key6', 'key7', 'keyA', 'keyB', 'keyC' ))); - $cachetwo = cache::make('phpunit', 'two'); + $cachetwo = \cache::make('phpunit', 'two'); // Test adding many. $this->assertEquals(3, $cacheone->set_many(array( @@ -171,7 +167,7 @@ class cachestore_session_test extends cachestore_tests { } public function test_ttl() { - $config = cache_config_testing::instance(); + $config = \cache_config_testing::instance(); $config->phpunit_add_definition('phpunit/three', array( 'mode' => cache_store::MODE_SESSION, 'component' => 'phpunit', @@ -180,7 +176,7 @@ class cachestore_session_test extends cachestore_tests { 'ttl' => 3 )); - $cachethree = cache::make('phpunit', 'three'); + $cachethree = \cache::make('phpunit', 'three'); // Make sure that when cache with ttl is full the elements that were added first are deleted first regardless of access time. $cachethree->set('key1', 'value1'); @@ -196,4 +192,4 @@ class cachestore_session_test extends cachestore_tests { $this->assertEquals(array('key3' => false, 'key4' => false, 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7'), $cachethree->get_many(array('key3', 'key4', 'key5', 'key6', 'key7'))); } -} \ No newline at end of file +} diff --git a/cache/stores/static/tests/static_test.php b/cache/stores/static/tests/store_test.php similarity index 93% rename from cache/stores/static/tests/static_test.php rename to cache/stores/static/tests/store_test.php index f2efb42de80..0e4615a42c8 100644 --- a/cache/stores/static/tests/static_test.php +++ b/cache/stores/static/tests/store_test.php @@ -14,13 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Static unit tests - * - * @package cachestore_static - * @copyright 2013 Sam Hemelryk - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace cachestore_static; + +use cache_definition; +use cache_store; +use cachestore_static; defined('MOODLE_INTERNAL') || die(); @@ -36,7 +34,7 @@ require_once($CFG->dirroot.'/cache/stores/static/lib.php'); * @copyright 2013 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class cachestore_static_test extends cachestore_tests { +class store_test extends \cachestore_tests { /** * Returns the static class name * @return string @@ -50,7 +48,7 @@ class cachestore_static_test extends cachestore_tests { */ public function test_maxsize() { $defid = 'phpunit/testmaxsize'; - $config = cache_config_testing::instance(); + $config = \cache_config_testing::instance(); $config->phpunit_add_definition($defid, array( 'mode' => cache_store::MODE_REQUEST, 'component' => 'phpunit', @@ -128,7 +126,7 @@ class cachestore_static_test extends cachestore_tests { } // Prepare the static instance. $defid = 'phpunit/igbinary'; - $config = cache_config_testing::instance(); + $config = \cache_config_testing::instance(); $config->phpunit_add_definition($defid, array( 'mode' => cache_store::MODE_REQUEST, 'component' => 'phpunit', @@ -137,7 +135,7 @@ class cachestore_static_test extends cachestore_tests { $definition = cache_definition::load($defid, $config->get_definition_by_id($defid)); $instance = cachestore_static::initialise_test_instance($definition); // Prepare an object. - $obj = new stdClass(); + $obj = new \stdClass(); $obj->someint = 9; $obj->somestring = '99'; $obj->somearray = [9 => 999, '99' => '9999']; diff --git a/cache/tests/cache_test.php b/cache/tests/cache_test.php index 3eb6fd8b9a7..507f3d71766 100644 --- a/cache/tests/cache_test.php +++ b/cache/tests/cache_test.php @@ -14,17 +14,30 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * PHPunit tests for the cache API - * - * This file is part of Moodle's cache API, affectionately called MUC. - * It contains the components that are requried in order to use caching. - * - * @package core - * @category cache - * @copyright 2012 Sam Hemelryk - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_cache; + +use cache; +use cache_application; +use cache_config; +use cache_config_disabled; +use cache_config_testing; +use cache_definition; +use cache_disabled; +use cache_factory; +use cache_factory_disabled; +use cache_helper; +use cache_loader; +use cache_phpunit_application; +use cache_phpunit_cache; +use cache_phpunit_dummy_object; +use cache_phpunit_dummy_overrideclass; +use cache_phpunit_factory; +use cache_phpunit_request; +use cache_phpunit_session; +use cache_request; +use cache_session; +use cache_store; +use cacheable_object_array; defined('MOODLE_INTERNAL') || die(); @@ -36,10 +49,15 @@ require_once($CFG->dirroot.'/cache/tests/fixtures/lib.php'); /** * PHPunit tests for the cache API * + * This file is part of Moodle's cache API, affectionately called MUC. + * It contains the components that are requried in order to use caching. + * + * @package core + * @category cache * @copyright 2012 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_cache_testcase extends advanced_testcase { +class cache_test extends \advanced_testcase { /** * Set things back to the default before each test. @@ -114,7 +132,7 @@ class core_cache_testcase extends advanced_testcase { } $instance = cache_config::instance(); - $this->assertInstanceOf('cache_config_testing', $instance); + $this->assertInstanceOf(cache_config_testing::class, $instance); $this->assertTrue(cache_config_testing::config_file_exists()); @@ -215,7 +233,7 @@ class core_cache_testcase extends advanced_testcase { */ public function test_default_application_cache() { $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'phpunit', 'applicationtest'); - $this->assertInstanceOf('cache_application', $cache); + $this->assertInstanceOf(cache_application::class, $cache); $this->run_on_cache($cache); $instance = cache_config_testing::instance(true); @@ -227,7 +245,7 @@ class core_cache_testcase extends advanced_testcase { 'staticaccelerationsize' => 1 )); $cache = cache::make('phpunit', 'test_default_application_cache'); - $this->assertInstanceOf('cache_application', $cache); + $this->assertInstanceOf(cache_application::class, $cache); $this->run_on_cache($cache); } @@ -236,7 +254,7 @@ class core_cache_testcase extends advanced_testcase { */ public function test_default_session_cache() { $cache = cache::make_from_params(cache_store::MODE_SESSION, 'phpunit', 'applicationtest'); - $this->assertInstanceOf('cache_session', $cache); + $this->assertInstanceOf(cache_session::class, $cache); $this->run_on_cache($cache); } @@ -245,7 +263,7 @@ class core_cache_testcase extends advanced_testcase { */ public function test_default_request_cache() { $cache = cache::make_from_params(cache_store::MODE_REQUEST, 'phpunit', 'applicationtest'); - $this->assertInstanceOf('cache_request', $cache); + $this->assertInstanceOf(cache_request::class, $cache); $this->run_on_cache($cache); } @@ -333,7 +351,7 @@ class core_cache_testcase extends advanced_testcase { $specobject = new cache_phpunit_dummy_object('red', 'blue', $starttime); $this->assertTrue($cache->set($key, $specobject)); $result = $cache->get($key); - $this->assertInstanceOf('cache_phpunit_dummy_object', $result); + $this->assertInstanceOf(cache_phpunit_dummy_object::class, $result); $this->assertEquals('red_ptc_wfc', $result->property1); $this->assertEquals('blue_ptc_wfc', $result->property2); $this->assertGreaterThan($starttime, $result->propertytime); @@ -347,10 +365,10 @@ class core_cache_testcase extends advanced_testcase { ); $this->assertTrue($cache->set($key, $data)); $result = $cache->get($key); - $this->assertInstanceOf('cacheable_object_array', $result); + $this->assertInstanceOf(cacheable_object_array::class, $result); $this->assertCount(3, $data); foreach ($result as $item) { - $this->assertInstanceOf('cache_phpunit_dummy_object', $item); + $this->assertInstanceOf(cache_phpunit_dummy_object::class, $item); $this->assertEquals('red_ptc_wfc', $item->property1); $this->assertEquals('blue_ptc_wfc', $item->property2); // Ensure that wake from cache is called in all cases. @@ -394,29 +412,29 @@ class core_cache_testcase extends advanced_testcase { $this->assertFalse($cache->get('key3')); // Quick reference test. - $obj = new stdClass; + $obj = new \stdClass; $obj->key = 'value'; $ref =& $obj; $this->assertTrue($cache->set('obj', $obj)); $obj->key = 'eulav'; $var = $cache->get('obj'); - $this->assertInstanceOf('stdClass', $var); + $this->assertInstanceOf(\stdClass::class, $var); $this->assertEquals('value', $var->key); $ref->key = 'eulav'; $var = $cache->get('obj'); - $this->assertInstanceOf('stdClass', $var); + $this->assertInstanceOf(\stdClass::class, $var); $this->assertEquals('value', $var->key); $this->assertTrue($cache->delete('obj')); // Deep reference test. - $obj1 = new stdClass; + $obj1 = new \stdClass; $obj1->key = 'value'; - $obj2 = new stdClass; + $obj2 = new \stdClass; $obj2->key = 'test'; - $obj3 = new stdClass; + $obj3 = new \stdClass; $obj3->key = 'pork'; $obj1->subobj =& $obj2; $obj2->subobj =& $obj3; @@ -426,62 +444,62 @@ class core_cache_testcase extends advanced_testcase { $obj2->key = 'tset'; $obj3->key = 'krop'; $var = $cache->get('obj'); - $this->assertInstanceOf('stdClass', $var); + $this->assertInstanceOf(\stdClass::class, $var); $this->assertEquals('value', $var->key); - $this->assertInstanceOf('stdClass', $var->subobj); + $this->assertInstanceOf(\stdClass::class, $var->subobj); $this->assertEquals('test', $var->subobj->key); - $this->assertInstanceOf('stdClass', $var->subobj->subobj); + $this->assertInstanceOf(\stdClass::class, $var->subobj->subobj); $this->assertEquals('pork', $var->subobj->subobj->key); $this->assertTrue($cache->delete('obj')); // Death reference test... basically we don't want this to die. - $obj = new stdClass; + $obj = new \stdClass; $obj->key = 'value'; $obj->self =& $obj; $this->assertTrue($cache->set('obj', $obj)); $var = $cache->get('obj'); - $this->assertInstanceOf('stdClass', $var); + $this->assertInstanceOf(\stdClass::class, $var); $this->assertEquals('value', $var->key); // Reference test after retrieve. - $obj = new stdClass; + $obj = new \stdClass; $obj->key = 'value'; $this->assertTrue($cache->set('obj', $obj)); $var1 = $cache->get('obj'); - $this->assertInstanceOf('stdClass', $var1); + $this->assertInstanceOf(\stdClass::class, $var1); $this->assertEquals('value', $var1->key); $var1->key = 'eulav'; $this->assertEquals('eulav', $var1->key); $var2 = $cache->get('obj'); - $this->assertInstanceOf('stdClass', $var2); + $this->assertInstanceOf(\stdClass::class, $var2); $this->assertEquals('value', $var2->key); $this->assertTrue($cache->delete('obj')); // Death reference test on get_many... basically we don't want this to die. - $obj = new stdClass; + $obj = new \stdClass; $obj->key = 'value'; $obj->self =& $obj; $this->assertEquals(1, $cache->set_many(array('obj' => $obj))); $var = $cache->get_many(array('obj')); - $this->assertInstanceOf('stdClass', $var['obj']); + $this->assertInstanceOf(\stdClass::class, $var['obj']); $this->assertEquals('value', $var['obj']->key); // Reference test after retrieve. - $obj = new stdClass; + $obj = new \stdClass; $obj->key = 'value'; $this->assertEquals(1, $cache->set_many(array('obj' => $obj))); $var1 = $cache->get_many(array('obj')); - $this->assertInstanceOf('stdClass', $var1['obj']); + $this->assertInstanceOf(\stdClass::class, $var1['obj']); $this->assertEquals('value', $var1['obj']->key); $var1['obj']->key = 'eulav'; $this->assertEquals('eulav', $var1['obj']->key); $var2 = $cache->get_many(array('obj')); - $this->assertInstanceOf('stdClass', $var2['obj']); + $this->assertInstanceOf(\stdClass::class, $var2['obj']); $this->assertEquals('value', $var2['obj']->key); $this->assertTrue($cache->delete('obj')); @@ -490,20 +508,20 @@ class core_cache_testcase extends advanced_testcase { try { $cache->get('exception', MUST_EXIST); $this->fail('Exception expected from cache::get using MUST_EXIST'); - } catch (Exception $e) { + } catch (\Exception $e) { $this->assertTrue(true); } try { $cache->get_many(array('exception1', 'exception2'), MUST_EXIST); $this->fail('Exception expected from cache::get_many using MUST_EXIST'); - } catch (Exception $e) { + } catch (\Exception $e) { $this->assertTrue(true); } $cache->set('test', 'test'); try { $cache->get_many(array('test', 'exception'), MUST_EXIST); $this->fail('Exception expected from cache::get_many using MUST_EXIST'); - } catch (Exception $e) { + } catch (\Exception $e) { $this->assertTrue(true); } } @@ -522,7 +540,7 @@ class core_cache_testcase extends advanced_testcase { )); $cache = cache::make('phpunit', 'datasourcetest'); - $this->assertInstanceOf('cache_application', $cache); + $this->assertInstanceOf(cache_application::class, $cache); // Purge it to be sure. $this->assertTrue($cache->purge()); @@ -562,8 +580,8 @@ class core_cache_testcase extends advanced_testcase { 'overrideclassfile' => 'cache/tests/fixtures/lib.php' )); $cache = cache::make('phpunit', 'overridetest'); - $this->assertInstanceOf('cache_phpunit_dummy_overrideclass', $cache); - $this->assertInstanceOf('cache_application', $cache); + $this->assertInstanceOf(cache_phpunit_dummy_overrideclass::class, $cache); + $this->assertInstanceOf(cache_application::class, $cache); // Purge it to be sure. $this->assertTrue($cache->purge()); // It won't be there yet. @@ -594,12 +612,12 @@ class core_cache_testcase extends advanced_testcase { ), false); $cacheonly = cache::make('phpunit', 'mappingsonly'); - $this->assertInstanceOf('cache_application', $cacheonly); + $this->assertInstanceOf(cache_application::class, $cacheonly); $this->assertEquals('cachestore_dummy', $cacheonly->phpunit_get_store_class()); $expected = $this->get_expected_application_cache_store(); $cachenon = cache::make('phpunit', 'nonmappingsonly'); - $this->assertInstanceOf('cache_application', $cachenon); + $this->assertInstanceOf(cache_application::class, $cachenon); $this->assertEquals($expected, $cachenon->phpunit_get_store_class()); } @@ -659,7 +677,7 @@ class core_cache_testcase extends advanced_testcase { 'ttl' => -86400 // Set to a day in the past to be extra sure. )); $cache = cache::make('phpunit', 'ttltest'); - $this->assertInstanceOf('cache_application', $cache); + $this->assertInstanceOf(cache_application::class, $cache); // Purge it to be sure. $this->assertTrue($cache->purge()); @@ -708,7 +726,7 @@ class core_cache_testcase extends advanced_testcase { 'ttl' => 86400 // Set to a day in the future to be extra sure. )); $cache = cache::make('phpunit', 'ttltest'); - $this->assertInstanceOf('cache_application', $cache); + $this->assertInstanceOf(cache_application::class, $cache); // Purge it to be sure. $this->assertTrue($cache->purge()); @@ -757,7 +775,7 @@ class core_cache_testcase extends advanced_testcase { 'ttl' => 86400 // Set to a day in the future to be extra sure. )); $cache = cache::make('phpunit', 'ttltest'); - $this->assertInstanceOf('cache_session', $cache); + $this->assertInstanceOf(cache_session::class, $cache); // Purge it to be sure. $this->assertTrue($cache->purge()); @@ -872,7 +890,7 @@ class core_cache_testcase extends advanced_testcase { ) )); $cache = cache::make('phpunit', 'test_session_event_invalidation'); - $this->assertInstanceOf('cache_session', $cache); + $this->assertInstanceOf(cache_session::class, $cache); $this->assertTrue($cache->set('testkey1', 'test data 1')); $this->assertEquals('test data 1', $cache->get('testkey1')); @@ -941,7 +959,7 @@ class core_cache_testcase extends advanced_testcase { 'area' => 'test_session_definition_invalidation' )); $cache = cache::make('phpunit', 'test_session_definition_invalidation'); - $this->assertInstanceOf('cache_session', $cache); + $this->assertInstanceOf(cache_session::class, $cache); $this->assertTrue($cache->set('testkey1', 'test data 1')); $this->assertEquals('test data 1', $cache->get('testkey1')); $this->assertTrue($cache->set('testkey2', 'test data 2')); @@ -1237,7 +1255,7 @@ class core_cache_testcase extends advanced_testcase { $this->resetAfterTest(); $CFG->altcacheconfigpath = $CFG->dataroot.'/cache/altcacheconfigpath'; $instance = cache_config_testing::instance(); - $this->assertInstanceOf('cache_config', $instance); + $this->assertInstanceOf(cache_config::class, $instance); } /** @@ -1267,9 +1285,9 @@ class core_cache_testcase extends advanced_testcase { 'disabletest3' => cache::make('phpunit', 'disabletest3') ); - $this->assertInstanceOf('cache_phpunit_application', $caches['disabletest1']); - $this->assertInstanceOf('cache_phpunit_session', $caches['disabletest2']); - $this->assertInstanceOf('cache_phpunit_request', $caches['disabletest3']); + $this->assertInstanceOf(cache_phpunit_application::class, $caches['disabletest1']); + $this->assertInstanceOf(cache_phpunit_session::class, $caches['disabletest2']); + $this->assertInstanceOf(cache_phpunit_request::class, $caches['disabletest3']); $this->assertEquals('cachestore_file', $caches['disabletest1']->phpunit_get_store_class()); $this->assertEquals('cachestore_session', $caches['disabletest2']->phpunit_get_store_class()); @@ -1289,9 +1307,9 @@ class core_cache_testcase extends advanced_testcase { 'disabletest3' => cache::make('phpunit', 'disabletest3') ); - $this->assertInstanceOf('cache_phpunit_application', $caches['disabletest1']); - $this->assertInstanceOf('cache_phpunit_session', $caches['disabletest2']); - $this->assertInstanceOf('cache_phpunit_request', $caches['disabletest3']); + $this->assertInstanceOf(cache_phpunit_application::class, $caches['disabletest1']); + $this->assertInstanceOf(cache_phpunit_session::class, $caches['disabletest2']); + $this->assertInstanceOf(cache_phpunit_request::class, $caches['disabletest3']); $this->assertEquals('cachestore_dummy', $caches['disabletest1']->phpunit_get_store_class()); $this->assertEquals('cachestore_dummy', $caches['disabletest2']->phpunit_get_store_class()); @@ -1328,19 +1346,19 @@ class core_cache_testcase extends advanced_testcase { // Check we get the expected disabled factory. $factory = cache_factory::instance(); - $this->assertInstanceOf('cache_factory_disabled', $factory); + $this->assertInstanceOf(cache_factory_disabled::class, $factory); // Check we get the expected disabled config. $config = $factory->create_config_instance(); - $this->assertInstanceOf('cache_config_disabled', $config); + $this->assertInstanceOf(cache_config_disabled::class, $config); // Check we get the expected disabled caches. $cache = cache::make('core', 'string'); - $this->assertInstanceOf('cache_disabled', $cache); + $this->assertInstanceOf(cache_disabled::class, $cache); // Test an application cache. $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'phpunit', 'disable'); - $this->assertInstanceOf('cache_disabled', $cache); + $this->assertInstanceOf(cache_disabled::class, $cache); $this->assertFalse($cache->get('test')); $this->assertFalse($cache->set('test', 'test')); @@ -1349,7 +1367,7 @@ class core_cache_testcase extends advanced_testcase { // Test a session cache. $cache = cache::make_from_params(cache_store::MODE_SESSION, 'phpunit', 'disable'); - $this->assertInstanceOf('cache_disabled', $cache); + $this->assertInstanceOf(cache_disabled::class, $cache); $this->assertFalse($cache->get('test')); $this->assertFalse($cache->set('test', 'test')); @@ -1358,7 +1376,7 @@ class core_cache_testcase extends advanced_testcase { // Finally test a request cache. $cache = cache::make_from_params(cache_store::MODE_REQUEST, 'phpunit', 'disable'); - $this->assertInstanceOf('cache_disabled', $cache); + $this->assertInstanceOf(cache_disabled::class, $cache); $this->assertFalse($cache->get('test')); $this->assertFalse($cache->set('test', 'test')); @@ -1388,7 +1406,7 @@ class core_cache_testcase extends advanced_testcase { $instance->phpunit_add_definition_mapping('phpunit/multi_loader', 'phpunittest2', 2); $cache = cache::make('phpunit', 'multi_loader'); - $this->assertInstanceOf('cache_application', $cache); + $this->assertInstanceOf(cache_application::class, $cache); $this->assertFalse($cache->get('test')); $this->assertTrue($cache->set('test', 'test')); $this->assertEquals('test', $cache->get('test')); @@ -1457,7 +1475,7 @@ class core_cache_testcase extends advanced_testcase { $instance->phpunit_add_definition_mapping('phpunit/multi_loader', 'phpunittest2', 2); $cache = cache::make('phpunit', 'multi_loader'); - $this->assertInstanceOf('cache_session', $cache); + $this->assertInstanceOf(cache_session::class, $cache); $this->assertFalse($cache->get('test')); $this->assertTrue($cache->set('test', 'test')); $this->assertEquals('test', $cache->get('test')); @@ -1653,7 +1671,7 @@ class core_cache_testcase extends advanced_testcase { 'requirelockingwrite' => true )); $cache = cache::make('phpunit', 'test_application_locking'); - $this->assertInstanceOf('cache_application', $cache); + $this->assertInstanceOf(cache_application::class, $cache); $this->assertTrue($cache->set('a', 'A')); $this->assertTrue($cache->set('b', 'B')); @@ -1675,14 +1693,14 @@ class core_cache_testcase extends advanced_testcase { 'area' => 'test_purge_stores_used_by_definition' )); $cache = cache::make('phpunit', 'test_purge_stores_used_by_definition'); - $this->assertInstanceOf('cache_application', $cache); + $this->assertInstanceOf(cache_application::class, $cache); $this->assertTrue($cache->set('test', 'test')); unset($cache); cache_helper::purge_stores_used_by_definition('phpunit', 'test_purge_stores_used_by_definition'); $cache = cache::make('phpunit', 'test_purge_stores_used_by_definition'); - $this->assertInstanceOf('cache_application', $cache); + $this->assertInstanceOf(cache_application::class, $cache); $this->assertFalse($cache->get('test')); } @@ -1709,7 +1727,7 @@ class core_cache_testcase extends advanced_testcase { $definition = $factory->create_definition('phpunit', 'purge1'); $this->assertFalse($definition->has_required_identifiers()); $cache = $factory->create_cache($definition); - $this->assertInstanceOf('cache_application', $cache); + $this->assertInstanceOf(cache_application::class, $cache); $this->assertTrue($cache->set('test', 'test')); $this->assertTrue($cache->has('test')); cache_helper::purge_by_definition('phpunit', 'purge1'); @@ -1719,7 +1737,7 @@ class core_cache_testcase extends advanced_testcase { $definition = $factory->create_definition('phpunit', 'purge2'); $this->assertTrue($definition->has_required_identifiers()); $cache = $factory->create_cache($definition); - $this->assertInstanceOf('cache_application', $cache); + $this->assertInstanceOf(cache_application::class, $cache); $this->assertTrue($cache->set('test', 'test')); $this->assertTrue($cache->has('test')); cache_helper::purge_stores_used_by_definition('phpunit', 'purge2'); @@ -1728,7 +1746,7 @@ class core_cache_testcase extends advanced_testcase { try { cache_helper::purge_by_definition('phpunit', 'purge2'); $this->fail('Should not be able to purge a definition required identifiers without providing them.'); - } catch (coding_exception $ex) { + } catch (\coding_exception $ex) { $this->assertStringContainsString('Identifier required for cache has not been provided', $ex->getMessage()); } } @@ -1737,7 +1755,7 @@ class core_cache_testcase extends advanced_testcase { * Tests that ad-hoc caches are correctly purged with a purge_all call. */ public function test_purge_all_with_adhoc_caches() { - $cache = \cache::make_from_params(\cache_store::MODE_REQUEST, 'core_cache', 'test'); + $cache = cache::make_from_params(cache_store::MODE_REQUEST, 'core_cache', 'test'); $cache->set('test', 123); cache_helper::purge_all(); $this->assertFalse($cache->get('test')); @@ -1770,26 +1788,26 @@ class core_cache_testcase extends advanced_testcase { // Test application cache is searchable. $definition = $factory->create_definition('phpunit', 'search1'); - $this->assertInstanceOf('cache_definition', $definition); + $this->assertInstanceOf(cache_definition::class, $definition); $this->assertEquals(cache_store::IS_SEARCHABLE, $definition->get_requirements_bin() & cache_store::IS_SEARCHABLE); $cache = $factory->create_cache($definition); - $this->assertInstanceOf('cache_application', $cache); + $this->assertInstanceOf(cache_application::class, $cache); $this->assertArrayHasKey('cache_is_searchable', $cache->phpunit_get_store_implements()); // Test session cache is searchable. $definition = $factory->create_definition('phpunit', 'search2'); - $this->assertInstanceOf('cache_definition', $definition); + $this->assertInstanceOf(cache_definition::class, $definition); $this->assertEquals(cache_store::IS_SEARCHABLE, $definition->get_requirements_bin() & cache_store::IS_SEARCHABLE); $cache = $factory->create_cache($definition); - $this->assertInstanceOf('cache_session', $cache); + $this->assertInstanceOf(cache_session::class, $cache); $this->assertArrayHasKey('cache_is_searchable', $cache->phpunit_get_store_implements()); // Test request cache is searchable. $definition = $factory->create_definition('phpunit', 'search3'); - $this->assertInstanceOf('cache_definition', $definition); + $this->assertInstanceOf(cache_definition::class, $definition); $this->assertEquals(cache_store::IS_SEARCHABLE, $definition->get_requirements_bin() & cache_store::IS_SEARCHABLE); $cache = $factory->create_cache($definition); - $this->assertInstanceOf('cache_request', $cache); + $this->assertInstanceOf(cache_request::class, $cache); $this->assertArrayHasKey('cache_is_searchable', $cache->phpunit_get_store_implements()); } @@ -1845,7 +1863,7 @@ class core_cache_testcase extends advanced_testcase { )); $cache = cache::make('phpunit', 'accelerated'); - $this->assertInstanceOf('cache_phpunit_application', $cache); + $this->assertInstanceOf(cache_phpunit_application::class, $cache); // Set and get three elements. $this->assertTrue($cache->set('a', 'A')); @@ -1912,12 +1930,12 @@ class core_cache_testcase extends advanced_testcase { // Get the value from the backend store, populating the static cache. $cachevalue = $cache->get('a'); - $this->assertInstanceOf('cache_phpunit_dummy_object', $cachevalue); + $this->assertInstanceOf(cache_phpunit_dummy_object::class, $cachevalue); $this->assertGreaterThanOrEqual($staticaccelerationreturntime, $cachevalue->propertytime); $backingstorereturntime = $cachevalue->propertytime; $results = $cache->get_many(array('b')); - $this->assertInstanceOf('cache_phpunit_dummy_object', $results['b']); + $this->assertInstanceOf(cache_phpunit_dummy_object::class, $results['b']); $this->assertGreaterThanOrEqual($staticaccelerationreturntimeb, $results['b']->propertytime); $backingstorereturntimeb = $results['b']->propertytime; @@ -1925,16 +1943,16 @@ class core_cache_testcase extends advanced_testcase { // Upon failure, the times are not adjusted as wake_from_cache is skipped as the // value is stored serialized in the static acceleration cache. $cachevalue = $cache->phpunit_static_acceleration_get('a'); - $this->assertInstanceOf('cache_phpunit_dummy_object', $cachevalue); + $this->assertInstanceOf(cache_phpunit_dummy_object::class, $cachevalue); $this->assertGreaterThanOrEqual($backingstorereturntime, $cachevalue->propertytime); $results = $cache->get_many(array('b')); - $this->assertInstanceOf('cache_phpunit_dummy_object', $results['b']); + $this->assertInstanceOf(cache_phpunit_dummy_object::class, $results['b']); $this->assertGreaterThanOrEqual($backingstorereturntimeb, $results['b']->propertytime); /** @var cache_phpunit_application $cache */ $cache = cache::make('phpunit', 'accelerated2'); - $this->assertInstanceOf('cache_phpunit_application', $cache); + $this->assertInstanceOf(cache_phpunit_application::class, $cache); // Check that the array holds the last accessed items by get/set. $this->assertTrue($cache->set('a', 'A')); @@ -1968,7 +1986,7 @@ class core_cache_testcase extends advanced_testcase { $cache = cache::make('phpunit', 'accelerated3'); - $this->assertInstanceOf('cache_phpunit_application', $cache); + $this->assertInstanceOf(cache_phpunit_application::class, $cache); // Check that the array holds the last accessed items by get/set. $this->assertTrue($cache->set('a', 'A')); @@ -1997,7 +2015,7 @@ class core_cache_testcase extends advanced_testcase { $this->assertEquals('E', $cache->phpunit_static_acceleration_get('e')); $cache = cache::make('phpunit', 'accelerated4'); - $this->assertInstanceOf('cache_phpunit_application', $cache); + $this->assertInstanceOf(cache_phpunit_application::class, $cache); $this->assertTrue($cache->set('a', 'A')); $this->assertTrue($cache->set('a', 'A')); $this->assertTrue($cache->set('a', 'A')); @@ -2010,7 +2028,7 @@ class core_cache_testcase extends advanced_testcase { // Setting simpledata to false objects are cloned when retrieving data. $cache = cache::make('phpunit', 'simpledataarea1'); - $notreallysimple = new stdClass(); + $notreallysimple = new \stdClass(); $notreallysimple->name = 'a'; $cache->set('a', $notreallysimple); $returnedinstance1 = $cache->get('a'); @@ -2020,7 +2038,7 @@ class core_cache_testcase extends advanced_testcase { // Setting simpledata to true we assume that data does not contain references. $cache = cache::make('phpunit', 'simpledataarea2'); - $notreallysimple = new stdClass(); + $notreallysimple = new \stdClass(); $notreallysimple->name = 'a'; $cache->set('a', $notreallysimple); $returnedinstance1 = $cache->get('a'); @@ -2331,7 +2349,7 @@ class core_cache_testcase extends advanced_testcase { $this->assertFalse($cache->get('testkey1')); // Set up the cache again in the same request and add a new value back in. - $factory = \cache_factory::instance(); + $factory = cache_factory::instance(); $factory->reset_cache_instances(); $cache = cache::make('phpunit', 'eventpurgetest'); $cache->set('testkey1', 'test data 2'); @@ -2339,7 +2357,7 @@ class core_cache_testcase extends advanced_testcase { // Trick the cache into thinking that this is a new request. cache_phpunit_cache::simulate_new_request(); - $factory = \cache_factory::instance(); + $factory = cache_factory::instance(); $factory->reset_cache_instances(); // Set up the cache again. diff --git a/calendar/tests/event_test.php b/calendar/tests/event_test.php index 843bce0e5b4..26abea7e6e7 100644 --- a/calendar/tests/event_test.php +++ b/calendar/tests/event_test.php @@ -14,15 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Event tests. - * - * @package core_calendar - * @copyright 2017 Cameron Ball - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); +namespace core_calendar; use core_calendar\local\event\entities\event; use core_calendar\local\event\proxies\std_proxy; @@ -31,13 +23,16 @@ use core_calendar\local\event\value_objects\event_description; use core_calendar\local\event\value_objects\event_times; use core_calendar\local\event\entities\event_collection_interface; +defined('MOODLE_INTERNAL') || die(); + /** - * Event testcase. + * Calendar event tests.. * + * @package core_calendar * @copyright 2017 Cameron Ball * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_calendar_event_testcase extends advanced_testcase { +class event_test extends \advanced_testcase { /** * Test event class getters. * diff --git a/cohort/tests/cohortlib_test.php b/cohort/tests/lib_test.php similarity index 88% rename from cohort/tests/cohortlib_test.php rename to cohort/tests/lib_test.php index 05bcd0ef3de..ccadc66a0c7 100644 --- a/cohort/tests/cohortlib_test.php +++ b/cohort/tests/lib_test.php @@ -14,14 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Cohort library tests. - * - * @package core_cohort - * @category phpunit - * @copyright 2012 Petr Skoda {@link http://skodak.org} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_cohort; defined('MOODLE_INTERNAL') || die(); @@ -37,15 +30,15 @@ require_once("$CFG->dirroot/cohort/lib.php"); * @copyright 2012 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_cohort_cohortlib_testcase extends advanced_testcase { +class lib_test extends \advanced_testcase { public function test_cohort_add_cohort() { global $DB; $this->resetAfterTest(); - $cohort = new stdClass(); - $cohort->contextid = context_system::instance()->id; + $cohort = new \stdClass(); + $cohort->contextid = \context_system::instance()->id; $cohort->name = 'test cohort'; $cohort->idnumber = 'testid'; $cohort->description = 'test cohort desc'; @@ -66,14 +59,14 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { } public function test_cohort_add_cohort_missing_name() { - $cohort = new stdClass(); - $cohort->contextid = context_system::instance()->id; + $cohort = new \stdClass(); + $cohort->contextid = \context_system::instance()->id; $cohort->name = null; $cohort->idnumber = 'testid'; $cohort->description = 'test cohort desc'; $cohort->descriptionformat = FORMAT_HTML; - $this->expectException(coding_exception::class); + $this->expectException(\coding_exception::class); $this->expectExceptionMessage('Missing cohort name in cohort_add_cohort()'); cohort_add_cohort($cohort); } @@ -82,8 +75,8 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $this->resetAfterTest(); // Setup cohort data structure. - $cohort = new stdClass(); - $cohort->contextid = context_system::instance()->id; + $cohort = new \stdClass(); + $cohort->contextid = \context_system::instance()->id; $cohort->name = 'test cohort'; $cohort->idnumber = 'testid'; $cohort->description = 'test cohort desc'; @@ -106,7 +99,7 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $this->assertEquals('cohort', $event->objecttable); $this->assertEquals($id, $event->objectid); $this->assertEquals($cohort->contextid, $event->contextid); - $url = new moodle_url('/cohort/index.php', array('contextid' => $event->contextid)); + $url = new \moodle_url('/cohort/index.php', array('contextid' => $event->contextid)); $this->assertEquals($url, $event->get_url()); $this->assertEquals($cohort, $event->get_record_snapshot('cohort', $id)); $this->assertEventLegacyData($cohort, $event); @@ -118,8 +111,8 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $this->resetAfterTest(); - $cohort = new stdClass(); - $cohort->contextid = context_system::instance()->id; + $cohort = new \stdClass(); + $cohort->contextid = \context_system::instance()->id; $cohort->name = 'test cohort'; $cohort->idnumber = 'testid'; $cohort->description = 'test cohort desc'; @@ -152,8 +145,8 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $this->resetAfterTest(); // Setup the cohort data structure. - $cohort = new stdClass(); - $cohort->contextid = context_system::instance()->id; + $cohort = new \stdClass(); + $cohort->contextid = \context_system::instance()->id; $cohort->name = 'test cohort'; $cohort->idnumber = 'testid'; $cohort->description = 'test cohort desc'; @@ -183,7 +176,7 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $this->assertEquals('cohort', $event->objecttable); $this->assertEquals($updatedcohort->id, $event->objectid); $this->assertEquals($updatedcohort->contextid, $event->contextid); - $url = new moodle_url('/cohort/edit.php', array('id' => $event->objectid)); + $url = new \moodle_url('/cohort/edit.php', array('id' => $event->objectid)); $this->assertEquals($url, $event->get_url()); $this->assertEquals($cohort, $event->get_record_snapshot('cohort', $id)); $this->assertEventLegacyData($cohort, $event); @@ -223,7 +216,7 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $this->assertInstanceOf('\core\event\cohort_deleted', $event); $this->assertEquals('cohort', $event->objecttable); $this->assertEquals($cohort->id, $event->objectid); - $url = new moodle_url('/cohort/index.php', array('contextid' => $event->contextid)); + $url = new \moodle_url('/cohort/index.php', array('contextid' => $event->contextid)); $this->assertEquals($url, $event->get_url()); $this->assertEquals($cohort, $event->get_record_snapshot('cohort', $cohort->id)); $this->assertEventLegacyData($cohort, $event); @@ -237,13 +230,13 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $category = $this->getDataGenerator()->create_category(); - $cohort = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($category->id)->id)); + $cohort = $this->getDataGenerator()->create_cohort(array('contextid'=>\context_coursecat::instance($category->id)->id)); cohort_delete_category($category); $this->assertTrue($DB->record_exists('cohort', array('id'=>$cohort->id))); $newcohort = $DB->get_record('cohort', array('id'=>$cohort->id)); - $this->assertEquals(context_system::instance()->id, $newcohort->contextid); + $this->assertEquals(\context_system::instance()->id, $newcohort->contextid); } public function test_cohort_add_member() { @@ -284,7 +277,7 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $this->assertEquals($cohort->id, $event->objectid); $this->assertEquals($user->id, $event->relateduserid); $this->assertEquals($USER->id, $event->userid); - $url = new moodle_url('/cohort/assign.php', array('id' => $event->objectid)); + $url = new \moodle_url('/cohort/assign.php', array('id' => $event->objectid)); $this->assertEquals($url, $event->get_url()); $this->assertEventLegacyData((object) array('cohortid' => $cohort->id, 'userid' => $user->id), $event); $this->assertEventContextNotUsed($event); @@ -330,7 +323,7 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $this->assertEquals($cohort->id, $event->objectid); $this->assertEquals($user->id, $event->relateduserid); $this->assertEquals($USER->id, $event->userid); - $url = new moodle_url('/cohort/assign.php', array('id' => $event->objectid)); + $url = new \moodle_url('/cohort/assign.php', array('id' => $event->objectid)); $this->assertEquals($url, $event->get_url()); $this->assertEventLegacyData((object) array('cohortid' => $cohort->id, 'userid' => $user->id), $event); $this->assertEventContextNotUsed($event); @@ -357,52 +350,52 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $category1 = $this->getDataGenerator()->create_category(); $category2 = $this->getDataGenerator()->create_category(); - $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($category1->id)->id, 'name'=>'aaagrrryyy', 'idnumber'=>'','description'=>'')); - $cohort2 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($category1->id)->id, 'name'=>'bbb', 'idnumber'=>'', 'description'=>'yyybrrr')); - $cohort3 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($category1->id)->id, 'name'=>'ccc', 'idnumber'=>'xxarrrghyyy', 'description'=>'po_us')); - $cohort4 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_system::instance()->id)); + $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>\context_coursecat::instance($category1->id)->id, 'name'=>'aaagrrryyy', 'idnumber'=>'','description'=>'')); + $cohort2 = $this->getDataGenerator()->create_cohort(array('contextid'=>\context_coursecat::instance($category1->id)->id, 'name'=>'bbb', 'idnumber'=>'', 'description'=>'yyybrrr')); + $cohort3 = $this->getDataGenerator()->create_cohort(array('contextid'=>\context_coursecat::instance($category1->id)->id, 'name'=>'ccc', 'idnumber'=>'xxarrrghyyy', 'description'=>'po_us')); + $cohort4 = $this->getDataGenerator()->create_cohort(array('contextid'=>\context_system::instance()->id)); - $result = cohort_get_cohorts(context_coursecat::instance($category2->id)->id); + $result = cohort_get_cohorts(\context_coursecat::instance($category2->id)->id); $this->assertEquals(0, $result['totalcohorts']); $this->assertEquals(0, count($result['cohorts'])); $this->assertEquals(0, $result['allcohorts']); - $result = cohort_get_cohorts(context_coursecat::instance($category1->id)->id); + $result = cohort_get_cohorts(\context_coursecat::instance($category1->id)->id); $this->assertEquals(3, $result['totalcohorts']); $this->assertEquals(array($cohort1->id=>$cohort1, $cohort2->id=>$cohort2, $cohort3->id=>$cohort3), $result['cohorts']); $this->assertEquals(3, $result['allcohorts']); - $result = cohort_get_cohorts(context_coursecat::instance($category1->id)->id, 0, 100, 'arrrgh'); + $result = cohort_get_cohorts(\context_coursecat::instance($category1->id)->id, 0, 100, 'arrrgh'); $this->assertEquals(1, $result['totalcohorts']); $this->assertEquals(array($cohort3->id=>$cohort3), $result['cohorts']); $this->assertEquals(3, $result['allcohorts']); - $result = cohort_get_cohorts(context_coursecat::instance($category1->id)->id, 0, 100, 'brrr'); + $result = cohort_get_cohorts(\context_coursecat::instance($category1->id)->id, 0, 100, 'brrr'); $this->assertEquals(1, $result['totalcohorts']); $this->assertEquals(array($cohort2->id=>$cohort2), $result['cohorts']); $this->assertEquals(3, $result['allcohorts']); - $result = cohort_get_cohorts(context_coursecat::instance($category1->id)->id, 0, 100, 'grrr'); + $result = cohort_get_cohorts(\context_coursecat::instance($category1->id)->id, 0, 100, 'grrr'); $this->assertEquals(1, $result['totalcohorts']); $this->assertEquals(array($cohort1->id=>$cohort1), $result['cohorts']); $this->assertEquals(3, $result['allcohorts']); - $result = cohort_get_cohorts(context_coursecat::instance($category1->id)->id, 1, 1, 'yyy'); + $result = cohort_get_cohorts(\context_coursecat::instance($category1->id)->id, 1, 1, 'yyy'); $this->assertEquals(3, $result['totalcohorts']); $this->assertEquals(array($cohort2->id=>$cohort2), $result['cohorts']); $this->assertEquals(3, $result['allcohorts']); - $result = cohort_get_cohorts(context_coursecat::instance($category1->id)->id, 0, 100, 'po_us'); + $result = cohort_get_cohorts(\context_coursecat::instance($category1->id)->id, 0, 100, 'po_us'); $this->assertEquals(1, $result['totalcohorts']); $this->assertEquals(array($cohort3->id=>$cohort3), $result['cohorts']); $this->assertEquals(3, $result['allcohorts']); - $result = cohort_get_cohorts(context_coursecat::instance($category1->id)->id, 0, 100, 'pokus'); + $result = cohort_get_cohorts(\context_coursecat::instance($category1->id)->id, 0, 100, 'pokus'); $this->assertEquals(0, $result['totalcohorts']); $this->assertEquals(array(), $result['cohorts']); $this->assertEquals(3, $result['allcohorts']); - $result = cohort_get_cohorts(context_system::instance()->id); + $result = cohort_get_cohorts(\context_system::instance()->id); $this->assertEquals(1, $result['totalcohorts']); $this->assertEquals(array($cohort4->id=>$cohort4), $result['cohorts']); $this->assertEquals(1, $result['allcohorts']); @@ -416,10 +409,10 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $category1 = $this->getDataGenerator()->create_category(); $category2 = $this->getDataGenerator()->create_category(); - $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($category1->id)->id, 'name'=>'aaagrrryyy', 'idnumber'=>'','description'=>'')); - $cohort2 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($category1->id)->id, 'name'=>'bbb', 'idnumber'=>'', 'description'=>'yyybrrr')); - $cohort3 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($category2->id)->id, 'name'=>'ccc', 'idnumber'=>'xxarrrghyyy', 'description'=>'po_us')); - $cohort4 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_system::instance()->id)); + $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>\context_coursecat::instance($category1->id)->id, 'name'=>'aaagrrryyy', 'idnumber'=>'','description'=>'')); + $cohort2 = $this->getDataGenerator()->create_cohort(array('contextid'=>\context_coursecat::instance($category1->id)->id, 'name'=>'bbb', 'idnumber'=>'', 'description'=>'yyybrrr')); + $cohort3 = $this->getDataGenerator()->create_cohort(array('contextid'=>\context_coursecat::instance($category2->id)->id, 'name'=>'ccc', 'idnumber'=>'xxarrrghyyy', 'description'=>'po_us')); + $cohort4 = $this->getDataGenerator()->create_cohort(array('contextid'=>\context_system::instance()->id)); // Get list of all cohorts as admin. $this->setAdminUser(); @@ -437,7 +430,7 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { // Get list of all cohorts as manager who has capability everywhere. $user = $this->getDataGenerator()->create_user(); $managerrole = $DB->get_record('role', array('shortname' => 'manager')); - role_assign($managerrole->id, $user->id, context_system::instance()->id); + role_assign($managerrole->id, $user->id, \context_system::instance()->id); $this->setUser($user); $result = cohort_get_all_cohorts(0, 100, ''); @@ -451,7 +444,7 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $this->assertEquals(4, $result['allcohorts']); // Get list of all cohorts as manager who has capability everywhere except category2. - $context2 = context_coursecat::instance($category2->id); + $context2 = \context_coursecat::instance($category2->id); role_change_permission($managerrole->id, $context2, 'moodle/cohort:view', CAP_PROHIBIT); role_change_permission($managerrole->id, $context2, 'moodle/cohort:manage', CAP_PROHIBIT); $this->assertFalse(has_any_capability(array('moodle/cohort:view', 'moodle/cohort:manage'), $context2)); @@ -466,7 +459,7 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $this->assertEquals(array($cohort1->id=>$cohort1), $result['cohorts']); $this->assertEquals(3, $result['allcohorts']); - $result = cohort_get_cohorts(context_coursecat::instance($category1->id)->id, 1, 1, 'yyy'); + $result = cohort_get_cohorts(\context_coursecat::instance($category1->id)->id, 1, 1, 'yyy'); $this->assertEquals(2, $result['totalcohorts']); $this->assertEquals(array($cohort2->id=>$cohort2), $result['cohorts']); $this->assertEquals(2, $result['allcohorts']); @@ -483,11 +476,11 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $course1 = $this->getDataGenerator()->create_course(array('category' => $category1->id)); $course2 = $this->getDataGenerator()->create_course(array('category' => $category2->id)); - $category1ctx = context_coursecat::instance($category1->id); - $category2ctx = context_coursecat::instance($category2->id); - $course1ctx = context_course::instance(($course1->id)); - $course2ctx = context_course::instance(($course2->id)); - $systemctx = context_system::instance(); + $category1ctx = \context_coursecat::instance($category1->id); + $category2ctx = \context_coursecat::instance($category2->id); + $course1ctx = \context_course::instance(($course1->id)); + $course2ctx = \context_course::instance(($course2->id)); + $systemctx = \context_system::instance(); $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>$category1ctx->id, 'name'=>'aaagrrryyy', 'idnumber'=>'','description'=>'')); $cohort2 = $this->getDataGenerator()->create_cohort(array('contextid'=>$category1ctx->id, 'name'=>'bbb', 'idnumber'=>'', 'description'=>'yyybrrr', 'visible'=>0)); @@ -649,7 +642,7 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { // Assign user1 additional 'manager' role in the category context. He can now see hidden cohort in category1 // but still can not see hidden category in system. $managerrole = $DB->get_record('role', array('shortname' => 'manager')); - role_assign($managerrole->id, $user1->id, context_coursecat::instance($category1->id)); + role_assign($managerrole->id, $user1->id, \context_coursecat::instance($category1->id)); $this->setUser($user1); $result = cohort_get_available_cohorts($course1ctx, COHORT_ALL, 0, 0, ''); $this->assertEquals(array($cohort1->id, $cohort2->id, $cohort4->id), array_keys($result)); @@ -667,7 +660,7 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { set_config('allowcohortthemes', 1); set_config('theme', 'boost'); - $systemctx = context_system::instance(); + $systemctx = \context_system::instance(); $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid' => $systemctx->id, 'name' => 'test cohort 1', 'idnumber' => 'testid1', 'description' => 'test cohort desc', 'descriptionformat' => FORMAT_HTML, 'theme' => 'classic')); @@ -709,7 +702,7 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { set_config('allowcohortthemes', 1); set_config('theme', 'boost'); - $systemctx = context_system::instance(); + $systemctx = \context_system::instance(); $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid' => $systemctx->id, 'name' => 'test cohort 1', 'idnumber' => 'testid1', 'description' => 'test cohort desc', 'descriptionformat' => FORMAT_HTML, 'theme' => 'classic')); $id = cohort_add_cohort($cohort1); diff --git a/competency/tests/event_test.php b/competency/tests/event/events_test.php similarity index 97% rename from competency/tests/event_test.php rename to competency/tests/event/events_test.php index f54fd98b18f..3c916dfeb88 100644 --- a/competency/tests/event_test.php +++ b/competency/tests/event/events_test.php @@ -14,21 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Event tests. - * - * @package core_competency - * @copyright 2016 Serge Gauthier - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_competency\event; + +use core_competency\api; +use core_competency\plan; +use core_competency\url; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/comment/lib.php'); -use core_competency\api; -use core_competency\url; - /** * Event tests. * @@ -36,7 +31,7 @@ use core_competency\url; * @copyright 2016 Serge Gauthier * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_competency_event_testcase extends advanced_testcase { +class events_test extends \advanced_testcase { /** * Test the competency framework created event. @@ -501,7 +496,7 @@ class core_competency_event_testcase extends advanced_testcase { $sink = $this->redirectEvents(); api::create_plans_from_template_cohort($t1->get('id'), $c1->id); // Get our event event. - $plans = core_competency\plan::get_records(array('templateid' => $t1->get('id')), 'id'); + $plans = plan::get_records(array('templateid' => $t1->get('id')), 'id'); $events = $sink->get_events(); $this->assertCount(2, $events); $this->assertCount(2, $plans); @@ -713,7 +708,7 @@ class core_competency_event_testcase extends advanced_testcase { api::user_competency_viewed_in_plan($uc, $plan->get('id')); $this->fail('To log the user competency in completed plan ' . 'use user_competency_plan_viewed method.'); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertMatchesRegularExpression('/To log the user competency in completed plan ' . 'use user_competency_plan_viewed method./', $e->getMessage()); } @@ -749,7 +744,7 @@ class core_competency_event_testcase extends advanced_testcase { try { \core\event\competency_user_competency_viewed_in_plan::create($params)->trigger(); $this->fail('The \'competencyid\' and \'planid\' values must be set.'); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertMatchesRegularExpression("/The 'competencyid' and 'planid' values must be set./", $e->getMessage()); } @@ -758,7 +753,7 @@ class core_competency_event_testcase extends advanced_testcase { try { \core\event\competency_user_competency_viewed_in_plan::create($params)->trigger(); $this->fail('The \'competencyid\' value must be set.'); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertMatchesRegularExpression("/The 'competencyid' value must be set./", $e->getMessage()); } @@ -767,7 +762,7 @@ class core_competency_event_testcase extends advanced_testcase { try { \core\event\competency_user_competency_viewed_in_plan::create($params)->trigger(); $this->fail('The \'planid\' value must be set.'); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertMatchesRegularExpression("/The 'planid' value must be set./", $e->getMessage()); } } @@ -800,7 +795,7 @@ class core_competency_event_testcase extends advanced_testcase { // Check that the event data is valid. $this->assertInstanceOf('\core\event\competency_user_competency_viewed_in_course', $event); $this->assertEquals($ucc->get('id'), $event->objectid); - $this->assertEquals(context_course::instance($course->id)->id, $event->contextid); + $this->assertEquals(\context_course::instance($course->id)->id, $event->contextid); $this->assertEquals($ucc->get('userid'), $event->relateduserid); $this->assertEquals($course->id, $event->courseid); $this->assertEquals($c->get('id'), $event->other['competencyid']); @@ -819,17 +814,17 @@ class core_competency_event_testcase extends advanced_testcase { try { \core\event\competency_user_competency_viewed_in_course::create($params)->trigger(); $this->fail('The \'courseid\' value must be set.'); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertMatchesRegularExpression("/The 'courseid' value must be set./", $e->getMessage()); } - $params['contextid'] = context_course::instance($course->id)->id; + $params['contextid'] = \context_course::instance($course->id)->id; $params['courseid'] = $course->id; // Missing competencyid. try { \core\event\competency_user_competency_viewed_in_course::create($params)->trigger(); $this->fail('The \'competencyid\' value must be set.'); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertMatchesRegularExpression("/The 'competencyid' value must be set./", $e->getMessage()); } } @@ -858,7 +853,7 @@ class core_competency_event_testcase extends advanced_testcase { api::user_competency_plan_viewed($ucp); $this->fail('To log the user competency in non-completed plan ' . 'use user_competency_viewed_in_plan method.'); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertMatchesRegularExpression('/To log the user competency in non-completed plan ' . 'use user_competency_viewed_in_plan method./', $e->getMessage()); } @@ -896,7 +891,7 @@ class core_competency_event_testcase extends advanced_testcase { try { \core\event\competency_user_competency_plan_viewed::create($params)->trigger(); $this->fail('The \'competencyid\' and \'planid\' values must be set.'); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertMatchesRegularExpression("/The 'competencyid' and 'planid' values must be set./", $e->getMessage()); } @@ -905,7 +900,7 @@ class core_competency_event_testcase extends advanced_testcase { try { \core\event\competency_user_competency_plan_viewed::create($params)->trigger(); $this->fail('The \'competencyid\' value must be set.'); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertMatchesRegularExpression("/The 'competencyid' value must be set./", $e->getMessage()); } @@ -914,7 +909,7 @@ class core_competency_event_testcase extends advanced_testcase { try { \core\event\competency_user_competency_plan_viewed::create($params)->trigger(); $this->fail('The \'planid\' value must be set.'); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertMatchesRegularExpression("/The 'planid' value must be set./", $e->getMessage()); } } @@ -964,7 +959,7 @@ class core_competency_event_testcase extends advanced_testcase { try { \core\event\competency_user_competency_viewed::create($params)->trigger(); $this->fail('The \'competencyid\' value must be set.'); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertMatchesRegularExpression("/The 'competencyid' value must be set./", $e->getMessage()); } } @@ -1236,15 +1231,15 @@ class core_competency_event_testcase extends advanced_testcase { $user = $dg->create_user(); $this->setUser($user); $plan = $lpg->create_plan(array('userid' => $user->id)); - $context = context_user::instance($user->id); + $context = \context_user::instance($user->id); - $cmt = new stdClass(); + $cmt = new \stdClass(); $cmt->context = $context; $cmt->area = 'plan'; $cmt->itemid = $plan->get('id'); $cmt->component = 'competency'; $cmt->showcount = 1; - $manager = new comment($cmt); + $manager = new \comment($cmt); $manager->set_post_permission(true); // Triggering and capturing the event. @@ -1274,14 +1269,14 @@ class core_competency_event_testcase extends advanced_testcase { $user1 = $dg->create_user(); $plan = $lpg->create_plan(array('userid' => $user1->id)); - $context = context_user::instance($user1->id); + $context = \context_user::instance($user1->id); - $cmt = new stdClass(); + $cmt = new \stdClass(); $cmt->context = $context; $cmt->area = 'plan'; $cmt->itemid = $plan->get('id'); $cmt->component = 'competency'; - $manager = new comment($cmt); + $manager = new \comment($cmt); $newcomment = $manager->add("Comment to be deleted"); // Triggering and capturing the event. @@ -1307,7 +1302,7 @@ class core_competency_event_testcase extends advanced_testcase { $this->resetAfterTest(true); $dg = $this->getDataGenerator(); - $syscontext = context_system::instance(); + $syscontext = \context_system::instance(); // Create a student. $student = $dg->create_user(); @@ -1364,7 +1359,7 @@ class core_competency_event_testcase extends advanced_testcase { public function test_evidence_created_with_invalid_user_competency() { $this->resetAfterTest(true); $dg = $this->getDataGenerator(); - $syscontext = context_system::instance(); + $syscontext = \context_system::instance(); // Create students. $student = $dg->create_user(); @@ -1407,7 +1402,7 @@ class core_competency_event_testcase extends advanced_testcase { try { \core\event\competency_evidence_created::create($eventdata)->trigger(); $this->fail('Coding exception should have been thrown: ' . $errormsg); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString($errormsg, $e->getMessage()); } $eventdata['relateduserid'] = 1; @@ -1417,7 +1412,7 @@ class core_competency_event_testcase extends advanced_testcase { try { \core\event\competency_evidence_created::create($eventdata)->trigger(); $this->fail('Coding exception should have been thrown: ' . $errormsg); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString($errormsg, $e->getMessage()); } $eventdata['other']['usercompetencyid'] = 1; @@ -1427,7 +1422,7 @@ class core_competency_event_testcase extends advanced_testcase { try { \core\event\competency_evidence_created::create($eventdata)->trigger(); $this->fail('Coding exception should have been thrown: ' . $errormsg); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString($errormsg, $e->getMessage()); } $eventdata['other']['competencyid'] = 1; @@ -1437,7 +1432,7 @@ class core_competency_event_testcase extends advanced_testcase { try { \core\event\competency_evidence_created::create($eventdata)->trigger(); $this->fail('Coding exception should have been thrown: ' . $errormsg); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString($errormsg, $e->getMessage()); } $eventdata['other']['action'] = 1; @@ -1447,7 +1442,7 @@ class core_competency_event_testcase extends advanced_testcase { try { \core\event\competency_evidence_created::create($eventdata)->trigger(); $this->fail('Coding exception should have been thrown: ' . $errormsg); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertStringContainsString($errormsg, $e->getMessage()); } $eventdata['other']['recommend'] = 1; @@ -1553,7 +1548,7 @@ class core_competency_event_testcase extends advanced_testcase { // Check that the event data is valid. $this->assertInstanceOf('\core\event\competency_evidence_created', $evidencecreatedevent); $this->assertInstanceOf('\core\event\competency_user_competency_rated_in_course', $event); - $this->assertEquals(context_course::instance($course->id)->id, $event->contextid); + $this->assertEquals(\context_course::instance($course->id)->id, $event->contextid); $this->assertEquals($course->id, $event->courseid); $this->assertEquals($uc->get('userid'), $event->relateduserid); $this->assertEquals($uc->get('competencyid'), $event->other['competencyid']); @@ -1630,14 +1625,14 @@ class core_competency_event_testcase extends advanced_testcase { 'competencyid' => $c->get('id') )); - $context = context_user::instance($user->id); - $cmt = new stdClass(); + $context = \context_user::instance($user->id); + $cmt = new \stdClass(); $cmt->context = $context; $cmt->area = 'user_competency'; $cmt->itemid = $uc->get('id'); $cmt->component = 'competency'; $cmt->showcount = 1; - $manager = new comment($cmt); + $manager = new \comment($cmt); // Triggering and capturing the event. $sink = $this->redirectEvents(); @@ -1670,14 +1665,14 @@ class core_competency_event_testcase extends advanced_testcase { 'userid' => $user->id, 'competencyid' => $c->get('id') )); - $context = context_user::instance($user->id); + $context = \context_user::instance($user->id); - $cmt = new stdClass(); + $cmt = new \stdClass(); $cmt->context = $context; $cmt->area = 'user_competency'; $cmt->itemid = $uc->get('id'); $cmt->component = 'competency'; - $manager = new comment($cmt); + $manager = new \comment($cmt); $newcomment = $manager->add("Comment to be deleted"); // Triggering and capturing the event. diff --git a/competency/tests/plan_test.php b/competency/tests/plan_test.php index 191a0b041aa..b71e0d9d826 100644 --- a/competency/tests/plan_test.php +++ b/competency/tests/plan_test.php @@ -14,19 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Plan persistent class tests. - * - * @package core_competency - * @copyright 2015 Frédéric Massart - FMCorz.net - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); -global $CFG; - -use core_competency\api; -use core_competency\plan; +namespace core_competency; /** * Plan persistent testcase. @@ -35,7 +23,7 @@ use core_competency\plan; * @copyright 2015 Frédéric Massart - FMCorz.net * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_competency_plan_testcase extends advanced_testcase { +class plan_test extends \advanced_testcase { public function test_can_manage_user() { $this->resetAfterTest(true); @@ -47,10 +35,10 @@ class core_competency_plan_testcase extends advanced_testcase { $u2 = $this->getDataGenerator()->create_user(); $u3 = $this->getDataGenerator()->create_user(); - $syscontext = context_system::instance(); - $u1context = context_user::instance($u1->id); - $u2context = context_user::instance($u2->id); - $u3context = context_user::instance($u3->id); + $syscontext = \context_system::instance(); + $u1context = \context_user::instance($u1->id); + $u2context = \context_user::instance($u2->id); + $u3context = \context_user::instance($u3->id); assign_capability('moodle/competency:planmanage', CAP_ALLOW, $manage, $syscontext->id); assign_capability('moodle/competency:planmanageown', CAP_ALLOW, $manageown, $u2context->id); @@ -90,12 +78,12 @@ class core_competency_plan_testcase extends advanced_testcase { $u4 = $this->getDataGenerator()->create_user(); $u5 = $this->getDataGenerator()->create_user(); - $syscontext = context_system::instance(); - $u1context = context_user::instance($u1->id); - $u2context = context_user::instance($u2->id); - $u3context = context_user::instance($u3->id); - $u4context = context_user::instance($u4->id); - $u5context = context_user::instance($u5->id); + $syscontext = \context_system::instance(); + $u1context = \context_user::instance($u1->id); + $u2context = \context_user::instance($u2->id); + $u3context = \context_user::instance($u3->id); + $u4context = \context_user::instance($u4->id); + $u5context = \context_user::instance($u5->id); assign_capability('moodle/competency:planmanage', CAP_ALLOW, $manage, $syscontext->id); assign_capability('moodle/competency:planmanageown', CAP_ALLOW, $manageown, $syscontext->id); @@ -155,10 +143,10 @@ class core_competency_plan_testcase extends advanced_testcase { $u2 = $this->getDataGenerator()->create_user(); $u3 = $this->getDataGenerator()->create_user(); - $syscontext = context_system::instance(); - $u1context = context_user::instance($u1->id); - $u2context = context_user::instance($u2->id); - $u3context = context_user::instance($u3->id); + $syscontext = \context_system::instance(); + $u1context = \context_user::instance($u1->id); + $u2context = \context_user::instance($u2->id); + $u3context = \context_user::instance($u3->id); assign_capability('moodle/competency:planview', CAP_ALLOW, $read, $syscontext->id); assign_capability('moodle/competency:planviewown', CAP_ALLOW, $readown, $u2context->id); @@ -198,12 +186,12 @@ class core_competency_plan_testcase extends advanced_testcase { $u4 = $this->getDataGenerator()->create_user(); $u5 = $this->getDataGenerator()->create_user(); - $syscontext = context_system::instance(); - $u1context = context_user::instance($u1->id); - $u2context = context_user::instance($u2->id); - $u3context = context_user::instance($u3->id); - $u4context = context_user::instance($u4->id); - $u5context = context_user::instance($u5->id); + $syscontext = \context_system::instance(); + $u1context = \context_user::instance($u1->id); + $u2context = \context_user::instance($u2->id); + $u3context = \context_user::instance($u3->id); + $u4context = \context_user::instance($u4->id); + $u5context = \context_user::instance($u5->id); assign_capability('moodle/competency:planview', CAP_ALLOW, $read, $syscontext->id); assign_capability('moodle/competency:planviewown', CAP_ALLOW, $readown, $syscontext->id); @@ -268,28 +256,28 @@ class core_competency_plan_testcase extends advanced_testcase { // Ignore duedate validation on create/update draft plan. $plan = $lpg->create_plan($record); - $this->assertInstanceOf('core_competency\plan', $plan); + $this->assertInstanceOf(plan::class, $plan); // Passing from draft to active. $plan->set('status', plan::STATUS_ACTIVE); // Draft to active with duedate in the past. $expected = array( - 'duedate' => new lang_string('errorcannotsetduedateinthepast', 'core_competency'), + 'duedate' => new \lang_string('errorcannotsetduedateinthepast', 'core_competency'), ); $this->assertEquals($expected, $plan->validate()); // Draft to active: past date => past date(fail). $plan->set('duedate', time() - 100); $expected = array( - 'duedate' => new lang_string('errorcannotsetduedateinthepast', 'core_competency'), + 'duedate' => new \lang_string('errorcannotsetduedateinthepast', 'core_competency'), ); $this->assertEquals($expected, $plan->validate()); // Draft to active: past date => too soon (fail). $plan->set('duedate', time() + 100); $expected = array( - 'duedate' => new lang_string('errorcannotsetduedatetoosoon', 'core_competency'), + 'duedate' => new \lang_string('errorcannotsetduedatetoosoon', 'core_competency'), ); $this->assertEquals($expected, $plan->validate()); @@ -324,14 +312,14 @@ class core_competency_plan_testcase extends advanced_testcase { // Active to active: unset date => past date(fail). $plan->set('duedate', time() - 100); $expected = array( - 'duedate' => new lang_string('errorcannotsetduedateinthepast', 'core_competency'), + 'duedate' => new \lang_string('errorcannotsetduedateinthepast', 'core_competency'), ); $this->assertEquals($expected, $plan->validate()); // Active to active: unset date => too soon (fail). $plan->set('duedate', time() + 100); $expected = array( - 'duedate' => new lang_string('errorcannotsetduedatetoosoon', 'core_competency'), + 'duedate' => new \lang_string('errorcannotsetduedatetoosoon', 'core_competency'), ); $this->assertEquals($expected, $plan->validate()); @@ -353,14 +341,14 @@ class core_competency_plan_testcase extends advanced_testcase { // Active to active: future date => past date(fail). $plan->set('duedate', time() - 100); $expected = array( - 'duedate' => new lang_string('errorcannotsetduedateinthepast', 'core_competency'), + 'duedate' => new \lang_string('errorcannotsetduedateinthepast', 'core_competency'), ); $this->assertEquals($expected, $plan->validate()); // Active to active: future date => too soon (fail). $plan->set('duedate', time() + 100); $expected = array( - 'duedate' => new lang_string('errorcannotsetduedatetoosoon', 'core_competency'), + 'duedate' => new \lang_string('errorcannotsetduedatetoosoon', 'core_competency'), ); $this->assertEquals($expected, $plan->validate()); @@ -374,7 +362,7 @@ class core_competency_plan_testcase extends advanced_testcase { $record->duedate = time() - 200; $DB->update_record(plan::TABLE, $record); - $success = core_competency\api::complete_plan($plan->get('id')); + $success = api::complete_plan($plan->get('id')); $this->assertTrue($success); // Completing plan: with due date too soon (pass). @@ -383,7 +371,7 @@ class core_competency_plan_testcase extends advanced_testcase { $record->duedate = time() + 200; $DB->update_record(plan::TABLE, $record); - $success = core_competency\api::complete_plan($plan->get('id')); + $success = api::complete_plan($plan->get('id')); $this->assertTrue($success); // Completing plan: with due date in the future (pass). @@ -392,7 +380,7 @@ class core_competency_plan_testcase extends advanced_testcase { $record->duedate = time() + plan::DUEDATE_THRESHOLD + 10; $DB->update_record(plan::TABLE, $record); - $success = core_competency\api::complete_plan($plan->get('id')); + $success = api::complete_plan($plan->get('id')); $this->assertTrue($success); // Completing plan: with due date unset (pass). @@ -401,7 +389,7 @@ class core_competency_plan_testcase extends advanced_testcase { $record->duedate = 0; $DB->update_record(plan::TABLE, $record); - $success = core_competency\api::complete_plan($plan->get('id')); + $success = api::complete_plan($plan->get('id')); $this->assertTrue($success); // Reopening plan: with due date in the past => duedate unset. @@ -410,7 +398,7 @@ class core_competency_plan_testcase extends advanced_testcase { $record->duedate = time() - 200; $DB->update_record(plan::TABLE, $record); - $success = core_competency\api::reopen_plan($plan->get('id')); + $success = api::reopen_plan($plan->get('id')); $this->assertTrue($success); $plan->read(); $this->assertEquals(0, $plan->get('duedate')); @@ -421,7 +409,7 @@ class core_competency_plan_testcase extends advanced_testcase { $record->duedate = time() + 100; $DB->update_record(plan::TABLE, $record); - $success = core_competency\api::reopen_plan($plan->get('id')); + $success = api::reopen_plan($plan->get('id')); $this->assertTrue($success); $plan->read(); $this->assertEquals(0, $plan->get('duedate')); @@ -433,7 +421,7 @@ class core_competency_plan_testcase extends advanced_testcase { $record->duedate = $duedate; $DB->update_record(plan::TABLE, $record); - $success = core_competency\api::reopen_plan($plan->get('id')); + $success = api::reopen_plan($plan->get('id')); $this->assertTrue($success); $plan->read(); diff --git a/competency/tests/task_test.php b/competency/tests/task/task_test.php similarity index 90% rename from competency/tests/task_test.php rename to competency/tests/task/task_test.php index d36b92691a9..cbca259d5a9 100644 --- a/competency/tests/task_test.php +++ b/competency/tests/task/task_test.php @@ -14,18 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Task tests. - * - * @package core_competency - * @copyright 2015 Issam Taboubi - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); +namespace core_competency\task; use core_competency\api; use core_competency\plan; +use core_competency\template; /** * Task tests. @@ -34,7 +27,7 @@ use core_competency\plan; * @copyright 2015 Issam Taboubi * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_competency_task_testcase extends advanced_testcase { +class task_test extends \advanced_testcase { public function test_sync_plans_from_cohorts_task() { global $DB; @@ -46,8 +39,8 @@ class core_competency_task_testcase extends advanced_testcase { // Sql to simulate the execution in time. $cmsql = "UPDATE {cohort_members} SET timeadded = :currenttime WHERE cohortid = :cohortid AND userid = :userid"; - $tplsql = "UPDATE {" . \core_competency\template::TABLE . "} SET timemodified = :currenttime WHERE id = :templateid"; - $plansql = "UPDATE {" . \core_competency\plan::TABLE . "} SET timemodified = :currenttime WHERE id = :planid"; + $tplsql = "UPDATE {" . template::TABLE . "} SET timemodified = :currenttime WHERE id = :templateid"; + $plansql = "UPDATE {" . plan::TABLE . "} SET timemodified = :currenttime WHERE id = :planid"; $currenttime = time(); @@ -122,7 +115,7 @@ class core_competency_task_testcase extends advanced_testcase { // Let's unlink the plan and run the task again, it should not be recreated. $currenttime = $currenttime + 1; $plan = plan::get_record(array('userid' => $user5->id, 'templateid' => $tpl->get('id'))); - \core_competency\api::unlink_plan_from_template($plan); + api::unlink_plan_from_template($plan); $DB->execute($plansql, array('currenttime' => $currenttime, 'planid' => $plan->get('id'))); $this->assertTrue(plan::record_exists_select('userid = ?', array($user5->id))); $this->assertFalse(plan::record_exists_select('userid = ? AND templateid = ?', array($user5->id, $tpl->get('id')))); @@ -149,7 +142,7 @@ class core_competency_task_testcase extends advanced_testcase { // Test a user plan deleted will not be recreated. $currenttime = $currenttime + 1; $plan = plan::get_record(array('userid' => $user4->id, 'templateid' => $tpl->get('id'))); - \core_competency\api::delete_plan($plan->get('id')); + api::delete_plan($plan->get('id')); $currenttime = $currenttime + 1; $task->execute(); $task->set_last_run_time($currenttime); @@ -218,7 +211,7 @@ class core_competency_task_testcase extends advanced_testcase { // Let's unlink the plan and run the task again, it should not be recreated. $plan = plan::get_record(array('userid' => $user5->id, 'templateid' => $tpl->get('id'))); - \core_competency\api::unlink_plan_from_template($plan); + api::unlink_plan_from_template($plan); $this->assertTrue(plan::record_exists_select('userid = ?', array($user5->id))); $this->assertFalse(plan::record_exists_select('userid = ? AND templateid = ?', array($user5->id, $tpl->get('id')))); $this->assertEquals(4, plan::count_records(array('templateid' => $tpl->get('id')))); @@ -255,22 +248,22 @@ class core_competency_task_testcase extends advanced_testcase { // Creating plans from template cohort. $task->execute(); - $this->assertEquals(1, \core_competency\plan::count_records()); + $this->assertEquals(1, plan::count_records()); // Now add another user, but this time the template will be expired. cohort_add_member($cohort->id, $user2->id); $record = $tpl->to_record(); $record->duedate = time() - 10000; - $DB->update_record(\core_competency\template::TABLE, $record); + $DB->update_record(template::TABLE, $record); $tpl->read(); $task->execute(); - $this->assertEquals(1, \core_competency\plan::count_records()); // Still only one plan. + $this->assertEquals(1, plan::count_records()); // Still only one plan. // Pretend it wasn't expired. $tpl->set('duedate', time() + 100); $tpl->update(); $task->execute(); - $this->assertEquals(2, \core_competency\plan::count_records()); // Now there is two. + $this->assertEquals(2, plan::count_records()); // Now there is two. } public function test_complete_plans_task() { @@ -283,9 +276,9 @@ class core_competency_task_testcase extends advanced_testcase { $user = $dg->create_user(); $up1 = $lpg->create_plan(array('userid' => $user->id, - 'status' => \core_competency\plan::STATUS_DRAFT)); + 'status' => plan::STATUS_DRAFT)); $up2 = $lpg->create_plan(array('userid' => $user->id, - 'status' => \core_competency\plan::STATUS_ACTIVE)); + 'status' => plan::STATUS_ACTIVE)); // Set duedate in the past. $date = new \DateTime('yesterday'); $record1 = $up1->to_record(); @@ -303,12 +296,12 @@ class core_competency_task_testcase extends advanced_testcase { $task->execute(); $plandraft = api::read_plan($up1->get('id')); - $this->assertEquals(\core_competency\plan::STATUS_DRAFT, $plandraft->get('status')); + $this->assertEquals(plan::STATUS_DRAFT, $plandraft->get('status')); // Test that active plan can be completed on running task. $task->execute(); $planactive = api::read_plan($up2->get('id')); - $this->assertEquals(\core_competency\plan::STATUS_COMPLETE, $planactive->get('status')); + $this->assertEquals(plan::STATUS_COMPLETE, $planactive->get('status')); } } diff --git a/competency/tests/template_test.php b/competency/tests/template_test.php index 5ac64e0f26f..6087ca7fb25 100644 --- a/competency/tests/template_test.php +++ b/competency/tests/template_test.php @@ -14,18 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Template persistent class tests. - * - * @package core_competency - * @copyright 2016 Frédéric Massart - FMCorz.net - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); -global $CFG; - -use core_competency\template; +namespace core_competency; /** * Template persistent testcase. @@ -34,7 +23,7 @@ use core_competency\template; * @copyright 2016 Frédéric Massart - FMCorz.net * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_competency_template_testcase extends advanced_testcase { +class template_test extends \advanced_testcase { public function test_validate_duedate() { global $DB; diff --git a/completion/tests/progress_test.php b/completion/tests/progress_test.php index 2ea3061a0f8..08785fa3b25 100644 --- a/completion/tests/progress_test.php +++ b/completion/tests/progress_test.php @@ -14,16 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Test completion progress API. - * - * @package core_completion - * @category test - * @copyright 2017 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_completion; -defined('MOODLE_INTERNAL') || die(); +use completion_completion; /** * Test completion progress API. @@ -33,7 +26,7 @@ defined('MOODLE_INTERNAL') || die(); * @copyright 2017 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_completion_progress_testcase extends advanced_testcase { +class progress_test extends \advanced_testcase { /** * Test setup. @@ -75,7 +68,7 @@ class core_completion_progress_testcase extends advanced_testcase { // Mark two of them as completed for a user. $cmassign = get_coursemodule_from_id('assign', $assign->cmid); $cmdata = get_coursemodule_from_id('data', $data->cmid); - $completion = new completion_info($course); + $completion = new \completion_info($course); $completion->update_state($cmassign, COMPLETION_COMPLETE, $user->id); $completion->update_state($cmdata, COMPLETION_COMPLETE, $user->id); @@ -114,7 +107,7 @@ class core_completion_progress_testcase extends advanced_testcase { // Mark two of them as completed for a user. $cmassign = get_coursemodule_from_id('assign', $assign->cmid); $cmdata = get_coursemodule_from_id('data', $data->cmid); - $completion = new completion_info($course); + $completion = new \completion_info($course); $completion->update_state($cmassign, COMPLETION_COMPLETE, $user->id); $completion->update_state($cmdata, COMPLETION_COMPLETE, $user->id); diff --git a/course/format/weeks/tests/observer_test.php b/course/format/weeks/tests/observer_test.php index 5d833b12664..4ab42703a63 100644 --- a/course/format/weeks/tests/observer_test.php +++ b/course/format/weeks/tests/observer_test.php @@ -14,15 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the event observers used by the weeks course format. - * - * @package format_weeks - * @copyright 2017 Mark Nelson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); +namespace format_weeks; /** * Unit tests for the event observers used by the weeks course format. @@ -31,7 +23,7 @@ defined('MOODLE_INTERNAL') || die(); * @copyright 2017 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class format_weeks_observer_testcase extends advanced_testcase { +class observer_test extends \advanced_testcase { /** * Test setup. diff --git a/course/tests/indicators_test.php b/course/tests/analytics/indicators_test.php similarity index 95% rename from course/tests/indicators_test.php rename to course/tests/analytics/indicators_test.php index 3ad47f95e89..7a1baab8bf1 100644 --- a/course/tests/indicators_test.php +++ b/course/tests/analytics/indicators_test.php @@ -14,31 +14,24 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for core_course indicators. - * - * @package core_course - * @category analytics - * @copyright 2017 David Monllaó {@link http://www.davidmonllao.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_course\analytics; defined('MOODLE_INTERNAL') || die(); global $CFG; -require_once(__DIR__ . '/../../lib/completionlib.php'); -require_once(__DIR__ . '/../../completion/criteria/completion_criteria_self.php'); -require_once(__DIR__ . '/../../analytics/tests/fixtures/test_target_course_users.php'); +require_once(__DIR__ . '/../../../lib/completionlib.php'); +require_once(__DIR__ . '/../../../completion/criteria/completion_criteria_self.php'); +require_once(__DIR__ . '/../../../analytics/tests/fixtures/test_target_course_users.php'); /** * Unit tests for core_course indicators. * * @package core_course - * @category analytics + * @category test * @copyright 2017 David Monllaó {@link http://www.davidmonllao.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_course_indicators_testcase extends advanced_testcase { +class indicators_test extends \advanced_testcase { /** * test_no_teacher @@ -94,10 +87,10 @@ class core_course_indicators_testcase extends advanced_testcase { $course3 = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); // Criteria only for the last one. - $criteriadata = new stdClass(); + $criteriadata = new \stdClass(); $criteriadata->id = $course3->id; $criteriadata->criteria_self = 1; - $criterion = new completion_criteria_self(); + $criterion = new \completion_criteria_self(); $criterion->update_config($criteriadata); $indicator = new \core_course\analytics\indicator\completion_enabled(); diff --git a/course/tests/restore_test.php b/course/tests/backup/restore_test.php similarity index 98% rename from course/tests/restore_test.php rename to course/tests/backup/restore_test.php index 4f659902ffb..17f6000f17d 100644 --- a/course/tests/restore_test.php +++ b/course/tests/backup/restore_test.php @@ -14,13 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Course restore tests. - * - * @package core_course - * @copyright 2016 Frédéric Massart - FMCorz.net - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_course\backup; + +use backup; +use backup_controller; +use restore_controller; +use restore_dbops; defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -35,7 +34,7 @@ require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php'); * @copyright 2016 Frédéric Massart - FMCorz.net * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_course_restore_testcase extends advanced_testcase { +class restore_test extends \advanced_testcase { /** * Backup a course and return its backup ID. @@ -72,7 +71,7 @@ class core_course_restore_testcase extends advanced_testcase { $dg = $this->getDataGenerator(); $roleid = $dg->create_role(); foreach ($caps as $cap) { - assign_capability($cap, $perm, $roleid, context_system::instance()->id, true); + assign_capability($cap, $perm, $roleid, \context_system::instance()->id, true); } accesslib_clear_all_caches_for_unit_testing(); return $roleid; diff --git a/course/tests/customfield_test.php b/course/tests/customfield_test.php index 64d5ba00460..ff0f5cb85cc 100644 --- a/course/tests/customfield_test.php +++ b/course/tests/customfield_test.php @@ -14,13 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Tests for customfields in courses - * - * @package core_course - * @copyright 2018 Marina Glancy - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_course; defined('MOODLE_INTERNAL') || die(); @@ -35,7 +29,7 @@ require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php'); * @copyright 2018 Marina Glancy * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_course_customfield_testcase extends advanced_testcase { +class customfield_test extends \advanced_testcase { /** * Set up @@ -96,8 +90,8 @@ class core_course_customfield_testcase extends advanced_testcase { $backuptempdir = make_backup_temp_directory(''); $packer = get_file_packer('application/vnd.moodle.backup'); - $bc = new backup_controller(backup::TYPE_1COURSE, $courseid, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, - backup::MODE_GENERAL, $userid); + $bc = new \backup_controller(\backup::TYPE_1COURSE, $courseid, \backup::FORMAT_MOODLE, \backup::INTERACTIVE_NO, + \backup::MODE_GENERAL, $userid); $bc->execute_plan(); $results = $bc->get_results(); @@ -119,15 +113,15 @@ class core_course_customfield_testcase extends advanced_testcase { protected function restore_course($backupid, $courseid, $userid) { global $DB; - $target = backup::TARGET_CURRENT_ADDING; + $target = \backup::TARGET_CURRENT_ADDING; if (!$courseid) { - $target = backup::TARGET_NEW_COURSE; + $target = \backup::TARGET_NEW_COURSE; $categoryid = $DB->get_field_sql("SELECT MIN(id) FROM {course_categories}"); - $courseid = restore_dbops::create_new_course('Tmp', 'tmp', $categoryid); + $courseid = \restore_dbops::create_new_course('Tmp', 'tmp', $categoryid); } - $rc = new restore_controller($backupid, $courseid, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $userid, $target); - $target == backup::TARGET_NEW_COURSE ?: $rc->get_plan()->get_setting('overwrite_conf')->set_value(true); + $rc = new \restore_controller($backupid, $courseid, \backup::INTERACTIVE_NO, \backup::MODE_GENERAL, $userid, $target); + $target == \backup::TARGET_NEW_COURSE ?: $rc->get_plan()->get_setting('overwrite_conf')->set_value(true); $this->assertTrue($rc->execute_precheck()); $rc->execute_plan(); diff --git a/enrol/cohort/tests/cohortlib_test.php b/enrol/cohort/tests/lib_test.php similarity index 91% rename from enrol/cohort/tests/cohortlib_test.php rename to enrol/cohort/tests/lib_test.php index 080f0dd84a4..8bead87fced 100644 --- a/enrol/cohort/tests/cohortlib_test.php +++ b/enrol/cohort/tests/lib_test.php @@ -14,14 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Cohort enrolment sync functional test. - * - * @package enrol_cohort - * @category test - * @copyright 2015 Adrian Greeve - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace enrol_cohort; defined('MOODLE_INTERNAL') || die(); @@ -33,10 +26,11 @@ require_once($CFG->dirroot.'/group/lib.php'); * Contains tests for the cohort library. * * @package enrol_cohort + * @category test * @copyright 2015 Adrian Greeve * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class enrol_cohort_lib_testcase extends advanced_testcase { +class lib_test extends \advanced_testcase { /** * Test that a new group with the name of the cohort is created. @@ -50,7 +44,7 @@ class enrol_cohort_lib_testcase extends advanced_testcase { $course = $this->getDataGenerator()->create_course(array('category' => $category->id)); $course2 = $this->getDataGenerator()->create_course(array('category' => $category->id)); // Create a cohort. - $cohort = $this->getDataGenerator()->create_cohort(array('context' => context_coursecat::instance($category->id)->id)); + $cohort = $this->getDataGenerator()->create_cohort(array('context' => \context_coursecat::instance($category->id)->id)); // Run the function. $groupid = enrol_cohort_create_new_group($course->id, $cohort->id); // Check the results. @@ -61,7 +55,7 @@ class enrol_cohort_lib_testcase extends advanced_testcase { $this->assertEquals($course->id, $group->courseid); // Create a group that will have the same name as the cohort. - $groupdata = new stdClass(); + $groupdata = new \stdClass(); $groupdata->courseid = $course2->id; $groupdata->name = $cohort->name . ' cohort'; groups_create_group($groupdata); @@ -72,7 +66,7 @@ class enrol_cohort_lib_testcase extends advanced_testcase { $this->assertEquals($cohort->name . ' cohort (2)', $groupinfo->name); // Create another group that will have the same name as a generated cohort. - $groupdata = new stdClass(); + $groupdata = new \stdClass(); $groupdata->courseid = $course2->id; $groupdata->name = $cohort->name . ' cohort (2)'; groups_create_group($groupdata); @@ -117,7 +111,7 @@ class enrol_cohort_lib_testcase extends advanced_testcase { // Teachers don't have enrol/cohort:unenrol capability by default. Login as admin for simplicity. $this->setAdminUser(); require_once($CFG->dirroot . '/enrol/locallib.php'); - $manager = new course_enrolment_manager($PAGE, $course); + $manager = new \course_enrolment_manager($PAGE, $course); $userenrolments = $manager->get_user_enrolments($student->id); $this->assertCount(1, $userenrolments); diff --git a/enrol/cohort/tests/sync_test.php b/enrol/cohort/tests/sync_test.php index 668f59af5e6..3d914496365 100644 --- a/enrol/cohort/tests/sync_test.php +++ b/enrol/cohort/tests/sync_test.php @@ -14,14 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Cohort enrolment sync functional test. - * - * @package enrol_cohort - * @category phpunit - * @copyright 2012 Petr Skoda {@link http://skodak.org} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace enrol_cohort; defined('MOODLE_INTERNAL') || die(); @@ -30,7 +23,15 @@ require_once($CFG->dirroot.'/enrol/cohort/locallib.php'); require_once($CFG->dirroot.'/cohort/lib.php'); require_once($CFG->dirroot.'/group/lib.php'); -class enrol_cohort_testcase extends advanced_testcase { +/** + * Cohort enrolment sync functional test. + * + * @package enrol_cohort + * @category test + * @copyright 2012 Petr Skoda {@link http://skodak.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class sync_test extends \advanced_testcase { protected function enable_plugin() { $enabled = enrol_get_plugins(true); @@ -50,7 +51,7 @@ class enrol_cohort_testcase extends advanced_testcase { global $DB; $this->resetAfterTest(); - $trace = new null_progress_trace(); + $trace = new \null_progress_trace(); // Setup a few courses and categories. @@ -78,8 +79,8 @@ class enrol_cohort_testcase extends advanced_testcase { $user3 = $this->getDataGenerator()->create_user(); $user4 = $this->getDataGenerator()->create_user(); - $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($cat1->id)->id)); - $cohort2 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($cat2->id)->id)); + $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>\context_coursecat::instance($cat1->id)->id)); + $cohort2 = $this->getDataGenerator()->create_cohort(array('contextid'=>\context_coursecat::instance($cat2->id)->id)); $cohort3 = $this->getDataGenerator()->create_cohort(); $this->enable_plugin(); @@ -112,9 +113,9 @@ class enrol_cohort_testcase extends advanced_testcase { $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance1->id, 'userid'=>$user2->id))); $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance1->id, 'userid'=>$user4->id))); $this->assertEquals(5, $DB->count_records('role_assignments', array())); - $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); - $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); - $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); + $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); + $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); + $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); cohort_add_member($cohort2->id, $user3->id); $this->assertEquals(7, $DB->count_records('user_enrolments', array())); @@ -122,8 +123,8 @@ class enrol_cohort_testcase extends advanced_testcase { $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance3->id, 'userid'=>$user3->id))); $this->assertFalse($DB->record_exists('user_enrolments', array('enrolid' => $cohortinstance4->id, 'userid' => $user3->id))); $this->assertEquals(7, $DB->count_records('role_assignments', array())); - $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id))); - $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course2->id)->id, 'userid'=>$user3->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance3->id))); + $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id))); + $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course2->id)->id, 'userid'=>$user3->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance3->id))); cohort_add_member($cohort3->id, $user3->id); $this->assertEquals(7, $DB->count_records('user_enrolments', array())); @@ -138,15 +139,15 @@ class enrol_cohort_testcase extends advanced_testcase { cohort_remove_member($cohort1->id, $user4->id); $this->assertEquals(7, $DB->count_records('user_enrolments', array())); $this->assertEquals(5, $DB->count_records('role_assignments', array())); - $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); - $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); + $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); + $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); cohort_add_member($cohort1->id, $user2->id); cohort_add_member($cohort1->id, $user4->id); $this->assertEquals(7, $DB->count_records('user_enrolments', array())); $this->assertEquals(7, $DB->count_records('role_assignments', array())); - $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); - $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); + $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); + $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); $cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_UNENROL); cohort_remove_member($cohort1->id, $user2->id); @@ -154,18 +155,14 @@ class enrol_cohort_testcase extends advanced_testcase { $this->assertEquals(5, $DB->count_records('user_enrolments', array())); $this->assertFalse($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance1->id, 'userid'=>$user2->id))); $this->assertFalse($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance1->id, 'userid'=>$user4->id))); - $this->assertEquals(5, $DB->count_records('role_assignments', array())); - $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); - $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); cohort_remove_member($cohort2->id, $user3->id); $this->assertEquals(3, $DB->count_records('user_enrolments', array())); $this->assertFalse($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance2->id, 'userid'=>$user3->id))); $this->assertFalse($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance3->id, 'userid'=>$user3->id))); $this->assertEquals(3, $DB->count_records('role_assignments', array())); - $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id))); - $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course2->id)->id, 'userid'=>$user3->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance3->id))); - + $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id))); + $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course2->id)->id, 'userid'=>$user3->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance3->id))); // Test cohort deleting. @@ -206,14 +203,14 @@ class enrol_cohort_testcase extends advanced_testcase { $id = groups_create_group((object)array('name'=>'Group 2', 'courseid'=>$course1->id)); $group2 = $DB->get_record('groups', array('id'=>$id), '*', MUST_EXIST); - $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($cat1->id)->id)); + $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>\context_coursecat::instance($cat1->id)->id)); $id = $cohortplugin->add_instance($course1, array('customint1'=>$cohort1->id, 'roleid'=>$studentrole->id, 'customint2'=>$group1->id)); $cohortinstance1 = $DB->get_record('enrol', array('id'=>$id)); $this->assertEquals(3, $DB->count_records('user_enrolments', array())); $this->assertEquals(2, $DB->count_records('role_assignments', array())); - $this->assertTrue(is_enrolled(context_course::instance($course1->id), $user4)); + $this->assertTrue(is_enrolled(\context_course::instance($course1->id), $user4)); $this->assertTrue(groups_add_member($group1, $user4)); $this->assertTrue(groups_add_member($group2, $user4)); @@ -267,7 +264,7 @@ class enrol_cohort_testcase extends advanced_testcase { global $DB; $this->resetAfterTest(); - $trace = new null_progress_trace(); + $trace = new \null_progress_trace(); // Setup a few courses and categories. @@ -295,8 +292,8 @@ class enrol_cohort_testcase extends advanced_testcase { $user3 = $this->getDataGenerator()->create_user(); $user4 = $this->getDataGenerator()->create_user(); - $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($cat1->id)->id)); - $cohort2 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($cat2->id)->id)); + $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>\context_coursecat::instance($cat1->id)->id)); + $cohort2 = $this->getDataGenerator()->create_cohort(array('contextid'=>\context_coursecat::instance($cat2->id)->id)); $cohort3 = $this->getDataGenerator()->create_cohort(); $this->disable_plugin(); // Prevents event sync. @@ -351,17 +348,17 @@ class enrol_cohort_testcase extends advanced_testcase { $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance2->id, 'userid'=>$user3->id))); $this->assertFalse($DB->record_exists('user_enrolments', array('enrolid' => $cohortinstance4->id, 'userid' => $user3->id))); $this->assertEquals(7, $DB->count_records('role_assignments', array())); - $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); - $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); - $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); - $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id))); + $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); + $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); + $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); + $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id))); $cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES); $DB->delete_records('cohort_members', array('cohortid'=>$cohort2->id, 'userid'=>$user3->id)); // Use low level DB api to prevent events! enrol_cohort_sync($trace, $course1->id); $this->assertEquals(7, $DB->count_records('user_enrolments', array())); $this->assertEquals(6, $DB->count_records('role_assignments', array())); - $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id))); + $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id))); $cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_UNENROL); $DB->delete_records('cohort_members', array('cohortid'=>$cohort1->id, 'userid'=>$user1->id)); // Use low level DB api to prevent events! @@ -370,8 +367,8 @@ class enrol_cohort_testcase extends advanced_testcase { $this->assertFalse($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance2->id, 'userid'=>$user3->id))); $this->assertFalse($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance1->id, 'userid'=>$user1->id))); $this->assertEquals(5, $DB->count_records('role_assignments', array())); - $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id))); - $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); + $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id))); + $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); $cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES); $DB->delete_records('cohort_members', array('cohortid'=>$cohort1->id)); // Use low level DB api to prevent events! @@ -399,11 +396,11 @@ class enrol_cohort_testcase extends advanced_testcase { $id = groups_create_group((object)array('name'=>'Group 2', 'courseid'=>$course1->id)); $group2 = $DB->get_record('groups', array('id'=>$id), '*', MUST_EXIST); - $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($cat1->id)->id)); + $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>\context_coursecat::instance($cat1->id)->id)); $id = $cohortplugin->add_instance($course1, array('customint1'=>$cohort1->id, 'roleid'=>$studentrole->id, 'customint2'=>$group1->id)); $cohortinstance1 = $DB->get_record('enrol', array('id'=>$id)); - $this->assertTrue(is_enrolled(context_course::instance($course1->id), $user4)); + $this->assertTrue(is_enrolled(\context_course::instance($course1->id), $user4)); $this->assertTrue(groups_add_member($group1, $user4)); $this->assertTrue(groups_add_member($group2, $user4)); @@ -455,7 +452,7 @@ class enrol_cohort_testcase extends advanced_testcase { $this->resetAfterTest(); - $trace = new null_progress_trace(); + $trace = new \null_progress_trace(); // Setup a few courses and categories. @@ -483,8 +480,8 @@ class enrol_cohort_testcase extends advanced_testcase { $user3 = $this->getDataGenerator()->create_user(); $user4 = $this->getDataGenerator()->create_user(); - $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($cat1->id)->id)); - $cohort2 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($cat2->id)->id)); + $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>\context_coursecat::instance($cat1->id)->id)); + $cohort2 = $this->getDataGenerator()->create_cohort(array('contextid'=>\context_coursecat::instance($cat2->id)->id)); $cohort3 = $this->getDataGenerator()->create_cohort(); $this->disable_plugin(); // Prevents event sync. @@ -529,17 +526,17 @@ class enrol_cohort_testcase extends advanced_testcase { $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance1->id, 'userid'=>$user4->id))); $this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance2->id, 'userid'=>$user3->id))); $this->assertEquals(7, $DB->count_records('role_assignments', array())); - $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); - $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); - $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); - $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id))); + $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); + $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); + $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); + $this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id))); $cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES); $DB->delete_records('cohort_members', array('cohortid'=>$cohort2->id, 'userid'=>$user3->id)); // Use low level DB api to prevent events! enrol_cohort_sync($trace, $course1->id); $this->assertEquals(7, $DB->count_records('user_enrolments', array())); $this->assertEquals(6, $DB->count_records('role_assignments', array())); - $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id))); + $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id))); $cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_UNENROL); $DB->delete_records('cohort_members', array('cohortid'=>$cohort1->id, 'userid'=>$user1->id)); // Use low level DB api to prevent events! @@ -548,8 +545,8 @@ class enrol_cohort_testcase extends advanced_testcase { $this->assertFalse($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance2->id, 'userid'=>$user3->id))); $this->assertFalse($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance1->id, 'userid'=>$user1->id))); $this->assertEquals(5, $DB->count_records('role_assignments', array())); - $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id))); - $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); + $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id))); + $this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>\context_course::instance($course1->id)->id, 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); $cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES); $DB->delete_records('cohort_members', array('cohortid'=>$cohort1->id)); // Use low level DB api to prevent events! @@ -578,7 +575,7 @@ class enrol_cohort_testcase extends advanced_testcase { $id = groups_create_group((object)array('name'=>'Group 2', 'courseid'=>$course2->id)); $group3 = $DB->get_record('groups', array('id'=>$id), '*', MUST_EXIST); - $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($cat1->id)->id)); + $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>\context_coursecat::instance($cat1->id)->id)); $id = $cohortplugin->add_instance($course1, array('customint1'=>$cohort1->id, 'roleid'=>$studentrole->id, 'customint2'=>$group1->id)); $cohortinstance1 = $DB->get_record('enrol', array('id'=>$id)); @@ -604,11 +601,11 @@ class enrol_cohort_testcase extends advanced_testcase { $this->assertTrue(groups_is_member($group1->id, $user1->id)); $this->assertTrue($DB->record_exists('groups_members', array('groupid'=>$group1->id, 'userid'=>$user1->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); - $this->assertTrue(is_enrolled(context_course::instance($course1->id), $user4)); + $this->assertTrue(is_enrolled(\context_course::instance($course1->id), $user4)); $this->assertTrue(groups_is_member($group1->id, $user4->id)); $this->assertFalse($DB->record_exists('groups_members', array('groupid'=>$group1->id, 'userid'=>$user4->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id))); - $this->assertTrue(is_enrolled(context_course::instance($course2->id), $user3)); + $this->assertTrue(is_enrolled(\context_course::instance($course2->id), $user3)); $this->assertFalse(groups_is_member($group3->id, $user3->id)); $cohortinstance1->customint2 = $group2->id; diff --git a/enrol/database/tests/sync_test.php b/enrol/database/tests/sync_test.php index 09523dba0de..81634ab435b 100644 --- a/enrol/database/tests/sync_test.php +++ b/enrol/database/tests/sync_test.php @@ -14,19 +14,20 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace enrol_database; + /** - * External database enrolment sync tests, this also tests adodb drivers - * that are matching our four supported Moodle database drivers. + * External database enrolment sync tests + * + * This also tests adodb drivers that are matching + * our four supported Moodle database drivers. * * @package enrol_database - * @category phpunit + * @category test * @copyright 2011 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -class enrol_database_testcase extends advanced_testcase { +class sync_test extends \advanced_testcase { protected static $courses = array(); protected static $users = array(); protected static $roles = array(); @@ -115,7 +116,7 @@ class enrol_database_testcase extends advanced_testcase { // but there is no other simple way to test ext database enrol sync, so let's // disable transactions are try to cleanup after the tests. - $table = new xmldb_table('enrol_database_test_enrols'); + $table = new \xmldb_table('enrol_database_test_enrols'); $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('courseid', XMLDB_TYPE_CHAR, '255', null, null, null); $table->add_field('userid', XMLDB_TYPE_CHAR, '255', null, null, null); @@ -132,7 +133,7 @@ class enrol_database_testcase extends advanced_testcase { set_config('remoterolefield', 'roleid', 'enrol_database'); set_config('remoteotheruserfield', 'otheruser', 'enrol_database'); - $table = new xmldb_table('enrol_database_test_courses'); + $table = new \xmldb_table('enrol_database_test_courses'); $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('fullname', XMLDB_TYPE_CHAR, '255', null, null, null); $table->add_field('shortname', XMLDB_TYPE_CHAR, '255', null, null, null); @@ -167,9 +168,9 @@ class enrol_database_testcase extends advanced_testcase { global $DB; $dbman = $DB->get_manager(); - $table = new xmldb_table('enrol_database_test_enrols'); + $table = new \xmldb_table('enrol_database_test_enrols'); $dbman->drop_table($table); - $table = new xmldb_table('enrol_database_test_courses'); + $table = new \xmldb_table('enrol_database_test_courses'); $dbman->drop_table($table); self::$courses = null; @@ -209,7 +210,7 @@ class enrol_database_testcase extends advanced_testcase { global $DB; $dbinstance = $DB->get_record('enrol', array('courseid' => self::$courses[$courseindex]->id, 'enrol' => 'database'), '*', MUST_EXIST); - $coursecontext = context_course::instance(self::$courses[$courseindex]->id); + $coursecontext = \context_course::instance(self::$courses[$courseindex]->id); if ($rolename === false) { $this->assertFalse($DB->record_exists('role_assignments', array('component' => 'enrol_database', 'itemid' => $dbinstance->id, 'userid' => self::$users[$userindex]->id, 'contextid' => $coursecontext->id))); } else if ($rolename !== null) { @@ -424,7 +425,7 @@ class enrol_database_testcase extends advanced_testcase { $plugin = enrol_get_plugin('database'); - $trace = new null_progress_trace(); + $trace = new \null_progress_trace(); // Test basic enrol sync for one user after login. @@ -696,7 +697,7 @@ class enrol_database_testcase extends advanced_testcase { $plugin = enrol_get_plugin('database'); - $trace = new null_progress_trace(); + $trace = new \null_progress_trace(); $plugin->set_config('localcategoryfield', 'id'); $coursecat = $this->getDataGenerator()->create_category(array('name' => 'Test category 1', 'idnumber' => 'tcid1')); diff --git a/filter/displayh5p/tests/upgradelib_test.php b/filter/displayh5p/tests/upgradelib_test.php index 24b2d76355a..91b43a7def0 100644 --- a/filter/displayh5p/tests/upgradelib_test.php +++ b/filter/displayh5p/tests/upgradelib_test.php @@ -14,14 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the upgradelib of the Display H5P filter. - * - * @package filter_displayh5p - * @category test - * @copyright 2019 Carlos Escobedo - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace filter_displayh5p; defined('MOODLE_INTERNAL') || die(); @@ -32,10 +25,12 @@ require_once("$CFG->libdir/filterlib.php"); /** * Unit tests for the upgradelib of the Display H5P filter. * + * @package filter_displayh5p + * @category test * @copyright 2019 Carlos Escobedo * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class filter_displayh5p_upgradelib_testcase extends advanced_testcase { +class upgradelib_test extends \advanced_testcase { /** * test_filter_displayh5p_reorder @@ -78,4 +73,4 @@ class filter_displayh5p_upgradelib_testcase extends advanced_testcase { // Make sure that displayh5p is enabled. $this->assertEquals(TEXTFILTER_ON, $states['displayh5p']->active); } -} \ No newline at end of file +} diff --git a/grade/export/ods/tests/logging_test.php b/grade/export/ods/tests/event/events_test.php similarity index 80% rename from grade/export/ods/tests/logging_test.php rename to grade/export/ods/tests/event/events_test.php index b2e97920749..87e2dbd66bb 100644 --- a/grade/export/ods/tests/logging_test.php +++ b/grade/export/ods/tests/event/events_test.php @@ -14,24 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace gradeexport_ods\event; + /** - * Events test. + * ODS grade export events test cases. * * @package gradeexport_ods * @copyright 2016 Zane Karl zkarl@oid.ucla.edu * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * Resource events test cases. - * - * @package gradeexport_ods - * @copyright 2016 Zane Karl zkarl@oid.ucla.edu - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class ods_logging_events_testcase extends advanced_testcase { +class events_test extends \advanced_testcase { /** * Setup is called before calling test case. @@ -48,7 +40,7 @@ class ods_logging_events_testcase extends advanced_testcase { // doing here is simply making sure that the events returns the right information. $course = $this->getDataGenerator()->create_course(); $params = array( - 'context' => context_course::instance($course->id) + 'context' => \context_course::instance($course->id) ); $event = \gradeexport_ods\event\grade_exported::create($params); // Triggering and capturing the event. @@ -59,7 +51,7 @@ class ods_logging_events_testcase extends advanced_testcase { $event = reset($events); // Checking that the event contains the expected values. $this->assertInstanceOf('\gradeexport_ods\event\grade_exported', $event); - $this->assertEquals(context_course::instance($course->id), $event->get_context()); + $this->assertEquals(\context_course::instance($course->id), $event->get_context()); $this->assertEquals('ods', $event->get_export_type()); } } diff --git a/grade/export/txt/tests/logging_test.php b/grade/export/txt/tests/event/events_test.php similarity index 80% rename from grade/export/txt/tests/logging_test.php rename to grade/export/txt/tests/event/events_test.php index 3bc0b49e3c2..c3c222d90fc 100644 --- a/grade/export/txt/tests/logging_test.php +++ b/grade/export/txt/tests/event/events_test.php @@ -14,24 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace gradeexport_txt\event; + /** - * Events test. + * TXT grade export events test cases. * * @package gradeexport_txt * @copyright 2016 Zane Karl zkarl@oid.ucla.edu * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * Resource events test cases. - * - * @package gradeexport_txt - * @copyright 2016 Zane Karl zkarl@oid.ucla.edu - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class txt_logging_events_testcase extends advanced_testcase { +class events_test extends \advanced_testcase { /** * Setup is called before calling test case. @@ -48,7 +40,7 @@ class txt_logging_events_testcase extends advanced_testcase { // doing here is simply making sure that the events returns the right information. $course = $this->getDataGenerator()->create_course(); $params = array( - 'context' => context_course::instance($course->id) + 'context' => \context_course::instance($course->id) ); $event = \gradeexport_txt\event\grade_exported::create($params); // Triggering and capturing the event. @@ -59,7 +51,7 @@ class txt_logging_events_testcase extends advanced_testcase { $event = reset($events); // Checking that the event contains the expected values. $this->assertInstanceOf('\gradeexport_txt\event\grade_exported', $event); - $this->assertEquals(context_course::instance($course->id), $event->get_context()); + $this->assertEquals(\context_course::instance($course->id), $event->get_context()); $this->assertEquals('txt', $event->get_export_type()); } } diff --git a/grade/export/xls/tests/logging_test.php b/grade/export/xls/tests/event/events_test.php similarity index 80% rename from grade/export/xls/tests/logging_test.php rename to grade/export/xls/tests/event/events_test.php index 277481f3f2b..75921b7195a 100644 --- a/grade/export/xls/tests/logging_test.php +++ b/grade/export/xls/tests/event/events_test.php @@ -14,24 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace gradeexport_xls\event; + /** - * Events test. + * XLS grade export events test cases. * * @package gradeexport_xls * @copyright 2016 Zane Karl zkarl@oid.ucla.edu * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * Resource events test cases. - * - * @package gradeexport_xls - * @copyright 2016 Zane Karl zkarl@oid.ucla.edu - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class xls_logging_events_testcase extends advanced_testcase { +class events_test extends \advanced_testcase { /** * Setup is called before calling test case. @@ -48,7 +40,7 @@ class xls_logging_events_testcase extends advanced_testcase { // doing here is simply making sure that the events returns the right information. $course = $this->getDataGenerator()->create_course(); $params = array( - 'context' => context_course::instance($course->id) + 'context' => \context_course::instance($course->id) ); $event = \gradeexport_xls\event\grade_exported::create($params); // Triggering and capturing the event. @@ -59,7 +51,7 @@ class xls_logging_events_testcase extends advanced_testcase { $event = reset($events); // Checking that the event contains the expected values. $this->assertInstanceOf('\gradeexport_xls\event\grade_exported', $event); - $this->assertEquals(context_course::instance($course->id), $event->get_context()); + $this->assertEquals(\context_course::instance($course->id), $event->get_context()); $this->assertEquals('xls', $event->get_export_type()); } } diff --git a/grade/export/xml/tests/logging_test.php b/grade/export/xml/tests/event/events_test.php similarity index 80% rename from grade/export/xml/tests/logging_test.php rename to grade/export/xml/tests/event/events_test.php index 2e8263290e5..d2b94bd04b9 100644 --- a/grade/export/xml/tests/logging_test.php +++ b/grade/export/xml/tests/event/events_test.php @@ -14,24 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace gradeexport_xml\event; + /** - * Events test. + * XML grade export events test cases. * * @package gradeexport_xml * @copyright 2016 Zane Karl zkarl@oid.ucla.edu * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * Resource events test cases. - * - * @package gradeexport_xml - * @copyright 2016 Zane Karl zkarl@oid.ucla.edu - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class xml_logging_events_testcase extends advanced_testcase { +class events_test extends \advanced_testcase { /** * Setup is called before calling test case. @@ -48,7 +40,7 @@ class xml_logging_events_testcase extends advanced_testcase { // doing here is simply making sure that the events returns the right information. $course = $this->getDataGenerator()->create_course(); $params = array( - 'context' => context_course::instance($course->id) + 'context' => \context_course::instance($course->id) ); $event = \gradeexport_xml\event\grade_exported::create($params); // Triggering and capturing the event. @@ -59,7 +51,7 @@ class xml_logging_events_testcase extends advanced_testcase { $event = reset($events); // Checking that the event contains the expected values. $this->assertInstanceOf('\gradeexport_xml\event\grade_exported', $event); - $this->assertEquals(context_course::instance($course->id), $event->get_context()); + $this->assertEquals(\context_course::instance($course->id), $event->get_context()); $this->assertEquals('xml', $event->get_export_type()); } } diff --git a/grade/grading/tests/privacy_legacy_polyfill_test.php b/grade/grading/tests/privacy/legacy_polyfill_test.php similarity index 92% rename from grade/grading/tests/privacy_legacy_polyfill_test.php rename to grade/grading/tests/privacy/legacy_polyfill_test.php index c424d57d78f..13190762037 100644 --- a/grade/grading/tests/privacy_legacy_polyfill_test.php +++ b/grade/grading/tests/privacy/legacy_polyfill_test.php @@ -14,29 +14,24 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the privacy legacy polyfill for gradingform. - * - * @package core_grading - * @category test - * @copyright 2018 Jake Dallimore - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_grading\privacy; defined('MOODLE_INTERNAL') || die(); /** * Unit tests for the Grading API's privacy legacy_polyfill. * + * @package core_grading + * @category test * @copyright 2018 Jake Dallimore * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class gradeform_privacy_legacy_polyfill_test extends advanced_testcase { +class legacy_polyfill_test extends \advanced_testcase { /** * Test that the core_grading\privacy\legacy_polyfill works and that the static _export_gradingform_instance_data can be called. */ public function test_export_gradingform_instance_data() { - $context = context_system::instance(); + $context = \context_system::instance(); $mock = $this->createMock(test_gradingform_legacy_polyfill_mock_wrapper::class); $mock->expects($this->once()) @@ -59,7 +54,7 @@ class gradeform_privacy_legacy_polyfill_test extends advanced_testcase { * Test the _delete_gradingform_for_instances shim. */ public function test_delete_gradingform_for_instances() { - $context = context_system::instance(); + $context = \context_system::instance(); $mock = $this->createMock(test_gradingform_legacy_polyfill_mock_wrapper::class); $mock->expects($this->once()) diff --git a/grade/report/history/tests/report_test.php b/grade/report/history/tests/report_test.php index 7a58ae1363e..ce33653f833 100644 --- a/grade/report/history/tests/report_test.php +++ b/grade/report/history/tests/report_test.php @@ -14,13 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Grade history report test. - * - * @package gradereport_history - * @copyright 2014 Frédéric Massart - FMCorz.net - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace gradereport_history; defined('MOODLE_INTERNAL') || die(); @@ -31,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); * @copyright 2014 Frédéric Massart - FMCorz.net * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class gradereport_history_report_testcase extends advanced_testcase { +class report_test extends \advanced_testcase { /** * Create some grades. @@ -42,8 +36,8 @@ class gradereport_history_report_testcase extends advanced_testcase { // Making the setup. $c1 = $this->getDataGenerator()->create_course(); $c2 = $this->getDataGenerator()->create_course(); - $c1ctx = context_course::instance($c1->id); - $c2ctx = context_course::instance($c2->id); + $c1ctx = \context_course::instance($c1->id); + $c2ctx = \context_course::instance($c2->id); // Users. $u1 = $this->getDataGenerator()->create_user(); @@ -73,7 +67,7 @@ class gradereport_history_report_testcase extends advanced_testcase { $this->setUser($grader1); - $gi = grade_item::fetch($giparams + array('iteminstance' => $c1m1->id)); + $gi = \grade_item::fetch($giparams + array('iteminstance' => $c1m1->id)); $grades['c1m1u1'] = $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u1->id, 'timemodified' => time() - 3600)); $grades['c1m1u2'] = $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u2->id, @@ -82,14 +76,14 @@ class gradereport_history_report_testcase extends advanced_testcase { $grades['c1m1u4'] = $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u4->id)); $grades['c1m1u5'] = $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u5->id)); - $gi = grade_item::fetch($giparams + array('iteminstance' => $c1m2->id)); + $gi = \grade_item::fetch($giparams + array('iteminstance' => $c1m2->id)); $grades['c1m2u1'] = $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u1->id)); $grades['c1m2u2'] = $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u2->id)); - $gi = grade_item::fetch($giparams + array('iteminstance' => $c1m3->id)); + $gi = \grade_item::fetch($giparams + array('iteminstance' => $c1m3->id)); $grades['c1m3u1'] = $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u1->id)); - $gi = grade_item::fetch($giparams + array('iteminstance' => $c2m1->id)); + $gi = \grade_item::fetch($giparams + array('iteminstance' => $c2m1->id)); $grades['c2m1u1'] = $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u1->id, 'usermodified' => $grader1->id)); $grades['c2m1u2'] = $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u2->id, @@ -109,7 +103,7 @@ class gradereport_history_report_testcase extends advanced_testcase { // Histories where grades have been revised and not revised. $now = time(); - $gi = grade_item::fetch($giparams + array('iteminstance' => $c2m2->id)); + $gi = \grade_item::fetch($giparams + array('iteminstance' => $c2m2->id)); $grades['c2m2u1a'] = $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u1->id, 'timemodified' => $now - 60, 'finalgrade' => 50)); $grades['c2m2u1b'] = $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u1->id, @@ -139,9 +133,9 @@ class gradereport_history_report_testcase extends advanced_testcase { $this->assertEquals(4, $this->get_tablelog_results($c1ctx, array('userids' => "$u1->id,$u3->id"), true)); // Filtering based on one grade item. - $gi = grade_item::fetch($giparams + array('iteminstance' => $c1m1->id)); + $gi = \grade_item::fetch($giparams + array('iteminstance' => $c1m1->id)); $this->assertEquals(5, $this->get_tablelog_results($c1ctx, array('itemid' => $gi->id), true)); - $gi = grade_item::fetch($giparams + array('iteminstance' => $c1m3->id)); + $gi = \grade_item::fetch($giparams + array('iteminstance' => $c1m3->id)); $this->assertEquals(1, $this->get_tablelog_results($c1ctx, array('itemid' => $gi->id), true)); // Filtering based on the grader. @@ -162,7 +156,7 @@ class gradereport_history_report_testcase extends advanced_testcase { $this->assertEquals(1, $this->get_tablelog_results($c2ctx, array('userids' => $u5->id, 'revisedonly' => true), true)); // More filtering based on revised only. - $gi = grade_item::fetch($giparams + array('iteminstance' => $c2m2->id)); + $gi = \grade_item::fetch($giparams + array('iteminstance' => $c2m2->id)); $this->assertEquals(6, $this->get_tablelog_results($c2ctx, array('userids' => $u1->id, 'itemid' => $gi->id), true)); $results = $this->get_tablelog_results($c2ctx, array('userids' => $u1->id, 'itemid' => $gi->id, 'revisedonly' => true)); $this->assertGradeHistoryIds(array($grades['c2m2u1a']->id, $grades['c2m2u1c']->id, $grades['c2m2u1e']->id), $results); @@ -196,8 +190,8 @@ class gradereport_history_report_testcase extends advanced_testcase { // Making the setup. $c1 = $this->getDataGenerator()->create_course(); $c2 = $this->getDataGenerator()->create_course(); - $c1ctx = context_course::instance($c1->id); - $c2ctx = context_course::instance($c2->id); + $c1ctx = \context_course::instance($c1->id); + $c2ctx = \context_course::instance($c2->id); $c1m1 = $this->getDataGenerator()->create_module('assign', array('course' => $c1)); $c2m1 = $this->getDataGenerator()->create_module('assign', array('course' => $c2)); @@ -209,12 +203,12 @@ class gradereport_history_report_testcase extends advanced_testcase { $u4 = $this->getDataGenerator()->create_user(array('firstname' => 'Kenny', 'lastname' => 'McCormick')); // Creating grade history for some users. - $gi = grade_item::fetch(array('iteminstance' => $c1m1->id, 'itemtype' => 'mod', 'itemmodule' => 'assign')); + $gi = \grade_item::fetch(array('iteminstance' => $c1m1->id, 'itemtype' => 'mod', 'itemmodule' => 'assign')); $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u1->id)); $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u2->id)); $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u3->id)); - $gi = grade_item::fetch(array('iteminstance' => $c2m1->id, 'itemtype' => 'mod', 'itemmodule' => 'assign')); + $gi = \grade_item::fetch(array('iteminstance' => $c2m1->id, 'itemtype' => 'mod', 'itemmodule' => 'assign')); $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u4->id)); // Checking fetching some users. @@ -333,7 +327,7 @@ class gradereport_history_report_testcase extends advanced_testcase { $generator->create_group_member(['groupid' => $groups['g5']->id, 'userid' => $s5->id]); // Creating grade history for the students. - $gi = grade_item::fetch(['iteminstance' => $assign->id, 'itemtype' => 'mod', 'itemmodule' => 'assign']); + $gi = \grade_item::fetch(['iteminstance' => $assign->id, 'itemtype' => 'mod', 'itemmodule' => 'assign']); $this->create_grade_history(['itemid' => $gi->id, 'userid' => $s1->id]); $this->create_grade_history(['itemid' => $gi->id, 'userid' => $s2->id]); $this->create_grade_history(['itemid' => $gi->id, 'userid' => $s3->id]); @@ -344,7 +338,7 @@ class gradereport_history_report_testcase extends advanced_testcase { $this->setUser($t1); // Fetch the users. - $users = \gradereport_history\helper::get_users(context_course::instance($course->id)); + $users = \gradereport_history\helper::get_users(\context_course::instance($course->id)); // Confirm that the number of users fetched is the same as the count of expected users. $this->assertCount(count($expectedusers), $users); foreach ($users as $user) { @@ -381,15 +375,15 @@ class gradereport_history_report_testcase extends advanced_testcase { } // Creating grade history for some users. - $gi = grade_item::fetch(array('iteminstance' => $c1m1->id, 'itemtype' => 'mod', 'itemmodule' => 'assign')); + $gi = \grade_item::fetch(array('iteminstance' => $c1m1->id, 'itemtype' => 'mod', 'itemmodule' => 'assign')); $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u1->id, 'usermodified' => $u1->id)); $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u1->id, 'usermodified' => $u2->id)); $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u1->id, 'usermodified' => $u3->id)); - $gi = grade_item::fetch(array('iteminstance' => $c2m1->id, 'itemtype' => 'mod', 'itemmodule' => 'assign')); + $gi = \grade_item::fetch(array('iteminstance' => $c2m1->id, 'itemtype' => 'mod', 'itemmodule' => 'assign')); $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u1->id, 'usermodified' => $u4->id)); - $gi = grade_item::fetch(array('iteminstance' => $c3m1->id, 'itemtype' => 'mod', 'itemmodule' => 'assign')); + $gi = \grade_item::fetch(array('iteminstance' => $c3m1->id, 'itemtype' => 'mod', 'itemmodule' => 'assign')); $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u1->id, 'usermodified' => $u1->id)); $this->create_grade_history(array('itemid' => $gi->id, 'userid' => $u2->id, 'usermodified' => $u2->id)); @@ -442,14 +436,14 @@ class gradereport_history_report_testcase extends advanced_testcase { $params = (array) $params; if (!isset($params['itemid'])) { - throw new coding_exception('Missing itemid key.'); + throw new \coding_exception('Missing itemid key.'); } if (!isset($params['userid'])) { - throw new coding_exception('Missing userid key.'); + throw new \coding_exception('Missing userid key.'); } // Default object. - $grade = new stdClass(); + $grade = new \stdClass(); $grade->itemid = 0; $grade->userid = 0; $grade->oldid = 123; @@ -481,7 +475,7 @@ class gradereport_history_report_testcase extends advanced_testcase { * @return mixed Count or array of objects. */ protected function get_tablelog_results($coursecontext, $filters = array(), $count = false) { - $table = new gradereport_history_tests_tablelog('something', $coursecontext, new moodle_url(''), $filters); + $table = new gradereport_history_tests_tablelog('something', $coursecontext, new \moodle_url(''), $filters); return $table->get_test_results($count); } diff --git a/lib/form/tests/course_test.php b/lib/form/tests/course_test.php index ac44a5c7f9b..dcd104a8669 100644 --- a/lib/form/tests/course_test.php +++ b/lib/form/tests/course_test.php @@ -14,16 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for MoodleQuickForm_course. - * - * This file contains unit tests related to course forms element. - * - * @package core_form - * @category test - * @copyright 2020 Ruslan Kabalin - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_form; defined('MOODLE_INTERNAL') || die(); @@ -40,7 +31,7 @@ require_once($CFG->libdir . '/form/course.php'); * @copyright 2020 Ruslan Kabalin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_form_course_testcase extends basic_testcase { +class course_test extends \basic_testcase { /** * Test constructor supports all declared attributes. @@ -51,7 +42,7 @@ class core_form_course_testcase extends basic_testcase { 'requiredcapabilities' => ['moodle/course:update'], ]; - $element = new MoodleQuickForm_course('testel', null, $attributes); + $element = new \MoodleQuickForm_course('testel', null, $attributes); $html = $element->toHtml(); $this->assertStringContainsString('data-exclude="1,2"', $html); $this->assertStringContainsString('data-requiredcapabilities="moodle/course:update"', $html); @@ -67,7 +58,7 @@ class core_form_course_testcase extends basic_testcase { 'includefrontpage' => true, 'onlywithcompletion' => true, ]; - $element = new MoodleQuickForm_course('testel', null, $attributes); + $element = new \MoodleQuickForm_course('testel', null, $attributes); $html = $element->toHtml(); $this->assertStringContainsString('multiple', $html); $this->assertStringContainsString('data-limittoenrolled="1"', $html); diff --git a/lib/mlbackend/python/tests/processor_test.php b/lib/mlbackend/python/tests/processor_test.php index e9ceb51b273..d14dd088ccc 100644 --- a/lib/mlbackend/python/tests/processor_test.php +++ b/lib/mlbackend/python/tests/processor_test.php @@ -14,24 +14,17 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Provides the {@link mlbackend_python_processor_testcase} class. - * - * @package mlbackend_python - * @category test - * @copyright 2019 David Mudrák - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); +namespace mlbackend_python; /** * Unit tests for the {@link \mlbackend_python\processor} class. * + * @package mlbackend_python + * @category test * @copyright 2019 David Mudrák * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mlbackend_python_processor_testcase extends advanced_testcase { +class processor_test extends \advanced_testcase { /** * Test implementation of the {@link \mlbackend_python\processor::check_pip_package_version()} method. diff --git a/lib/tests/indicators_test.php b/lib/tests/analytics/indicators_test.php similarity index 96% rename from lib/tests/indicators_test.php rename to lib/tests/analytics/indicators_test.php index e804dff48ee..f2a11eb1e02 100644 --- a/lib/tests/indicators_test.php +++ b/lib/tests/analytics/indicators_test.php @@ -14,30 +14,23 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for core indicators. - * - * @package core - * @category analytics - * @copyright 2017 David Monllaó {@link http://www.davidmonllao.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core\analytics; defined('MOODLE_INTERNAL') || die(); -require_once(__DIR__ . '/../../analytics/tests/fixtures/test_target_shortname.php'); -require_once(__DIR__ . '/../../admin/tool/log/store/standard/tests/fixtures/event.php'); -require_once(__DIR__ . '/../../lib/enrollib.php'); +require_once(__DIR__ . '/../../../analytics/tests/fixtures/test_target_shortname.php'); +require_once(__DIR__ . '/../../../admin/tool/log/store/standard/tests/fixtures/event.php'); +require_once(__DIR__ . '/../../../lib/enrollib.php'); /** * Unit tests for core indicators. * * @package core - * @category analytics + * @category test * @copyright 2017 David Monllaó {@link http://www.davidmonllao.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_analytics_indicators_testcase extends advanced_testcase { +class indicators_test extends \advanced_testcase { /** * Test all core indicators. diff --git a/lib/tests/datalib_test.php b/lib/tests/datalib_test.php index 8891a62f73f..f13f456f8b4 100644 --- a/lib/tests/datalib_test.php +++ b/lib/tests/datalib_test.php @@ -14,27 +14,17 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Test for various bits of datalib.php. - * - * @package core - * @category phpunit - * @copyright 2012 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - +namespace core; /** * Test for various bits of datalib.php. * * @package core - * @category phpunit + * @category test * @copyright 2012 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_datalib_testcase extends advanced_testcase { +class datalib_test extends \advanced_testcase { protected function normalise_sql($sort) { return preg_replace('~\s+~', ' ', $sort); } @@ -176,7 +166,7 @@ class core_datalib_testcase extends advanced_testcase { $CFG->showuseridentity = ''; - list($sort, $params) = users_order_by_sql('', 'search', context_system::instance()); + list($sort, $params) = users_order_by_sql('', 'search', \context_system::instance()); $this->assert_same_sql('CASE WHEN ' . $DB->sql_fullname() . ' = :usersortexact1 OR LOWER(firstname) = LOWER(:usersortexact2) OR @@ -193,7 +183,7 @@ class core_datalib_testcase extends advanced_testcase { $CFG->showuseridentity = 'email,idnumber'; $this->setAdminUser(); - list($sort, $params) = users_order_by_sql('u', 'search', context_system::instance()); + list($sort, $params) = users_order_by_sql('u', 'search', \context_system::instance()); $this->assert_same_sql('CASE WHEN ' . $DB->sql_fullname('u.firstname', 'u.lastname') . ' = :usersortexact1 OR LOWER(u.firstname) = LOWER(:usersortexact2) OR @@ -213,7 +203,7 @@ class core_datalib_testcase extends advanced_testcase { $this->setAdminUser(); list($sort, $params) = - users_order_by_sql('u', 'search', context_system::instance(), ['profile_field_customfield' => 'x.customfield']); + users_order_by_sql('u', 'search', \context_system::instance(), ['profile_field_customfield' => 'x.customfield']); $this->assert_same_sql('CASE WHEN ' . $DB->sql_fullname('u.firstname', 'u.lastname') . ' = :usersortexact1 OR LOWER(u.firstname) = LOWER(:usersortexact2) OR @@ -439,28 +429,28 @@ class core_datalib_testcase extends advanced_testcase { try { get_coursemodule_from_id('folder', -11, 0, false, MUST_EXIST); $this->fail('dml_missing_record_exception expected'); - } catch (moodle_exception $e) { + } catch (\moodle_exception $e) { $this->assertInstanceOf('dml_missing_record_exception', $e); } try { get_coursemodule_from_id('', -11, 0, false, MUST_EXIST); $this->fail('dml_missing_record_exception expected'); - } catch (moodle_exception $e) { + } catch (\moodle_exception $e) { $this->assertInstanceOf('dml_missing_record_exception', $e); } try { get_coursemodule_from_id('a b', $folder1a->cmid, 0, false, MUST_EXIST); $this->fail('coding_exception expected'); - } catch (moodle_exception $e) { + } catch (\moodle_exception $e) { $this->assertInstanceOf('coding_exception', $e); } try { get_coursemodule_from_id('abc', $folder1a->cmid, 0, false, MUST_EXIST); $this->fail('dml_read_exception expected'); - } catch (moodle_exception $e) { + } catch (\moodle_exception $e) { $this->assertInstanceOf('dml_read_exception', $e); } } @@ -503,28 +493,28 @@ class core_datalib_testcase extends advanced_testcase { try { get_coursemodule_from_instance('folder', -11, 0, false, MUST_EXIST); $this->fail('dml_missing_record_exception expected'); - } catch (moodle_exception $e) { + } catch (\moodle_exception $e) { $this->assertInstanceOf('dml_missing_record_exception', $e); } try { get_coursemodule_from_instance('a b', $folder1a->cmid, 0, false, MUST_EXIST); $this->fail('coding_exception expected'); - } catch (moodle_exception $e) { + } catch (\moodle_exception $e) { $this->assertInstanceOf('coding_exception', $e); } try { get_coursemodule_from_instance('', $folder1a->cmid, 0, false, MUST_EXIST); $this->fail('coding_exception expected'); - } catch (moodle_exception $e) { + } catch (\moodle_exception $e) { $this->assertInstanceOf('coding_exception', $e); } try { get_coursemodule_from_instance('abc', $folder1a->cmid, 0, false, MUST_EXIST); $this->fail('dml_read_exception expected'); - } catch (moodle_exception $e) { + } catch (\moodle_exception $e) { $this->assertInstanceOf('dml_read_exception', $e); } } @@ -586,14 +576,14 @@ class core_datalib_testcase extends advanced_testcase { try { get_coursemodules_in_course('a b', $course1->id); $this->fail('coding_exception expected'); - } catch (moodle_exception $e) { + } catch (\moodle_exception $e) { $this->assertInstanceOf('coding_exception', $e); } try { get_coursemodules_in_course('abc', $course1->id); $this->fail('dml_read_exception expected'); - } catch (moodle_exception $e) { + } catch (\moodle_exception $e) { $this->assertInstanceOf('dml_read_exception', $e); } } @@ -641,14 +631,14 @@ class core_datalib_testcase extends advanced_testcase { try { get_all_instances_in_courses('a b', array($course1->id => $course1, $course2->id => $course2)); $this->fail('coding_exception expected'); - } catch (moodle_exception $e) { + } catch (\moodle_exception $e) { $this->assertInstanceOf('coding_exception', $e); } try { get_all_instances_in_courses('', array($course1->id => $course1, $course2->id => $course2)); $this->fail('coding_exception expected'); - } catch (moodle_exception $e) { + } catch (\moodle_exception $e) { $this->assertInstanceOf('coding_exception', $e); } } @@ -694,14 +684,14 @@ class core_datalib_testcase extends advanced_testcase { try { get_all_instances_in_course('a b', $course1); $this->fail('coding_exception expected'); - } catch (moodle_exception $e) { + } catch (\moodle_exception $e) { $this->assertInstanceOf('coding_exception', $e); } try { get_all_instances_in_course('', $course1); $this->fail('coding_exception expected'); - } catch (moodle_exception $e) { + } catch (\moodle_exception $e) { $this->assertInstanceOf('coding_exception', $e); } } @@ -717,16 +707,16 @@ class core_datalib_testcase extends advanced_testcase { $this->assertEquals(MAX_COURSES_IN_CATEGORY, get_max_courses_in_category()); // Misc category. - $misc = core_course_category::get_default(); + $misc = \core_course_category::get_default(); $this->assertEquals(MAX_COURSES_IN_CATEGORY, $misc->sortorder); $category1 = $this->getDataGenerator()->create_category(); $category2 = $this->getDataGenerator()->create_category(); // Check category sort orders. - $this->assertEquals(MAX_COURSES_IN_CATEGORY, core_course_category::get($misc->id)->sortorder); - $this->assertEquals(MAX_COURSES_IN_CATEGORY * 2, core_course_category::get($category1->id)->sortorder); - $this->assertEquals(MAX_COURSES_IN_CATEGORY * 3, core_course_category::get($category2->id)->sortorder); + $this->assertEquals(MAX_COURSES_IN_CATEGORY, \core_course_category::get($misc->id)->sortorder); + $this->assertEquals(MAX_COURSES_IN_CATEGORY * 2, \core_course_category::get($category1->id)->sortorder); + $this->assertEquals(MAX_COURSES_IN_CATEGORY * 3, \core_course_category::get($category2->id)->sortorder); // Create courses. $course1 = $this->getDataGenerator()->create_course(['category' => $category1->id]); @@ -746,9 +736,9 @@ class core_datalib_testcase extends advanced_testcase { // The sort order has not yet fixed, these sort orders should be the same as before. // Categories. - $this->assertEquals(MAX_COURSES_IN_CATEGORY, core_course_category::get($misc->id)->sortorder); - $this->assertEquals(MAX_COURSES_IN_CATEGORY * 2, core_course_category::get($category1->id)->sortorder); - $this->assertEquals(MAX_COURSES_IN_CATEGORY * 3, core_course_category::get($category2->id)->sortorder); + $this->assertEquals(MAX_COURSES_IN_CATEGORY, \core_course_category::get($misc->id)->sortorder); + $this->assertEquals(MAX_COURSES_IN_CATEGORY * 2, \core_course_category::get($category1->id)->sortorder); + $this->assertEquals(MAX_COURSES_IN_CATEGORY * 3, \core_course_category::get($category2->id)->sortorder); // Courses in category 1. $this->assertEquals(MAX_COURSES_IN_CATEGORY * 2 + 2, get_course($course1->id)->sortorder); $this->assertEquals(MAX_COURSES_IN_CATEGORY * 2 + 1, get_course($course3->id)->sortorder); @@ -759,10 +749,10 @@ class core_datalib_testcase extends advanced_testcase { // Create new category so that the sort orders are applied. $category3 = $this->getDataGenerator()->create_category(); // Categories. - $this->assertEquals(20000, core_course_category::get($misc->id)->sortorder); - $this->assertEquals(20000 * 2, core_course_category::get($category1->id)->sortorder); - $this->assertEquals(20000 * 3, core_course_category::get($category2->id)->sortorder); - $this->assertEquals(20000 * 4, core_course_category::get($category3->id)->sortorder); + $this->assertEquals(20000, \core_course_category::get($misc->id)->sortorder); + $this->assertEquals(20000 * 2, \core_course_category::get($category1->id)->sortorder); + $this->assertEquals(20000 * 3, \core_course_category::get($category2->id)->sortorder); + $this->assertEquals(20000 * 4, \core_course_category::get($category3->id)->sortorder); // Courses in category 1. $this->assertEquals(20000 * 2 + 2, get_course($course1->id)->sortorder); $this->assertEquals(20000 * 2 + 1, get_course($course3->id)->sortorder); diff --git a/lib/tests/event_test.php b/lib/tests/event/base_test.php similarity index 95% rename from lib/tests/event_test.php rename to lib/tests/event/base_test.php index 208482482c9..ed8c8e2ab76 100644 --- a/lib/tests/event_test.php +++ b/lib/tests/event/base_test.php @@ -14,6 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core\event; + +defined('MOODLE_INTERNAL') || die(); + +require_once(__DIR__.'/..//fixtures/event_fixtures.php'); + /** * Tests for event manager, base event and observers. * @@ -22,12 +28,7 @@ * @copyright 2013 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -require_once(__DIR__.'/fixtures/event_fixtures.php'); - -class core_event_testcase extends advanced_testcase { +class base_test extends \advanced_testcase { const DEBUGGING_MSG = 'Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.'; @@ -68,14 +69,14 @@ class core_event_testcase extends advanced_testcase { $event->courseid = 2; $this->fail('Exception expected on event modification'); } catch (\moodle_exception $e) { - $this->assertInstanceOf('coding_exception', $e); + $this->assertInstanceOf(\coding_exception::class, $e); } try { $event->xxxx = 1; $this->fail('Exception expected on event modification'); } catch (\moodle_exception $e) { - $this->assertInstanceOf('coding_exception', $e); + $this->assertInstanceOf(\coding_exception::class, $e); } $event2 = \core_tests\event\unittest_executed::create(array('contextid'=>$system->id, 'objectid'=>5, 'anonymous'=>1, 'other'=>array('sample'=>null, 'xx'=>10))); @@ -92,7 +93,7 @@ class core_event_testcase extends advanced_testcase { $course = $this->getDataGenerator()->create_course(); $forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id)); - $context = context_module::instance($forum->cmid); + $context = \context_module::instance($forum->cmid); $event = \core_tests\event\unittest_executed::create(array('context' => $context, 'objectid' => 5)); // Check guessed course ID, and default properties. @@ -107,7 +108,7 @@ class core_event_testcase extends advanced_testcase { $this->assertNull($event->relateduserid); $user = $this->getDataGenerator()->create_user(); - $context = context_user::instance($user->id); + $context = \context_user::instance($user->id); $event = \core_tests\event\unittest_executed::create(array('contextid' => $context->id, 'objectid' => 5)); // Check guessing on contextid, and user context level. @@ -156,7 +157,7 @@ class core_event_testcase extends advanced_testcase { $this->assertCount(3, $result); $expected = array(); - $observer = new stdClass(); + $observer = new \stdClass(); $observer->callable = '\core_tests\event\unittest_observer::external_observer'; $observer->priority = 200; $observer->internal = false; @@ -164,7 +165,7 @@ class core_event_testcase extends advanced_testcase { $observer->plugintype = null; $observer->plugin = null; $expected[0] = $observer; - $observer = new stdClass(); + $observer = new \stdClass(); $observer->callable = '\core_tests\event\unittest_observer::observe_one'; $observer->priority = 0; $observer->internal = true; @@ -176,7 +177,7 @@ class core_event_testcase extends advanced_testcase { $this->assertEquals($expected, $result['\core_tests\event\unittest_executed']); $expected = array(); - $observer = new stdClass(); + $observer = new \stdClass(); $observer->callable = '\core_tests\event\unittest_observer::broken_observer'; $observer->priority = 100; $observer->internal = true; @@ -188,7 +189,7 @@ class core_event_testcase extends advanced_testcase { $this->assertEquals($expected, $result['\core\event\unknown_executed']); $expected = array(); - $observer = new stdClass(); + $observer = new \stdClass(); $observer->callable = array('\core_tests\event\unittest_observer', 'observe_all'); $observer->priority = 10; $observer->internal = true; @@ -196,7 +197,7 @@ class core_event_testcase extends advanced_testcase { $observer->plugintype = null; $observer->plugin = null; $expected[0] = $observer; - $observer = new stdClass(); + $observer = new \stdClass(); $observer->callable = array('\core_tests\event\unittest_observer', 'observe_all_alt'); $observer->priority = 0; $observer->internal = true; @@ -220,7 +221,7 @@ class core_event_testcase extends advanced_testcase { $result = \core\event\manager::phpunit_replace_observers($observers); $this->assertCount(1, $result); $expected = array(); - $observer = new stdClass(); + $observer = new \stdClass(); $observer->callable = '\core_tests\event\unittest_observer::observe_one'; $observer->priority = 0; $observer->internal = true; @@ -452,7 +453,7 @@ class core_event_testcase extends advanced_testcase { $trans->rollback(new \moodle_exception('xxx')); $this->fail('Expecting exception'); } catch (\moodle_exception $e) { - $this->assertInstanceOf('moodle_exception', $e); + $this->assertInstanceOf(\moodle_exception::class, $e); } $this->assertSame( @@ -494,17 +495,17 @@ class core_event_testcase extends advanced_testcase { $this->assertCount(0, \core_tests\event\unittest_observer::$event); try { - $transaction2->rollback(new Exception('x')); + $transaction2->rollback(new \Exception('x')); $this->fail('Expecting exception'); - } catch (Exception $e) {} + } catch (\Exception $e) {} $this->assertCount(0, \core_tests\event\unittest_observer::$event); $this->assertTrue($DB->is_transaction_started()); try { - $transaction1->rollback(new Exception('x')); + $transaction1->rollback(new \Exception('x')); $this->fail('Expecting exception'); - } catch (Exception $e) {} + } catch (\Exception $e) {} $this->assertCount(0, \core_tests\event\unittest_observer::$event); $this->assertFalse($DB->is_transaction_started()); @@ -592,7 +593,7 @@ class core_event_testcase extends advanced_testcase { ); $DB->delete_records('log', array()); - $this->expectException('coding_exception'); + $this->expectException(\coding_exception::class); events_update_definition('unittest'); $DB->delete_records_select('events_handlers', "component <> 'unittest'"); @@ -632,7 +633,7 @@ class core_event_testcase extends advanced_testcase { $this->assertTrue($event2->is_triggered()); $this->assertTrue($event2->is_restored()); $this->assertEquals($data1, $data2); - $this->assertInstanceOf('core_tests\event\unittest_executed', $event2); + $this->assertInstanceOf(\core_tests\event\unittest_executed::class, $event2); $this->assertEquals($event1->get_context(), $event2->get_context()); @@ -645,13 +646,13 @@ class core_event_testcase extends advanced_testcase { $data4 = $data1; unset($data4['userid']); $event4 = \core\event\base::restore($data4, array()); - $this->assertInstanceOf('core_tests\event\unittest_executed', $event4); + $this->assertInstanceOf(\core_tests\event\unittest_executed::class, $event4); $this->assertDebuggingCalled(); $data5 = $data1; $data5['xx'] = 'xx'; $event5 = \core\event\base::restore($data5, array()); - $this->assertInstanceOf('core_tests\event\unittest_executed', $event5); + $this->assertInstanceOf(\core_tests\event\unittest_executed::class, $event5); $this->assertDebuggingCalled(); } @@ -665,7 +666,7 @@ class core_event_testcase extends advanced_testcase { $event->trigger(); $this->fail('Exception expected on double trigger'); } catch (\moodle_exception $e) { - $this->assertInstanceOf('coding_exception', $e); + $this->assertInstanceOf(\coding_exception::class, $e); } $data = $event->get_data(); @@ -677,7 +678,7 @@ class core_event_testcase extends advanced_testcase { $restored->trigger(); $this->fail('Exception expected on triggering of restored event'); } catch (\moodle_exception $e) { - $this->assertInstanceOf('coding_exception', $e); + $this->assertInstanceOf(\coding_exception::class, $e); } $event = \core_tests\event\unittest_executed::create(array('context'=>\context_system::instance(), 'other'=>array('sample'=>5, 'xx'=>10))); @@ -685,7 +686,7 @@ class core_event_testcase extends advanced_testcase { \core\event\manager::dispatch($event); $this->fail('Exception expected on manual event dispatching'); } catch (\moodle_exception $e) { - $this->assertInstanceOf('coding_exception', $e); + $this->assertInstanceOf(\coding_exception::class, $e); } } @@ -696,7 +697,7 @@ class core_event_testcase extends advanced_testcase { $event = \core_tests\event\unittest_executed::create(array('other'=>array('sample'=>5, 'xx'=>10))); $this->fail('Exception expected when context and contextid missing'); } catch (\moodle_exception $e) { - $this->assertInstanceOf('coding_exception', $e); + $this->assertInstanceOf(\coding_exception::class, $e); } $event = \core_tests\event\bad_event1::create(array('context'=>\context_system::instance())); @@ -704,7 +705,7 @@ class core_event_testcase extends advanced_testcase { $event->trigger(); $this->fail('Exception expected when $data not valid'); } catch (\moodle_exception $e) { - $this->assertInstanceOf('\coding_exception', $e); + $this->assertInstanceOf(\coding_exception::class, $e); } $event = \core_tests\event\bad_event2::create(array('context'=>\context_system::instance())); @@ -712,7 +713,7 @@ class core_event_testcase extends advanced_testcase { $event->trigger(); $this->fail('Exception expected when $data not valid'); } catch (\moodle_exception $e) { - $this->assertInstanceOf('\coding_exception', $e); + $this->assertInstanceOf(\coding_exception::class, $e); } $event = \core_tests\event\bad_event2b::create(array('context'=>\context_system::instance())); @@ -740,7 +741,7 @@ class core_event_testcase extends advanced_testcase { $event->trigger(); $this->fail('Exception expected when $data contains objectid but objecttable not specified'); } catch (\moodle_exception $e) { - $this->assertInstanceOf('\coding_exception', $e); + $this->assertInstanceOf(\coding_exception::class, $e); } $event = \core_tests\event\bad_event8::create(array('context'=>\context_system::instance())); @@ -773,7 +774,7 @@ class core_event_testcase extends advanced_testcase { $event5->trigger(); $this->assertDebuggingCalled(); - $url = new moodle_url('/admin/'); + $url = new \moodle_url('/admin/'); $event6 = \core_tests\event\problematic_event1::create(array('context'=>\context_system::instance(), 'other'=>array('a'=>$url))); $this->assertDebuggingNotCalled(); $event6->trigger(); @@ -821,7 +822,7 @@ class core_event_testcase extends advanced_testcase { $event->add_record_snapshot('course', $course1); $this->fail('Updating of snapshots after trigger is not ok');; } catch (\moodle_exception $e) { - $this->assertInstanceOf('\coding_exception', $e); + $this->assertInstanceOf(\coding_exception::class, $e); } $event2 = \core_tests\event\unittest_executed::restore($event->get_data(), array()); @@ -829,7 +830,7 @@ class core_event_testcase extends advanced_testcase { $event2->get_record_snapshot('course', $course1->id); $this->fail('Reading of snapshots from restored events is not ok');; } catch (\moodle_exception $e) { - $this->assertInstanceOf('\coding_exception', $e); + $this->assertInstanceOf(\coding_exception::class, $e); } } @@ -878,7 +879,7 @@ class core_event_testcase extends advanced_testcase { $observers = \core\event\manager::get_all_observers(); // Expected information from the workshop allocation scheduled observer. - $expected = new stdClass(); + $expected = new \stdClass(); $expected->callable = '\workshopallocation_scheduled\observer::workshop_viewed'; $expected->priority = 0; $expected->internal = true; @@ -959,7 +960,7 @@ and nothing else."; $course = $this->getDataGenerator()->create_course(); $feed = $this->getDataGenerator()->create_module('feedback', ['course' => $course->id]); - $context = context_module::instance($feed->cmid); + $context = \context_module::instance($feed->cmid); $data = [ 'context' => $context, 'courseid' => $course->id, diff --git a/lib/tests/messagelib_test.php b/lib/tests/messagelib_test.php index b77b08f7b13..6c260bf15ab 100644 --- a/lib/tests/messagelib_test.php +++ b/lib/tests/messagelib_test.php @@ -14,18 +14,17 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core; + /** * Tests for messagelib.php. * - * @package core_message - * @category phpunit + * @package core + * @category test * @copyright 2012 The Open Universtiy * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -class core_messagelib_testcase extends advanced_testcase { +class messagelib_test extends \advanced_testcase { public function test_message_provider_disabled() { $this->resetAfterTest(); @@ -80,9 +79,9 @@ class core_messagelib_testcase extends advanced_testcase { $quiz = $generator->create_module('quiz', array('course' => $course->id)); $user = $generator->create_user(); - $coursecontext = context_course::instance($course->id); - $quizcontext = context_module::instance($quiz->cmid); - $frontpagecontext = context_course::instance(SITEID); + $coursecontext = \context_course::instance($course->id); + $quizcontext = \context_module::instance($quiz->cmid); + $frontpagecontext = \context_course::instance(SITEID); $studentrole = $DB->get_record('role', array('shortname' => 'student')); @@ -103,7 +102,7 @@ class core_messagelib_testcase extends advanced_testcase { // A user is a student in a different course, they should not get confirmation. $course2 = $generator->create_course(array('category' => $cat->id)); $user2 = $generator->create_user(); - $coursecontext2 = context_course::instance($course2->id); + $coursecontext2 = \context_course::instance($course2->id); role_assign($studentrole->id, $user2->id, $coursecontext2->id); accesslib_clear_all_caches_for_unit_testing(); $providers = message_get_providers_for_user($user2->id); @@ -127,13 +126,13 @@ class core_messagelib_testcase extends advanced_testcase { // Create a course. $course = $this->getDataGenerator()->create_course(); - $coursecontext = context_course::instance($course->id); + $coursecontext = \context_course::instance($course->id); // It would probably be better to use a quiz instance as it has capability controlled messages // however mod_quiz doesn't have a data generator. // Instead we're going to use backup notifications and give and take away the capability at various levels. $assign = $this->getDataGenerator()->create_module('assign', array('course'=>$course->id)); - $modulecontext = context_module::instance($assign->cmid); + $modulecontext = \context_module::instance($assign->cmid); // Create and enrol a teacher. $teacherrole = $DB->get_record('role', array('shortname'=>'editingteacher'), '*', MUST_EXIST); @@ -161,7 +160,7 @@ class core_messagelib_testcase extends advanced_testcase { // They should now be able to see the backup message. assign_capability('moodle/site:config', CAP_ALLOW, $teacherrole->id, $modulecontext->id, true); accesslib_clear_all_caches_for_unit_testing(); - $modulecontext = context_module::instance($assign->cmid); + $modulecontext = \context_module::instance($assign->cmid); $this->assertTrue(has_capability('moodle/site:config', $modulecontext)); $providers = message_get_providers_for_user($teacher->id); @@ -172,7 +171,7 @@ class core_messagelib_testcase extends advanced_testcase { // They should not be able to see the backup message. assign_capability('moodle/site:config', CAP_PROHIBIT, $teacherrole->id, $coursecontext->id, true); accesslib_clear_all_caches_for_unit_testing(); - $modulecontext = context_module::instance($assign->cmid); + $modulecontext = \context_module::instance($assign->cmid); $this->assertFalse(has_capability('moodle/site:config', $modulecontext)); $providers = message_get_providers_for_user($teacher->id); @@ -290,7 +289,7 @@ class core_messagelib_testcase extends advanced_testcase { $sink = $this->redirectMessages(); try { message_send($message); - } catch (moodle_exception $e) { + } catch (\moodle_exception $e) { $this->assertInstanceOf('coding_exception', $e); } $this->assertCount(0, $sink->get_messages()); @@ -302,7 +301,7 @@ class core_messagelib_testcase extends advanced_testcase { $sink = $this->redirectMessages(); try { message_send($message); - } catch (moodle_exception $e) { + } catch (\moodle_exception $e) { $this->assertInstanceOf('coding_exception', $e); } $this->assertCount(0, $sink->get_messages()); @@ -352,7 +351,7 @@ class core_messagelib_testcase extends advanced_testcase { $message->component = 'moodle'; $message->name = 'instantmessage'; $message->userfrom = $user1; - $message->userto = core_user::NOREPLY_USER; + $message->userto = \core_user::NOREPLY_USER; $message->subject = 'message subject 1'; $message->fullmessage = 'message body'; $message->fullmessageformat = FORMAT_MARKDOWN; @@ -723,8 +722,8 @@ class core_messagelib_testcase extends advanced_testcase { $events = $eventsink->get_events(); $this->assertCount(0, $events); try { - $transaction->rollback(new Exception('ignore')); - } catch (Exception $e) { + $transaction->rollback(new \Exception('ignore')); + } catch (\Exception $e) { $this->assertSame('ignore', $e->getMessage()); } $events = $eventsink->get_events(); @@ -918,7 +917,7 @@ class core_messagelib_testcase extends advanced_testcase { 'core_group', 'groups', $group1->id, - context_course::instance($course->id)->id + \context_course::instance($course->id)->id ); // Generate the message. @@ -1003,7 +1002,7 @@ class core_messagelib_testcase extends advanced_testcase { 'core_group', 'groups', $group1->id, - context_course::instance($course->id)->id + \context_course::instance($course->id)->id ); // Test basic email redirection. @@ -1093,18 +1092,18 @@ class core_messagelib_testcase extends advanced_testcase { $this->assertEquals(0, $mailsink->count()); try { - $transaction2->rollback(new Exception('x')); + $transaction2->rollback(new \Exception('x')); $this->fail('Expecting exception'); - } catch (Exception $e) {} + } catch (\Exception $e) {} $this->assertDebuggingNotCalled(); $this->assertEquals(0, $mailsink->count()); $this->assertTrue($DB->is_transaction_started()); try { - $transaction1->rollback(new Exception('x')); + $transaction1->rollback(new \Exception('x')); $this->fail('Expecting exception'); - } catch (Exception $e) {} + } catch (\Exception $e) {} $this->assertDebuggingNotCalled(); $this->assertEquals(0, $mailsink->count()); @@ -1168,7 +1167,7 @@ class core_messagelib_testcase extends advanced_testcase { unset_config('noemailever'); $user = $this->getDataGenerator()->create_user(); - $context = context_user::instance($user->id); + $context = \context_user::instance($user->id); // Create a test file. $fs = get_file_storage(); diff --git a/lib/tests/progress_test.php b/lib/tests/progress_test.php index 5181f4f59d4..31496cdd1a3 100644 --- a/lib/tests/progress_test.php +++ b/lib/tests/progress_test.php @@ -14,21 +14,19 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the progress classes. - * - * @package core_progress - * @category phpunit - * @copyright 2013 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core; defined('MOODLE_INTERNAL') || die(); /** - * Progress tests. + * Unit tests for the progress classes. + * + * @package core + * @category test + * @copyright 2013 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_progress_testcase extends basic_testcase { +class progress_test extends \basic_testcase { /** * Tests for basic use with simple numeric progress. @@ -52,11 +50,11 @@ class core_progress_testcase extends basic_testcase { // Make some progress and check that the time limit gets added. $progress->step_time(); - core_php_time_limit::get_and_clear_unit_test_data(); + \core_php_time_limit::get_and_clear_unit_test_data(); $progress->progress(2); $this->assertTrue($progress->was_update_called()); $this->assertEquals(array(\core\progress\base::TIME_LIMIT_WITHOUT_PROGRESS), - core_php_time_limit::get_and_clear_unit_test_data()); + \core_php_time_limit::get_and_clear_unit_test_data()); // Check the new value. $this->assert_min_max(0.2, 0.2, $progress); @@ -231,25 +229,25 @@ class core_progress_testcase extends basic_testcase { try { $progress->progress(); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertEquals(1, preg_match('~without start_progress~', $e->getMessage())); } try { $progress->end_progress(); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertEquals(1, preg_match('~without start_progress~', $e->getMessage())); } try { $progress->get_current_description(); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertEquals(1, preg_match('~Not inside progress~', $e->getMessage())); } try { $progress->start_progress('', 1, 7); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertEquals(1, preg_match('~must be 1~', $e->getMessage())); } @@ -257,7 +255,7 @@ class core_progress_testcase extends basic_testcase { try { $progress->start_progress('hello', -2); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertEquals(1, preg_match('~cannot be negative~', $e->getMessage())); } @@ -266,7 +264,7 @@ class core_progress_testcase extends basic_testcase { try { $progress->progress(\core\progress\base::INDETERMINATE); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertEquals(1, preg_match('~expecting value~', $e->getMessage())); } @@ -275,7 +273,7 @@ class core_progress_testcase extends basic_testcase { try { $progress->progress(4); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertEquals(1, preg_match('~expecting INDETERMINATE~', $e->getMessage())); } @@ -284,13 +282,13 @@ class core_progress_testcase extends basic_testcase { try { $progress->progress(-2); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertEquals(1, preg_match('~out of range~', $e->getMessage())); } try { $progress->progress(11); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertEquals(1, preg_match('~out of range~', $e->getMessage())); } @@ -304,7 +302,7 @@ class core_progress_testcase extends basic_testcase { try { $progress->progress(3); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertEquals(1, preg_match('~backwards~', $e->getMessage())); } @@ -312,7 +310,7 @@ class core_progress_testcase extends basic_testcase { try { $progress->start_progress('', 1, 7); $this->fail(); - } catch (coding_exception $e) { + } catch (\coding_exception $e) { $this->assertEquals(1, preg_match('~would exceed max~', $e->getMessage())); } } diff --git a/lib/tests/rsslib_test.php b/lib/tests/rsslib_test.php index 0db975b54a4..ff0674595b8 100644 --- a/lib/tests/rsslib_test.php +++ b/lib/tests/rsslib_test.php @@ -14,6 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core; + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once($CFG->libdir.'/simplepie/moodle_simplepie.php'); + + /** * These tests rely on the rsstest.xml file on download.moodle.org, * from eloys listing: @@ -24,30 +32,23 @@ * If networking/proxy configuration is wrong these tests will fail.. * * @package core - * @category phpunit + * @category test * @copyright 2009 Dan Poltawski * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -global $CFG; -require_once($CFG->libdir.'/simplepie/moodle_simplepie.php'); - - -class core_rsslib_testcase extends advanced_testcase { +class rsslib_test extends \advanced_testcase { // The number of seconds tests should wait for the server to respond (high to prevent false positives). const TIMEOUT = 10; protected function setUp(): void { - moodle_simplepie::reset_cache(); + \moodle_simplepie::reset_cache(); } public function test_getfeed() { - $feed = new moodle_simplepie($this->getExternalTestFileUrl('/rsstest.xml'), self::TIMEOUT); + $feed = new \moodle_simplepie($this->getExternalTestFileUrl('/rsstest.xml'), self::TIMEOUT); - $this->assertInstanceOf('moodle_simplepie', $feed); + $this->assertInstanceOf('\moodle_simplepie', $feed); $this->assertNull($feed->error(), "Failed to load the sample RSS file. Please check your proxy settings in Moodle. %s"); @@ -103,7 +104,7 @@ EOD; // We do not want this in php error log. $errorlevel = error_reporting($CFG->debug & ~E_USER_NOTICE); - $feed = new moodle_simplepie($this->getExternalTestFileUrl('/rsstest-which-doesnt-exist.xml'), self::TIMEOUT); + $feed = new \moodle_simplepie($this->getExternalTestFileUrl('/rsstest-which-doesnt-exist.xml'), self::TIMEOUT); error_reporting($errorlevel); $this->assertNotEmpty($feed->error()); @@ -121,7 +122,7 @@ EOD; $oldproxybypass = $CFG->proxybypass; // Ensure we don't get locally served extests bypassing the proxy. $CFG->proxybypass = ''; - $feed = new moodle_simplepie($this->getExternalTestFileUrl('/rsstest.xml')); + $feed = new \moodle_simplepie($this->getExternalTestFileUrl('/rsstest.xml')); $this->assertNotEmpty($feed->error()); $this->assertEmpty($feed->get_title()); @@ -133,7 +134,7 @@ EOD; * Test retrieving a url which sends a redirect to another valid feed. */ public function test_redirect() { - $feed = new moodle_simplepie($this->getExternalTestFileUrl('/rss_redir.php'), self::TIMEOUT); + $feed = new \moodle_simplepie($this->getExternalTestFileUrl('/rss_redir.php'), self::TIMEOUT); $this->assertNull($feed->error()); $this->assertSame('Moodle News', $feed->get_title()); diff --git a/lib/tests/scss_test.php b/lib/tests/scss_test.php index 55e7cd902fe..ea53368e423 100644 --- a/lib/tests/scss_test.php +++ b/lib/tests/scss_test.php @@ -14,16 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains the unittests for core scss. - * - * @package core - * @category phpunit - * @copyright 2016 onwards Ankit Agarwal - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core; -defined('MOODLE_INTERNAL') || die(); +use core_scss; /** * This file contains the unittests for core scss. @@ -33,14 +26,14 @@ defined('MOODLE_INTERNAL') || die(); * @copyright 2016 onwards Ankit Agarwal * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_scss_testcase extends advanced_testcase { +class scss_test extends \advanced_testcase { /** * Data provider for is_valid_file * @return array */ public function is_valid_file_provider() { - $themedirectory = core_component::get_component_directory('theme_boost'); + $themedirectory = \core_component::get_component_directory('theme_boost'); $realroot = realpath($themedirectory); return [ "File import 1" => [ @@ -130,7 +123,7 @@ CSS */ public function test_is_valid_file($path, $valid) { $scss = new \core_scss(); - $pathvalid = phpunit_util::call_internal_method($scss, 'is_valid_file', [$path], \core_scss::class); + $pathvalid = \phpunit_util::call_internal_method($scss, 'is_valid_file', [$path], \core_scss::class); $this->assertSame($valid, $pathvalid); } diff --git a/media/player/html5audio/tests/player_test.php b/media/player/html5audio/tests/player_test.php index 63fb1757743..b5285cb23a9 100644 --- a/media/player/html5audio/tests/player_test.php +++ b/media/player/html5audio/tests/player_test.php @@ -14,15 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Test classes for handling embedded media. - * - * @package media_html5audio - * @copyright 2016 Marina Glancy - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace media_html5audio; -defined('MOODLE_INTERNAL') || die(); +use core_media_manager; +use media_html5audio_plugin; /** * Test script for media embedding. @@ -31,7 +26,7 @@ defined('MOODLE_INTERNAL') || die(); * @copyright 2016 Marina Glancy * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class media_html5audio_testcase extends advanced_testcase { +class player_test extends \advanced_testcase { /** * Pre-test setup. Preserves $CFG. @@ -46,7 +41,7 @@ class media_html5audio_testcase extends advanced_testcase { \core\plugininfo\media::set_enabled_plugins('html5audio'); // Pretend to be using Firefox browser (must support ogg for tests to work). - core_useragent::instance(true, 'Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0 '); + \core_useragent::instance(true, 'Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0 '); } /** @@ -83,7 +78,7 @@ class media_html5audio_testcase extends advanced_testcase { // Create list of URLs for each extension. $urls = array_map(function($ext){ - return new moodle_url('http://example.org/audio.' . $ext); + return new \moodle_url('http://example.org/audio.' . $ext); }, $nativeextensions); // Make sure that the list of supported URLs is not filtering permitted extensions. @@ -97,7 +92,7 @@ class media_html5audio_testcase extends advanced_testcase { public function test_embed_url() { global $CFG; - $url = new moodle_url('http://example.org/1.wav'); + $url = new \moodle_url('http://example.org/1.wav'); $manager = core_media_manager::instance(); $embedoptions = array( @@ -126,8 +121,8 @@ class media_html5audio_testcase extends advanced_testcase { * filter_mediaplugin is enabled by default. */ public function test_embed_link() { - $url = new moodle_url('http://example.org/some_filename.wav'); - $text = html_writer::link($url, 'Watch this one'); + $url = new \moodle_url('http://example.org/some_filename.wav'); + $text = \html_writer::link($url, 'Watch this one'); $content = format_text($text, FORMAT_HTML); $this->assertMatchesRegularExpression('~mediaplugin_html5audio~', $content); @@ -140,8 +135,8 @@ class media_html5audio_testcase extends advanced_testcase { * Test that mediaplugin filter does not work on