MDL-74413 phpunit: Move more tests to use correct names and namespaces

Applied the following changes to various testcase classes:

- Namespaced with component[\level2-API]
- Moved to level2-API subdirectory when required.
- Fixed incorrect use statements with leading backslash.
- Remove file phpdoc block
- Remove MOODLE_INTERNAL if not needed.
- Changed code to point to global scope when needed.
- Fix some relative paths and comments here and there.
- All them passing individually.
- Complete runs passing too.

Special mention to:

- Moved to the level2 "privacy" namespace:
  - \mod_assign\privacy\feedback_legacy_polyfill_test
  - \mod_assign\privacy\submission_legacy_polyfill_test

- Moved to the level2 "task" namespace:
  - \core_message\task\migrate_message_data_test
  - \ltiservice_gradebookservices\task\cleanup_test
  - \message_email\task\send_email_test
  - \mod_lti\task\clean_access_tokens_test
  - \mod_workshop\task\cron_task_test

- Moved to the level2 "event" namespace:
  - \core_h5p\event\deleted_test
  - \core_h5p\event\viewed_test

- Renamed to a better name:
  - backup_forum_activity_task_test.php (missing "task")
This commit is contained in:
Eloy Lafuente (stronk7)
2022-05-07 20:33:10 +02:00
parent 99fc164199
commit d8ea630f24
106 changed files with 1081 additions and 1507 deletions
+10 -10
View File
@@ -13,24 +13,24 @@
//
// 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 filter_mathjaxloader_filtermath_testcase} class.
*
* @package filter_mathjaxloader
* @category test
* @copyright 2018 Markku Riekkinen
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace filter_mathjaxloader;
use filter_mathjaxloader;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot.'/filter/mathjaxloader/filter.php');
/**
* Unit tests for the MathJax loader filter.
*
* @package filter_mathjaxloader
* @category test
* @copyright 2018 Markku Riekkinen
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class filter_mathjaxloader_filtermath_testcase extends advanced_testcase {
class filtermath_test extends \advanced_testcase {
/**
* Test the functionality of {@link filter_mathjaxloader::filter()}.
@@ -41,7 +41,7 @@ class filter_mathjaxloader_filtermath_testcase extends advanced_testcase {
* @dataProvider test_math_filtering_inputs
*/
public function test_math_filtering($inputtext, $expected) {
$filter = new filter_mathjaxloader(context_system::instance(), []);
$filter = new filter_mathjaxloader(\context_system::instance(), []);
$this->assertEquals($expected, $filter->filter($inputtext));
}
@@ -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/>.
/**
* Unit tests for Marking Guide grading method.
*
* @package gradingform_guide
* @category test
* @copyright 2015 Nikita Kalinin <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace gradingform_guide;
use gradingform_controller;
defined('MOODLE_INTERNAL') || die();
@@ -37,7 +32,7 @@ require_once($CFG->dirroot . '/grade/grading/form/guide/lib.php');
* @copyright 2015 Nikita Kalinin <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class gradingform_guide_testcase extends advanced_testcase {
class guide_test extends \advanced_testcase {
/**
* Unit test to get draft instance and create new instance.
*/
+12 -30
View File
@@ -14,42 +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/>.
/**
* Unit tests for the advanced grading subsystem
*
* @package core_grading
* @category phpunit
* @copyright 2011 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_grading;
use grading_manager;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/grade/grading/lib.php'); // Include the code to test
/**
* Makes protected method accessible for testing purposes
*
* @package core_grading
* @category phpunit
* @copyright 2011 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class testable_grading_manager extends grading_manager {
}
/**
* Test cases for the grading manager API
*
* @package core_grading
* @category phpunit
* @category test
* @copyright 2011 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_grade_grading_manager_testcase extends advanced_testcase {
class grading_manager_test extends \advanced_testcase {
public function test_basic_instantiation() {
$manager1 = get_grading_manager();
@@ -103,7 +85,7 @@ class core_grade_grading_manager_testcase extends advanced_testcase {
$this->assertEquals('rubric', $gradingman->get_active_method());
// attempting to set an invalid method
$this->expectException(moodle_exception::class);
$this->expectException(\moodle_exception::class);
$gradingman->set_active_method('no_one_should_ever_try_to_implement_a_method_with_this_silly_name');
}
@@ -115,27 +97,27 @@ class core_grade_grading_manager_testcase extends advanced_testcase {
$UTFfailuremessage = 'A test using UTF-8 characters has failed. Consider updating PHP and PHP\'s PCRE or INTL extensions (MDL-30494)';
$needle = " šašek, \n\n \r a král; \t";
$tokens = testable_grading_manager::tokenize($needle);
$tokens = grading_manager::tokenize($needle);
$this->assertEquals(2, count($tokens), $UTFfailuremessage);
$this->assertTrue(in_array('šašek', $tokens), $UTFfailuremessage);
$this->assertTrue(in_array('král', $tokens), $UTFfailuremessage);
$needle = ' " šašek a král " ';
$tokens = testable_grading_manager::tokenize($needle);
$tokens = grading_manager::tokenize($needle);
$this->assertEquals(1, count($tokens));
$this->assertTrue(in_array('šašek a král', $tokens));
$needle = '""';
$tokens = testable_grading_manager::tokenize($needle);
$tokens = grading_manager::tokenize($needle);
$this->assertTrue(empty($tokens));
$needle = '"0"';
$tokens = testable_grading_manager::tokenize($needle);
$tokens = grading_manager::tokenize($needle);
$this->assertEquals(1, count($tokens));
$this->assertTrue(in_array('0', $tokens));
$needle = '<span>Aha</span>, then who\'s a bad guy here he?';
$tokens = testable_grading_manager::tokenize($needle);
$tokens = grading_manager::tokenize($needle);
$this->assertEquals(8, count($tokens));
$this->assertTrue(in_array('span', $tokens)); // Extracted the tag name
$this->assertTrue(in_array('Aha', $tokens));
@@ -144,7 +126,7 @@ class core_grade_grading_manager_testcase extends advanced_testcase {
$this->assertTrue(in_array('he', $tokens)); // Removed the trailing ?
$needle = 'grammar, "english language"';
$tokens = testable_grading_manager::tokenize($needle);
$tokens = grading_manager::tokenize($needle);
$this->assertTrue(in_array('grammar', $tokens));
$this->assertTrue(in_array('english', $tokens));
$this->assertTrue(in_array('language', $tokens));
+33 -40
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/>.
/**
* Unit tests for the class in load_data.php
*
* @package gradeimport_csv
* @category phpunit
* @copyright 2014 Adrian Greeve
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace gradeimport_csv;
defined('MOODLE_INTERNAL') || die();
@@ -38,7 +31,7 @@ require_once($CFG->libdir . '/grade/tests/fixtures/lib.php');
* @copyright 2014 Adrian Greeve
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class gradeimport_csv_load_data_testcase extends grade_base_testcase {
class load_data_test extends \grade_base_testcase {
/** @var string $oktext Text to be imported. This data should have no issues being imported. */
protected $oktext = '"First name",Surname,"ID number",Institution,Department,"Email address","Assignment: Assignment for grape group", "Feedback: Assignment for grape group","Assignment: Second new grade item","Course total"
@@ -76,8 +69,8 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
*/
protected function csv_load($content) {
// Import the csv strings.
$this->iid = csv_import_reader::get_new_iid('grade');
$this->csvimport = new csv_import_reader($this->iid, 'grade');
$this->iid = \csv_import_reader::get_new_iid('grade');
$this->csvimport = new \csv_import_reader($this->iid, 'grade');
$this->csvimport->load_csv_content($content, 'utf8', 'comma');
$this->columns = $this->csvimport->get_columns();
@@ -97,7 +90,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
$encoding = 'utf8';
$separator = 'comma';
$previewrows = 5;
$csvpreview = new phpunit_gradeimport_csv_load_data();
$csvpreview = new \phpunit_gradeimport_csv_load_data();
$csvpreview->load_csv_content($this->oktext, $encoding, $separator, $previewrows);
$expecteddata = array(array(
@@ -144,7 +137,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
$this->assertEquals($csvpreview->get_headers(), $expectedheaders);
// Check that errors are being recorded.
$csvpreview = new phpunit_gradeimport_csv_load_data();
$csvpreview = new \phpunit_gradeimport_csv_load_data();
$csvpreview->load_csv_content($this->badtext, $encoding, $separator, $previewrows);
// Columns shouldn't match.
$this->assertEquals($csvpreview->get_error(), get_string('csvweirdcolumns', 'error'));
@@ -155,8 +148,8 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
*/
public function test_fetch_grade_items() {
$gradeitemsarray = grade_item::fetch_all(array('courseid' => $this->courseid));
$gradeitems = phpunit_gradeimport_csv_load_data::fetch_grade_items($this->courseid);
$gradeitemsarray = \grade_item::fetch_all(array('courseid' => $this->courseid));
$gradeitems = \phpunit_gradeimport_csv_load_data::fetch_grade_items($this->courseid);
// Make sure that each grade item is located in the gradeitemsarray.
foreach ($gradeitems as $key => $gradeitem) {
@@ -187,13 +180,13 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
$user = $this->getDataGenerator()->create_user();
$this->setAdminUser();
$record = new stdClass();
$record = new \stdClass();
$record->itemid = 4;
$record->newgradeitem = 25;
$record->finalgrade = 62.00;
$record->feedback = 'Some test feedback';
$testobject = new phpunit_gradeimport_csv_load_data();
$testobject = new \phpunit_gradeimport_csv_load_data();
$testobject->test_insert_grade_record($record, $user->id);
$gradeimportvalues = $DB->get_records('grade_import_values');
@@ -201,7 +194,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
$key = key($gradeimportvalues);
$testarray = array();
$testarray[$key] = new stdClass();
$testarray[$key] = new \stdClass();
$testarray[$key]->id = $key;
$testarray[$key]->itemid = $record->itemid;
$testarray[$key]->newgradeitem = $record->newgradeitem;
@@ -228,7 +221,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
// The assignment is item 6.
$key = 6;
$testobject = new phpunit_gradeimport_csv_load_data();
$testobject = new \phpunit_gradeimport_csv_load_data();
// Key for this assessment.
$this->csvimport->init();
@@ -329,7 +322,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
'label' => 'Field label: ' . $field
];
$testobject = new phpunit_gradeimport_csv_load_data();
$testobject = new \phpunit_gradeimport_csv_load_data();
// Check whether the user exists. If so, then the user id is returned. Otherwise, it returns null.
$userid = $testobject->test_check_user_exists($value, $userfields);
@@ -367,7 +360,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
public function test_create_feedback() {
$testarray = $this->csv_load($this->oktext);
$testobject = new phpunit_gradeimport_csv_load_data();
$testobject = new \phpunit_gradeimport_csv_load_data();
// Try to insert some feedback for an assessment.
$feedback = $testobject->test_create_feedback($this->courseid, 1, $testarray[0][7]);
@@ -383,7 +376,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
public function test_update_grade_item() {
$testarray = $this->csv_load($this->oktext);
$testobject = new phpunit_gradeimport_csv_load_data();
$testobject = new \phpunit_gradeimport_csv_load_data();
// We're not using scales so no to this option.
$verbosescales = 0;
@@ -394,7 +387,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
$newgrades = $testobject->test_update_grade_item($this->courseid, $map, $key, $verbosescales, $testarray[0][6]);
$expectedresult = array();
$expectedresult[0] = new stdClass();
$expectedresult[0] = new \stdClass();
$expectedresult[0]->itemid = 1;
$expectedresult[0]->finalgrade = $testarray[0][6];
@@ -415,14 +408,14 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
*/
public function test_map_user_data_with_value() {
// Need to add one of the users into the system.
$user = new stdClass();
$user = new \stdClass();
$user->firstname = 'Anne';
$user->lastname = 'Able';
$user->email = '[email protected]';
$userdetail = $this->getDataGenerator()->create_user($user);
$testarray = $this->csv_load($this->oktext);
$testobject = new phpunit_gradeimport_csv_load_data();
$testobject = new \phpunit_gradeimport_csv_load_data();
// We're not using scales so no to this option.
$verbosescales = 0;
@@ -452,7 +445,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
$this->courseid, $map[$key], $verbosescales);
// Expected result.
$resultarray = array();
$resultarray[0] = new stdClass();
$resultarray[0] = new \stdClass();
$resultarray[0]->itemid = 1;
$resultarray[0]->feedback = $testarray[0][7];
$this->assertEquals($feedback, $resultarray);
@@ -470,13 +463,13 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
global $DB;
// Need to add one of the users into the system.
$user = new stdClass();
$user = new \stdClass();
$user->firstname = 'Anne';
$user->lastname = 'Able';
$user->email = '[email protected]';
// Insert user 1.
$this->getDataGenerator()->create_user($user);
$user = new stdClass();
$user = new \stdClass();
$user->firstname = 'Bobby';
$user->lastname = 'Bunce';
$user->email = '[email protected]';
@@ -489,7 +482,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
$verbosescales = 0;
// Form data object.
$formdata = new stdClass();
$formdata = new \stdClass();
$formdata->mapfrom = 5;
$formdata->mapto = 'useremail';
$formdata->mapping_0 = 0;
@@ -509,7 +502,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
$formdata->forceimport = false;
// Blam go time.
$testobject = new phpunit_gradeimport_csv_load_data();
$testobject = new \phpunit_gradeimport_csv_load_data();
$dataloaded = $testobject->prepare_import_grade_data($this->columns, $formdata, $this->csvimport, $this->courseid, '', '',
$verbosescales);
// If everything inserted properly then this should be true.
@@ -522,13 +515,13 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
public function test_force_import_option () {
// Need to add users into the system.
$user = new stdClass();
$user = new \stdClass();
$user->firstname = 'Anne';
$user->lastname = 'Able';
$user->email = '[email protected]';
$user->id_number = 1;
$user1 = $this->getDataGenerator()->create_user($user);
$user = new stdClass();
$user = new \stdClass();
$user->firstname = 'Bobby';
$user->lastname = 'Bunce';
$user->email = '[email protected]';
@@ -542,14 +535,14 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
'gradetype' => GRADE_TYPE_VALUE,
'courseid' => $this->courseid
);
$gradeitem = new grade_item($params, false);
$gradeitem = new \grade_item($params, false);
$gradeitemid = $gradeitem->insert();
$importcode = 001;
$verbosescales = 0;
// Form data object.
$formdata = new stdClass();
$formdata = new \stdClass();
$formdata->mapfrom = 5;
$formdata->mapto = 'useremail';
$formdata->mapping_0 = 0;
@@ -572,7 +565,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
$exportdate = time();
$newcsvdata = str_replace('{exportdate}', $exportdate, $this->csvtext);
$this->csv_load($newcsvdata);
$testobject = new phpunit_gradeimport_csv_load_data();
$testobject = new \phpunit_gradeimport_csv_load_data();
$dataloaded = $testobject->prepare_import_grade_data($this->columns, $formdata, $this->csvimport,
$this->courseid, '', '', $verbosescales);
$this->assertTrue($dataloaded);
@@ -584,7 +577,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
$pastdate = strtotime('-1 day', time());
$newcsvdata = str_replace('{exportdate}', $pastdate, $this->csvtext);
$this->csv_load($newcsvdata);
$testobject = new phpunit_gradeimport_csv_load_data();
$testobject = new \phpunit_gradeimport_csv_load_data();
$dataloaded = $testobject->prepare_import_grade_data($this->columns, $formdata, $this->csvimport,
$this->courseid, '', '', $verbosescales);
$this->assertFalse($dataloaded);
@@ -593,7 +586,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
// Test using force import enabled and a date in the past.
$formdata->forceimport = true;
$testobject = new phpunit_gradeimport_csv_load_data();
$testobject = new \phpunit_gradeimport_csv_load_data();
$dataloaded = $testobject->prepare_import_grade_data($this->columns, $formdata, $this->csvimport,
$this->courseid, '', '', $verbosescales);
$this->assertTrue($dataloaded);
@@ -603,7 +596,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
$twoyearsago = strtotime('-2 year', time());
$newcsvdata = str_replace('{exportdate}', $twoyearsago, $this->csvtext);
$this->csv_load($newcsvdata);
$testobject = new phpunit_gradeimport_csv_load_data();
$testobject = new \phpunit_gradeimport_csv_load_data();
$dataloaded = $testobject->prepare_import_grade_data($this->columns, $formdata, $this->csvimport,
$this->courseid, '', '', $verbosescales);
$this->assertFalse($dataloaded);
@@ -615,7 +608,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
$newcsvdata = str_replace('{exportdate}', $baddate, $this->csvtext);
$this->csv_load($newcsvdata);
$formdata->mapping_6 = $gradeitemid;
$testobject = new phpunit_gradeimport_csv_load_data();
$testobject = new \phpunit_gradeimport_csv_load_data();
$dataloaded = $testobject->prepare_import_grade_data($this->columns, $formdata, $this->csvimport,
$this->courseid, '', '', $verbosescales);
$this->assertFalse($dataloaded);
@@ -627,7 +620,7 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",[email protected],75.00,,75.00,{exportdat
$oldcsv = str_replace('{exportdate}', $oneyearahead, $this->csvtext);
$this->csv_load($oldcsv);
$formdata->mapping_6 = $gradeitemid;
$testobject = new phpunit_gradeimport_csv_load_data();
$testobject = new \phpunit_gradeimport_csv_load_data();
$dataloaded = $testobject->prepare_import_grade_data($this->columns, $formdata, $this->csvimport,
$this->courseid, '', '', $verbosescales);
$this->assertFalse($dataloaded);
+13 -14
View File
@@ -14,26 +14,25 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace gradereport_singleview;
use gradereport_singleview_screen_testable;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once(__DIR__ . '/fixtures/screen.php');
require_once($CFG->libdir . '/gradelib.php');
/**
* Unit tests for gradereport_singleview screen class.
* Tests for screen class.
*
* @package gradereport_singleview
* @category test
* @copyright 2014 onwards Simey Lameze <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
global $CFG;
require_once(__DIR__ . '/fixtures/screen.php');
require_once($CFG->libdir . '/gradelib.php');
defined('MOODLE_INTERNAL') || die();
/**
* Tests for screen class.
*
* Class gradereport_singleview_screen_testcase.
*/
class gradereport_singleview_screen_testcase extends advanced_testcase {
class screen_test extends \advanced_testcase {
/**
* Test load_users method.
@@ -48,7 +47,7 @@ class gradereport_singleview_screen_testcase extends advanced_testcase {
// Create a course, users and groups.
$course = $this->getDataGenerator()->create_course();
$coursecontext = context_course::instance($course->id);
$coursecontext = \context_course::instance($course->id);
$group = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
$teacher = $this->getDataGenerator()->create_user();
$user1 = $this->getDataGenerator()->create_user();
+16 -16
View File
@@ -14,25 +14,25 @@
// 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 grade/edit/tree/lib.php.
*
* @package core_grades
* @category phpunit
* @author Andrew Davis
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
namespace core_grades;
use grade_edit_tree;
use grade_edit_tree_column;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot.'/grade/edit/tree/lib.php');
/**
* Tests grade_edit_tree (deals with the data on the 'Gradebook setup' page in the gradebook)
*
* @package core_grades
* @category test
* @author Andrew Davis
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
class core_grade_edittreelib_testcase extends advanced_testcase {
class edittreelib_test extends \advanced_testcase {
public function test_format_number() {
$numinput = array(0, 1, 1.01, '1.010', 1.2345);
$numoutput = array(0.0, 1.0, 1.01, 1.01, 1.2345);
@@ -52,9 +52,9 @@ class core_grade_edittreelib_testcase extends advanced_testcase {
$scale = $this->getDataGenerator()->create_scale();
$course = $this->getDataGenerator()->create_course();
$assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
$modulecontext = context_module::instance($assign->cmid);
$modulecontext = \context_module::instance($assign->cmid);
// The generator returns a dummy object, lets get the real assign object.
$assign = new assign($modulecontext, false, false);
$assign = new \assign($modulecontext, false, false);
$cm = $assign->get_course_module();
// Get range column.
@@ -74,7 +74,7 @@ class core_grade_edittreelib_testcase extends advanced_testcase {
$instance->instance = $instance->id;
$assign->update_instance($instance);
$gradeitem = grade_item::fetch($gradeitemparams);
$gradeitem = \grade_item::fetch($gradeitemparams);
$cell = $column->get_item_cell($gradeitem, array());
$this->assertEquals(GRADE_TYPE_VALUE, $gradeitem->gradetype);
@@ -87,7 +87,7 @@ class core_grade_edittreelib_testcase extends advanced_testcase {
$instance->instance = $instance->id;
$assign->update_instance($instance);
$gradeitem = grade_item::fetch($gradeitemparams);
$gradeitem = \grade_item::fetch($gradeitemparams);
$cell = $column->get_item_cell($gradeitem, array());
// Make the expected scale text.
@@ -113,7 +113,7 @@ class core_grade_edittreelib_testcase extends advanced_testcase {
$instance->instance = $instance->id;
$assign->update_instance($instance);
$gradeitem = grade_item::fetch($gradeitemparams);
$gradeitem = \grade_item::fetch($gradeitemparams);
$cell = $column->get_item_cell($gradeitem, array());
$this->assertEquals(GRADE_TYPE_TEXT, $gradeitem->gradetype);
@@ -127,7 +127,7 @@ class core_grade_edittreelib_testcase extends advanced_testcase {
$instance->instance = $instance->id;
$assign->update_instance($instance);
$gradeitem = grade_item::fetch($gradeitemparams);
$gradeitem = \grade_item::fetch($gradeitemparams);
$cell = $column->get_item_cell($gradeitem, array());
$this->assertEquals(GRADE_TYPE_NONE, $gradeitem->gradetype);
+8 -10
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/>.
/**
* Unit tests for grade/report/lib.php.
*
* @package core_grades
* @category phpunit
* @copyright Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
namespace core_grades;
defined('MOODLE_INTERNAL') || die();
@@ -31,8 +24,13 @@ require_once($CFG->dirroot.'/grade/export/lib.php');
/**
* A test class used to test grade_report, the abstract grade report parent class
*
* @package core_grades
* @category test
* @copyright Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
class core_grade_export_test extends advanced_testcase {
class export_test extends \advanced_testcase {
/**
* Ensure that feedback is correct formatted. Test the default implementation of format_feedback
@@ -67,7 +65,7 @@ class core_grade_export_test extends advanced_testcase {
$dg = $this->getDataGenerator();
$c1 = $dg->create_course();
$u1 = $dg->create_user();
$gi1a = new grade_item($dg->create_grade_item(['courseid' => $c1->id]), false);
$gi1a = new \grade_item($dg->create_grade_item(['courseid' => $c1->id]), false);
$gi1a->update_final_grade($u1->id, 1, 'test');
$contextid = $gi1a->get_context()->id;
$gradeid = $gi1a->id;
+21 -23
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/>.
/**
* Unit tests for grade/import/lib.php.
*
* @package core_grades
* @category phpunit
* @copyright 2015 Adrian Greeve <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
namespace core_grades;
defined('MOODLE_INTERNAL') || die();
@@ -30,8 +23,13 @@ require_once($CFG->dirroot . '/grade/import/lib.php');
/**
* Tests grade_import_lib functions.
*
* @package core_grades
* @category test
* @copyright 2015 Adrian Greeve <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
class core_grade_import_lib_test extends advanced_testcase {
class importlib_test extends \advanced_testcase {
/**
* Import grades into 'grade_import_values' table. This is done differently in the various import plugins,
@@ -42,7 +40,7 @@ class core_grade_import_lib_test extends advanced_testcase {
*/
private function import_grades($data) {
global $DB, $USER;
$graderecord = new stdClass();
$graderecord = new \stdClass();
$graderecord->importcode = $data['importcode'];
if (isset($data['itemid'])) {
$graderecord->itemid = $data['itemid'];
@@ -86,9 +84,9 @@ class core_grade_import_lib_test extends advanced_testcase {
$course = $this->getDataGenerator()->create_course();
$assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
$itemname = $assign->name;
$modulecontext = context_module::instance($assign->cmid);
$modulecontext = \context_module::instance($assign->cmid);
// The generator returns a dummy object, lets get the real assign object.
$assign = new assign($modulecontext, false, false);
$assign = new \assign($modulecontext, false, false);
$cm = $assign->get_course_module();
// Enrol users in the course.
@@ -96,7 +94,7 @@ class core_grade_import_lib_test extends advanced_testcase {
$this->getDataGenerator()->enrol_user($user2->id, $course->id);
// Enter a new grade into an existing grade item.
$gradeitem = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod'));
$gradeitem = \grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod'));
// Keep this value around for a test further down.
$originalgrade = 55;
@@ -111,14 +109,14 @@ class core_grade_import_lib_test extends advanced_testcase {
$this->assertTrue($status);
// Get imported grade_grade.
$gradegrade = grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id));
$gradegrade = \grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id));
$this->assertEquals($originalgrade, $gradegrade->finalgrade);
// Overriden field will be a timestamp and will evaluate out to true.
$this->assertTrue($gradegrade->is_overridden());
// Create a new grade item and import into that.
$importcode = get_new_importcode();
$record = new stdClass();
$record = new \stdClass();
$record->itemname = 'New grade item';
$record->importcode = $importcode;
$record->importer = $USER->id;
@@ -134,18 +132,18 @@ class core_grade_import_lib_test extends advanced_testcase {
$status = grade_import_commit($course->id, $importcode, false, false);
$this->assertTrue($status);
// Check that we have a new grade_item.
$gradeitem = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'manual'));
// Check that we have a new \grade_item.
$gradeitem = \grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'manual'));
$this->assertEquals($record->itemname, $gradeitem->itemname);
// Grades were imported.
$gradegrade = grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id));
$gradegrade = \grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id));
$this->assertEquals($finalgrade, $gradegrade->finalgrade);
// As this is a new item the grade has not been overridden.
$this->assertFalse($gradegrade->is_overridden());
// Import feedback only.
$importcode = get_new_importcode();
$gradeitem = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod'));
$gradeitem = \grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod'));
$originalfeedback = 'feedback can be useful';
$this->import_grades(array(
@@ -158,14 +156,14 @@ class core_grade_import_lib_test extends advanced_testcase {
$status = grade_import_commit($course->id, $importcode, true, false);
$this->assertTrue($status);
$gradegrade = grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id));
$gradegrade = \grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id));
// The final grade should be the same as the first record further up. We are only altering the feedback.
$this->assertEquals($originalgrade, $gradegrade->finalgrade);
$this->assertTrue($gradegrade->is_overridden());
// Import grades only.
$importcode = get_new_importcode();
$gradeitem = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod'));
$gradeitem = \grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod'));
$finalgrade = 60;
$this->import_grades(array(
@@ -178,7 +176,7 @@ class core_grade_import_lib_test extends advanced_testcase {
$status = grade_import_commit($course->id, $importcode, false, false);
$this->assertTrue($status);
$gradegrade = grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id));
$gradegrade = \grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id));
$this->assertEquals($finalgrade, $gradegrade->finalgrade);
// The final feedback should not have changed.
$this->assertEquals($originalfeedback, $gradegrade->feedback);
@@ -186,7 +184,7 @@ class core_grade_import_lib_test extends advanced_testcase {
// Check that printing of import status is correct.
$importcode = get_new_importcode();
$gradeitem = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod'));
$gradeitem = \grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod'));
$this->import_grades(array(
'importcode' => $importcode,
+10 -10
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/>.
/**
* Unit tests for grade quering
*
* @package core_grades
* @category phpunit
* @copyright 2011 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
namespace core_grades;
defined('MOODLE_INTERNAL') || die();
@@ -29,8 +22,15 @@ global $CFG;
require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->dirroot.'/grade/querylib.php');
class core_grade_querylib_testcase extends advanced_testcase {
/**
* Unit tests for grade quering
*
* @package core_grades
* @category test
* @copyright 2011 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
class querylib_test extends \advanced_testcase {
public function test_grade_get_gradable_activities() {
$this->resetAfterTest(true);
+23 -22
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 grade/report/user/lib.php.
*
* @package core_grades
* @category phpunit
* @copyright 2012 Andrew Davis
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
namespace core_grades;
use grade_plugin_return;
use grade_report_grader;
defined('MOODLE_INTERNAL') || die();
@@ -31,8 +27,13 @@ require_once($CFG->dirroot.'/grade/report/grader/lib.php');
/**
* Tests grade_report_grader (the grader report)
*
* @package core_grades
* @category test
* @copyright 2012 Andrew Davis
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
class core_grade_report_graderlib_testcase extends advanced_testcase {
class report_graderlib_test extends \advanced_testcase {
/**
* Tests grade_report_grader::process_data()
@@ -57,12 +58,12 @@ class core_grade_report_graderlib_testcase extends advanced_testcase {
$forummax = 80;
$forum1 = $this->getDataGenerator()->create_module('forum', array('assessed' => 1, 'scale' => $forummax, 'course' => $course->id));
// Switch the stdClass instance for a grade item instance.
$forum1 = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum1->id, 'courseid' => $course->id));
$forum1 = \grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum1->id, 'courseid' => $course->id));
$report = $this->create_report($course);
$testgrade = 60.00;
$data = new stdClass();
$data = new \stdClass();
$data->id = $course->id;
$data->report = 'grader';
$data->timepageload = time();
@@ -74,7 +75,7 @@ class core_grade_report_graderlib_testcase extends advanced_testcase {
$warnings = $report->process_data($data);
$this->assertEquals(count($warnings), 0);
$studentgrade = grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id));
$studentgrade = \grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id));
$this->assertEquals($studentgrade->finalgrade, $testgrade);
// Grade above max. Should be pulled down to max.
@@ -84,7 +85,7 @@ class core_grade_report_graderlib_testcase extends advanced_testcase {
$warnings = $report->process_data($data);
$this->assertEquals(count($warnings), 1);
$studentgrade = grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id));
$studentgrade = \grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id));
$this->assertEquals($studentgrade->finalgrade, $forummax);
// Grade below min. Should be pulled up to min.
@@ -94,7 +95,7 @@ class core_grade_report_graderlib_testcase extends advanced_testcase {
$warnings = $report->process_data($data);
$this->assertEquals(count($warnings), 1);
$studentgrade = grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id));
$studentgrade = \grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id));
$this->assertEquals($studentgrade->finalgrade, 0);
// Test unlimited grades so we can give a student a grade about max.
@@ -105,7 +106,7 @@ class core_grade_report_graderlib_testcase extends advanced_testcase {
$warnings = $report->process_data($data);
$this->assertEquals(count($warnings), 0);
$studentgrade = grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id));
$studentgrade = \grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id));
$this->assertEquals($studentgrade->finalgrade, $toobig);
}
@@ -504,7 +505,7 @@ class core_grade_report_graderlib_testcase extends advanced_testcase {
// Supposing the user cannot view hidden grades, this shouldn't make any difference (due
// to a bug, it previously did).
$context = context_course::instance($course->id);
$context = \context_course::instance($course->id);
$managerroleid = $DB->get_field('role', 'id', array('shortname' => 'manager'));
assign_capability('moodle/grade:viewhidden', CAP_PROHIBIT, $managerroleid, $context->id, true);
$this->assertFalse(has_capability('moodle/grade:viewhidden', $context));
@@ -520,16 +521,16 @@ class core_grade_report_graderlib_testcase extends advanced_testcase {
private function create_grade_category($course) {
static $cnt = 0;
$cnt++;
$grade_category = new grade_category(array('courseid' => $course->id, 'fullname' => 'Cat '.$cnt), false);
$grade_category->apply_default_settings();
$grade_category->apply_forced_settings();
$grade_category->insert();
return $grade_category;
$gradecat = new \grade_category(array('courseid' => $course->id, 'fullname' => 'Cat '.$cnt), false);
$gradecat->apply_default_settings();
$gradecat->apply_forced_settings();
$gradecat->insert();
return $gradecat;
}
private function create_report($course) {
$coursecontext = context_course::instance($course->id);
$coursecontext = \context_course::instance($course->id);
$gpr = new grade_plugin_return(array('type' => 'report', 'plugin'=>'grader', 'courseid' => $course->id));
$report = new grade_report_grader($course->id, $gpr, $coursecontext);
+16 -16
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 grade/report/user/lib.php.
*
* @package core_grades
* @category phpunit
* @copyright 2012 Andrew Davis
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
namespace core_grades;
use grade_plugin_return;
use grade_report_user;
defined('MOODLE_INTERNAL') || die();
@@ -29,11 +25,15 @@ global $CFG;
require_once($CFG->dirroot.'/grade/lib.php');
require_once($CFG->dirroot.'/grade/report/user/lib.php');
/**
* Tests grade_report_user (the gradebook's user report)
*
* @package core_grades
* @category test
* @copyright 2012 Andrew Davis
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
class core_grade_reportuserlib_testcase extends advanced_testcase {
class reportuserlib_test extends \advanced_testcase {
/**
* Tests grade_report_user::inject_rowspans()
@@ -52,8 +52,8 @@ class core_grade_reportuserlib_testcase extends advanced_testcase {
// Create a course.
$course = $this->getDataGenerator()->create_course();
$coursecategory = grade_category::fetch_course_category($course->id);
$coursecontext = context_course::instance($course->id);
$coursecategory = \grade_category::fetch_course_category($course->id);
$coursecontext = \context_course::instance($course->id);
// Create and enrol test users.
$student = $this->getDataGenerator()->create_user(array('username' => 'student_sam'));
@@ -87,8 +87,8 @@ class core_grade_reportuserlib_testcase extends advanced_testcase {
$forum1 = $this->getDataGenerator()->create_module('forum', array('assessed' => 1, 'scale' => 100, 'course' => $course->id));
$forum1cm = get_coursemodule_from_id('forum', $forum1->cmid);
// Switch the stdClass instance for a grade item instance so grade_item::set_parent() is available.
$forum1 = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum1->id, 'courseid' => $course->id));
// Switch the stdClass instance for a grade item instance so \grade_item::set_parent() is available.
$forum1 = \grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum1->id, 'courseid' => $course->id));
$report = $this->create_report($course, $student, $coursecontext);
// Lead column + course + (2 x activity) = 4
@@ -123,11 +123,11 @@ class core_grade_reportuserlib_testcase extends advanced_testcase {
set_coursemodule_visible($forum1cm->id, 1);
// Create a category and put the forum in it.
$params = new stdClass();
$params = new \stdClass();
$params->courseid = $course->id;
$params->fullname = 'unittestcategory';
$params->parent = $coursecategory->id;
$gradecategory = new grade_category($params, false);
$gradecategory = new \grade_category($params, false);
$gradecategory->insert();
$forum1->set_parent($gradecategory->id);
@@ -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/>.
/**
* Tests for h5p deleted event.
*
* @package core_h5p
* @category test
* @copyright 2019 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.8
*/
defined('MOODLE_INTERNAL') || die();
namespace core_h5p\event;
use core_h5p\local\library\autoloader;
@@ -37,7 +27,7 @@ use core_h5p\local\library\autoloader;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.8
*/
class core_h5p_event_h5p_deleted_testcase extends advanced_testcase {
class deleted_test extends \advanced_testcase {
/**
* Setup test.
@@ -74,7 +64,7 @@ class core_h5p_event_h5p_deleted_testcase extends advanced_testcase {
// Prepare redirect Events.
$sink = $this->redirectEvents();
// Test the event H5P deleted.
$event = \core_h5p\event\h5p_deleted::create($params);
$event = h5p_deleted::create($params);
$event->trigger();
$result = $sink->get_events();
$event = reset($result);
@@ -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/>.
/**
* Tests for h5p viewed event.
*
* @package core_h5p
* @category test
* @copyright 2019 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.8
*/
defined('MOODLE_INTERNAL') || die();
namespace core_h5p\event;
use core_h5p\local\library\autoloader;
@@ -37,7 +27,7 @@ use core_h5p\local\library\autoloader;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.8
*/
class core_h5p_event_h5p_viewed_testcase extends advanced_testcase {
class moved_test extends \advanced_testcase {
/**
* Setup test.
@@ -83,7 +73,7 @@ class core_h5p_event_h5p_viewed_testcase extends advanced_testcase {
// Prepare redirect Events.
$sink = $this->redirectEvents();
// Test the event H5P viewed.
$event = \core_h5p\event\h5p_viewed::create($params);
$event = h5p_viewed::create($params);
$event->trigger();
$result = $sink->get_events();
$event = reset($result);
+7 -9
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/>.
/**
* GeoIP tests
*
* @package core_iplookup
* @category phpunit
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core;
defined('MOODLE_INTERNAL') || die();
@@ -33,8 +26,13 @@ require_once("{$CFG->dirroot}/iplookup/lib.php");
/**
* GeoIp data file parsing test.
*
* @package core
* @category test
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_iplookup_geoip_testcase extends advanced_testcase {
class geoip_test extends \advanced_testcase {
public function setUp(): void {
$this->resetAfterTest();
}
+7 -12
View File
@@ -14,22 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* GeoIP tests
*
* @package core_iplookup
* @category phpunit
* @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();
namespace core;
/**
* GeoIp data file parsing test.
*
* @package core
* @category test
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_iplookup_geoplugin_testcase extends advanced_testcase {
class geoplugin_test extends \advanced_testcase {
public function setUp(): void {
global $CFG;
+4 -5
View File
@@ -14,18 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace antivirus_clamav;
/**
* Tests for ClamAV antivirus scanner class.
*
* @package antivirus_clamav
* @category phpunit
* @category test
* @copyright 2016 Ruslan Kabalin, Lancaster University.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
class antivirus_clamav_scanner_testcase extends advanced_testcase {
class scanner_test extends \advanced_testcase {
/** @var string temporary file used in testing */
protected $tempfile;
@@ -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/>.
/**
* Tests the event observers.
*
* @package message_email
* @category test
* @copyright 2019 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace message_email;
/**
* Class for testing the event observers.
@@ -33,7 +24,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2019 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class message_email_event_observers_task_testcase extends advanced_testcase {
class event_observers_test extends \advanced_testcase {
/**
* Test the message viewed event observer.
@@ -63,7 +54,7 @@ class message_email_event_observers_task_testcase extends advanced_testcase {
'core_group',
'groups',
$group1->id,
context_course::instance($course->id)->id
\context_course::instance($course->id)->id
);
$message = new \core\message\message();
@@ -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/>.
/**
* Tests the send email task.
*
* @package message_email
* @category test
* @copyright 2018 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace message_email\task;
defined('MOODLE_INTERNAL') || die();
@@ -37,7 +30,7 @@ require_once($CFG->dirroot . '/message/tests/messagelib_test.php');
* @copyright 2019 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_message_send_email_task_testcase extends advanced_testcase {
class send_email_test extends \advanced_testcase {
/**
* Test sending email task.
@@ -72,7 +65,7 @@ class core_message_send_email_task_testcase extends advanced_testcase {
'core_group',
'groups',
$group1->id,
context_course::instance($course->id)->id
\context_course::instance($course->id)->id
);
$conversation2 = \core_message\api::create_conversation(
@@ -83,7 +76,7 @@ class core_message_send_email_task_testcase extends advanced_testcase {
'core_group',
'groups',
$group2->id,
context_course::instance($course->id)->id
\context_course::instance($course->id)->id
);
// Go through each conversation.
@@ -115,7 +108,7 @@ class core_message_send_email_task_testcase extends advanced_testcase {
// Only 1 email is sent as the messages are included in it at a digest.
$sink = $this->redirectEmails();
$task = new \message_email\task\send_email_task();
$task = new send_email_task();
$task->execute();
$this->assertEquals(1, $sink->count());
@@ -137,7 +130,7 @@ class core_message_send_email_task_testcase extends advanced_testcase {
// Confirm running it again does not send another.
$sink = $this->redirectEmails();
$task = new \message_email\task\send_email_task();
$task = new send_email_task();
$task->execute();
$this->assertEquals(0, $sink->count());
}
@@ -14,18 +14,12 @@
// 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 messaging cleanup task
*
* @package message_popup
* @category test
* @copyright 2020 Paul Holden <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace message_popup;
use core\task\messaging_cleanup_task;
use message_popup_test_helper;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/message/output/popup/tests/base.php');
@@ -38,7 +32,7 @@ require_once($CFG->dirroot . '/message/output/popup/tests/base.php');
* @copyright 2020 Paul Holden <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class message_popup_messaging_cleanup_testcase extends advanced_testcase {
class messaging_cleanup_test extends \advanced_testcase {
// Helper trait for sending fake popup notifications.
use message_popup_test_helper;
+1 -1
View File
@@ -32,7 +32,7 @@ require_once($CFG->dirroot . '/message/tests/messagelib_test.php');
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class api_test extends \core_message_messagelib_testcase {
class api_test extends messagelib_test {
public function test_mark_all_read_for_user_touser() {
$sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1'));
+1 -3
View File
@@ -25,8 +25,6 @@
namespace core_message\event;
use core_message_messagelib_testcase;
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -41,7 +39,7 @@ require_once($CFG->dirroot . '/message/tests/messagelib_test.php');
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class events_test extends core_message_messagelib_testcase {
class events_test extends \core_message\messagelib_test {
/**
* Test set up.
+5 -2
View File
@@ -22,16 +22,19 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_message;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/fixtures/inbound_fixtures.php');
/**
* Tests for core_message_inbound to test Variable Envelope Return Path functionality.
*
* @package core_message
* @copyright 2014 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_message_inbound_testcase extends advanced_testcase {
class inbound_test extends \advanced_testcase {
/**
* Perform setup tasks generic to each test.
@@ -67,7 +70,7 @@ class core_message_inbound_testcase extends advanced_testcase {
$record->component = $component;
$record->enabled = $enabled;
$record->id = $DB->insert_record('messageinbound_handlers', $record);
$handler = \core_message_inbound_test_manager::handler_from_record($record);
$handler = core_message_inbound_test_manager::handler_from_record($record);
return $handler;
}
+8 -15
View File
@@ -14,22 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Test api's in message lib.
*
* @package core_message
* @category test
* @copyright 2014 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_message;
use core_message\tests\helper as testhelper;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/message/lib.php');
use \core_message\tests\helper as testhelper;
/**
* Test api's in message lib.
*
@@ -38,7 +31,7 @@ use \core_message\tests\helper as testhelper;
* @copyright 2014 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_message_messagelib_testcase extends advanced_testcase {
class messagelib_test extends \advanced_testcase {
/** @var phpunit_message_sink keep track of messages. */
protected $messagesink = null;
@@ -61,8 +54,8 @@ class core_message_messagelib_testcase extends advanced_testcase {
* sent from a user to another. We should stop using it once {@link message_send()} will support
* transactions. This is not clean at all, this is just used to add rows to the table.
*
* @param stdClass $userfrom user object of the one sending the message.
* @param stdClass $userto user object of the one receiving the message.
* @param \stdClass $userfrom user object of the one sending the message.
* @param \stdClass $userto user object of the one receiving the message.
* @param string $message message to send.
* @param int $notification if the message is a notification.
* @param int $time the time the message was sent
@@ -76,7 +69,7 @@ class core_message_messagelib_testcase extends advanced_testcase {
}
if ($notification) {
$record = new stdClass();
$record = new \stdClass();
$record->useridfrom = $userfrom->id;
$record->useridto = $userto->id;
$record->subject = 'No subject';
@@ -110,7 +103,7 @@ class core_message_messagelib_testcase extends advanced_testcase {
}
// Ok, send the message.
$record = new stdClass();
$record = new \stdClass();
$record->useridfrom = $userfrom->id;
$record->conversationid = $conversationid;
$record->subject = 'No subject';
+10 -16
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/>.
/**
* received message global search unit tests.
*
* @package core
* @copyright 2016 Devang Gaur
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_message;
defined('MOODLE_INTERNAL') || die();
@@ -30,11 +24,11 @@ require_once($CFG->dirroot . '/search/tests/fixtures/testable_core_search.php');
/**
* Provides the unit tests for received messages global search.
*
* @package core
* @package core_message
* @copyright 2016 Devang Gaur
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class message_received_search_testcase extends advanced_testcase {
class search_received_test extends \advanced_testcase {
/**
* @var string Area id
@@ -52,7 +46,7 @@ class message_received_search_testcase extends advanced_testcase {
$this->messagereceivedareaid = \core_search\manager::generate_areaid('core_message', 'message_received');
// Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this.
$search = testable_core_search::instance();
$search = \testable_core_search::instance();
}
/**
@@ -163,19 +157,19 @@ class message_received_search_testcase extends advanced_testcase {
// Test function with null context and system context (same).
$rs = $searcharea->get_document_recordset(0, null);
$this->assertEquals(['Test1', 'Test2'], message_sent_search_testcase::recordset_to_subjects($rs));
$rs = $searcharea->get_document_recordset(0, context_system::instance());
$this->assertEquals(['Test1', 'Test2'], message_sent_search_testcase::recordset_to_subjects($rs));
$this->assertEquals(['Test1', 'Test2'], search_sent_test::recordset_to_subjects($rs));
$rs = $searcharea->get_document_recordset(0, \context_system::instance());
$this->assertEquals(['Test1', 'Test2'], search_sent_test::recordset_to_subjects($rs));
// Test with user context for each user.
$rs = $searcharea->get_document_recordset(0, \context_user::instance($user1->id));
$this->assertEquals(['Test2'], message_sent_search_testcase::recordset_to_subjects($rs));
$this->assertEquals(['Test2'], search_sent_test::recordset_to_subjects($rs));
$rs = $searcharea->get_document_recordset(0, \context_user::instance($user2->id));
$this->assertEquals(['Test1'], message_sent_search_testcase::recordset_to_subjects($rs));
$this->assertEquals(['Test1'], search_sent_test::recordset_to_subjects($rs));
// Test with a course context (should return null).
$this->assertNull($searcharea->get_document_recordset(0,
context_course::instance($SITE->id)));
\context_course::instance($SITE->id)));
}
/**
+7 -13
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/>.
/**
* Sent message global search unit tests.
*
* @package core
* @copyright 2016 Devang Gaur
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_message;
defined('MOODLE_INTERNAL') || die();
@@ -30,11 +24,11 @@ require_once($CFG->dirroot . '/search/tests/fixtures/testable_core_search.php');
/**
* Provides the unit tests for sent message global search.
*
* @package core
* @package core_message
* @copyright 2016 Devang Gaur
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class message_sent_search_testcase extends advanced_testcase {
class search_sent_test extends \advanced_testcase {
/**
* @var string Area id
@@ -52,7 +46,7 @@ class message_sent_search_testcase extends advanced_testcase {
$this->messagesentareaid = \core_search\manager::generate_areaid('core_message', 'message_sent');
// Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this.
$search = testable_core_search::instance();
$search = \testable_core_search::instance();
}
/**
@@ -163,7 +157,7 @@ class message_sent_search_testcase extends advanced_testcase {
// Test function with null context and system context (same).
$rs = $searcharea->get_document_recordset(0, null);
$this->assertEquals(['Test1', 'Test2'], self::recordset_to_subjects($rs));
$rs = $searcharea->get_document_recordset(0, context_system::instance());
$rs = $searcharea->get_document_recordset(0, \context_system::instance());
$this->assertEquals(['Test1', 'Test2'], self::recordset_to_subjects($rs));
// Test with user context for each user.
@@ -174,7 +168,7 @@ class message_sent_search_testcase extends advanced_testcase {
// Test with a course context (should return null).
$this->assertNull($searcharea->get_document_recordset(0,
context_course::instance($SITE->id)));
\context_course::instance($SITE->id)));
}
/**
@@ -183,7 +177,7 @@ class message_sent_search_testcase extends advanced_testcase {
* @param moodle_recordset $rs Recordset to convert (and close)
* @return array Array of IDs from records indexed by number (0, 1, 2, ...)
*/
public static function recordset_to_subjects(moodle_recordset $rs) {
public static function recordset_to_subjects(\moodle_recordset $rs) {
$results = [];
foreach ($rs as $rec) {
$results[] = $rec->subject;
@@ -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/>.
/**
* Tests the migrate message data task.
*
* @package core_message
* @category test
* @copyright 2018 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_message\task;
defined('MOODLE_INTERNAL') || die();
@@ -37,7 +30,7 @@ require_once($CFG->dirroot . '/message/tests/messagelib_test.php');
* @copyright 2018 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_message_migrate_message_data_task_testcase extends advanced_testcase {
class migrate_message_data_test extends \advanced_testcase {
/**
* Test set up.
@@ -83,18 +76,18 @@ class core_message_migrate_message_data_task_testcase extends advanced_testcase
$m9 = $this->create_legacy_message_or_notification($user3->id, $user2->id, 9);
// Let's delete some messages, not using API here as it does not use the legacy tables.
$messageupdate = new stdClass();
$messageupdate = new \stdClass();
$messageupdate->id = $m1;
$messageupdate->timeusertodeleted = $timedeleted1;
$DB->update_record('message_read', $messageupdate);
$messageupdate = new stdClass();
$messageupdate = new \stdClass();
$messageupdate->id = $m5;
$messageupdate->timeuserfromdeleted = $timedeleted2;
$DB->update_record('message', $messageupdate);
// Now, let's execute the task for user 1.
$task = new \core_message\task\migrate_message_data();
$task = new migrate_message_data();
$task->set_custom_data(
[
'userid' => $user1->id
@@ -214,7 +207,7 @@ class core_message_migrate_message_data_task_testcase extends advanced_testcase
$this->create_legacy_message_or_notification($user3->id, $user2->id, 9, true);
// Now, let's execute the task for user 1.
$task = new \core_message\task\migrate_message_data();
$task = new migrate_message_data();
$task->set_custom_data(
[
'userid' => $user1->id
@@ -281,7 +274,7 @@ class core_message_migrate_message_data_task_testcase extends advanced_testcase
$this->create_legacy_message_or_notification($user1->id, $user2->id, null, false, null, null);
// Now, let's execute the task for user 1.
$task = new \core_message\task\migrate_message_data();
$task = new migrate_message_data();
$task->set_custom_data(
[
'userid' => $user1->id
@@ -309,7 +302,7 @@ class core_message_migrate_message_data_task_testcase extends advanced_testcase
$this->create_legacy_message_or_notification($user1->id, $user2->id, null, true, null, null);
// Now, let's execute the task for user 1.
$task = new \core_message\task\migrate_message_data();
$task = new migrate_message_data();
$task->set_custom_data(
[
'userid' => $user1->id
@@ -336,14 +329,14 @@ class core_message_migrate_message_data_task_testcase extends advanced_testcase
$m1 = $this->create_legacy_message_or_notification($user1->id, $user1->id, null, false, null, null);
// Let's delete the message for the 'user to' and 'user from' which in this case is the same user.
$messageupdate = new stdClass();
$messageupdate = new \stdClass();
$messageupdate->id = $m1;
$messageupdate->timeuserfromdeleted = time();
$messageupdate->timeusertodeleted = time();
$DB->update_record('message', $messageupdate);
// Now, let's execute the task for the user.
$task = new \core_message\task\migrate_message_data();
$task = new migrate_message_data();
$task->set_custom_data(
[
'userid' => $user1->id
@@ -409,7 +402,7 @@ class core_message_migrate_message_data_task_testcase extends advanced_testcase
// Insert into the legacy 'message_popup' table if it is a notification.
if ($notification) {
$mp = new stdClass();
$mp = new \stdClass();
$mp->messageid = $id;
$mp->isread = (!is_null($timeread)) ? 1 : 0;
@@ -22,6 +22,10 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignfeedback_file;
use mod_assign_test_generator;
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -31,10 +35,11 @@ require_once($CFG->dirroot . '/mod/assign/feedback/file/importziplib.php');
/**
* Unit tests for importziplib.
*
* @package assignfeedback_file
* @copyright 2020 Eric Merrill <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assignfeedback_importziplib_testcase extends advanced_testcase {
class importziplib_test extends \advanced_testcase {
// Use the generator helper.
use mod_assign_test_generator;
@@ -61,7 +66,7 @@ class assignfeedback_importziplib_testcase extends advanced_testcase {
$fs = get_file_storage();
// Setup a basic file we will work with. We will keep renaming and repathing it.
$record = new stdClass;
$record = new \stdClass;
$record->contextid = $assign->get_context()->id;
$record->component = 'assignfeedback_file';
$record->filearea = ASSIGNFEEDBACK_FILE_FILEAREA;
@@ -72,7 +77,7 @@ class assignfeedback_importziplib_testcase extends advanced_testcase {
$file = $fs->create_file_from_string($record, 'file content');
// The importer we will use.
$importer = new assignfeedback_file_zip_importer();
$importer = new \assignfeedback_file_zip_importer();
// Setup some variable we use.
$user = null;
@@ -132,7 +137,7 @@ class assignfeedback_importziplib_testcase extends advanced_testcase {
$this->assertTrue($result);
$this->assertEquals($participants[$studentid], $user);
$this->assertEquals('My_cool_filename.txt', $filename);
$this->assertInstanceOf(assign_submission_file::class, $plugin);
$this->assertInstanceOf(\assign_submission_file::class, $plugin);
// Test another good file, with some additional path and underscores.
$user = null;
@@ -143,6 +148,6 @@ class assignfeedback_importziplib_testcase extends advanced_testcase {
$this->assertTrue($result);
$this->assertEquals($participants[$studentid], $user);
$this->assertEquals('/some_path/My File.txt', $filename);
$this->assertInstanceOf(assign_submission_file::class, $plugin);
$this->assertInstanceOf(\assign_submission_file::class, $plugin);
}
}
+6 -12
View File
@@ -14,14 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Assign feedback unit tests.
*
* @package mod_assign
* @category test
* @copyright 2019 Ilya Tregubov [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign;
use assignfeedback_editpdf\document_services;
use assignfeedback_editpdf\combined_document;
use mod_assign_test_generator;
defined('MOODLE_INTERNAL') || die();
@@ -29,9 +26,6 @@ global $CFG;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
require_once($CFG->dirroot . '/mod/assign/tests/generator.php');
use \assignfeedback_editpdf\document_services;
use \assignfeedback_editpdf\combined_document;
/**
* Provides the unit tests for feedback.
*
@@ -40,7 +34,7 @@ use \assignfeedback_editpdf\combined_document;
* @copyright 2019 Ilya Tregubov [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_assign_feedback_testcase extends advanced_testcase {
class feedback_test extends \advanced_testcase {
// Use the generator helper.
use mod_assign_test_generator;
+21 -19
View File
@@ -14,15 +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/>.
/**
* Unit tests for (some of) mod/assign/locallib.php.
*
* @package mod_assign
* @category phpunit
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign;
use mod_assign_test_generator;
defined('MOODLE_INTERNAL') || die();
@@ -30,7 +24,15 @@ global $CFG;
require_once(__DIR__ . '/../locallib.php');
require_once($CFG->dirroot . '/mod/assign/tests/generator.php');
class mod_assign_locallib_participants extends advanced_testcase {
/**
* Unit tests for (some of) mod/assign/locallib.php.
*
* @package mod_assign
* @category test
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class locallib_participants_test extends \advanced_testcase {
use mod_assign_test_generator;
public function test_list_participants_blind_marking() {
@@ -61,12 +63,12 @@ class mod_assign_locallib_participants extends advanced_testcase {
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
$instance = $generator->create_instance(['course' => $course->id, 'blindmarking' => 1]);
$cm = get_coursemodule_from_instance('assign', $instance->id);
$context = context_module::instance($cm->id);
$assign = new assign($context, $cm, $course);
$context = \context_module::instance($cm->id);
$assign = new \assign($context, $cm, $course);
// Allocate IDs now.
// We're testing whether the IDs are correct after allocation.
assign::allocate_unique_ids($assign->get_instance()->id);
\assign::allocate_unique_ids($assign->get_instance()->id);
$participants = $assign->list_participants(null, false);
@@ -79,20 +81,20 @@ class mod_assign_locallib_participants extends advanced_testcase {
$keys = array_keys($participants);
// Create a grading table, and query the DB This should have the same order.
$table = new assign_grading_table($assign, 10, '', 0, false);
$table = new \assign_grading_table($assign, 10, '', 0, false);
$table->setup();
$table->query_db(10);
$this->assertEquals($keys, array_keys($table->rawdata));
// Submit a file for the second student.
$data = new stdClass();
$data = new \stdClass();
$data->onlinetext_editor = array('itemid'=>file_get_unused_draft_itemid(),
'text'=>'Submission text',
'format'=>FORMAT_MOODLE);
static::helper_add_submission($assign, $participants[$keys[1]], $data, 'onlinetext');
// Assign has a private cache. The easiest way to clear this is to create a new instance.
$assign = new assign($context, $cm, $course);
$assign = new \assign($context, $cm, $course);
$newparticipants = $assign->list_participants(null, false);
@@ -109,7 +111,7 @@ class mod_assign_locallib_participants extends advanced_testcase {
// Submit for the other student.
static::helper_add_submission($assign, $participants[$keys[0]], $data, 'onlinetext');
$assign = new assign($context, $cm, $course);
$assign = new \assign($context, $cm, $course);
$newparticipants = $assign->list_participants(null, false);
// The users should still be listed in order of the first submission
@@ -129,10 +131,10 @@ class mod_assign_locallib_participants extends advanced_testcase {
$this->resetAfterTest(true);
// Create a role that will prevent users submitting.
$role = self::getDataGenerator()->create_role();
assign_capability('mod/assign:submit', CAP_PROHIBIT, $role, context_system::instance());
assign_capability('mod/assign:submit', CAP_PROHIBIT, $role, \context_system::instance());
// Create the test data.
$course = self::getDataGenerator()->create_course();
$coursecontext = context_course::instance($course->id);
$coursecontext = \context_course::instance($course->id);
$assign = $this->create_instance($course);
self::getDataGenerator()->create_and_enrol($course, 'teacher');
$student1 = self::getDataGenerator()->create_and_enrol($course, 'student');
@@ -164,7 +166,7 @@ class mod_assign_locallib_participants extends advanced_testcase {
$submission = $assign->get_user_submission($user->id, true);
$submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
$rc = new ReflectionClass('assign');
$rc = new \ReflectionClass('assign');
$rcm = $rc->getMethod('update_submission');
$rcm->setAccessible(true);
$rcm->invokeArgs($assign, [$submission, $user->id, true, false]);
+7 -13
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/>.
/**
* Unit tests for (some of) mod/assign/markerallocaion_test.php.
*
* @package mod_assign
* @category test
* @copyright 2017 Andrés Melo <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign;
defined('MOODLE_INTERNAL') || die();
@@ -30,13 +23,14 @@ require_once($CFG->dirroot . '/lib/accesslib.php');
require_once($CFG->dirroot . '/course/lib.php');
/**
* This class tests some of marker allocation functionality.
* Unit tests for (some of) mod/assign/markerallocaion_test.php.
*
* @package mod_assign
* @category test
* @copyright 2017 Andrés Melo <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_assign_markerallocation_testcase extends advanced_testcase {
class markerallocation_test extends \advanced_testcase {
/**
* Create all the needed elements to test the difference between both functions.
@@ -49,7 +43,7 @@ class mod_assign_markerallocation_testcase extends advanced_testcase {
$this->course = $this->getDataGenerator()->create_course();
// Setting assing module, markingworkflow and markingallocation set to 1 to enable marker allocation.
$record = new stdClass();
$record = new \stdClass();
$record->course = $this->course;
$modulesettings = array(
@@ -122,9 +116,9 @@ class mod_assign_markerallocation_testcase extends advanced_testcase {
list($sort, $params) = users_order_by_sql('u');
// Old code, it must return 3 users: teacher1, teacher2 and Manger.
$oldmarkers = get_users_by_capability(context_course::instance($this->course->id), 'mod/assign:grade', '', $sort);
$oldmarkers = get_users_by_capability(\context_course::instance($this->course->id), 'mod/assign:grade', '', $sort);
// New code, it must return 2 users: teacher1 and teacher2.
$newmarkers = get_enrolled_users(context_course::instance($this->course->id), 'mod/assign:grade', 0, 'u.*', $sort);
$newmarkers = get_enrolled_users(\context_course::instance($this->course->id), 'mod/assign:grade', 0, 'u.*', $sort);
// Test result quantity.
$this->assertEquals(count($oldusers), count($oldmarkers));
@@ -13,6 +13,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 privacy legacy polyfill for mod_assign.
*
@@ -22,6 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\privacy;
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -31,10 +34,12 @@ require_once($CFG->dirroot . '/mod/assign/feedback/comments/locallib.php');
/**
* Unit tests for the assignment feedback subplugins API's privacy legacy_polyfill.
*
* @package mod_assign
* @category test
* @copyright 2018 Adrian Greeve <adriangreeve.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_assignfeedback_privacy_legacy_polyfill_test extends advanced_testcase {
class feedback_legacy_polyfill_test extends \advanced_testcase {
/**
* Convenience function to create an instance of an assignment.
@@ -86,8 +91,8 @@ class mod_assignfeedback_privacy_legacy_polyfill_test extends advanced_testcase
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$assign = $this->create_instance(['course' => $course]);
$context = context_system::instance();
$subplugin = new assign_feedback_comments($assign, 'comments');
$context = \context_system::instance();
$subplugin = new \assign_feedback_comments($assign, 'comments');
$requestdata = new \mod_assign\privacy\assign_plugin_request_data($context,$assign);
$mock = $this->createMock(test_assignfeedback_legacy_polyfill_mock_wrapper::class);
$mock->expects($this->once())
@@ -104,8 +109,8 @@ class mod_assignfeedback_privacy_legacy_polyfill_test extends advanced_testcase
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$assign = $this->create_instance(['course' => $course]);
$context = context_system::instance();
$subplugin = new assign_feedback_comments($assign, 'comments');
$context = \context_system::instance();
$subplugin = new \assign_feedback_comments($assign, 'comments');
$requestdata = new \mod_assign\privacy\assign_plugin_request_data($context,$assign);
$mock = $this->createMock(test_assignfeedback_legacy_polyfill_mock_wrapper::class);
$mock->expects($this->once())
@@ -122,8 +127,8 @@ class mod_assignfeedback_privacy_legacy_polyfill_test extends advanced_testcase
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$assign = $this->create_instance(['course' => $course]);
$context = context_system::instance();
$subplugin = new assign_feedback_comments($assign, 'comments');
$context = \context_system::instance();
$subplugin = new \assign_feedback_comments($assign, 'comments');
$requestdata = new \mod_assign\privacy\assign_plugin_request_data($context,$assign);
$mock = $this->createMock(test_assignfeedback_legacy_polyfill_mock_wrapper::class);
$mock->expects($this->once())
@@ -13,6 +13,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 privacy legacy polyfill for mod_assign.
*
@@ -21,6 +22,9 @@
* @copyright 2018 Adrian Greeve <adriangreeve.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\privacy;
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -30,10 +34,12 @@ require_once($CFG->dirroot . '/mod/assign/submission/comments/locallib.php');
/**
* Unit tests for the assignment submission subplugins API's privacy legacy_polyfill.
*
* @package mod_assign
* @category test
* @copyright 2018 Adrian Greeve <adriangreeve.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_assignsubmission_privacy_legacy_polyfill_test extends advanced_testcase {
class submission_legacy_polyfill_test extends \advanced_testcase {
/**
* Convenience function to create an instance of an assignment.
@@ -85,8 +91,8 @@ class mod_assignsubmission_privacy_legacy_polyfill_test extends advanced_testcas
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$assign = $this->create_instance(['course' => $course]);
$context = context_system::instance();
$subplugin = new assign_submission_comments($assign, 'comment');
$context = \context_system::instance();
$subplugin = new \assign_submission_comments($assign, 'comment');
$requestdata = new \mod_assign\privacy\assign_plugin_request_data($context, $assign);
$mock = $this->createMock(test_assignsubmission_legacy_polyfill_mock_wrapper::class);
$mock->expects($this->once())
@@ -103,8 +109,8 @@ class mod_assignsubmission_privacy_legacy_polyfill_test extends advanced_testcas
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$assign = $this->create_instance(['course' => $course]);
$context = context_system::instance();
$subplugin = new assign_submission_comments($assign, 'comment');
$context = \context_system::instance();
$subplugin = new \assign_submission_comments($assign, 'comment');
$requestdata = new \mod_assign\privacy\assign_plugin_request_data($context, $assign);
$mock = $this->createMock(test_assignsubmission_legacy_polyfill_mock_wrapper::class);
$mock->expects($this->once())
@@ -121,8 +127,8 @@ class mod_assignsubmission_privacy_legacy_polyfill_test extends advanced_testcas
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$assign = $this->create_instance(['course' => $course]);
$context = context_system::instance();
$subplugin = new assign_submission_comments($assign, 'comment');
$context = \context_system::instance();
$subplugin = new \assign_submission_comments($assign, 'comment');
$requestdata = new \mod_assign\privacy\assign_plugin_request_data($context, $assign);
$mock = $this->createMock(test_assignsubmission_legacy_polyfill_mock_wrapper::class);
$mock->expects($this->once())
+2 -8
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 format_message.
*
* @package mod_chat
* @copyright 2016 Andrew NIcols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_chat;
defined('MOODLE_INTERNAL') || die();
@@ -34,7 +28,7 @@ require_once($CFG->dirroot . '/mod/chat/lib.php');
* @copyright 2016 Andrew NIcols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_chat_format_message_testcase extends advanced_testcase {
class format_message_test extends \advanced_testcase {
const USER_CURRENT = 1;
const USER_OTHER = 2;
+7 -8
View File
@@ -13,13 +13,11 @@
//
// 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 (some of) mod/feedback/classes/lib.php.
*
* @package mod_feedback
* @copyright 2019 Tobias Reischmann
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_feedback;
use mod_feedback_completion;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/feedback/classes/completion.php');
@@ -27,10 +25,11 @@ require_once($CFG->dirroot . '/mod/feedback/classes/completion.php');
/**
* Unit tests for (some of) mod/feedback/classes/completion.php.
*
* @package mod_feedback
* @copyright 2019 Tobias Reischmann
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_feedback_completion_testcase extends advanced_testcase {
class completion_test extends \advanced_testcase {
/**
* Returns the number of pages with visible elements for the current state of the feedback completion.
* @param mod_feedback_completion $completion
@@ -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/>.
/**
* Tests for mod_forum_backup_forum_activity_task.
*
* @package mod_forum
* @category test
* @copyright 2016 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum;
use backup_forum_activity_task;
defined('MOODLE_INTERNAL') || die();
@@ -40,7 +35,7 @@ require_once($CFG->dirroot . '/mod/forum/backup/moodle2/backup_forum_activity_ta
* @copyright 2016 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_backup_forum_activity_task_testcase extends advanced_testcase {
class backup_forum_activity_task_test extends \advanced_testcase {
/**
* Test the encoding of forum content links.
@@ -14,13 +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/>.
/**
* The exported_posts builder tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum;
use mod_forum_tests_generator_trait;
defined('MOODLE_INTERNAL') || die();
@@ -33,7 +29,7 @@ require_once(__DIR__ . '/generator_trait.php');
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_builders_exported_posts_testcase extends advanced_testcase {
class builders_exported_posts_test extends \advanced_testcase {
// Make use of the test generator trait.
use mod_forum_tests_generator_trait;
@@ -78,16 +74,16 @@ class mod_forum_builders_exported_posts_testcase extends advanced_testcase {
array_map(function($forum) use ($entityfactory, $DB) {
$course = $DB->get_record('course', ['id' => $forum->course]);
$coursemodule = get_coursemodule_from_instance('forum', $forum->id);
$context = context_module::instance($coursemodule->id);
return $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course);
$context = \context_module::instance($coursemodule->id);
return $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course);
}, $forums),
// Discussions.
array_map(function($discussion) use ($entityfactory) {
return $entityfactory->get_discussion_from_stdclass($discussion);
return $entityfactory->get_discussion_from_stdClass($discussion);
}, $discussions),
// Posts.
array_map(function($post) use ($entityfactory) {
return $entityfactory->get_post_from_stdclass($post);
return $entityfactory->get_post_from_stdClass($post);
}, $posts)
];
}
+2 -10
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/>.
/**
* The author entity tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace mod_forum;
use mod_forum\local\entities\author as author_entity;
@@ -33,7 +25,7 @@ use mod_forum\local\entities\author as author_entity;
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_entities_author_testcase extends advanced_testcase {
class entities_author_test extends \advanced_testcase {
/**
* Test the entity returns expected values.
*/
@@ -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/>.
/**
* The discussion_summary entity tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace mod_forum;
use mod_forum\local\entities\author as author_entity;
use mod_forum\local\entities\discussion as discussion_entity;
@@ -36,7 +28,7 @@ use mod_forum\local\entities\post as post_entity;
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_entities_discussion_summary_testcase extends advanced_testcase {
class entities_discussion_summary_test extends \advanced_testcase {
/**
* Test the entity returns expected values.
*/
+2 -10
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/>.
/**
* The discussion entity tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace mod_forum;
use mod_forum\local\entities\discussion as discussion_entity;
use mod_forum\local\entities\post as post_entity;
@@ -34,7 +26,7 @@ use mod_forum\local\entities\post as post_entity;
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_entities_discussion_testcase extends advanced_testcase {
class entities_discussion_test extends \advanced_testcase {
/**
* Test the entity returns expected values.
*/
+6 -12
View File
@@ -14,22 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The forum entity tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum;
use mod_forum\local\entities\discussion as discussion_entity;
use mod_forum\local\entities\forum as forum_entity;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/rating/lib.php');
use mod_forum\local\entities\discussion as discussion_entity;
use mod_forum\local\entities\forum as forum_entity;
/**
* The forum entity tests.
*
@@ -37,7 +31,7 @@ use mod_forum\local\entities\forum as forum_entity;
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_entities_forum_testcase extends advanced_testcase {
class entities_forum_test extends \advanced_testcase {
/**
* Test the entity returns expected values.
*/
@@ -66,7 +60,7 @@ class mod_forum_entities_forum_testcase extends advanced_testcase {
$course = $this->getDataGenerator()->create_course();
$forum = $this->getDataGenerator()->create_module('forum', ['course' => $course->id]);
$coursemodule = get_coursemodule_from_instance('forum', $forum->id);
$context = context_module::instance($coursemodule->id);
$context = \context_module::instance($coursemodule->id);
$effectivegroupmode = NOGROUPS;
$id = 1;
$courseid = 2;
@@ -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/>.
/**
* The post_read_receipt_collection entity tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace mod_forum;
use mod_forum\local\entities\post_read_receipt_collection as collection_entity;
use mod_forum\local\entities\post as post_entity;
@@ -34,7 +26,7 @@ use mod_forum\local\entities\post as post_entity;
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_entities_post_read_receipt_collection_testcase extends advanced_testcase {
class entities_post_read_receipt_collection_test extends \advanced_testcase {
/**
* Test the entity returns expected values.
*/
+2 -10
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/>.
/**
* The post entity tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace mod_forum;
use mod_forum\local\entities\post as post_entity;
@@ -33,7 +25,7 @@ use mod_forum\local\entities\post as post_entity;
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_entities_post_testcase extends advanced_testcase {
class entities_post_test extends \advanced_testcase {
/**
* Test the entity returns expected values.
*/
+2 -10
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/>.
/**
* The discussion entity tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace mod_forum;
use mod_forum\local\entities\sorter as sorter_entity;
@@ -33,7 +25,7 @@ use mod_forum\local\entities\sorter as sorter_entity;
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_entities_sorter_testcase extends advanced_testcase {
class entities_sorter_test extends \advanced_testcase {
/**
* Test the entity returns expected values.
*/
+8 -17
View File
@@ -14,19 +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/>.
/**
* The author exporter tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace mod_forum;
use mod_forum\local\entities\author as author_entity;
use mod_forum\local\exporters\author as author_exporter;
global $CFG;
/**
* The author exporter tests.
@@ -35,7 +26,7 @@ global $CFG;
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_exporters_author_testcase extends advanced_testcase {
class exporters_author_test extends \advanced_testcase {
/**
* Test the export function returns expected values.
*/
@@ -48,9 +39,9 @@ class mod_forum_exporters_author_testcase extends advanced_testcase {
$course = $datagenerator->create_course();
$forum = $datagenerator->create_module('forum', ['course' => $course->id]);
$coursemodule = get_coursemodule_from_instance('forum', $forum->id);
$context = context_module::instance($coursemodule->id);
$context = \context_module::instance($coursemodule->id);
$entityfactory = \mod_forum\local\container::get_entity_factory();
$forum = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course);
$forum = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course);
$author = new author_entity(
1,
1,
@@ -88,9 +79,9 @@ class mod_forum_exporters_author_testcase extends advanced_testcase {
$course = $datagenerator->create_course();
$forum = $datagenerator->create_module('forum', ['course' => $course->id]);
$coursemodule = get_coursemodule_from_instance('forum', $forum->id);
$context = context_module::instance($coursemodule->id);
$context = \context_module::instance($coursemodule->id);
$entityfactory = \mod_forum\local\container::get_entity_factory();
$forum = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course);
$forum = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course);
$author = new author_entity(
1,
1,
@@ -127,9 +118,9 @@ class mod_forum_exporters_author_testcase extends advanced_testcase {
$course = $datagenerator->create_course();
$forum = $datagenerator->create_module('forum', ['course' => $course->id]);
$coursemodule = get_coursemodule_from_instance('forum', $forum->id);
$context = context_module::instance($coursemodule->id);
$context = \context_module::instance($coursemodule->id);
$entityfactory = \mod_forum\local\container::get_entity_factory();
$forum = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course);
$forum = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course);
$author = new author_entity(
1,
1,
+4 -12
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/>.
/**
* The discussion exporter tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace mod_forum;
use mod_forum\local\entities\discussion as discussion_entity;
use mod_forum\local\exporters\discussion as discussion_exporter;
@@ -34,7 +26,7 @@ use mod_forum\local\exporters\discussion as discussion_exporter;
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_exporters_discussion_testcase extends advanced_testcase {
class exporters_discussion_test extends \advanced_testcase {
/**
* Test set up function.
*/
@@ -69,9 +61,9 @@ class mod_forum_exporters_discussion_testcase extends advanced_testcase {
$course = $datagenerator->create_course();
$forum = $datagenerator->create_module('forum', ['course' => $course->id]);
$coursemodule = get_coursemodule_from_instance('forum', $forum->id);
$context = context_module::instance($coursemodule->id);
$context = \context_module::instance($coursemodule->id);
$entityfactory = \mod_forum\local\container::get_entity_factory();
$forum = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course);
$forum = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course);
$group = $datagenerator->create_group(['courseid' => $course->id]);
$now = time();
$discussion = new discussion_entity(
+4 -12
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/>.
/**
* The discussion forum tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace mod_forum;
use mod_forum\local\entities\forum as forum_entity;
use mod_forum\local\exporters\forum as forum_exporter;
@@ -34,7 +26,7 @@ use mod_forum\local\exporters\forum as forum_exporter;
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_exporters_forum_testcase extends advanced_testcase {
class exporters_forum_test extends \advanced_testcase {
/**
* Test the export function returns expected values.
*/
@@ -51,9 +43,9 @@ class mod_forum_exporters_forum_testcase extends advanced_testcase {
'groupmode' => VISIBLEGROUPS
]);
$coursemodule = get_coursemodule_from_instance('forum', $forum->id);
$context = context_module::instance($coursemodule->id);
$context = \context_module::instance($coursemodule->id);
$entityfactory = \mod_forum\local\container::get_entity_factory();
$forum = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course);
$forum = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course);
$exporter = new forum_exporter($forum, [
'legacydatamapperfactory' => \mod_forum\local\container::get_legacy_data_mapper_factory(),
+45 -42
View File
@@ -22,12 +22,15 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace mod_forum;
use \mod_forum\local\entities\discussion as discussion_entity;
use \mod_forum\local\entities\post as post_entity;
use \mod_forum\local\exporters\post as post_exporter;
use \mod_forum\local\managers\capability as capability_manager;
use mod_forum\local\entities\discussion as discussion_entity;
use mod_forum\local\entities\post as post_entity;
use mod_forum\local\exporters\post as post_exporter;
use mod_forum\local\managers\capability as capability_manager;
use mod_forum_tests_generator_trait;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once(__DIR__ . '/generator_trait.php');
@@ -40,7 +43,7 @@ require_once($CFG->dirroot . '/rating/lib.php');
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_exporters_post_testcase extends advanced_testcase {
class exporters_post_test extends \advanced_testcase {
// Make use of the test generator trait.
use mod_forum_tests_generator_trait;
@@ -64,7 +67,7 @@ class mod_forum_exporters_post_testcase extends advanced_testcase {
$course = $datagenerator->create_course();
$forum = $datagenerator->create_module('forum', ['course' => $course->id]);
$coursemodule = get_coursemodule_from_instance('forum', $forum->id);
$context = context_module::instance($coursemodule->id);
$context = \context_module::instance($coursemodule->id);
$now = time();
$forumgenparams = [
@@ -128,11 +131,11 @@ class mod_forum_exporters_post_testcase extends advanced_testcase {
);
$managerfactory = \mod_forum\local\container::get_manager_factory();
$entityfactory = \mod_forum\local\container::get_entity_factory();
$forum = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course);
$discussion = $entityfactory->get_discussion_from_stdclass($discussion);
$post = $entityfactory->get_post_from_stdclass($post);
$author = $entityfactory->get_author_from_stdclass($user);
$authorcontext = context_user::instance($author->get_id());
$forum = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course);
$discussion = $entityfactory->get_discussion_from_stdClass($discussion);
$post = $entityfactory->get_post_from_stdClass($post);
$author = $entityfactory->get_author_from_stdClass($user);
$authorcontext = \context_user::instance($author->get_id());
$exporter = new post_exporter($post, [
'legacydatamapperfactory' => \mod_forum\local\container::get_legacy_data_mapper_factory(),
@@ -229,7 +232,7 @@ class mod_forum_exporters_post_testcase extends advanced_testcase {
$course = $datagenerator->create_course();
$forum = $datagenerator->create_module('forum', ['course' => $course->id]);
$coursemodule = get_coursemodule_from_instance('forum', $forum->id);
$context = context_module::instance($coursemodule->id);
$context = \context_module::instance($coursemodule->id);
$discussion = $forumgenerator->create_discussion((object) [
'course' => $forum->course,
'userid' => $user->id,
@@ -283,11 +286,11 @@ class mod_forum_exporters_post_testcase extends advanced_testcase {
);
$managerfactory = \mod_forum\local\container::get_manager_factory();
$entityfactory = \mod_forum\local\container::get_entity_factory();
$forum = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course);
$discussion = $entityfactory->get_discussion_from_stdclass($discussion);
$post = $entityfactory->get_post_from_stdclass($post);
$author = $entityfactory->get_author_from_stdclass($user);
$authorcontext = context_user::instance($author->get_id());
$forum = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course);
$discussion = $entityfactory->get_discussion_from_stdClass($discussion);
$post = $entityfactory->get_post_from_stdClass($post);
$author = $entityfactory->get_author_from_stdClass($user);
$authorcontext = \context_user::instance($author->get_id());
$exporter = new post_exporter($post, [
'legacydatamapperfactory' => \mod_forum\local\container::get_legacy_data_mapper_factory(),
@@ -337,7 +340,7 @@ class mod_forum_exporters_post_testcase extends advanced_testcase {
$course = $datagenerator->create_course();
$forum = $datagenerator->create_module('forum', ['course' => $course->id]);
$coursemodule = get_coursemodule_from_instance('forum', $forum->id);
$context = context_module::instance($coursemodule->id);
$context = \context_module::instance($coursemodule->id);
$discussion = $forumgenerator->create_discussion((object) [
'course' => $forum->course,
'userid' => $user->id,
@@ -391,11 +394,11 @@ class mod_forum_exporters_post_testcase extends advanced_testcase {
);
$managerfactory = \mod_forum\local\container::get_manager_factory();
$entityfactory = \mod_forum\local\container::get_entity_factory();
$forum = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course);
$discussion = $entityfactory->get_discussion_from_stdclass($discussion);
$post = $entityfactory->get_post_from_stdclass($post);
$author = $entityfactory->get_author_from_stdclass($user);
$authorcontext = context_user::instance($author->get_id());
$forum = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course);
$discussion = $entityfactory->get_discussion_from_stdClass($discussion);
$post = $entityfactory->get_post_from_stdClass($post);
$author = $entityfactory->get_author_from_stdClass($user);
$authorcontext = \context_user::instance($author->get_id());
$exporter = new post_exporter($post, [
'legacydatamapperfactory' => \mod_forum\local\container::get_legacy_data_mapper_factory(),
@@ -492,37 +495,37 @@ class test_capability_manager extends capability_manager {
/**
* Override can_view_post
*
* @param stdClass $user The user
* @param \stdClass $user The user
* @param discussion_entity $discussion The discussion
* @param post_entity $post The post
* @return bool
*/
public function can_view_post(stdClass $user, discussion_entity $discussion, post_entity $post) : bool {
public function can_view_post(\stdClass $user, discussion_entity $discussion, post_entity $post) : bool {
return $this->view;
}
/**
* Override can_edit_post
*
* @param stdClass $user The user
* @param \stdClass $user The user
* @param discussion_entity $discussion The discussion
* @param post_entity $post The post
* @return bool
*/
public function can_edit_post(stdClass $user, discussion_entity $discussion, post_entity $post) : bool {
public function can_edit_post(\stdClass $user, discussion_entity $discussion, post_entity $post) : bool {
return $this->edit;
}
/**
* Override can_delete_post
*
* @param stdClass $user The user
* @param \stdClass $user The user
* @param discussion_entity $discussion The discussion
* @param post_entity $post The post
* @param bool $hasreplies
* @return bool
*/
public function can_delete_post(stdClass $user, discussion_entity $discussion, post_entity $post,
public function can_delete_post(\stdClass $user, discussion_entity $discussion, post_entity $post,
bool $hasreplies = false) : bool {
return $this->delete;
}
@@ -530,64 +533,64 @@ class test_capability_manager extends capability_manager {
/**
* Override can_split_post
*
* @param stdClass $user The user
* @param \stdClass $user The user
* @param discussion_entity $discussion The discussion
* @param post_entity $post The post
* @return bool
*/
public function can_split_post(stdClass $user, discussion_entity $discussion, post_entity $post) : bool {
public function can_split_post(\stdClass $user, discussion_entity $discussion, post_entity $post) : bool {
return $this->split;
}
/**
* Override can_reply_to_post
*
* @param stdClass $user The user
* @param \stdClass $user The user
* @param discussion_entity $discussion The discussion
* @param post_entity $post The post
* @return bool
*/
public function can_reply_to_post(stdClass $user, discussion_entity $discussion, post_entity $post) : bool {
public function can_reply_to_post(\stdClass $user, discussion_entity $discussion, post_entity $post) : bool {
return $this->reply;
}
/**
* Override can_export_post
*
* @param stdClass $user The user
* @param \stdClass $user The user
* @param post_entity $post The post
* @return bool
*/
public function can_export_post(stdClass $user, post_entity $post) : bool {
public function can_export_post(\stdClass $user, post_entity $post) : bool {
return $this->export;
}
/**
* Override can_manually_control_post_read_status
*
* @param stdClass $user The user
* @param \stdClass $user The user
* @return bool
*/
public function can_manually_control_post_read_status(stdClass $user) : bool {
public function can_manually_control_post_read_status(\stdClass $user) : bool {
return $this->controlreadstatus;
}
/**
* Override can_reply_privately_to_post
* @param stdClass $user
* @param \stdClass $user
* @param post_entity $post
* @return bool
*/
public function can_reply_privately_to_post(stdClass $user, post_entity $post) : bool {
public function can_reply_privately_to_post(\stdClass $user, post_entity $post) : bool {
return $this->canreplyprivatelytopost;
}
/**
* Override can_self_enrol
* @param stdClass $user
* @param \stdClass $user
* @return bool
*/
public function can_self_enrol(stdClass $user) : bool {
public function can_self_enrol(\stdClass $user) : bool {
return $this->canenrol;
}
}
+3 -10
View File
@@ -14,24 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace mod_forum;
/**
* Tests for the local\container class.
*
* @package mod_forum
* @copyright 2019 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Tests for the local\container class.
*
* @copyright 2019 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \mod_forum\local\container
*/
class mod_forum_local_container_testcase extends advanced_testcase {
class local_container_test extends \advanced_testcase {
/**
* Ensure that a renderer factory is returned.
*
+5 -8
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/>.
/**
* The forum module mail generation tests for groups.
*
* @package mod_forum
* @copyright 2013 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum;
use mod_forum_tests_cron_trait;
use mod_forum_tests_generator_trait;
defined('MOODLE_INTERNAL') || die();
@@ -35,7 +32,7 @@ require_once(__DIR__ . '/generator_trait.php');
* @copyright 2013 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_mail_group_testcase extends advanced_testcase {
class mail_group_test extends \advanced_testcase {
// Make use of the cron tester trait.
use mod_forum_tests_cron_trait;
+17 -12
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/>.
/**
* The forum module mail generation tests.
*
* @package mod_forum
* @category external
* @copyright 2013 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum;
use mod_forum_tests_generator_trait;
use mod_forum_tests_cron_trait;
defined('MOODLE_INTERNAL') || die();
@@ -30,7 +26,16 @@ require_once($CFG->dirroot . '/mod/forum/lib.php');
require_once(__DIR__ . '/cron_trait.php');
require_once(__DIR__ . '/generator_trait.php');
class mod_forum_mail_testcase extends advanced_testcase {
/**
* The forum module mail generation tests.
*
* @package mod_forum
* @category test
* @copyright 2013 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/
class mail_test extends \advanced_testcase {
// Make use of the cron tester trait.
use mod_forum_tests_cron_trait;
@@ -240,7 +245,7 @@ class mod_forum_mail_testcase extends advanced_testcase {
// A user with the manageactivities capability within the course can subscribe.
$roleids = $DB->get_records_menu('role', null, '', 'shortname, id');
assign_capability('moodle/course:manageactivities', CAP_ALLOW, $roleids['student'], context_course::instance($course->id));
assign_capability('moodle/course:manageactivities', CAP_ALLOW, $roleids['student'], \context_course::instance($course->id));
// Suscribe the recipient only.
\mod_forum\subscriptions::subscribe_user($recipient->id, $forum);
@@ -289,7 +294,7 @@ class mod_forum_mail_testcase extends advanced_testcase {
// A user with the manageactivities capability within the course can subscribe.
$roleids = $DB->get_records_menu('role', null, '', 'shortname, id');
assign_capability('moodle/course:manageactivities', CAP_ALLOW, $roleids['student'], context_course::instance($course->id));
assign_capability('moodle/course:manageactivities', CAP_ALLOW, $roleids['student'], \context_course::instance($course->id));
// Run cron and check that the expected number of users received the notification.
list($discussion, $post) = $this->helper_post_to_forum($forum, $author);
@@ -1187,7 +1192,7 @@ class mod_forum_mail_testcase extends advanced_testcase {
$fs = get_file_storage();
foreach ($attachments as $attachment) {
$filerecord = array(
'contextid' => context_module::instance($forum->cmid)->id,
'contextid' => \context_module::instance($forum->cmid)->id,
'component' => 'mod_forum',
'filearea' => 'attachment',
'itemid' => $post->id,
+18 -14
View File
@@ -15,21 +15,25 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The module forums external functions unit tests
*
* @package mod_forum
* @category external
* @copyright 2013 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum;
defined('MOODLE_INTERNAL') || die();
use mod_forum_tests_cron_trait;
use mod_forum_tests_generator_trait;
defined('MOODLE_INTERNAL') || die;
require_once(__DIR__ . '/cron_trait.php');
require_once(__DIR__ . '/generator_trait.php');
class mod_forum_maildigest_testcase extends advanced_testcase {
/**
* The module forums external functions unit tests
*
* @package mod_forum
* @category test
* @copyright 2013 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class maildigest_test extends \advanced_testcase {
// Make use of the cron tester trait.
use mod_forum_tests_cron_trait;
@@ -95,9 +99,9 @@ class mod_forum_maildigest_testcase extends advanced_testcase {
protected function helper_setup_user_in_course() {
global $DB;
$return = new stdClass();
$return->courses = new stdClass();
$return->forums = new stdClass();
$return = new \stdClass();
$return->courses = new \stdClass();
$return->forums = new \stdClass();
$return->forumids = array();
// Create a user.
@@ -108,7 +112,7 @@ class mod_forum_maildigest_testcase extends advanced_testcase {
$return->courses->course1 = $this->getDataGenerator()->create_course();
// Create forums.
$record = new stdClass();
$record = new \stdClass();
$record->course = $return->courses->course1->id;
$record->forcesubscribe = 1;
+51 -55
View File
@@ -14,22 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The capability manager tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum;
use mod_forum\local\container;
use mod_forum\local\entities\forum;
use mod_forum\local\managers\capability as capability_manager;
use mod_forum_tests_generator_trait;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once(__DIR__ . '/generator_trait.php');
use mod_forum\local\entities\forum;
use mod_forum\local\managers\capability as capability_manager;
/**
* The capability manager tests.
*
@@ -38,7 +34,7 @@ use mod_forum\local\managers\capability as capability_manager;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \mod_forum\local\managers\capability
*/
class mod_forum_managers_capability_testcase extends advanced_testcase {
class managers_capability_test extends \advanced_testcase {
// Make use of the test generator trait.
use mod_forum_tests_generator_trait;
@@ -90,19 +86,19 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$datagenerator = $this->getDataGenerator();
$this->user = $datagenerator->create_user();
$this->managerfactory = \mod_forum\local\container::get_manager_factory();
$this->entityfactory = \mod_forum\local\container::get_entity_factory();
$this->managerfactory = container::get_manager_factory();
$this->entityfactory = container::get_entity_factory();
$this->course = $datagenerator->create_course();
$this->forumrecord = $datagenerator->create_module('forum', ['course' => $this->course->id]);
$this->coursemodule = get_coursemodule_from_instance('forum', $this->forumrecord->id);
$this->context = context_module::instance($this->coursemodule->id);
$this->context = \context_module::instance($this->coursemodule->id);
$this->roleid = $DB->get_field('role', 'id', ['shortname' => 'teacher'], MUST_EXIST);
$datagenerator->enrol_user($this->user->id, $this->course->id, 'teacher');
[$discussion, $post] = $this->helper_post_to_forum($this->forumrecord, $this->user, ['timemodified' => time() - 100]);
$this->discussion = $this->entityfactory->get_discussion_from_stdclass($discussion);
$this->discussion = $this->entityfactory->get_discussion_from_stdClass($discussion);
$this->discussionrecord = $discussion;
$this->post = $this->entityfactory->get_post_from_stdclass(
$this->post = $this->entityfactory->get_post_from_stdClass(
(object) array_merge((array) $post, ['timecreated' => time() - 100])
);
$this->postrecord = $post;
@@ -127,7 +123,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
*/
private function create_forum(array $forumproperties = []) {
$forumrecord = (object) array_merge((array) $this->forumrecord, $forumproperties);
return $this->entityfactory->get_forum_from_stdclass(
return $this->entityfactory->get_forum_from_stdClass(
$forumrecord,
$this->context,
$this->coursemodule,
@@ -218,8 +214,8 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
['course' => $this->course->id, 'groupmode' => SEPARATEGROUPS]
);
$coursemodule = get_coursemodule_from_instance('forum', $forumrecord->id);
$context = context_module::instance($coursemodule->id);
$forum = $this->entityfactory->get_forum_from_stdclass(
$context = \context_module::instance($coursemodule->id);
$forum = $this->entityfactory->get_forum_from_stdClass(
$forumrecord,
$context,
$coursemodule,
@@ -421,7 +417,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$forum = $this->create_forum();
$user = $this->user;
$capabilitymanager = $this->managerfactory->get_capability_manager($forum);
$cache = cache::make('mod_forum', 'forum_is_tracked');
$cache = \cache::make('mod_forum', 'forum_is_tracked');
$user->trackforums = true;
$prefid = $DB->insert_record('forum_track_prefs', ['userid' => $user->id, 'forumid' => $forum->get_id()]);
@@ -577,8 +573,8 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
['course' => $this->course->id, 'groupmode' => SEPARATEGROUPS]
);
$coursemodule = get_coursemodule_from_instance('forum', $forumrecord->id);
$context = context_module::instance($coursemodule->id);
$forum = $this->entityfactory->get_forum_from_stdclass(
$context = \context_module::instance($coursemodule->id);
$forum = $this->entityfactory->get_forum_from_stdClass(
$forumrecord,
$context,
$coursemodule,
@@ -593,7 +589,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$this->assertFalse($capabilitymanager->can_post_in_discussion($user, $discussion));
$group = $this->getDataGenerator()->create_group(['courseid' => $this->course->id]);
$discussion = $this->entityfactory->get_discussion_from_stdclass(
$discussion = $this->entityfactory->get_discussion_from_stdClass(
(object) array_merge((array) $this->discussionrecord, ['groupid' => $group->id])
);
@@ -609,8 +605,8 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
['course' => $this->course->id, 'groupmode' => VISIBLEGROUPS]
);
$coursemodule = get_coursemodule_from_instance('forum', $forumrecord->id);
$context = context_module::instance($coursemodule->id);
$forum = $this->entityfactory->get_forum_from_stdclass(
$context = \context_module::instance($coursemodule->id);
$forum = $this->entityfactory->get_forum_from_stdClass(
$forumrecord,
$context,
$coursemodule,
@@ -625,7 +621,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$this->assertTrue($capabilitymanager->can_post_in_discussion($user, $discussion));
$group = $this->getDataGenerator()->create_group(['courseid' => $this->course->id]);
$discussion = $this->entityfactory->get_discussion_from_stdclass(
$discussion = $this->entityfactory->get_discussion_from_stdClass(
(object) array_merge((array) $this->discussionrecord, ['groupid' => $group->id])
);
@@ -689,7 +685,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$forum = $this->create_forum(['type' => 'news']);
$capabilitymanager = $this->managerfactory->get_capability_manager($forum);
// Discussion hasn't started yet.
$discussion = $this->entityfactory->get_discussion_from_stdclass(
$discussion = $this->entityfactory->get_discussion_from_stdClass(
(object) array_merge((array) $this->discussionrecord, ['timestart' => time() + 100])
);
@@ -698,7 +694,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
// Back to a discussion that has started.
$discussion = $this->discussion;
// Post is a reply.
$post = $this->entityfactory->get_post_from_stdclass(
$post = $this->entityfactory->get_post_from_stdClass(
(object) array_merge((array) $this->postrecord, ['parent' => 5])
);
@@ -714,7 +710,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
// Create a new post that definitely isn't the first post of the discussion.
// Only the author, and a user with editanypost can edit it.
$post = $this->entityfactory->get_post_from_stdclass(
$post = $this->entityfactory->get_post_from_stdClass(
(object) array_merge((array) $this->postrecord, ['id' => $post->get_id() + 100])
);
$this->give_capability('mod/forum:editanypost');
@@ -723,7 +719,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$post = $this->post;
// Set the first post of the discussion to our post.
$discussion = $this->entityfactory->get_discussion_from_stdclass(
$discussion = $this->entityfactory->get_discussion_from_stdClass(
(object) array_merge((array) $this->discussionrecord, ['firstpost' => $post->get_id()])
);
@@ -752,7 +748,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$capabilitymanager = $this->managerfactory->get_capability_manager($forum);
// Set the first post of the discussion to our post.
$discussion = $this->entityfactory->get_discussion_from_stdclass(
$discussion = $this->entityfactory->get_discussion_from_stdClass(
(object) array_merge((array) $this->discussionrecord, ['firstpost' => $post->get_id()])
);
@@ -760,7 +756,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$this->assertFalse($capabilitymanager->can_delete_post($user, $discussion, $post));
// Set the first post of the discussion to something else.
$discussion = $this->entityfactory->get_discussion_from_stdclass(
$discussion = $this->entityfactory->get_discussion_from_stdClass(
(object) array_merge((array) $this->discussionrecord, ['firstpost' => $post->get_id() - 1])
);
@@ -774,7 +770,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$CFG->maxeditingtime = 200;
// Make the post owned by someone else.
$post = $this->entityfactory->get_post_from_stdclass(
$post = $this->entityfactory->get_post_from_stdClass(
(object) array_merge((array) $this->postrecord, ['userid' => $user->id - 1])
);
@@ -815,7 +811,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$capabilitymanager = $this->managerfactory->get_capability_manager($forum);
// Make the post a reply.
$post = $this->entityfactory->get_post_from_stdclass(
$post = $this->entityfactory->get_post_from_stdClass(
(object) array_merge((array) $this->postrecord, ['parent' => 5])
);
@@ -826,7 +822,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$this->assertTrue($capabilitymanager->can_split_post($user, $discussion, $post));
// Make the post have no parent.
$post = $this->entityfactory->get_post_from_stdclass(
$post = $this->entityfactory->get_post_from_stdClass(
(object) array_merge((array) $this->postrecord, ['parent' => 0])
);
@@ -835,7 +831,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$forum = $this->create_forum(['type' => 'single']);
$capabilitymanager = $this->managerfactory->get_capability_manager($forum);
// Make the post a reply.
$post = $this->entityfactory->get_post_from_stdclass(
$post = $this->entityfactory->get_post_from_stdClass(
(object) array_merge((array) $this->postrecord, ['parent' => 5])
);
@@ -843,7 +839,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$this->assertFalse($capabilitymanager->can_split_post($user, $discussion, $post));
// Make the post a private reply.
$post = $this->entityfactory->get_post_from_stdclass(
$post = $this->entityfactory->get_post_from_stdClass(
(object) array_merge((array) $this->postrecord, ['parent' => 5, 'privatereplyto' => $user->id])
);
@@ -899,8 +895,8 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
['course' => $this->course->id, 'groupmode' => SEPARATEGROUPS]
);
$coursemodule = get_coursemodule_from_instance('forum', $forumrecord->id);
$context = context_module::instance($coursemodule->id);
$forum = $this->entityfactory->get_forum_from_stdclass(
$context = \context_module::instance($coursemodule->id);
$forum = $this->entityfactory->get_forum_from_stdClass(
$forumrecord,
$context,
$coursemodule,
@@ -915,7 +911,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$this->assertFalse($capabilitymanager->can_reply_to_post($user, $discussion, $post));
$group = $this->getDataGenerator()->create_group(['courseid' => $this->course->id]);
$discussion = $this->entityfactory->get_discussion_from_stdclass(
$discussion = $this->entityfactory->get_discussion_from_stdClass(
(object) array_merge((array) $this->discussionrecord, ['groupid' => $group->id])
);
@@ -931,8 +927,8 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
['course' => $this->course->id, 'groupmode' => VISIBLEGROUPS]
);
$coursemodule = get_coursemodule_from_instance('forum', $forumrecord->id);
$context = context_module::instance($coursemodule->id);
$forum = $this->entityfactory->get_forum_from_stdclass(
$context = \context_module::instance($coursemodule->id);
$forum = $this->entityfactory->get_forum_from_stdClass(
$forumrecord,
$context,
$coursemodule,
@@ -947,7 +943,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$this->assertTrue($capabilitymanager->can_reply_to_post($user, $discussion, $post));
$group = $this->getDataGenerator()->create_group(['courseid' => $this->course->id]);
$discussion = $this->entityfactory->get_discussion_from_stdclass(
$discussion = $this->entityfactory->get_discussion_from_stdClass(
(object) array_merge((array) $this->discussionrecord, ['groupid' => $group->id])
);
@@ -958,7 +954,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$this->assertTrue($capabilitymanager->can_reply_to_post($user, $discussion, $post));
// Make the post a private reply.
$post = $this->entityfactory->get_post_from_stdclass(
$post = $this->entityfactory->get_post_from_stdClass(
(object) array_merge((array) $this->postrecord, ['parent' => 5, 'privatereplyto' => $user->id])
);
@@ -997,7 +993,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$now = time();
$options = ['parent' => $this->post->get_id(), 'created' => $now - 100];
$student1post = $this->helper_post_to_discussion($this->forumrecord, $this->discussionrecord, $student1, $options);
$student1postentity = $this->entityfactory->get_post_from_stdclass($student1post);
$student1postentity = $this->entityfactory->get_post_from_stdClass($student1post);
// Confirm Student 2 cannot reply student 1's answer yet.
$this->assertFalse($capabilitymanager->can_reply_to_post($student2, $this->discussion, $student1postentity));
@@ -1035,7 +1031,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$this->assertTrue($capabilitymanager->can_reply_privately_to_post($this->user, $post));
// Make the post a private reply.
$post = $this->entityfactory->get_post_from_stdclass(
$post = $this->entityfactory->get_post_from_stdClass(
(object) array_merge((array) $this->postrecord, ['parent' => 5, 'privatereplyto' => $user->id])
);
@@ -1060,7 +1056,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$discussion = $this->discussion;
$post = $this->post;
$privatepost = $this->entityfactory->get_post_from_stdclass(
$privatepost = $this->entityfactory->get_post_from_stdClass(
(object) array_merge((array) $this->postrecord, ['parent' => $post->get_id(), 'privatereplyto' => $otheruser->id])
);
@@ -1084,10 +1080,10 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$discussion = $this->discussion;
$post = $this->post;
$privatepost = $this->entityfactory->get_post_from_stdclass(
$privatepost = $this->entityfactory->get_post_from_stdClass(
(object) array_merge((array) $this->postrecord, ['parent' => $post->get_id(), 'privatereplyto' => $otheruser->id])
);
$privateposttome = $this->entityfactory->get_post_from_stdclass(
$privateposttome = $this->entityfactory->get_post_from_stdClass(
(object) array_merge((array) $this->postrecord, ['parent' => $post->get_id(), 'privatereplyto' => $user->id])
);
@@ -1232,7 +1228,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$forum = $this->create_forum();
$user = $this->user;
$capabilitymanager = $this->managerfactory->get_capability_manager($forum);
$context = context_system::instance();
$context = \context_system::instance();
$roleid = $DB->get_field('role', 'id', ['shortname' => 'user'], MUST_EXIST);
assign_capability('moodle/tag:manage', CAP_PREVENT, $roleid, $context->id, true);
@@ -1275,7 +1271,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
self::getDataGenerator()->enrol_user($user->id, $course->id, $role->id);
// Add a discussion.
$record = new stdClass();
$record = new \stdClass();
$record->course = $course->id;
$record->userid = $user->id;
$record->forum = $forum->id;
@@ -1287,7 +1283,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$post->totalscore = 80;
$DB->update_record('forum_posts', $post);
$vaultfactory = mod_forum\local\container::get_vault_factory();
$vaultfactory = container::get_vault_factory();
$forumvault = $vaultfactory->get_forum_vault();
$discussionvault = $vaultfactory->get_discussion_vault();
$postvault = $vaultfactory->get_post_vault();
@@ -1317,7 +1313,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
self::getDataGenerator()->enrol_user($user->id, $course->id, $role->id);
// Add a discussion.
$record = new stdClass();
$record = new \stdClass();
$record->course = $course->id;
$record->userid = $user->id;
$record->forum = $forum->id;
@@ -1326,7 +1322,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$parentpost = $DB->get_record('forum_posts', array('discussion' => $discussion->id));
// Add a post.
$record = new stdClass();
$record = new \stdClass();
$record->course = $course->id;
$record->userid = $user->id;
$record->forum = $forum->id;
@@ -1334,7 +1330,7 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
$record->parent = $parentpost->id;
$this->getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
$vaultfactory = mod_forum\local\container::get_vault_factory();
$vaultfactory = container::get_vault_factory();
$forumvault = $vaultfactory->get_forum_vault();
$discussionvault = $vaultfactory->get_discussion_vault();
$postvault = $vaultfactory->get_post_vault();
+7 -12
View File
@@ -14,23 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace mod_forum;
use mod_forum\output\forum_post_email;
/**
* The module forums tests
* Tests for the forum output/email class.
*
* @package mod_forum
* @copyright 2016 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Tests for the forum output/email class.
*
* @copyright 2016 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_output_email_testcase extends advanced_testcase {
class output_email_test extends \advanced_testcase {
/**
* Data provider for the postdate function tests.
*/
@@ -174,7 +169,7 @@ class mod_forum_output_email_testcase extends advanced_testcase {
$DB->update_record('forum_posts', $post);
// Create the renderable.
$renderable = new mod_forum\output\forum_post_email(
$renderable = new forum_post_email(
$course,
$cm,
$forum,
+5 -8
View File
@@ -14,13 +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/>.
/**
* Tests for private reply functionality.
*
* @package mod_forum
* @copyright 2019 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum;
use mod_forum_tests_generator_trait;
defined('MOODLE_INTERNAL') || die();
@@ -32,10 +28,11 @@ require_once(__DIR__ . '/generator_trait.php');
/**
* Tests for private reply functionality.
*
* @package mod_forum
* @copyright 2019 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class private_replies extends advanced_testcase {
class private_replies_test extends \advanced_testcase {
use mod_forum_tests_generator_trait;
+6 -8
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/>.
/**
* The forum module mail generation tests for groups.
*
* @package mod_forum
* @copyright 2013 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum;
use mod_forum_tests_cron_trait;
use mod_forum_tests_generator_trait;
defined('MOODLE_INTERNAL') || die();
@@ -32,10 +29,11 @@ require_once(__DIR__ . '/generator_trait.php');
/**
* The forum module mail generation tests for groups.
*
* @package mod_forum
* @copyright 2013 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_qanda_testcase extends advanced_testcase {
class qanda_test extends \advanced_testcase {
// Make use of the cron tester trait.
use mod_forum_tests_cron_trait;
+12 -9
View File
@@ -14,13 +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/>.
/**
* The module forums tests
*
* @package mod_forum
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum;
use mod_forum_tests_generator_trait;
defined('MOODLE_INTERNAL') || die();
@@ -28,7 +24,14 @@ global $CFG;
require_once(__DIR__ . '/generator_trait.php');
require_once("{$CFG->dirroot}/mod/forum/lib.php");
class mod_forum_subscriptions_testcase extends advanced_testcase {
/**
* The module forums tests
*
* @package mod_forum
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class subscriptions_test extends \advanced_testcase {
// Include the mod_forum test helpers.
// This includes functions to create forums, users, discussions, and posts.
use mod_forum_tests_generator_trait;
@@ -843,7 +846,7 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
$this->assertEquals($usercount, count($subscribers));
// Manually insert an extra subscription for one of the users.
$record = new stdClass();
$record = new \stdClass();
$record->userid = $users[2]->id;
$record->forum = $forum->id;
$record->discussion = $discussion->id;
+5 -13
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/>.
/**
* The author vault tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace mod_forum;
/**
* The author vault tests.
@@ -31,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_vaults_author_testcase extends advanced_testcase {
class vaults_author_test extends \advanced_testcase {
/**
* Test get_from_id.
*/
@@ -62,9 +54,9 @@ class mod_forum_vaults_author_testcase extends advanced_testcase {
$fakeuserid = $user3->id + 1000;
$vaultfactory = \mod_forum\local\container::get_vault_factory();
$authorvault = $vaultfactory->get_author_vault();
$user1context = context_user::instance($user1->id);
$user2context = context_user::instance($user2->id);
$user3context = context_user::instance($user3->id);
$user1context = \context_user::instance($user1->id);
$user2context = \context_user::instance($user2->id);
$user3context = \context_user::instance($user3->id);
$user1contextid = $user1context->id;
$user2contextid = $user2context->id;
$user3contextid = $user3context->id;
@@ -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/>.
/**
* The discussion_list vault tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum;
use mod_forum_external;
use mod_forum_tests_generator_trait;
defined('MOODLE_INTERNAL') || die();
@@ -36,7 +33,7 @@ require_once(__DIR__ . '/generator_trait.php');
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_vaults_discussion_list_testcase extends advanced_testcase {
class vaults_discussion_list_test extends \advanced_testcase {
// Make use of the test generator trait.
use mod_forum_tests_generator_trait;
@@ -536,9 +533,9 @@ class mod_forum_vaults_discussion_list_testcase extends advanced_testcase {
/**
* Pin a duscussion.
*
* @param stdClass $discussion
* @param \stdClass $discussion
*/
private function pin_discussion(stdClass $discussion) {
private function pin_discussion(\stdClass $discussion) {
global $DB;
$DB->update_record('forum_discussions',
@@ -548,10 +545,10 @@ class mod_forum_vaults_discussion_list_testcase extends advanced_testcase {
/**
* Star a duscussion.
*
* @param stdClass $discussion
* @param \stdClass $discussion
* @param bool $targetstate The new starred state of the discussion (0 => unstar, 1 => star)
*/
private function star_discussion(stdClass $discussion, bool $targetstate) {
private function star_discussion(\stdClass $discussion, bool $targetstate) {
mod_forum_external::toggle_favourite_state($discussion->id, $targetstate);
}
}
+8 -12
View File
@@ -14,13 +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/>.
/**
* The discussion vault tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum;
use mod_forum_tests_generator_trait;
defined('MOODLE_INTERNAL') || die();
@@ -33,7 +29,7 @@ require_once(__DIR__ . '/generator_trait.php');
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_vaults_discussion_testcase extends advanced_testcase {
class vaults_discussion_test extends \advanced_testcase {
// Make use of the test generator trait.
use mod_forum_tests_generator_trait;
@@ -79,8 +75,8 @@ class mod_forum_vaults_discussion_testcase extends advanced_testcase {
$course = $datagenerator->create_course();
$forum = $datagenerator->create_module('forum', ['course' => $course->id]);
$coursemodule = get_coursemodule_from_instance('forum', $forum->id);
$context = context_module::instance($coursemodule->id);
$forumentity = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course);
$context = \context_module::instance($coursemodule->id);
$forumentity = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course);
$this->assertEquals(null, $vault->get_first_discussion_in_forum($forumentity));
@@ -105,8 +101,8 @@ class mod_forum_vaults_discussion_testcase extends advanced_testcase {
$course = $datagenerator->create_course();
$forum = $datagenerator->create_module('forum', ['course' => $course->id]);
$coursemodule = get_coursemodule_from_instance('forum', $forum->id);
$context = context_module::instance($coursemodule->id);
$forumentity = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course);
$context = \context_module::instance($coursemodule->id);
$forumentity = $entityfactory->get_forum_from_stdClass($forum, $context, $coursemodule, $course);
$this->assertEquals([], $vault->get_all_discussions_in_forum($forumentity));
+4 -8
View File
@@ -14,13 +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/>.
/**
* The forum vault tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum;
use mod_forum_tests_generator_trait;
defined('MOODLE_INTERNAL') || die();
@@ -34,7 +30,7 @@ require_once(__DIR__ . '/generator_trait.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \mod_forum\local\vaults\forum
*/
class mod_forum_vaults_forum_testcase extends advanced_testcase {
class vaults_forum_test extends \advanced_testcase {
// Make use of the test generator trait.
use mod_forum_tests_generator_trait;
+14 -18
View File
@@ -14,13 +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/>.
/**
* The post_attachment vault tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum;
use mod_forum_tests_generator_trait;
defined('MOODLE_INTERNAL') || die();
@@ -33,7 +29,7 @@ require_once(__DIR__ . '/generator_trait.php');
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_vaults_post_attachment_testcase extends advanced_testcase {
class vaults_post_attachment_test extends \advanced_testcase {
// Make use of the test generator trait.
use mod_forum_tests_generator_trait;
@@ -52,7 +48,7 @@ class mod_forum_vaults_post_attachment_testcase extends advanced_testcase {
$course = $datagenerator->create_course();
$forum = $datagenerator->create_module('forum', ['course' => $course->id]);
$coursemodule = get_coursemodule_from_instance('forum', $forum->id);
$context = context_module::instance($coursemodule->id);
$context = \context_module::instance($coursemodule->id);
[$discussion, $post1] = $this->helper_post_to_forum($forum, $user);
$post2 = $this->helper_reply_to_post($post1, $user);
$post3 = $this->helper_reply_to_post($post1, $user);
@@ -79,11 +75,11 @@ class mod_forum_vaults_post_attachment_testcase extends advanced_testcase {
'image contents'
);
$post1 = $entityfactory->get_post_from_stdclass($post1);
$post2 = $entityfactory->get_post_from_stdclass($post2);
$post3 = $entityfactory->get_post_from_stdclass($post3);
$post1 = $entityfactory->get_post_from_stdClass($post1);
$post2 = $entityfactory->get_post_from_stdClass($post2);
$post3 = $entityfactory->get_post_from_stdClass($post3);
$results = $vault->get_attachments_for_posts(context_system::instance(), [$post1, $post2, $post3]);
$results = $vault->get_attachments_for_posts(\context_system::instance(), [$post1, $post2, $post3]);
$this->assertCount(3, $results);
$this->assertEquals([], $results[$post1->get_id()]);
$this->assertEquals([], $results[$post2->get_id()]);
@@ -120,7 +116,7 @@ class mod_forum_vaults_post_attachment_testcase extends advanced_testcase {
$course = $datagenerator->create_course();
$forum = $datagenerator->create_module('forum', ['course' => $course->id]);
$coursemodule = get_coursemodule_from_instance('forum', $forum->id);
$context = context_module::instance($coursemodule->id);
$context = \context_module::instance($coursemodule->id);
[$discussion, $post1] = $this->helper_post_to_forum($forum, $user);
$post2 = $this->helper_reply_to_post($post1, $user);
$post3 = $this->helper_reply_to_post($post1, $user);
@@ -147,11 +143,11 @@ class mod_forum_vaults_post_attachment_testcase extends advanced_testcase {
'image contents'
);
$post1 = $entityfactory->get_post_from_stdclass($post1);
$post2 = $entityfactory->get_post_from_stdclass($post2);
$post3 = $entityfactory->get_post_from_stdclass($post3);
$post1 = $entityfactory->get_post_from_stdClass($post1);
$post2 = $entityfactory->get_post_from_stdClass($post2);
$post3 = $entityfactory->get_post_from_stdClass($post3);
$results = $vault->get_inline_attachments_for_posts(context_system::instance(), [$post1, $post2, $post3]);
$results = $vault->get_inline_attachments_for_posts(\context_system::instance(), [$post1, $post2, $post3]);
$this->assertCount(3, $results);
$this->assertEquals([], $results[$post1->get_id()]);
$this->assertEquals([], $results[$post2->get_id()]);
@@ -14,13 +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/>.
/**
* The post read receipt collection vault tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum;
use mod_forum_tests_generator_trait;
defined('MOODLE_INTERNAL') || die();
@@ -33,7 +29,7 @@ require_once(__DIR__ . '/generator_trait.php');
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_vaults_post_read_receipt_collection_testcase extends advanced_testcase {
class vaults_post_read_receipt_collection_test extends \advanced_testcase {
// Make use of the test generator trait.
use mod_forum_tests_generator_trait;
@@ -82,9 +78,9 @@ class mod_forum_vaults_post_read_receipt_collection_testcase extends advanced_te
'lastread' => time()
]);
$post1 = $entityfactory->get_post_from_stdclass($post1);
$post2 = $entityfactory->get_post_from_stdclass($post2);
$post3 = $entityfactory->get_post_from_stdclass($post3);
$post1 = $entityfactory->get_post_from_stdClass($post1);
$post2 = $entityfactory->get_post_from_stdClass($post2);
$post3 = $entityfactory->get_post_from_stdClass($post3);
$collection = $vault->get_from_user_id_and_post_ids($user->id, [$post1->get_id(), $post2->get_id()]);
// True because there is a read receipt for this user.
+19 -23
View File
@@ -14,13 +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/>.
/**
* The post vault tests.
*
* @package mod_forum
* @copyright 2019 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_forum;
use mod_forum_tests_generator_trait;
defined('MOODLE_INTERNAL') || die();
@@ -34,7 +30,7 @@ require_once(__DIR__ . '/generator_trait.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \mod_forum\local\vaults\post
*/
class mod_forum_vaults_post_testcase extends advanced_testcase {
class vaults_post_test extends \advanced_testcase {
// Make use of the test generator trait.
use mod_forum_tests_generator_trait;
@@ -333,10 +329,10 @@ class mod_forum_vaults_post_testcase extends advanced_testcase {
[$discussion2, $post5] = $this->helper_post_to_forum($forum, $user);
$entityfactory = \mod_forum\local\container::get_entity_factory();
$post1 = $entityfactory->get_post_from_stdclass($post1);
$post2 = $entityfactory->get_post_from_stdclass($post2);
$post3 = $entityfactory->get_post_from_stdclass($post3);
$post4 = $entityfactory->get_post_from_stdclass($post4);
$post1 = $entityfactory->get_post_from_stdClass($post1);
$post2 = $entityfactory->get_post_from_stdClass($post2);
$post3 = $entityfactory->get_post_from_stdClass($post3);
$post4 = $entityfactory->get_post_from_stdClass($post4);
$entities = $this->vault->get_replies_to_post($user, $post1, false);
$this->assertCount(3, $entities);
@@ -393,15 +389,15 @@ class mod_forum_vaults_post_testcase extends advanced_testcase {
$pcaaa = $this->helper_reply_to_post($pcaa, $teacher, ['privatereplyto' => $otherstudent->id]);
$entityfactory = \mod_forum\local\container::get_entity_factory();
$ep = $entityfactory->get_post_from_stdclass($p);
$epa = $entityfactory->get_post_from_stdclass($pa);
$epaa = $entityfactory->get_post_from_stdclass($paa);
$epab = $entityfactory->get_post_from_stdclass($pab);
$epb = $entityfactory->get_post_from_stdclass($pb);
$epc = $entityfactory->get_post_from_stdclass($pc);
$epca = $entityfactory->get_post_from_stdclass($pca);
$epcaa = $entityfactory->get_post_from_stdclass($pcaa);
$epcaaa = $entityfactory->get_post_from_stdclass($pcaaa);
$ep = $entityfactory->get_post_from_stdClass($p);
$epa = $entityfactory->get_post_from_stdClass($pa);
$epaa = $entityfactory->get_post_from_stdClass($paa);
$epab = $entityfactory->get_post_from_stdClass($pab);
$epb = $entityfactory->get_post_from_stdClass($pb);
$epc = $entityfactory->get_post_from_stdClass($pc);
$epca = $entityfactory->get_post_from_stdClass($pca);
$epcaa = $entityfactory->get_post_from_stdClass($pcaa);
$epcaaa = $entityfactory->get_post_from_stdClass($pcaaa);
// As `student`, you should see all public posts, plus all private replies intended for you.
$entities = $this->vault->get_replies_to_post($student, $ep, false);
@@ -1000,7 +996,7 @@ class mod_forum_vaults_post_testcase extends advanced_testcase {
[$discussion1, $post1] = $this->helper_post_to_forum($forum, $user);
$date = new DateTime('2019-07-05');
$date = new \DateTime('2019-07-05');
$post2 = $this->helper_reply_to_post($post1, $user, ['created' => $date->getTimestamp()]);
$post3 = $this->helper_reply_to_post($post1, $user, ['created' => $date->getTimestamp()]);
$date->modify('+1 month');
@@ -1010,7 +1006,7 @@ class mod_forum_vaults_post_testcase extends advanced_testcase {
[$discussion2, $post4] = $this->helper_post_to_forum($forum, $user);
$datefilter = new DateTime('2019-07-01');
$datefilter = new \DateTime('2019-07-01');
$filters = ['from' => $datefilter->getTimestamp()];
$entities = $this->vault->get_from_filters($user, $filters, false);
$this->assertCount(7, $entities);
+3 -10
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/>.
/**
* Concept fetching and caching tests.
*
* @package mod_glossary
* @category test
* @copyright 2014 Petr Skoda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_glossary;
/**
* Concept fetching and caching tests.
@@ -31,7 +24,7 @@
* @copyright 2014 Petr Skoda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_glossary_concept_cache_testcase extends advanced_testcase {
class concept_cache_test extends \advanced_testcase {
/**
* Test convect fetching.
*/
@@ -174,7 +167,7 @@ class mod_glossary_concept_cache_testcase extends advanced_testcase {
$this->assertCount(4, $concepts1[0]);
$this->assertCount(4, $concepts1[1]);
$this->setUser($user);
course_modinfo::clear_instance_cache();
\course_modinfo::clear_instance_cache();
\mod_glossary\local\concept_cache::reset_caches();
$concepts1 = \mod_glossary\local\concept_cache::get_concepts($course1->id);
$this->assertCount(3, $concepts1[0]);
+6 -14
View File
@@ -14,27 +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/>.
namespace mod_lesson;
use mod_lesson\local\numeric\helper;
/**
* Unit tests for page types classes
* This class contains the test cases for the numeric helper functions
*
* @package mod_lesson
* @category test
* @copyright 2020 Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
use mod_lesson\local\numeric\helper;
/**
* This class contains the test cases for the numeric helper functions
*
* @copyright 2020 Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
class mod_lesson_numeric_type_helper_test extends advanced_testcase {
class numeric_helper_test extends \advanced_testcase {
/**
* Test the lesson_unformat_numeric_value function.
*
+7 -11
View File
@@ -14,15 +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/>.
/**
* Unit tests for page types classes
*
* @package mod_lesson
* @category test
* @copyright 2015 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
namespace mod_lesson;
use lesson_page_type_essay;
defined('MOODLE_INTERNAL') || die();
@@ -34,16 +28,18 @@ require_once($CFG->dirroot . '/mod/lesson/pagetypes/essay.php');
/**
* This class contains the test cases for some of the functions in the lesson essay page type class.
*
* @package mod_lesson
* @category test
* @copyright 2015 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
class mod_lesson_essay_page_type_test extends advanced_testcase {
class pagetypes_test extends \advanced_testcase {
public function test_lesson_essay_extract_useranswer() {
// Test that reponseformat is added when not present.
$answer = 'O:8:"stdClass":6:{s:4:"sent";i:1;s:6:"graded";i:1;s:5:"score";s:1:"1";'
. 's:6:"answer";s:64:"<p>This is my answer <b>with bold</b> and <i>italics</i><br></p>";'
. 's:12:"answerformat";s:1:"1";s:8:"response";s:10:"Well done!";}';
$userresponse = new stdClass;
$userresponse = new \stdClass;
$userresponse->sent = 1;
$userresponse->graded = 1;
$userresponse->score = 1;
@@ -57,7 +53,7 @@ class mod_lesson_essay_page_type_test extends advanced_testcase {
$answer = 'O:8:"stdClass":7:{s:4:"sent";i:0;s:6:"graded";i:1;s:5:"score";s:1:"0";'
. 's:6:"answer";s:64:"<p>This is my answer <b>with bold</b> and <i>italics</i><br></p>";'
. 's:12:"answerformat";s:1:"1";s:8:"response";s:10:"Well done!";s:14:"responseformat";s:1:"2";}';
$userresponse = new stdClass;
$userresponse = new \stdClass;
$userresponse->sent = 0;
$userresponse->graded = 1;
$userresponse->score = 0;
@@ -14,21 +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/>.
/**
* Unit tests for mod_lti gradebookservices
* @package ltiservice_gradebookservices
* @category external
* @copyright 2020 Claude Vervoort <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use ltiservice_gradebookservices\local\service\gradebookservices;
namespace ltiservice_gradebookservices;
defined('MOODLE_INTERNAL') || die();
use ltiservice_gradebookservices\local\service\gradebookservices;
/**
* Unit tests for lti gradebookservices.
*
* @package ltiservice_gradebookservices
* @category test
* @copyright 2020 Claude Vervoort <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_lti_gradebookservices_testcase extends advanced_testcase {
class gradebookservices_test extends \advanced_testcase {
/**
* Test saving a graded LTI with resource and tag info (as a result of
@@ -278,15 +276,15 @@ class mod_lti_gradebookservices_testcase extends advanced_testcase {
* Creates a new LTI Tool Type.
*/
private function create_type() {
$type = new stdClass();
$type = new \stdClass();
$type->state = LTI_TOOL_STATE_CONFIGURED;
$type->name = "Test tool";
$type->description = "Example description";
$type->clientid = "Test client ID";
$type->baseurl = $this->getExternalTestFileUrl('/test.html');
$config = new stdClass();
$config = new \stdClass();
$config->ltiservice_gradesynchronization = 2;
return lti_add_type($type, $config);
}
}
}
@@ -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/>.
/**
* Tests cleaning up the gradebook services task.
*
* @package ltiservice_gradebookservices
* @category test
* @copyright 2018 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace ltiservice_gradebookservices\task;
/**
* Tests cleaning up the gradebook services task.
@@ -33,7 +24,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2018 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class ltiservice_gradebookservices_cleanup_task_testcase extends advanced_testcase {
class cleanup_test extends \advanced_testcase {
/**
* Test set up.
@@ -71,7 +62,7 @@ class ltiservice_gradebookservices_cleanup_task_testcase extends advanced_testca
$gradeitem2 = $DB->get_record('grade_items', $conditions);
// Insert these into the 'ltiservice_gradebookservices' table.
$data = new stdClass();
$data = new \stdClass();
$data->gradeitemid = $gradeitem->id;
$data->courseid = $course->id;
$DB->insert_record('ltiservice_gradebookservices', $data);
@@ -79,7 +70,7 @@ class ltiservice_gradebookservices_cleanup_task_testcase extends advanced_testca
$data->gradeitemid = $gradeitem2->id;
$DB->insert_record('ltiservice_gradebookservices', $data);
$task = new \ltiservice_gradebookservices\task\cleanup_task();
$task = new cleanup_task();
$task->execute();
// Check they both still exist.
@@ -89,7 +80,7 @@ class ltiservice_gradebookservices_cleanup_task_testcase extends advanced_testca
course_delete_module($lti->cmid);
// Run the task again.
$task = new \ltiservice_gradebookservices\task\cleanup_task();
$task = new cleanup_task();
$task->execute();
// Check only the second grade item exists.
@@ -116,17 +107,17 @@ class ltiservice_gradebookservices_cleanup_task_testcase extends advanced_testca
'courseid' => $course->id,
'itemtype' => 'manual'
];
$gradeitem = new grade_item($params);
$gradeitem = new \grade_item($params);
$gradeitem->insert();
// Insert it into the 'ltiservice_gradebookservices' table.
$data = new stdClass();
$data = new \stdClass();
$data->gradeitemid = $gradeitem->id;
$data->courseid = $course->id;
$DB->insert_record('ltiservice_gradebookservices', $data);
// Run the task.
$task = new \ltiservice_gradebookservices\task\cleanup_task();
$task = new cleanup_task();
$task->execute();
// Check it still exist.
@@ -136,7 +127,7 @@ class ltiservice_gradebookservices_cleanup_task_testcase extends advanced_testca
$gradeitem->delete();
// Run the task again.
$task = new \ltiservice_gradebookservices\task\cleanup_task();
$task = new cleanup_task();
$task->execute();
// Check it has been removed.
@@ -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/>.
/**
* Unknown service API called event tests
*
* @package mod_lti
* @copyright Copyright (c) 2012 Moodlerooms Inc. (http://www.moodlerooms.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
use mod_lti\event\unknown_service_api_called;
namespace mod_lti\event;
/**
* Unknown service API called event tests
@@ -33,7 +23,7 @@ use mod_lti\event\unknown_service_api_called;
* @copyright Copyright (c) 2012 Moodlerooms Inc. (http://www.moodlerooms.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_lti_event_unknown_service_api_called_test extends advanced_testcase {
class unknown_service_api_called_test extends \advanced_testcase {
/*
* Ensure create event works.
*/
@@ -47,7 +37,7 @@ class mod_lti_event_unknown_service_api_called_test extends advanced_testcase {
*/
public function test_event_context() {
$event = unknown_service_api_called::create();
$this->assertEquals(context_system::instance(), $event->get_context());
$this->assertEquals(\context_system::instance(), $event->get_context());
}
/*
@@ -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 mod_lti\external;
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -28,7 +30,7 @@ require_once($CFG->dirroot . '/mod/lti/tests/mod_lti_testcase.php');
* @copyright 2021 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_lti_get_tool_types_and_proxies_count_testcase extends mod_lti_testcase {
class get_tool_types_and_proxies_count_test extends \mod_lti_testcase {
/**
* This method runs before every test.
@@ -48,7 +50,7 @@ class mod_lti_get_tool_types_and_proxies_count_testcase extends mod_lti_testcase
}
$data = \mod_lti\external\get_tool_types_and_proxies_count::execute(0, false);
$data = external_api::clean_returnvalue(\mod_lti\external\get_tool_types_and_proxies_count::execute_returns(), $data);
$data = \external_api::clean_returnvalue(\mod_lti\external\get_tool_types_and_proxies_count::execute_returns(), $data);
$this->assertEquals(20, $data['count']);
}
@@ -58,7 +60,7 @@ class mod_lti_get_tool_types_and_proxies_count_testcase extends mod_lti_testcase
*/
public function test_mod_lti_get_tool_types_and_proxies_count_with_no_tools_configured() {
$data = \mod_lti\external\get_tool_types_and_proxies_count::execute(0, false);
$data = external_api::clean_returnvalue(\mod_lti\external\get_tool_types_and_proxies_count::execute_returns(), $data);
$data = \external_api::clean_returnvalue(\mod_lti\external\get_tool_types_and_proxies_count::execute_returns(), $data);
$this->assertEquals(0, $data['count']);
}
+6 -6
View File
@@ -14,7 +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/>.
use mod_lti\external\get_tool_types_and_proxies;
namespace mod_lti\external;
defined('MOODLE_INTERNAL') || die();
@@ -30,7 +30,7 @@ require_once($CFG->dirroot . '/mod/lti/tests/mod_lti_testcase.php');
* @copyright 2021 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_lti_get_tool_types_and_proxies_testcase extends mod_lti_testcase {
class get_tool_types_and_proxies_test extends \mod_lti_testcase {
/**
* This method runs before every test.
@@ -48,7 +48,7 @@ class mod_lti_get_tool_types_and_proxies_testcase extends mod_lti_testcase {
$this->generate_tool_type(1, $proxy->id);
$data = get_tool_types_and_proxies::execute(0, false, 50, 0);
$data = external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$data = \external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$this->assertCount(1, $data['types']);
$type = $data['types'][0];
@@ -71,7 +71,7 @@ class mod_lti_get_tool_types_and_proxies_testcase extends mod_lti_testcase {
}
$data = get_tool_types_and_proxies::execute(0, false, 5, 0);
$data = external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$data = \external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$this->assertCount(2, $data['types']);
$this->assertCount(3, $data['proxies']);
@@ -89,7 +89,7 @@ class mod_lti_get_tool_types_and_proxies_testcase extends mod_lti_testcase {
}
$data = get_tool_types_and_proxies::execute(0, false, 5, 10);
$data = external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$data = \external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$this->assertCount(2, $data['types']);
$this->assertCount(0, $data['proxies']);
@@ -107,7 +107,7 @@ class mod_lti_get_tool_types_and_proxies_testcase extends mod_lti_testcase {
}
$data = get_tool_types_and_proxies::execute(0, false, 0, 0);
$data = external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$data = \external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$this->assertCount(10, $data['types']);
$this->assertCount(10, $data['proxies']);
@@ -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/>.
/**
* Tests Exception handler for LTI services
*
* @package mod_lti
* @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use mod_lti\service_exception_handler;
defined('MOODLE_INTERNAL') || die();
namespace mod_lti;
/**
* Tests Exception handler for LTI services
@@ -33,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_lti_service_exception_handler_testcase extends advanced_testcase {
class service_exception_handler_test extends \advanced_testcase {
/**
* Testing service error handling.
*/
@@ -41,7 +31,7 @@ class mod_lti_service_exception_handler_testcase extends advanced_testcase {
$handler = new service_exception_handler(false);
$handler->set_message_id('123');
$handler->set_message_type('testRequest');
$handler->handle(new Exception('Error happened'));
$handler->handle(new \Exception('Error happened'));
$this->expectOutputRegex('/imsx_codeMajor>failure/');
$this->expectOutputRegex('/imsx_description>Error happened/');
@@ -55,7 +45,7 @@ class mod_lti_service_exception_handler_testcase extends advanced_testcase {
*/
public function test_handle_early_error() {
$handler = new service_exception_handler(false);
$handler->handle(new Exception('Error happened'));
$handler->handle(new \Exception('Error happened'));
$this->expectOutputRegex('/imsx_codeMajor>failure/');
$this->expectOutputRegex('/imsx_description>Error happened/');
@@ -75,11 +65,11 @@ class mod_lti_service_exception_handler_testcase extends advanced_testcase {
$handler = new service_exception_handler(true);
ob_start();
$handler->handle(new Exception('Error happened'));
$handler->handle(new \Exception('Error happened'));
ob_end_clean();
$this->assertTrue(is_dir($CFG->dataroot.'/temp/mod_lti'));
$files = glob($CFG->dataroot.'/temp/mod_lti/mod*');
$this->assertEquals(1, count($files));
}
}
}
+3 -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/>.
/**
* Tests for servicelib.php
*
* @package mod_lti
* @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_lti;
defined('MOODLE_INTERNAL') || die();
@@ -35,7 +29,7 @@ require_once($CFG->dirroot.'/mod/lti/servicelib.php');
* @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_lti_servicelib_testcase extends basic_testcase {
class servicelib_test extends \basic_testcase {
/**
* Test that lti_parse_message_id never fails with good and bad XML.
*
@@ -112,4 +106,4 @@ XML;
array('', $noidentifier),
);
}
}
}
@@ -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/>.
/**
* Tests cleaning up the access tokens task.
*
* @package mod_lti
* @category test
* @copyright 2019 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace mod_lti\task;
/**
* Tests cleaning up the access tokens task.
@@ -33,7 +24,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2019 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_lti_clean_access_tokens_testcase extends advanced_testcase {
class clean_access_tokens_test extends \advanced_testcase {
/**
* Test set up.
@@ -53,7 +44,7 @@ class mod_lti_clean_access_tokens_testcase extends advanced_testcase {
$time = time();
// Create an expired access token.
$token = new stdClass();
$token = new \stdClass();
$token->typeid = 1;
$token->scope = 'scope';
$token->token = 'token';
@@ -69,7 +60,7 @@ class mod_lti_clean_access_tokens_testcase extends advanced_testcase {
$t2id = $DB->insert_record('lti_access_tokens', $token);
// Run the task.
$task = new \mod_lti\task\clean_access_tokens();
$task = new clean_access_tokens();
$task->execute();
// Check there is only one token now.
+11 -11
View File
@@ -14,23 +14,23 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') || die;
namespace mod_scorm;
/*
* Unit tests for scorm_formatduration function from locallib.php
*
* @package mod_scorm
* @category phpunit
* @copyright 2009 Dan Marsden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
// Make sure the code being tested is accessible.
global $CFG;
require_once($CFG->dirroot . '/mod/scorm/locallib.php'); // Include the code to test.
class mod_scorm_formatduration_testcase extends basic_testcase {
/**
* Unit tests for scorm_formatduration function from locallib.php
*
* @package mod_scorm
* @category test
* @copyright 2009 Dan Marsden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class formatduration_test extends \basic_testcase {
public function test_scorm2004_format() {
$stryears = get_string('years');
$strmonths = trim(get_string('nummonths'));
+9 -16
View File
@@ -14,29 +14,22 @@
// 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 mod_quiz_display_options class.
*
* @package mod_scorm
* @category phpunit
* @copyright 2013 Dan Marsden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_scorm;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/scorm/locallib.php');
/**
* Unit tests for {@link mod_scorm}.
*
* @package mod_scorm
* @category test
* @copyright 2013 Dan Marsden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_scorm_validatepackage_testcase extends advanced_testcase {
class validatepackage_test extends \advanced_testcase {
/**
* Convenience to take a fixture test file and create a stored_file.
@@ -45,7 +38,7 @@ class mod_scorm_validatepackage_testcase extends advanced_testcase {
* @return stored_file
*/
protected function create_stored_file_from_path($filepath) {
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
$filerecord = array(
'contextid' => $syscontext->id,
'component' => 'mod_scorm',
@@ -66,17 +59,17 @@ class mod_scorm_validatepackage_testcase extends advanced_testcase {
$this->resetAfterTest(true);
$filename = "validscorm.zip";
$file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, file_archive::OPEN);
$file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, \file_archive::OPEN);
$errors = scorm_validate_package($file);
$this->assertEmpty($errors);
$filename = "validaicc.zip";
$file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, file_archive::OPEN);
$file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, \file_archive::OPEN);
$errors = scorm_validate_package($file);
$this->assertEmpty($errors);
$filename = "invalid.zip";
$file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, file_archive::OPEN);
$file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, \file_archive::OPEN);
$errors = scorm_validate_package($file);
$this->assertArrayHasKey('packagefile', $errors);
if (isset($errors['packagefile'])) {
@@ -84,7 +77,7 @@ class mod_scorm_validatepackage_testcase extends advanced_testcase {
}
$filename = "badscorm.zip";
$file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, file_archive::OPEN);
$file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, \file_archive::OPEN);
$errors = scorm_validate_package($file);
$this->assertArrayHasKey('packagefile', $errors);
if (isset($errors['packagefile'])) {
+13 -11
View File
@@ -8,17 +8,26 @@
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
namespace mod_wiki;
use wiki_parser_proxy;
defined('MOODLE_INTERNAL') || die;
global $CFG;
require_once($CFG->dirroot . '/mod/wiki/parser/parser.php');
/**
* Unit tests for the wiki parser
*
* @package mod_wiki
* @category phpunit
* @category test
* @copyright 2009 Marc Alier, Jordi Piguillem [email protected]
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
*
@@ -30,14 +39,7 @@
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
global $CFG;
require_once($CFG->dirroot . '/mod/wiki/parser/parser.php');
class mod_wiki_wikiparser_test extends basic_testcase {
class wikiparser_test extends \basic_testcase {
/**
* URL inside the clickable text of some link should not be turned into a new link via the url_tag_rule.
@@ -18,11 +18,16 @@
* Unit tests for Random allocation
*
* @package workshopallocation_random
* @category phpunit
* @category test
* @copyright 2009 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace workshopallocation_random;
use workshop;
use workshop_random_allocator;
defined('MOODLE_INTERNAL') || die();
// Include the code to test
@@ -30,8 +35,15 @@ global $CFG;
require_once($CFG->dirroot . '/mod/workshop/locallib.php');
require_once($CFG->dirroot . '/mod/workshop/allocation/random/lib.php');
class workshopallocation_random_testcase extends advanced_testcase {
/**
* Unit tests for Random allocation
*
* @package workshopallocation_random
* @category test
* @copyright 2009 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class allocator_test extends \advanced_testcase {
/** workshop instance emulation */
protected $workshop;
@@ -63,8 +75,8 @@ class workshopallocation_random_testcase extends advanced_testcase {
public function test_self_allocation_equal_user_groups() {
// fixture setup
$authors = array(0 => array_fill_keys(array(4, 6, 10), new stdclass()));
$reviewers = array(0 => array_fill_keys(array(4, 6, 10), new stdclass()));
$authors = array(0 => array_fill_keys(array(4, 6, 10), new \stdClass()));
$reviewers = array(0 => array_fill_keys(array(4, 6, 10), new \stdClass()));
// exercise SUT
$newallocations = $this->allocator->self_allocation($authors, $reviewers);
// verify
@@ -73,8 +85,8 @@ class workshopallocation_random_testcase extends advanced_testcase {
public function test_self_allocation_different_user_groups() {
// fixture setup
$authors = array(0 => array_fill_keys(array(1, 4, 5, 10, 13), new stdclass()));
$reviewers = array(0 => array_fill_keys(array(4, 7, 10), new stdclass()));
$authors = array(0 => array_fill_keys(array(1, 4, 5, 10, 13), new \stdClass()));
$reviewers = array(0 => array_fill_keys(array(4, 7, 10), new \stdClass()));
// exercise SUT
$newallocations = $this->allocator->self_allocation($authors, $reviewers);
// verify
@@ -83,8 +95,8 @@ class workshopallocation_random_testcase extends advanced_testcase {
public function test_self_allocation_skip_existing() {
// fixture setup
$authors = array(0 => array_fill_keys(array(3, 4, 10), new stdclass()));
$reviewers = array(0 => array_fill_keys(array(3, 4, 10), new stdclass()));
$authors = array(0 => array_fill_keys(array(3, 4, 10), new \stdClass()));
$reviewers = array(0 => array_fill_keys(array(3, 4, 10), new \stdClass()));
$assessments = array(23 => (object)array('authorid' => 3, 'reviewerid' => 3));
// exercise SUT
$newallocations = $this->allocator->self_allocation($authors, $reviewers, $assessments);
@@ -121,7 +133,7 @@ class workshopallocation_random_testcase extends advanced_testcase {
87 => (object)array('id' => 121, 'authorid' => 3),
);
// exercise SUT
$this->expectException(moodle_exception::class);
$this->expectException(\moodle_exception::class);
$submissions = $this->allocator->index_submissions_by_authors($submissions);
}
@@ -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/>.
/**
* Provides the {@link mod_workshop_cron_task_testcase} class.
*
* @package mod_workshop
* @category test
* @copyright 2019 David Mudrák <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_workshop\task;
use workshop;
defined('MOODLE_INTERNAL') || die();
@@ -32,10 +27,12 @@ require_once($CFG->dirroot.'/mod/workshop/lib.php');
/**
* Test the functionality provided by the {@link mod_workshop\task\cron_task} scheduled task.
*
* @package mod_workshop
* @category test
* @copyright 2019 David Mudrák <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_workshop_cron_task_testcase extends advanced_testcase {
class cron_task_test extends \advanced_testcase {
/**
* Test that the phase is automatically switched after the submissions deadline.
+6 -11
View File
@@ -14,30 +14,25 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Collection unit tests.
*
* @package core_privacy
* @category test
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_privacy;
defined('MOODLE_INTERNAL') || die();
global $CFG;
use \core_privacy\local\metadata\collection;
use \core_privacy\local\metadata\types;
use core_privacy\local\metadata\collection;
use core_privacy\local\metadata\types;
/**
* Tests for the \core_privacy API's collection functionality.
*
* @package core_privacy
* @category test
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\metadata\collection
*/
class core_privacy_metadata_collection extends advanced_testcase {
class collection_test extends \advanced_testcase {
/**
* Test that adding an unknown type causes the type to be added to the collection.
+11 -7
View File
@@ -15,31 +15,35 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for the privacy legacy polyfill.
* Unit tests for the Privacy API's legacy_polyfill.
*
* @package core_privacy
* @category test
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\legacy_polyfill
*/
namespace core_privacy;
use core_privacy\local\metadata\collection;
use core_privacy\local\request\contextlist;
use core_privacy\local\request\approved_contextlist;
defined('MOODLE_INTERNAL') || die();
global $CFG;
use \core_privacy\local\metadata\collection;
use \core_privacy\local\request\contextlist;
use \core_privacy\local\request\approved_contextlist;
/**
* Tests for the \core_privacy API's types\user_preference functionality.
* Unit tests for the Privacy API's legacy_polyfill.
*
* @package core_privacy
* @category test
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\legacy_polyfill
*/
class core_privacy_legacy_polyfill_test extends advanced_testcase {
class legacy_polyfill_test extends \advanced_testcase {
/**
* Test that the null_provider polyfill works and that the static _get_reason can be
* successfully called.
+6 -11
View File
@@ -14,29 +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/>.
/**
* Type unit tests for the Database Table.
*
* @package core_privacy
* @category test
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_privacy;
use core_privacy\local\metadata\types\database_table;
defined('MOODLE_INTERNAL') || die();
global $CFG;
use \core_privacy\local\metadata\types\database_table;
/**
* Tests for the \core_privacy API's types\database_table functionality.
*
* @package core_privacy
* @category test
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\metadata\types\database_table
*/
class core_privacy_metadata_types_database_table extends advanced_testcase {
class types_database_table_test extends \advanced_testcase {
/**
* Ensure that warnings are thrown if string identifiers contain invalid characters.
+5 -10
View File
@@ -14,29 +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/>.
/**
* Type unit tests for the External Location.
*
* @package core_privacy
* @category test
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_privacy;
defined('MOODLE_INTERNAL') || die();
global $CFG;
use \core_privacy\local\metadata\types\external_location;
use core_privacy\local\metadata\types\external_location;
/**
* Tests for the \core_privacy API's types\external_location functionality.
*
* @package core_privacy
* @category test
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\metadata\types\external_location
*/
class core_privacy_metadata_types_external_location extends advanced_testcase {
class types_external_location_test extends \advanced_testcase {
/**
* Ensure that warnings are thrown if string identifiers contain invalid characters.
+6 -15
View File
@@ -14,29 +14,20 @@
// 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_privacy;
use core_privacy\local\metadata\types\plugintype_link;
/**
* Types unit tests for the Plugintype Link.
* Tests for the \core_privacy API's types\plugintype_link functionality.
*
* @package core_privacy
* @category test
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
use \core_privacy\local\metadata\types\plugintype_link;
/**
* Tests for the \core_privacy API's types\plugintype_link functionality.
*
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\metadata\types\plugintype_link
*/
class core_privacy_metadata_types_plugintype_link extends advanced_testcase {
class types_plugintype_link_test extends \advanced_testcase {
/**
* Ensure that warnings are thrown if string identifiers contain invalid characters.
+6 -15
View File
@@ -14,29 +14,20 @@
// 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_privacy;
use core_privacy\local\metadata\types\subsystem_link;
/**
* Types unit tests for the Subsystem Link.
* Tests for the \core_privacy API's types\subsystem_link functionality.
*
* @package core_privacy
* @category test
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
use \core_privacy\local\metadata\types\subsystem_link;
/**
* Tests for the \core_privacy API's types\subsystem_link functionality.
*
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\metadata\types\subsystem_link
*/
class core_privacy_metadata_types_subsystem_link extends advanced_testcase {
class types_subsystem_link_test extends \advanced_testcase {
/**
* Ensure that warnings are thrown if string identifiers contain invalid characters.
+6 -15
View File
@@ -14,29 +14,20 @@
// 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_privacy;
use core_privacy\local\metadata\types\user_preference;
/**
* Types unit tests for the Subsystem Link.
* Tests for the \core_privacy API's types\user_preference functionality.
*
* @package core_privacy
* @category test
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
use \core_privacy\local\metadata\types\user_preference;
/**
* Tests for the \core_privacy API's types\user_preference functionality.
*
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\metadata\types\user_preference
*/
class core_privacy_metadata_types_user_preference extends advanced_testcase {
class types_user_preference_test extends \advanced_testcase {
/**
* Ensure that warnings are thrown if string identifiers contain invalid characters.
+18 -9
View File
@@ -17,12 +17,16 @@
/**
* Unit tests for rating/lib.php
*
* @package core_ratings
* @category phpunit
* @package core_rating
* @category test
* @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_rating;
use rating_manager;
defined('MOODLE_INTERNAL') || die();
// Include all the needed stuff.
@@ -32,8 +36,13 @@ require_once($CFG->dirroot . '/rating/lib.php');
/**
* Unit test case for all the rating/lib.php requiring DB mockup & manipulation
*
* @package core_rating
* @category test
* @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_rating_testcase extends advanced_testcase {
class rating_test extends \advanced_testcase {
protected $syscontext;
protected $neededcaps = array('view', 'viewall', 'viewany', 'rate');
@@ -55,7 +64,7 @@ class core_rating_testcase extends advanced_testcase {
global $DB;
// We load 3 items. Each is rated twice. For simplicity itemid == user id of the item owner.
$ctxid = context_system::instance()->id;
$ctxid = \context_system::instance()->id;
$ratings = array(
// User 1's items. Average == 2.
array('contextid' => $ctxid,
@@ -136,7 +145,7 @@ class core_rating_testcase extends advanced_testcase {
// Prepare the default options.
$defaultoptions = array (
'context' => context_system::instance(),
'context' => \context_system::instance(),
'component' => 'mod_forum',
'ratingarea' => 'post',
'scaleid' => 10,
@@ -345,7 +354,7 @@ class core_rating_testcase extends advanced_testcase {
* @dataProvider get_aggregate_string_provider
*/
public function test_get_aggregate_string($method, $aggregate, $isnumeric, $scaleitems, $expectation) {
$options = new stdClass();
$options = new \stdClass();
$options->aggregate = $aggregate;
$options->context = null;
$options->component = null;
@@ -354,13 +363,13 @@ class core_rating_testcase extends advanced_testcase {
$options->scaleid = null;
$options->userid = null;
$options->settings = new stdClass();
$options->settings = new \stdClass();
$options->settings->aggregationmethod = $method;
$options->settings->scale = new stdClass();
$options->settings->scale = new \stdClass();
$options->settings->scale->isnumeric = $isnumeric;
$options->settings->scale->scaleitems = $scaleitems;
$rating = new rating($options);
$rating = new \rating($options);
$this->assertEquals($expectation, $rating->get_aggregate_string());
}
}
@@ -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/>.
/**
* Content bank repository browser unit tests.
*
* @package repository_contentbank
* @copyright 2020 Mihail Geshoski <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace repository_contentbank;
defined('MOODLE_INTERNAL') || die();
@@ -35,7 +29,7 @@ require_once("$CFG->dirroot/repository/lib.php");
* @copyright 2020 Mihail Geshoski <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class repository_contentbank_browser_testcase extends advanced_testcase {
class browser_test extends \advanced_testcase {
/**
* Test get_content() in the system context with users that have capability to access/view content bank content
@@ -14,15 +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/>.
/**
* This file contains tests for the repository_nextcloud class.
*
* @package repository_nextcloud
* @copyright 2017 Project seminar (Learnweb, University of Münster)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace repository_nextcloud;
use core\oauth2\system_account;
use testable_access_controlled_link_manager;
defined('MOODLE_INTERNAL') || die();
@@ -32,11 +26,13 @@ require_once($CFG->dirroot . '/repository/nextcloud/tests/fixtures/testable_acce
/**
* Class repository_nextcloud_testcase
*
* @package repository_nextcloud
* @group repository_nextcloud
* @copyright 2017 Project seminar (Learnweb, University of Münster)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class repository_nextcloud_access_controlled_link_manager_testcase extends advanced_testcase {
class access_controlled_link_manager_test extends \advanced_testcase {
/** @var null|testable_access_controlled_link_manager a malleable variant of the access_controlled_link_manager. */
public $linkmanager = null;
@@ -64,24 +60,24 @@ class repository_nextcloud_access_controlled_link_manager_testcase extends advan
$generator->test_create_endpoints($this->issuer->get('id'));
// Mock clients.
$this->ocsmockclient = $this->getMockBuilder(repository_nextcloud\ocs_client::class
$this->ocsmockclient = $this->getMockBuilder(ocs_client::class
)->disableOriginalConstructor()->disableOriginalClone()->getMock();
$this->oauthsystemmock = $this->getMockBuilder(\core\oauth2\client::class
)->disableOriginalConstructor()->disableOriginalClone()->getMock();
$systemwebdavclient = $this->getMockBuilder(\webdav_client::class
)->disableOriginalConstructor()->disableOriginalClone()->getMock();
$systemocsclient = $systemocsclient = $this->getMockBuilder(repository_nextcloud\ocs_client::class
$systemocsclient = $systemocsclient = $this->getMockBuilder(ocs_client::class
)->disableOriginalConstructor()->disableOriginalClone()->getMock();
// Pseudo system account user.
$this->systemaccountusername = 'pseudouser';
$record = new stdClass();
$record = new \stdClass();
$record->issuerid = $this->issuer->get('id');
$record->refreshtoken = 'pseudotoken';
$record->grantedscopes = 'scopes';
$record->email = '';
$record->username = $this->systemaccountusername;
$systemaccount = new system_account(0, $record);
$systemaccount = new \core\oauth2\system_account(0, $record);
$systemaccount->create();
$this->linkmanager = new testable_access_controlled_link_manager($this->ocsmockclient,
@@ -220,7 +216,7 @@ XML;
*/
protected function set_up_mocks_for_create_folder_path($returnisdir, $returnestedcontext, $callmkcol = false,
$returnmkcol = 201) {
$mockcontext = $this->createMock(context_module::class);
$mockcontext = $this->createMock(\context_module::class);
$mockclient = $this->getMockBuilder(\webdav_client::class
)->disableOriginalConstructor()->disableOriginalClone()->getMock();
$parsedwebdavurl = parse_url($this->issuer->get_endpoint_url('webdav'));
@@ -345,7 +341,7 @@ XML;
'path' => '/Kernsystem/Kursbereich Miscellaneous/Kurs Example Course/Datei zet/mod_resource/content/0/picture.png',
'reshares' => true
];
$reference = new stdClass();
$reference = new \stdClass();
$reference->link = "/Kernsystem/Kursbereich Miscellaneous/Kurs Example Course/Datei zet/mod_resource/content/0/picture.png";
$reference->name = "f\u00fcrdennis.png";
$reference->usesystem = true;
@@ -435,7 +431,7 @@ XML;
*/
public function test_create_system_dav() {
// Initialize mock and params.
$fakeaccesstoken = new stdClass();
$fakeaccesstoken = new \stdClass();
$fakeaccesstoken->token = "fake access token";
// Use `atLeastOnce` instead of `exactly(2)` because it is only called a second time on dev systems that allow http://.
$this->oauthsystemmock->expects($this->atLeastOnce())->method('get_accesstoken')->willReturn($fakeaccesstoken);
@@ -453,7 +449,7 @@ XML;
$this->delete_endpoints('webdav_endpoint');
// Creates a new one which requires different ports.
try {
$endpoint = new stdClass();
$endpoint = new \stdClass();
$endpoint->name = "webdav_endpoint";
$endpoint->url = 'http://www.default.test/webdav/index.php';
$endpoint->issuerid = $this->issuer->get('id');
@@ -587,7 +583,7 @@ XML;
* @return ReflectionProperty the resulting reflection property.
*/
protected function set_private_property($value, $propertyname, $class) {
$refclient = new ReflectionClass($class);
$refclient = new \ReflectionClass($class);
$private = $refclient->getProperty($propertyname);
$private->setAccessible(true);
$private->setValue($class, $value);
@@ -601,7 +597,7 @@ XML;
* @return mixed the resulting value.
*/
protected function get_private_property($propertyname, $class) {
$refclient = new ReflectionClass($class);
$refclient = new \ReflectionClass($class);
$private = $refclient->getProperty($propertyname);
$private->setAccessible(true);
$property = $private->getValue($private);
@@ -626,7 +622,7 @@ XML;
return;
}
foreach ($arrayofids as $id) {
core\oauth2\api::delete_endpoint($id);
\core\oauth2\api::delete_endpoint($id);
}
}
+5 -11
View File
@@ -14,23 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains tests for the repository_nextcloud class.
*
* @package repository_nextcloud
* @copyright 2017 Jan Dageförde (Learnweb, University of Münster)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace repository_nextcloud;
/**
* Class repository_nextcloud_ocs_testcase
*
* @package repository_nextcloud
* @group repository_nextcloud
* @copyright 2017 Jan Dageförde (Learnweb, University of Münster)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class repository_nextcloud_ocs_testcase extends advanced_testcase {
class ocs_test extends \advanced_testcase {
/**
* @var \core\oauth2\issuer
@@ -58,7 +52,7 @@ class repository_nextcloud_ocs_testcase extends advanced_testcase {
$mock = $this->createMock(\core\oauth2\client::class);
$mock->expects($this->once())->method('get_issuer')->willReturn($this->issuer);
$client = new \repository_nextcloud\ocs_client($mock);
$client = new ocs_client($mock);
$functions = $client->get_api_functions();
// Assert that relevant (and used) functions are actually present.
+44 -39
View File
@@ -14,21 +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/>.
/**
* Repository API unit tests
*
* @package repository
* @category phpunit
* @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_repository;
use repository;
use repository_exception;
use repository_type;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once("$CFG->dirroot/repository/lib.php");
class core_repositorylib_testcase extends advanced_testcase {
/**
* Repository API unit tests
*
* @package core_repository
* @category test
* @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class repositorylib_test extends \advanced_testcase {
/**
* Installing repository tests
@@ -40,7 +45,7 @@ class core_repositorylib_testcase extends advanced_testcase {
$this->resetAfterTest(true);
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
$repositorypluginname = 'dropbox';
// override repository permission
$capability = 'repository/' . $repositorypluginname . ':view';
@@ -68,7 +73,7 @@ class core_repositorylib_testcase extends advanced_testcase {
$fs = get_file_storage();
$draftitemid = null;
$context = context_user::instance($USER->id);
$context = \context_user::instance($USER->id);
file_prepare_draft_area($draftitemid, $context->id, 'phpunit', 'test_get_unused_filename', 1);
$dummy = array(
@@ -122,7 +127,7 @@ class core_repositorylib_testcase extends advanced_testcase {
$fs = get_file_storage();
$draftitemid = file_get_unused_draft_itemid();
$context = context_user::instance($USER->id);
$context = \context_user::instance($USER->id);
$dummy = array(
'contextid' => $context->id,
@@ -163,7 +168,7 @@ class core_repositorylib_testcase extends advanced_testcase {
$fs = get_file_storage();
$draftitemid = file_get_unused_draft_itemid();
$context = context_user::instance($USER->id);
$context = \context_user::instance($USER->id);
$dummy = [
'contextid' => $context->id,
@@ -211,9 +216,9 @@ class core_repositorylib_testcase extends advanced_testcase {
public function test_can_be_edited_by_user() {
$this->resetAfterTest(true);
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
$course = $this->getDataGenerator()->create_course();
$coursecontext = context_course::instance($course->id);
$coursecontext = \context_course::instance($course->id);
$roleid = create_role('A role', 'arole', 'A role', '');
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
@@ -268,7 +273,7 @@ class core_repositorylib_testcase extends advanced_testcase {
// Instance on a user level.
$otheruser = $this->getDataGenerator()->create_user();
$otherusercontext = context_user::instance($otheruser->id);
$otherusercontext = \context_user::instance($otheruser->id);
role_assign($roleid, $user->id, $syscontext->id);
assign_capability('repository/flickr_public:view', CAP_ALLOW, $roleid, $syscontext, true);
accesslib_clear_all_caches_for_unit_testing();
@@ -280,7 +285,7 @@ class core_repositorylib_testcase extends advanced_testcase {
$this->assertFalse($userrepo->can_be_edited_by_user());
// Editing my own instance.
$usercontext = context_user::instance($user->id);
$usercontext = \context_user::instance($user->id);
$record = array('contextid' => $usercontext->id);
$repoid = $this->getDataGenerator()->create_repository('flickr_public', $record)->id;
$userrepo = repository::get_repository_by_id($repoid, $syscontext);
@@ -291,32 +296,32 @@ class core_repositorylib_testcase extends advanced_testcase {
public function test_check_capability() {
$this->resetAfterTest(true);
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
$course1 = $this->getDataGenerator()->create_course();
$course1context = context_course::instance($course1->id);
$course1context = \context_course::instance($course1->id);
$course2 = $this->getDataGenerator()->create_course();
$course2context = context_course::instance($course2->id);
$course2context = \context_course::instance($course2->id);
$forumdata = new stdClass();
$forumdata = new \stdClass();
$forumdata->course = $course1->id;
$forumc1 = $this->getDataGenerator()->create_module('forum', $forumdata);
$forumc1context = context_module::instance($forumc1->cmid);
$forumc1context = \context_module::instance($forumc1->cmid);
$forumdata->course = $course2->id;
$forumc2 = $this->getDataGenerator()->create_module('forum', $forumdata);
$forumc2context = context_module::instance($forumc2->cmid);
$forumc2context = \context_module::instance($forumc2->cmid);
$blockdata = new stdClass();
$blockdata = new \stdClass();
$blockdata->parentcontextid = $course1context->id;
$blockc1 = $this->getDataGenerator()->create_block('online_users', $blockdata);
$blockc1context = context_block::instance($blockc1->id);
$blockc1context = \context_block::instance($blockc1->id);
$blockdata->parentcontextid = $course2context->id;
$blockc2 = $this->getDataGenerator()->create_block('online_users', $blockdata);
$blockc2context = context_block::instance($blockc2->id);
$blockc2context = \context_block::instance($blockc2->id);
$user1 = $this->getDataGenerator()->create_user();
$user1context = context_user::instance($user1->id);
$user1context = \context_user::instance($user1->id);
$user2 = $this->getDataGenerator()->create_user();
$user2context = context_user::instance($user2->id);
$user2context = \context_user::instance($user2->id);
// New role prohibiting Flickr Public access.
$roleid = create_role('No Flickr Public', 'noflickrpublic', 'No Flickr Public', '');
@@ -349,7 +354,7 @@ class core_repositorylib_testcase extends advanced_testcase {
$this->assertTrue($caughtexception);
// Instance on a course level.
$record = new stdClass();
$record = new \stdClass();
$record->contextid = $course1context->id;
$courserepoid = $this->getDataGenerator()->create_repository('flickr_public', $record)->id;
@@ -438,7 +443,7 @@ class core_repositorylib_testcase extends advanced_testcase {
// Instance on a user level.
// Instance on a course level.
$record = new stdClass();
$record = new \stdClass();
$record->contextid = $user1context->id;
$user1repoid = $this->getDataGenerator()->create_repository('flickr_public', $record)->id;
$record->contextid = $user2context->id;
@@ -478,7 +483,7 @@ class core_repositorylib_testcase extends advanced_testcase {
accesslib_clear_all_caches_for_unit_testing();
// Check that a user can view SOME repositories when logged in as someone else.
$params = new stdClass();
$params = new \stdClass();
$params->name = 'Dropbox';
$params->dropbox_issuerid = '2';
$privaterepoid = $this->getDataGenerator()->create_repository('dropbox')->id;
@@ -522,8 +527,8 @@ class core_repositorylib_testcase extends advanced_testcase {
$user = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->create_repository_type('flickr_public');
$this->getDataGenerator()->create_repository_type('filesystem');
$coursecontext = context_course::instance($course->id);
$usercontext = context_user::instance($user->id);
$coursecontext = \context_course::instance($course->id);
$usercontext = \context_user::instance($user->id);
// Creating course instances.
$repo = $this->getDataGenerator()->create_repository('flickr_public', array('contextid' => $coursecontext->id));
@@ -561,7 +566,7 @@ class core_repositorylib_testcase extends advanced_testcase {
// Checking deletion upon course context deletion.
$course = $this->getDataGenerator()->create_course();
$coursecontext = context_course::instance($course->id);
$coursecontext = \context_course::instance($course->id);
$repo = $this->getDataGenerator()->create_repository('flickr_public', array('contextid' => $coursecontext->id));
$courserepo = repository::get_repository_by_id($repo->id, $coursecontext);
$this->assertEquals(1, $DB->count_records('repository_instances', array('contextid' => $coursecontext->id)));
@@ -570,7 +575,7 @@ class core_repositorylib_testcase extends advanced_testcase {
// Checking deletion upon user context deletion.
$user = $this->getDataGenerator()->create_user();
$usercontext = context_user::instance($user->id);
$usercontext = \context_user::instance($user->id);
$repo = $this->getDataGenerator()->create_repository('flickr_public', array('contextid' => $usercontext->id));
$userrepo = repository::get_repository_by_id($repo->id, $usercontext);
$this->assertEquals(1, $DB->count_records('repository_instances', array('contextid' => $usercontext->id)));
@@ -579,7 +584,7 @@ class core_repositorylib_testcase extends advanced_testcase {
// Checking deletion upon course deletion.
$course = $this->getDataGenerator()->create_course();
$coursecontext = context_course::instance($course->id);
$coursecontext = \context_course::instance($course->id);
$repo = $this->getDataGenerator()->create_repository('flickr_public', array('contextid' => $coursecontext->id));
$courserepo = repository::get_repository_by_id($repo->id, $coursecontext);
$this->assertEquals(1, $DB->count_records('repository_instances', array('contextid' => $coursecontext->id)));
@@ -588,7 +593,7 @@ class core_repositorylib_testcase extends advanced_testcase {
// Checking deletion upon user deletion.
$user = $this->getDataGenerator()->create_user();
$usercontext = context_user::instance($user->id);
$usercontext = \context_user::instance($user->id);
$repo = $this->getDataGenerator()->create_repository('flickr_public', array('contextid' => $usercontext->id));
$userrepo = repository::get_repository_by_id($repo->id, $usercontext);
$this->assertEquals(1, $DB->count_records('repository_instances', array('contextid' => $usercontext->id)));
@@ -606,7 +611,7 @@ class core_repositorylib_testcase extends advanced_testcase {
global $USER;
$filerecord = [];
$filerecord['contextid'] = context_user::instance($USER->id)->id;
$filerecord['contextid'] = \context_user::instance($USER->id)->id;
$filerecord['component'] = 'user';
$filerecord['filearea'] = 'private';
$filerecord['itemid'] = 0;
@@ -629,7 +634,7 @@ class core_repositorylib_testcase extends advanced_testcase {
$this->create_user_private_file('/ftexts/', 'file3.txt');
// Listing without filters returns 4 records (2 files and 2 directories).
$repo = repository::get_repository_by_id($repoid, context_system::instance());
$repo = repository::get_repository_by_id($repoid, \context_system::instance());
$this->assertCount(4, $repo->get_listing()['list']);
// Listing with filters returns 3 records (1 files and 2 directories).
+3 -12
View File
@@ -14,6 +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/>.
namespace core_search;
/**
* Area category unit tests.
*
@@ -21,17 +22,7 @@
* @copyright 2018 Dmitrii Metelkin <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Area category unit tests.
*
* @package core_search
* @copyright 2018 Dmitrii Metelkin <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class search_area_category_testcase extends advanced_testcase {
class area_category_test extends \advanced_testcase {
/**
* A helper function to get a mocked search area.
@@ -65,7 +56,7 @@ class search_area_category_testcase extends advanced_testcase {
$areas[] = null;
$areas[] = [$this->get_mocked_area('area2')];
$areas[] = $this;
$areas[] = new stdClass();
$areas[] = new \stdClass();
$areas[] = $this->get_mocked_area('area3');
$areas[] = $this->get_mocked_area('area4');
+12 -18
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/>.
/**
* Search engine base unit tests.
*
* @package core_search
* @copyright 2017 Matt Porritt <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_search;
defined('MOODLE_INTERNAL') || die();
@@ -35,7 +29,7 @@ require_once($CFG->dirroot . '/search/tests/fixtures/mock_search_area.php');
* @copyright 2017 Matt Porritt <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class search_base_activity_testcase extends advanced_testcase {
class base_activity_test extends \advanced_testcase {
/**
* @var \core_search::manager
*/
@@ -63,7 +57,7 @@ class search_base_activity_testcase extends advanced_testcase {
set_config('enableglobalsearch', true);
// Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this.
$search = testable_core_search::instance();
$search = \testable_core_search::instance();
$this->generator = self::getDataGenerator()->get_plugin_generator('core_search');
$this->generator->setup();
@@ -153,7 +147,7 @@ class search_base_activity_testcase extends advanced_testcase {
// Construct the search document.
$rec = new \stdClass();
$rec->courseid = $course->id;
$area = new core_mocksearch\search\mock_search_area();
$area = new \core_mocksearch\search\mock_search_area();
$record = $this->generator->create_record($rec);
$document = $area->get_document($record);
@@ -186,7 +180,7 @@ class search_base_activity_testcase extends advanced_testcase {
global $USER, $DB;
// Get all the forums to index (no restriction).
$area = new mod_forum\search\activity();
$area = new \mod_forum\search\activity();
$results = self::recordset_to_indexed_array($area->get_document_recordset());
// Should return all forums.
@@ -211,7 +205,7 @@ class search_base_activity_testcase extends advanced_testcase {
// Now use context restrictions. First, the whole site (no change).
$results = self::recordset_to_indexed_array($area->get_document_recordset(
0, context_system::instance()));
0, \context_system::instance()));
$this->assertEquals($allids, self::records_to_ids($results));
// Course 1 only.
@@ -249,13 +243,13 @@ class search_base_activity_testcase extends advanced_testcase {
// Find an arbitrary block on the system to get a block context.
$blockid = array_values($DB->get_records('block_instances', null, 'id', 'id', 0, 1))[0]->id;
$blockcontext = context_block::instance($blockid);
$blockcontext = \context_block::instance($blockid);
// Block context (cannot return anything, so always null).
$this->assertNull($area->get_document_recordset(0, $blockcontext));
// User context (cannot return anything, so always null).
$usercontext = context_user::instance($USER->id);
$usercontext = \context_user::instance($USER->id);
$this->assertNull($area->get_document_recordset(0, $usercontext));
}
@@ -265,7 +259,7 @@ class search_base_activity_testcase extends advanced_testcase {
* @param moodle_recordset $rs Recordset to convert
* @return array Array indexed by number (0, 1, 2, ...)
*/
protected static function recordset_to_indexed_array(moodle_recordset $rs) {
protected static function recordset_to_indexed_array(\moodle_recordset $rs) {
$results = [];
foreach ($rs as $rec) {
$results[] = $rec;
@@ -292,11 +286,11 @@ class search_base_activity_testcase extends advanced_testcase {
* Tests the get_doc_url function.
*/
public function test_get_doc_url() {
$area = new mod_forum\search\activity();
$area = new \mod_forum\search\activity();
$results = self::recordset_to_indexed_array($area->get_document_recordset());
for ($i = 0; $i < 4; $i++) {
$this->assertEquals(new moodle_url('/mod/forum/view.php',
$this->assertEquals(new \moodle_url('/mod/forum/view.php',
['id' => $this->forums[$i + 1]->cmid]),
$area->get_doc_url($area->get_document($results[$i])));
}
@@ -321,7 +315,7 @@ class search_base_activity_testcase extends advanced_testcase {
set_coursemodule_visible($this->forums[3]->cmid, 0);
// Call check access on all the first three.
$area = new mod_forum\search\activity();
$area = new \mod_forum\search\activity();
$this->assertEquals(\core_search\manager::ACCESS_GRANTED, $area->check_access(
$this->forums[1]->id));
$this->assertEquals(\core_search\manager::ACCESS_DELETED, $area->check_access(
+16 -22
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 base_block class.
*
* @package core_search
* @copyright 2017 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_search;
defined('MOODLE_INTERNAL') || die();
@@ -34,7 +28,7 @@ require_once(__DIR__ . '/fixtures/mock_block_area.php');
* @copyright 2017 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class base_block_testcase extends advanced_testcase {
class base_block_test extends \advanced_testcase {
/**
* Tests getting the name out of the class name.
*/
@@ -136,7 +130,7 @@ class base_block_testcase extends advanced_testcase {
\context_block::instance($block9id);
// Get all the blocks.
$area = new block_mockblock\search\area();
$area = new \block_mockblock\search\area();
$results = self::recordset_to_indexed_array($area->get_document_recordset());
// Only blocks 1, 3, 6, 7, 8, 9 should be returned. Check all the fields for the first two.
@@ -171,7 +165,7 @@ class base_block_testcase extends advanced_testcase {
// Now use context restrictions. First, the whole site (no change).
$results = self::recordset_to_indexed_array($area->get_document_recordset(
0, context_system::instance()));
0, \context_system::instance()));
$this->assertEquals([$block1id, $block3id, $block6id, $block7id, $block8id, $block9id],
self::records_to_ids($results));
@@ -197,7 +191,7 @@ class base_block_testcase extends advanced_testcase {
$this->assertEquals([$block3id], self::records_to_ids($results));
// User context (no results).
$usercontext = context_user::instance($USER->id);
$usercontext = \context_user::instance($USER->id);
$results = self::recordset_to_indexed_array($area->get_document_recordset(
0, $usercontext));
$this->assertCount(0, $results);
@@ -225,7 +219,7 @@ class base_block_testcase extends advanced_testcase {
* @param moodle_recordset $rs Recordset to convert
* @return array Array indexed by number (0, 1, 2, ...)
*/
protected static function recordset_to_indexed_array(moodle_recordset $rs) {
protected static function recordset_to_indexed_array(\moodle_recordset $rs) {
$results = [];
foreach ($rs as $rec) {
$results[] = $rec;
@@ -271,9 +265,9 @@ class base_block_testcase extends advanced_testcase {
$blockid = $DB->insert_record('block_instances', $instance);
// Get document URL.
$area = new block_mockblock\search\area();
$area = new \block_mockblock\search\area();
$doc = $this->get_doc($course->id, $blockid);
$expected = new moodle_url('/course/view.php', ['id' => $course->id], 'inst' . $blockid);
$expected = new \moodle_url('/course/view.php', ['id' => $course->id], 'inst' . $blockid);
$this->assertEquals($expected, $area->get_doc_url($doc));
$this->assertEquals($expected, $area->get_context_url($doc));
@@ -286,7 +280,7 @@ class base_block_testcase extends advanced_testcase {
// Get document URL.
$doc2 = $this->get_doc($course->id, $block2id);
$expected = new moodle_url('/', ['redirect' => 0], 'inst' . $block2id);
$expected = new \moodle_url('/', ['redirect' => 0], 'inst' . $block2id);
$this->assertEquals($expected, $area->get_doc_url($doc2));
$this->assertEquals($expected, $area->get_context_url($doc2));
@@ -302,7 +296,7 @@ class base_block_testcase extends advanced_testcase {
$doc3 = $this->get_doc($course->id, $block3id);
$this->assertDebuggingCalledCount(2, [$debugmessage, $debugmessage]);
$expected = new moodle_url('/mod/page/view.php', ['id' => $page->cmid], 'inst' . $block3id);
$expected = new \moodle_url('/mod/page/view.php', ['id' => $page->cmid], 'inst' . $block3id);
$this->assertEquals($expected, $area->get_doc_url($doc3));
$this->assertDebuggingCalled($debugmessage);
$this->assertEquals($expected, $area->get_context_url($doc3));
@@ -315,7 +309,7 @@ class base_block_testcase extends advanced_testcase {
// Get document URL.
$doc = $this->get_doc($course->id, $block4id);
$expected = new moodle_url('/course/view.php', ['id' => $course->id], 'inst' . $block4id);
$expected = new \moodle_url('/course/view.php', ['id' => $course->id], 'inst' . $block4id);
$this->assertEquals($expected, $area->get_doc_url($doc));
$this->assertEquals($expected, $area->get_context_url($doc));
@@ -325,7 +319,7 @@ class base_block_testcase extends advanced_testcase {
// Get document URL.
$doc = $this->get_doc($course->id, $block5id);
$expected = new moodle_url('/course/view.php', ['id' => $course->id], 'inst' . $block5id);
$expected = new \moodle_url('/course/view.php', ['id' => $course->id], 'inst' . $block5id);
$this->assertEquals($expected, $area->get_doc_url($doc));
$this->assertEquals($expected, $area->get_context_url($doc));
}
@@ -353,7 +347,7 @@ class base_block_testcase extends advanced_testcase {
$blockid = $DB->insert_record('block_instances', $instance);
// Check access for block that exists.
$area = new block_mockblock\search\area();
$area = new \block_mockblock\search\area();
$this->assertEquals(\core_search\manager::ACCESS_GRANTED, $area->check_access($blockid));
// Check access for nonexistent block.
@@ -420,7 +414,7 @@ class base_block_testcase extends advanced_testcase {
\context_block::instance($blockid4);
// Check list of contexts.
$area = new block_mockblock\search\area();
$area = new \block_mockblock\search\area();
$contexts = iterator_to_array($area->get_contexts_to_reindex(), false);
$expected = [
$context2,
@@ -438,8 +432,8 @@ class base_block_testcase extends advanced_testcase {
* @return \core_search\document Document object
*/
protected function get_doc($courseid, $blockinstanceid) {
$engine = testable_core_search::instance()->get_engine();
$area = new block_mockblock\search\area();
$engine = \testable_core_search::instance()->get_engine();
$area = new \block_mockblock\search\area();
$docdata = ['id' => $blockinstanceid, 'courseid' => $courseid,
'areaid' => $area->get_area_id(), 'itemid' => 0];
return $engine->to_document($area, $docdata);
+2 -10
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/>.
/**
* Document icon unit tests.
*
* @package core_search
* @copyright 2018 Dmitrii Metelkin <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
namespace core_search;
/**
* Document icon unit tests.
@@ -31,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2018 Dmitrii Metelkin <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class search_document_icon_testcase extends advanced_testcase {
class document_icon_test extends \advanced_testcase {
/**
* Test that default component gets returned correctly.
*/
+3 -3
View File
@@ -27,12 +27,12 @@ use stdClass;
* Unit tests for search document.
*
* @package core_search
* @category phpunit
* @category test
* @copyright 2016 Eric Merrill {@link http://www.merrilldigital.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_search\document
*/
class document_test extends advanced_testcase {
class document_test extends \advanced_testcase {
/**
* Setup to ensure that fixtures are loaded.
@@ -53,7 +53,7 @@ class document_test extends advanced_testcase {
set_config('enableglobalsearch', true);
// Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this.
$search = testable_core_search::instance();
$search = \testable_core_search::instance();
$this->generator = self::getDataGenerator()->get_plugin_generator('core_search');
$this->generator->setup();
+3 -10
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 for top results
*
* @package core_search
* @author Nathan Nguyen <[email protected]>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_search;
defined('MOODLE_INTERNAL') || die();
@@ -37,7 +30,7 @@ require_once(__DIR__ . '/fixtures/mock_search_area.php');
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class search_top_result_testcase extends advanced_testcase {
class top_result_test extends \advanced_testcase {
/** @var stdClass course 1 */
protected $course1;
@@ -61,7 +54,7 @@ class search_top_result_testcase extends advanced_testcase {
$this->setAdminUser();
// Search engine.
$this->search = testable_core_search::instance(new \search_simpledb\engine());
$this->search = \testable_core_search::instance(new \search_simpledb\engine());
// Set default configurations.
set_config('searchallavailablecourses', 1);
+86 -86
View File
@@ -14,6 +14,12 @@
// 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_tag;
use core_tag_area;
use core_tag_collection;
use core_tag_tag;
/**
* Tag related unit tests.
*
@@ -22,12 +28,7 @@
* @copyright 2014 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
class core_tag_taglib_testcase extends advanced_testcase {
class taglib_test extends \advanced_testcase {
/**
* Test set up.
@@ -81,7 +82,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$course = $this->getDataGenerator()->create_course();
// Create the tag and tag instance we are going to delete.
core_tag_tag::add_item_tag('core', 'course', $course->id, context_course::instance($course->id), 'A random tag');
core_tag_tag::add_item_tag('core', 'course', $course->id, \context_course::instance($course->id), 'A random tag');
$this->assertEquals(1, $DB->count_records('tag'));
$this->assertEquals(1, $DB->count_records('tag_instance'));
@@ -117,27 +118,27 @@ class core_tag_taglib_testcase extends advanced_testcase {
// Create a tag (ordering should start at 1).
$ti1 = core_tag_tag::add_item_tag('core', 'course', $course1->id,
context_course::instance($course1->id), 'A random tag for course 1');
\context_course::instance($course1->id), 'A random tag for course 1');
$this->assertEquals(1, $DB->get_field('tag_instance', 'ordering', ['id' => $ti1]));
// Create another tag with a common component, itemtype and itemid (should increase the ordering by 1).
$ti2 = core_tag_tag::add_item_tag('core', 'course', $course1->id,
context_course::instance($course1->id), 'Another random tag for course 1');
\context_course::instance($course1->id), 'Another random tag for course 1');
$this->assertEquals(2, $DB->get_field('tag_instance', 'ordering', ['id' => $ti2]));
// Create a new tag with the same component and itemtype, but different itemid (should start counting from 1 again).
$ti3 = core_tag_tag::add_item_tag('core', 'course', $course2->id,
context_course::instance($course2->id), 'A random tag for course 2');
\context_course::instance($course2->id), 'A random tag for course 2');
$this->assertEquals(1, $DB->get_field('tag_instance', 'ordering', ['id' => $ti3]));
// Create a new tag with a different itemtype (should start counting from 1 again).
$ti4 = core_tag_tag::add_item_tag('core', 'user', $user1->id,
context_user::instance($user1->id), 'A random tag for user 1');
\context_user::instance($user1->id), 'A random tag for user 1');
$this->assertEquals(1, $DB->get_field('tag_instance', 'ordering', ['id' => $ti4]));
// Create a new tag with a different component (should start counting from 1 again).
$ti5 = core_tag_tag::add_item_tag('mod_book', 'book_chapters', $chapter1id,
context_module::instance($book1->cmid), 'A random tag for a book chapter');
\context_module::instance($book1->cmid), 'A random tag for a book chapter');
$this->assertEquals(1, $DB->get_field('tag_instance', 'ordering', ['id' => $ti5]));
}
@@ -146,7 +147,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
* This function was deprecated in 3.1
*/
public function test_tag_assign() {
$this->expectException('coding_exception');
$this->expectException(\coding_exception::class);
$this->expectExceptionMessage('tag_assign() can not be used anymore. Please use core_tag_tag::set_item_tags() ' .
'or core_tag_tag::add_item_tag() instead.');
tag_assign();
@@ -168,7 +169,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
// Create a course to tag.
$course = $this->getDataGenerator()->create_course();
$context = context_course::instance($course->id);
$context = \context_course::instance($course->id);
// Test clean up instances with tags that no longer exist.
$tags = array();
@@ -199,7 +200,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
// Test clean up with users that have been deleted.
// Create a tag for this course.
foreach ($users as $user) {
$context = context_user::instance($user->id);
$context = \context_user::instance($user->id);
core_tag_tag::set_item_tags('core', 'user', $user->id, $context, array($tags[0]->rawname));
}
$usertags = $DB->count_records('tag_instance', array('itemtype' => 'user'));
@@ -226,11 +227,11 @@ class core_tag_taglib_testcase extends advanced_testcase {
// Test clean up where a post has been removed.
// Create default post.
$post = new stdClass();
$post = new \stdClass();
$post->userid = $users[1]->id;
$post->content = 'test post content text';
$post->id = $DB->insert_record('post', $post);
$context = context_system::instance();
$context = \context_system::instance();
core_tag_tag::set_item_tags('core', 'post', $post->id, $context, array($tags[0]->rawname));
// Add another one with a fake post id to be removed.
@@ -255,7 +256,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
// Setup.
$user = $this->getDataGenerator()->create_user();
$course = $this->getDataGenerator()->create_course();
$context = context_course::instance($course->id);
$context = \context_course::instance($course->id);
// Create some tag instances.
for ($i = 0; $i < 10; $i++) {
@@ -281,9 +282,9 @@ class core_tag_taglib_testcase extends advanced_testcase {
public function test_set_item_tags_with_invalid_userid(): void {
$user = $this->getDataGenerator()->create_user();
$this->expectException(coding_exception::class);
$this->expectException(\coding_exception::class);
$this->expectExceptionMessage('Related tags can not have tag instance userid');
core_tag_tag::set_item_tags('core', 'tag', 1, context_system::instance(), ['all', 'night', 'long'], $user->id);
core_tag_tag::set_item_tags('core', 'tag', 1, \context_system::instance(), ['all', 'night', 'long'], $user->id);
}
/**
@@ -306,13 +307,12 @@ class core_tag_taglib_testcase extends advanced_testcase {
// Several records have both 'cat' and 'cats' tags attached to them.
// This will make those tags automatically correlated.
// Same with 'dog', 'dogs' and 'puppy.
core_tag_tag::set_item_tags('core', 'user', $user1->id, context_user::instance($user1->id), array('cat', 'cats'));
core_tag_tag::set_item_tags('core', 'user', $user2->id, context_user::instance($user2->id), array('cat', 'cats', 'kitten'));
core_tag_tag::set_item_tags('core', 'user', $user3->id, context_user::instance($user3->id), array('cat', 'cats'));
core_tag_tag::set_item_tags('core', 'user', $user4->id, context_user::instance($user4->id), array('dog', 'dogs', 'puppy'));
core_tag_tag::set_item_tags('core', 'user', $user5->id, context_user::instance($user5->id), array('dog', 'dogs', 'puppy'));
core_tag_tag::set_item_tags('core', 'user', $user6->id, context_user::instance($user6->id), array('dog', 'dogs', 'puppy'));
core_tag_tag::set_item_tags('core', 'user', $user1->id, \context_user::instance($user1->id), array('cat', 'cats'));
core_tag_tag::set_item_tags('core', 'user', $user2->id, \context_user::instance($user2->id), array('cat', 'cats', 'kitten'));
core_tag_tag::set_item_tags('core', 'user', $user3->id, \context_user::instance($user3->id), array('cat', 'cats'));
core_tag_tag::set_item_tags('core', 'user', $user4->id, \context_user::instance($user4->id), array('dog', 'dogs', 'puppy'));
core_tag_tag::set_item_tags('core', 'user', $user5->id, \context_user::instance($user5->id), array('dog', 'dogs', 'puppy'));
core_tag_tag::set_item_tags('core', 'user', $user6->id, \context_user::instance($user6->id), array('dog', 'dogs', 'puppy'));
$tags = core_tag_tag::get_by_name_bulk(core_tag_collection::get_default(),
array('cat', 'cats', 'dog', 'dogs', 'kitten', 'puppy'), '*');
@@ -435,7 +435,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$defaultcoll = core_tag_collection::get_default();
// Setting tags will create non-standard tags 'cat', 'dog' and 'fish'.
core_tag_tag::set_item_tags('core', 'user', $user->id, context_user::instance($user->id), array('cat', 'dog', 'fish'));
core_tag_tag::set_item_tags('core', 'user', $user->id, \context_user::instance($user->id), array('cat', 'dog', 'fish'));
$this->assertTrue($DB->record_exists('tag', array('name' => 'cat')));
$this->assertTrue($DB->record_exists('tag', array('name' => 'dog')));
@@ -466,7 +466,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$this->assertFalse($DB->record_exists('tag', array('name' => 'cat')));
// Assign tag to non-existing record. Make sure tag was created in the DB.
core_tag_tag::set_item_tags('core', 'course', 1231231, context_system::instance(), array('bird'));
core_tag_tag::set_item_tags('core', 'course', 1231231, \context_system::instance(), array('bird'));
$this->assertTrue($DB->record_exists('tag', array('name' => 'bird')));
$task->cleanup();
@@ -476,7 +476,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
// Now we have a tag instance pointing on 'sometag' tag.
$user = $this->getDataGenerator()->create_user();
core_tag_tag::set_item_tags('core', 'user', $user->id, context_user::instance($user->id), array('sometag'));
core_tag_tag::set_item_tags('core', 'user', $user->id, \context_user::instance($user->id), array('sometag'));
$sometag = core_tag_tag::get_by_name($defaultcoll, 'sometag');
$this->assertTrue($DB->record_exists('tag_instance', array('tagid' => $sometag->id)));
@@ -509,7 +509,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
// Create a course to tag.
$course = $this->getDataGenerator()->create_course();
$context = context_course::instance($course->id);
$context = \context_course::instance($course->id);
$initialtagscount = $DB->count_records('tag');
@@ -654,14 +654,14 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid2 = core_tag_collection::create(array('name' => 'newcoll'))->id;
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$blogpost = new blog_entry(null, array('subject' => 'test'), null);
$states = blog_entry::get_applicable_publish_states();
$blogpost = new \blog_entry(null, array('subject' => 'test'), null);
$states = \blog_entry::get_applicable_publish_states();
$blogpost->publishstate = reset($states);
$blogpost->add();
core_tag_tag::set_item_tags('core', 'user', $user1->id, context_user::instance($user1->id),
core_tag_tag::set_item_tags('core', 'user', $user1->id, \context_user::instance($user1->id),
array('Tag1', 'Tag2'));
core_tag_tag::set_item_tags('core', 'user', $user2->id, context_user::instance($user2->id),
core_tag_tag::set_item_tags('core', 'user', $user2->id, \context_user::instance($user2->id),
array('Tag2', 'Tag3'));
$this->getDataGenerator()->create_tag(array('rawname' => 'Tag4',
'tagcollid' => $collid1, 'isstandard' => 1));
@@ -697,7 +697,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
global $DB;
list($collid1, $collid2, $user1, $user2, $blogpost) = $this->prepare_move_tags();
core_tag_tag::set_item_tags('core', 'post', $blogpost->id, context_system::instance(),
core_tag_tag::set_item_tags('core', 'post', $blogpost->id, \context_system::instance(),
array('Tag1', 'Tag3'));
// Move 'user' area from collection 1 to collection 2, make sure tag Tag2 was moved and tags Tag1 and Tag3 were duplicated.
@@ -727,7 +727,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tagareablog = $DB->get_record('tag_area', array('itemtype' => 'post', 'component' => 'core'));
core_tag_area::update($tagareablog, array('tagcollid' => $collid2));
core_tag_tag::set_item_tags('core', 'post', $blogpost->id, context_system::instance(),
core_tag_tag::set_item_tags('core', 'post', $blogpost->id, \context_system::instance(),
array('TAG1', 'Tag3'));
// Move 'user' area from collection 1 to collection 2,
@@ -761,7 +761,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tagareablog = $DB->get_record('tag_area', array('itemtype' => 'post', 'component' => 'core'));
core_tag_area::update($tagareablog, array('tagcollid' => $collid2));
core_tag_tag::set_item_tags('core', 'post', $blogpost->id, context_system::instance(),
core_tag_tag::set_item_tags('core', 'post', $blogpost->id, \context_system::instance(),
array('TAG1', 'Tag3'));
// Move 'user' area from collection 1 to collection 2, make sure tags were moved completely.
@@ -838,7 +838,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
* This function was deprecated in 3.1
*/
public function test_normalize() {
$this->expectException('coding_exception');
$this->expectException(\coding_exception::class);
$this->expectExceptionMessage('tag_normalize() can not be used anymore. Please use ' .
'core_tag_tag::normalize().');
tag_normalize();
@@ -900,7 +900,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
);
$collid = core_tag_collection::get_default();
$context = context_system::instance();
$context = \context_system::instance();
foreach ($initialtags as $id => $taglist) {
core_tag_tag::set_item_tags('core', 'course', $id + 10, $context, $initialtags[$id]);
}
@@ -931,7 +931,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
*/
public function test_combine_tags_with_related() {
$collid = core_tag_collection::get_default();
$context = context_system::instance();
$context = \context_system::instance();
core_tag_tag::set_item_tags('core', 'course', 10, $context, array('Cat', 'Cats', 'Dog'));
core_tag_tag::get_by_name($collid, 'Cat', '*')->set_related_tags(array('Kitty'));
core_tag_tag::get_by_name($collid, 'Cats', '*')->set_related_tags(array('Cat', 'Kitten', 'Kitty'));
@@ -975,7 +975,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
// Add tag that does not have any correlations.
$user7 = $this->getDataGenerator()->create_user();
core_tag_tag::set_item_tags('core', 'user', $user7->id, context_user::instance($user7->id), array('hippo'));
core_tag_tag::set_item_tags('core', 'user', $user7->id, \context_user::instance($user7->id), array('hippo'));
$tags['hippo'] = core_tag_tag::get_by_name(core_tag_collection::get_default(), 'hippo', '*');
// Combine tag 'cat' into 'hippo'. Now 'hippo' should have the same correlations 'cat' used to have and also
@@ -1001,7 +1001,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
$context = context_user::instance($user->id);
$context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
@@ -1019,7 +1019,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
$context = context_user::instance($user->id);
$context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
core_tag_tag::set_item_tags($component, $itemtype, $user->id, $context, $tagnames);
@@ -1048,7 +1048,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
$context = context_user::instance($user->id);
$context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
core_tag_tag::set_item_tags($component, $itemtype, $user->id, $context, array_slice($tagnames, 0, 2));
@@ -1080,9 +1080,9 @@ class core_tag_taglib_testcase extends advanced_testcase {
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$user3 = $this->getDataGenerator()->create_user();
$context1 = context_user::instance($user1->id);
$context2 = context_user::instance($user2->id);
$context3 = context_user::instance($user3->id);
$context1 = \context_user::instance($user1->id);
$context2 = \context_user::instance($user2->id);
$context3 = \context_user::instance($user3->id);
$component = 'core';
$itemtype = 'user';
@@ -1118,7 +1118,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
global $CFG;
$user1 = $this->getDataGenerator()->create_user();
$context1 = context_user::instance($user1->id);
$context1 = \context_user::instance($user1->id);
$component = 'core';
$itemtype = 'user';
$itemids = [$user1->id];
@@ -1137,7 +1137,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
*/
public function test_get_items_tags_empty_itemids() {
$user1 = $this->getDataGenerator()->create_user();
$context1 = context_user::instance($user1->id);
$context1 = \context_user::instance($user1->id);
$component = 'core';
$itemtype = 'user';
@@ -1195,8 +1195,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$user3 = $this->getDataGenerator()->create_user();
$context1 = context_user::instance($user1->id);
$context2 = context_user::instance($user2->id);
$context1 = \context_user::instance($user1->id);
$context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype = 'user';
$itemids = [$user1->id, $user2->id, $user3->id];
@@ -1237,7 +1237,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$context = context_user::instance($user1->id);
$context = \context_user::instance($user1->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1279,8 +1279,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$context1 = context_user::instance($user1->id);
$context2 = context_user::instance($user2->id);
$context1 = \context_user::instance($user1->id);
$context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1318,8 +1318,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$context1 = context_user::instance($user1->id);
$context2 = context_user::instance($user2->id);
$context1 = \context_user::instance($user1->id);
$context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1368,8 +1368,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$context1 = context_user::instance($user1->id);
$context2 = context_user::instance($user2->id);
$context1 = \context_user::instance($user1->id);
$context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1420,8 +1420,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$context1 = context_user::instance($user1->id);
$context2 = context_user::instance($user2->id);
$context1 = \context_user::instance($user1->id);
$context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1464,8 +1464,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$context1 = context_user::instance($user1->id);
$context2 = context_user::instance($user2->id);
$context1 = \context_user::instance($user1->id);
$context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1505,7 +1505,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
*/
public function test_delete_instances_as_record_empty_set() {
$user = $this->getDataGenerator()->create_user();
$context = context_user::instance($user->id);
$context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1528,7 +1528,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
$context = context_user::instance($user->id);
$context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1553,7 +1553,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
$context = context_user::instance($user->id);
$context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1576,7 +1576,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
$context = context_user::instance($user->id);
$context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1598,7 +1598,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
*/
public function test_delete_instances_by_id_empty_set() {
$user = $this->getDataGenerator()->create_user();
$context = context_user::instance($user->id);
$context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1621,7 +1621,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
$context = context_user::instance($user->id);
$context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1645,7 +1645,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
$context = context_user::instance($user->id);
$context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1668,7 +1668,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
$context = context_user::instance($user->id);
$context = \context_user::instance($user->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1696,7 +1696,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
$context = context_user::instance($user->id);
$context = \context_user::instance($user->id);
$component = 'core';
$itemtype1 = 'user';
$itemtype2 = 'course';
@@ -1726,7 +1726,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
$collid = core_tag_collection::get_default();
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user = $this->getDataGenerator()->create_user();
$context = context_user::instance($user->id);
$context = \context_user::instance($user->id);
$component = 'core';
$itemtype1 = 'user';
$itemtype2 = 'course';
@@ -1760,8 +1760,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$context1 = context_user::instance($user1->id);
$context2 = context_user::instance($user2->id);
$context1 = \context_user::instance($user1->id);
$context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype1 = 'user';
$itemtype2 = 'course';
@@ -1796,8 +1796,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$context1 = context_user::instance($user1->id);
$context2 = context_user::instance($user2->id);
$context1 = \context_user::instance($user1->id);
$context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype1 = 'user';
$itemtype2 = 'course';
@@ -1841,8 +1841,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$context1 = context_user::instance($user1->id);
$context2 = context_user::instance($user2->id);
$context1 = \context_user::instance($user1->id);
$context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1869,8 +1869,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$context1 = context_user::instance($user1->id);
$context2 = context_user::instance($user2->id);
$context1 = \context_user::instance($user1->id);
$context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1901,9 +1901,9 @@ class core_tag_taglib_testcase extends advanced_testcase {
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$user3 = $this->getDataGenerator()->create_user();
$context1 = context_user::instance($user1->id);
$context2 = context_user::instance($user2->id);
$context3 = context_user::instance($user3->id);
$context1 = \context_user::instance($user1->id);
$context2 = \context_user::instance($user2->id);
$context3 = \context_user::instance($user3->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
@@ -1941,8 +1941,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
$tags = core_tag_tag::create_if_missing($collid, $tagnames);
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$context1 = context_user::instance($user1->id);
$context2 = context_user::instance($user2->id);
$context1 = \context_user::instance($user1->id);
$context2 = \context_user::instance($user2->id);
$component = 'core';
$itemtype = 'user';
$itemid = 1;
+6 -13
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/>.
/**
* Unit tests for user/editlib.php.
*
* @package core_user
* @category phpunit
* @copyright 2013 Adrian Greeve <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_user;
defined('MOODLE_INTERNAL') || die();
@@ -32,11 +25,11 @@ require_once($CFG->dirroot.'/user/editlib.php');
* Unit tests for user editlib api.
*
* @package core_user
* @category phpunit
* @category test
* @copyright 2013 Adrian Greeve <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_user_editlib_testcase extends advanced_testcase {
class editlib_test extends \advanced_testcase {
/**
* Test that the required fields are returned in the correct order.
@@ -44,7 +37,7 @@ class core_user_editlib_testcase extends advanced_testcase {
function test_useredit_get_required_name_fields() {
global $CFG;
// Back up config settings for restore later.
$originalcfg = new stdClass();
$originalcfg = new \stdClass();
$originalcfg->fullnamedisplay = $CFG->fullnamedisplay;
$CFG->fullnamedisplay = 'language';
@@ -70,7 +63,7 @@ class core_user_editlib_testcase extends advanced_testcase {
function test_useredit_get_enabled_name_fields() {
global $CFG;
// Back up config settings for restore later.
$originalcfg = new stdClass();
$originalcfg = new \stdClass();
$originalcfg->fullnamedisplay = $CFG->fullnamedisplay;
$CFG->fullnamedisplay = 'language';
@@ -96,7 +89,7 @@ class core_user_editlib_testcase extends advanced_testcase {
function test_useredit_get_disabled_name_fields() {
global $CFG;
// Back up config settings for restore later.
$originalcfg = new stdClass();
$originalcfg = new \stdClass();
$originalcfg->fullnamedisplay = $CFG->fullnamedisplay;
$CFG->fullnamedisplay = 'language';
@@ -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/>.
/**
* Unit tests for {@link group_non_members_selector} class.
*
* @package core_user
* @category test
* @copyright 2019 Huong Nguyen <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_user;
use group_non_members_selector;
defined('MOODLE_INTERNAL') || die();
@@ -36,7 +31,7 @@ require_once($CFG->dirroot . '/user/selector/lib.php');
* @copyright 2019 Huong Nguyen <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_group_non_members_selector_testcase extends advanced_testcase {
class group_non_members_selector_test extends \advanced_testcase {
/**
* Test find_users that only return group non members

Some files were not shown because too many files have changed in this diff Show More