MDL-73659 phpunit: restore_date, api, rule, plugin, manager & helper

All restore_date_test, api_test, rule_test, plugin_test,
manager_test, helper_test 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:

- All restore_date_test cases have been put under xxx\backup
  level 2 (valid API) namespace.
This commit is contained in:
Eloy Lafuente (stronk7) 2022-01-21 22:59:40 +01:00
parent 6652ec135b
commit 7a0d024e60
58 changed files with 1606 additions and 1974 deletions

View File

@ -14,17 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* API tests.
*
* @package tool_cohortroles
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
use tool_cohortroles\api;
namespace tool_cohortroles;
/**
* API tests.
@ -33,17 +23,17 @@ use tool_cohortroles\api;
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_cohortroles_api_testcase extends advanced_testcase {
/** @var stdClass $cohort */
class api_test extends \advanced_testcase {
/** @var \stdClass $cohort */
protected $cohort = null;
/** @var stdClass $userassignto */
/** @var \stdClass $userassignto */
protected $userassignto = null;
/** @var stdClass $userassignover */
/** @var \stdClass $userassignover */
protected $userassignover = null;
/** @var stdClass $role */
/** @var \stdClass $role */
protected $role = null;
/**
@ -67,7 +57,7 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
'roleid' => $this->roleid,
'cohortid' => $this->cohort->id
);
$this->expectException(required_capability_exception::class);
$this->expectException(\required_capability_exception::class);
api::create_cohort_role_assignment($params);
}
@ -105,7 +95,7 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
);
$result = api::create_cohort_role_assignment($params);
$this->setUser($this->userassignto);
$this->expectException(required_capability_exception::class);
$this->expectException(\required_capability_exception::class);
api::delete_cohort_role_assignment($result->get('id'));
}
@ -117,7 +107,7 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
'cohortid' => $this->cohort->id
);
$result = api::create_cohort_role_assignment($params);
$this->expectException(dml_missing_record_exception::class);
$this->expectException(\dml_missing_record_exception::class);
api::delete_cohort_role_assignment($result->get('id') + 1);
}
@ -274,7 +264,7 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
$this->assertEquals($sync, $expected);
// Verify roles assigned by any other component are not removed.
$usercontext = context_user::instance($this->userassignover->id);
$usercontext = \context_user::instance($this->userassignover->id);
role_assign($this->roleid, $this->userassignto->id, $usercontext->id);
$sync = api::sync_all_cohort_roles();

View File

@ -14,29 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* API tests.
*
* @package tool_dataprivacy
* @copyright 2018 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_dataprivacy;
use core\invalid_persistent_exception;
use core\task\manager;
use tool_dataprivacy\context_instance;
use tool_dataprivacy\api;
use tool_dataprivacy\data_registry;
use tool_dataprivacy\expired_context;
use tool_dataprivacy\data_request;
use tool_dataprivacy\purpose;
use tool_dataprivacy\category;
use testing_data_generator;
use tool_dataprivacy\local\helper;
use tool_dataprivacy\task\process_data_request_task;
defined('MOODLE_INTERNAL') || die();
global $CFG;
/**
* API tests.
*
@ -44,7 +29,7 @@ global $CFG;
* @copyright 2018 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_dataprivacy_api_testcase extends advanced_testcase {
class api_test extends \advanced_testcase {
/**
* Ensure that the check_can_manage_data_registry function fails cap testing when a user without capabilities is
@ -68,7 +53,7 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
$this->expectException(required_capability_exception::class);
$this->expectException(\required_capability_exception::class);
api::check_can_manage_data_registry();
}
@ -82,7 +67,7 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
$this->expectException(required_capability_exception::class);
$this->expectException(\required_capability_exception::class);
api::check_can_manage_data_registry(\context_system::instance()->id);
}
@ -96,7 +81,7 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
$this->expectException(required_capability_exception::class);
$this->expectException(\required_capability_exception::class);
api::check_can_manage_data_registry(\context_user::instance($user->id)->id);
}
@ -174,7 +159,7 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
$u1 = $generator->create_user();
$u2 = $generator->create_user();
$context = context_system::instance();
$context = \context_system::instance();
// Give the manager role with the capability to manage data requests.
$managerroleid = $DB->get_field('role', 'id', array('shortname' => 'manager'));
@ -215,7 +200,7 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
// Confirm that the returned list is empty.
$this->assertEmpty($roleids);
$context = context_system::instance();
$context = \context_system::instance();
// Give the manager role with the capability to manage data requests.
assign_capability('tool/dataprivacy:managedatarequests', CAP_ALLOW, $managerroleid, $context->id, true);
@ -254,7 +239,7 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
$s1 = $generator->create_user();
$u1 = $generator->create_user();
$context = context_system::instance();
$context = \context_system::instance();
// Manager role.
$managerroleid = $DB->get_field('role', 'id', array('shortname' => 'manager'));
@ -304,7 +289,7 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
// Login as a user without DPO role.
$this->setUser($teacher);
$this->expectException(required_capability_exception::class);
$this->expectException(\required_capability_exception::class);
api::approve_data_request($requestid);
}
@ -327,8 +312,8 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
$this->assertEquals(api::DATAREQUEST_STATUS_REJECTED, $request->get('status'));
// Confirm they weren't deleted.
$user = core_user::get_user($request->get('userid'));
core_user::require_active_user($user);
$user = \core_user::get_user($request->get('userid'));
\core_user::require_active_user($user);
}
/**
@ -366,7 +351,7 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
$nondpocapable = $generator->create_user();
$nondpoincapable = $generator->create_user();
$context = context_system::instance();
$context = \context_system::instance();
// Manager role.
$managerroleid = $DB->get_field('role', 'id', array('shortname' => 'manager'));
@ -666,8 +651,8 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
$comment = 'sample comment';
// Get the teacher role pretend it's the parent roles ;).
$systemcontext = context_system::instance();
$usercontext = context_user::instance($user->id);
$systemcontext = \context_system::instance();
$usercontext = \context_user::instance($user->id);
$parentroleid = $DB->get_field('role', 'id', array('shortname' => 'teacher'));
// Give the manager role with the capability to manage data requests.
assign_capability('tool/dataprivacy:makedatarequestsforchildren', CAP_ALLOW, $parentroleid, $systemcontext->id, true);
@ -923,7 +908,7 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
$dpo = $generator->create_user();
$nondpo = $generator->create_user();
$context = context_system::instance();
$context = \context_system::instance();
// Manager role.
$managerroleid = $DB->get_field('role', 'id', array('shortname' => 'manager'));
@ -1222,7 +1207,7 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
*/
public function test_set_contextlevel_invalid_contextlevels($contextlevel) {
$this->expectException(coding_exception::class);
$this->expectException(\coding_exception::class);
api::set_contextlevel((object) [
'contextlevel' => $contextlevel,
]);
@ -1291,7 +1276,7 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
'categoryid' => $category1->get('id'),
]);
$this->expectException(coding_exception::class);
$this->expectException(\coding_exception::class);
api::get_effective_contextlevel_purpose($contextlevel);
}
@ -1908,14 +1893,14 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
$assign = $generator->create_module('assign', ['course' => $course->id]);
$forum = $generator->create_module('forum', ['course' => $course->id]);
$coursecatcontext = context_coursecat::instance($coursecat->id);
$coursecontext = context_course::instance($course->id);
$blockcontext = context_block::instance($block->id);
$coursecatcontext = \context_coursecat::instance($coursecat->id);
$coursecontext = \context_course::instance($course->id);
$blockcontext = \context_block::instance($block->id);
list($course, $assigncm) = get_course_and_cm_from_instance($assign->id, 'assign');
list($course, $forumcm) = get_course_and_cm_from_instance($forum->id, 'forum');
$assigncontext = context_module::instance($assigncm->id);
$forumcontext = context_module::instance($forumcm->id);
$assigncontext = \context_module::instance($assigncm->id);
$forumcontext = \context_module::instance($forumcm->id);
// Generate purposes and categories.
$category1 = api::create_category((object)['name' => 'Test category 1']);
@ -2199,8 +2184,8 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
$this->resetAfterTest();
$userid = $this->getDataGenerator()->create_user()->id;
$roleid = $this->getDataGenerator()->create_role();
assign_capability('tool/dataprivacy:requestdelete', CAP_PROHIBIT, $roleid, context_user::instance($userid));
role_assign($roleid, $userid, context_user::instance($userid));
assign_capability('tool/dataprivacy:requestdelete', CAP_PROHIBIT, $roleid, \context_user::instance($userid));
role_assign($roleid, $userid, \context_user::instance($userid));
$this->setUser($userid);
$this->assertFalse(api::can_create_data_deletion_request_for_self());
}
@ -2269,7 +2254,7 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
$this->resetAfterTest();
$userid = $this->getDataGenerator()->create_user()->id;
$roleid = $this->getDataGenerator()->create_role();
$contextsystem = context_system::instance();
$contextsystem = \context_system::instance();
assign_capability('tool/dataprivacy:requestdeleteforotheruser', CAP_ALLOW, $roleid, $contextsystem);
role_assign($roleid, $userid, $contextsystem);
$this->setUser($userid);

View File

@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace tool_log;
/**
* Log manager and log API tests.
*
@ -21,10 +23,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;
class tool_log_manager_testcase extends advanced_testcase {
class manager_test extends \advanced_testcase {
public function test_get_log_manager() {
global $CFG;
$this->resetAfterTest();

View File

@ -14,18 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Manager tests.
*
* @package tool_messageinbound
* @category test
* @copyright 2018 Frédéric Massart
* @author Frédéric Massart <fred@branchup.tech>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
namespace tool_messageinbound;
use core_privacy\tests\provider_testcase;
use core_privacy\local\request\approved_contextlist;
@ -42,7 +31,7 @@ use tool_messageinbound\privacy\provider;
* @author Frédéric Massart <fred@branchup.tech>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_messageinbound_manager_testcase extends provider_testcase {
class manager_test extends provider_testcase {
public function setUp(): void {
global $CFG;

View File

@ -14,15 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Moodle Mobile admin tool api tests.
*
* @package tool_mobile
* @category external
* @copyright 2016 Juan Leyva
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.1
*/
namespace tool_mobile;
defined('MOODLE_INTERNAL') || die();
@ -30,8 +22,6 @@ global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
use tool_mobile\api;
/**
* Moodle Mobile admin tool api tests.
*
@ -40,7 +30,7 @@ use tool_mobile\api;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.1
*/
class tool_mobile_api_testcase extends externallib_advanced_testcase {
class api_test extends \externallib_advanced_testcase {
/**
* Test get_autologin_key.

View File

@ -14,30 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Provides the {@link tool_policy_api_testcase} class.
*
* @package tool_policy
* @category test
* @copyright 2018 David Mudrák <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_policy;
use tool_policy\api;
use tool_policy\policy_version;
use tool_policy\test\helper;
defined('MOODLE_INTERNAL') || die();
global $CFG;
/**
* Unit tests for the {@link \tool_policy\api} class.
*
* @package tool_policy
* @category test
* @copyright 2018 David Mudrak <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_policy_api_testcase extends advanced_testcase {
class api_test extends \advanced_testcase {
/**
* Test the common operations with a policy document and its versions.
@ -257,8 +246,8 @@ class tool_policy_api_testcase extends advanced_testcase {
$officer = $this->getDataGenerator()->create_user();
$manager = $this->getDataGenerator()->create_user();
$syscontext = context_system::instance();
$childcontext = context_user::instance($child->id);
$syscontext = \context_system::instance();
$childcontext = \context_user::instance($child->id);
$roleminorid = create_role('Digital minor', 'digiminor', 'Not old enough to accept site policies themselves');
$roleparentid = create_role('Parent', 'parent', 'Can accept policies on behalf of their child');
@ -336,8 +325,8 @@ class tool_policy_api_testcase extends advanced_testcase {
$officer = $this->getDataGenerator()->create_user();
$manager = $this->getDataGenerator()->create_user();
$syscontext = context_system::instance();
$childcontext = context_user::instance($child->id);
$syscontext = \context_system::instance();
$childcontext = \context_user::instance($child->id);
$roleminorid = create_role('Digital minor', 'digiminor', 'Not old enough to accept site policies themselves');
$roleparentid = create_role('Parent', 'parent', 'Can accept policies on behalf of their child');
@ -412,8 +401,8 @@ class tool_policy_api_testcase extends advanced_testcase {
$officer = $this->getDataGenerator()->create_user();
$manager = $this->getDataGenerator()->create_user();
$syscontext = context_system::instance();
$childcontext = context_user::instance($child->id);
$syscontext = \context_system::instance();
$childcontext = \context_user::instance($child->id);
$roleminorid = create_role('Digital minor', 'digiminor', 'Not old enough to accept site policies themselves');
$roleparentid = create_role('Parent', 'parent', 'Can accept policies on behalf of their child');
@ -494,8 +483,8 @@ class tool_policy_api_testcase extends advanced_testcase {
$officer = $this->getDataGenerator()->create_user();
$manager = $this->getDataGenerator()->create_user();
$syscontext = context_system::instance();
$childcontext = context_user::instance($child->id);
$syscontext = \context_system::instance();
$childcontext = \context_user::instance($child->id);
$roleminorid = create_role('Digital minor', 'digiminor', 'Not old enough to accept site policies themselves');
$roleparentid = create_role('Parent', 'parent', 'Can accept policies on behalf of their child');
@ -693,9 +682,9 @@ class tool_policy_api_testcase extends advanced_testcase {
$child1 = $this->getDataGenerator()->create_user();
$child2 = $this->getDataGenerator()->create_user();
$syscontext = context_system::instance();
$child1context = context_user::instance($child1->id);
$child2context = context_user::instance($child2->id);
$syscontext = \context_system::instance();
$child1context = \context_user::instance($child1->id);
$child2context = \context_user::instance($child2->id);
$roleparentid = create_role('Parent', 'parent', 'Can accept policies on behalf of their child');

View File

@ -14,17 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* File containing tests for the helper.
*
* @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_helper;
/**
* Helper test case.
@ -33,7 +25,7 @@ global $CFG;
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_uploadcourse_helper_testcase extends advanced_testcase {
class helper_test extends \advanced_testcase {
public function test_generate_shortname() {
$data = (object) array('fullname' => 'Ah bh Ch 01 02 03', 'idnumber' => 'ID123');
@ -53,7 +45,7 @@ class tool_uploadcourse_helper_testcase extends advanced_testcase {
public function test_get_course_formats() {
$result = tool_uploadcourse_helper::get_course_formats();
$this->assertSame(array_keys(core_component::get_plugin_list('format')), $result);
$this->assertSame(array_keys(\core_component::get_plugin_list('format')), $result);
// Should be similar as first result, as cached.
$this->assertSame($result, tool_uploadcourse_helper::get_course_formats());
}
@ -122,8 +114,8 @@ class tool_uploadcourse_helper_testcase extends advanced_testcase {
$c2 = $this->getDataGenerator()->create_course((object) array('shortname' => 'Yay'));
// Creating backup file.
$bc = new backup_controller(backup::TYPE_1COURSE, $c1->id, backup::FORMAT_MOODLE,
backup::INTERACTIVE_NO, backup::MODE_GENERAL, 2);
$bc = new \backup_controller(\backup::TYPE_1COURSE, $c1->id, \backup::FORMAT_MOODLE,
\backup::INTERACTIVE_NO, \backup::MODE_GENERAL, 2);
$bc->execute_plan();
$result = $bc->get_results();
$this->assertTrue(isset($result['backup_destination']));
@ -131,8 +123,8 @@ class tool_uploadcourse_helper_testcase extends advanced_testcase {
$bc->destroy();
// Creating backup file.
$bc = new backup_controller(backup::TYPE_1COURSE, $c2->id, backup::FORMAT_MOODLE,
backup::INTERACTIVE_NO, backup::MODE_GENERAL, 2);
$bc = new \backup_controller(\backup::TYPE_1COURSE, $c2->id, \backup::FORMAT_MOODLE,
\backup::INTERACTIVE_NO, \backup::MODE_GENERAL, 2);
$bc->execute_plan();
$result = $bc->get_results();
$this->assertTrue(isset($result['backup_destination']));
@ -144,7 +136,7 @@ class tool_uploadcourse_helper_testcase extends advanced_testcase {
// Checking restore dir.
$dir = tool_uploadcourse_helper::get_restore_content_dir($c1backupfile, null);
$bcinfo = backup_general_helper::get_backup_information($dir);
$bcinfo = \backup_general_helper::get_backup_information($dir);
$this->assertEquals($bcinfo->original_course_id, $c1->id);
$this->assertEquals($bcinfo->original_course_fullname, $c1->fullname);
@ -154,13 +146,13 @@ class tool_uploadcourse_helper_testcase extends advanced_testcase {
// Get the second course.
$dir = tool_uploadcourse_helper::get_restore_content_dir($c2backupfile, null);
$bcinfo = backup_general_helper::get_backup_information($dir);
$bcinfo = \backup_general_helper::get_backup_information($dir);
$this->assertEquals($bcinfo->original_course_id, $c2->id);
$this->assertEquals($bcinfo->original_course_fullname, $c2->fullname);
// Checking with a shortname.
$dir = tool_uploadcourse_helper::get_restore_content_dir(null, $c1->shortname);
$bcinfo = backup_general_helper::get_backup_information($dir);
$bcinfo = \backup_general_helper::get_backup_information($dir);
$this->assertEquals($bcinfo->original_course_id, $c1->id);
$this->assertEquals($bcinfo->original_course_fullname, $c1->fullname);
@ -170,7 +162,7 @@ class tool_uploadcourse_helper_testcase extends advanced_testcase {
// Get the second course.
$dir = tool_uploadcourse_helper::get_restore_content_dir(null, $c2->shortname);
$bcinfo = backup_general_helper::get_backup_information($dir);
$bcinfo = \backup_general_helper::get_backup_information($dir);
$this->assertEquals($bcinfo->original_course_id, $c2->id);
$this->assertEquals($bcinfo->original_course_fullname, $c2->fullname);
@ -271,19 +263,19 @@ class tool_uploadcourse_helper_testcase extends advanced_testcase {
$this->assertCount(5, $fields);
$this->assertArrayHasKey($checkboxfield->get('shortname'), $fields);
$this->assertInstanceOf(customfield_checkbox\field_controller::class, $fields[$checkboxfield->get('shortname')]);
$this->assertInstanceOf(\customfield_checkbox\field_controller::class, $fields[$checkboxfield->get('shortname')]);
$this->assertArrayHasKey($datefield->get('shortname'), $fields);
$this->assertInstanceOf(customfield_date\field_controller::class, $fields[$datefield->get('shortname')]);
$this->assertInstanceOf(\customfield_date\field_controller::class, $fields[$datefield->get('shortname')]);
$this->assertArrayHasKey($selectfield->get('shortname'), $fields);
$this->assertInstanceOf(customfield_select\field_controller::class, $fields[$selectfield->get('shortname')]);
$this->assertInstanceOf(\customfield_select\field_controller::class, $fields[$selectfield->get('shortname')]);
$this->assertArrayHasKey($textfield->get('shortname'), $fields);
$this->assertInstanceOf(customfield_text\field_controller::class, $fields[$textfield->get('shortname')]);
$this->assertInstanceOf(\customfield_text\field_controller::class, $fields[$textfield->get('shortname')]);
$this->assertArrayHasKey($textareafield->get('shortname'), $fields);
$this->assertInstanceOf(customfield_textarea\field_controller::class, $fields[$textareafield->get('shortname')]);
$this->assertInstanceOf(\customfield_textarea\field_controller::class, $fields[$textareafield->get('shortname')]);
$data = [
'customfield_mycheckbox' => '1',
@ -304,7 +296,7 @@ class tool_uploadcourse_helper_testcase extends advanced_testcase {
$user = $this->getDataGenerator()->create_and_enrol($course, 'manager');
$this->setUser($user);
$context = context_course::instance($course->id);
$context = \context_course::instance($course->id);
$this->assertEquals($expected, tool_uploadcourse_helper::get_custom_course_field_data($data, [], $context));
@ -475,7 +467,7 @@ class tool_uploadcourse_helper_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');
}
@ -498,4 +490,4 @@ class tool_uploadcourse_helper_testcase extends advanced_testcase {
'configdata' => $configdata,
]);
}
}
}

View File

@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Tests for manager.
*
* @package tool_usertours
* @copyright 2016 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_usertours;
defined('MOODLE_INTERNAL') || die();
@ -35,9 +29,9 @@ require_once(__DIR__ . '/helper_trait.php');
* @copyright 2016 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_usertours_manager_testcase extends advanced_testcase {
class manager_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;
/**
* @var moodle_database
@ -190,7 +184,7 @@ class tool_usertours_manager_testcase extends advanced_testcase {
$tour = \tool_usertours\tour::load_from_record($record);
// Call protected method via reflection.
$class = new ReflectionClass(\tool_usertours\manager::class);
$class = new \ReflectionClass(\tool_usertours\manager::class);
$method = $class->getMethod('_move_tour');
$method->setAccessible(true);
$method->invokeArgs(null, [$tour, $direction]);
@ -332,7 +326,7 @@ class tool_usertours_manager_testcase extends advanced_testcase {
$this->helper_create_step((object) ['tourid' => $tour->get_id()]);
}
$matches = \tool_usertours\manager::get_matching_tours(new moodle_url($url));
$matches = \tool_usertours\manager::get_matching_tours(new \moodle_url($url));
$this->assertEquals(count($expected), count($matches));
for ($i = 0; $i < count($matches); $i++) {
$this->assertEquals($expected[$i], $matches[$i]->get_name());
@ -360,12 +354,12 @@ class tool_usertours_manager_testcase extends advanced_testcase {
'tourid' => $tour->get_id(),
]);
$matches = \tool_usertours\manager::get_matching_tours(new moodle_url('/'));
$matches = \tool_usertours\manager::get_matching_tours(new \moodle_url('/'));
$this->assertEquals(1, count($matches));
$CFG->sitepolicyguest = 'https://example.com';
$matches = \tool_usertours\manager::get_matching_tours(new moodle_url('/'));
$matches = \tool_usertours\manager::get_matching_tours(new \moodle_url('/'));
$this->assertEmpty($matches);
}
}

View File

@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for the manager.
*
* @package core_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();
@ -30,13 +24,13 @@ require_once(__DIR__ . '/fixtures/test_indicator_fullname.php');
require_once(__DIR__ . '/fixtures/test_target_course_level_shortname.php');
/**
* Unit tests for the manager.
* Unit tests for the core_analytics manager.
*
* @package core_analytics
* @copyright 2017 David Monllaó {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class analytics_manager_testcase extends advanced_testcase {
class manager_test extends \advanced_testcase {
/**
* test_deleted_context

View File

@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace auth_ldap;
/**
* LDAP authentication plugin tests.
*
@ -31,10 +33,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();
class auth_ldap_plugin_testcase extends advanced_testcase {
class plugin_test extends \advanced_testcase {
/**
* Data provider for auth_ldap tests
@ -164,7 +163,7 @@ class auth_ldap_plugin_testcase extends advanced_testcase {
$this->assertEquals(2, $DB->count_records('user'));
$this->assertEquals(0, $DB->count_records('role_assignments'));
/** @var auth_plugin_ldap $auth */
/** @var \auth_plugin_ldap $auth */
$auth = get_auth_plugin('ldap');
ob_start();
@ -224,7 +223,7 @@ class auth_ldap_plugin_testcase extends advanced_testcase {
set_config('removeuser', AUTH_REMOVEUSER_SUSPEND, 'auth_ldap');
/** @var auth_plugin_ldap $auth */
/** @var \auth_plugin_ldap $auth */
$auth = get_auth_plugin('ldap');
ob_start();
@ -288,7 +287,7 @@ class auth_ldap_plugin_testcase extends advanced_testcase {
set_config('removeuser', AUTH_REMOVEUSER_FULLDELETE, 'auth_ldap');
/** @var auth_plugin_ldap $auth */
/** @var \auth_plugin_ldap $auth */
$auth = get_auth_plugin('ldap');
$this->delete_ldap_user($connection, $topdn, 1);
@ -357,7 +356,7 @@ class auth_ldap_plugin_testcase extends advanced_testcase {
// Note: we are just going to trigger the function that calls the event,
// not actually perform a LDAP login, for the sake of sanity.
$ldap = new auth_plugin_ldap();
$ldap = new \auth_plugin_ldap();
// Set the key for the cache flag we want to set which is used by LDAP.
set_cache_flag($ldap->pluginconfig . '/ntlmsess', sesskey(), $user->username, AUTH_NTLMTIMEOUT);
@ -379,7 +378,7 @@ class auth_ldap_plugin_testcase extends advanced_testcase {
$this->assertInstanceOf('\core\event\user_loggedin', $event);
$this->assertEquals('user', $event->objecttable);
$this->assertEquals('2', $event->objectid);
$this->assertEquals(context_system::instance()->id, $event->contextid);
$this->assertEquals(\context_system::instance()->id, $event->contextid);
$expectedlog = array(SITEID, 'user', 'login', 'view.php?id=' . $USER->id . '&course=' . SITEID, $user->id,
0, $user->id);
$this->assertEventLegacyLogData($expectedlog, $event);
@ -488,7 +487,7 @@ class auth_ldap_plugin_testcase extends advanced_testcase {
$this->assertEquals(2, $DB->count_records('user'));
$this->assertEquals(0, $DB->count_records('role_assignments'));
/** @var auth_plugin_ldap $auth */
/** @var \auth_plugin_ldap $auth */
$auth = get_auth_plugin('ldap');
$sink = $this->redirectEvents();
@ -510,7 +509,7 @@ class auth_ldap_plugin_testcase extends advanced_testcase {
$this->assertInstanceOf('\core\event\user_created', $event);
$this->assertEquals($user['id'], $event->objectid);
$this->assertEquals('user_created', $event->get_legacy_eventname());
$this->assertEquals(context_user::instance($user['id']), $event->get_context());
$this->assertEquals(\context_user::instance($user['id']), $event->get_context());
$expectedlogdata = array(SITEID, 'user', 'add', '/view.php?id='.$event->objectid, fullname($dbuser));
$this->assertEventLegacyLogData($expectedlogdata, $event);

View File

@ -14,17 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Auth oauth2 api functions tests.
*
* @package auth_oauth2
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
namespace auth_oauth2;
/**
* External auth oauth2 API tests.
@ -33,7 +23,7 @@ global $CFG;
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_oauth2_external_testcase extends advanced_testcase {
class api_test extends \advanced_testcase {
/**
* Test the cleaning of orphaned linked logins for all issuers.

View File

@ -14,26 +14,26 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @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;
defined('MOODLE_INTERNAL') || die();
// Include all the needed stuff
// Include all the needed stuff.
global $CFG;
require_once($CFG->dirroot . '/backup/util/interfaces/checksumable.class.php');
require_once($CFG->dirroot . '/backup/backup.class.php');
require_once($CFG->dirroot . '/backup/util/helper/backup_helper.class.php');
require_once($CFG->dirroot . '/backup/util/helper/backup_general_helper.class.php');
/*
/**
* backup_helper 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_helper_testcase extends basic_testcase {
class helper_test extends \basic_testcase {
/*
* test backup_helper class

View File

@ -14,18 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Block recentlyaccesseditems helper tests.
*
* @package block_recentlyaccesseditems
* @copyright 2019 University of Nottingham
* @author Neill Magill <neill.magill@nottingham.ac.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use block_recentlyaccesseditems\helper;
defined('MOODLE_INTERNAL') || die();
namespace block_recentlyaccesseditems;
/**
* Block Recently accessed helper class tests.
@ -35,7 +24,7 @@ defined('MOODLE_INTERNAL') || die();
* @author Neill Magill <neill.magill@nottingham.ac.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_recentlyaccesseditems_helper_testcase extends advanced_testcase {
class helper_test extends \advanced_testcase {
/**
* Tests that the get recent items method can handle getting records when courses have been deleted.
*/
@ -52,10 +41,10 @@ class block_recentlyaccesseditems_helper_testcase extends advanced_testcase {
self::setUser($user);
// Get the user to visit the activities.
$event1params = ['context' => context_module::instance($forum->cmid), 'objectid' => $forum->id];
$event1params = ['context' => \context_module::instance($forum->cmid), 'objectid' => $forum->id];
$event1 = \mod_forum\event\course_module_viewed::create($event1params);
$event1->trigger();
$event2params = ['context' => context_module::instance($glossary->cmid), 'objectid' => $glossary->id];
$event2params = ['context' => \context_module::instance($glossary->cmid), 'objectid' => $glossary->id];
$event2 = \mod_glossary\event\course_module_viewed::create($event2params);
$event2->trigger();
$recent1 = helper::get_recent_items();

View File

@ -14,24 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* API 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\competency;
use core_competency\competency_framework;
use core_competency\course_competency_settings;
use core_competency\evidence;
use core_competency\user_competency;
use core_competency\plan;
namespace core_competency;
/**
* API tests.
@ -40,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_api_testcase extends advanced_testcase {
class api_test extends \advanced_testcase {
public function test_get_framework_related_contexts() {
$this->resetAfterTest(true);
@ -50,10 +33,10 @@ class core_competency_api_testcase extends advanced_testcase {
$cat3 = $dg->create_category(array('parent' => $cat2->id));
$c1 = $dg->create_course(array('category' => $cat2->id)); // This context should not be returned.
$cat1ctx = context_coursecat::instance($cat1->id);
$cat2ctx = context_coursecat::instance($cat2->id);
$cat3ctx = context_coursecat::instance($cat3->id);
$sysctx = context_system::instance();
$cat1ctx = \context_coursecat::instance($cat1->id);
$cat2ctx = \context_coursecat::instance($cat2->id);
$cat3ctx = \context_coursecat::instance($cat3->id);
$sysctx = \context_system::instance();
$expected = array($cat1ctx->id => $cat1ctx);
$this->assertEquals($expected, api::get_related_contexts($cat1ctx, 'self'));
@ -74,10 +57,10 @@ class core_competency_api_testcase extends advanced_testcase {
$cat3 = $dg->create_category(array('parent' => $cat2->id));
$c1 = $dg->create_course(array('category' => $cat2->id)); // This context should not be returned.
$cat1ctx = context_coursecat::instance($cat1->id);
$cat2ctx = context_coursecat::instance($cat2->id);
$cat3ctx = context_coursecat::instance($cat3->id);
$sysctx = context_system::instance();
$cat1ctx = \context_coursecat::instance($cat1->id);
$cat2ctx = \context_coursecat::instance($cat2->id);
$cat3ctx = \context_coursecat::instance($cat3->id);
$sysctx = \context_system::instance();
$roleallow = create_role('Allow', 'allow', 'Allow read');
assign_capability('moodle/competency:competencyview', CAP_ALLOW, $roleallow, $sysctx->id);
@ -111,10 +94,10 @@ class core_competency_api_testcase extends advanced_testcase {
$cat3 = $dg->create_category(array('parent' => $cat2->id));
$c1 = $dg->create_course(array('category' => $cat2->id)); // This context should not be returned.
$cat1ctx = context_coursecat::instance($cat1->id);
$cat2ctx = context_coursecat::instance($cat2->id);
$cat3ctx = context_coursecat::instance($cat3->id);
$sysctx = context_system::instance();
$cat1ctx = \context_coursecat::instance($cat1->id);
$cat2ctx = \context_coursecat::instance($cat2->id);
$cat3ctx = \context_coursecat::instance($cat3->id);
$sysctx = \context_system::instance();
$expected = array($cat1ctx->id => $cat1ctx);
$this->assertEquals($expected, api::get_related_contexts($cat1ctx, 'self'));
@ -135,10 +118,10 @@ class core_competency_api_testcase extends advanced_testcase {
$cat3 = $dg->create_category(array('parent' => $cat2->id));
$c1 = $dg->create_course(array('category' => $cat2->id)); // This context should not be returned.
$cat1ctx = context_coursecat::instance($cat1->id);
$cat2ctx = context_coursecat::instance($cat2->id);
$cat3ctx = context_coursecat::instance($cat3->id);
$sysctx = context_system::instance();
$cat1ctx = \context_coursecat::instance($cat1->id);
$cat2ctx = \context_coursecat::instance($cat2->id);
$cat3ctx = \context_coursecat::instance($cat3->id);
$sysctx = \context_system::instance();
$roleallow = create_role('Allow', 'allow', 'Allow read');
assign_capability('moodle/competency:templateview', CAP_ALLOW, $roleallow, $sysctx->id);
@ -172,7 +155,7 @@ class core_competency_api_testcase extends advanced_testcase {
$this->resetAfterTest(true);
$this->setAdminUser();
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
$template = api::create_template((object) array('shortname' => 'testing', 'contextid' => $syscontext->id));
$this->assertEquals('testing', $template->get('shortname'));
@ -184,8 +167,8 @@ class core_competency_api_testcase extends advanced_testcase {
$this->assertEquals('success', $template->get('shortname'));
// Trying to change the context.
$this->expectException(coding_exception::class);
api::update_template((object) ['id' => $template->get('id'), 'contextid' => context_coursecat::instance($cat->id)->id]);
$this->expectException(\coding_exception::class);
api::update_template((object) ['id' => $template->get('id'), 'contextid' => \context_coursecat::instance($cat->id)->id]);
}
/**
@ -203,7 +186,7 @@ class core_competency_api_testcase extends advanced_testcase {
'description' => 'description',
'descriptionformat' => FORMAT_HTML,
'visible' => true,
'contextid' => context_system::instance()->id
'contextid' => \context_system::instance()->id
));
$framework2 = $lpg->create_framework(array(
@ -212,7 +195,7 @@ class core_competency_api_testcase extends advanced_testcase {
'description' => 'description',
'descriptionformat' => FORMAT_HTML,
'visible' => true,
'contextid' => context_system::instance()->id
'contextid' => \context_system::instance()->id
));
$framework3 = $lpg->create_framework(array(
@ -221,11 +204,11 @@ class core_competency_api_testcase extends advanced_testcase {
'description' => 'description',
'descriptionformat' => FORMAT_HTML,
'visible' => false,
'contextid' => context_system::instance()->id
'contextid' => \context_system::instance()->id
));
// Get frameworks list order by shortname desc.
$result = api::list_frameworks('shortname', 'DESC', null, 3, context_system::instance());
$result = api::list_frameworks('shortname', 'DESC', null, 3, \context_system::instance());
$f = (object) array_shift($result);
$this->assertEquals($framework3->get('id'), $f->get('id'));
@ -235,7 +218,7 @@ class core_competency_api_testcase extends advanced_testcase {
$this->assertEquals($framework1->get('id'), $f->get('id'));
// Get frameworks list order by idnumber asc.
$result = api::list_frameworks('idnumber', 'ASC', null, 3, context_system::instance());
$result = api::list_frameworks('idnumber', 'ASC', null, 3, \context_system::instance());
$f = (object) array_shift($result);
$this->assertEquals($framework2->get('id'), $f->get('id'));
@ -245,7 +228,7 @@ class core_competency_api_testcase extends advanced_testcase {
$this->assertEquals($framework1->get('id'), $f->get('id'));
// Repeat excluding the non-visible ones.
$result = api::list_frameworks('idnumber', 'ASC', null, 3, context_system::instance(), 'self', true);
$result = api::list_frameworks('idnumber', 'ASC', null, 3, \context_system::instance(), 'self', true);
$this->assertCount(2, $result);
$f = (object) array_shift($result);
$this->assertEquals($framework2->get('id'), $f->get('id'));
@ -253,23 +236,23 @@ class core_competency_api_testcase extends advanced_testcase {
$this->assertEquals($framework1->get('id'), $f->get('id'));
// Search by query string, trying match on shortname.
$result = api::list_frameworks('idnumber', 'ASC', null, 3, context_system::instance(), 'self', false, 'crisp');
$result = api::list_frameworks('idnumber', 'ASC', null, 3, \context_system::instance(), 'self', false, 'crisp');
$this->assertCount(1, $result);
$f = (object) array_shift($result);
$this->assertEquals($framework3->get('id'), $f->get('id'));
// Search by query string, trying match on shortname, but hidden.
$result = api::list_frameworks('idnumber', 'ASC', null, 3, context_system::instance(), 'self', true, 'crisp');
$result = api::list_frameworks('idnumber', 'ASC', null, 3, \context_system::instance(), 'self', true, 'crisp');
$this->assertCount(0, $result);
// Search by query string, trying match on ID number.
$result = api::list_frameworks('idnumber', 'ASC', null, 3, context_system::instance(), 'self', false, 'apple');
$result = api::list_frameworks('idnumber', 'ASC', null, 3, \context_system::instance(), 'self', false, 'apple');
$this->assertCount(1, $result);
$f = (object) array_shift($result);
$this->assertEquals($framework2->get('id'), $f->get('id'));
// Search by query string, trying match on both.
$result = api::list_frameworks('idnumber', 'ASC', null, 3, context_system::instance(), 'self', false, 'bee');
$result = api::list_frameworks('idnumber', 'ASC', null, 3, \context_system::instance(), 'self', false, 'bee');
$this->assertCount(2, $result);
$f = (object) array_shift($result);
$this->assertEquals($framework2->get('id'), $f->get('id'));
@ -285,7 +268,7 @@ class core_competency_api_testcase extends advanced_testcase {
$this->resetAfterTest(true);
$this->setAdminUser();
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
$params = array(
'shortname' => 'shortname_a',
'idnumber' => 'idnumber_c',
@ -397,7 +380,7 @@ class core_competency_api_testcase extends advanced_testcase {
$usermanagedraft = $dg->create_user();
$usermanage = $dg->create_user();
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
// Creating specific roles.
$manageowndraftrole = $dg->create_role(array(
@ -454,7 +437,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
$plan = api::update_plan($record);
$this->fail('Updating the status is not allowed.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/To change the status of a plan use the appropriate methods./',
$e->getMessage());
}
@ -466,7 +449,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
$plan = api::update_plan($record);
$this->fail('User with manage own plan capability can only edit his own plan.');
} catch (required_capability_exception $e) {
} catch (\required_capability_exception $e) {
$this->assertTrue(true);
}
@ -476,7 +459,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
$plan = api::update_plan($record);
$this->fail('User with manage plan capability cannot edit the other user plans with status draft');
} catch (required_capability_exception $e) {
} catch (\required_capability_exception $e) {
$this->assertTrue(true);
}
@ -506,7 +489,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::update_plan($record);
$this->fail('Completed plan can not be edited');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertTrue(true);
}
}
@ -533,7 +516,7 @@ class core_competency_api_testcase extends advanced_testcase {
// Check that api::create_plan cannot be used.
unset($record->id);
$this->expectException(coding_exception::class);
$this->expectException(\coding_exception::class);
$plan = api::create_plan($record);
}
@ -556,7 +539,7 @@ class core_competency_api_testcase extends advanced_testcase {
$record->templateid = null;
api::update_plan($record);
$this->fail('A plan cannot be unlinked using api::update_plan()');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
// All good.
}
@ -566,7 +549,7 @@ class core_competency_api_testcase extends advanced_testcase {
$record->templateid = $tpl2->get('id');
api::update_plan($record);
$this->fail('A plan cannot be moved to another template.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
// All good.
}
@ -576,7 +559,7 @@ class core_competency_api_testcase extends advanced_testcase {
$record->templateid = $tpl1->get('id');
api::update_plan($record);
$this->fail('A plan cannot be update to use a template.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
// All good.
}
}
@ -638,7 +621,7 @@ class core_competency_api_testcase extends advanced_testcase {
// Check we can unlink draft plan.
try {
api::unlink_plan_from_template($plan2);
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->fail('Fail to unlink draft plan.');
}
@ -646,7 +629,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::unlink_plan_from_template($plan3);
$this->fail('We can not unlink completed plan.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
// All good.
}
@ -821,7 +804,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::add_competency_to_plan($plan->get('id'), $c4->get('id'));
$this->fail('We can not add competency to completed plan.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
// All good.
}
@ -829,12 +812,12 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::remove_competency_from_plan($plan->get('id'), $c3->get('id'));
$this->fail('We can not remove competency to completed plan.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
// All good.
}
// Completing a plan that is completed throws an exception.
$this->expectException(coding_exception::class);
$this->expectException(\coding_exception::class);
api::complete_plan($plan);
}
@ -851,7 +834,7 @@ class core_competency_api_testcase extends advanced_testcase {
$reviewer = $dg->create_user();
$otheruser = $dg->create_user();
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
$userrole = $dg->create_role();
$reviewerrole = $dg->create_role();
$otheruserrole = $dg->create_role();
@ -900,7 +883,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_request_review($plan);
$this->fail('The user can not read the plan.');
} catch (required_capability_exception $e) {
} catch (\required_capability_exception $e) {
$this->assertEquals('nopermissions', $e->errorcode);
}
@ -909,7 +892,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_request_review($tplplan);
$this->fail('The plan is based on a template.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/Template plans cannot be reviewed./', $e->getMessage());
}
@ -919,7 +902,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_request_review($plan);
$this->fail('The plan cannot be sent for review at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan cannot be sent for review at this stage./', $e->getMessage());
}
@ -929,7 +912,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_request_review($plan);
$this->fail('The plan cannot be sent for review at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan cannot be sent for review at this stage./', $e->getMessage());
}
@ -939,7 +922,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_request_review($plan);
$this->fail('The plan cannot be sent for review at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan cannot be sent for review at this stage./', $e->getMessage());
}
@ -949,7 +932,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_request_review($plan);
$this->fail('The plan cannot be sent for review at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan cannot be sent for review at this stage./', $e->getMessage());
}
@ -959,7 +942,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_request_review($plan);
$this->fail('The user can not request a review.');
} catch (required_capability_exception $e) {
} catch (\required_capability_exception $e) {
$this->assertEquals('nopermissions', $e->errorcode);
}
@ -1001,7 +984,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_cancel_review_request($plan);
$this->fail('The user can not read the plan.');
} catch (required_capability_exception $e) {
} catch (\required_capability_exception $e) {
$this->assertEquals('nopermissions', $e->errorcode);
}
@ -1010,7 +993,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_cancel_review_request($tplplan);
$this->fail('The plan is based on a template.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/Template plans cannot be reviewed./', $e->getMessage());
}
@ -1020,7 +1003,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_cancel_review_request($plan);
$this->fail('The plan cannot be sent for review at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan review cannot be cancelled at this stage./', $e->getMessage());
}
@ -1030,7 +1013,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_cancel_review_request($plan);
$this->fail('The plan review cannot be cancelled at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan review cannot be cancelled at this stage./', $e->getMessage());
}
@ -1040,7 +1023,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_cancel_review_request($plan);
$this->fail('The plan review cannot be cancelled at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan review cannot be cancelled at this stage./', $e->getMessage());
}
@ -1050,7 +1033,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_cancel_review_request($plan);
$this->fail('The plan review cannot be cancelled at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan review cannot be cancelled at this stage./', $e->getMessage());
}
@ -1060,7 +1043,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_cancel_review_request($plan);
$this->fail('The user can not cancel a review request.');
} catch (required_capability_exception $e) {
} catch (\required_capability_exception $e) {
$this->assertEquals('nopermissions', $e->errorcode);
}
@ -1102,7 +1085,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_start_review($plan);
$this->fail('The user can not read the plan.');
} catch (required_capability_exception $e) {
} catch (\required_capability_exception $e) {
$this->assertEquals('nopermissions', $e->errorcode);
}
@ -1111,7 +1094,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_start_review($tplplan);
$this->fail('The plan is based on a template.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/Template plans cannot be reviewed./', $e->getMessage());
}
@ -1121,7 +1104,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_start_review($plan);
$this->fail('The plan review cannot be started at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan review cannot be started at this stage./', $e->getMessage());
}
@ -1131,7 +1114,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_start_review($plan);
$this->fail('The plan review cannot be started at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan review cannot be started at this stage./', $e->getMessage());
}
@ -1141,7 +1124,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_start_review($plan);
$this->fail('The plan review cannot be started at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan review cannot be started at this stage./', $e->getMessage());
}
@ -1151,7 +1134,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_start_review($plan);
$this->fail('The plan review cannot be started at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan review cannot be started at this stage./', $e->getMessage());
}
@ -1161,7 +1144,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_start_review($plan);
$this->fail('The user can not start a review.');
} catch (required_capability_exception $e) {
} catch (\required_capability_exception $e) {
$this->assertEquals('nopermissions', $e->errorcode);
}
@ -1206,7 +1189,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_stop_review($plan);
$this->fail('The user can not read the plan.');
} catch (required_capability_exception $e) {
} catch (\required_capability_exception $e) {
$this->assertEquals('nopermissions', $e->errorcode);
}
@ -1215,7 +1198,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_stop_review($tplplan);
$this->fail('The plan is based on a template.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/Template plans cannot be reviewed./', $e->getMessage());
}
@ -1225,7 +1208,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_stop_review($plan);
$this->fail('The plan review cannot be stopped at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan review cannot be stopped at this stage./', $e->getMessage());
}
@ -1235,7 +1218,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_stop_review($plan);
$this->fail('The plan review cannot be stopped at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan review cannot be stopped at this stage./', $e->getMessage());
}
@ -1245,7 +1228,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_stop_review($plan);
$this->fail('The plan review cannot be stopped at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan review cannot be stopped at this stage./', $e->getMessage());
}
@ -1255,7 +1238,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_stop_review($plan);
$this->fail('The plan review cannot be stopped at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan review cannot be stopped at this stage./', $e->getMessage());
}
@ -1265,7 +1248,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::plan_stop_review($plan);
$this->fail('The user can not stop a review.');
} catch (required_capability_exception $e) {
} catch (\required_capability_exception $e) {
$this->assertEquals('nopermissions', $e->errorcode);
}
@ -1307,7 +1290,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::approve_plan($plan);
$this->fail('The user can not read the plan.');
} catch (required_capability_exception $e) {
} catch (\required_capability_exception $e) {
$this->assertEquals('nopermissions', $e->errorcode);
}
@ -1316,7 +1299,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::approve_plan($tplplan);
$this->fail('The plan is based on a template.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/Template plans are already approved./', $e->getMessage());
}
@ -1326,7 +1309,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::approve_plan($plan);
$this->fail('The plan cannot be approved at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan cannot be approved at this stage./', $e->getMessage());
}
@ -1336,7 +1319,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::approve_plan($plan);
$this->fail('The plan cannot be approved at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan cannot be approved at this stage./', $e->getMessage());
}
@ -1346,7 +1329,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::approve_plan($plan);
$this->fail('The user can not approve the plan.');
} catch (required_capability_exception $e) {
} catch (\required_capability_exception $e) {
$this->assertEquals('nopermissions', $e->errorcode);
}
@ -1402,7 +1385,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::unapprove_plan($plan);
$this->fail('The user can not read the plan.');
} catch (required_capability_exception $e) {
} catch (\required_capability_exception $e) {
$this->assertEquals('nopermissions', $e->errorcode);
}
@ -1411,7 +1394,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::unapprove_plan($tplplan);
$this->fail('The plan is based on a template.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/Template plans are always approved./', $e->getMessage());
}
@ -1421,7 +1404,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::unapprove_plan($plan);
$this->fail('The plan cannot be sent back to draft at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan cannot be sent back to draft at this stage./', $e->getMessage());
}
@ -1431,7 +1414,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::unapprove_plan($plan);
$this->fail('The plan cannot be sent back to draft at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan cannot be sent back to draft at this stage./', $e->getMessage());
}
@ -1441,7 +1424,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::unapprove_plan($plan);
$this->fail('The plan cannot be sent back to draft at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan cannot be sent back to draft at this stage./', $e->getMessage());
}
@ -1451,7 +1434,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::unapprove_plan($plan);
$this->fail('The plan cannot be sent back to draft at this stage.');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/The plan cannot be sent back to draft at this stage./', $e->getMessage());
}
@ -1461,7 +1444,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::unapprove_plan($plan);
$this->fail('The user can not unapprove the plan.');
} catch (required_capability_exception $e) {
} catch (\required_capability_exception $e) {
$this->assertEquals('nopermissions', $e->errorcode);
}
@ -1489,7 +1472,7 @@ class core_competency_api_testcase extends advanced_testcase {
$dg = $this->getDataGenerator();
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
// Create users and roles for the test.
$user = $dg->create_user();
@ -1541,7 +1524,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
$plan = api::update_plan($record);
$this->fail('We cannot complete a plan using api::update_plan().');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
// All good.
}
api::complete_plan($plan);
@ -1577,7 +1560,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::update_plan($record);
$this->fail('Completed plan can not be edited');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
// All good.
}
@ -1598,7 +1581,7 @@ class core_competency_api_testcase extends advanced_testcase {
$dg = $this->getDataGenerator();
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
// Create users and roles for the test.
$user = $dg->create_user();
@ -1685,7 +1668,7 @@ class core_competency_api_testcase extends advanced_testcase {
$dg = $this->getDataGenerator();
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
// Create user and role for the test.
$user = $dg->create_user();
@ -1734,7 +1717,7 @@ class core_competency_api_testcase extends advanced_testcase {
$dg = $this->getDataGenerator();
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
// Create user and role for the test.
$user = $dg->create_user();
@ -1842,8 +1825,8 @@ class core_competency_api_testcase extends advanced_testcase {
$dg = $this->getDataGenerator();
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
$cat = $dg->create_category();
$catcontext = context_coursecat::instance($cat->id);
$syscontext = context_system::instance();
$catcontext = \context_coursecat::instance($cat->id);
$syscontext = \context_system::instance();
$user = $dg->create_user();
$role = $dg->create_role();
@ -1868,7 +1851,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
$result = api::create_template_cohort($t1, $c2);
$this->fail('Permission required.');
} catch (required_capability_exception $e) {
} catch (\required_capability_exception $e) {
// That's what should happen.
}
@ -1886,8 +1869,8 @@ class core_competency_api_testcase extends advanced_testcase {
$dg = $this->getDataGenerator();
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
$cat = $dg->create_category();
$catcontext = context_coursecat::instance($cat->id);
$syscontext = context_system::instance();
$catcontext = \context_coursecat::instance($cat->id);
$syscontext = \context_system::instance();
$user = $dg->create_user();
$role = $dg->create_role();
@ -1923,7 +1906,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::reorder_template_competency($template->get('id'), $competency2->get('id'), $competency1->get('id'));
$this->fail('Exception expected due to not permissions to manage template competencies');
} catch (required_capability_exception $e) {
} catch (\required_capability_exception $e) {
$this->assertEquals('nopermissions', $e->errorcode);
}
@ -1940,7 +1923,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::reorder_template_competency($template->get('id'), $competency2->get('id'), $competency1->get('id'));
$this->fail('Exception expected due to not permissions to manage template competencies');
} catch (required_capability_exception $e) {
} catch (\required_capability_exception $e) {
$this->assertEquals('nopermissions', $e->errorcode);
}
}
@ -2020,7 +2003,7 @@ class core_competency_api_testcase extends advanced_testcase {
$lpg = $dg->get_plugin_generator('core_competency');
$u1 = $dg->create_user();
$u1ctx = context_user::instance($u1->id);
$u1ctx = \context_user::instance($u1->id);
$f1 = $lpg->create_framework();
$c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get('id')));
$c2 = $lpg->create_competency(array('competencyframeworkid' => $f1->get('id')));
@ -2074,7 +2057,7 @@ class core_competency_api_testcase extends advanced_testcase {
$evidence = api::add_evidence($u1->id, $c1->get('id'), $u1ctx->id, \core_competency\evidence::ACTION_LOG, 'invaliddata',
'error', null, false, null, 1);
$this->fail('A grade can not be set');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/grade MUST NOT be set/', $e->getMessage());
}
}
@ -2085,7 +2068,7 @@ class core_competency_api_testcase extends advanced_testcase {
$lpg = $dg->get_plugin_generator('core_competency');
$u1 = $dg->create_user();
$u1ctx = context_user::instance($u1->id);
$u1ctx = \context_user::instance($u1->id);
$scale = $dg->create_scale(array('scale' => 'A,B,C,D'));
$scaleconfig = array(array('scaleid' => $scale->id));
$scaleconfig[] = array('name' => 'B', 'id' => 2, 'scaledefault' => 1, 'proficient' => 0);
@ -2170,7 +2153,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::add_evidence($u1->id, $c2->get('id'), $u1ctx->id, \core_competency\evidence::ACTION_COMPLETE, 'invaliddata',
'error', null, false, null, 1);
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertMatchesRegularExpression('/grade MUST NOT be set/', $e->getMessage());
}
}
@ -2181,7 +2164,7 @@ class core_competency_api_testcase extends advanced_testcase {
$lpg = $dg->get_plugin_generator('core_competency');
$u1 = $dg->create_user();
$u1ctx = context_user::instance($u1->id);
$u1ctx = \context_user::instance($u1->id);
$f1 = $lpg->create_framework();
$c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get('id')));
@ -2256,7 +2239,7 @@ class core_competency_api_testcase extends advanced_testcase {
$lpg = $dg->get_plugin_generator('core_competency');
$u1 = $dg->create_user();
$u1ctx = context_user::instance($u1->id);
$u1ctx = \context_user::instance($u1->id);
$f1 = $lpg->create_framework();
$c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get('id')));
@ -2289,7 +2272,7 @@ class core_competency_api_testcase extends advanced_testcase {
$dg = $this->getDataGenerator();
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
// Create users.
$user = $dg->create_user();
@ -2331,7 +2314,7 @@ class core_competency_api_testcase extends advanced_testcase {
$dg = $this->getDataGenerator();
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
// Create users.
$user = $dg->create_user();
@ -2367,7 +2350,7 @@ class core_competency_api_testcase extends advanced_testcase {
$this->resetAfterTest(true);
$dg = $this->getDataGenerator();
$lpg = $dg->get_plugin_generator('core_competency');
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
$ctxid = $syscontext->id;
$u1 = $dg->create_user();
@ -2466,7 +2449,7 @@ class core_competency_api_testcase extends advanced_testcase {
public function test_add_evidence_for_user_competency_course_grade_outside_course() {
$this->resetAfterTest(true);
$dg = $this->getDataGenerator();
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
// Create a student.
$student = $dg->create_user();
@ -2509,7 +2492,7 @@ class core_competency_api_testcase extends advanced_testcase {
$record = array('courseid' => $course->id, 'pushratingstouserplans' => false);
$settings = new course_competency_settings(0, (object) $record);
$settings->create();
$coursecontext = context_course::instance($course->id);
$coursecontext = \context_course::instance($course->id);
// Create a student and enrol into the course.
$student = $dg->create_user();
@ -2563,7 +2546,7 @@ class core_competency_api_testcase extends advanced_testcase {
// Set-up users, framework, competencies and course competencies.
$course = $dg->create_course();
$coursectx = context_course::instance($course->id);
$coursectx = \context_course::instance($course->id);
$u1 = $dg->create_user();
$f1 = $lpg->create_framework();
$c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get('id')));
@ -2659,7 +2642,7 @@ class core_competency_api_testcase extends advanced_testcase {
$lpg = $dg->get_plugin_generator('core_competency');
$u1 = $dg->create_user();
$course = $dg->create_course();
$coursecontext = context_course::instance($course->id);
$coursecontext = \context_course::instance($course->id);
$this->setAdminUser();
$f = $lpg->create_framework();
@ -2672,7 +2655,7 @@ class core_competency_api_testcase extends advanced_testcase {
$page = $pagegenerator->create_instance(array('course' => $course->id));
$cm = get_coursemodule_from_instance('page', $page->id);
$cmcontext = context_module::instance($cm->id);
$cmcontext = \context_module::instance($cm->id);
// Add the competency to the course module.
$ccm = api::add_competency_to_course_module($cm, $c->get('id'));
@ -2902,7 +2885,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::add_competency_to_course($course->id, $competency->get('id'));
$this->fail('A competency belonging to hidden framework can not be linked to course');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertTrue(true);
}
@ -2910,7 +2893,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::add_competency_to_template($template->get('id'), $competency->get('id'));
$this->fail('A competency belonging to hidden framework can not be added to template');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertTrue(true);
}
@ -2918,7 +2901,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::add_competency_to_plan($plan->get('id'), $competency->get('id'));
$this->fail('A competency belonging to hidden framework can not be added to plan');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertTrue(true);
}
}
@ -2942,7 +2925,7 @@ class core_competency_api_testcase extends advanced_testcase {
try {
api::create_plan_from_template($template->get('id'), $user->id);
$this->fail('Can not link a hidden template to plan');
} catch (coding_exception $e) {
} catch (\coding_exception $e) {
$this->assertTrue(true);
}
@ -3933,9 +3916,9 @@ class core_competency_api_testcase extends advanced_testcase {
$c1 = $dg->create_course();
$c2 = $dg->create_course();
$sysctx = context_system::instance();
$c1ctx = context_course::instance($c1->id);
$c2ctx = context_course::instance($c2->id);
$sysctx = \context_system::instance();
$c1ctx = \context_course::instance($c1->id);
$c2ctx = \context_course::instance($c2->id);
$teacher1 = $dg->create_user();
$noneditingteacher = $dg->create_user();
@ -4064,7 +4047,7 @@ class core_competency_api_testcase extends advanced_testcase {
$raised = false;
try {
api::grade_competency_in_course($courseid, $userid, $compid, $grade);
} catch (moodle_exception $e) {
} catch (\moodle_exception $e) {
$raised = true;
$this->assertInstanceOf($exceptiontype, $e);
$this->assertMatchesRegularExpression('@' . $exceptiontext . '@', $e->getMessage());
@ -4085,7 +4068,7 @@ class core_competency_api_testcase extends advanced_testcase {
$dg = $this->getDataGenerator();
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
// Create users.
$user = $dg->create_user();
@ -4143,7 +4126,7 @@ class core_competency_api_testcase extends advanced_testcase {
// Enrol the user so they can be rated in the course.
$studentarch = get_archetype_roles('student');
$studentrole = array_shift($studentarch);
$coursecontext = context_course::instance($c1->id);
$coursecontext = \context_course::instance($c1->id);
$dg->role_assign($studentrole->id, $user->id, $coursecontext->id);
$dg->enrol_user($user->id, $c1->id, $studentrole->id);
@ -4189,7 +4172,7 @@ class core_competency_api_testcase extends advanced_testcase {
// Enrol students in the course.
$studentarch = get_archetype_roles('student');
$studentrole = array_shift($studentarch);
$coursecontext = context_course::instance($c1->id);
$coursecontext = \context_course::instance($c1->id);
$dg->role_assign($studentrole->id, $u1->id, $coursecontext->id);
$dg->enrol_user($u1->id, $c1->id, $studentrole->id);
$dg->role_assign($studentrole->id, $u2->id, $coursecontext->id);
@ -4526,7 +4509,7 @@ class core_competency_api_testcase extends advanced_testcase {
$this->setUser($u1);
$this->expectException(required_capability_exception::class);
$this->expectException(\required_capability_exception::class);
api::delete_evidence($ev1);
}
@ -4534,7 +4517,7 @@ class core_competency_api_testcase extends advanced_testcase {
$dg = $this->getDataGenerator();
$this->resetAfterTest();
$ccg = $dg->get_plugin_generator('core_competency');
$sysctx = context_system::instance();
$sysctx = \context_system::instance();
$this->setAdminUser();
$reviewer = $dg->create_user();
@ -4567,7 +4550,7 @@ class core_competency_api_testcase extends advanced_testcase {
$this->assertEquals($p2a->get('id'), $result['plans'][2]->plan->get('id'));
// The reviewer cannot view the plans when they do not have the permission in the user's context.
role_assign($roleprohibit, $reviewer->id, context_user::instance($u2->id)->id);
role_assign($roleprohibit, $reviewer->id, \context_user::instance($u2->id)->id);
accesslib_clear_all_caches_for_unit_testing();
$result = api::list_plans_to_review();
$this->assertEquals(2, $result['count']);
@ -4582,7 +4565,7 @@ class core_competency_api_testcase extends advanced_testcase {
$dg = $this->getDataGenerator();
$this->resetAfterTest();
$ccg = $dg->get_plugin_generator('core_competency');
$sysctx = context_system::instance();
$sysctx = \context_system::instance();
$this->setAdminUser();
$reviewer = $dg->create_user();
@ -4632,7 +4615,7 @@ class core_competency_api_testcase extends advanced_testcase {
$this->assertEquals(3, $result['count']);
// The reviewer cannot view the plans when they do not have the permission in the user's context.
role_assign($roleprohibit, $reviewer->id, context_user::instance($u2->id)->id);
role_assign($roleprohibit, $reviewer->id, \context_user::instance($u2->id)->id);
accesslib_clear_all_caches_for_unit_testing();
$result = api::list_user_competencies_to_review();
$this->assertEquals(2, $result['count']);

View File

@ -14,16 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Test completion API.
*
* @package core_completion
* @category test
* @copyright 2017 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace core_completion;
/**
* Test completion API.
@ -33,7 +24,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2017 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_completion_api_testcase extends advanced_testcase {
class api_test extends \advanced_testcase {
/**
* Test setup.
@ -247,21 +238,21 @@ class core_completion_api_testcase extends advanced_testcase {
array('completion' => 1));
$cmdata = get_coursemodule_from_id('data', $data->cmid);
$cm = get_coursemodule_from_instance('data', $data->id);
$c = new completion_info($course);
$c = new \completion_info($course);
// Add activity completion criteria.
$criteriadata = new stdClass();
$criteriadata = new \stdClass();
$criteriadata->id = $course->id;
$criteriadata->criteria_activity = array();
// Some activities.
$criteriadata->criteria_activity[$cmdata->id] = 1;
$criterion = new completion_criteria_activity();
$criterion = new \completion_criteria_activity();
$criterion->update_config($criteriadata);
$this->setUser($teacher);
// Mark activity complete for both users.
$completion = new stdClass();
$completion = new \stdClass();
$completion->coursemoduleid = $cm->id;
$completion->completionstate = COMPLETION_COMPLETE;
$completion->timemodified = time();

View File

@ -14,18 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Tests for class customfield_checkbox
*
* @package customfield_checkbox
* @copyright 2019 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customfield_checkbox;
defined('MOODLE_INTERNAL') || die();
use customfield_checkbox\field_controller;
use customfield_checkbox\data_controller;
use core_customfield_generator;
use core_customfield_test_instance_form;
/**
* Functional test for customfield_checkbox
@ -34,9 +26,9 @@ use customfield_checkbox\data_controller;
* @copyright 2019 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class customfield_checkbox_plugin_testcase extends advanced_testcase {
class plugin_test extends \advanced_testcase {
/** @var stdClass[] */
/** @var \stdClass[] */
private $courses = [];
/** @var \core_customfield\category_controller */
private $cfcat;
@ -161,12 +153,12 @@ class customfield_checkbox_plugin_testcase extends advanced_testcase {
$this->assertEquals('Yes', $this->cfdata[1]->export_value());
// Field without data.
$d = core_customfield\data_controller::create(0, null, $this->cfields[2]);
$d = \core_customfield\data_controller::create(0, null, $this->cfields[2]);
$this->assertEquals(0, $d->get_value());
$this->assertEquals('No', $d->export_value());
// Field without data that is checked by default.
$d = core_customfield\data_controller::create(0, null, $this->cfields[3]);
$d = \core_customfield\data_controller::create(0, null, $this->cfields[3]);
$this->assertEquals(1, $d->get_value());
$this->assertEquals('Yes', $d->export_value());
}

View File

@ -14,18 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Tests for class customfield_date
*
* @package customfield_date
* @copyright 2019 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customfield_date;
defined('MOODLE_INTERNAL') || die();
use customfield_date\field_controller;
use customfield_date\data_controller;
use core_customfield_generator;
use core_customfield_test_instance_form;
/**
* Functional test for customfield_date
@ -34,7 +26,7 @@ use customfield_date\data_controller;
* @copyright 2019 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class customfield_date_plugin_testcase extends advanced_testcase {
class plugin_test extends \advanced_testcase {
/** @var stdClass[] */
private $courses = [];
@ -167,7 +159,7 @@ class customfield_date_plugin_testcase extends advanced_testcase {
$this->assertStringMatchesFormat('%a 1 January 2019%a', $this->cfdata[1]->export_value());
// Field without data.
$d = core_customfield\data_controller::create(0, null, $this->cfields[2]);
$d = \core_customfield\data_controller::create(0, null, $this->cfields[2]);
$this->assertEquals(0, $d->get_value());
$this->assertEquals(null, $d->export_value());
}

View File

@ -14,18 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Tests for class customfield_select
*
* @package customfield_select
* @copyright 2019 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customfield_select;
defined('MOODLE_INTERNAL') || die();
use customfield_select\field_controller;
use customfield_select\data_controller;
use core_customfield_generator;
use core_customfield_test_instance_form;
/**
* Functional test for customfield_select
@ -34,7 +26,7 @@ use customfield_select\data_controller;
* @copyright 2019 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class customfield_select_plugin_testcase extends advanced_testcase {
class plugin_test extends \advanced_testcase {
/** @var stdClass[] */
private $courses = [];
@ -153,7 +145,7 @@ class customfield_select_plugin_testcase extends advanced_testcase {
$this->assertEquals('a', $this->cfdata[1]->export_value());
// Field without data but with a default value.
$d = core_customfield\data_controller::create(0, null, $this->cfields[3]);
$d = \core_customfield\data_controller::create(0, null, $this->cfields[3]);
$this->assertEquals(2, $d->get_value());
$this->assertEquals('b', $d->export_value());
}

View File

@ -14,18 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Tests for class customfield_text
*
* @package customfield_text
* @copyright 2019 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customfield_text;
defined('MOODLE_INTERNAL') || die();
use customfield_text\field_controller;
use customfield_text\data_controller;
use core_customfield_generator;
use core_customfield_test_instance_form;
/**
* Functional test for customfield_text
@ -34,7 +26,7 @@ use customfield_text\data_controller;
* @copyright 2019 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class customfield_text_plugin_testcase extends advanced_testcase {
class plugin_test extends \advanced_testcase {
/** @var stdClass[] */
private $courses = [];
@ -158,7 +150,7 @@ class customfield_text_plugin_testcase extends advanced_testcase {
$this->assertEquals('Value1', $this->cfdata[1]->export_value());
// Field without data but with a default value.
$d = core_customfield\data_controller::create(0, null, $this->cfields[3]);
$d = \core_customfield\data_controller::create(0, null, $this->cfields[3]);
$this->assertEquals('Defvalue', $d->get_value());
$this->assertEquals('Defvalue', $d->export_value());

View File

@ -14,18 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Tests for class customfield_textarea
*
* @package customfield_textarea
* @copyright 2019 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customfield_textarea;
defined('MOODLE_INTERNAL') || die();
use customfield_textarea\field_controller;
use customfield_textarea\data_controller;
use core_customfield_generator;
use core_customfield_test_instance_form;
/**
* Functional test for customfield_textarea
@ -34,7 +26,7 @@ use customfield_textarea\data_controller;
* @copyright 2019 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class customfield_textarea_plugin_testcase extends advanced_testcase {
class plugin_test extends \advanced_testcase {
/** @var stdClass[] */
private $courses = [];
@ -169,7 +161,7 @@ class customfield_textarea_plugin_testcase extends advanced_testcase {
$handler->instance_form_save($form->get_data());
$this->assertEquals($submitdata['customfield_myfield1_editor']['text'],
core_customfield\data_controller::create($this->cfdata[1]->get('id'))->export_value());
\core_customfield\data_controller::create($this->cfdata[1]->get('id'))->export_value());
// Now empty our non-required field.
$submitdata['customfield_myfield1_editor']['text'] = '';
@ -178,7 +170,7 @@ class customfield_textarea_plugin_testcase extends advanced_testcase {
$form = new core_customfield_test_instance_form('post', ['handler' => $handler, 'instance' => $this->courses[1]]);
$handler->instance_form_save($form->get_data());
$this->assertEmpty(core_customfield\data_controller::create($this->cfdata[1]->get('id'))->export_value());
$this->assertEmpty(\core_customfield\data_controller::create($this->cfdata[1]->get('id'))->export_value());
}
/**
@ -189,7 +181,7 @@ class customfield_textarea_plugin_testcase extends advanced_testcase {
$this->assertEquals('<div class="text_to_html">Value1</div>', $this->cfdata[1]->export_value());
// Field without data but with a default value.
$d = core_customfield\data_controller::create(0, null, $this->cfields[3]);
$d = \core_customfield\data_controller::create(0, null, $this->cfields[3]);
$this->assertEquals('Value3', $d->get_value());
$this->assertEquals('<div class="text_to_html">Value3</div>', $d->export_value());
}

View File

@ -14,35 +14,24 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core_customfield;
/**
* Tests for class \core_customfield\api.
* Functional test for class \core_customfield\api
*
* @package core_customfield
* @category test
* @copyright 2018 Toni Barbera <toni@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
use \core_customfield\api;
use \core_customfield\category_controller;
/**
* Functional test for class \core_customfield\api
*
* @package core_customfield
* @copyright 2018 Toni Barbera <toni@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_customfield_api_testcase extends advanced_testcase {
class api_test extends \advanced_testcase {
/**
* Get generator.
*
* @return core_customfield_generator
*/
protected function get_generator(): core_customfield_generator {
protected function get_generator(): \core_customfield_generator {
return $this->getDataGenerator()->get_plugin_generator('core_customfield');
}
@ -124,7 +113,7 @@ class core_customfield_api_testcase extends advanced_testcase {
'component' => 'core_course',
'area' => 'course',
'itemid' => 0,
'contextid' => context_system::instance()->id
'contextid' => \context_system::instance()->id
];
$category0 = $this->get_generator()->create_category(['name' => 'aaaa'] + $options);
$category1 = $this->get_generator()->create_category(['name' => 'bbbb'] + $options);
@ -156,7 +145,7 @@ class core_customfield_api_testcase extends advanced_testcase {
$this->resetAfterTest();
$params = ['component' => 'core_course', 'area' => 'course', 'itemid' => 0, 'name' => 'Cat1',
'contextid' => context_system::instance()->id];
'contextid' => \context_system::instance()->id];
$c1 = category_controller::create(0, (object)$params);
api::save_category($c1);
$this->assertNotEmpty($c1->get('id'));
@ -220,11 +209,11 @@ class core_customfield_api_testcase extends advanced_testcase {
'component' => 'core_course',
'area' => 'course',
'itemid' => 0,
'contextid' => context_system::instance()->id
'contextid' => \context_system::instance()->id
];
$lpg = $this->get_generator();
$course = $this->getDataGenerator()->create_course();
$dataparams = ['instanceid' => $course->id, 'contextid' => context_course::instance($course->id)->id];
$dataparams = ['instanceid' => $course->id, 'contextid' => \context_course::instance($course->id)->id];
$category0 = $lpg->create_category($options);
$category1 = $lpg->create_category($options);
for ($i = 0; $i < 6; $i++) {

View File

@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace enrol_category;
/**
* Category enrolment sync functional test.
*
@ -22,10 +24,7 @@
* @copyright 2012 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_category_plugin_testcase extends advanced_testcase {
class plugin_test extends \advanced_testcase {
protected function enable_plugin() {
$enabled = enrol_get_plugins(true);
@ -42,13 +41,13 @@ class enrol_category_plugin_testcase extends advanced_testcase {
}
protected function enable_role_sync($roleid) {
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
assign_capability('enrol/category:synchronised', CAP_ALLOW, $roleid, $syscontext, true);
}
protected function disable_role_sync($roleid) {
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
unassign_capability('enrol/category:synchronised', $roleid, $syscontext);
}
@ -63,7 +62,7 @@ class enrol_category_plugin_testcase extends advanced_testcase {
$this->resetAfterTest();
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
$this->assertFalse(enrol_is_enabled('category'));
$this->enable_plugin();
@ -123,37 +122,37 @@ class enrol_category_plugin_testcase extends advanced_testcase {
// Test assign event.
role_assign($managerrole->id, $user1->id, context_coursecat::instance($cat1->id));
role_assign($managerrole->id, $user3->id, context_course::instance($course1->id));
role_assign($managerrole->id, $user3->id, context_course::instance($course2->id));
role_assign($managerrole->id, $user1->id, \context_coursecat::instance($cat1->id));
role_assign($managerrole->id, $user3->id, \context_course::instance($course1->id));
role_assign($managerrole->id, $user3->id, \context_course::instance($course2->id));
$this->assertEquals(0, $DB->count_records('user_enrolments', array()));
role_assign($studentrole->id, $user1->id, context_coursecat::instance($cat2->id));
$this->assertTrue(is_enrolled(context_course::instance($course2->id), $user1->id));
$this->assertTrue(is_enrolled(context_course::instance($course3->id), $user1->id));
$this->assertTrue(is_enrolled(context_course::instance($course4->id), $user1->id));
role_assign($studentrole->id, $user1->id, \context_coursecat::instance($cat2->id));
$this->assertTrue(is_enrolled(\context_course::instance($course2->id), $user1->id));
$this->assertTrue(is_enrolled(\context_course::instance($course3->id), $user1->id));
$this->assertTrue(is_enrolled(\context_course::instance($course4->id), $user1->id));
$this->assertEquals(3, $DB->count_records('user_enrolments', array()));
role_assign($managerrole->id, $user2->id, context_coursecat::instance($cat3->id));
role_assign($managerrole->id, $user2->id, \context_coursecat::instance($cat3->id));
$this->assertEquals(3, $DB->count_records('user_enrolments', array()));
role_assign($teacherrole->id, $user4->id, context_coursecat::instance($cat1->id));
$this->assertTrue(is_enrolled(context_course::instance($course1->id), $user4->id));
role_assign($teacherrole->id, $user4->id, \context_coursecat::instance($cat1->id));
$this->assertTrue(is_enrolled(\context_course::instance($course1->id), $user4->id));
$this->assertEquals(4, $DB->count_records('user_enrolments', array()));
// Test role unassigned event.
role_unassign($teacherrole->id, $user4->id, context_coursecat::instance($cat1->id)->id);
$this->assertFalse(is_enrolled(context_course::instance($course1->id), $user4->id));
role_unassign($teacherrole->id, $user4->id, \context_coursecat::instance($cat1->id)->id);
$this->assertFalse(is_enrolled(\context_course::instance($course1->id), $user4->id));
$this->assertEquals(3, $DB->count_records('user_enrolments', array()));
// Make sure handlers are disabled when plugin disabled.
$this->disable_plugin();
role_unassign($studentrole->id, $user1->id, context_coursecat::instance($cat2->id)->id);
role_unassign($studentrole->id, $user1->id, \context_coursecat::instance($cat2->id)->id);
$this->assertEquals(3, $DB->count_records('user_enrolments', array()));
role_assign($studentrole->id, $user3->id, context_coursecat::instance($cat1->id));
role_assign($studentrole->id, $user3->id, \context_coursecat::instance($cat1->id));
$this->assertEquals(3, $DB->count_records('user_enrolments', array()));
}
@ -192,47 +191,47 @@ class enrol_category_plugin_testcase extends advanced_testcase {
$this->enable_plugin();
$this->assertEquals(0, $DB->count_records('role_assignments', array()));
role_assign($managerrole->id, $user1->id, context_coursecat::instance($cat1->id));
role_assign($managerrole->id, $user3->id, context_course::instance($course1->id));
role_assign($managerrole->id, $user3->id, context_course::instance($course2->id));
role_assign($managerrole->id, $user1->id, \context_coursecat::instance($cat1->id));
role_assign($managerrole->id, $user3->id, \context_course::instance($course1->id));
role_assign($managerrole->id, $user3->id, \context_course::instance($course2->id));
$this->assertEquals(0, $DB->count_records('user_enrolments', array()));
$this->disable_plugin(); // Stops the event handlers.
role_assign($studentrole->id, $user1->id, context_coursecat::instance($cat2->id));
role_assign($studentrole->id, $user1->id, \context_coursecat::instance($cat2->id));
$this->assertEquals(0, $DB->count_records('user_enrolments', array()));
$this->enable_plugin();
enrol_category_sync_course($course2);
$this->assertTrue(is_enrolled(context_course::instance($course2->id), $user1->id));
$this->assertFalse(is_enrolled(context_course::instance($course3->id), $user1->id));
$this->assertFalse(is_enrolled(context_course::instance($course4->id), $user1->id));
$this->assertTrue(is_enrolled(\context_course::instance($course2->id), $user1->id));
$this->assertFalse(is_enrolled(\context_course::instance($course3->id), $user1->id));
$this->assertFalse(is_enrolled(\context_course::instance($course4->id), $user1->id));
$this->assertEquals(1, $DB->count_records('user_enrolments', array()));
enrol_category_sync_course($course2);
enrol_category_sync_course($course3);
enrol_category_sync_course($course4);
$this->assertFalse(is_enrolled(context_course::instance($course1->id), $user1->id));
$this->assertTrue(is_enrolled(context_course::instance($course2->id), $user1->id));
$this->assertTrue(is_enrolled(context_course::instance($course3->id), $user1->id));
$this->assertTrue(is_enrolled(context_course::instance($course4->id), $user1->id));
$this->assertFalse(is_enrolled(\context_course::instance($course1->id), $user1->id));
$this->assertTrue(is_enrolled(\context_course::instance($course2->id), $user1->id));
$this->assertTrue(is_enrolled(\context_course::instance($course3->id), $user1->id));
$this->assertTrue(is_enrolled(\context_course::instance($course4->id), $user1->id));
$this->assertEquals(3, $DB->count_records('user_enrolments', array()));
$this->disable_plugin(); // Stops the event handlers.
role_assign($studentrole->id, $user2->id, context_coursecat::instance($cat1->id));
role_assign($teacherrole->id, $user4->id, context_coursecat::instance($cat1->id));
role_unassign($studentrole->id, $user1->id, context_coursecat::instance($cat2->id)->id);
role_assign($studentrole->id, $user2->id, \context_coursecat::instance($cat1->id));
role_assign($teacherrole->id, $user4->id, \context_coursecat::instance($cat1->id));
role_unassign($studentrole->id, $user1->id, \context_coursecat::instance($cat2->id)->id);
$this->assertEquals(3, $DB->count_records('user_enrolments', array()));
$this->enable_plugin();
enrol_category_sync_course($course2);
$this->assertFalse(is_enrolled(context_course::instance($course2->id), $user1->id));
$this->assertFalse(is_enrolled(context_course::instance($course2->id), $user2->id));
$this->assertFalse(is_enrolled(context_course::instance($course2->id), $user4->id));
$this->assertFalse(is_enrolled(\context_course::instance($course2->id), $user1->id));
$this->assertFalse(is_enrolled(\context_course::instance($course2->id), $user2->id));
$this->assertFalse(is_enrolled(\context_course::instance($course2->id), $user4->id));
enrol_category_sync_course($course1);
enrol_category_sync_course($course3);
enrol_category_sync_course($course4);
$this->assertEquals(2, $DB->count_records('user_enrolments', array()));
$this->assertTrue(is_enrolled(context_course::instance($course1->id), $user2->id));
$this->assertTrue(is_enrolled(context_course::instance($course1->id), $user4->id));
$this->assertTrue(is_enrolled(\context_course::instance($course1->id), $user2->id));
$this->assertTrue(is_enrolled(\context_course::instance($course1->id), $user4->id));
$this->disable_role_sync($studentrole->id);
enrol_category_sync_course($course1);
@ -240,7 +239,7 @@ class enrol_category_plugin_testcase extends advanced_testcase {
enrol_category_sync_course($course3);
enrol_category_sync_course($course4);
$this->assertEquals(1, $DB->count_records('user_enrolments', array()));
$this->assertTrue(is_enrolled(context_course::instance($course1->id), $user4->id));
$this->assertTrue(is_enrolled(\context_course::instance($course1->id), $user4->id));
$this->assertEquals(1, $DB->count_records('enrol', array('enrol'=>'category')));
$this->disable_role_sync($teacherrole->id);
@ -258,7 +257,7 @@ class enrol_category_plugin_testcase extends advanced_testcase {
$this->resetAfterTest();
$trace = new null_progress_trace();
$trace = new \null_progress_trace();
// Setup a few courses and categories.
@ -288,39 +287,39 @@ class enrol_category_plugin_testcase extends advanced_testcase {
$this->enable_plugin();
$this->assertEquals(0, $DB->count_records('role_assignments', array()));
role_assign($managerrole->id, $user1->id, context_coursecat::instance($cat1->id));
role_assign($managerrole->id, $user3->id, context_course::instance($course1->id));
role_assign($managerrole->id, $user3->id, context_course::instance($course2->id));
role_assign($managerrole->id, $user1->id, \context_coursecat::instance($cat1->id));
role_assign($managerrole->id, $user3->id, \context_course::instance($course1->id));
role_assign($managerrole->id, $user3->id, \context_course::instance($course2->id));
$this->assertEquals(0, $DB->count_records('user_enrolments', array()));
$result = enrol_category_sync_full($trace);
$this->assertSame(0, $result);
$this->disable_plugin();
role_assign($studentrole->id, $user1->id, context_coursecat::instance($cat2->id));
role_assign($studentrole->id, $user1->id, \context_coursecat::instance($cat2->id));
$this->enable_plugin();
$result = enrol_category_sync_full($trace);
$this->assertSame(0, $result);
$this->assertEquals(3, $DB->count_records('user_enrolments', array()));
$this->assertTrue(is_enrolled(context_course::instance($course2->id), $user1->id));
$this->assertTrue(is_enrolled(context_course::instance($course3->id), $user1->id));
$this->assertTrue(is_enrolled(context_course::instance($course4->id), $user1->id));
$this->assertTrue(is_enrolled(\context_course::instance($course2->id), $user1->id));
$this->assertTrue(is_enrolled(\context_course::instance($course3->id), $user1->id));
$this->assertTrue(is_enrolled(\context_course::instance($course4->id), $user1->id));
$this->disable_plugin();
role_unassign($studentrole->id, $user1->id, context_coursecat::instance($cat2->id)->id);
role_assign($studentrole->id, $user2->id, context_coursecat::instance($cat1->id));
role_assign($teacherrole->id, $user4->id, context_coursecat::instance($cat1->id));
role_assign($teacherrole->id, $user3->id, context_coursecat::instance($cat2->id));
role_assign($managerrole->id, $user3->id, context_course::instance($course3->id));
role_unassign($studentrole->id, $user1->id, \context_coursecat::instance($cat2->id)->id);
role_assign($studentrole->id, $user2->id, \context_coursecat::instance($cat1->id));
role_assign($teacherrole->id, $user4->id, \context_coursecat::instance($cat1->id));
role_assign($teacherrole->id, $user3->id, \context_coursecat::instance($cat2->id));
role_assign($managerrole->id, $user3->id, \context_course::instance($course3->id));
$this->enable_plugin();
$result = enrol_category_sync_full($trace);
$this->assertSame(0, $result);
$this->assertEquals(5, $DB->count_records('user_enrolments', array()));
$this->assertTrue(is_enrolled(context_course::instance($course1->id), $user2->id));
$this->assertTrue(is_enrolled(context_course::instance($course1->id), $user4->id));
$this->assertTrue(is_enrolled(context_course::instance($course2->id), $user3->id));
$this->assertTrue(is_enrolled(context_course::instance($course3->id), $user3->id));
$this->assertTrue(is_enrolled(context_course::instance($course4->id), $user3->id));
$this->assertTrue(is_enrolled(\context_course::instance($course1->id), $user2->id));
$this->assertTrue(is_enrolled(\context_course::instance($course1->id), $user4->id));
$this->assertTrue(is_enrolled(\context_course::instance($course2->id), $user3->id));
$this->assertTrue(is_enrolled(\context_course::instance($course3->id), $user3->id));
$this->assertTrue(is_enrolled(\context_course::instance($course4->id), $user3->id));
// Cleanup everything.

View File

@ -14,15 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Test the helper functionality.
*
* @package enrol_lti
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace enrol_lti;
/**
* Test the helper functionality.
@ -31,15 +23,15 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class enrol_lti_helper_testcase extends advanced_testcase {
class helper_test extends \advanced_testcase {
/**
* @var stdClass $user1 A user.
* @var \stdClass $user1 A user.
*/
public $user1;
/**
* @var stdClass $user2 A user.
* @var \stdClass $user2 A user.
*/
public $user2;
@ -72,14 +64,14 @@ class enrol_lti_helper_testcase extends advanced_testcase {
$this->user1 = $DB->get_record('user', array('id' => $this->user1->id));
// Set the page details.
$page = new moodle_page();
$page = new \moodle_page();
$page->set_url('/user/profile.php');
$page->set_context(context_system::instance());
$page->set_context(\context_system::instance());
$renderer = $page->get_renderer('core');
$usercontext = context_user::instance($this->user1->id);
$usercontext = \context_user::instance($this->user1->id);
// Get the user's profile picture and make sure it is correct.
$userpicture = new user_picture($this->user1);
$userpicture = new \user_picture($this->user1);
$this->assertSame($CFG->wwwroot . '/pluginfile.php/' . $usercontext->id . '/user/icon/boost/f2?rev=' .$this->user1->picture,
$userpicture->get_url($page, $renderer)->out(false));
}
@ -91,7 +83,7 @@ class enrol_lti_helper_testcase extends advanced_testcase {
global $DB;
// Set up the LTI enrolment tool.
$data = new stdClass();
$data = new \stdClass();
$data->maxenrolled = 1;
$tool = $this->getDataGenerator()->create_lti_tool($data);
@ -120,7 +112,7 @@ class enrol_lti_helper_testcase extends advanced_testcase {
global $DB;
// Set up the LTI enrolment tool.
$data = new stdClass();
$data = new \stdClass();
$data->enrolstartdate = time() + DAYSECS; // Make sure it is in the future.
$tool = $this->getDataGenerator()->create_lti_tool($data);
@ -142,7 +134,7 @@ class enrol_lti_helper_testcase extends advanced_testcase {
global $DB;
// Set up the LTI enrolment tool.
$data = new stdClass();
$data = new \stdClass();
$data->enrolenddate = time() - DAYSECS; // Make sure it is in the past.
$tool = $this->getDataGenerator()->create_lti_tool($data);
@ -164,14 +156,14 @@ class enrol_lti_helper_testcase extends advanced_testcase {
$generator = $this->getDataGenerator();
// Create two tools belonging to the same course.
$course1 = $generator->create_course();
$data = new stdClass();
$data = new \stdClass();
$data->courseid = $course1->id;
$generator->create_lti_tool($data);
$generator->create_lti_tool($data);
// Create two more tools in a separate course.
$course2 = $this->getDataGenerator()->create_course();
$data = new stdClass();
$data = new \stdClass();
$data->courseid = $course2->id;
$generator->create_lti_tool($data);
@ -203,14 +195,14 @@ class enrol_lti_helper_testcase extends advanced_testcase {
$generator = $this->getDataGenerator();
// Create two tools belonging to the same course.
$course1 = $generator->create_course();
$data = new stdClass();
$data = new \stdClass();
$data->courseid = $course1->id;
$tool1 = $generator->create_lti_tool($data);
$tool2 = $generator->create_lti_tool($data);
// Create two more tools in a separate course.
$course2 = $generator->create_course();
$data = new stdClass();
$data = new \stdClass();
$data->courseid = $course2->id;
$tool3 = $generator->create_lti_tool($data);
@ -254,7 +246,7 @@ class enrol_lti_helper_testcase extends advanced_testcase {
*/
public function test_get_launch_url() {
$course1 = $this->getDataGenerator()->create_course();
$data = new stdClass();
$data = new \stdClass();
$data->courseid = $course1->id;
$tool1 = $this->getDataGenerator()->create_lti_tool($data);
@ -274,7 +266,7 @@ class enrol_lti_helper_testcase extends advanced_testcase {
$CFG->slasharguments = false;
$course1 = $this->getDataGenerator()->create_course();
$data = new stdClass();
$data = new \stdClass();
$data->courseid = $course1->id;
$tool1 = $this->getDataGenerator()->create_lti_tool($data);
@ -304,7 +296,7 @@ class enrol_lti_helper_testcase extends advanced_testcase {
$CFG->slasharguments = false;
$course1 = $this->getDataGenerator()->create_course();
$data = new stdClass();
$data = new \stdClass();
$data->courseid = $course1->id;
$tool1 = $this->getDataGenerator()->create_lti_tool($data);
@ -328,7 +320,7 @@ class enrol_lti_helper_testcase extends advanced_testcase {
*/
public function test_get_name() {
$course1 = $this->getDataGenerator()->create_course();
$data = new stdClass();
$data = new \stdClass();
$data->courseid = $course1->id;
$tool1 = $this->getDataGenerator()->create_lti_tool($data);
@ -346,7 +338,7 @@ class enrol_lti_helper_testcase extends advanced_testcase {
public function test_get_description() {
$generator = $this->getDataGenerator();
$course1 = $generator->create_course();
$data = new stdClass();
$data = new \stdClass();
$data->courseid = $course1->id;
$tool1 = $generator->create_lti_tool($data);
@ -356,7 +348,7 @@ class enrol_lti_helper_testcase extends advanced_testcase {
$module1 = $generator->create_module('assign', array(
'course' => $course1->id
));
$data = new stdClass();
$data = new \stdClass();
$data->cmid = $module1->cmid;
$tool2 = $generator->create_lti_tool($data);
$description = \enrol_lti\helper::get_description($tool2);
@ -370,7 +362,7 @@ class enrol_lti_helper_testcase extends advanced_testcase {
global $CFG;
$course1 = $this->getDataGenerator()->create_course();
$data = new stdClass();
$data = new \stdClass();
$data->courseid = $course1->id;
$tool = $this->getDataGenerator()->create_lti_tool($data);
@ -386,7 +378,7 @@ class enrol_lti_helper_testcase extends advanced_testcase {
*/
public function test_verify_cartridge_token() {
$course1 = $this->getDataGenerator()->create_course();
$data = new stdClass();
$data = new \stdClass();
$data->courseid = $course1->id;
$tool1 = $this->getDataGenerator()->create_lti_tool($data);
@ -400,7 +392,7 @@ class enrol_lti_helper_testcase extends advanced_testcase {
*/
public function test_verify_proxy_token() {
$course1 = $this->getDataGenerator()->create_course();
$data = new stdClass();
$data = new \stdClass();
$data->courseid = $course1->id;
$tool1 = $this->getDataGenerator()->create_lti_tool($data);
@ -483,7 +475,7 @@ class enrol_lti_helper_testcase extends advanced_testcase {
* @param string $expected The name of the fixture file containing the expected result.
*/
public function test_set_xpath($parameters, $expected) {
$helper = new ReflectionClass('enrol_lti\\helper');
$helper = new \ReflectionClass('enrol_lti\\helper');
$function = $helper->getMethod('set_xpath');
$function->setAccessible(true);
@ -508,7 +500,7 @@ class enrol_lti_helper_testcase extends advanced_testcase {
],
]
];
$helper = new ReflectionClass('enrol_lti\\helper');
$helper = new \ReflectionClass('enrol_lti\\helper');
$function = $helper->getMethod('set_xpath');
$function->setAccessible(true);
@ -527,7 +519,7 @@ class enrol_lti_helper_testcase extends advanced_testcase {
global $CFG;
$course1 = $this->getDataGenerator()->create_course();
$data = new stdClass();
$data = new \stdClass();
$data->courseid = $course1->id;
$tool1 = $this->getDataGenerator()->create_lti_tool($data);

View File

@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace enrol_meta;
/**
* Meta enrolment sync functional test.
*
@ -22,12 +24,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();
global $CFG;
class enrol_meta_plugin_testcase extends advanced_testcase {
class plugin_test extends \advanced_testcase {
protected function enable_plugin() {
$enabled = enrol_get_plugins(true);
@ -60,7 +57,7 @@ class enrol_meta_plugin_testcase extends advanced_testcase {
protected function has_role($user, $enrol, $role) {
global $DB;
$context = context_course::instance($enrol->courseid);
$context = \context_course::instance($enrol->courseid);
if ($role === false) {
if ($DB->record_exists('role_assignments', array('contextid'=>$context->id, 'userid'=>$user->id, 'component'=>'enrol_meta', 'itemid'=>$enrol->id))) {
@ -294,7 +291,7 @@ class enrol_meta_plugin_testcase extends advanced_testcase {
$this->assertEquals(10, $DB->count_records('user_enrolments', array('status'=>ENROL_USER_ACTIVE)));
$this->assertFalse($this->is_meta_enrolled($user1, $enrol1, $student));
role_assign($teacher->id, $user1->id, context_course::instance($course1->id)->id);
role_assign($teacher->id, $user1->id, \context_course::instance($course1->id)->id);
$this->assertEquals(11, $DB->count_records('user_enrolments'));
$this->assertEquals(10, $DB->count_records('role_assignments'));
$this->assertEquals(11, $DB->count_records('user_enrolments', array('status'=>ENROL_USER_ACTIVE)));
@ -305,7 +302,7 @@ class enrol_meta_plugin_testcase extends advanced_testcase {
$this->assertEquals(11, $DB->count_records('user_enrolments', array('status'=>ENROL_USER_ACTIVE)));
$this->assertTrue($this->is_meta_enrolled($user1, $enrol1, $teacher));
role_unassign($teacher->id, $user1->id, context_course::instance($course1->id)->id);
role_unassign($teacher->id, $user1->id, \context_course::instance($course1->id)->id);
$this->assertEquals(10, $DB->count_records('user_enrolments'));
$this->assertEquals(8, $DB->count_records('role_assignments'));
$this->assertEquals(10, $DB->count_records('user_enrolments', array('status'=>ENROL_USER_ACTIVE)));
@ -510,29 +507,29 @@ class enrol_meta_plugin_testcase extends advanced_testcase {
enrol_get_plugin('manual')->unenrol_user($manualenrol1, $user1->id);
$this->assertFalse(groups_is_member($group31->id, $user1->id));
$this->assertTrue(groups_is_member($group32->id, $user1->id));
$this->assertTrue(is_enrolled(context_course::instance($course3->id), $user1, '', true)); // He still has active enrolment.
$this->assertTrue(is_enrolled(\context_course::instance($course3->id), $user1, '', true)); // He still has active enrolment.
// And the same after sync.
enrol_meta_sync(null, false);
$this->assertFalse(groups_is_member($group31->id, $user1->id));
$this->assertTrue(groups_is_member($group32->id, $user1->id));
$this->assertTrue(is_enrolled(context_course::instance($course3->id), $user1, '', true));
$this->assertTrue(is_enrolled(\context_course::instance($course3->id), $user1, '', true));
// Unenroll user1 from course2 and make sure he is completely unenrolled from course3.
enrol_get_plugin('manual')->unenrol_user($manualenrol2, $user1->id);
$this->assertFalse(groups_is_member($group32->id, $user1->id));
$this->assertFalse(is_enrolled(context_course::instance($course3->id), $user1));
$this->assertFalse(is_enrolled(\context_course::instance($course3->id), $user1));
set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES, 'enrol_meta');
// When user is unenrolled in this case, he is still a member of a group (but enrolment is suspended).
enrol_get_plugin('manual')->unenrol_user($manualenrol1, $user4->id);
$this->assertTrue(groups_is_member($group31->id, $user4->id));
$this->assertTrue(is_enrolled(context_course::instance($course3->id), $user4));
$this->assertFalse(is_enrolled(context_course::instance($course3->id), $user4, '', true));
$this->assertTrue(is_enrolled(\context_course::instance($course3->id), $user4));
$this->assertFalse(is_enrolled(\context_course::instance($course3->id), $user4, '', true));
enrol_meta_sync(null, false);
$this->assertTrue(groups_is_member($group31->id, $user4->id));
$this->assertTrue(is_enrolled(context_course::instance($course3->id), $user4));
$this->assertFalse(is_enrolled(context_course::instance($course3->id), $user4, '', true));
$this->assertTrue(is_enrolled(\context_course::instance($course3->id), $user4));
$this->assertFalse(is_enrolled(\context_course::instance($course3->id), $user4, '', true));
}
/**
@ -730,7 +727,7 @@ class enrol_meta_plugin_testcase extends advanced_testcase {
$this->assertEquals($metacourse->id, $group->courseid);
// Create a group that will have the same name as the course.
$groupdata = new stdClass();
$groupdata = new \stdClass();
$groupdata->courseid = $metacourse->id;
$groupdata->name = 'Physics course';
groups_create_group($groupdata);
@ -904,7 +901,7 @@ class enrol_meta_plugin_testcase extends advanced_testcase {
// Teachers don't have enrol/meta: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);
@ -935,7 +932,7 @@ class enrol_meta_plugin_testcase extends advanced_testcase {
// A course with meta enrolment.
$course = $this->getDataGenerator()->create_course();
$coursecontext = context_course::instance($course->id);
$coursecontext = \context_course::instance($course->id);
// Create a meta enrolment instance.
$instance = (object)$metaplugin->get_instance_defaults();
@ -979,10 +976,10 @@ class enrol_meta_plugin_testcase extends advanced_testcase {
$this->assertEquals('You are trying to use an invalid course ID', $errors['customint1']);
// Test when a course is set as a not visible and a user doesn't have the capability to use it here.
$metacourse2record = new stdClass();
$metacourse2record = new \stdClass();
$metacourse2record->visible = 0;
$metacourse2 = $this->getDataGenerator()->create_course($metacourse2record);
$metacourse2context = context_course::instance($metacourse2->id);
$metacourse2context = \context_course::instance($metacourse2->id);
$user = $this->getDataGenerator()->create_user();
$teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
@ -1003,7 +1000,7 @@ class enrol_meta_plugin_testcase extends advanced_testcase {
$metacourse2->visible = 1;
$DB->update_record('course', $metacourse2);
assign_capability('moodle/course:viewhiddencourses', CAP_ALLOW,
$teacherrole->id, context_course::instance($metacourse2->id));
$teacherrole->id, \context_course::instance($metacourse2->id));
// Test with no 'enrol/meta:selectaslinked' capability.
unassign_capability('enrol/meta:selectaslinked', $teacherrole->id);

View File

@ -14,6 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace message_airnotifier;
use message_airnotifier_manager;
/**
* Unit tests for message_airnotifier_manager.
*
@ -22,7 +26,7 @@
* @copyright 2020 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
class message_airnotifier_manager_testcase extends advanced_testcase {
class manager_test extends \advanced_testcase {
/** Test check_configuration by default **/
public function test_check_configuration_default() {
@ -33,17 +37,17 @@ class message_airnotifier_manager_testcase extends advanced_testcase {
// Mock server responses.
$CFG->airnotifierurl = 'localhost';
curl::mock_response(json_encode(['error' => 'Invalid access key'])); // Mock request to check access key.
\curl::mock_response(json_encode(['error' => 'Invalid access key'])); // Mock request to check access key.
$checks = $manager->check_configuration();
$this->assertEquals(core\check\result::OK, $checks[0]->get_status()); // Mobile service enabled.
$this->assertEquals(core\check\result::OK, $checks[1]->get_status()); // Message output not disabled in config.php.
$this->assertEquals(core\check\result::OK, $checks[2]->get_status()); // Mobile notifications enabled.
$this->assertEquals(core\check\result::ERROR, $checks[3]->get_status()); // Airnotifier NOT configured, missing key.
$this->assertEquals(core\check\result::OK, $checks[4]->get_status()); // Airnotifier URL available.
$this->assertEquals(core\check\result::ERROR, $checks[5]->get_status()); // Missing access key.
$this->assertEquals(core\check\result::OK, $checks[6]->get_status()); // Enough default mobile notifications.
$this->assertEquals(core\check\result::ERROR, $checks[7]->get_status()); // No registered devices yet.
$this->assertEquals(\core\check\result::OK, $checks[0]->get_status()); // Mobile service enabled.
$this->assertEquals(\core\check\result::OK, $checks[1]->get_status()); // Message output not disabled in config.php.
$this->assertEquals(\core\check\result::OK, $checks[2]->get_status()); // Mobile notifications enabled.
$this->assertEquals(\core\check\result::ERROR, $checks[3]->get_status()); // Airnotifier NOT configured, missing key.
$this->assertEquals(\core\check\result::OK, $checks[4]->get_status()); // Airnotifier URL available.
$this->assertEquals(\core\check\result::ERROR, $checks[5]->get_status()); // Missing access key.
$this->assertEquals(\core\check\result::OK, $checks[6]->get_status()); // Enough default mobile notifications.
$this->assertEquals(\core\check\result::ERROR, $checks[7]->get_status()); // No registered devices yet.
}
/** Test check_configuration with token **/
@ -55,19 +59,19 @@ class message_airnotifier_manager_testcase extends advanced_testcase {
// Mock server responses.
$CFG->airnotifierurl = 'localhost';
curl::mock_response(json_encode(['status' => 'ok'])); // Mock first request to check URL.
curl::mock_response(json_encode(['error' => 'Invalid access key'])); // Mock second request to check acces key.
\curl::mock_response(json_encode(['status' => 'ok'])); // Mock first request to check URL.
\curl::mock_response(json_encode(['error' => 'Invalid access key'])); // Mock second request to check acces key.
$CFG->airnotifieraccesskey = 'test'; // For enabling Airnotifier.
$checks = $manager->check_configuration();
$this->assertEquals(core\check\result::OK, $checks[0]->get_status()); // Mobile service enabled.
$this->assertEquals(core\check\result::OK, $checks[1]->get_status()); // Message output not disabled in config.php.
$this->assertEquals(core\check\result::OK, $checks[2]->get_status()); // Mobile notifications enabled.
$this->assertEquals(core\check\result::OK, $checks[3]->get_status()); // Airnotifier configured.
$this->assertEquals(core\check\result::OK, $checks[4]->get_status()); // Airnotifier URL available.
$this->assertEquals(\core\check\result::OK, $checks[0]->get_status()); // Mobile service enabled.
$this->assertEquals(\core\check\result::OK, $checks[1]->get_status()); // Message output not disabled in config.php.
$this->assertEquals(\core\check\result::OK, $checks[2]->get_status()); // Mobile notifications enabled.
$this->assertEquals(\core\check\result::OK, $checks[3]->get_status()); // Airnotifier configured.
$this->assertEquals(\core\check\result::OK, $checks[4]->get_status()); // Airnotifier URL available.
// The original function fourth check (access key valid in the remote Airnotifier server) is not mockable.
$this->assertEquals(core\check\result::OK, $checks[5]->get_status()); // Enough default mobile notifications.
$this->assertEquals(core\check\result::ERROR, $checks[6]->get_status()); // No registered devices yet.
$this->assertEquals(\core\check\result::OK, $checks[5]->get_status()); // Enough default mobile notifications.
$this->assertEquals(\core\check\result::ERROR, $checks[6]->get_status()); // No registered devices yet.
}
/** Test check_configuration bad settings **/
@ -79,23 +83,23 @@ class message_airnotifier_manager_testcase extends advanced_testcase {
// Mock server responses.
$CFG->airnotifierurl = 'localhost';
curl::mock_response(json_encode(['status' => 'ok'])); // Mock first request to check URL.
curl::mock_response(json_encode(['error' => 'Invalid access key'])); // Mock second request to check acces key.
\curl::mock_response(json_encode(['status' => 'ok'])); // Mock first request to check URL.
\curl::mock_response(json_encode(['error' => 'Invalid access key'])); // Mock second request to check acces key.
$CFG->airnotifieraccesskey = 'test'; // For enabling Airnotifier.
$CFG->airnotifierappname .= ' ';
$CFG->noemailever = true;
$checks = $manager->check_configuration();
$this->assertEquals(core\check\result::OK, $checks[0]->get_status()); // Mobile service enabled.
$this->assertEquals(core\check\result::CRITICAL, $checks[1]->get_status()); // Message output disabled in config.php.
$this->assertEquals(core\check\result::OK, $checks[2]->get_status()); // Mobile notifications enabled.
$this->assertEquals(core\check\result::OK, $checks[3]->get_status()); // Airnotifier configured.
$this->assertEquals(core\check\result::ERROR, $checks[4]->get_status()); // Airnotifier URL available.
$this->assertEquals(core\check\result::OK, $checks[5]->get_status()); // Invalid setting (empty space).
$this->assertEquals(\core\check\result::OK, $checks[0]->get_status()); // Mobile service enabled.
$this->assertEquals(\core\check\result::CRITICAL, $checks[1]->get_status()); // Message output disabled in config.php.
$this->assertEquals(\core\check\result::OK, $checks[2]->get_status()); // Mobile notifications enabled.
$this->assertEquals(\core\check\result::OK, $checks[3]->get_status()); // Airnotifier configured.
$this->assertEquals(\core\check\result::ERROR, $checks[4]->get_status()); // Airnotifier URL available.
$this->assertEquals(\core\check\result::OK, $checks[5]->get_status()); // Invalid setting (empty space).
// The original function fifth check (access key valid in the remote Airnotifier server) is not mockable.
$this->assertEquals(core\check\result::OK, $checks[6]->get_status()); // Enough default mobile notifications.
$this->assertEquals(core\check\result::ERROR, $checks[7]->get_status()); // No registered devices yet.
$this->assertEquals(\core\check\result::OK, $checks[6]->get_status()); // Enough default mobile notifications.
$this->assertEquals(\core\check\result::ERROR, $checks[7]->get_status()); // No registered devices yet.
}
/** Test has_enabled_devices **/
@ -110,7 +114,7 @@ class message_airnotifier_manager_testcase extends advanced_testcase {
$this->assertFalse($manager->has_enabled_devices($CFG->airnotifiermobileappname));
// Add devices.
curl::mock_response(json_encode(['status' => 'ok']));
\curl::mock_response(json_encode(['status' => 'ok']));
$DB->insert_record('user_devices',
['userid' => $USER->id, 'appid' => $CFG->airnotifiermobileappname, 'platform' => 'ios',
'timecreated' => time(), 'timemodified' => time()]);

View File

@ -14,14 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Test message popup API.
*
* @package message_popup
* @category test
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace message_popup;
defined('MOODLE_INTERNAL') || die();
@ -38,8 +31,8 @@ require_once($CFG->dirroot . '/message/output/popup/tests/base.php');
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class message_popup_api_testcase extends advanced_testcase {
use message_popup_test_helper;
class api_test extends \advanced_testcase {
use \message_popup_test_helper;
/**
* Test set up.

File diff suppressed because it is too large Load Diff

View File

@ -14,14 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains a test class for the message helper.
*
* @package core_message
* @category test
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_message;
defined('MOODLE_INTERNAL') || die();
@ -37,7 +30,7 @@ require_once($CFG->dirroot . '/message/tests/messagelib_test.php');
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_message_helper_testcase extends advanced_testcase {
class helper_test extends \advanced_testcase {
public function setUp(): void {
$this->resetAfterTest(true);

View File

@ -14,18 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore date tests.
*
* @package mod_assign
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\backup;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php");
require_once($CFG->libdir . '/phpunit/classes/restore_date_testcase.php');
require_once($CFG->dirroot . '/mod/assign/tests/fixtures/testable_assign.php');
/**
* Restore date tests.
@ -34,7 +29,7 @@ require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php");
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_assign_restore_date_testcase extends restore_date_testcase {
class restore_date_test extends \restore_date_testcase {
/**
* Test restore dates.
@ -45,7 +40,7 @@ class mod_assign_restore_date_testcase extends restore_date_testcase {
$record = ['cutoffdate' => 100, 'allowsubmissionsfromdate' => 100, 'duedate' => 100, 'timemodified' => 100];
list($course, $assign) = $this->create_course_and_module('assign', $record);
$cm = $DB->get_record('course_modules', ['course' => $course->id, 'instance' => $assign->id]);
$assignobj = new mod_assign_testable_assign(context_module::instance($cm->id), $cm, $course);
$assignobj = new \mod_assign_testable_assign(\context_module::instance($cm->id), $cm, $course);
$submission = $assignobj->get_user_submission($USER->id, true);
$grade = $assignobj->get_user_grade($USER->id, true);

View File

@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore date tests.
*
* @package mod_chat
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_chat\backup;
defined('MOODLE_INTERNAL') || die();
@ -34,18 +28,18 @@ require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php");
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_chat_restore_date_testcase extends restore_date_testcase {
class restore_date_test extends \restore_date_testcase {
public function test_restore_dates() {
global $DB;
list($course, $chat) = $this->create_course_and_module('chat');
$result = mod_chat_external::login_user($chat->id);
$result = external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
$result = \mod_chat_external::login_user($chat->id);
$result = \external_api::clean_returnvalue(\mod_chat_external::login_user_returns(), $result);
$chatsid = $result['chatsid'];
$result = mod_chat_external::send_chat_message($chatsid, 'hello!');
$result = external_api::clean_returnvalue(mod_chat_external::send_chat_message_returns(), $result);
$result = \mod_chat_external::send_chat_message($chatsid, 'hello!');
$result = \external_api::clean_returnvalue(\mod_chat_external::send_chat_message_returns(), $result);
$message = $DB->get_record('chat_messages', ['id' => $result['messageid']]);
$timestamp = 1000;
$DB->set_field('chat_messages', 'timestamp', $timestamp);

View File

@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore date tests.
*
* @package mod_choice
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_choice\backup;
defined('MOODLE_INTERNAL') || die();
@ -34,7 +28,7 @@ require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php");
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_choice_restore_date_testcase extends restore_date_testcase {
class restore_date_test extends \restore_date_testcase {
public function test_restore_dates() {
global $DB, $USER;

View File

@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore date tests.
*
* @package mod_data
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_data\backup;
defined('MOODLE_INTERNAL') || die();
@ -35,7 +29,7 @@ require_once($CFG->dirroot . '/rating/lib.php');
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_data_restore_date_testcase extends restore_date_testcase {
class restore_date_test extends \restore_date_testcase {
/**
* Test restore dates.
@ -51,7 +45,7 @@ class mod_data_restore_date_testcase extends restore_date_testcase {
// Data field/record.
$timestamp = 996699;
$diff = $this->get_diff();
$record = new StdClass();
$record = new \stdClass();
$record->name = 'field-1';
$record->type = 'text';
$field = $gg->create_field($record, $data);
@ -59,14 +53,14 @@ class mod_data_restore_date_testcase extends restore_date_testcase {
$datarecord = $DB->get_record('data_records', ['id' => $datarecordid]);
// Ratings.
$ratingoptions = new stdClass;
$ratingoptions->context = context_module::instance($data->cmid);
$ratingoptions = new \stdClass;
$ratingoptions->context = \context_module::instance($data->cmid);
$ratingoptions->ratingarea = 'entry';
$ratingoptions->component = 'mod_data';
$ratingoptions->itemid = $datarecord->id;
$ratingoptions->scaleid = 2;
$ratingoptions->userid = $USER->id;
$rating = new rating($ratingoptions);
$rating = new \rating($ratingoptions);
$rating->update_rating(2);
$rating = $DB->get_record('rating', ['itemid' => $datarecord->id]);
@ -86,7 +80,7 @@ class mod_data_restore_date_testcase extends restore_date_testcase {
$this->assertEquals($datarecord->timemodified, $newdatarecord->timemodified);
// Rating test.
$newrating = $DB->get_record('rating', ['contextid' => context_module::instance($newcm->id)->id]);
$newrating = $DB->get_record('rating', ['contextid' => \context_module::instance($newcm->id)->id]);
$this->assertEquals($rating->timecreated, $newrating->timecreated);
$this->assertEquals($rating->timemodified, $newrating->timemodified);
}

View File

@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore date tests.
*
* @package mod_feedback
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_feedback\backup;
defined('MOODLE_INTERNAL') || die();
@ -34,7 +28,7 @@ require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php");
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_feedback_restore_date_testcase extends restore_date_testcase {
class restore_date_test extends \restore_date_testcase {
public function test_restore_dates() {
global $DB, $USER;
@ -43,7 +37,7 @@ class mod_feedback_restore_date_testcase extends restore_date_testcase {
list($course, $feedback) = $this->create_course_and_module('feedback', ['timeopen' => $time, 'timeclose' => $time]);
// Create response.
$response = new stdClass();
$response = new \stdClass();
$response->feedback = $feedback->id;
$response->userid = $USER->id;
$response->anonymous_response = FEEDBACK_ANONYMOUS_NO;

View File

@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore date tests.
*
* @package mod_folder
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_folder\backup;
defined('MOODLE_INTERNAL') || die();
@ -34,7 +28,7 @@ require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php");
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_folder_restore_date_testcase extends restore_date_testcase {
class restore_date_test extends \restore_date_testcase {
public function test_restore_dates() {
global $DB;

View File

@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore date tests.
*
* @package mod_forum
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum\backup;
defined('MOODLE_INTERNAL') || die();
@ -35,7 +29,7 @@ require_once($CFG->dirroot . '/rating/lib.php');
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_restore_date_testcase extends restore_date_testcase {
class restore_date_test extends \restore_date_testcase {
/**
* Test restore dates.
@ -50,14 +44,14 @@ class mod_forum_restore_date_testcase extends restore_date_testcase {
// Forum Discussions/posts/ratings.
$timestamp = 996699;
$diff = $this->get_diff();
$record = new stdClass();
$record = new \stdClass();
$record->course = $course->id;
$record->userid = $USER->id;
$record->forum = $forum->id;
$record->timestart = $record->timeend = $record->timemodified = $timestamp;
$discussion = $gg->create_discussion($record);
$record = new stdClass();
$record = new \stdClass();
$record->discussion = $discussion->id;
$record->parent = $discussion->firstpost;
$record->userid = $USER->id;
@ -68,14 +62,14 @@ class mod_forum_restore_date_testcase extends restore_date_testcase {
$DB->set_field('forum_discussions', 'timemodified', $timestamp);
// Ratings.
$ratingoptions = new stdClass;
$ratingoptions->context = context_module::instance($forum->cmid);
$ratingoptions = new \stdClass;
$ratingoptions->context = \context_module::instance($forum->cmid);
$ratingoptions->ratingarea = 'post';
$ratingoptions->component = 'mod_forum';
$ratingoptions->itemid = $post->id;
$ratingoptions->scaleid = 2;
$ratingoptions->userid = $USER->id;
$rating = new rating($ratingoptions);
$rating = new \rating($ratingoptions);
$rating->update_rating(2);
$rating = $DB->get_record('rating', ['itemid' => $post->id]);
@ -103,7 +97,7 @@ class mod_forum_restore_date_testcase extends restore_date_testcase {
}
// Rating test.
$newrating = $DB->get_record('rating', ['contextid' => context_module::instance($newcm->id)->id]);
$newrating = $DB->get_record('rating', ['contextid' => \context_module::instance($newcm->id)->id]);
$this->assertEquals($rating->timecreated, $newrating->timecreated);
$this->assertEquals($rating->timemodified, $newrating->timemodified);
}

View File

@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore date tests.
*
* @package mod_glossary
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_glossary\backup;
defined('MOODLE_INTERNAL') || die();
@ -35,7 +29,7 @@ require_once($CFG->dirroot . '/rating/lib.php');
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_glossary_restore_date_testcase extends restore_date_testcase {
class restore_date_test extends \restore_date_testcase {
/**
* Test restore dates.
@ -55,14 +49,14 @@ class mod_glossary_restore_date_testcase extends restore_date_testcase {
$timestamp = 10000;
$DB->set_field('glossary_entries', 'timecreated', $timestamp);
$DB->set_field('glossary_entries', 'timemodified', $timestamp);
$ratingoptions = new stdClass;
$ratingoptions->context = context_module::instance($glossary->cmid);
$ratingoptions = new \stdClass;
$ratingoptions->context = \context_module::instance($glossary->cmid);
$ratingoptions->ratingarea = 'entry';
$ratingoptions->component = 'mod_glossary';
$ratingoptions->itemid = $entry1->id;
$ratingoptions->scaleid = 2;
$ratingoptions->userid = $USER->id;
$rating = new rating($ratingoptions);
$rating = new \rating($ratingoptions);
$rating->update_rating(2);
$rating = $DB->get_record('rating', ['itemid' => $entry1->id]);
@ -84,7 +78,7 @@ class mod_glossary_restore_date_testcase extends restore_date_testcase {
}
// Rating test.
$newrating = $DB->get_record('rating', ['contextid' => context_module::instance($newcm->id)->id]);
$newrating = $DB->get_record('rating', ['contextid' => \context_module::instance($newcm->id)->id]);
$this->assertEquals($rating->timecreated, $newrating->timecreated);
$this->assertEquals($rating->timemodified, $newrating->timemodified);
}

View File

@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore date tests.
*
* @package mod_imscp
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_imscp\backup;
defined('MOODLE_INTERNAL') || die();
@ -34,7 +28,7 @@ require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php");
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_imscp_restore_date_testcase extends restore_date_testcase {
class restore_date_test extends \restore_date_testcase {
public function test_restore_dates() {
global $DB;

View File

@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore date tests.
*
* @package mod_lesson
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lesson\backup;
defined('MOODLE_INTERNAL') || die();
@ -34,15 +28,15 @@ require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php");
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_lesson_restore_date_testcase extends restore_date_testcase {
class restore_date_test extends \restore_date_testcase {
/**
* Creates an attempt for the given userwith a correct or incorrect answer and optionally finishes it.
*
* TODO This api can be better extracted to a generator.
*
* @param stdClass $lesson Lesson object.
* @param stdClass $page page object.
* @param \stdClass $lesson Lesson object.
* @param \stdClass $page page object.
* @param boolean $correct If the answer should be correct.
* @param boolean $finished If we should finish the attempt.
*
@ -52,7 +46,7 @@ class mod_lesson_restore_date_testcase extends restore_date_testcase {
global $DB, $USER;
// First we need to launch the lesson so the timer is on.
mod_lesson_external::launch_attempt($lesson->id);
\mod_lesson_external::launch_attempt($lesson->id);
$DB->set_field('lesson', 'feedback', 1, array('id' => $lesson->id));
$DB->set_field('lesson', 'progressbar', 1, array('id' => $lesson->id));
@ -80,8 +74,8 @@ class mod_lesson_restore_date_testcase extends restore_date_testcase {
'value' => 1,
)
);
$result = mod_lesson_external::process_page($lesson->id, $page->id, $data);
$result = external_api::clean_returnvalue(mod_lesson_external::process_page_returns(), $result);
$result = \mod_lesson_external::process_page($lesson->id, $page->id, $data);
$result = \external_api::clean_returnvalue(\mod_lesson_external::process_page_returns(), $result);
// Create attempt.
$newpageattempt = [
@ -97,8 +91,8 @@ class mod_lesson_restore_date_testcase extends restore_date_testcase {
$DB->insert_record('lesson_attempts', (object) $newpageattempt);
if ($finished) {
$result = mod_lesson_external::finish_attempt($lesson->id);
$result = external_api::clean_returnvalue(mod_lesson_external::finish_attempt_returns(), $result);
$result = \mod_lesson_external::finish_attempt($lesson->id);
$result = \external_api::clean_returnvalue(\mod_lesson_external::finish_attempt_returns(), $result);
}
return $result;
}
@ -120,7 +114,7 @@ class mod_lesson_restore_date_testcase extends restore_date_testcase {
$timer = $DB->get_record('lesson_timer', ['lessonid' => $lesson->id]);
// Lesson grade.
$timestamp = 100;
$grade = new stdClass();
$grade = new \stdClass();
$grade->lessonid = $lesson->id;
$grade->userid = $USER->id;
$grade->grade = 8.9;

View File

@ -14,15 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for the quizaccess_delaybetweenattempts plugin.
*
* @package quizaccess
* @subpackage delaybetweenattempts
* @category phpunit
* @copyright 2008 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace quizaccess_delaybetweenattempts;
use quiz;
use quizaccess_delaybetweenattempts;
defined('MOODLE_INTERNAL') || die();
@ -33,21 +28,23 @@ require_once($CFG->dirroot . '/mod/quiz/accessrule/delaybetweenattempts/rule.php
/**
* Unit tests for the quizaccess_delaybetweenattempts plugin.
*
* @package quizaccess_delaybetweenattempts
* @category test
* @copyright 2008 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quizaccess_delaybetweenattempts_testcase extends basic_testcase {
class rule_test extends \basic_testcase {
public function test_just_first_delay() {
$quiz = new stdClass();
$quiz = new \stdClass();
$quiz->attempts = 3;
$quiz->timelimit = 0;
$quiz->delay1 = 1000;
$quiz->delay2 = 0;
$quiz->timeclose = 0;
$cm = new stdClass();
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz($quiz, $cm, null);
$attempt = new stdClass();
$attempt = new \stdClass();
$attempt->timefinish = 10000;
$rule = new quizaccess_delaybetweenattempts($quizobj, 10000);
@ -72,16 +69,16 @@ class quizaccess_delaybetweenattempts_testcase extends basic_testcase {
}
public function test_just_second_delay() {
$quiz = new stdClass();
$quiz = new \stdClass();
$quiz->attempts = 5;
$quiz->timelimit = 0;
$quiz->delay1 = 0;
$quiz->delay2 = 1000;
$quiz->timeclose = 0;
$cm = new stdClass();
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz($quiz, $cm, null);
$attempt = new stdClass();
$attempt = new \stdClass();
$attempt->timefinish = 10000;
$rule = new quizaccess_delaybetweenattempts($quizobj, 10000);
@ -111,16 +108,16 @@ class quizaccess_delaybetweenattempts_testcase extends basic_testcase {
}
public function test_just_both_delays() {
$quiz = new stdClass();
$quiz = new \stdClass();
$quiz->attempts = 5;
$quiz->timelimit = 0;
$quiz->delay1 = 2000;
$quiz->delay2 = 1000;
$quiz->timeclose = 0;
$cm = new stdClass();
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz($quiz, $cm, null);
$attempt = new stdClass();
$attempt = new \stdClass();
$attempt->timefinish = 10000;
$rule = new quizaccess_delaybetweenattempts($quizobj, 10000);
@ -162,16 +159,16 @@ class quizaccess_delaybetweenattempts_testcase extends basic_testcase {
}
public function test_with_close_date() {
$quiz = new stdClass();
$quiz = new \stdClass();
$quiz->attempts = 5;
$quiz->timelimit = 0;
$quiz->delay1 = 2000;
$quiz->delay2 = 1000;
$quiz->timeclose = 15000;
$cm = new stdClass();
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz($quiz, $cm, null);
$attempt = new stdClass();
$attempt = new \stdClass();
$attempt->timefinish = 13000;
$rule = new quizaccess_delaybetweenattempts($quizobj, 10000);
@ -218,16 +215,16 @@ class quizaccess_delaybetweenattempts_testcase extends basic_testcase {
}
public function test_time_limit_and_overdue() {
$quiz = new stdClass();
$quiz = new \stdClass();
$quiz->attempts = 5;
$quiz->timelimit = 100;
$quiz->delay1 = 2000;
$quiz->delay2 = 1000;
$quiz->timeclose = 0;
$cm = new stdClass();
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz($quiz, $cm, null);
$attempt = new stdClass();
$attempt = new \stdClass();
$attempt->timestart = 9900;
$attempt->timefinish = 10100;

View File

@ -14,16 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for the quizaccess_ipaddress plugin.
*
* @package quizaccess
* @subpackage ipaddress
* @category phpunit
* @copyright 2008 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace quizaccess_ipaddress;
use quiz;
use quizaccess_ipaddress;
defined('MOODLE_INTERNAL') || die();
@ -34,14 +28,16 @@ require_once($CFG->dirroot . '/mod/quiz/accessrule/ipaddress/rule.php');
/**
* Unit tests for the quizaccess_ipaddress plugin.
*
* @package quizaccess_ipaddress
* @category test
* @copyright 2008 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quizaccess_ipaddress_testcase extends basic_testcase {
class rule_test extends \basic_testcase {
public function test_ipaddress_access_rule() {
$quiz = new stdClass();
$attempt = new stdClass();
$cm = new stdClass();
$quiz = new \stdClass();
$attempt = new \stdClass();
$cm = new \stdClass();
$cm->id = 0;
// Test the allowed case by getting the user's IP address. However, this

View File

@ -14,16 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for the quizaccess_numattempts plugin.
*
* @package quizaccess
* @subpackage numattempts
* @category phpunit
* @copyright 2008 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace quizaccess_numattempts;
use quiz;
use quizaccess_numattempts;
defined('MOODLE_INTERNAL') || die();
@ -34,18 +28,20 @@ require_once($CFG->dirroot . '/mod/quiz/accessrule/numattempts/rule.php');
/**
* Unit tests for the quizaccess_numattempts plugin.
*
* @package quizaccess_numattempts
* @category test
* @copyright 2008 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quizaccess_numattempts_testcase extends basic_testcase {
class rule_test extends \basic_testcase {
public function test_num_attempts_access_rule() {
$quiz = new stdClass();
$quiz = new \stdClass();
$quiz->attempts = 3;
$cm = new stdClass();
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz($quiz, $cm, null);
$rule = new quizaccess_numattempts($quizobj, 0);
$attempt = new stdClass();
$attempt = new \stdClass();
$this->assertEquals($rule->description(),
get_string('attemptsallowedn', 'quizaccess_numattempts', 3));

View File

@ -14,14 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for the quizaccess_offlineattempts plugin.
*
* @package quizaccess_offlineattempts
* @copyright 2016 Juan Leyva
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace quizaccess_offlineattempts;
use quiz;
use quizaccess_offlineattempts;
defined('MOODLE_INTERNAL') || die();
@ -32,18 +28,19 @@ require_once($CFG->dirroot . '/mod/quiz/accessrule/offlineattempts/rule.php');
/**
* Unit tests for the quizaccess_offlineattempts plugin.
*
* @package quizaccess_offlineattempts
* @copyright 2016 Juan Leyva
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quizaccess_offlineattempts_testcase extends basic_testcase {
class rule_test extends \basic_testcase {
public function test_offlineattempts_access_rule() {
$quiz = new stdClass();
$quiz = new \stdClass();
$quiz->allowofflineattempts = 1;
$cm = new stdClass();
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz($quiz, $cm, null);
$rule = new quizaccess_offlineattempts($quizobj, 0);
$attempt = new stdClass();
$attempt = new \stdClass();
$this->assertFalse($rule->prevent_access());
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));

View File

@ -14,16 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for the quizaccess_openclosedate plugin.
*
* @package quizaccess
* @subpackage openclosedate
* @category phpunit
* @copyright 2008 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace quizaccess_openclosedate;
use quiz;
use quizaccess_openclosedate;
defined('MOODLE_INTERNAL') || die();
@ -34,19 +28,21 @@ require_once($CFG->dirroot . '/mod/quiz/accessrule/openclosedate/rule.php');
/**
* Unit tests for the quizaccess_openclosedate plugin.
*
* @package quizaccess_openclosedate
* @category test
* @copyright 2008 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quizaccess_openclosedate_testcase extends basic_testcase {
class rule_test extends \basic_testcase {
public function test_no_dates() {
$quiz = new stdClass();
$quiz = new \stdClass();
$quiz->timeopen = 0;
$quiz->timeclose = 0;
$quiz->overduehandling = 'autosubmit';
$cm = new stdClass();
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz($quiz, $cm, null);
$attempt = new stdClass();
$attempt = new \stdClass();
$attempt->preview = 0;
$rule = new quizaccess_openclosedate($quizobj, 10000);
@ -66,14 +62,14 @@ class quizaccess_openclosedate_testcase extends basic_testcase {
}
public function test_start_date() {
$quiz = new stdClass();
$quiz = new \stdClass();
$quiz->timeopen = 10000;
$quiz->timeclose = 0;
$quiz->overduehandling = 'autosubmit';
$cm = new stdClass();
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz($quiz, $cm, null);
$attempt = new stdClass();
$attempt = new \stdClass();
$attempt->preview = 0;
$rule = new quizaccess_openclosedate($quizobj, 9999);
@ -93,14 +89,14 @@ class quizaccess_openclosedate_testcase extends basic_testcase {
}
public function test_close_date() {
$quiz = new stdClass();
$quiz = new \stdClass();
$quiz->timeopen = 0;
$quiz->timeclose = 20000;
$quiz->overduehandling = 'autosubmit';
$cm = new stdClass();
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz($quiz, $cm, null);
$attempt = new stdClass();
$attempt = new \stdClass();
$attempt->preview = 0;
$rule = new quizaccess_openclosedate($quizobj, 20000);
@ -127,14 +123,14 @@ class quizaccess_openclosedate_testcase extends basic_testcase {
}
public function test_both_dates() {
$quiz = new stdClass();
$quiz = new \stdClass();
$quiz->timeopen = 10000;
$quiz->timeclose = 20000;
$quiz->overduehandling = 'autosubmit';
$cm = new stdClass();
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz($quiz, $cm, null);
$attempt = new stdClass();
$attempt = new \stdClass();
$attempt->preview = 0;
$rule = new quizaccess_openclosedate($quizobj, 9999);
@ -167,15 +163,15 @@ class quizaccess_openclosedate_testcase extends basic_testcase {
}
public function test_close_date_with_overdue() {
$quiz = new stdClass();
$quiz = new \stdClass();
$quiz->timeopen = 0;
$quiz->timeclose = 20000;
$quiz->overduehandling = 'graceperiod';
$quiz->graceperiod = 1000;
$cm = new stdClass();
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz($quiz, $cm, null);
$attempt = new stdClass();
$attempt = new \stdClass();
$attempt->preview = 0;
$rule = new quizaccess_openclosedate($quizobj, 20000);

View File

@ -14,16 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for the quizaccess_password plugin.
*
* @package quizaccess
* @subpackage password
* @category phpunit
* @copyright 2008 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace quizaccess_password;
use quiz;
use quizaccess_password;
defined('MOODLE_INTERNAL') || die();
@ -34,18 +28,20 @@ require_once($CFG->dirroot . '/mod/quiz/accessrule/password/rule.php');
/**
* Unit tests for the quizaccess_password plugin.
*
* @package quizaccess_password
* @category test
* @copyright 2008 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quizaccess_password_testcase extends basic_testcase {
class rule_test extends \basic_testcase {
public function test_password_access_rule() {
$quiz = new stdClass();
$quiz = new \stdClass();
$quiz->password = 'frog';
$cm = new stdClass();
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz($quiz, $cm, null);
$rule = new quizaccess_password($quizobj, 0);
$attempt = new stdClass();
$attempt = new \stdClass();
$this->assertFalse($rule->prevent_access());
$this->assertEquals($rule->description(),

View File

@ -14,15 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* PHPUnit tests for helper class.
*
* @package quizaccess_seb
* @author Dmitrii Metelkin <dmitriim@catalyst-au.net>
* @copyright 2020 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace quizaccess_seb;
defined('MOODLE_INTERNAL') || die();
@ -31,11 +23,13 @@ require_once(__DIR__ . '/test_helper_trait.php');
/**
* PHPUnit tests for helper class.
*
* @package quizaccess_seb
* @author Dmitrii Metelkin <dmitriim@catalyst-au.net>
* @copyright 2020 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quizaccess_seb_helper_testhelpertrait extends advanced_testcase {
use quizaccess_seb_test_helper_trait;
class helper_test extends \advanced_testcase {
use \quizaccess_seb_test_helper_trait;
/**
* Test that we can check valid seb string.
@ -87,7 +81,7 @@ class quizaccess_seb_helper_testhelpertrait extends advanced_testcase {
$this->getDataGenerator()->enrol_user($user->id, $course->id);
$this->setUser($user); // Log user in.
$this->expectException(dml_exception::class);
$this->expectException(\dml_exception::class);
$this->expectExceptionMessage("Can't find data record in database. (SELECT cm.*, m.name, md.name AS modname \n"
. " FROM {course_modules} cm\n"
. " JOIN {modules} md ON md.id = cm.module\n"
@ -115,7 +109,7 @@ class quizaccess_seb_helper_testhelpertrait extends advanced_testcase {
$user = $this->getDataGenerator()->create_user();
$this->setUser($user); // Log user in.
$this->expectException(moodle_exception::class);
$this->expectException(\moodle_exception::class);
$this->expectExceptionMessage('Unsupported redirect detected, script execution terminated');
\quizaccess_seb\helper::get_seb_config_content($quiz->cmid);
}
@ -134,7 +128,7 @@ class quizaccess_seb_helper_testhelpertrait extends advanced_testcase {
$this->getDataGenerator()->enrol_user($user->id, $course->id);
$this->setUser($user); // Log user in.
$this->expectException(moodle_exception::class);
$this->expectException(\moodle_exception::class);
$this->expectExceptionMessage("No SEB config could be found for quiz with cmid: $quiz->cmid");
\quizaccess_seb\helper::get_seb_config_content($quiz->cmid);
}
@ -154,7 +148,7 @@ class quizaccess_seb_helper_testhelpertrait extends advanced_testcase {
$this->getDataGenerator()->enrol_user($user->id, $course->id);
$this->setUser($user); // Log user in.
$this->expectException(moodle_exception::class);
$this->expectException(\moodle_exception::class);
$this->expectExceptionMessage("No SEB config could be found for quiz with cmid: $quiz->cmid");
\quizaccess_seb\helper::get_seb_config_content($quiz->cmid);
}
@ -176,7 +170,7 @@ class quizaccess_seb_helper_testhelpertrait extends advanced_testcase {
$config = \quizaccess_seb\helper::get_seb_config_content($quiz->cmid);
$url = new moodle_url("/mod/quiz/view.php", ['id' => $quiz->cmid]);
$url = new \moodle_url("/mod/quiz/view.php", ['id' => $quiz->cmid]);
$this->assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
. "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"

View File

@ -14,17 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* PHPUnit tests for plugin rule class.
*
* @package quizaccess_seb
* @author Andrew Madden <andrewmadden@catalyst-au.net>
* @copyright 2019 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace quizaccess_seb;
use quizaccess_seb\quiz_settings;
use quizaccess_seb\settings_provider;
use quizaccess_seb;
defined('MOODLE_INTERNAL') || die();
@ -33,11 +25,13 @@ require_once(__DIR__ . '/test_helper_trait.php');
/**
* PHPUnit tests for plugin rule class.
*
* @package quizaccess_seb
* @author Andrew Madden <andrewmadden@catalyst-au.net>
* @copyright 2020 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quizaccess_seb_rule__testcase extends advanced_testcase {
use quizaccess_seb_test_helper_trait;
class rule_test extends \advanced_testcase {
use \quizaccess_seb_test_helper_trait;
/**
* Called before every test.
@ -122,7 +116,7 @@ class quizaccess_seb_rule__testcase extends advanced_testcase {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
$form = $this->createMock('mod_quiz_mod_form');
$form->method('get_context')->willReturn(context_module::instance($this->quiz->cmid));
$form->method('get_context')->willReturn(\context_module::instance($this->quiz->cmid));
// Validate settings with a dummy form.
$errors = quizaccess_seb::validate_settings_form_fields([], [
@ -146,7 +140,7 @@ class quizaccess_seb_rule__testcase extends advanced_testcase {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
$form = $this->createMock('mod_quiz_mod_form');
$form->method('get_context')->willReturn(context_module::instance($this->quiz->cmid));
$form->method('get_context')->willReturn(\context_module::instance($this->quiz->cmid));
// Validate settings with a dummy form and quiz instance.
$errors = quizaccess_seb::validate_settings_form_fields([], [
@ -168,7 +162,7 @@ class quizaccess_seb_rule__testcase extends advanced_testcase {
$this->setAdminUser();
$form = $this->createMock('mod_quiz_mod_form');
$form->method('get_context')->willReturn(context_module::instance($this->quiz->cmid));
$form->method('get_context')->willReturn(\context_module::instance($this->quiz->cmid));
// Validate settings with a dummy form and quiz instance.
$errors = quizaccess_seb::validate_settings_form_fields([], [
@ -186,11 +180,11 @@ class quizaccess_seb_rule__testcase extends advanced_testcase {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
$form = $this->createMock('mod_quiz_mod_form');
$form->method('get_context')->willReturn(context_module::instance($this->quiz->cmid));
$form->method('get_context')->willReturn(\context_module::instance($this->quiz->cmid));
$user = $this->getDataGenerator()->create_user();
$roleid = $this->getDataGenerator()->create_role();
$context = context_module::instance($this->quiz->cmid);
$context = \context_module::instance($this->quiz->cmid);
assign_capability('quizaccess/seb:manage_seb_requiresafeexambrowser', CAP_ALLOW, $roleid, $context->id);
$this->getDataGenerator()->role_assign($roleid, $user->id, $context->id);
@ -216,7 +210,7 @@ class quizaccess_seb_rule__testcase extends advanced_testcase {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
$form = $this->createMock('mod_quiz_mod_form');
$form->method('get_context')->willReturn(context_module::instance($this->quiz->cmid));
$form->method('get_context')->willReturn(\context_module::instance($this->quiz->cmid));
// Validate settings with a dummy form and quiz instance.
$errors = quizaccess_seb::validate_settings_form_fields([], [
@ -270,7 +264,7 @@ class quizaccess_seb_rule__testcase extends advanced_testcase {
$user = $this->getDataGenerator()->create_user();
$roleid = $this->getDataGenerator()->create_role();
$context = context_module::instance($this->quiz->cmid);
$context = \context_module::instance($this->quiz->cmid);
assign_capability('quizaccess/seb:manage_seb_requiresafeexambrowser', CAP_ALLOW, $roleid, $context->id);
$this->getDataGenerator()->role_assign($roleid, $user->id, $context->id);
@ -290,7 +284,7 @@ class quizaccess_seb_rule__testcase extends advanced_testcase {
public function test_save_settings_throw_an_exception_if_cm_not_found() {
global $DB;
$this->expectException(dml_missing_record_exception::class);
$this->expectException(\dml_missing_record_exception::class);
$this->expectExceptionMessage('Can\'t find data record in database.');
$this->setAdminUser();
@ -308,7 +302,7 @@ class quizaccess_seb_rule__testcase extends advanced_testcase {
global $DB;
$this->setAdminUser();
$quiz = new stdClass();
$quiz = new \stdClass();
$quiz->id = 1;
quizaccess_seb::delete_settings($quiz);
$this->assertFalse($DB->record_exists('quizaccess_seb_quizsettings', ['quizid' => $quiz->id]));
@ -841,7 +835,7 @@ class quizaccess_seb_rule__testcase extends advanced_testcase {
$this->setUser($user);
// Set the bypass SEB check capability to $USER.
$this->assign_user_capability('quizaccess/seb:bypassseb', context_module::instance($this->quiz->cmid)->id);
$this->assign_user_capability('quizaccess/seb:bypassseb', \context_module::instance($this->quiz->cmid)->id);
// Check that correct error message is returned.
$this->assertFalse($this->make_rule()->prevent_access());
@ -855,7 +849,7 @@ class quizaccess_seb_rule__testcase extends advanced_testcase {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
$form = $this->createMock('mod_quiz_mod_form');
$form->method('get_context')->willReturn(context_module::instance($this->quiz->cmid));
$form->method('get_context')->willReturn(\context_module::instance($this->quiz->cmid));
// Validate settings with a dummy form.
$errors = quizaccess_seb::validate_settings_form_fields([], [
@ -875,7 +869,7 @@ class quizaccess_seb_rule__testcase extends advanced_testcase {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
$form = $this->createMock('mod_quiz_mod_form');
$form->method('get_context')->willReturn(context_module::instance($this->quiz->cmid));
$form->method('get_context')->willReturn(\context_module::instance($this->quiz->cmid));
// Validate settings with a dummy form.
$errors = quizaccess_seb::validate_settings_form_fields([], [
@ -898,7 +892,7 @@ class quizaccess_seb_rule__testcase extends advanced_testcase {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
$form = $this->createMock('mod_quiz_mod_form');
$form->method('get_context')->willReturn(context_module::instance($this->quiz->cmid));
$form->method('get_context')->willReturn(\context_module::instance($this->quiz->cmid));
// Validate settings with a dummy form.
$errors = quizaccess_seb::validate_settings_form_fields([], [
@ -922,7 +916,7 @@ class quizaccess_seb_rule__testcase extends advanced_testcase {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
$form = $this->createMock('mod_quiz_mod_form');
$form->method('get_context')->willReturn(context_module::instance($this->quiz->cmid));
$form->method('get_context')->willReturn(\context_module::instance($this->quiz->cmid));
// Validate settings with a dummy form.
$errors = quizaccess_seb::validate_settings_form_fields([], [
@ -944,7 +938,7 @@ class quizaccess_seb_rule__testcase extends advanced_testcase {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_NO);
$form = $this->createMock('mod_quiz_mod_form');
$form->method('get_context')->willReturn(context_module::instance($this->quiz->cmid));
$form->method('get_context')->willReturn(\context_module::instance($this->quiz->cmid));
// Validate settings with a dummy form.
$errors = quizaccess_seb::validate_settings_form_fields([], [
@ -1134,7 +1128,7 @@ class quizaccess_seb_rule__testcase extends advanced_testcase {
$user = $this->getDataGenerator()->create_user();
$roleid = $this->getDataGenerator()->create_role();
$context = context_module::instance($this->quiz->cmid);
$context = \context_module::instance($this->quiz->cmid);
assign_capability('quizaccess/seb:bypassseb', CAP_ALLOW, $roleid, $context->id);
$this->setUser($user);

View File

@ -14,15 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for the quizaccess_securewindow plugin.
*
* @package quizaccess
* @subpackage securewindow
* @copyright 2008 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace quizaccess_securewindow;
use quiz;
use quizaccess_securewindow;
defined('MOODLE_INTERNAL') || die();
@ -33,21 +28,22 @@ require_once($CFG->dirroot . '/mod/quiz/accessrule/securewindow/rule.php');
/**
* Unit tests for the quizaccess_securewindow plugin.
*
* @package quizaccess_securewindow
* @copyright 2008 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quizaccess_securewindow_testcase extends basic_testcase {
class rule_test extends \basic_testcase {
public static $includecoverage = array('mod/quiz/accessrule/securewindow/rule.php');
// Nothing very testable in this class, just test that it obeys the general access rule contact.
public function test_securewindow_access_rule() {
$quiz = new stdClass();
$quiz = new \stdClass();
$quiz->browsersecurity = 'securewindow';
$cm = new stdClass();
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz($quiz, $cm, null);
$rule = new quizaccess_securewindow($quizobj, 0);
$attempt = new stdClass();
$attempt = new \stdClass();
$this->assertFalse($rule->prevent_access());
$this->assertEmpty($rule->description());

View File

@ -14,15 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for the quizaccess_timelimit plugin.
*
* @package quizaccess
* @subpackage timelimit
* @copyright 2008 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace quizaccess_timelimit;
use quiz;
use quizaccess_timelimit;
defined('MOODLE_INTERNAL') || die();
@ -33,19 +28,20 @@ require_once($CFG->dirroot . '/mod/quiz/accessrule/timelimit/rule.php');
/**
* Unit tests for the quizaccess_timelimit plugin.
*
* @package quizaccess_timelimit
* @copyright 2008 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quizaccess_timelimit_testcase extends basic_testcase {
class rule_test extends \basic_testcase {
public function test_time_limit_access_rule() {
$quiz = new stdClass();
$quiz = new \stdClass();
$quiz->timeclose = 0;
$quiz->timelimit = 3600;
$cm = new stdClass();
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz($quiz, $cm, null);
$rule = new quizaccess_timelimit($quizobj, 10000);
$attempt = new stdClass();
$attempt = new \stdClass();
$this->assertEquals($rule->description(),
get_string('quiztimelimit', 'quizaccess_timelimit', format_time(3600)));
@ -87,14 +83,14 @@ class quizaccess_timelimit_testcase extends basic_testcase {
public function test_time_limit_access_rule_with_time_close($timetoclose, $timelimit, $displaylimit, $actuallimit) {
$timenow = 10000;
$quiz = new stdClass();
$quiz = new \stdClass();
$quiz->timeclose = $timenow + $timetoclose;
$quiz->timelimit = $timelimit;
$cm = new stdClass();
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz($quiz, $cm, null);
$rule = new quizaccess_timelimit($quizobj, $timenow);
$attempt = new stdClass();
$attempt = new \stdClass();
$this->assertEquals($rule->description(),
get_string('quiztimelimit', 'quizaccess_timelimit', format_time($displaylimit)));

View File

@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore date tests.
*
* @package mod_quiz
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_quiz\backup;
defined('MOODLE_INTERNAL') || die();
@ -34,8 +28,7 @@ require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php");
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_quiz_restore_date_testcase extends restore_date_testcase
{
class restore_date_test extends \restore_date_testcase {
/**
* Test restore dates.
@ -57,15 +50,15 @@ class mod_quiz_restore_date_testcase extends restore_date_testcase
// Create an attempt.
$timestamp = 100;
$quizobj = quiz::create($quiz->id);
$quizobj = \quiz::create($quiz->id);
$attempt = quiz_create_attempt($quizobj, 1, false, $timestamp, false);
$quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
$quba = \question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timestamp);
quiz_attempt_save_started($quizobj, $quba, $attempt);
// Quiz grade.
$grade = new stdClass();
$grade = new \stdClass();
$grade->quiz = $quiz->id;
$grade->userid = $USER->id;
$grade->grade = 8.9;

View File

@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore date tests.
*
* @package mod_resource
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_resource\backup;
defined('MOODLE_INTERNAL') || die();
@ -34,7 +28,7 @@ require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php");
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_resource_restore_date_testcase extends restore_date_testcase {
class restore_date_test extends \restore_date_testcase {
public function test_restore_dates() {
global $DB;

View File

@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore date tests.
*
* @package mod_scorm
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_scorm\backup;
defined('MOODLE_INTERNAL') || die();
@ -34,7 +28,7 @@ require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php");
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_scorm_restore_date_testcase extends restore_date_testcase {
class restore_date_test extends \restore_date_testcase {
public function test_restore_dates() {
global $DB, $USER;

View File

@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore date tests.
*
* @package mod_survey
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_survey\backup;
defined('MOODLE_INTERNAL') || die();
@ -34,13 +28,13 @@ require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php");
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_survey_restore_date_testcase extends restore_date_testcase {
class restore_date_test extends \restore_date_testcase {
public function test_restore_dates() {
global $DB;
list($course, $survey) = $this->create_course_and_module('survey');
$context = context_module::instance($survey->cmid);
$context = \context_module::instance($survey->cmid);
// Build our questions and responses array.
$realquestions = array();

View File

@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore date tests.
*
* @package mod_wiki
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\backup;
defined('MOODLE_INTERNAL') || die();
@ -34,7 +28,7 @@ require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php");
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_wiki_restore_date_testcase extends restore_date_testcase {
class restore_date_test extends \restore_date_testcase {
/**
* Test restore dates.

View File

@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore date tests.
*
* @package mod_workshop
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_workshop\backup;
defined('MOODLE_INTERNAL') || die();
@ -37,7 +31,7 @@ require_once($CFG->dirroot . "/mod/workshop/tests/fixtures/testable.php");
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_workshop_restore_date_testcase extends restore_date_testcase {
class restore_date_test extends \restore_date_testcase {
/**
* Test restore dates.

View File

@ -14,14 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Googledocs portfolio functional test.
*
* @package portfolio_googledocs
* @category tests
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace portfolio_googledocs;
use portfolio_admin_form;
defined('MOODLE_INTERNAL') || die();
@ -37,7 +32,7 @@ require_once($CFG->libdir . '/portfolio/forms.php');
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class portfolio_googledocs_plugin_testcase extends advanced_testcase {
class plugin_test extends \advanced_testcase {
/** @var string name of the portfolio plugin */
protected $pluginname = 'googledocs';
@ -46,13 +41,13 @@ class portfolio_googledocs_plugin_testcase extends advanced_testcase {
* Creates a new instance of the portfolio plugin
*
* @param string $name name of the instance
* @param stdClass $data config data for the instance
* @param \stdClass $data config data for the instance
* @return portfolio_plugin_base
*/
protected function enable_plugin($name = 'Instance name', $data = null) {
$data = $data ?: new stdClass();
$data = $data ?: new \stdClass();
$instance = portfolio_static_function($this->pluginname, 'create_instance', $this->pluginname, $name, $data);
core_plugin_manager::reset_caches();
\core_plugin_manager::reset_caches();
return $instance;
}

View File

@ -14,13 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy manager unit tests.
*
* @package core_privacy
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_privacy;
use core_privacy\local\request\writer;
use core_privacy\local\request\approved_contextlist;
defined('MOODLE_INTERNAL') || die();
global $CFG;
@ -31,9 +28,6 @@ require_once($CFG->dirroot . '/privacy/tests/fixtures/mock_mod_with_user_data_pr
require_once($CFG->dirroot . '/privacy/tests/fixtures/provider_a.php');
require_once($CFG->dirroot . '/privacy/tests/fixtures/provider_throwing_exception.php');
use \core_privacy\local\request\writer;
use \core_privacy\local\request\approved_contextlist;
/**
* Privacy manager unit tests.
*
@ -41,7 +35,7 @@ use \core_privacy\local\request\approved_contextlist;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\manager
*/
class privacy_manager_testcase extends advanced_testcase {
class manager_test extends \advanced_testcase {
/**
* Test tearDown.
*/
@ -188,7 +182,7 @@ class privacy_manager_testcase extends advanced_testcase {
// Create an approved contextlist.
$approvedcontextlistcollection = new \core_privacy\local\request\contextlist_collection(10);
foreach ($contextlistcollection->get_contextlists() as $contextlist) {
$approvedcontextlist = new approved_contextlist(new stdClass(), $contextlist->get_component(),
$approvedcontextlist = new approved_contextlist(new \stdClass(), $contextlist->get_component(),
$contextlist->get_contextids());
$approvedcontextlistcollection->add_contextlist($approvedcontextlist);
}
@ -203,7 +197,7 @@ class privacy_manager_testcase extends advanced_testcase {
$this->assertEquals('mydescription', $prefs->mykey->description);
// Verify an exception is thrown if trying to pass in a collection of non-approved_contextlist items.
$this->expectException(moodle_exception::class);
$this->expectException(\moodle_exception::class);
$mockman->export_user_data($contextlistcollection);
}
@ -234,7 +228,7 @@ class privacy_manager_testcase extends advanced_testcase {
$this->assertNull($mockman->delete_data_for_user($approvedcontextlistcollection));
// Verify an exception is thrown if trying to pass in a collection of non-approved_contextlist items.
$this->expectException(moodle_exception::class);
$this->expectException(\moodle_exception::class);
$mockman->delete_data_for_user($contextlistcollection);
}

View File

@ -14,13 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Tests for the Dropbox API (v2).
*
* @package repository_dropbox
* @copyright Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace repository_dropbox;
/**
* Tests for the Dropbox API (v2).
@ -29,7 +23,7 @@
* @copyright Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class repository_dropbox_api_testcase extends advanced_testcase {
class api_test extends \advanced_testcase {
/**
* Data provider for has_additional_results.
*

View File

@ -14,14 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Search manager unit tests.
*
* @package core_search
* @category phpunit
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_search;
defined('MOODLE_INTERNAL') || die();
@ -36,7 +29,7 @@ require_once(__DIR__ . '/fixtures/mock_search_area.php');
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class search_manager_testcase extends advanced_testcase {
class manager_test extends \advanced_testcase {
/**
* Forum area id.
@ -60,7 +53,7 @@ class search_manager_testcase extends advanced_testcase {
protected function tearDown(): void {
// Stop it from faking time in the search manager (if set by test).
testable_core_search::fake_current_time();
\testable_core_search::fake_current_time();
parent::tearDown();
}
@ -105,7 +98,7 @@ class search_manager_testcase extends advanced_testcase {
$area->set_enabled($enablearea);
}
$this->assertEquals(new moodle_url($expected), \core_search\manager::get_course_search_url());
$this->assertEquals(new \moodle_url($expected), \core_search\manager::get_course_search_url());
}
/**
@ -216,7 +209,7 @@ class search_manager_testcase extends advanced_testcase {
$this->resetAfterTest();
$search = testable_core_search::instance();
$search = \testable_core_search::instance();
// We should test both plugin types and core subsystems. No core subsystems available yet.
$searcharea = $search->get_search_area($this->forumpostareaid);
@ -238,7 +231,7 @@ class search_manager_testcase extends advanced_testcase {
$fakeareaid = \core_search\manager::generate_areaid('mod_unexisting', 'chihuaquita');
$search->reset_config($fakeareaid);
$this->fail('An exception should be triggered if the provided search area does not exist.');
} catch (moodle_exception $ex) {
} catch (\moodle_exception $ex) {
$this->assertStringContainsString($fakeareaid . ' search area is not available.', $ex->getMessage());
}
@ -275,7 +268,7 @@ class search_manager_testcase extends advanced_testcase {
public function test_get_last_indexing_duration() {
$this->resetAfterTest();
$search = testable_core_search::instance();
$search = \testable_core_search::instance();
$searcharea = $search->get_search_area($this->forumpostareaid);
@ -310,7 +303,7 @@ class search_manager_testcase extends advanced_testcase {
// Index everything up to current. Ensure the course is older than current second so it
// definitely doesn't get indexed again next time.
$this->waitForSecond();
$search = testable_core_search::instance();
$search = \testable_core_search::instance();
$search->index(false, 0);
$searcharea = $search->get_search_area($this->forumpostareaid);
@ -340,7 +333,7 @@ class search_manager_testcase extends advanced_testcase {
$search->get_engine()->set_add_delay(1.2);
// Use fake time, starting from now.
testable_core_search::fake_current_time(time());
\testable_core_search::fake_current_time(time());
// Index with a limit of 2 seconds - it should index 2 of the documents (after the second
// one, it will have taken 2.4 seconds so it will stop).
@ -360,7 +353,7 @@ class search_manager_testcase extends advanced_testcase {
// Wait to next second (so as to not reindex the label more than once, as it will now
// be timed before the indexing run).
$this->waitForSecond();
testable_core_search::fake_current_time(time());
\testable_core_search::fake_current_time(time());
// Next index with 1 second limit should do the label and not the forum - the logic is,
// if it spent ages indexing an area last time, do that one last on next run.
@ -401,7 +394,7 @@ class search_manager_testcase extends advanced_testcase {
$generator = $this->getDataGenerator();
// Set up the fake search area.
$search = testable_core_search::instance();
$search = \testable_core_search::instance();
$area = new \core_mocksearch\search\mock_search_area();
$search->add_search_area('whatever', $area);
$searchgenerator = $generator->get_plugin_generator('core_search');
@ -421,7 +414,7 @@ class search_manager_testcase extends advanced_testcase {
$search->get_engine()->set_add_delay(15.789);
// Run search indexing and check output.
$progress = new progress_trace_buffer(new text_progress_trace(), false);
$progress = new \progress_trace_buffer(new \text_progress_trace(), false);
$search->index(false, 75, $progress);
$out = $progress->get_buffer();
$progress->reset_buffer();
@ -447,7 +440,7 @@ class search_manager_testcase extends advanced_testcase {
$search->get_engine()->set_add_delay(1);
// Run search indexing (still partial) and check output.
$progress = new progress_trace_buffer(new text_progress_trace(), false);
$progress = new \progress_trace_buffer(new \text_progress_trace(), false);
$search->index(false, 5, $progress);
$out = $progress->get_buffer();
$progress->reset_buffer();
@ -460,7 +453,7 @@ class search_manager_testcase extends advanced_testcase {
'(not complete; done to 1/11/17, 01:05).', $out);
// Run the remaining items to complete it.
$progress = new progress_trace_buffer(new text_progress_trace(), false);
$progress = new \progress_trace_buffer(new \text_progress_trace(), false);
$search->index(false, 100, $progress);
$out = $progress->get_buffer();
$progress->reset_buffer();
@ -490,7 +483,7 @@ class search_manager_testcase extends advanced_testcase {
// Index everything up to current. Ensure the course is older than current second so it
// definitely doesn't get indexed again next time.
$this->waitForSecond();
$search = testable_core_search::instance();
$search = \testable_core_search::instance();
$search->index(false, 0);
$search->get_engine()->get_and_clear_added_documents();
@ -556,8 +549,8 @@ class search_manager_testcase extends advanced_testcase {
$generator->create_module('forum', ['course' => $course->id]);
// Index forum 1 only.
$search = testable_core_search::instance();
$buffer = new progress_trace_buffer(new text_progress_trace(), false);
$search = \testable_core_search::instance();
$buffer = new \progress_trace_buffer(new \text_progress_trace(), false);
$result = $search->index_context(\context_module::instance($forum1->cmid), '', 0, $buffer);
$this->assertTrue($result->complete);
$log = $buffer->get_buffer();
@ -636,19 +629,19 @@ class search_manager_testcase extends advanced_testcase {
$this->resetAfterTest();
$frontpage = $DB->get_record('course', array('id' => SITEID));
$frontpagectx = context_course::instance($frontpage->id);
$frontpagectx = \context_course::instance($frontpage->id);
$course1 = $this->getDataGenerator()->create_course();
$course1ctx = context_course::instance($course1->id);
$course1ctx = \context_course::instance($course1->id);
$course2 = $this->getDataGenerator()->create_course();
$course2ctx = context_course::instance($course2->id);
$course2ctx = \context_course::instance($course2->id);
$course3 = $this->getDataGenerator()->create_course();
$course3ctx = context_course::instance($course3->id);
$course3ctx = \context_course::instance($course3->id);
$teacher = $this->getDataGenerator()->create_user();
$teacherctx = context_user::instance($teacher->id);
$teacherctx = \context_user::instance($teacher->id);
$student = $this->getDataGenerator()->create_user();
$studentctx = context_user::instance($student->id);
$studentctx = \context_user::instance($student->id);
$noaccess = $this->getDataGenerator()->create_user();
$noaccessctx = context_user::instance($noaccess->id);
$noaccessctx = \context_user::instance($noaccess->id);
$this->getDataGenerator()->enrol_user($teacher->id, $course1->id, 'teacher');
$this->getDataGenerator()->enrol_user($student->id, $course1->id, 'student');
@ -656,17 +649,17 @@ class search_manager_testcase extends advanced_testcase {
$forum1 = $this->getDataGenerator()->create_module('forum', array('course' => $course1->id));
$forum2 = $this->getDataGenerator()->create_module('forum', array('course' => $course1->id));
$forum3 = $this->getDataGenerator()->create_module('forum', array('course' => $course2->id));
$frontpageforumcontext = context_module::instance($frontpageforum->cmid);
$context1 = context_module::instance($forum1->cmid);
$context2 = context_module::instance($forum2->cmid);
$context3 = context_module::instance($forum3->cmid);
$frontpageforumcontext = \context_module::instance($frontpageforum->cmid);
$context1 = \context_module::instance($forum1->cmid);
$context2 = \context_module::instance($forum2->cmid);
$context3 = \context_module::instance($forum3->cmid);
$forum4 = $this->getDataGenerator()->create_module('forum', array('course' => $course3->id));
$context4 = context_module::instance($forum4->cmid);
$context4 = \context_module::instance($forum4->cmid);
$search = testable_core_search::instance();
$search = \testable_core_search::instance();
$mockareaid = \core_search\manager::generate_areaid('core_mocksearch', 'mock_search_area');
$search->add_core_search_areas();
$search->add_search_area($mockareaid, new core_mocksearch\search\mock_search_area());
$search->add_search_area($mockareaid, new \core_mocksearch\search\mock_search_area());
$this->setAdminUser();
$this->assertEquals((object)['everything' => true], $search->get_areas_user_accesses());
@ -810,7 +803,7 @@ class search_manager_testcase extends advanced_testcase {
$page->blocks->add_block_at_end_of_default_region('html');
$forum = $this->getDataGenerator()->create_module('forum', array('course' => $course2->id));
$forumcontext = context_module::instance($forum->cmid);
$forumcontext = \context_module::instance($forum->cmid);
$page = new \moodle_page();
$page->set_context($forumcontext);
$page->set_course($course2);
@ -845,7 +838,7 @@ class search_manager_testcase extends advanced_testcase {
$student3 = $generator->create_user();
$generator->enrol_user($student3->id, $course3->id, 'student');
$search = testable_core_search::instance();
$search = \testable_core_search::instance();
$search->add_core_search_areas();
// Admin gets 'true' result to function regardless of blocks.
@ -905,11 +898,11 @@ class search_manager_testcase extends advanced_testcase {
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
$search = testable_core_search::instance();
$search = \testable_core_search::instance();
$search->add_core_search_areas();
$course = $this->getDataGenerator()->create_course();
$context = context_course::instance($course->id);
$context = \context_course::instance($course->id);
// Limit courses to search to only those the user is enrolled in.
set_config('searchallavailablecourses', 0);
@ -944,22 +937,22 @@ class search_manager_testcase extends advanced_testcase {
// Front page, including a forum.
$frontpage = $DB->get_record('course', array('id' => SITEID));
$forumfront = $this->getDataGenerator()->create_module('forum', array('course' => $frontpage->id));
$forumfrontctx = context_module::instance($forumfront->cmid);
$forumfrontctx = \context_module::instance($forumfront->cmid);
// Course 1 does not allow guest access.
$course1 = $this->getDataGenerator()->create_course((object)array(
'enrol_guest_status_0' => ENROL_INSTANCE_DISABLED,
'enrol_guest_password_0' => ''));
$forum1 = $this->getDataGenerator()->create_module('forum', array('course' => $course1->id));
$forum1ctx = context_module::instance($forum1->cmid);
$forum1ctx = \context_module::instance($forum1->cmid);
// Course 2 does not allow guest but is accessible by all users.
$course2 = $this->getDataGenerator()->create_course((object)array(
'enrol_guest_status_0' => ENROL_INSTANCE_DISABLED,
'enrol_guest_password_0' => ''));
$course2ctx = context_course::instance($course2->id);
$course2ctx = \context_course::instance($course2->id);
$forum2 = $this->getDataGenerator()->create_module('forum', array('course' => $course2->id));
$forum2ctx = context_module::instance($forum2->cmid);
$forum2ctx = \context_module::instance($forum2->cmid);
assign_capability('moodle/course:view', CAP_ALLOW, $CFG->defaultuserroleid, $course2ctx->id);
// Course 3 allows guest access without password.
@ -967,7 +960,7 @@ class search_manager_testcase extends advanced_testcase {
'enrol_guest_status_0' => ENROL_INSTANCE_ENABLED,
'enrol_guest_password_0' => ''));
$forum3 = $this->getDataGenerator()->create_module('forum', array('course' => $course2->id));
$forum3ctx = context_module::instance($forum3->cmid);
$forum3ctx = \context_module::instance($forum3->cmid);
// Student user is enrolled in course 1.
$student = $this->getDataGenerator()->create_user();
@ -977,7 +970,7 @@ class search_manager_testcase extends advanced_testcase {
$noaccess = $this->getDataGenerator()->create_user();
// First test without the all available option.
$search = testable_core_search::instance();
$search = \testable_core_search::instance();
// Admin user can access everything.
$this->setAdminUser();
@ -1032,16 +1025,16 @@ class search_manager_testcase extends advanced_testcase {
$group3 = $generator->create_group(['courseid' => $course2->id]);
$group4 = $generator->create_group(['courseid' => $course2->id]);
$forum1s = $generator->create_module('forum', ['course' => $course1->id, 'groupmode' => SEPARATEGROUPS]);
$id1s = context_module::instance($forum1s->cmid)->id;
$id1s = \context_module::instance($forum1s->cmid)->id;
$forum1v = $generator->create_module('forum', ['course' => $course1->id, 'groupmode' => VISIBLEGROUPS]);
$id1v = context_module::instance($forum1v->cmid)->id;
$id1v = \context_module::instance($forum1v->cmid)->id;
$forum2s = $generator->create_module('forum', ['course' => $course2->id, 'groupmode' => SEPARATEGROUPS]);
$id2s = context_module::instance($forum2s->cmid)->id;
$id2s = \context_module::instance($forum2s->cmid)->id;
$forum2n = $generator->create_module('forum', ['course' => $course2->id, 'groupmode' => NOGROUPS]);
$id2n = context_module::instance($forum2n->cmid)->id;
$id2n = \context_module::instance($forum2n->cmid)->id;
// Get search instance.
$search = testable_core_search::instance();
$search = \testable_core_search::instance();
$search->add_core_search_areas();
// User 1 is a manager in one course and a student in the other one. They belong to
@ -1119,12 +1112,12 @@ class search_manager_testcase extends advanced_testcase {
*/
public function test_is_search_area() {
$this->assertFalse(testable_core_search::is_search_area('\asd\asd'));
$this->assertFalse(testable_core_search::is_search_area('\mod_forum\search\posta'));
$this->assertFalse(testable_core_search::is_search_area('\core_search\base_mod'));
$this->assertTrue(testable_core_search::is_search_area('\mod_forum\search\post'));
$this->assertTrue(testable_core_search::is_search_area('\\mod_forum\\search\\post'));
$this->assertTrue(testable_core_search::is_search_area('mod_forum\\search\\post'));
$this->assertFalse(\testable_core_search::is_search_area('\asd\asd'));
$this->assertFalse(\testable_core_search::is_search_area('\mod_forum\search\posta'));
$this->assertFalse(\testable_core_search::is_search_area('\core_search\base_mod'));
$this->assertTrue(\testable_core_search::is_search_area('\mod_forum\search\post'));
$this->assertTrue(\testable_core_search::is_search_area('\\mod_forum\\search\\post'));
$this->assertTrue(\testable_core_search::is_search_area('mod_forum\\search\\post'));
}
/**
@ -1138,13 +1131,13 @@ class search_manager_testcase extends advanced_testcase {
$this->resetAfterTest();
$course1 = $this->getDataGenerator()->create_course();
$course1ctx = context_course::instance($course1->id);
$course1ctx = \context_course::instance($course1->id);
$course2 = $this->getDataGenerator()->create_course();
$course2ctx = context_course::instance($course2->id);
$course2ctx = \context_course::instance($course2->id);
$forum1 = $this->getDataGenerator()->create_module('forum', ['course' => $course1->id]);
$forum1ctx = context_module::instance($forum1->cmid);
$forum1ctx = \context_module::instance($forum1->cmid);
$forum2 = $this->getDataGenerator()->create_module('forum', ['course' => $course2->id]);
$forum2ctx = context_module::instance($forum2->cmid);
$forum2ctx = \context_module::instance($forum2->cmid);
// Initially no requests.
$this->assertEquals(0, $DB->count_records('search_index_requests'));
@ -1246,10 +1239,10 @@ class search_manager_testcase extends advanced_testcase {
$this->resetAfterTest();
$search = testable_core_search::instance();
$search = \testable_core_search::instance();
// When there are no index requests, nothing gets logged.
$progress = new progress_trace_buffer(new text_progress_trace(), false);
$progress = new \progress_trace_buffer(new \text_progress_trace(), false);
$search->process_index_requests(0.0, $progress);
$out = $progress->get_buffer();
$progress->reset_buffer();
@ -1270,10 +1263,10 @@ class search_manager_testcase extends advanced_testcase {
$forum2time = $now - 20;
// Make 2 index requests.
testable_core_search::fake_current_time($now - 3);
$search::request_index(context_course::instance($course->id), 'mod_label-activity');
testable_core_search::fake_current_time($now - 2);
$search::request_index(context_module::instance($forum1->cmid));
\testable_core_search::fake_current_time($now - 3);
$search::request_index(\context_course::instance($course->id), 'mod_label-activity');
\testable_core_search::fake_current_time($now - 2);
$search::request_index(\context_module::instance($forum1->cmid));
// Run with no time limit.
$search->process_index_requests(0.0, $progress);
@ -1294,10 +1287,10 @@ class search_manager_testcase extends advanced_testcase {
$this->assertEquals(0, $DB->count_records('search_index_requests'));
// Request indexing the course a couple of times.
testable_core_search::fake_current_time($now - 3);
$search::request_index(context_course::instance($course->id), 'mod_forum-activity');
testable_core_search::fake_current_time($now - 2);
$search::request_index(context_course::instance($course->id), 'mod_forum-post');
\testable_core_search::fake_current_time($now - 3);
$search::request_index(\context_course::instance($course->id), 'mod_forum-activity');
\testable_core_search::fake_current_time($now - 2);
$search::request_index(\context_course::instance($course->id), 'mod_forum-post');
// Do the processing again with a time limit and indexing delay. The time limit is too
// small; because of the way the logic works, this means it will index 2 activities.
@ -1335,11 +1328,11 @@ class search_manager_testcase extends advanced_testcase {
$this->assertEquals(0, $DB->count_records('search_index_requests'));
// Make 2 requests - first one is low priority.
testable_core_search::fake_current_time($now - 3);
$search::request_index(context_module::instance($forum1->cmid), 'mod_forum-activity',
\testable_core_search::fake_current_time($now - 3);
$search::request_index(\context_module::instance($forum1->cmid), 'mod_forum-activity',
\core_search\manager::INDEX_PRIORITY_REINDEXING);
testable_core_search::fake_current_time($now - 2);
$search::request_index(context_module::instance($forum2->cmid), 'mod_forum-activity');
\testable_core_search::fake_current_time($now - 2);
$search::request_index(\context_module::instance($forum2->cmid), 'mod_forum-activity');
// Process with short time limit and confirm it does the second one first.
$search->process_index_requests(0.1, $progress);
@ -1357,7 +1350,7 @@ class search_manager_testcase extends advanced_testcase {
// Make a request for a course context...
$course = $generator->create_course();
$context = context_course::instance($course->id);
$context = \context_course::instance($course->id);
$search::request_index($context);
// ...but then delete it (note: delete_course spews output, so we throw it away).
@ -1481,9 +1474,9 @@ class search_manager_testcase extends advanced_testcase {
$this->getDataGenerator()->enrol_user($USER->id, $course1->id);
$this->getDataGenerator()->enrol_user($USER->id, $course3->id);
$search = testable_core_search::instance();
$search = \testable_core_search::instance();
$formdata = new stdClass();
$formdata = new \stdClass();
$formdata->courseids = [];
$formdata->mycoursesonly = false;
$limitcourseids = $search->build_limitcourseids($formdata);
@ -1563,7 +1556,7 @@ class search_manager_testcase extends advanced_testcase {
// Get all settings to DB and make sure they are there.
foreach (\core_search\base::get_settingnames() as $settingname) {
$record = new stdClass();
$record = new \stdClass();
$record->plugin = $plugin;
$record->name = 'core_course_mycourse'. $settingname;
$record->value = 'test';
@ -1606,7 +1599,7 @@ class search_manager_testcase extends advanced_testcase {
$user = $generator->create_user();
$usercontext = \context_user::instance($user->id);
$search = testable_core_search::instance();
$search = \testable_core_search::instance();
// Delete two of the pages individually.
course_delete_module($page1->cmid);