Commit 511801cb authored by Eloy Lafuente's avatar Eloy Lafuente
Browse files

MDL-73352 phpunit: lib_test and locallib_test testcase names

All lib_test and locallib_test classes:

- Namespaced with component (and API whenever makes sense).
- Fixed incorrect use statements with leading backslash.
- Changed code to point to global scope when needed or add new uses.
- All them passing individually.
- Complete runs passing too.

Special mention to tests under login/tests:

1) The core_login component doesn't exist.
2) But login/tests are allowed because there is a suite pointing to it (phpunit.xml).
3) So, the only possible namespace for them is "core".
4) And to avoid problems with other core testcases (under lib/tests)
   they have been renamed to have login_xxxx as prefix.
parent 541d999d
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
* @copyright 2021 The Open University * @copyright 2021 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/ */
namespace tool_capability;
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
global $CFG; global $CFG;
...@@ -30,7 +31,7 @@ require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/capability/locallib.php' ...@@ -30,7 +31,7 @@ require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/capability/locallib.php'
/** /**
* Tests for the capability overview helper functions. * Tests for the capability overview helper functions.
*/ */
class tool_capability_locallib_testcase extends advanced_testcase { class locallib_test extends \advanced_testcase {
/** /**
* Test the function that gets the data - simple case. * Test the function that gets the data - simple case.
...@@ -40,7 +41,7 @@ class tool_capability_locallib_testcase extends advanced_testcase { ...@@ -40,7 +41,7 @@ class tool_capability_locallib_testcase extends advanced_testcase {
$data = tool_capability_calculate_role_data('mod/quiz:attempt', get_all_roles()); $data = tool_capability_calculate_role_data('mod/quiz:attempt', get_all_roles());
$systcontext = context_system::instance(); $systcontext = \context_system::instance();
$studentroleid = $DB->get_field('role', 'id', ['shortname' => 'student']); $studentroleid = $DB->get_field('role', 'id', ['shortname' => 'student']);
$this->assertArrayHasKey($systcontext->id, $data); $this->assertArrayHasKey($systcontext->id, $data);
...@@ -63,10 +64,10 @@ class tool_capability_locallib_testcase extends advanced_testcase { ...@@ -63,10 +64,10 @@ class tool_capability_locallib_testcase extends advanced_testcase {
// This simulates a situation that seems to happen sometimes, where // This simulates a situation that seems to happen sometimes, where
// we end up with contexts with path = NULL in the database. // we end up with contexts with path = NULL in the database.
$systcontext = context_system::instance(); $systcontext = \context_system::instance();
$generator = $this->getDataGenerator(); $generator = $this->getDataGenerator();
$course = $generator->create_course(); $course = $generator->create_course();
$coursecontext = context_course::instance($course->id); $coursecontext = \context_course::instance($course->id);
$studentroleid = $DB->get_field('role', 'id', ['shortname' => 'student']); $studentroleid = $DB->get_field('role', 'id', ['shortname' => 'student']);
role_change_permission($studentroleid, $coursecontext, 'mod/quiz:attempt', CAP_PREVENT); role_change_permission($studentroleid, $coursecontext, 'mod/quiz:attempt', CAP_PREVENT);
// This is where we simulate the breakage. // This is where we simulate the breakage.
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
* @copyright 2020 Peter Dias * @copyright 2020 Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
namespace tool_moodlenet;
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
...@@ -30,7 +31,7 @@ require_once($CFG->dirroot . '/admin/tool/moodlenet/lib.php'); ...@@ -30,7 +31,7 @@ require_once($CFG->dirroot . '/admin/tool/moodlenet/lib.php');
/** /**
* Test moodlenet functions * Test moodlenet functions
*/ */
class tool_moodlenet_lib_testcase extends advanced_testcase { class lib_test extends \advanced_testcase {
/** /**
* Test the generate_mnet_endpoint function * Test the generate_mnet_endpoint function
......
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
* @copyright 2009 Nicolas Connault * @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
namespace core_blog;
use blog_listing;
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
...@@ -32,7 +35,7 @@ require_once($CFG->dirroot . '/blog/lib.php'); ...@@ -32,7 +35,7 @@ require_once($CFG->dirroot . '/blog/lib.php');
/** /**
* Test functions that rely on the DB tables * Test functions that rely on the DB tables
*/ */
class core_blog_lib_testcase extends advanced_testcase { class lib_test extends \advanced_testcase {
private $courseid; private $courseid;
private $cmid; private $cmid;
...@@ -54,7 +57,7 @@ class core_blog_lib_testcase extends advanced_testcase { ...@@ -54,7 +57,7 @@ class core_blog_lib_testcase extends advanced_testcase {
$this->assertNotEmpty($page); $this->assertNotEmpty($page);
// Create default group. // Create default group.
$group = new stdClass(); $group = new \stdClass();
$group->courseid = $course->id; $group->courseid = $course->id;
$group->name = 'ANON'; $group->name = 'ANON';
$group->id = $DB->insert_record('groups', $group); $group->id = $DB->insert_record('groups', $group);
...@@ -71,7 +74,7 @@ class core_blog_lib_testcase extends advanced_testcase { ...@@ -71,7 +74,7 @@ class core_blog_lib_testcase extends advanced_testcase {
'rawname' => 'Testtagname', 'isstandard' => 1)); 'rawname' => 'Testtagname', 'isstandard' => 1));
// Create default post. // Create default post.
$post = new stdClass(); $post = new \stdClass();
$post->userid = $user->id; $post->userid = $user->id;
$post->groupid = $group->id; $post->groupid = $group->id;
$post->content = 'test post content text'; $post->content = 'test post content text';
...@@ -170,7 +173,7 @@ class core_blog_lib_testcase extends advanced_testcase { ...@@ -170,7 +173,7 @@ class core_blog_lib_testcase extends advanced_testcase {
// Check the node tree is correct. // Check the node tree is correct.
core_blog_myprofile_navigation($tree, $USER, $iscurrentuser, $course); core_blog_myprofile_navigation($tree, $USER, $iscurrentuser, $course);
$reflector = new ReflectionObject($tree); $reflector = new \ReflectionObject($tree);
$nodes = $reflector->getProperty('nodes'); $nodes = $reflector->getProperty('nodes');
$nodes->setAccessible(true); $nodes->setAccessible(true);
$this->assertArrayHasKey('blogs', $nodes->getValue($tree)); $this->assertArrayHasKey('blogs', $nodes->getValue($tree));
...@@ -192,7 +195,7 @@ class core_blog_lib_testcase extends advanced_testcase { ...@@ -192,7 +195,7 @@ class core_blog_lib_testcase extends advanced_testcase {
// Check the node tree is correct. // Check the node tree is correct.
core_blog_myprofile_navigation($tree, $USER, $iscurrentuser, $course); core_blog_myprofile_navigation($tree, $USER, $iscurrentuser, $course);
$reflector = new ReflectionObject($tree); $reflector = new \ReflectionObject($tree);
$nodes = $reflector->getProperty('nodes'); $nodes = $reflector->getProperty('nodes');
$nodes->setAccessible(true); $nodes->setAccessible(true);
$this->assertArrayNotHasKey('blogs', $nodes->getValue($tree)); $this->assertArrayNotHasKey('blogs', $nodes->getValue($tree));
...@@ -215,7 +218,7 @@ class core_blog_lib_testcase extends advanced_testcase { ...@@ -215,7 +218,7 @@ class core_blog_lib_testcase extends advanced_testcase {
// Check the node tree is correct. // Check the node tree is correct.
core_blog_myprofile_navigation($tree, $USER, $iscurrentuser, $course); core_blog_myprofile_navigation($tree, $USER, $iscurrentuser, $course);
$reflector = new ReflectionObject($tree); $reflector = new \ReflectionObject($tree);
$nodes = $reflector->getProperty('nodes'); $nodes = $reflector->getProperty('nodes');
$nodes->setAccessible(true); $nodes->setAccessible(true);
$this->assertArrayNotHasKey('blogs', $nodes->getValue($tree)); $this->assertArrayNotHasKey('blogs', $nodes->getValue($tree));
...@@ -223,11 +226,11 @@ class core_blog_lib_testcase extends advanced_testcase { ...@@ -223,11 +226,11 @@ class core_blog_lib_testcase extends advanced_testcase {
public function test_blog_get_listing_course() { public function test_blog_get_listing_course() {
$this->setAdminUser(); $this->setAdminUser();
$coursecontext = context_course::instance($this->courseid); $coursecontext = \context_course::instance($this->courseid);
$anothercourse = $this->getDataGenerator()->create_course(); $anothercourse = $this->getDataGenerator()->create_course();
// Add blog associations with a course. // Add blog associations with a course.
$blog = new blog_entry($this->postid); $blog = new \blog_entry($this->postid);
$blog->add_association($coursecontext->id); $blog->add_association($coursecontext->id);
// There is one entry associated with a course. // There is one entry associated with a course.
...@@ -253,12 +256,12 @@ class core_blog_lib_testcase extends advanced_testcase { ...@@ -253,12 +256,12 @@ class core_blog_lib_testcase extends advanced_testcase {
public function test_blog_get_listing_module() { public function test_blog_get_listing_module() {
$this->setAdminUser(); $this->setAdminUser();
$coursecontext = context_course::instance($this->courseid); $coursecontext = \context_course::instance($this->courseid);
$contextmodule = context_module::instance($this->cmid); $contextmodule = \context_module::instance($this->cmid);
$anothermodule = $this->getDataGenerator()->create_module('page', array('course' => $this->courseid)); $anothermodule = $this->getDataGenerator()->create_module('page', array('course' => $this->courseid));
// Add blog associations with a course. // Add blog associations with a course.
$blog = new blog_entry($this->postid); $blog = new \blog_entry($this->postid);
$blog->add_association($contextmodule->id); $blog->add_association($contextmodule->id);
// There is no entry associated with a course. // There is no entry associated with a course.
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
* @copyright 2017 Mark Nelson <markn@moodle.com> * @copyright 2017 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
namespace core_calendar;
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
...@@ -33,7 +34,7 @@ require_once(__DIR__ . '/helpers.php'); ...@@ -33,7 +34,7 @@ require_once(__DIR__ . '/helpers.php');
* @copyright 2017 Mark Nelson <markn@moodle.com> * @copyright 2017 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class core_calendar_lib_testcase extends advanced_testcase { class lib_test extends \advanced_testcase {
/** /**
* Tests set up * Tests set up
...@@ -89,7 +90,7 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -89,7 +90,7 @@ class core_calendar_lib_testcase extends advanced_testcase {
] ]
]; ];
foreach ($events as $event) { foreach ($events as $event) {
calendar_event::create($event, false); \calendar_event::create($event, false);
} }
$timestart = time() - 60; $timestart = time() - 60;
$timeend = time() + 60; $timeend = time() + 60;
...@@ -145,7 +146,7 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -145,7 +146,7 @@ class core_calendar_lib_testcase extends advanced_testcase {
public function test_update_subscription() { public function test_update_subscription() {
$this->resetAfterTest(true); $this->resetAfterTest(true);
$subscription = new stdClass(); $subscription = new \stdClass();
$subscription->eventtype = 'site'; $subscription->eventtype = 'site';
$subscription->name = 'test'; $subscription->name = 'test';
$id = calendar_add_subscription($subscription); $id = calendar_add_subscription($subscription);
...@@ -164,7 +165,7 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -164,7 +165,7 @@ class core_calendar_lib_testcase extends advanced_testcase {
$this->assertEquals($subscription->name, $sub->name); $this->assertEquals($subscription->name, $sub->name);
$this->assertEquals($subscription->pollinterval, $sub->pollinterval); $this->assertEquals($subscription->pollinterval, $sub->pollinterval);
$subscription = new stdClass(); $subscription = new \stdClass();
$subscription->name = 'awesome4'; $subscription->name = 'awesome4';
$this->expectException('coding_exception'); $this->expectException('coding_exception');
calendar_update_subscription($subscription); calendar_update_subscription($subscription);
...@@ -178,14 +179,14 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -178,14 +179,14 @@ class core_calendar_lib_testcase extends advanced_testcase {
$this->resetAfterTest(true); $this->resetAfterTest(true);
// Test for Microsoft Outlook 2010. // Test for Microsoft Outlook 2010.
$subscription = new stdClass(); $subscription = new \stdClass();
$subscription->name = 'Microsoft Outlook 2010'; $subscription->name = 'Microsoft Outlook 2010';
$subscription->importfrom = CALENDAR_IMPORT_FROM_FILE; $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
$subscription->eventtype = 'site'; $subscription->eventtype = 'site';
$id = calendar_add_subscription($subscription); $id = calendar_add_subscription($subscription);
$calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/ms_outlook_2010.ics'); $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/ms_outlook_2010.ics');
$ical = new iCalendar(); $ical = new \iCalendar();
$ical->unserialize($calendar); $ical->unserialize($calendar);
$this->assertEquals($ical->parser_errors, array()); $this->assertEquals($ical->parser_errors, array());
...@@ -195,14 +196,14 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -195,14 +196,14 @@ class core_calendar_lib_testcase extends advanced_testcase {
$this->assertEquals($count, 1); $this->assertEquals($count, 1);
// Test for OSX Yosemite. // Test for OSX Yosemite.
$subscription = new stdClass(); $subscription = new \stdClass();
$subscription->name = 'OSX Yosemite'; $subscription->name = 'OSX Yosemite';
$subscription->importfrom = CALENDAR_IMPORT_FROM_FILE; $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
$subscription->eventtype = 'site'; $subscription->eventtype = 'site';
$id = calendar_add_subscription($subscription); $id = calendar_add_subscription($subscription);
$calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/osx_yosemite.ics'); $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/osx_yosemite.ics');
$ical = new iCalendar(); $ical = new \iCalendar();
$ical->unserialize($calendar); $ical->unserialize($calendar);
$this->assertEquals($ical->parser_errors, array()); $this->assertEquals($ical->parser_errors, array());
...@@ -212,14 +213,14 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -212,14 +213,14 @@ class core_calendar_lib_testcase extends advanced_testcase {
$this->assertEquals($count, 1); $this->assertEquals($count, 1);
// Test for Google Gmail. // Test for Google Gmail.
$subscription = new stdClass(); $subscription = new \stdClass();
$subscription->name = 'Google Gmail'; $subscription->name = 'Google Gmail';
$subscription->importfrom = CALENDAR_IMPORT_FROM_FILE; $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
$subscription->eventtype = 'site'; $subscription->eventtype = 'site';
$id = calendar_add_subscription($subscription); $id = calendar_add_subscription($subscription);
$calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/google_gmail.ics'); $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/google_gmail.ics');
$ical = new iCalendar(); $ical = new \iCalendar();
$ical->unserialize($calendar); $ical->unserialize($calendar);
$this->assertEquals($ical->parser_errors, array()); $this->assertEquals($ical->parser_errors, array());
...@@ -229,13 +230,13 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -229,13 +230,13 @@ class core_calendar_lib_testcase extends advanced_testcase {
$this->assertEquals($count, 1); $this->assertEquals($count, 1);
// Test for ICS file with repeated events. // Test for ICS file with repeated events.
$subscription = new stdClass(); $subscription = new \stdClass();
$subscription->name = 'Repeated events'; $subscription->name = 'Repeated events';
$subscription->importfrom = CALENDAR_IMPORT_FROM_FILE; $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
$subscription->eventtype = 'site'; $subscription->eventtype = 'site';
$id = calendar_add_subscription($subscription); $id = calendar_add_subscription($subscription);
$calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/repeated_events.ics'); $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/repeated_events.ics');
$ical = new iCalendar(); $ical = new \iCalendar();
$ical->unserialize($calendar); $ical->unserialize($calendar);
$this->assertEquals($ical->parser_errors, []); $this->assertEquals($ical->parser_errors, []);
...@@ -356,7 +357,7 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -356,7 +357,7 @@ class core_calendar_lib_testcase extends advanced_testcase {
]; ];
foreach ($events as $event) { foreach ($events as $event) {
calendar_event::create($event, false); \calendar_event::create($event, false);
} }
$timestart = $now - 100; $timestart = $now - 100;
...@@ -432,7 +433,7 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -432,7 +433,7 @@ class core_calendar_lib_testcase extends advanced_testcase {
]; ];
foreach ($repeatingevents as $event) { foreach ($repeatingevents as $event) {
calendar_event::create($event, false); \calendar_event::create($event, false);
} }
// Make sure repeating events are not filtered out. // Make sure repeating events are not filtered out.
...@@ -450,7 +451,7 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -450,7 +451,7 @@ class core_calendar_lib_testcase extends advanced_testcase {
$course1 = $generator->create_course(); $course1 = $generator->create_course();
$course2 = $generator->create_course(); $course2 = $generator->create_course();
$course3 = $generator->create_course(); $course3 = $generator->create_course();
$context = context_course::instance($course1->id); $context = \context_course::instance($course1->id);
$this->setAdminUser(); $this->setAdminUser();
$admin = clone $USER; $admin = clone $USER;
...@@ -551,9 +552,9 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -551,9 +552,9 @@ class core_calendar_lib_testcase extends advanced_testcase {
$course1 = $generator->create_course(); // Has capability. $course1 = $generator->create_course(); // Has capability.
$course2 = $generator->create_course(); // Doesn't have capability. $course2 = $generator->create_course(); // Doesn't have capability.
$course3 = $generator->create_course(); // Not enrolled. $course3 = $generator->create_course(); // Not enrolled.
$context1 = context_course::instance($course1->id); $context1 = \context_course::instance($course1->id);
$context2 = context_course::instance($course2->id); $context2 = \context_course::instance($course2->id);
$context3 = context_course::instance($course3->id); $context3 = \context_course::instance($course3->id);
$roleid = $generator->create_role(); $roleid = $generator->create_role();
$contexts = [$context1, $context2, $context3]; $contexts = [$context1, $context2, $context3];
$enrolledcourses = [$course1, $course2]; $enrolledcourses = [$course1, $course2];
...@@ -600,7 +601,7 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -600,7 +601,7 @@ class core_calendar_lib_testcase extends advanced_testcase {
$generator = $this->getDataGenerator(); $generator = $this->getDataGenerator();
$user = $generator->create_user(); $user = $generator->create_user();
$course = $generator->create_course(); $course = $generator->create_course();
$context = context_course::instance($course->id); $context = \context_course::instance($course->id);
$roleid = $generator->create_role(); $roleid = $generator->create_role();
$generator->enrol_user($user->id, $course->id, 'student'); $generator->enrol_user($user->id, $course->id, 'student');
...@@ -627,7 +628,7 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -627,7 +628,7 @@ class core_calendar_lib_testcase extends advanced_testcase {
$generator = $this->getDataGenerator(); $generator = $this->getDataGenerator();
$user = $generator->create_user(); $user = $generator->create_user();
$course = $generator->create_course(); $course = $generator->create_course();
$context = context_course::instance($course->id); $context = \context_course::instance($course->id);
$roleid = $generator->create_role(); $roleid = $generator->create_role();
$generator->enrol_user($user->id, $course->id, 'student'); $generator->enrol_user($user->id, $course->id, 'student');
$generator->role_assign($roleid, $user->id, $context->id); $generator->role_assign($roleid, $user->id, $context->id);
...@@ -652,8 +653,8 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -652,8 +653,8 @@ class core_calendar_lib_testcase extends advanced_testcase {
$course2 = $generator->create_course(); $course2 = $generator->create_course();
$generator->create_group(array('courseid' => $course1->id)); $generator->create_group(array('courseid' => $course1->id));
$generator->create_group(array('courseid' => $course2->id)); $generator->create_group(array('courseid' => $course2->id));
$context1 = context_course::instance($course1->id); $context1 = \context_course::instance($course1->id);
$context2 = context_course::instance($course2->id); $context2 = \context_course::instance($course2->id);
$roleid = $generator->create_role(); $roleid = $generator->create_role();
$generator->enrol_user($user->id, $course1->id, 'student'); $generator->enrol_user($user->id, $course1->id, 'student');
$generator->enrol_user($user->id, $course2->id, 'student'); $generator->enrol_user($user->id, $course2->id, 'student');
...@@ -678,7 +679,7 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -678,7 +679,7 @@ class core_calendar_lib_testcase extends advanced_testcase {
$generator = $this->getDataGenerator(); $generator = $this->getDataGenerator();
$user = $generator->create_user(); $user = $generator->create_user();
$course = $generator->create_course(); $course = $generator->create_course();
$context = context_course::instance($course->id); $context = \context_course::instance($course->id);
$group1 = $generator->create_group(array('courseid' => $course->id)); $group1 = $generator->create_group(array('courseid' => $course->id));
$group2 = $generator->create_group(array('courseid' => $course->id)); $group2 = $generator->create_group(array('courseid' => $course->id));
$roleid = $generator->create_role(); $roleid = $generator->create_role();
...@@ -711,7 +712,7 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -711,7 +712,7 @@ class core_calendar_lib_testcase extends advanced_testcase {
$generator = $this->getDataGenerator(); $generator = $this->getDataGenerator();
$user = $generator->create_user(); $user = $generator->create_user();
$course = $generator->create_course(); $course = $generator->create_course();
$context = context_course::instance($course->id); $context = \context_course::instance($course->id);
$roleid = $generator->create_role(); $roleid = $generator->create_role();
$group = $generator->create_group(['courseid' => $course->id]); $group = $generator->create_group(['courseid' => $course->id]);
$generator->enrol_user($user->id, $course->id, 'student'); $generator->enrol_user($user->id, $course->id, 'student');
...@@ -733,7 +734,7 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -733,7 +734,7 @@ class core_calendar_lib_testcase extends advanced_testcase {
$generator = $this->getDataGenerator(); $generator = $this->getDataGenerator();
$user = $generator->create_user(); $user = $generator->create_user();
$course = $generator->create_course(); $course = $generator->create_course();
$context = context_course::instance($course->id); $context = \context_course::instance($course->id);
$roleid = $generator->create_role(); $roleid = $generator->create_role();
$group = $generator->create_group(['courseid' => $course->id]); $group = $generator->create_group(['courseid' => $course->id]);
$generator->enrol_user($user->id, $course->id, 'student'); $generator->enrol_user($user->id, $course->id, 'student');
...@@ -756,7 +757,7 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -756,7 +757,7 @@ class core_calendar_lib_testcase extends advanced_testcase {
$generator = $this->getDataGenerator(); $generator = $this->getDataGenerator();
$user = $generator->create_user(); $user = $generator->create_user();
$course = $generator->create_course(); $course = $generator->create_course();
$context = context_course::instance($course->id); $context = \context_course::instance($course->id);
$roleid = $generator->create_role(); $roleid = $generator->create_role();
$group = $generator->create_group(['courseid' => $course->id]); $group = $generator->create_group(['courseid' => $course->id]);
$generator->enrol_user($user->id, $course->id, 'student'); $generator->enrol_user($user->id, $course->id, 'student');
...@@ -941,13 +942,13 @@ class core_calendar_lib_testcase extends advanced_testcase { ...@@ -941,13 +942,13 @@ class core_calendar_lib_testcase extends advanced_testcase {
'timeduration' => 86400, 'timeduration' => 86400,
'visible' => 1 'visible' => 1
]; ];
$caleventmanual = calendar_event::create($manualevent, false); $caleventmanual = \calendar_event::create($manualevent, false);
// Create a course event for the course with guest access. // Create a course event for the course with guest access.
$guestevent = clone $manualevent; $guestevent = clone $manualevent;
$guestevent->name = 'Guest course event'; $guestevent->name = 'Guest course event';
$guestevent->courseid = $guestcourse->id; $guestevent->courseid = $guestcourse->id;
$caleventguest = calendar_event::create($guestevent, false); $caleventguest = \calendar_event::create($guestevent, false);
// Viewing as admin. // Viewing as admin.
$this->assertTrue(calendar_view_event_allowed($caleventmanual)); $this->assertTrue(calendar_view_event_allowed($caleventmanual));
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
* @copyright 2015 Frédéric Massart - FMCorz.net * @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
namespace core_competency;
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
...@@ -37,7 +38,7 @@ global $CFG; ...@@ -37,7 +38,7 @@ global $CFG;
* @copyright 2015 Frédéric Massart - FMCorz.net * @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class core_competency_lib_testcase extends advanced_testcase { class lib_test extends \advanced_testcase {
public function test_comment_add_user_competency() { public function test_comment_add_user_competency() {
global $DB, $PAGE; global $DB, $PAGE;
...@@ -49,11 +50,11 @@ class core_competency_lib_testcase extends advanced_testcase { ...@@ -49,11 +50,11 @@ class core_competency_lib_testcase extends advanced_testcase {
$u2 = $dg->create_user(); $u2 = $dg->create_user();
$u3 = $dg->create_user(); $u3 = $dg->create_user();
$reviewerroleid = $dg->create_role(); $reviewerroleid = $dg->create_role();
assign_capability('moodle/competency:planview', CAP_ALLOW, $reviewerroleid, context_system::instance()->id, true); assign_capability('moodle/competency:planview', CAP_ALLOW, $reviewerroleid, \context_system::instance()->id, true);
assign_capability('moodle/competency:usercompetencycomment', CAP_ALLOW, $reviewerroleid, assign_capability('moodle/competency:usercompetencycomment', CAP_ALLOW, $reviewerroleid,
context_system::instance()->id, true); \context_system::instance()->id, true);
$dg->role_assign($reviewerroleid, $u2->id, context_user::instance($u1->id)); $dg->role_assign($reviewerroleid, $u2->id, \context_user::instance($u1->id));
$dg->role_assign(