MDL-73971 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: - Some fixtures, initially defined in the test files have been moved to new files in fixtures subdirectory, leaving the unit test files clearer: - moodle2_course_format_test.php - Rename wrong named test: - baseoptiogroup_test = baseoptigroup_test
This commit is contained in:
@@ -14,19 +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 core_role;
|
||||
|
||||
use core_role_preset;
|
||||
|
||||
/**
|
||||
* Role XML presets test case.
|
||||
*
|
||||
* @package core_role
|
||||
* @category phpunit
|
||||
* @category test
|
||||
* @copyright 2013 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
class core_role_preset_testcase extends advanced_testcase {
|
||||
class preset_test extends \advanced_testcase {
|
||||
public function test_xml() {
|
||||
global $DB;
|
||||
|
||||
@@ -61,7 +61,7 @@ class core_role_preset_testcase extends advanced_testcase {
|
||||
FROM {role_capabilities}
|
||||
WHERE contextid = :syscontext AND roleid = :roleid
|
||||
ORDER BY capability ASC",
|
||||
array('syscontext'=>context_system::instance()->id, 'roleid'=>$role->id));
|
||||
array('syscontext' => \context_system::instance()->id, 'roleid' => $role->id));
|
||||
|
||||
foreach ($capabilities as $cap) {
|
||||
$this->assertEquals($cap->permission, $info['permissions'][$cap->capability]);
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the data_registry class.
|
||||
*
|
||||
* @package tool_dataprivacy
|
||||
* @copyright 2018 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use \tool_dataprivacy\data_registry;
|
||||
namespace tool_dataprivacy;
|
||||
|
||||
/**
|
||||
* Unit tests for the data_registry class.
|
||||
@@ -33,7 +23,7 @@ use \tool_dataprivacy\data_registry;
|
||||
* @copyright 2018 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_dataprivacy_dataregistry_testcase extends advanced_testcase {
|
||||
class data_registry_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure that the get_effective_context_value only errors if provided an inappropriate element.
|
||||
@@ -41,7 +31,7 @@ class tool_dataprivacy_dataregistry_testcase extends advanced_testcase {
|
||||
* This test is not great because we only test a limited set of values. This is a fault of the underlying API.
|
||||
*/
|
||||
public function test_get_effective_context_value_invalid_element() {
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectException(\coding_exception::class);
|
||||
data_registry::get_effective_context_value(\context_system::instance(), 'invalid');
|
||||
}
|
||||
|
||||
@@ -51,7 +41,7 @@ class tool_dataprivacy_dataregistry_testcase extends advanced_testcase {
|
||||
* This test is not great because we only test a limited set of values. This is a fault of the underlying API.
|
||||
*/
|
||||
public function test_get_effective_contextlevel_value_invalid_element() {
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectException(\coding_exception::class);
|
||||
data_registry::get_effective_contextlevel_value(\context_system::instance(), 'invalid');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,19 +14,13 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Tests for the data_request persistent.
|
||||
*
|
||||
* @package tool_dataprivacy
|
||||
* @copyright 2018 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_dataprivacy;
|
||||
|
||||
use data_privacy_testcase;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once('data_privacy_testcase.php');
|
||||
|
||||
use tool_dataprivacy\api;
|
||||
|
||||
/**
|
||||
* Tests for the data_request persistent.
|
||||
*
|
||||
@@ -34,7 +28,7 @@ use tool_dataprivacy\api;
|
||||
* @copyright 2018 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_dataprivacy_data_request_testcase extends data_privacy_testcase {
|
||||
class data_request_test extends data_privacy_testcase {
|
||||
|
||||
/**
|
||||
* Data provider for testing is_resettable, and is_active.
|
||||
|
||||
@@ -14,25 +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/>.
|
||||
|
||||
/**
|
||||
* Expired contexts tests.
|
||||
*
|
||||
* @package tool_dataprivacy
|
||||
* @copyright 2018 David Monllao
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use tool_dataprivacy\api;
|
||||
use tool_dataprivacy\data_registry;
|
||||
use tool_dataprivacy\expired_context;
|
||||
use tool_dataprivacy\purpose;
|
||||
use tool_dataprivacy\purpose_override;
|
||||
use tool_dataprivacy\category;
|
||||
use tool_dataprivacy\contextlevel;
|
||||
use tool_dataprivacy\expired_contexts_manager;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
global $CFG;
|
||||
namespace tool_dataprivacy;
|
||||
|
||||
/**
|
||||
* Expired contexts tests.
|
||||
@@ -41,7 +23,7 @@ global $CFG;
|
||||
* @copyright 2018 David Monllao
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_dataprivacy_expired_contexts_testcase extends advanced_testcase {
|
||||
class expired_contexts_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Setup the basics with the specified retention period.
|
||||
|
||||
@@ -14,21 +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/>.
|
||||
|
||||
/**
|
||||
* Expired data requests tests.
|
||||
*
|
||||
* @package tool_dataprivacy
|
||||
* @copyright 2018 Michael Hawkins
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_dataprivacy;
|
||||
|
||||
use tool_dataprivacy\api;
|
||||
use tool_dataprivacy\category;
|
||||
use tool_dataprivacy\data_request;
|
||||
use tool_dataprivacy\purpose;
|
||||
use data_privacy_testcase;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
global $CFG;
|
||||
|
||||
require_once('data_privacy_testcase.php');
|
||||
|
||||
@@ -39,7 +29,7 @@ require_once('data_privacy_testcase.php');
|
||||
* @copyright 2018 Michael Hawkins
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_dataprivacy_expired_data_requests_testcase extends data_privacy_testcase {
|
||||
class expired_data_requests_test extends data_privacy_testcase {
|
||||
|
||||
/**
|
||||
* Test tearDown.
|
||||
@@ -59,7 +49,7 @@ class tool_dataprivacy_expired_data_requests_testcase extends data_privacy_testc
|
||||
// Set up test users.
|
||||
$this->setAdminUser();
|
||||
$studentuser = $this->getDataGenerator()->create_user();
|
||||
$studentusercontext = context_user::instance($studentuser->id);
|
||||
$studentusercontext = \context_user::instance($studentuser->id);
|
||||
|
||||
$dpouser = $this->getDataGenerator()->create_user();
|
||||
$this->assign_site_dpo($dpouser);
|
||||
|
||||
@@ -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 filtered_userlist.
|
||||
*
|
||||
* @package tool_dataprivacy
|
||||
* @copyright 2018 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_dataprivacy;
|
||||
|
||||
/**
|
||||
* Unit tests for the filtered_userlist.
|
||||
@@ -29,7 +23,7 @@
|
||||
* @copyright 2018 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_dataprivacy_filtered_userlist_testcase extends advanced_testcase {
|
||||
class filtered_userlist_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test the apply_expired_contexts_filters function with arange of options.
|
||||
*
|
||||
|
||||
@@ -14,6 +14,13 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace tool_dataprivacy;
|
||||
|
||||
use data_privacy_testcase;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once('data_privacy_testcase.php');
|
||||
|
||||
/**
|
||||
* Tests for the manager observer.
|
||||
*
|
||||
@@ -21,18 +28,7 @@
|
||||
* @copyright 2018 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once('data_privacy_testcase.php');
|
||||
|
||||
/**
|
||||
* API tests.
|
||||
*
|
||||
* @package tool_dataprivacy
|
||||
* @copyright 2018 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_dataprivacy_manager_observer_testcase extends data_privacy_testcase {
|
||||
class manager_observer_test extends data_privacy_testcase {
|
||||
/**
|
||||
* Ensure that when users are configured as DPO, they are sent an message upon failure.
|
||||
*/
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Metadata registry tests.
|
||||
*
|
||||
* @package tool_dataprivacy
|
||||
* @copyright 2018 Adrian Greeve <adriangreeve.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
global $CFG;
|
||||
namespace tool_dataprivacy;
|
||||
|
||||
/**
|
||||
* Metadata registry tests.
|
||||
@@ -32,7 +23,7 @@ global $CFG;
|
||||
* @copyright 2018 Adrian Greeve <adriangreeve.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_dataprivacy_metadata_registry_testcase extends advanced_testcase {
|
||||
class metadata_registry_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Fetch the meta data and return it in a form that we can easily unit test.
|
||||
|
||||
@@ -14,18 +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 the event observer.
|
||||
*
|
||||
* @package tool_dataprivacy
|
||||
* @copyright 2018 Mihail Geshoski <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_dataprivacy;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use \tool_dataprivacy\event\user_deleted_observer;
|
||||
use \tool_dataprivacy\api;
|
||||
use tool_dataprivacy\event\user_deleted_observer;
|
||||
|
||||
/**
|
||||
* Event observer test.
|
||||
@@ -34,7 +25,7 @@ use \tool_dataprivacy\api;
|
||||
* @copyright 2018 Mihail Geshoski <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_dataprivacy_user_deleted_observer_testcase extends advanced_testcase {
|
||||
class user_deleted_observer_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure that a delete data request is created upon user deletion.
|
||||
|
||||
@@ -14,7 +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/>.
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace tool_generator;
|
||||
|
||||
use tool_generator_course_backend;
|
||||
|
||||
/**
|
||||
* Automated unit testing. This tests the 'make large course' backend,
|
||||
@@ -24,7 +26,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2013 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_generator_maketestcourse_testcase extends advanced_testcase {
|
||||
class maketestcourse_test extends \advanced_testcase {
|
||||
/**
|
||||
* Creates a small test course and checks all the components have been put in place.
|
||||
*/
|
||||
@@ -52,7 +54,7 @@ class tool_generator_maketestcourse_testcase extends advanced_testcase {
|
||||
|
||||
// Get course details.
|
||||
$course = get_course($courseid);
|
||||
$context = context_course::instance($courseid);
|
||||
$context = \context_course::instance($courseid);
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
|
||||
// Check course names.
|
||||
@@ -88,7 +90,7 @@ class tool_generator_maketestcourse_testcase extends advanced_testcase {
|
||||
|
||||
// Check it contains 2 files (the default txt and a dat file).
|
||||
$fs = get_file_storage();
|
||||
$resourcecontext = context_module::instance($resource->id);
|
||||
$resourcecontext = \context_module::instance($resource->id);
|
||||
$files = $fs->get_area_files($resourcecontext->id, 'mod_resource', 'content', false, 'filename', false);
|
||||
$files = array_values($files);
|
||||
$this->assertEquals(2, count($files));
|
||||
@@ -106,7 +108,7 @@ class tool_generator_maketestcourse_testcase extends advanced_testcase {
|
||||
$this->assertTrue($ok);
|
||||
|
||||
// Check it contains 2 files.
|
||||
$resourcecontext = context_module::instance($resource->id);
|
||||
$resourcecontext = \context_module::instance($resource->id);
|
||||
$files = $fs->get_area_files($resourcecontext->id, 'mod_resource', 'content', false, 'filename', false);
|
||||
$files = array_values($files);
|
||||
$this->assertEquals(2, count($files));
|
||||
@@ -155,7 +157,7 @@ class tool_generator_maketestcourse_testcase extends advanced_testcase {
|
||||
$lastusernumber = 0;
|
||||
$discussionstarters = array();
|
||||
foreach ($discussions as $discussion) {
|
||||
$usernumber = core_user::get_user($discussion->userid, 'id, idnumber')->idnumber;
|
||||
$usernumber = \core_user::get_user($discussion->userid, 'id, idnumber')->idnumber;
|
||||
|
||||
// Checks that the users are odd numbers.
|
||||
$this->assertEquals(1, $usernumber % 2);
|
||||
@@ -190,7 +192,7 @@ class tool_generator_maketestcourse_testcase extends advanced_testcase {
|
||||
$fs = get_file_storage();
|
||||
$resources = $modinfo->get_instances_of('resource');
|
||||
foreach ($resources as $resource) {
|
||||
$resourcecontext = context_module::instance($resource->id);
|
||||
$resourcecontext = \context_module::instance($resource->id);
|
||||
$files = $fs->get_area_files($resourcecontext->id, 'mod_resource', 'content', false, 'filename', false);
|
||||
foreach ($files as $file) {
|
||||
if ($file->get_mimetype() == 'application/octet-stream') {
|
||||
@@ -210,7 +212,7 @@ class tool_generator_maketestcourse_testcase extends advanced_testcase {
|
||||
$fs = get_file_storage();
|
||||
$resources = $modinfo->get_instances_of('resource');
|
||||
foreach ($resources as $resource) {
|
||||
$resourcecontext = context_module::instance($resource->id);
|
||||
$resourcecontext = \context_module::instance($resource->id);
|
||||
$files = $fs->get_area_files($resourcecontext->id, 'mod_resource', 'content', false, 'filename', false);
|
||||
foreach ($files as $file) {
|
||||
if ($file->get_mimetype() == 'application/octet-stream') {
|
||||
|
||||
@@ -22,27 +22,12 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace tool_generator;
|
||||
|
||||
use tool_generator_site_backend;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Silly class to access site_backend internal methods.
|
||||
*
|
||||
* @package tool_generator
|
||||
* @copyright 2013 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class testable_tool_generator_site_backend extends tool_generator_site_backend {
|
||||
|
||||
/**
|
||||
* Public accessor.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function get_last_testcourse_id() {
|
||||
return parent::get_last_testcourse_id();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit test for the site generator
|
||||
*
|
||||
@@ -50,7 +35,7 @@ class testable_tool_generator_site_backend extends tool_generator_site_backend {
|
||||
* @copyright 2013 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_generator_maketestsite_testcase extends advanced_testcase {
|
||||
class maketestsite_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Checks that site courses shortnames are properly generated.
|
||||
@@ -102,5 +87,22 @@ class tool_generator_maketestsite_testcase extends advanced_testcase {
|
||||
$lastshortname = testable_tool_generator_site_backend::get_last_testcourse_id();
|
||||
$this->assertEquals(20, $lastshortname);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Silly class to access site_backend internal methods.
|
||||
*
|
||||
* @copyright 2013 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class testable_tool_generator_site_backend extends tool_generator_site_backend {
|
||||
|
||||
/**
|
||||
* Public accessor.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function get_last_testcourse_id() {
|
||||
return parent::get_last_testcourse_id();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,14 +15,10 @@
|
||||
// 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 unit tests class and some helper classes
|
||||
*
|
||||
* @package tool_installaddon
|
||||
* @category test
|
||||
* @copyright 2013 David Mudrak <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_installaddon;
|
||||
|
||||
use testable_tool_installaddon_installer;
|
||||
use tool_installaddon_installer;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -32,10 +28,12 @@ require_once(__DIR__.'/fixtures/testable_installer.php');
|
||||
/**
|
||||
* Unit tests for the {@link tool_installaddon_installer} class
|
||||
*
|
||||
* @package tool_installaddon
|
||||
* @category test
|
||||
* @copyright 2013 David Mudrak <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_installaddon_installer_testcase extends advanced_testcase {
|
||||
class installer_test extends \advanced_testcase {
|
||||
|
||||
public function test_get_addons_repository_url() {
|
||||
$installer = testable_tool_installaddon_installer::instance();
|
||||
|
||||
@@ -22,15 +22,17 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace tool_langimport;
|
||||
|
||||
/**
|
||||
* Tests for \tool_langimport\locale class.
|
||||
*
|
||||
* @package tool_langimport
|
||||
* @category test
|
||||
* @copyright 2018 Université Rennes 2 {@link https://www.univ-rennes2.fr}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class locale_testcase extends \advanced_testcase {
|
||||
class locale_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test that \tool_langimport\locale::check_locale_availability() works as expected.
|
||||
*
|
||||
@@ -65,7 +67,7 @@ class locale_testcase extends \advanced_testcase {
|
||||
|
||||
// Test an invalid parameter.
|
||||
$locale = new \tool_langimport\locale();
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectException(\coding_exception::class);
|
||||
$locale->check_locale_availability('');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 event observers.
|
||||
*
|
||||
* @package tool_monitor
|
||||
* @category test
|
||||
* @copyright 2014 onwards Ankit Agarwal <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_monitor;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -30,11 +23,14 @@ require_once($CFG->dirroot . '/blog/locallib.php');
|
||||
require_once($CFG->dirroot . '/blog/lib.php');
|
||||
|
||||
/**
|
||||
* Class tool_monitor_eventobservers_testcase
|
||||
* Unit tests for event observers.
|
||||
*
|
||||
* Tests for event observers
|
||||
* @package tool_monitor
|
||||
* @category test
|
||||
* @copyright 2014 onwards Ankit Agarwal <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
class eventobservers_test extends \advanced_testcase {
|
||||
/**
|
||||
* Set up method.
|
||||
*/
|
||||
@@ -57,12 +53,12 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
$course2 = $this->getDataGenerator()->create_course();
|
||||
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
|
||||
|
||||
$rule = new stdClass();
|
||||
$rule = new \stdClass();
|
||||
$rule->userid = $user->id;
|
||||
$rule->courseid = $course1->id;
|
||||
$rule->plugin = 'test';
|
||||
|
||||
$sub = new stdClass();
|
||||
$sub = new \stdClass();
|
||||
$sub->courseid = $course1->id;
|
||||
$sub->userid = $user->id;
|
||||
|
||||
@@ -83,7 +79,7 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
// Add a site rule.
|
||||
$rule = new stdClass();
|
||||
$rule = new \stdClass();
|
||||
$rule->userid = $user->id;
|
||||
$rule->courseid = 0;
|
||||
$rule->plugin = 'core';
|
||||
@@ -135,7 +131,7 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
// Fire a bunch of events.
|
||||
// Trigger a bunch of other events.
|
||||
$eventparams = array(
|
||||
'context' => context_course::instance($course->id)
|
||||
'context' => \context_course::instance($course->id)
|
||||
);
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
\core\event\course_viewed::create($eventparams)->trigger();
|
||||
@@ -148,14 +144,14 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
$this->assertEquals(0, $DB->count_records('tool_monitor_events'));
|
||||
|
||||
// Now, let's create a rule so an event can be stored.
|
||||
$rule = new stdClass();
|
||||
$rule = new \stdClass();
|
||||
$rule->courseid = $course->id;
|
||||
$rule->plugin = 'mod_book';
|
||||
$rule->eventname = '\mod_book\event\course_module_instance_list_viewed';
|
||||
$rule = $monitorgenerator->create_rule($rule);
|
||||
|
||||
// Let's subscribe to this rule.
|
||||
$sub = new stdClass;
|
||||
$sub = new \stdClass;
|
||||
$sub->courseid = $course->id;
|
||||
$sub->ruleid = $rule->id;
|
||||
$sub->userid = $user->id;
|
||||
@@ -187,14 +183,14 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
$DB->delete_records('tool_monitor_events');
|
||||
|
||||
// Now, let's create a site wide rule.
|
||||
$rule = new stdClass();
|
||||
$rule = new \stdClass();
|
||||
$rule->courseid = 0;
|
||||
$rule->plugin = 'mod_book';
|
||||
$rule->eventname = '\mod_book\event\course_module_instance_list_viewed';
|
||||
$rule = $monitorgenerator->create_rule($rule);
|
||||
|
||||
// Let's subscribe to this rule.
|
||||
$sub = new stdClass;
|
||||
$sub = new \stdClass;
|
||||
$sub->courseid = 0;
|
||||
$sub->ruleid = $rule->id;
|
||||
$sub->userid = $user->id;
|
||||
@@ -231,14 +227,14 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$toolgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
|
||||
|
||||
$rulerecord = new stdClass();
|
||||
$rulerecord = new \stdClass();
|
||||
$rulerecord->courseid = $course->id;
|
||||
$rulerecord->eventname = '\mod_book\event\course_module_instance_list_viewed';
|
||||
$rulerecord->frequency = 1;
|
||||
|
||||
$rule = $toolgenerator->create_rule($rulerecord);
|
||||
|
||||
$subrecord = new stdClass();
|
||||
$subrecord = new \stdClass();
|
||||
$subrecord->courseid = $course->id;
|
||||
$subrecord->ruleid = $rule->id;
|
||||
$subrecord->userid = $USER->id;
|
||||
@@ -279,7 +275,7 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
$DB->delete_records('tool_monitor_events');
|
||||
|
||||
// Now let us create a rule specific to a module instance.
|
||||
$cm = new stdClass();
|
||||
$cm = new \stdClass();
|
||||
$cm->course = $course->id;
|
||||
$book = $this->getDataGenerator()->create_module('book', $cm);
|
||||
$rulerecord->eventname = '\mod_book\event\course_module_viewed';
|
||||
@@ -290,7 +286,7 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
|
||||
// Let us trigger events.
|
||||
$params = array(
|
||||
'context' => context_module::instance($book->cmid),
|
||||
'context' => \context_module::instance($book->cmid),
|
||||
'objectid' => $book->id
|
||||
);
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
@@ -337,10 +333,10 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
$toolgenerator->create_subscription($subrecord);
|
||||
|
||||
// Let us trigger events.
|
||||
$blog = new blog_entry();
|
||||
$blog = new \blog_entry();
|
||||
$blog->subject = "Subject of blog";
|
||||
$blog->userid = $USER->id;
|
||||
$states = blog_entry::get_applicable_publish_states();
|
||||
$states = \blog_entry::get_applicable_publish_states();
|
||||
$blog->publishstate = reset($states);
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$newblog = fullclone($blog);
|
||||
@@ -367,14 +363,14 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$toolgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
|
||||
|
||||
$rulerecord = new stdClass();
|
||||
$rulerecord = new \stdClass();
|
||||
$rulerecord->courseid = $course->id;
|
||||
$rulerecord->eventname = '\mod_book\event\course_module_instance_list_viewed';
|
||||
$rulerecord->frequency = 5;
|
||||
|
||||
$rule = $toolgenerator->create_rule($rulerecord);
|
||||
|
||||
$subrecord = new stdClass();
|
||||
$subrecord = new \stdClass();
|
||||
$subrecord->courseid = $course->id;
|
||||
$subrecord->ruleid = $rule->id;
|
||||
$subrecord->userid = $USER->id;
|
||||
@@ -416,7 +412,7 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
*
|
||||
* @param phpunit_message_sink $msgsink Message sink
|
||||
*/
|
||||
protected function verify_processed_data(phpunit_message_sink $msgsink) {
|
||||
protected function verify_processed_data(\phpunit_message_sink $msgsink) {
|
||||
global $DB, $USER;
|
||||
|
||||
$recordexists = $DB->count_records('task_adhoc', array('component' => 'tool_monitor'));
|
||||
@@ -435,7 +431,7 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
*
|
||||
* @param phpunit_message_sink $msgsink Message sink
|
||||
*/
|
||||
protected function verify_message_not_sent_yet(phpunit_message_sink $msgsink) {
|
||||
protected function verify_message_not_sent_yet(\phpunit_message_sink $msgsink) {
|
||||
$msgs = $msgsink->get_messages();
|
||||
$this->assertCount(0, $msgs);
|
||||
$msgsink->clear();
|
||||
@@ -457,12 +453,12 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
$context = \context_user::instance($USER->id, IGNORE_MISSING);
|
||||
|
||||
// Creating book.
|
||||
$cm = new stdClass();
|
||||
$cm = new \stdClass();
|
||||
$cm->course = $course->id;
|
||||
$book = $this->getDataGenerator()->create_module('book', $cm);
|
||||
|
||||
// Creating rule.
|
||||
$rulerecord = new stdClass();
|
||||
$rulerecord = new \stdClass();
|
||||
$rulerecord->courseid = $course->id;
|
||||
$rulerecord->eventname = '\mod_book\event\course_module_viewed';
|
||||
$rulerecord->cmid = $book->cmid;
|
||||
@@ -478,7 +474,7 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
$rule = $toolgenerator->create_rule($rulerecord);
|
||||
|
||||
// Creating subscription.
|
||||
$subrecord = new stdClass();
|
||||
$subrecord = new \stdClass();
|
||||
$subrecord->courseid = $course->id;
|
||||
$subrecord->ruleid = $rule->id;
|
||||
$subrecord->userid = $USER->id;
|
||||
@@ -486,7 +482,7 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
|
||||
// Now let us trigger the event.
|
||||
$params = array(
|
||||
'context' => context_module::instance($book->cmid),
|
||||
'context' => \context_module::instance($book->cmid),
|
||||
'objectid' => $book->id
|
||||
);
|
||||
|
||||
@@ -496,7 +492,7 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
$msgs = $msgsink->get_messages();
|
||||
$msg = array_pop($msgs);
|
||||
|
||||
$modurl = new moodle_url('/mod/book/view.php', array('id' => $book->cmid));
|
||||
$modurl = new \moodle_url('/mod/book/view.php', array('id' => $book->cmid));
|
||||
|
||||
$this->assertMatchesRegularExpression('~<h2>.*' . preg_quote($event->get_url()->out(), '~') . '.*</h2>~',
|
||||
$msg->fullmessagehtml);
|
||||
@@ -529,12 +525,12 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
$course2 = $this->getDataGenerator()->create_course();
|
||||
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
|
||||
|
||||
$rule = new stdClass();
|
||||
$rule = new \stdClass();
|
||||
$rule->userid = $user->id;
|
||||
$rule->courseid = $course1->id;
|
||||
$rule->plugin = 'test';
|
||||
|
||||
$sub = new stdClass();
|
||||
$sub = new \stdClass();
|
||||
$sub->courseid = $course1->id;
|
||||
$sub->userid = $user->id;
|
||||
|
||||
@@ -585,16 +581,16 @@ class tool_monitor_eventobservers_testcase extends advanced_testcase {
|
||||
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
|
||||
|
||||
// Now let us create a rule specific to a module instance.
|
||||
$cm = new stdClass();
|
||||
$cm = new \stdClass();
|
||||
$cm->course = $course1->id;
|
||||
$book = $this->getDataGenerator()->create_module('book', $cm);
|
||||
|
||||
$rule = new stdClass();
|
||||
$rule = new \stdClass();
|
||||
$rule->userid = $user->id;
|
||||
$rule->courseid = $course1->id;
|
||||
$rule->plugin = 'test';
|
||||
|
||||
$sub = new stdClass();
|
||||
$sub = new \stdClass();
|
||||
$sub->courseid = $course1->id;
|
||||
$sub->userid = $user->id;
|
||||
$sub->cmid = $book->cmid;
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace tool_monitor;
|
||||
|
||||
/**
|
||||
* Unit tests for rule manager api.
|
||||
*
|
||||
@@ -22,17 +24,7 @@
|
||||
* @copyright 2014 onwards Simey Lameze <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
|
||||
/**
|
||||
* Tests for rule manager.
|
||||
*
|
||||
* Class tool_monitor_rule_manager_testcase
|
||||
*/
|
||||
class tool_monitor_rule_manager_testcase extends advanced_testcase {
|
||||
class rule_manager_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Set up method.
|
||||
@@ -53,7 +45,7 @@ class tool_monitor_rule_manager_testcase extends advanced_testcase {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$now = time();
|
||||
|
||||
$rule = new stdClass();
|
||||
$rule = new \stdClass();
|
||||
$rule->userid = $user->id;
|
||||
$rule->courseid = $course->id;
|
||||
$rule->name = 'test rule 1';
|
||||
@@ -98,7 +90,7 @@ class tool_monitor_rule_manager_testcase extends advanced_testcase {
|
||||
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
|
||||
$rule = $monitorgenerator->create_rule();
|
||||
|
||||
$ruledata = new stdClass;
|
||||
$ruledata = new \stdClass;
|
||||
$ruledata->id = $rule->id;
|
||||
$ruledata->frequency = 25;
|
||||
|
||||
@@ -119,10 +111,10 @@ class tool_monitor_rule_manager_testcase extends advanced_testcase {
|
||||
$course1 = $this->getDataGenerator()->create_course();
|
||||
$course2 = $this->getDataGenerator()->create_course();
|
||||
|
||||
$record = new stdClass();
|
||||
$record = new \stdClass();
|
||||
$record->courseid = $course1->id;
|
||||
|
||||
$record2 = new stdClass();
|
||||
$record2 = new \stdClass();
|
||||
$record2->courseid = $course2->id;
|
||||
|
||||
$ruleids = array();
|
||||
@@ -147,10 +139,10 @@ class tool_monitor_rule_manager_testcase extends advanced_testcase {
|
||||
|
||||
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
|
||||
|
||||
$record = new stdClass();
|
||||
$record = new \stdClass();
|
||||
$record->plugin = 'core';
|
||||
|
||||
$record2 = new stdClass();
|
||||
$record2 = new \stdClass();
|
||||
$record2->plugin = 'mod_assign';
|
||||
|
||||
$ruleids = array();
|
||||
@@ -175,10 +167,10 @@ class tool_monitor_rule_manager_testcase extends advanced_testcase {
|
||||
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
|
||||
$rule = $monitorgenerator->create_rule();
|
||||
|
||||
$record = new stdClass();
|
||||
$record = new \stdClass();
|
||||
$record->eventname = '\core\event\calendar_event_created';
|
||||
|
||||
$record2 = new stdClass();
|
||||
$record2 = new \stdClass();
|
||||
$record2->eventname = '\core\event\calendar_event_updated';
|
||||
|
||||
$ruleids = array();
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace tool_monitor;
|
||||
|
||||
/**
|
||||
* Unit tests for subscription manager api.
|
||||
*
|
||||
@@ -22,17 +24,7 @@
|
||||
* @copyright 2014 onwards Simey Lameze <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
|
||||
/**
|
||||
* Tests for subscription manager.
|
||||
*
|
||||
* Class tool_monitor_subscription_manager_testcase.
|
||||
*/
|
||||
class tool_monitor_subscription_manager_testcase extends advanced_testcase {
|
||||
class subscription_manager_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test count_rule_subscriptions method.
|
||||
@@ -56,7 +48,7 @@ class tool_monitor_subscription_manager_testcase extends advanced_testcase {
|
||||
$this->assertEquals(0, $subs);
|
||||
|
||||
// Subscribe user 1 to rule 1.
|
||||
$record = new stdClass;
|
||||
$record = new \stdClass;
|
||||
$record->ruleid = $rule1->id;
|
||||
$record->userid = $user1->id;
|
||||
$monitorgenerator->create_subscription($record);
|
||||
@@ -75,4 +67,4 @@ class tool_monitor_subscription_manager_testcase extends advanced_testcase {
|
||||
$this->assertEquals(2, $subs1);
|
||||
$this->assertEquals(1, $subs2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
//
|
||||
// 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') || exit();
|
||||
|
||||
namespace tool_monitor;
|
||||
|
||||
/**
|
||||
* Unit tests for the subscription class.
|
||||
@@ -24,7 +25,7 @@ defined('MOODLE_INTERNAL') || exit();
|
||||
* @copyright 2016 Jake Dallimore <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_monitor_subscription_testcase extends advanced_testcase {
|
||||
class subscription_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* @var \tool_monitor\subscription $subscription object.
|
||||
@@ -38,7 +39,7 @@ class tool_monitor_subscription_testcase extends advanced_testcase {
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Create the mock subscription.
|
||||
$sub = new stdClass();
|
||||
$sub = new \stdClass();
|
||||
$sub->id = 100;
|
||||
$sub->name = 'My test rule';
|
||||
$sub->courseid = 20;
|
||||
@@ -62,7 +63,7 @@ class tool_monitor_subscription_testcase extends advanced_testcase {
|
||||
*/
|
||||
public function test_magic_get() {
|
||||
$this->assertEquals(20, $this->subscription->courseid);
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectException(\coding_exception::class);
|
||||
$this->subscription->ruleid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
//
|
||||
// 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') || exit();
|
||||
|
||||
namespace tool_monitor;
|
||||
|
||||
/**
|
||||
* Unit tests for the tool_monitor clean events task.
|
||||
@@ -24,7 +25,7 @@ defined('MOODLE_INTERNAL') || exit();
|
||||
* @copyright 2016 Jake Dallimore <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_monitor_task_check_subscriptions_testcase extends advanced_testcase {
|
||||
class task_check_subscriptions_test extends \advanced_testcase {
|
||||
|
||||
private $course;
|
||||
private $user;
|
||||
@@ -45,7 +46,7 @@ class tool_monitor_task_check_subscriptions_testcase extends advanced_testcase {
|
||||
$this->user = $this->getDataGenerator()->create_user();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
|
||||
$rule = new stdClass();
|
||||
$rule = new \stdClass();
|
||||
$rule->userid = 2; // Rule created by admin.
|
||||
$rule->courseid = $this->course->id;
|
||||
$rule->plugin = 'mod_book';
|
||||
@@ -54,7 +55,7 @@ class tool_monitor_task_check_subscriptions_testcase extends advanced_testcase {
|
||||
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
|
||||
$this->rule = $monitorgenerator->create_rule($rule);
|
||||
|
||||
$sub = new stdClass();
|
||||
$sub = new \stdClass();
|
||||
$sub->courseid = $this->course->id;
|
||||
$sub->userid = $this->user->id;
|
||||
$sub->ruleid = $this->rule->id;
|
||||
@@ -90,7 +91,7 @@ class tool_monitor_task_check_subscriptions_testcase extends advanced_testcase {
|
||||
public function test_site_level_subscription() {
|
||||
// Create a site level subscription.
|
||||
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
|
||||
$sub = new stdClass();
|
||||
$sub = new \stdClass();
|
||||
$sub->userid = $this->user->id;
|
||||
$sub->ruleid = $this->rule->id;
|
||||
$this->subscription = $monitorgenerator->create_subscription($sub);
|
||||
@@ -104,7 +105,7 @@ class tool_monitor_task_check_subscriptions_testcase extends advanced_testcase {
|
||||
$this->assertEquals(false, \tool_monitor\subscription_manager::subscription_is_active($this->subscription));
|
||||
|
||||
// Now, assign the user as a teacher role at system context.
|
||||
$this->getDataGenerator()->role_assign($this->teacherrole->id, $this->user->id, context_system::instance());
|
||||
$this->getDataGenerator()->role_assign($this->teacherrole->id, $this->user->id, \context_system::instance());
|
||||
|
||||
// Run the task.
|
||||
$task = new \tool_monitor\task\check_subscriptions();
|
||||
@@ -238,7 +239,7 @@ class tool_monitor_task_check_subscriptions_testcase extends advanced_testcase {
|
||||
$book = $this->getDataGenerator()->create_module('book', array('course' => $this->course->id));
|
||||
|
||||
// And add a subscription to it.
|
||||
$sub = new stdClass();
|
||||
$sub = new \stdClass();
|
||||
$sub->courseid = $this->course->id;
|
||||
$sub->userid = $this->user->id;
|
||||
$sub->ruleid = $this->rule->id;
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace tool_monitor;
|
||||
|
||||
/**
|
||||
* Unit tests for the tool_monitor clean events task.
|
||||
*
|
||||
@@ -22,15 +24,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 used to test the tool_monitor clean events task.
|
||||
*/
|
||||
class tool_monitor_task_clean_events_testcase extends advanced_testcase {
|
||||
class task_clean_events_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test set up.
|
||||
@@ -51,16 +45,16 @@ class tool_monitor_task_clean_events_testcase extends advanced_testcase {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$bookgenerator = $this->getDataGenerator()->get_plugin_generator('mod_book');
|
||||
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
|
||||
$bookcontext = context_module::instance($book->cmid);
|
||||
$bookcontext = \context_module::instance($book->cmid);
|
||||
$bookchapter = $bookgenerator->create_chapter(array('bookid' => $book->id));
|
||||
$course2 = $this->getDataGenerator()->create_course();
|
||||
$book2 = $this->getDataGenerator()->create_module('book', array('course' => $course2->id));
|
||||
$book2context = context_module::instance($book2->cmid);
|
||||
$book2context = \context_module::instance($book2->cmid);
|
||||
$book2chapter = $bookgenerator->create_chapter(array('bookid' => $book2->id));
|
||||
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
|
||||
|
||||
// Let's set some data for the rules we need before we can generate them.
|
||||
$rule = new stdClass();
|
||||
$rule = new \stdClass();
|
||||
$rule->userid = $user->id;
|
||||
$rule->courseid = $course->id;
|
||||
$rule->plugin = 'mod_book';
|
||||
@@ -96,7 +90,7 @@ class tool_monitor_task_clean_events_testcase extends advanced_testcase {
|
||||
|
||||
|
||||
// Let's subscribe to these rules.
|
||||
$sub = new stdClass;
|
||||
$sub = new \stdClass;
|
||||
$sub->courseid = $course->id;
|
||||
$sub->ruleid = $rule1->id;
|
||||
$sub->userid = $user->id;
|
||||
@@ -133,7 +127,7 @@ class tool_monitor_task_clean_events_testcase extends advanced_testcase {
|
||||
|
||||
// Trigger a bunch of other events.
|
||||
$eventparams = array(
|
||||
'context' => context_course::instance($course->id)
|
||||
'context' => \context_course::instance($course->id)
|
||||
);
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
\mod_quiz\event\course_module_instance_list_viewed::create($eventparams)->trigger();
|
||||
@@ -164,7 +158,7 @@ class tool_monitor_task_clean_events_testcase extends advanced_testcase {
|
||||
$this->assertEquals($course2->id, $event4->courseid);
|
||||
|
||||
// Update the timewindow for two of the rules.
|
||||
$updaterule = new stdClass();
|
||||
$updaterule = new \stdClass();
|
||||
$updaterule->id = $rule1->id;
|
||||
$updaterule->timewindow = 0;
|
||||
\tool_monitor\rule_manager::update_rule($updaterule);
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace tool_moodlenet;
|
||||
|
||||
/**
|
||||
* Unit tests for the import_backup_helper
|
||||
*
|
||||
@@ -22,15 +24,7 @@
|
||||
* @copyright 2020 Adrian Greeve <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
|
||||
/**
|
||||
* Class import_backup_helper tests
|
||||
*/
|
||||
class tool_moodlenet_import_backup_helper_testcase extends advanced_testcase {
|
||||
class import_backup_helper_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test that the first available context with the capability to upload backup files is returned.
|
||||
@@ -47,7 +41,7 @@ class tool_moodlenet_import_backup_helper_testcase extends advanced_testcase {
|
||||
$user5 = $this->getDataGenerator()->create_user();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
$coursecontext = \context_course::instance($course->id);
|
||||
|
||||
$this->getDataGenerator()->enrol_user($user1->id, $course->id, 'student');
|
||||
$this->getDataGenerator()->enrol_user($user2->id, $course->id, 'editingteacher');
|
||||
@@ -55,12 +49,12 @@ class tool_moodlenet_import_backup_helper_testcase extends advanced_testcase {
|
||||
|
||||
$category = $this->getDataGenerator()->create_category();
|
||||
$rolerecord = $DB->get_record('role', ['shortname' => 'manager']);
|
||||
$categorycontext = context_coursecat::instance($category->id);
|
||||
$categorycontext = \context_coursecat::instance($category->id);
|
||||
$this->getDataGenerator()->role_assign($rolerecord->id, $user3->id, $categorycontext->id);
|
||||
$this->getDataGenerator()->role_assign($rolerecord->id, $user5->id, $categorycontext->id);
|
||||
|
||||
$roleid = $this->getDataGenerator()->create_role();
|
||||
$sitecontext = context_system::instance();
|
||||
$sitecontext = \context_system::instance();
|
||||
assign_capability('moodle/restore:uploadfile', CAP_ALLOW, $roleid, $sitecontext->id, true);
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
$this->getDataGenerator()->role_assign($roleid, $user4->id, $sitecontext->id);
|
||||
@@ -81,4 +75,4 @@ class tool_moodlenet_import_backup_helper_testcase extends advanced_testcase {
|
||||
$this->assertEquals(CONTEXT_COURSECAT, $result->contextlevel);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace tool_moodlenet;
|
||||
|
||||
/**
|
||||
* Unit tests for the profile manager
|
||||
*
|
||||
@@ -22,15 +24,7 @@
|
||||
* @copyright 2020 Adrian Greeve <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
|
||||
/**
|
||||
* Class profile_manager tests
|
||||
*/
|
||||
class tool_moodlenet_profile_manager_testcase extends advanced_testcase {
|
||||
class profile_manager_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test that on this site we use the user table to hold moodle net profile information.
|
||||
@@ -57,7 +51,7 @@ class tool_moodlenet_profile_manager_testcase extends advanced_testcase {
|
||||
$this->resetAfterTest();
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
|
||||
$this->expectException(moodle_exception::class);
|
||||
$this->expectException(\moodle_exception::class);
|
||||
$this->expectExceptionMessage(get_string('invalidmoodlenetprofile', 'tool_moodlenet'));
|
||||
$result = new \tool_moodlenet\moodlenet_user_profile("", $user->id);
|
||||
}
|
||||
|
||||
@@ -14,31 +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/>.
|
||||
|
||||
/**
|
||||
* Provides the {@link tool_policy_sitepolicy_handler_testcase} class.
|
||||
*
|
||||
* @package tool_policy
|
||||
* @category test
|
||||
* @copyright 2018 David Mudrák <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_policy;
|
||||
|
||||
use tool_policy\api;
|
||||
use tool_policy\policy_version;
|
||||
use tool_policy\privacy\local\sitepolicy\handler;
|
||||
use tool_policy\test\helper;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link \tool_policy\privacy\local\sitepolicy\handler} class.
|
||||
*
|
||||
* @package tool_policy
|
||||
* @category test
|
||||
* @copyright 2018 David Mudrak <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_policy_sitepolicy_handler_testcase extends advanced_testcase {
|
||||
class sitepolicy_handler_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test behaviour of the {@link \tool_policy\privacy\local\sitepolicy\handler::get_redirect_url()} method.
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Recycle bin tests.
|
||||
*
|
||||
* @package tool_recyclebin
|
||||
* @copyright 2015 University of Kent
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace tool_recyclebin;
|
||||
|
||||
/**
|
||||
* Recycle bin category tests.
|
||||
@@ -31,15 +23,15 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2015 University of Kent
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_recyclebin_category_bin_tests extends advanced_testcase {
|
||||
class category_bin_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* @var stdClass $course
|
||||
* @var \stdClass $course
|
||||
*/
|
||||
protected $course;
|
||||
|
||||
/**
|
||||
* @var stdClass $coursebeingrestored
|
||||
* @var \stdClass $coursebeingrestored
|
||||
*/
|
||||
protected $coursebeingrestored;
|
||||
|
||||
@@ -96,7 +88,7 @@ class tool_recyclebin_category_bin_tests extends advanced_testcase {
|
||||
$this->assertEquals(1, $DB->count_records('tool_recyclebin_category'));
|
||||
|
||||
// Now let's delete the course category.
|
||||
$category = core_course_category::get($this->course->category);
|
||||
$category = \core_course_category::get($this->course->category);
|
||||
$category->delete_full(false);
|
||||
|
||||
// Check that the course was deleted from the category recycle bin.
|
||||
@@ -242,7 +234,7 @@ class tool_recyclebin_category_bin_tests extends advanced_testcase {
|
||||
$this->assertEquals(0, count($recyclebin->get_items()));
|
||||
|
||||
// Verify that student DOES continue enrolled.
|
||||
$this->assertTrue(is_enrolled(context_course::instance($newcourse->id), $student->id));
|
||||
$this->assertTrue(is_enrolled(\context_course::instance($newcourse->id), $student->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,6 +278,6 @@ class tool_recyclebin_category_bin_tests extends advanced_testcase {
|
||||
$this->assertEquals(0, count($recyclebin->get_items()));
|
||||
|
||||
// Verify that student DOES NOT continue enrolled.
|
||||
$this->assertFalse(is_enrolled(context_course::instance($newcourse->id), $student->id));
|
||||
$this->assertFalse(is_enrolled(\context_course::instance($newcourse->id), $student->id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Recycle bin tests.
|
||||
*
|
||||
* @package tool_recyclebin
|
||||
* @copyright 2015 University of Kent
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace tool_recyclebin;
|
||||
|
||||
/**
|
||||
* Recycle bin course tests.
|
||||
@@ -31,10 +23,10 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2015 University of Kent
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_recyclebin_course_bin_tests extends advanced_testcase {
|
||||
class course_bin_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* @var stdClass $course
|
||||
* @var \stdClass $course
|
||||
*/
|
||||
protected $course;
|
||||
|
||||
@@ -72,7 +64,7 @@ class tool_recyclebin_course_bin_tests extends advanced_testcase {
|
||||
course_delete_module($this->quiz->cmid);
|
||||
|
||||
// Now, run the course module deletion adhoc task.
|
||||
phpunit_util::run_all_adhoc_tasks();
|
||||
\phpunit_util::run_all_adhoc_tasks();
|
||||
|
||||
// Check the course module is now in the recycle bin.
|
||||
$this->assertEquals(1, $DB->count_records('tool_recyclebin_course'));
|
||||
@@ -116,7 +108,7 @@ class tool_recyclebin_course_bin_tests extends advanced_testcase {
|
||||
course_delete_module($this->quiz->cmid);
|
||||
|
||||
// Now, run the course module deletion adhoc task.
|
||||
phpunit_util::run_all_adhoc_tasks();
|
||||
\phpunit_util::run_all_adhoc_tasks();
|
||||
|
||||
// Try purging.
|
||||
$recyclebin = new \tool_recyclebin\course_bin($this->course->id);
|
||||
@@ -141,7 +133,7 @@ class tool_recyclebin_course_bin_tests extends advanced_testcase {
|
||||
course_delete_module($this->quiz->cmid);
|
||||
|
||||
// Now, run the course module deletion adhoc task.
|
||||
phpunit_util::run_all_adhoc_tasks();
|
||||
\phpunit_util::run_all_adhoc_tasks();
|
||||
|
||||
// Set deleted date to the distant past.
|
||||
$recyclebin = new \tool_recyclebin\course_bin($this->course->id);
|
||||
@@ -157,7 +149,7 @@ class tool_recyclebin_course_bin_tests extends advanced_testcase {
|
||||
course_delete_module($book->cmid);
|
||||
|
||||
// Now, run the course module deletion adhoc task.
|
||||
phpunit_util::run_all_adhoc_tasks();
|
||||
\phpunit_util::run_all_adhoc_tasks();
|
||||
|
||||
// Should have 2 items now.
|
||||
$this->assertEquals(2, count($recyclebin->get_items()));
|
||||
@@ -223,7 +215,7 @@ class tool_recyclebin_course_bin_tests extends advanced_testcase {
|
||||
// Delete quiz.
|
||||
$cm = get_coursemodule_from_instance('quiz', $this->quiz->id);
|
||||
course_delete_module($cm->id);
|
||||
phpunit_util::run_all_adhoc_tasks();
|
||||
\phpunit_util::run_all_adhoc_tasks();
|
||||
$quizzes = get_coursemodules_in_course('quiz', $this->course->id);
|
||||
$this->assertEquals(0, count($quizzes));
|
||||
|
||||
@@ -240,7 +232,7 @@ class tool_recyclebin_course_bin_tests extends advanced_testcase {
|
||||
$attempts = quiz_get_user_attempts($cm->instance, $student->id);
|
||||
$this->assertEquals(1, count($attempts));
|
||||
$attempt = array_pop($attempts);
|
||||
$attemptobj = quiz_attempt::create($attempt->id);
|
||||
$attemptobj = \quiz_attempt::create($attempt->id);
|
||||
$this->assertEquals($student->id, $attemptobj->get_userid());
|
||||
$this->assertEquals(true, $attemptobj->is_finished());
|
||||
}
|
||||
@@ -270,7 +262,7 @@ class tool_recyclebin_course_bin_tests extends advanced_testcase {
|
||||
// Delete quiz.
|
||||
$cm = get_coursemodule_from_instance('quiz', $this->quiz->id);
|
||||
course_delete_module($cm->id);
|
||||
phpunit_util::run_all_adhoc_tasks();
|
||||
\phpunit_util::run_all_adhoc_tasks();
|
||||
$quizzes = get_coursemodules_in_course('quiz', $this->course->id);
|
||||
$this->assertEquals(0, count($quizzes));
|
||||
|
||||
@@ -303,17 +295,17 @@ class tool_recyclebin_course_bin_tests extends advanced_testcase {
|
||||
quiz_add_quiz_question($numq->id, $quiz);
|
||||
|
||||
// Create quiz attempt.
|
||||
$quizobj = quiz::create($quiz->id, $student->id);
|
||||
$quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
|
||||
$quizobj = \quiz::create($quiz->id, $student->id);
|
||||
$quba = \question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
|
||||
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
|
||||
$timenow = time();
|
||||
$attempt = quiz_create_attempt($quizobj, 1, false, $timenow, false, $student->id);
|
||||
quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow);
|
||||
quiz_attempt_save_started($quizobj, $quba, $attempt);
|
||||
$attemptobj = quiz_attempt::create($attempt->id);
|
||||
$attemptobj = \quiz_attempt::create($attempt->id);
|
||||
$tosubmit = array(1 => array('answer' => '0'));
|
||||
$attemptobj->process_submitted_actions($timenow, false, $tosubmit);
|
||||
$attemptobj = quiz_attempt::create($attempt->id);
|
||||
$attemptobj = \quiz_attempt::create($attempt->id);
|
||||
$attemptobj->process_finish($timenow, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,26 +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/>.
|
||||
|
||||
/**
|
||||
* File containing tests for the mform class.
|
||||
*
|
||||
* @package tool_task
|
||||
* @copyright 2014 onwards Ankit Agarwal <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
namespace tool_task;
|
||||
|
||||
/**
|
||||
* Mform test class.
|
||||
* Test for the task mform class.
|
||||
*
|
||||
* @package tool_task
|
||||
* @copyright 2014 onwards Ankit Agarwal <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late
|
||||
*/
|
||||
class tool_task_form_testcase extends advanced_testcase {
|
||||
class form_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test validations for minute field.
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Tests for CLI tool_uploaduser.
|
||||
*
|
||||
* @package tool_uploaduser
|
||||
* @copyright 2020 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use \tool_uploaduser\cli_helper;
|
||||
namespace tool_uploaduser;
|
||||
|
||||
/**
|
||||
* Tests for CLI tool_uploaduser.
|
||||
@@ -31,7 +23,7 @@ use \tool_uploaduser\cli_helper;
|
||||
* @copyright 2020 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_uploaduser_cli_testcase extends advanced_testcase {
|
||||
class cli_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Generate cli_helper and mock $_SERVER['argv']
|
||||
@@ -117,7 +109,7 @@ class tool_uploaduser_cli_testcase extends advanced_testcase {
|
||||
$this->assertEquals('Users created: 2', $stats[0]);
|
||||
|
||||
// Users have default values applied.
|
||||
$user1 = core_user::get_user_by_username('jonest');
|
||||
$user1 = \core_user::get_user_by_username('jonest');
|
||||
$this->assertEquals('Brighton', $user1->city);
|
||||
$this->assertEquals('Purchasing', $user1->department);
|
||||
}
|
||||
@@ -149,7 +141,7 @@ class tool_uploaduser_cli_testcase extends advanced_testcase {
|
||||
$this->assertEquals('Users created: 2', $stats[0]);
|
||||
|
||||
// Created users have data in the profile fields.
|
||||
$user1 = core_user::get_user_by_username('reznort');
|
||||
$user1 = \core_user::get_user_by_username('reznort');
|
||||
$profilefields1 = profile_user_record($user1->id);
|
||||
$this->assertEquals((object)['superfield' => 'Loves cats'], $profilefields1);
|
||||
}
|
||||
@@ -244,9 +236,9 @@ class tool_uploaduser_cli_testcase extends advanced_testcase {
|
||||
$enrols = array_values(enrol_get_course_users($course->id));
|
||||
$this->assertEqualsCanonicalizing(['jonest'], [$enrols[0]->username]);
|
||||
// User reznor is not created.
|
||||
$this->assertFalse(core_user::get_user_by_username('reznor'));
|
||||
$this->assertFalse(\core_user::get_user_by_username('reznor'));
|
||||
// User jonest is not updated.
|
||||
$this->assertEquals('OLDNAME', core_user::get_user_by_username('jonest')->firstname);
|
||||
$this->assertEquals('OLDNAME', \core_user::get_user_by_username('jonest')->firstname);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,8 +279,8 @@ class tool_uploaduser_cli_testcase extends advanced_testcase {
|
||||
$enrols = array_values(enrol_get_course_users($course->id));
|
||||
$this->assertEqualsCanonicalizing(['jonest'], [$enrols[0]->username]);
|
||||
// User reznor is not created.
|
||||
$this->assertFalse(core_user::get_user_by_username('reznor'));
|
||||
$this->assertFalse(\core_user::get_user_by_username('reznor'));
|
||||
// User jonest is updated, new first name is Tom.
|
||||
$this->assertEquals('Tom', core_user::get_user_by_username('jonest')->firstname);
|
||||
$this->assertEquals('Tom', \core_user::get_user_by_username('jonest')->firstname);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,20 +14,10 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Tests for field value validators of tool_uploaduser.
|
||||
*
|
||||
* @package tool_uploaduser
|
||||
* @copyright 2019 Jun Pataleta
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_uploaduser;
|
||||
|
||||
use tool_uploaduser\local\field_value_validators;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
|
||||
/**
|
||||
* Tests for field value validators of tool_uploaduser.
|
||||
*
|
||||
@@ -35,7 +25,7 @@ global $CFG;
|
||||
* @copyright 2019 Jun Pataleta
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class field_value_validators_testcase extends advanced_testcase {
|
||||
class field_value_validators_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Data provider for \field_value_validators_testcase::test_validate_theme().
|
||||
|
||||
@@ -14,17 +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/>.
|
||||
|
||||
/**
|
||||
* Tests for time filter.
|
||||
*
|
||||
* @package tool_usertours
|
||||
* @copyright 2019 Tom Dickman <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_usertours;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use tool_usertours\tour;
|
||||
use tool_usertours\local\filter\accessdate;
|
||||
|
||||
/**
|
||||
@@ -34,7 +25,7 @@ use tool_usertours\local\filter\accessdate;
|
||||
* @copyright 2019 Tom Dickman <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_usertours_accessdate_filter_test extends advanced_testcase {
|
||||
class accessdate_filter_test extends \advanced_testcase {
|
||||
|
||||
public function setUp(): void {
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Tests for role filter.
|
||||
*
|
||||
* @package tool_usertours
|
||||
* @copyright 2016 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace tool_usertours;
|
||||
|
||||
/**
|
||||
* Tests for role filter.
|
||||
@@ -31,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2016 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_usertours_role_filter_testcase extends advanced_testcase {
|
||||
class role_filter_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* @var $course Test course
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Tests for theme filter.
|
||||
*
|
||||
* @package tool_usertours
|
||||
* @copyright 2016 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace tool_usertours;
|
||||
|
||||
/**
|
||||
* Tests for theme filter.
|
||||
@@ -31,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2016 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_usertours_theme_filter_testcase extends advanced_testcase {
|
||||
class theme_filter_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Data Provider for filter_matches function.
|
||||
|
||||
@@ -14,21 +14,13 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Tests for tour.
|
||||
*
|
||||
* @package tool_usertours
|
||||
* @copyright 2016 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_usertours;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
|
||||
use tool_usertours\tour;
|
||||
|
||||
/**
|
||||
* Tests for tour.
|
||||
*
|
||||
@@ -36,7 +28,7 @@ use tool_usertours\tour;
|
||||
* @copyright 2016 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tour_testcase extends advanced_testcase {
|
||||
class tour_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* @var moodle_database
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace auth_db;
|
||||
|
||||
/**
|
||||
* External database auth sync tests, this also tests adodb drivers
|
||||
* that are matching our four supported Moodle database drivers.
|
||||
@@ -23,11 +25,7 @@
|
||||
* @copyright 2012 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
class auth_db_testcase extends advanced_testcase {
|
||||
class db_test extends \advanced_testcase {
|
||||
/** @var string Original error log */
|
||||
protected $oldlog;
|
||||
|
||||
@@ -123,7 +121,7 @@ class auth_db_testcase extends advanced_testcase {
|
||||
throw new exception('Unknown database family ' . $DB->get_dbfamily());
|
||||
}
|
||||
|
||||
$table = new xmldb_table('auth_db_users');
|
||||
$table = new \xmldb_table('auth_db_users');
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null);
|
||||
$table->add_field('pass', XMLDB_TYPE_CHAR, '255', null, null, null);
|
||||
@@ -168,7 +166,7 @@ class auth_db_testcase extends advanced_testcase {
|
||||
global $DB;
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
$table = new xmldb_table('auth_db_users');
|
||||
$table = new \xmldb_table('auth_db_users');
|
||||
$dbman->drop_table($table);
|
||||
|
||||
ini_set('error_log', $this->oldlog);
|
||||
@@ -222,7 +220,7 @@ class auth_db_testcase extends advanced_testcase {
|
||||
|
||||
$this->assertCount(2, $DB->get_records('user'));
|
||||
|
||||
$trace = new null_progress_trace();
|
||||
$trace = new \null_progress_trace();
|
||||
|
||||
// Sync users and make sure that two events user_created werer triggered.
|
||||
$sink = $this->redirectEvents();
|
||||
@@ -483,7 +481,7 @@ class auth_db_testcase extends advanced_testcase {
|
||||
$extdbuser3 = (object)array('name'=>'u3', 'pass'=>'heslo', 'email'=>'[email protected]',
|
||||
'lastname' => 'user<script>alert(1);</script>xss');
|
||||
$extdbuser3->id = $DB->insert_record('auth_db_users', $extdbuser3);
|
||||
$trace = new null_progress_trace();
|
||||
$trace = new \null_progress_trace();
|
||||
|
||||
// Let's test user sync make sure still works as expected..
|
||||
$auth->sync_users($trace, true);
|
||||
@@ -529,7 +527,7 @@ class auth_db_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
// Sync to moodle.
|
||||
$trace = new null_progress_trace();
|
||||
$trace = new \null_progress_trace();
|
||||
$auth->sync_users($trace, true);
|
||||
|
||||
// Check user is there.
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Manual authentication tests.
|
||||
*
|
||||
* @package auth_manual
|
||||
* @category test
|
||||
* @copyright 2014 Gilles-Philippe Leblanc <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace auth_manual;
|
||||
|
||||
use auth_plugin_manual;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -36,7 +31,7 @@ require_once($CFG->dirroot.'/auth/manual/auth.php');
|
||||
* @copyright 2014 Gilles-Philippe Leblanc <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class auth_manual_testcase extends advanced_testcase {
|
||||
class manual_test extends \advanced_testcase {
|
||||
|
||||
/** @var auth_plugin_manual Keeps the authentication plugin. */
|
||||
protected $authplugin;
|
||||
|
||||
@@ -14,26 +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 auth_oauth2;
|
||||
|
||||
/**
|
||||
* Auth oauth2 auth functions tests.
|
||||
*
|
||||
* @package auth_oauth2
|
||||
* @category test
|
||||
* @copyright 2019 Shamim Rezaie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
|
||||
/**
|
||||
* Tests for the \auth_oauth2\auth class.
|
||||
*
|
||||
* @copyright 2019 Shamim Rezaie
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class auth_oauth2_auth_testcase extends advanced_testcase {
|
||||
class auth_test extends \advanced_testcase {
|
||||
|
||||
public function test_get_password_change_info() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Unit tests for core_auth\digital_consent.
|
||||
*
|
||||
* @package core_auth
|
||||
* @copyright 2018 Mihail Geshoski
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace core_auth;
|
||||
|
||||
/**
|
||||
* Digital consent helper testcase.
|
||||
@@ -31,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2018 Mihail Geshoski
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_auth_digital_consent_testcase extends advanced_testcase {
|
||||
class digital_consent_test extends \advanced_testcase {
|
||||
|
||||
public function test_is_age_digital_consent_verification_enabled() {
|
||||
global $CFG;
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the capability checker class.
|
||||
*
|
||||
* @package core_availability
|
||||
* @copyright 2014 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use core_availability\capability_checker;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace core_availability;
|
||||
|
||||
/**
|
||||
* Unit tests for the capability checker class.
|
||||
@@ -33,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2014 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_availability_capability_checker_testcase extends advanced_testcase {
|
||||
class capability_checker_test extends \advanced_testcase {
|
||||
/**
|
||||
* Tests loading a class from /availability/classes.
|
||||
*/
|
||||
@@ -51,7 +41,7 @@ class core_availability_capability_checker_testcase extends advanced_testcase {
|
||||
$generator->enrol_user($student->id, $course->id, $roleids['student']);
|
||||
|
||||
// Check a capability which they both have.
|
||||
$context = context_course::instance($course->id);
|
||||
$context = \context_course::instance($course->id);
|
||||
$checker = new capability_checker($context);
|
||||
$result = array_keys($checker->get_users_by_capability('mod/forum:replypost'));
|
||||
sort($result);
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the component and plugin definitions for availability system.
|
||||
*
|
||||
* @package core_availability
|
||||
* @copyright 2014 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace core_availability;
|
||||
|
||||
/**
|
||||
* Unit tests for the component and plugin definitions for availability system.
|
||||
@@ -31,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2014 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_availability_component_testcase extends advanced_testcase {
|
||||
class component_test extends \advanced_testcase {
|
||||
/**
|
||||
* Tests loading a class from /availability/classes.
|
||||
*/
|
||||
@@ -47,7 +39,7 @@ class core_availability_component_testcase extends advanced_testcase {
|
||||
// This code will throw debugging information if the plugininfo class
|
||||
// is missing. Unfortunately it doesn't actually cause the test to
|
||||
// fail, but it's obvious when running test at least.
|
||||
$pluginmanager = core_plugin_manager::instance();
|
||||
$pluginmanager = \core_plugin_manager::instance();
|
||||
$list = $pluginmanager->get_enabled_plugins('availability');
|
||||
$this->assertArrayHasKey('completion', $list);
|
||||
$this->assertArrayHasKey('date', $list);
|
||||
|
||||
@@ -14,19 +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 info and subclasses.
|
||||
*
|
||||
* @package core_availability
|
||||
* @copyright 2014 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core_availability\info;
|
||||
use core_availability\info_module;
|
||||
use core_availability\info_section;
|
||||
namespace core_availability;
|
||||
|
||||
/**
|
||||
* Unit tests for info and subclasses.
|
||||
@@ -35,7 +23,7 @@ use core_availability\info_section;
|
||||
* @copyright 2014 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class info_testcase extends advanced_testcase {
|
||||
class info_test extends \advanced_testcase {
|
||||
public function setUp(): void {
|
||||
// Load the mock condition so that it can be used.
|
||||
require_once(__DIR__ . '/fixtures/mock_condition.php');
|
||||
@@ -491,7 +479,7 @@ class info_testcase extends advanced_testcase {
|
||||
|
||||
// If the students have viewhiddenactivities, they get past the module
|
||||
// restriction.
|
||||
role_change_permission($studentroleid, context_module::instance($page2->cmid),
|
||||
role_change_permission($studentroleid, \context_module::instance($page2->cmid),
|
||||
'moodle/course:ignoreavailabilityrestrictions', CAP_ALLOW);
|
||||
$expected = array($u1->id, $u2->id);
|
||||
$this->assertEquals($expected, array_keys($info->filter_user_list($allusers)));
|
||||
@@ -502,7 +490,7 @@ class info_testcase extends advanced_testcase {
|
||||
|
||||
// If they have viewhiddensections, they also get past the section
|
||||
// restriction.
|
||||
role_change_permission($studentroleid, context_course::instance($course->id),
|
||||
role_change_permission($studentroleid, \context_course::instance($course->id),
|
||||
'moodle/course:ignoreavailabilityrestrictions', CAP_ALLOW);
|
||||
$expected = array($u1->id, $u2->id, $u3->id);
|
||||
$this->assertEquals($expected, array_keys($info->filter_user_list($allusers)));
|
||||
|
||||
@@ -14,18 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the condition tree class and related logic.
|
||||
*
|
||||
* @package core_availability
|
||||
* @copyright 2014 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use core_availability\capability_checker;
|
||||
use \core_availability\tree;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace core_availability;
|
||||
|
||||
/**
|
||||
* Unit tests for the condition tree class and related logic.
|
||||
@@ -34,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2014 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tree_testcase extends \advanced_testcase {
|
||||
class tree_test extends \advanced_testcase {
|
||||
public function setUp(): void {
|
||||
// Load the mock classes so they can be used.
|
||||
require_once(__DIR__ . '/fixtures/mock_condition.php');
|
||||
@@ -48,83 +37,83 @@ class tree_testcase extends \advanced_testcase {
|
||||
try {
|
||||
new tree('frog');
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('not object', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array());
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('missing ->op', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '*'));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('unknown ->op', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '|'));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('missing ->show', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '|', 'show' => 0));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('->show not bool', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '&'));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('missing ->showc', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '&', 'showc' => 0));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('->showc not array', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '&', 'showc' => array(0)));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('->showc value not bool', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '|', 'show' => true));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('missing ->c', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '|', 'show' => true,
|
||||
'c' => 'side'));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('->c not array', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '|', 'show' => true,
|
||||
'c' => array(3)));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('child not object', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '|', 'show' => true,
|
||||
'c' => array((object)array('type' => 'doesnotexist'))));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('Unknown condition type: doesnotexist', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '|', 'show' => true,
|
||||
'c' => array((object)array())));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('missing ->op', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
@@ -133,7 +122,7 @@ class tree_testcase extends \advanced_testcase {
|
||||
'showc' => array(true, true)
|
||||
));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('->c, ->showc mismatch', $e->getMessage());
|
||||
}
|
||||
}
|
||||
@@ -336,7 +325,7 @@ class tree_testcase extends \advanced_testcase {
|
||||
/**
|
||||
* Shortcut function to check availability and also get information.
|
||||
*
|
||||
* @param stdClass $structure Tree structure
|
||||
* @param \stdClass $structure Tree structure
|
||||
* @param \core_availability\info $info Location info
|
||||
* @param int $userid User id
|
||||
*/
|
||||
@@ -355,7 +344,7 @@ class tree_testcase extends \advanced_testcase {
|
||||
/**
|
||||
* Shortcut function to render the full availability information.
|
||||
*
|
||||
* @param stdClass $structure Tree structure
|
||||
* @param \stdClass $structure Tree structure
|
||||
* @param \core_availability\info $info Location info
|
||||
*/
|
||||
protected function render_full_information($structure, \core_availability\info $info) {
|
||||
|
||||
@@ -16,22 +16,33 @@
|
||||
|
||||
/**
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_backup;
|
||||
|
||||
use backup;
|
||||
use backup_controller;
|
||||
use restore_controller;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// Include all the needed stuff
|
||||
// Include all the needed stuff.
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
|
||||
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
|
||||
|
||||
/*
|
||||
* controller tests (all)
|
||||
/**
|
||||
* Tests for the backup and restore controller classes.
|
||||
*
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_backup_controller_testcase extends advanced_testcase {
|
||||
class controller_test extends \advanced_testcase {
|
||||
|
||||
protected $moduleid; // course_modules id used for testing
|
||||
protected $sectionid; // course_sections id used for testing
|
||||
|
||||
@@ -14,23 +14,33 @@
|
||||
// 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 moodle1 converter
|
||||
*
|
||||
* @package core_backup
|
||||
* @subpackage backup-convert
|
||||
* @category phpunit
|
||||
* @copyright 2011 Mark Nielsen <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use backup;
|
||||
use convert_path;
|
||||
use convert_path_exception;
|
||||
use convert_factory;
|
||||
use convert_helper;
|
||||
use moodle1_converter;
|
||||
use moodle1_convert_empty_storage_exception;
|
||||
use moodle1_convert_exception;
|
||||
use moodle1_convert_storage_exception;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/backup/converter/moodle1/lib.php');
|
||||
|
||||
|
||||
class core_backup_moodle1_converter_testcase extends advanced_testcase {
|
||||
/**
|
||||
* Unit tests for the moodle1 converter
|
||||
*
|
||||
* @package core_backup
|
||||
* @subpackage backup-convert
|
||||
* @category test
|
||||
* @copyright 2011 Mark Nielsen <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class moodle1_converter_test extends \advanced_testcase {
|
||||
|
||||
/** @var string the name of the directory containing the unpacked Moodle 1.9 backup */
|
||||
protected $tempdir;
|
||||
@@ -68,7 +78,7 @@ class core_backup_moodle1_converter_testcase extends advanced_testcase {
|
||||
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
|
||||
"$this->tempdirpath/moddata/unittest/4/icon.gif"
|
||||
);
|
||||
$this->iconhash = file_storage::hash_from_path($this->tempdirpath.'/moddata/unittest/4/icon.gif');
|
||||
$this->iconhash = \file_storage::hash_from_path($this->tempdirpath.'/moddata/unittest/4/icon.gif');
|
||||
copy(
|
||||
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
|
||||
"$this->tempdirpath/moddata/unittest/4/7/icon.gif"
|
||||
@@ -351,8 +361,8 @@ class core_backup_moodle1_converter_testcase extends advanced_testcase {
|
||||
$this->assertEquals('array', gettype($files['/file1.gif']));
|
||||
$this->assertEquals('array', gettype($files['/sub1/.']));
|
||||
$this->assertEquals('array', gettype($files['/sub1/file2.gif']));
|
||||
$this->assertEquals(file_storage::hash_from_string(''), $files['/.']['contenthash']);
|
||||
$this->assertEquals(file_storage::hash_from_string(''), $files['/sub1/.']['contenthash']);
|
||||
$this->assertEquals(\file_storage::hash_from_string(''), $files['/.']['contenthash']);
|
||||
$this->assertEquals(\file_storage::hash_from_string(''), $files['/sub1/.']['contenthash']);
|
||||
$this->assertEquals($this->iconhash, $files['/file1.gif']['contenthash']);
|
||||
$this->assertEquals($this->iconhash, $files['/sub1/file2.gif']['contenthash']);
|
||||
|
||||
|
||||
@@ -14,13 +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/>.
|
||||
|
||||
/**
|
||||
* Tests for the handling of encrypted contents in backup and restore.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2016 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use backup;
|
||||
use base_element_struct_exception;
|
||||
use encrypted_final_element;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -29,7 +27,14 @@ require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
|
||||
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
|
||||
require_once($CFG->dirroot . '/backup/moodle2/backup_custom_fields.php');
|
||||
|
||||
class core_backup_encrypted_content_testscase extends advanced_testcase {
|
||||
/**
|
||||
* Tests for the handling of encrypted contents in backup and restore.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2016 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backup_encrypted_content_test extends \advanced_testcase {
|
||||
|
||||
public function setUp(): void {
|
||||
if (!function_exists('openssl_encrypt')) {
|
||||
@@ -64,7 +69,7 @@ class core_backup_encrypted_content_testscase extends advanced_testcase {
|
||||
set_config('backup_encryptkey', base64_encode($key), 'backup');
|
||||
$efe->set_value('tiny_secret');
|
||||
$this->fail('Expecting base_element_struct_exception exception, none happened');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('base_element_struct_exception', $e);
|
||||
$this->assertEquals('encrypted_final_element incorrect key length', $e->errorcode);
|
||||
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Tests for backup_xml_transformer class.
|
||||
*
|
||||
* @package core_backup
|
||||
* @subpackage moodle2
|
||||
* @category backup
|
||||
* @copyright 2017 Dmitrii Metelkin ([email protected])
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use backup_xml_transformer;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -34,10 +28,12 @@ require_once($CFG->dirroot . '/backup/moodle2/backup_plan_builder.class.php');
|
||||
* Tests for backup_xml_transformer.
|
||||
*
|
||||
* @package core_backup
|
||||
* @subpackage moodle2
|
||||
* @category test
|
||||
* @copyright 2017 Dmitrii Metelkin ([email protected])
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backup_xml_transformer_testcase extends advanced_testcase {
|
||||
class backup_xml_transformer_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Initial set up.
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
// This file is part of Moodle - https://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// 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
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Various fixture course formats for backup unit tests
|
||||
*
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2022 onwards Eloy Lafuente (stronk7) {@link https://stronk7.com}
|
||||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/course/format/topics/lib.php');
|
||||
|
||||
/**
|
||||
* Fixture course format with one option.
|
||||
*/
|
||||
class format_test_cs_options extends format_topics {
|
||||
/**
|
||||
* Override method format_topics::get_default_section_name to prevent PHPUnit errors related to the nonexistent
|
||||
* format_test_cs_options lang file.
|
||||
*
|
||||
* @param \stdClass $section The section in question.
|
||||
* @return string The section's name for display.
|
||||
*/
|
||||
public function get_default_section_name($section) {
|
||||
if ($section->section == 0) {
|
||||
return parent::get_default_section_name($section);
|
||||
} else {
|
||||
return get_string('sectionname', 'format_topics') . ' ' . $section->section;
|
||||
}
|
||||
}
|
||||
|
||||
public function section_format_options($foreditform = false) {
|
||||
return array(
|
||||
'numdaystocomplete' => array(
|
||||
'type' => PARAM_INT,
|
||||
'label' => 'Test days',
|
||||
'element_type' => 'text',
|
||||
'default' => 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixture course format with 2 options, 1 inherited.
|
||||
*/
|
||||
class format_test_cs2_options extends format_test_cs_options {
|
||||
public function section_format_options($foreditform = false) {
|
||||
return array(
|
||||
'numdaystocomplete' => array(
|
||||
'type' => PARAM_INT,
|
||||
'label' => 'Test days',
|
||||
'element_type' => 'text',
|
||||
'default' => 0,
|
||||
),
|
||||
'secondparameter' => array(
|
||||
'type' => PARAM_INT,
|
||||
'label' => 'Test Parmater',
|
||||
'element_type' => 'text',
|
||||
'default' => 0,
|
||||
),
|
||||
) + parent::section_format_options($foreditform);
|
||||
}
|
||||
}
|
||||
@@ -14,13 +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/>.
|
||||
|
||||
/**
|
||||
* Tests for Moodle 2 format backup operation.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2014 Russell Smith
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use backup;
|
||||
use backup_controller;
|
||||
use restore_dbops;
|
||||
use restore_controller;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -29,6 +28,7 @@ require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
|
||||
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
|
||||
require_once($CFG->dirroot . '/course/format/topics/lib.php');
|
||||
require_once($CFG->libdir . '/completionlib.php');
|
||||
require_once($CFG->dirroot . '/backup/moodle2/tests/fixtures/format_test_cs_options.php');
|
||||
|
||||
/**
|
||||
* Tests for Moodle 2 course format section_options backup operation.
|
||||
@@ -37,7 +37,7 @@ require_once($CFG->libdir . '/completionlib.php');
|
||||
* @copyright 2014 Russell Smith
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_backup_moodle2_course_format_testcase extends advanced_testcase {
|
||||
class moodle2_course_format_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests a backup and restore adds the required section option data
|
||||
@@ -58,7 +58,7 @@ class core_backup_moodle2_course_format_testcase extends advanced_testcase {
|
||||
'enablecompletion' => COMPLETION_ENABLED),
|
||||
array('createsections' => true));
|
||||
|
||||
$courseobject = core_courseformat\base::instance($course->id);
|
||||
$courseobject = \core_courseformat\base::instance($course->id);
|
||||
$section = $DB->get_record('course_sections',
|
||||
array('course' => $course->id, 'section' => 1), '*', MUST_EXIST);
|
||||
$data = array('id' => $section->id,
|
||||
@@ -91,7 +91,7 @@ class core_backup_moodle2_course_format_testcase extends advanced_testcase {
|
||||
'enablecompletion' => COMPLETION_ENABLED),
|
||||
array('createsections' => true));
|
||||
|
||||
$courseobject = core_courseformat\base::instance($course->id);
|
||||
$courseobject = \core_courseformat\base::instance($course->id);
|
||||
$section = $DB->get_record('course_sections',
|
||||
array('course' => $course->id, 'section' => 1), '*', MUST_EXIST);
|
||||
$data = array('id' => $section->id,
|
||||
@@ -134,7 +134,7 @@ class core_backup_moodle2_course_format_testcase extends advanced_testcase {
|
||||
array('createsections' => true));
|
||||
|
||||
// Set section 2 to have both options, and a name.
|
||||
$courseobject = core_courseformat\base::instance($course->id);
|
||||
$courseobject = \core_courseformat\base::instance($course->id);
|
||||
$section = $DB->get_record('course_sections',
|
||||
array('course' => $course->id, 'section' => 2), '*', MUST_EXIST);
|
||||
$data = array('id' => $section->id,
|
||||
@@ -151,7 +151,7 @@ class core_backup_moodle2_course_format_testcase extends advanced_testcase {
|
||||
// Check that the section contains the options suitable for the new
|
||||
// format and that even the one with the same name as from the old format
|
||||
// has NOT been set.
|
||||
$newcourseobject = core_courseformat\base::instance($newcourse->id);
|
||||
$newcourseobject = \core_courseformat\base::instance($newcourse->id);
|
||||
$sectionoptions = $newcourseobject->get_format_options(2);
|
||||
$this->assertArrayHasKey('numdaystocomplete', $sectionoptions);
|
||||
$this->assertArrayNotHasKey('secondparameter', $sectionoptions);
|
||||
@@ -167,8 +167,8 @@ class core_backup_moodle2_course_format_testcase extends advanced_testcase {
|
||||
/**
|
||||
* Backs a course up and restores it.
|
||||
*
|
||||
* @param stdClass $srccourse Course object to backup
|
||||
* @param stdClass $dstcourse Course object to restore into
|
||||
* @param \stdClass $srccourse Course object to backup
|
||||
* @param \stdClass $dstcourse Course object to restore into
|
||||
* @param int $target Target course mode (backup::TARGET_xx)
|
||||
* @return int ID of newly restored course
|
||||
*/
|
||||
@@ -206,60 +206,3 @@ class core_backup_moodle2_course_format_testcase extends advanced_testcase {
|
||||
return $newcourseid;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class format_test_cs_options
|
||||
*
|
||||
* Test course format that has 1 option.
|
||||
*/
|
||||
class format_test_cs_options extends format_topics {
|
||||
/**
|
||||
* Override method format_topics::get_default_section_name to prevent PHPUnit errors related to the nonexistent
|
||||
* format_test_cs_options lang file.
|
||||
*
|
||||
* @param stdClass $section The section in question.
|
||||
* @return string The section's name for display.
|
||||
*/
|
||||
public function get_default_section_name($section) {
|
||||
if ($section->section == 0) {
|
||||
return parent::get_default_section_name($section);
|
||||
} else {
|
||||
return get_string('sectionname', 'format_topics') . ' ' . $section->section;
|
||||
}
|
||||
}
|
||||
|
||||
public function section_format_options($foreditform = false) {
|
||||
return array(
|
||||
'numdaystocomplete' => array(
|
||||
'type' => PARAM_INT,
|
||||
'label' => 'Test days',
|
||||
'element_type' => 'text',
|
||||
'default' => 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class format_test_cs2_options
|
||||
*
|
||||
* Test course format that has 2 options, 1 inherited.
|
||||
*/
|
||||
class format_test_cs2_options extends format_test_cs_options {
|
||||
public function section_format_options($foreditform = false) {
|
||||
return array(
|
||||
'numdaystocomplete' => array(
|
||||
'type' => PARAM_INT,
|
||||
'label' => 'Test days',
|
||||
'element_type' => 'text',
|
||||
'default' => 0,
|
||||
),
|
||||
'secondparameter' => array(
|
||||
'type' => PARAM_INT,
|
||||
'label' => 'Test Parmater',
|
||||
'element_type' => 'text',
|
||||
'default' => 0,
|
||||
),
|
||||
) + parent::section_format_options($foreditform);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,13 +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/>.
|
||||
|
||||
/**
|
||||
* Tests for Moodle 2 format backup operation.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2014 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use backup;
|
||||
use backup_controller;
|
||||
use restore_controller;
|
||||
use restore_dbops;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -36,7 +35,7 @@ require_once($CFG->libdir . '/completionlib.php');
|
||||
* @copyright 2014 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
class moodle2_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests the availability field on modules and sections is correctly
|
||||
@@ -64,7 +63,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
// We need a grade, easiest is to add an assignment.
|
||||
$assignrow = $generator->create_module('assign', array(
|
||||
'course' => $course->id));
|
||||
$assign = new assign(context_module::instance($assignrow->cmid), false, false);
|
||||
$assign = new \assign(\context_module::instance($assignrow->cmid), false, false);
|
||||
$item = $assign->get_grade_item();
|
||||
|
||||
// Make a test grouping as well.
|
||||
@@ -88,7 +87,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
$modinfo = get_fast_modinfo($newcourseid);
|
||||
$forums = array_values($modinfo->get_instances_of('forum'));
|
||||
$assigns = array_values($modinfo->get_instances_of('assign'));
|
||||
$newassign = new assign(context_module::instance($assigns[0]->id), false, false);
|
||||
$newassign = new \assign(\context_module::instance($assigns[0]->id), false, false);
|
||||
$newitem = $newassign->get_grade_item();
|
||||
$newgroupingid = $DB->get_field('groupings', 'id', array('courseid' => $newcourseid));
|
||||
|
||||
@@ -181,7 +180,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
// Grade >= 75%.
|
||||
$grades = array_values(grade_get_grade_items_for_activity($quizzes[0], true));
|
||||
$gradeid = $grades[0]->id;
|
||||
$coursegrade = grade_item::fetch_course_item($newcourseid);
|
||||
$coursegrade = \grade_item::fetch_course_item($newcourseid);
|
||||
$this->assertEquals(
|
||||
'{"op":"&","showc":[true],"c":[{"type":"grade","id":' . $gradeid . ',"min":75}]}',
|
||||
$pages[4]->availability);
|
||||
@@ -282,7 +281,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
// We need a grade, easiest is to add an assignment.
|
||||
$assignrow = $generator->create_module('assign', array(
|
||||
'course' => $course->id));
|
||||
$assign = new assign(context_module::instance($assignrow->cmid), false, false);
|
||||
$assign = new \assign(\context_module::instance($assignrow->cmid), false, false);
|
||||
$item = $assign->get_grade_item();
|
||||
|
||||
// Make a test group and grouping as well.
|
||||
@@ -461,7 +460,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
/**
|
||||
* Backs a course up and restores it.
|
||||
*
|
||||
* @param stdClass $course Course object to backup
|
||||
* @param \stdClass $course Course object to backup
|
||||
* @param int $newdate If non-zero, specifies custom date for new course
|
||||
* @param callable|null $inbetween If specified, function that is called before restore
|
||||
* @return int ID of newly restored course
|
||||
@@ -507,7 +506,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
* This is based on the code from course/modduplicate.php, but reduced for
|
||||
* simplicity.
|
||||
*
|
||||
* @param stdClass $course Course object
|
||||
* @param \stdClass $course Course object
|
||||
* @param int $cmid Activity to duplicate
|
||||
* @return int ID of new activity
|
||||
*/
|
||||
@@ -529,7 +528,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
|
||||
// Find cmid.
|
||||
$tasks = $rc->get_plan()->get_tasks();
|
||||
$cmcontext = context_module::instance($cmid);
|
||||
$cmcontext = \context_module::instance($cmid);
|
||||
$newcmid = 0;
|
||||
foreach ($tasks as $task) {
|
||||
if (is_subclass_of($task, 'restore_activity_task')) {
|
||||
@@ -541,7 +540,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
}
|
||||
$rc->destroy();
|
||||
if (!$newcmid) {
|
||||
throw new coding_exception('Unexpected: failure to find restored cmid');
|
||||
throw new \coding_exception('Unexpected: failure to find restored cmid');
|
||||
}
|
||||
return $newcmid;
|
||||
}
|
||||
@@ -578,7 +577,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
$selfplugin->enrol_user($selfinstance, $user->id, $studentrole->id);
|
||||
|
||||
// Give current user capabilities to do backup and restore and assign student role.
|
||||
$categorycontext = context_course::instance($course->id)->get_parent_context();
|
||||
$categorycontext = \context_course::instance($course->id)->get_parent_context();
|
||||
|
||||
$caps = array_merge([
|
||||
'moodle/course:view',
|
||||
@@ -819,8 +818,8 @@ class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
|
||||
// Create course and add HTML block.
|
||||
$course = $generator->create_course();
|
||||
$context = context_course::instance($course->id);
|
||||
$page = new moodle_page();
|
||||
$context = \context_course::instance($course->id);
|
||||
$page = new \moodle_page();
|
||||
$page->set_context($context);
|
||||
$page->set_course($course);
|
||||
$page->set_pagelayout('standard');
|
||||
@@ -840,7 +839,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
$newcourseid = $this->backup_and_restore($course);
|
||||
|
||||
// Confirm that values were transferred correctly into HTML block on new course.
|
||||
$newcontext = context_course::instance($newcourseid);
|
||||
$newcontext = \context_course::instance($newcourseid);
|
||||
$blockdata = $DB->get_record('block_instances',
|
||||
['blockname' => 'html', 'parentcontextid' => $newcontext->id]);
|
||||
$this->assertEquals(12345, $blockdata->timecreated);
|
||||
@@ -860,7 +859,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
$after = time();
|
||||
|
||||
// The fields not specified should default to current time.
|
||||
$newcontext = context_course::instance($newcourseid);
|
||||
$newcontext = \context_course::instance($newcourseid);
|
||||
$blockdata = $DB->get_record('block_instances',
|
||||
['blockname' => 'html', 'parentcontextid' => $newcontext->id]);
|
||||
$this->assertTrue($before <= $blockdata->timecreated && $after >= $blockdata->timecreated);
|
||||
@@ -886,8 +885,8 @@ class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
$forum = $generator->create_module('forum', ['course' => $course->id]);
|
||||
|
||||
// Add a block.
|
||||
$context = context_course::instance($course->id);
|
||||
$page = new moodle_page();
|
||||
$context = \context_course::instance($course->id);
|
||||
$page = new \moodle_page();
|
||||
$page->set_context($context);
|
||||
$page->set_course($course);
|
||||
$page->set_pagelayout('standard');
|
||||
@@ -902,7 +901,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
$newcourseid = $this->backup_and_restore($course);
|
||||
|
||||
// Now the course should be requested for index (all search areas).
|
||||
$newcontext = context_course::instance($newcourseid);
|
||||
$newcontext = \context_course::instance($newcourseid);
|
||||
$requests = array_values($DB->get_records('search_index_requests'));
|
||||
$this->assertCount(1, $requests);
|
||||
$this->assertEquals($newcontext->id, $requests[0]->contextid);
|
||||
@@ -1077,7 +1076,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
|
||||
// Create course and add content bank content.
|
||||
$course = $generator->create_course();
|
||||
$context = context_course::instance($course->id);
|
||||
$context = \context_course::instance($course->id);
|
||||
$filepath = $CFG->dirroot . '/h5p/tests/fixtures/filltheblanks.h5p';
|
||||
$contents = $cbgenerator->generate_contentbank_data('contenttype_h5p', 2, $USER->id, $context, true, $filepath);
|
||||
$this->assertEquals(2, $DB->count_records('contentbank_content'));
|
||||
@@ -1086,7 +1085,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
$newcourseid = $this->backup_and_restore($course);
|
||||
|
||||
// Confirm that values were transferred correctly into content bank on new course.
|
||||
$newcontext = context_course::instance($newcourseid);
|
||||
$newcontext = \context_course::instance($newcourseid);
|
||||
|
||||
$this->assertEquals(4, $DB->count_records('contentbank_content'));
|
||||
$this->assertEquals(2, $DB->count_records('contentbank_content', ['contextid' => $newcontext->id]));
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Test for restore_stepslib.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2016 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -36,7 +30,7 @@ require_once($CFG->libdir . '/completionlib.php');
|
||||
* @copyright 2016 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_backup_restore_gradebook_structure_step_testcase extends advanced_testcase {
|
||||
class restore_gradebook_structure_step_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Provide tests for rewrite_step_backup_file_for_legacy_freeze based upon fixtures.
|
||||
|
||||
@@ -14,13 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Restore date tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2017 Adrian Greeve <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -36,7 +30,7 @@ require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
|
||||
* @copyright 2017 Adrian Greeve <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class restore_stepslib_date_testcase extends restore_date_testcase {
|
||||
class restore_stepslib_date_test extends \restore_date_testcase {
|
||||
|
||||
/**
|
||||
* Restoring a manual grade item does not result in the timecreated or
|
||||
@@ -46,17 +40,17 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
|
||||
|
||||
$course = $this->getDataGenerator()->create_course(['startdate' => time()]);
|
||||
|
||||
$params = new stdClass();
|
||||
$params = new \stdClass();
|
||||
$params->courseid = $course->id;
|
||||
$params->fullname = 'unittestgradecalccategory';
|
||||
$params->aggregation = GRADE_AGGREGATE_MEAN;
|
||||
$params->aggregateonlygraded = 0;
|
||||
$gradecategory = new grade_category($params, false);
|
||||
$gradecategory = new \grade_category($params, false);
|
||||
$gradecategory->insert();
|
||||
|
||||
$gradecategory->load_grade_item();
|
||||
|
||||
$gradeitems = new grade_item();
|
||||
$gradeitems = new \grade_item();
|
||||
$gradeitems->courseid = $course->id;
|
||||
$gradeitems->categoryid = $gradecategory->id;
|
||||
$gradeitems->itemname = 'manual grade_item';
|
||||
@@ -80,7 +74,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
|
||||
'courseid' => $course->id,
|
||||
];
|
||||
|
||||
$gradeitem = grade_item::fetch($gradeitemparams);
|
||||
$gradeitem = \grade_item::fetch($gradeitemparams);
|
||||
|
||||
// Do backup and restore.
|
||||
|
||||
@@ -92,7 +86,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
|
||||
'courseid' => $course->id,
|
||||
];
|
||||
|
||||
$newgradeitem = grade_item::fetch($newgradeitemparams);
|
||||
$newgradeitem = \grade_item::fetch($newgradeitemparams);
|
||||
$this->assertEquals($gradeitem->timecreated, $newgradeitem->timecreated);
|
||||
$this->assertEquals($gradeitem->timemodified, $newgradeitem->timemodified);
|
||||
}
|
||||
@@ -125,7 +119,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
|
||||
// Create a course.
|
||||
$course = $this->getDataGenerator()->create_course(['startdate' => time()]);
|
||||
// Create a badge.
|
||||
$fordb = new stdClass();
|
||||
$fordb = new \stdClass();
|
||||
$fordb->id = null;
|
||||
$fordb->name = "Test badge";
|
||||
$fordb->description = "Testing badges";
|
||||
@@ -187,7 +181,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
|
||||
'timeduration' => 86400,
|
||||
'visible' => 1
|
||||
];
|
||||
$calendarevent = calendar_event::create($event, false);
|
||||
$calendarevent = \calendar_event::create($event, false);
|
||||
|
||||
// Backup and restore.
|
||||
$newcourseid = $this->backup_and_restore($course);
|
||||
@@ -214,7 +208,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
|
||||
$studentrole = $DB->get_record('role', ['shortname' => 'student']);
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id);
|
||||
// Complete the course with a user.
|
||||
$ccompletion = new completion_completion(['course' => $course->id,
|
||||
$ccompletion = new \completion_completion(['course' => $course->id,
|
||||
'userid' => $user->id,
|
||||
'timeenrolled' => time(),
|
||||
'timestarted' => time()
|
||||
@@ -227,7 +221,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
|
||||
$newcourseid = $this->backup_and_restore($course);
|
||||
$newcourse = get_course($newcourseid);
|
||||
|
||||
$newcompletion = completion_completion::fetch(['course' => $newcourseid, 'userid' => $user->id]);
|
||||
$newcompletion = \completion_completion::fetch(['course' => $newcourseid, 'userid' => $user->id]);
|
||||
|
||||
// Compare dates.
|
||||
$this->assertEquals($ccompletion->timeenrolled, $newcompletion->timeenrolled);
|
||||
@@ -244,7 +238,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
|
||||
// Testing the restore of an overridden grade.
|
||||
list($course, $assign) = $this->create_course_and_module('assign', []);
|
||||
$cm = $DB->get_record('course_modules', ['course' => $course->id, 'instance' => $assign->id]);
|
||||
$assignobj = new mod_assign_testable_assign(context_module::instance($cm->id), $cm, $course);
|
||||
$assignobj = new \mod_assign_testable_assign(\context_module::instance($cm->id), $cm, $course);
|
||||
$submission = $assignobj->get_user_submission($USER->id, true);
|
||||
$grade = $assignobj->get_user_grade($USER->id, true);
|
||||
$grade->grade = 75;
|
||||
@@ -257,10 +251,10 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
|
||||
'itemmodule' => 'assign',
|
||||
'courseid' => $course->id,
|
||||
];
|
||||
$gradeitem = grade_item::fetch($gradeitemparams);
|
||||
$gradeitem = \grade_item::fetch($gradeitemparams);
|
||||
|
||||
// Next the grade grade.
|
||||
$gradegrade = grade_grade::fetch(['itemid' => $gradeitem->id, 'userid' => $USER->id]);
|
||||
$gradegrade = \grade_grade::fetch(['itemid' => $gradeitem->id, 'userid' => $USER->id]);
|
||||
$gradegrade->set_overridden(true);
|
||||
|
||||
// Back up and restore.
|
||||
@@ -277,9 +271,9 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
|
||||
'courseid' => $newcourse->id,
|
||||
];
|
||||
|
||||
$newgradeitem = grade_item::fetch($newgradeitemparams);
|
||||
$newgradeitem = \grade_item::fetch($newgradeitemparams);
|
||||
// Find grade grade.
|
||||
$newgradegrade = grade_grade::fetch(['itemid' => $newgradeitem->id, 'userid' => $USER->id]);
|
||||
$newgradegrade = \grade_grade::fetch(['itemid' => $newgradeitem->id, 'userid' => $USER->id]);
|
||||
// Compare dates.
|
||||
$this->assertEquals($gradegrade->timecreated, $newgradegrade->timecreated);
|
||||
$this->assertEquals($gradegrade->timemodified, $newgradegrade->timemodified);
|
||||
@@ -300,7 +294,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
|
||||
'completionusegrade' => 1 // Student must receive a grade to complete this activity.
|
||||
]);
|
||||
$cm = $DB->get_record('course_modules', ['course' => $course->id, 'instance' => $assign->id]);
|
||||
$assignobj = new mod_assign_testable_assign(context_module::instance($cm->id), $cm, $course);
|
||||
$assignobj = new \mod_assign_testable_assign(\context_module::instance($cm->id), $cm, $course);
|
||||
$submission = $assignobj->get_user_submission($USER->id, true);
|
||||
$grade = $assignobj->get_user_grade($USER->id, true);
|
||||
$grade->grade = 75;
|
||||
@@ -350,10 +344,10 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
|
||||
// Make a user to do the quiz.
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
|
||||
$quizobj = quiz::create($quiz->id, $user1->id);
|
||||
$quizobj = \quiz::create($quiz->id, $user1->id);
|
||||
|
||||
// Start the attempt.
|
||||
$quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
|
||||
$quba = \question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
|
||||
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
|
||||
|
||||
$timenow = time();
|
||||
@@ -364,7 +358,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
|
||||
quiz_attempt_save_started($quizobj, $quba, $attempt);
|
||||
|
||||
// Process some responses from the student.
|
||||
$attemptobj = quiz_attempt::create($attempt->id);
|
||||
$attemptobj = \quiz_attempt::create($attempt->id);
|
||||
|
||||
$prefix1 = $quba->get_field_prefix(1);
|
||||
$prefix2 = $quba->get_field_prefix(2);
|
||||
@@ -375,7 +369,7 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
|
||||
$attemptobj->process_submitted_actions($timenow, false, $tosubmit);
|
||||
|
||||
// Finish the attempt.
|
||||
$attemptobj = quiz_attempt::create($attempt->id);
|
||||
$attemptobj = \quiz_attempt::create($attempt->id);
|
||||
$attemptobj->process_finish($timenow, false);
|
||||
|
||||
$questionattemptstepdates = [];
|
||||
@@ -390,14 +384,14 @@ class restore_stepslib_date_testcase extends restore_date_testcase {
|
||||
|
||||
// Get the quiz for this new restored course.
|
||||
$quizdata = $DB->get_record('quiz', ['course' => $newcourseid]);
|
||||
$quizobj = quiz::create($quizdata->id, $user1->id);
|
||||
$quizobj = \quiz::create($quizdata->id, $user1->id);
|
||||
|
||||
$questionusage = $DB->get_record('question_usages', [
|
||||
'component' => 'mod_quiz',
|
||||
'contextid' => $quizobj->get_context()->id
|
||||
]);
|
||||
|
||||
$newquba = question_engine::load_questions_usage_by_activity($questionusage->id);
|
||||
$newquba = \question_engine::load_questions_usage_by_activity($questionusage->id);
|
||||
|
||||
$restorediterator = $newquba->get_attempt_iterator();
|
||||
$i = 0;
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Asyncronhous backup tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2018 Matt Porritt <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use backup;
|
||||
use backup_controller;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -32,10 +29,11 @@ require_once($CFG->libdir . '/completionlib.php');
|
||||
/**
|
||||
* Asyncronhous backup tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2018 Matt Porritt <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_backup_async_backup_testcase extends \core_privacy\tests\provider_testcase {
|
||||
class async_backup_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests the asynchronous backup.
|
||||
@@ -66,7 +64,7 @@ class core_backup_async_backup_testcase extends \core_privacy\tests\provider_tes
|
||||
// We need a grade, easiest is to add an assignment.
|
||||
$assignrow = $generator->create_module('assign', array(
|
||||
'course' => $course->id));
|
||||
$assign = new assign(context_module::instance($assignrow->cmid), false, false);
|
||||
$assign = new \assign(\context_module::instance($assignrow->cmid), false, false);
|
||||
$item = $assign->get_grade_item();
|
||||
|
||||
// Make a test grouping as well.
|
||||
@@ -161,7 +159,7 @@ class core_backup_async_backup_testcase extends \core_privacy\tests\provider_tes
|
||||
// We need a grade, easiest is to add an assignment.
|
||||
$assignrow = $generator->create_module('assign', array(
|
||||
'course' => $course->id));
|
||||
$assign = new assign(context_module::instance($assignrow->cmid), false, false);
|
||||
$assign = new \assign(\context_module::instance($assignrow->cmid), false, false);
|
||||
$item = $assign->get_grade_item();
|
||||
|
||||
// Make a test grouping as well.
|
||||
|
||||
@@ -14,13 +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/>.
|
||||
|
||||
/**
|
||||
* Asyncronhous restore tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2018 Matt Porritt <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use backup;
|
||||
use backup_controller;
|
||||
use restore_controller;
|
||||
use restore_dbops;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -32,10 +31,11 @@ require_once($CFG->libdir . '/completionlib.php');
|
||||
/**
|
||||
* Asyncronhous restore tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2018 Matt Porritt <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_backup_async_restore_testcase extends \core_privacy\tests\provider_testcase {
|
||||
class async_restore_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests the asynchronous backup.
|
||||
@@ -62,7 +62,7 @@ class core_backup_async_restore_testcase extends \core_privacy\tests\provider_te
|
||||
// We need a grade, easiest is to add an assignment.
|
||||
$assignrow = $generator->create_module('assign', array(
|
||||
'course' => $course->id));
|
||||
$assign = new assign(context_module::instance($assignrow->cmid), false, false);
|
||||
$assign = new \assign(\context_module::instance($assignrow->cmid), false, false);
|
||||
$item = $assign->get_grade_item();
|
||||
|
||||
// Make a test grouping as well.
|
||||
@@ -88,7 +88,7 @@ class core_backup_async_restore_testcase extends \core_privacy\tests\provider_te
|
||||
$bc->destroy();
|
||||
|
||||
// Get the backup file.
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
$coursecontext = \context_course::instance($course->id);
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($coursecontext->id, 'backup', 'course', false, 'id ASC');
|
||||
$backupfile = reset($files);
|
||||
@@ -164,7 +164,7 @@ class core_backup_async_restore_testcase extends \core_privacy\tests\provider_te
|
||||
// We need a grade, easiest is to add an assignment.
|
||||
$assignrow = $generator->create_module('assign', array(
|
||||
'course' => $course->id));
|
||||
$assign = new assign(context_module::instance($assignrow->cmid), false, false);
|
||||
$assign = new \assign(\context_module::instance($assignrow->cmid), false, false);
|
||||
$item = $assign->get_grade_item();
|
||||
|
||||
// Make a test grouping as well.
|
||||
@@ -189,7 +189,7 @@ class core_backup_async_restore_testcase extends \core_privacy\tests\provider_te
|
||||
$bc->destroy();
|
||||
|
||||
// Get the backup file.
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
$coursecontext = \context_course::instance($course->id);
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($coursecontext->id, 'backup', 'course', false, 'id ASC');
|
||||
$backupfile = reset($files);
|
||||
|
||||
@@ -22,6 +22,10 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_backup;
|
||||
|
||||
use backup_cron_automated_helper;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
@@ -32,17 +36,18 @@ require_once($CFG->libdir . '/completionlib.php');
|
||||
/**
|
||||
* Automated backup tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2019 John Yao <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_backup_automated_backup_testcase extends advanced_testcase {
|
||||
class automated_backup_test extends \advanced_testcase {
|
||||
/**
|
||||
* @var \backup_cron_automated_helper
|
||||
*/
|
||||
protected $backupcronautomatedhelper;
|
||||
|
||||
/**
|
||||
* @var stdClass $course
|
||||
* @var \stdClass $course
|
||||
*/
|
||||
protected $course;
|
||||
|
||||
@@ -70,7 +75,7 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
|
||||
// We need a grade, easiest is to add an assignment.
|
||||
$assignrow = $generator->create_module('assign', array(
|
||||
'course' => $this->course->id));
|
||||
$assign = new assign(context_module::instance($assignrow->cmid), false, false);
|
||||
$assign = new \assign(\context_module::instance($assignrow->cmid), false, false);
|
||||
$item = $assign->get_grade_item();
|
||||
|
||||
// Make a test grouping as well.
|
||||
@@ -111,11 +116,11 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
|
||||
|
||||
$classobject = $this->backupcronautomatedhelper->return_this();
|
||||
|
||||
$method = new ReflectionMethod('\backup_cron_automated_helper', 'get_courses');
|
||||
$method = new \ReflectionMethod('\backup_cron_automated_helper', 'get_courses');
|
||||
$method->setAccessible(true); // Allow accessing of private method.
|
||||
$courses = $method->invoke($classobject);
|
||||
|
||||
$method = new ReflectionMethod('\backup_cron_automated_helper', 'check_and_push_automated_backups');
|
||||
$method = new \ReflectionMethod('\backup_cron_automated_helper', 'check_and_push_automated_backups');
|
||||
$method->setAccessible(true); // Allow accessing of private method.
|
||||
$emailpending = $method->invokeArgs($classobject, [$courses, $admin]);
|
||||
|
||||
@@ -140,12 +145,12 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
|
||||
|
||||
$classobject = $this->backupcronautomatedhelper->return_this();
|
||||
|
||||
$method = new ReflectionMethod('\backup_cron_automated_helper', 'get_courses');
|
||||
$method = new \ReflectionMethod('\backup_cron_automated_helper', 'get_courses');
|
||||
$method->setAccessible(true); // Allow accessing of private method.
|
||||
$courses = $method->invoke($classobject);
|
||||
|
||||
// Create this backup course.
|
||||
$backupcourse = new stdClass;
|
||||
$backupcourse = new \stdClass;
|
||||
$backupcourse->courseid = $this->course->id;
|
||||
$backupcourse->laststatus = backup_cron_automated_helper::BACKUP_STATUS_NOTYETRUN;
|
||||
$DB->insert_record('backup_courses', $backupcourse);
|
||||
@@ -156,7 +161,7 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
|
||||
$backupcourse->nextstarttime = time() - 10;
|
||||
$DB->update_record('backup_courses', $backupcourse);
|
||||
|
||||
$method = new ReflectionMethod('\backup_cron_automated_helper', 'check_and_push_automated_backups');
|
||||
$method = new \ReflectionMethod('\backup_cron_automated_helper', 'check_and_push_automated_backups');
|
||||
$method->setAccessible(true); // Allow accessing of private method.
|
||||
$emailpending = $method->invokeArgs($classobject, [$courses, $admin]);
|
||||
$this->assertTrue($emailpending);
|
||||
@@ -186,7 +191,7 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
|
||||
set_config('backup_auto_skip_hidden', true, 'backup');
|
||||
set_config('backup_auto_weekdays', '1111111', 'backup');
|
||||
// Create this backup course.
|
||||
$backupcourse = new stdClass;
|
||||
$backupcourse = new \stdClass;
|
||||
$backupcourse->courseid = $this->course->id;
|
||||
// This is the status we believe last run was OK.
|
||||
$backupcourse->laststatus = backup_cron_automated_helper::BACKUP_STATUS_SKIPPED;
|
||||
@@ -199,7 +204,7 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
|
||||
$classobject = $this->backupcronautomatedhelper->return_this();
|
||||
$nextstarttime = backup_cron_automated_helper::calculate_next_automated_backup(null, time());
|
||||
|
||||
$method = new ReflectionMethod('\backup_cron_automated_helper', 'should_skip_course_backup');
|
||||
$method = new \ReflectionMethod('\backup_cron_automated_helper', 'should_skip_course_backup');
|
||||
$method->setAccessible(true); // Allow accessing of private method.
|
||||
$skipped = $method->invokeArgs($classobject, [$backupcourse, $course, $nextstarttime]);
|
||||
|
||||
@@ -219,7 +224,7 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
|
||||
set_config('backup_auto_weekdays', '1111111', 'backup');
|
||||
|
||||
// Create this backup course.
|
||||
$backupcourse = new stdClass;
|
||||
$backupcourse = new \stdClass;
|
||||
$backupcourse->courseid = $this->course->id;
|
||||
// This is the status we believe last run was OK.
|
||||
$backupcourse->laststatus = backup_cron_automated_helper::BACKUP_STATUS_SKIPPED;
|
||||
@@ -234,7 +239,7 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
|
||||
$classobject = $this->backupcronautomatedhelper->return_this();
|
||||
$nextstarttime = backup_cron_automated_helper::calculate_next_automated_backup(null, time());
|
||||
|
||||
$method = new ReflectionMethod('\backup_cron_automated_helper', 'should_skip_course_backup');
|
||||
$method = new \ReflectionMethod('\backup_cron_automated_helper', 'should_skip_course_backup');
|
||||
$method->setAccessible(true); // Allow accessing of private method.
|
||||
$skipped = $method->invokeArgs($classobject, [$backupcourse, $course, $nextstarttime]);
|
||||
|
||||
@@ -254,7 +259,7 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
|
||||
set_config('backup_auto_weekdays', '1111111', 'backup');
|
||||
|
||||
// Create this backup course.
|
||||
$backupcourse = new stdClass;
|
||||
$backupcourse = new \stdClass;
|
||||
$backupcourse->courseid = $this->course->id;
|
||||
// This is the status we believe last run was OK.
|
||||
$backupcourse->laststatus = backup_cron_automated_helper::BACKUP_STATUS_SKIPPED;
|
||||
@@ -269,7 +274,7 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
|
||||
$classobject = $this->backupcronautomatedhelper->return_this();
|
||||
$nextstarttime = backup_cron_automated_helper::calculate_next_automated_backup(null, time());
|
||||
|
||||
$method = new ReflectionMethod('\backup_cron_automated_helper', 'should_skip_course_backup');
|
||||
$method = new \ReflectionMethod('\backup_cron_automated_helper', 'should_skip_course_backup');
|
||||
$method->setAccessible(true); // Allow accessing of private method.
|
||||
$skipped = $method->invokeArgs($classobject, [$backupcourse, $course, $nextstarttime]);
|
||||
|
||||
@@ -286,28 +291,28 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
|
||||
$classobject = $this->backupcronautomatedhelper->return_this();
|
||||
|
||||
// Create this backup course.
|
||||
$backupcourse = new stdClass;
|
||||
$backupcourse = new \stdClass;
|
||||
$backupcourse->courseid = $this->course->id;
|
||||
$backupcourse->laststatus = backup_cron_automated_helper::BACKUP_STATUS_NOTYETRUN;
|
||||
$DB->insert_record('backup_courses', $backupcourse);
|
||||
$backupcourse = $DB->get_record('backup_courses', ['courseid' => $this->course->id]);
|
||||
|
||||
// Create a backup task.
|
||||
$method = new ReflectionMethod('\backup_cron_automated_helper', 'push_course_backup_adhoc_task');
|
||||
$method = new \ReflectionMethod('\backup_cron_automated_helper', 'push_course_backup_adhoc_task');
|
||||
$method->setAccessible(true); // Allow accessing of private method.
|
||||
$method->invokeArgs($classobject, [$backupcourse, $admin]);
|
||||
|
||||
// Delete course for this test.
|
||||
delete_course($this->course->id, false);
|
||||
|
||||
$task = core\task\manager::get_next_adhoc_task(time());
|
||||
$task = \core\task\manager::get_next_adhoc_task(time());
|
||||
|
||||
ob_start();
|
||||
$task->execute();
|
||||
$output = ob_get_clean();
|
||||
|
||||
$this->assertStringContainsString('Invalid course id: ' . $this->course->id . ', task aborted.', $output);
|
||||
core\task\manager::adhoc_task_complete($task);
|
||||
\core\task\manager::adhoc_task_complete($task);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -319,21 +324,21 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
|
||||
$classobject = $this->backupcronautomatedhelper->return_this();
|
||||
|
||||
// Create this backup course.
|
||||
$backupcourse = new stdClass;
|
||||
$backupcourse = new \stdClass;
|
||||
$backupcourse->courseid = $this->course->id;
|
||||
$backupcourse->laststatus = backup_cron_automated_helper::BACKUP_STATUS_NOTYETRUN;
|
||||
$DB->insert_record('backup_courses', $backupcourse);
|
||||
$backupcourse = $DB->get_record('backup_courses', ['courseid' => $this->course->id]);
|
||||
|
||||
// Create a backup task.
|
||||
$method = new ReflectionMethod('\backup_cron_automated_helper', 'push_course_backup_adhoc_task');
|
||||
$method = new \ReflectionMethod('\backup_cron_automated_helper', 'push_course_backup_adhoc_task');
|
||||
$method->setAccessible(true); // Allow accessing of private method.
|
||||
$method->invokeArgs($classobject, [$backupcourse, $admin]);
|
||||
|
||||
// Delete backup course for this test.
|
||||
$DB->delete_records('backup_courses', ['courseid' => $this->course->id]);
|
||||
|
||||
$task = core\task\manager::get_next_adhoc_task(time());
|
||||
$task = \core\task\manager::get_next_adhoc_task(time());
|
||||
|
||||
ob_start();
|
||||
$task->execute();
|
||||
@@ -341,7 +346,7 @@ class core_backup_automated_backup_testcase extends advanced_testcase {
|
||||
|
||||
$this->assertStringContainsString('Automated backup for course: ' . $this->course->fullname . ' encounters an error.',
|
||||
$output);
|
||||
core\task\manager::adhoc_task_complete($task);
|
||||
\core\task\manager::adhoc_task_complete($task);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,13 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Tests for the \core\task\backup_cleanup_task scheduled task.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2021 Mikhail Golenkov <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -30,10 +24,11 @@ require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
|
||||
/**
|
||||
* Tests for the \core\task\backup_cleanup_task scheduled task.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2021 Mikhail Golenkov <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_backup_cleanup_task_testcase extends advanced_testcase {
|
||||
class backup_cleanup_task_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Set up tasks for all tests.
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Backup restore permission tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright Tomo Tsuyuki <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use core_backup_backup_restore_base_testcase;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -30,9 +26,13 @@ require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
|
||||
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
|
||||
|
||||
/**
|
||||
* Testcase class for permission backup / restore functionality.
|
||||
* Backup restore permission tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright Tomo Tsuyuki <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_backup_backup_restore_permission_testcase extends core_backup_backup_restore_base_testcase {
|
||||
class backup_restore_permission_test extends core_backup_backup_restore_base_testcase {
|
||||
|
||||
/** @var stdClass A test course which is restored/imported from. */
|
||||
protected $course1;
|
||||
@@ -62,9 +62,9 @@ class core_backup_backup_restore_permission_testcase extends core_backup_backup_
|
||||
// Create a course with some availability data set.
|
||||
$generator = $this->getDataGenerator();
|
||||
$this->course1 = $generator->create_course();
|
||||
$this->course1context = context_course::instance($this->course1->id);
|
||||
$this->course1context = \context_course::instance($this->course1->id);
|
||||
$this->course2 = $generator->create_course();
|
||||
$this->course2context = context_course::instance($this->course2->id);
|
||||
$this->course2context = \context_course::instance($this->course2->id);
|
||||
$this->capabilityname = 'enrol/manual:enrol';
|
||||
$this->user = $generator->create_user();
|
||||
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Course copy tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2020 onward The Moodle Users Association <https://moodleassociation.org/>
|
||||
* @author Matt Porritt <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use backup;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
@@ -37,7 +33,7 @@ require_once($CFG->libdir . '/completionlib.php');
|
||||
* @author Matt Porritt <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
class course_copy_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -88,7 +84,7 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
// We need a grade, easiest is to add an assignment.
|
||||
$assignrow = $generator->create_module('assign', array(
|
||||
'course' => $course->id));
|
||||
$assign = new assign(context_module::instance($assignrow->cmid), false, false);
|
||||
$assign = new \assign(\context_module::instance($assignrow->cmid), false, false);
|
||||
$item = $assign->get_grade_item();
|
||||
|
||||
// Make a test grouping as well.
|
||||
@@ -384,7 +380,7 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
$this->assertEquals(1.0, $postrestorerec->progress);
|
||||
|
||||
// Check the restored course itself.
|
||||
$coursecontext = context_course::instance($postrestorerec->itemid);
|
||||
$coursecontext = \context_course::instance($postrestorerec->itemid);
|
||||
$users = get_enrolled_users($coursecontext);
|
||||
|
||||
$modinfo = get_fast_modinfo($postrestorerec->itemid);
|
||||
@@ -452,7 +448,7 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
$postrestorerec = $DB->get_record('backup_controllers', array('backupid' => $copyids['restoreid']));
|
||||
|
||||
// Check the restored course itself.
|
||||
$coursecontext = context_course::instance($postrestorerec->itemid);
|
||||
$coursecontext = \context_course::instance($postrestorerec->itemid);
|
||||
$users = get_enrolled_users($coursecontext);
|
||||
|
||||
$modinfo = get_fast_modinfo($postrestorerec->itemid);
|
||||
@@ -521,7 +517,7 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
$postrestorerec = $DB->get_record('backup_controllers', array('backupid' => $copyids['restoreid']));
|
||||
|
||||
// Check the restored course itself.
|
||||
$coursecontext = context_course::instance($postrestorerec->itemid);
|
||||
$coursecontext = \context_course::instance($postrestorerec->itemid);
|
||||
$users = get_enrolled_users($coursecontext);
|
||||
|
||||
$modinfo = get_fast_modinfo($postrestorerec->itemid);
|
||||
@@ -590,7 +586,7 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
$postrestorerec = $DB->get_record('backup_controllers', array('backupid' => $copyids['restoreid']));
|
||||
|
||||
// Check the restored course itself.
|
||||
$coursecontext = context_course::instance($postrestorerec->itemid);
|
||||
$coursecontext = \context_course::instance($postrestorerec->itemid);
|
||||
$users = get_enrolled_users($coursecontext);
|
||||
|
||||
get_fast_modinfo($postrestorerec->itemid, 0, true);
|
||||
|
||||
@@ -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 core_backup;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// Include all the needed stuff.
|
||||
@@ -29,7 +31,7 @@ require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
|
||||
* @copyright 2020 Ilya Tregubov <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class restore_quiz_decode_testcase extends \core_privacy\tests\provider_testcase {
|
||||
class quiz_restore_decode_links_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test restore_decode_rule class
|
||||
@@ -51,16 +53,16 @@ class restore_quiz_decode_testcase extends \core_privacy\tests\provider_testcase
|
||||
// Create questions.
|
||||
|
||||
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
||||
$context = context_course::instance($course->id);
|
||||
$context = \context_course::instance($course->id);
|
||||
$cat = $questiongenerator->create_question_category(array('contextid' => $context->id));
|
||||
$question = $questiongenerator->create_question('multichoice', null, array('category' => $cat->id));
|
||||
|
||||
// Add to the quiz.
|
||||
quiz_add_quiz_question($question->id, $quiz);
|
||||
mod_quiz\external\submit_question_version::execute(
|
||||
\mod_quiz\external\submit_question_version::execute(
|
||||
$DB->get_field('quiz_slots', 'id', ['quizid' => $quiz->id, 'slot' => 1]), 1);
|
||||
|
||||
$questiondata = question_bank::load_question_data($question->id);
|
||||
$questiondata = \question_bank::load_question_data($question->id);
|
||||
|
||||
$firstanswer = array_shift($questiondata->options->answers);
|
||||
$DB->set_field('question_answers', 'answer', $CFG->wwwroot . '/course/view.php?id=' . $course->id,
|
||||
@@ -81,7 +83,7 @@ class restore_quiz_decode_testcase extends \core_privacy\tests\provider_testcase
|
||||
$newcm = duplicate_module($course, get_fast_modinfo($course)->get_cm($quiz->cmid));
|
||||
|
||||
$quizquestions = \mod_quiz\question\bank\qbank_helper::get_question_structure(
|
||||
$newcm->instance, context_module::instance($newcm->id));
|
||||
$newcm->instance, \context_module::instance($newcm->id));
|
||||
$questionids = [];
|
||||
foreach ($quizquestions as $quizquestion) {
|
||||
if ($quizquestion->questionid) {
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use backup;
|
||||
use backup_check;
|
||||
use backup_controller;
|
||||
use backup_controller_exception;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -28,11 +28,15 @@ defined('MOODLE_INTERNAL') || die();
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
|
||||
|
||||
|
||||
/*
|
||||
* check tests (all)
|
||||
/**
|
||||
* Check tests (all).
|
||||
*
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backup_check_testcase extends advanced_testcase {
|
||||
class checks_test extends \advanced_testcase {
|
||||
|
||||
protected $moduleid; // course_modules id used for testing
|
||||
protected $sectionid; // course_sections id used for testing
|
||||
@@ -77,21 +81,21 @@ class backup_check_testcase extends advanced_testcase {
|
||||
try {
|
||||
backup_check::check_id(backup::TYPE_1ACTIVITY, 0);
|
||||
$this->assertTrue(false, 'backup_controller_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof backup_controller_exception);
|
||||
$this->assertEquals($e->errorcode, 'backup_check_module_not_exists');
|
||||
}
|
||||
try {
|
||||
backup_check::check_id(backup::TYPE_1SECTION, 0);
|
||||
$this->assertTrue(false, 'backup_controller_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\exception $e) {
|
||||
$this->assertTrue($e instanceof backup_controller_exception);
|
||||
$this->assertEquals($e->errorcode, 'backup_check_section_not_exists');
|
||||
}
|
||||
try {
|
||||
backup_check::check_id(backup::TYPE_1COURSE, 0);
|
||||
$this->assertTrue(false, 'backup_controller_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof backup_controller_exception);
|
||||
$this->assertEquals($e->errorcode, 'backup_check_course_not_exists');
|
||||
}
|
||||
@@ -100,7 +104,7 @@ class backup_check_testcase extends advanced_testcase {
|
||||
try {
|
||||
backup_check::check_id(12345678,0);
|
||||
$this->assertTrue(false, 'backup_controller_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof backup_controller_exception);
|
||||
$this->assertEquals($e->errorcode, 'backup_check_incorrect_type');
|
||||
}
|
||||
@@ -110,7 +114,7 @@ class backup_check_testcase extends advanced_testcase {
|
||||
try {
|
||||
backup_check::check_user($userid);
|
||||
$this->assertTrue(false, 'backup_controller_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof backup_controller_exception);
|
||||
$this->assertEquals($e->errorcode, 'backup_check_user_not_exists');
|
||||
}
|
||||
@@ -118,9 +122,9 @@ class backup_check_testcase extends advanced_testcase {
|
||||
// Security check tests
|
||||
// Try to pass wrong controller
|
||||
try {
|
||||
backup_check::check_security(new stdclass(), true);
|
||||
backup_check::check_security(new \stdClass(), true);
|
||||
$this->assertTrue(false, 'backup_controller_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof backup_controller_exception);
|
||||
$this->assertEquals($e->errorcode, 'backup_check_security_requires_backup_controller');
|
||||
}
|
||||
|
||||
@@ -16,11 +16,19 @@
|
||||
|
||||
/**
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_backup;
|
||||
|
||||
use backup;
|
||||
use backup_controller;
|
||||
use backup_controller_dbops;
|
||||
use backup_controller_exception;
|
||||
use backup_dbops_exception;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// Include all the needed stuff
|
||||
@@ -28,9 +36,12 @@ global $CFG;
|
||||
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
|
||||
|
||||
/**
|
||||
* Backup dbops tests (all).
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backup_dbops_testcase extends advanced_testcase {
|
||||
class backup_dbops_test extends \advanced_testcase {
|
||||
|
||||
protected $moduleid; // course_modules id used for testing
|
||||
protected $sectionid; // course_sections id used for testing
|
||||
@@ -98,17 +109,17 @@ class backup_dbops_testcase extends advanced_testcase {
|
||||
try {
|
||||
$recid = backup_controller_dbops::save_controller($bc, 'lalala');
|
||||
$this->assertTrue(false, 'backup_dbops_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof backup_dbops_exception);
|
||||
$this->assertEquals($e->errorcode, 'backup_controller_dbops_saving_checksum_mismatch');
|
||||
}
|
||||
|
||||
// Try to save non backup_controller object
|
||||
$bc = new stdclass();
|
||||
$bc = new \stdClass();
|
||||
try {
|
||||
$recid = backup_controller_dbops::save_controller($bc, 'lalala');
|
||||
$this->assertTrue(false, 'backup_controller_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof backup_controller_exception);
|
||||
$this->assertEquals($e->errorcode, 'backup_controller_expected');
|
||||
}
|
||||
@@ -129,7 +140,7 @@ class backup_dbops_testcase extends advanced_testcase {
|
||||
try {
|
||||
$bc = backup_controller_dbops::load_controller('1234567890');
|
||||
$this->assertTrue(false, 'backup_dbops_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof backup_dbops_exception);
|
||||
$this->assertEquals($e->errorcode, 'backup_controller_dbops_nonexisting');
|
||||
}
|
||||
@@ -150,7 +161,7 @@ class backup_dbops_testcase extends advanced_testcase {
|
||||
|
||||
// Test encoding/decoding of backup_ids_temp,backup_files_temp encode/decode functions.
|
||||
// We need to handle both objects and data elements.
|
||||
$object = new stdClass();
|
||||
$object = new \stdClass();
|
||||
$object->item1 = 10;
|
||||
$object->item2 = 'a String';
|
||||
$testarray = array($object, 10, null, 'string', array('a' => 'b', 1 => 1));
|
||||
|
||||
@@ -14,12 +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/>.
|
||||
|
||||
/**
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use restore_controller_dbops;
|
||||
use restore_dbops;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -28,9 +26,12 @@ global $CFG;
|
||||
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
|
||||
|
||||
/**
|
||||
* Restore dbops tests (all).
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class restore_dbops_testcase extends advanced_testcase {
|
||||
class restore_dbops_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Verify the xxx_ids_cached (in-memory backup_ids cache) stuff works as expected.
|
||||
@@ -47,7 +48,7 @@ class restore_dbops_testcase extends advanced_testcase {
|
||||
// Some variables and objects for testing.
|
||||
$restoreid = 'testrestoreid';
|
||||
|
||||
$mapping = new stdClass();
|
||||
$mapping = new \stdClass();
|
||||
$mapping->itemname = 'user';
|
||||
$mapping->itemid = 1;
|
||||
$mapping->newitemid = 2;
|
||||
@@ -68,8 +69,8 @@ class restore_dbops_testcase extends advanced_testcase {
|
||||
$this->assertSame(null, $result->info);
|
||||
|
||||
// Drop the backup_xxx_temp temptables manually, so memory cache won't be invalidated.
|
||||
$dbman->drop_table(new xmldb_table('backup_ids_temp'));
|
||||
$dbman->drop_table(new xmldb_table('backup_files_temp'));
|
||||
$dbman->drop_table(new \xmldb_table('backup_ids_temp'));
|
||||
$dbman->drop_table(new \xmldb_table('backup_files_temp'));
|
||||
|
||||
// Verify the mapping continues returning the same info,
|
||||
// now from cache (the table does not exist).
|
||||
@@ -90,8 +91,8 @@ class restore_dbops_testcase extends advanced_testcase {
|
||||
try {
|
||||
$result = restore_dbops::get_backup_ids_record($restoreid, $mapping->itemname, $mapping->itemid);
|
||||
$this->fail('Expecting an exception, none occurred');
|
||||
} catch (Exception $e) {
|
||||
$this->assertTrue($e instanceof dml_exception);
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof \dml_exception);
|
||||
$this->assertSame('Table "backup_ids_temp" does not exist', $e->getMessage());
|
||||
}
|
||||
|
||||
@@ -114,8 +115,8 @@ class restore_dbops_testcase extends advanced_testcase {
|
||||
try {
|
||||
$result = restore_dbops::get_backup_ids_record($restoreid, $mapping->itemname, $mapping->itemid);
|
||||
$this->fail('Expecting an exception, none occurred');
|
||||
} catch (Exception $e) {
|
||||
$this->assertTrue($e instanceof dml_exception);
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof \dml_exception);
|
||||
$this->assertSame('Table "backup_ids_temp" does not exist', $e->getMessage());
|
||||
}
|
||||
}
|
||||
@@ -349,7 +350,7 @@ class restore_dbops_testcase extends advanced_testcase {
|
||||
// Get the dbuser record, because we may have changed it above.
|
||||
$dbuser = $DB->get_record('user', ['id' => $dbuser->id]);
|
||||
|
||||
$method = (new ReflectionClass('restore_dbops'))->getMethod('precheck_user');
|
||||
$method = (new \ReflectionClass('restore_dbops'))->getMethod('precheck_user');
|
||||
$method->setAccessible(true);
|
||||
$result = $method->invoke(null, $backupuser, $samesite, $siteid);
|
||||
|
||||
|
||||
@@ -14,23 +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/>.
|
||||
|
||||
namespace core_backup;
|
||||
|
||||
/**
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// Include all the needed stuff
|
||||
global $CFG;
|
||||
//require_once($CFG->dirroot . '/backup/util/helper/backup_helper.class.php');
|
||||
|
||||
/**
|
||||
* dbops tests (all)
|
||||
*/
|
||||
class backup_destinations_testcase extends basic_testcase {
|
||||
class destinations_test extends \basic_testcase {
|
||||
|
||||
/**
|
||||
* test backup_destination class
|
||||
|
||||
@@ -14,12 +14,14 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use backup;
|
||||
use backup_factory;
|
||||
use database_logger;
|
||||
use error_log_logger;
|
||||
use file_logger;
|
||||
use output_indented_logger;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -34,11 +36,13 @@ require_once($CFG->dirroot . '/backup/util/loggers/database_logger.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/loggers/file_logger.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/factories/backup_factory.class.php');
|
||||
|
||||
|
||||
/**
|
||||
* backup_factory tests (all)
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backup_factories_testcase extends advanced_testcase {
|
||||
class factories_test extends \advanced_testcase {
|
||||
|
||||
public function setUp(): void {
|
||||
global $CFG;
|
||||
|
||||
@@ -14,13 +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/>.
|
||||
|
||||
/**
|
||||
* Asyncronhous helper tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2018 Matt Porritt <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use async_helper;
|
||||
use backup;
|
||||
use backup_controller;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -31,10 +29,11 @@ require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
|
||||
/**
|
||||
* Asyncronhous helper tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2018 Matt Porritt <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_backup_async_helper_testcase extends \core_privacy\tests\provider_testcase {
|
||||
class async_helper_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests sending message for asynchronous backup.
|
||||
@@ -113,7 +112,7 @@ class core_backup_async_helper_testcase extends \core_privacy\tests\provider_tes
|
||||
// We need a grade, easiest is to add an assignment.
|
||||
$assignrow = $generator->create_module('assign', array(
|
||||
'course' => $course->id));
|
||||
$assign = new assign(context_module::instance($assignrow->cmid), false, false);
|
||||
$assign = new \assign(\context_module::instance($assignrow->cmid), false, false);
|
||||
$item = $assign->get_grade_item();
|
||||
|
||||
// Make a test grouping as well.
|
||||
@@ -137,7 +136,7 @@ class core_backup_async_helper_testcase extends \core_privacy\tests\provider_tes
|
||||
$bc->destroy();
|
||||
unset($bc);
|
||||
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
$coursecontext = \context_course::instance($course->id);
|
||||
$renderer = $PAGE->get_renderer('core', 'backup');
|
||||
|
||||
$result = \async_helper::get_async_backups($renderer, $coursecontext->instanceid);
|
||||
|
||||
@@ -14,30 +14,29 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @copyright 2013 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use backup_course_task;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
|
||||
require_once($CFG->dirroot . '/backup/moodle2/backup_course_task.class.php');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tests for encoding content links in backup_course_task.
|
||||
*
|
||||
* The code that this tests is actually in backup/moodle2/backup_course_task.class.php,
|
||||
* but there is no place for unit tests near there, and perhaps one day it will
|
||||
* be refactored so it becomes more generic.
|
||||
*
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2013 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backup_course_task_testcase extends basic_testcase {
|
||||
class backup_encode_content_test extends \basic_testcase {
|
||||
|
||||
/**
|
||||
* Test the encode_content_links method for course.
|
||||
|
||||
@@ -15,34 +15,34 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Test the convert helper.
|
||||
*
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_backup;
|
||||
|
||||
use backup;
|
||||
use convert_helper;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// Include all the needed stuff
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/backup/util/helper/convert_helper.class.php');
|
||||
|
||||
|
||||
/**
|
||||
* Provides access to the protected methods we need to test
|
||||
* Test the convert helper.
|
||||
*
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class testable_convert_helper extends convert_helper {
|
||||
|
||||
public static function choose_conversion_path($format, array $descriptions) {
|
||||
return parent::choose_conversion_path($format, $descriptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Defines the test methods
|
||||
*/
|
||||
class backup_convert_helper_testcase extends basic_testcase {
|
||||
class converterhelper_test extends \basic_testcase {
|
||||
|
||||
public function test_choose_conversion_path() {
|
||||
|
||||
@@ -143,3 +143,13 @@ class backup_convert_helper_testcase extends basic_testcase {
|
||||
$this->assertEquals($path, array('cc1', 'cc3', 'cc4'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to the protected methods we need to test
|
||||
*/
|
||||
class testable_convert_helper extends convert_helper {
|
||||
|
||||
public static function choose_conversion_path($format, array $descriptions) {
|
||||
return parent::choose_conversion_path($format, $descriptions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,16 @@
|
||||
* Unit tests for backups cron helper.
|
||||
*
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @category test
|
||||
* @copyright 2012 Frédéric Massart <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_backup;
|
||||
|
||||
use backup;
|
||||
use backup_cron_automated_helper;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
@@ -31,9 +36,14 @@ require_once($CFG->dirroot . '/backup/util/interfaces/checksumable.class.php');
|
||||
require_once("$CFG->dirroot/backup/backup.class.php");
|
||||
|
||||
/**
|
||||
* Unit tests for backup cron helper
|
||||
* Unit tests for backups cron helper.
|
||||
*
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2012 Frédéric Massart <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backup_cron_helper_testcase extends advanced_testcase {
|
||||
class cronhelper_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test {@link backup_cron_automated_helper::calculate_next_automated_backup}.
|
||||
*/
|
||||
@@ -349,7 +359,7 @@ class backup_cron_helper_testcase extends advanced_testcase {
|
||||
];
|
||||
$event = \core\event\course_backup_created::create([
|
||||
'objectid' => $course->id,
|
||||
'context' => context_course::instance($course->id),
|
||||
'context' => \context_course::instance($course->id),
|
||||
'other' => $otherarray
|
||||
]);
|
||||
$event->trigger();
|
||||
@@ -380,13 +390,13 @@ class backup_cron_helper_testcase extends advanced_testcase {
|
||||
$course4 = $this->getDataGenerator()->create_course(array('timecreated' => 1552179600));
|
||||
|
||||
// Create backup course records for the courses that need them.
|
||||
$backupcourse3 = new stdClass;
|
||||
$backupcourse3 = new \stdClass;
|
||||
$backupcourse3->courseid = $course3->id;
|
||||
$backupcourse3->laststatus = testable_backup_cron_automated_helper::BACKUP_STATUS_OK;
|
||||
$backupcourse3->nextstarttime = 1554858160;
|
||||
$DB->insert_record('backup_courses', $backupcourse3);
|
||||
|
||||
$backupcourse4 = new stdClass;
|
||||
$backupcourse4 = new \stdClass;
|
||||
$backupcourse4->courseid = $course4->id;
|
||||
$backupcourse4->laststatus = testable_backup_cron_automated_helper::BACKUP_STATUS_OK;
|
||||
$backupcourse4->nextstarttime = 1554858160;
|
||||
|
||||
@@ -16,11 +16,16 @@
|
||||
|
||||
/**
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_backup;
|
||||
|
||||
use restore_decode_rule;
|
||||
use restore_decode_rule_exception;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// Include all the needed stuff
|
||||
@@ -29,9 +34,14 @@ require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
|
||||
|
||||
|
||||
/**
|
||||
* restore_decode tests (both rule and content)
|
||||
* Restore_decode tests (both rule and content)
|
||||
*
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backup_restore_decode_testcase extends basic_testcase {
|
||||
class decode_test extends \basic_testcase {
|
||||
|
||||
/**
|
||||
* test restore_decode_rule class
|
||||
@@ -42,7 +52,7 @@ class backup_restore_decode_testcase extends basic_testcase {
|
||||
try {
|
||||
$dr = new restore_decode_rule('28 HJH', '/index.php', array());
|
||||
$this->assertTrue(false, 'restore_decode_rule_exception exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof restore_decode_rule_exception);
|
||||
$this->assertEquals($e->errorcode, 'decode_rule_incorrect_name');
|
||||
$this->assertEquals($e->a, '28 HJH');
|
||||
@@ -51,7 +61,7 @@ class backup_restore_decode_testcase extends basic_testcase {
|
||||
try {
|
||||
$dr = new restore_decode_rule('HJHJhH', '/index.php', array());
|
||||
$this->assertTrue(false, 'restore_decode_rule_exception exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof restore_decode_rule_exception);
|
||||
$this->assertEquals($e->errorcode, 'decode_rule_incorrect_name');
|
||||
$this->assertEquals($e->a, 'HJHJhH');
|
||||
@@ -60,7 +70,7 @@ class backup_restore_decode_testcase extends basic_testcase {
|
||||
try {
|
||||
$dr = new restore_decode_rule('', '/index.php', array());
|
||||
$this->assertTrue(false, 'restore_decode_rule_exception exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof restore_decode_rule_exception);
|
||||
$this->assertEquals($e->errorcode, 'decode_rule_incorrect_name');
|
||||
$this->assertEquals($e->a, '');
|
||||
@@ -69,7 +79,7 @@ class backup_restore_decode_testcase extends basic_testcase {
|
||||
try {
|
||||
$dr = new restore_decode_rule('TESTRULE', 'index.php', array());
|
||||
$this->assertTrue(false, 'restore_decode_rule_exception exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof restore_decode_rule_exception);
|
||||
$this->assertEquals($e->errorcode, 'decode_rule_incorrect_urltemplate');
|
||||
$this->assertEquals($e->a, 'index.php');
|
||||
@@ -78,7 +88,7 @@ class backup_restore_decode_testcase extends basic_testcase {
|
||||
try {
|
||||
$dr = new restore_decode_rule('TESTRULE', '', array());
|
||||
$this->assertTrue(false, 'restore_decode_rule_exception exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof restore_decode_rule_exception);
|
||||
$this->assertEquals($e->errorcode, 'decode_rule_incorrect_urltemplate');
|
||||
$this->assertEquals($e->a, '');
|
||||
@@ -87,7 +97,7 @@ class backup_restore_decode_testcase extends basic_testcase {
|
||||
try {
|
||||
$dr = new restore_decode_rule('TESTRULE', '/course/view.php?id=$1&c=$2$3', array('test1', 'test2'));
|
||||
$this->assertTrue(false, 'restore_decode_rule_exception exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof restore_decode_rule_exception);
|
||||
$this->assertEquals($e->errorcode, 'decode_rule_mappings_incorrect_count');
|
||||
$this->assertEquals($e->a->placeholders, 3);
|
||||
@@ -97,7 +107,7 @@ class backup_restore_decode_testcase extends basic_testcase {
|
||||
try {
|
||||
$dr = new restore_decode_rule('TESTRULE', '/course/view.php?id=$5&c=$4$1', array('test1', 'test2', 'test3'));
|
||||
$this->assertTrue(false, 'restore_decode_rule_exception exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof restore_decode_rule_exception);
|
||||
$this->assertEquals($e->errorcode, 'decode_rule_nonconsecutive_placeholders');
|
||||
$this->assertEquals($e->a, '1, 4, 5');
|
||||
@@ -106,7 +116,7 @@ class backup_restore_decode_testcase extends basic_testcase {
|
||||
try {
|
||||
$dr = new restore_decode_rule('TESTRULE', '/course/view.php?id=$0&c=$3$2', array('test1', 'test2', 'test3'));
|
||||
$this->assertTrue(false, 'restore_decode_rule_exception exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof restore_decode_rule_exception);
|
||||
$this->assertEquals($e->errorcode, 'decode_rule_nonconsecutive_placeholders');
|
||||
$this->assertEquals($e->a, '0, 2, 3');
|
||||
@@ -115,7 +125,7 @@ class backup_restore_decode_testcase extends basic_testcase {
|
||||
try {
|
||||
$dr = new restore_decode_rule('TESTRULE', '/course/view.php?id=$1&c=$3$3', array('test1', 'test2', 'test3'));
|
||||
$this->assertTrue(false, 'restore_decode_rule_exception exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof restore_decode_rule_exception);
|
||||
$this->assertEquals($e->errorcode, 'decode_rule_duplicate_placeholders');
|
||||
$this->assertEquals($e->a, '1, 3, 3');
|
||||
|
||||
@@ -14,12 +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/>.
|
||||
|
||||
/**
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2015 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use restore_log_rule;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -27,13 +24,20 @@ defined('MOODLE_INTERNAL') || die();
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
|
||||
|
||||
|
||||
class backup_restore_log_rule_testcase extends basic_testcase {
|
||||
/**
|
||||
* Test the backup and restore of logs using rules.
|
||||
*
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2015 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class restore_log_rule_test extends \basic_testcase {
|
||||
|
||||
function test_process_keeps_log_unmodified() {
|
||||
|
||||
// Prepare a tiny log entry.
|
||||
$originallog = new stdClass();
|
||||
$originallog = new \stdClass();
|
||||
$originallog->url = 'original';
|
||||
$originallog->info = 'original';
|
||||
$log = clone($originallog);
|
||||
@@ -55,7 +59,7 @@ class backup_restore_log_rule_testcase extends basic_testcase {
|
||||
$expectation = '~Any \(string\) with (.*) like (.*) and (.*)\. (.*)\.~';
|
||||
|
||||
$lr = new restore_log_rule('this', 'doesnt', 'matter', 'here');
|
||||
$class = new ReflectionClass('restore_log_rule');
|
||||
$class = new \ReflectionClass('restore_log_rule');
|
||||
|
||||
$method = $class->getMethod('extract_tokens');
|
||||
$method->setAccessible(true);
|
||||
|
||||
@@ -15,12 +15,24 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Logger tests (all).
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_backup;
|
||||
|
||||
use backup;
|
||||
use base_logger;
|
||||
use base_logger_exception;
|
||||
use database_logger;
|
||||
use error_log_logger;
|
||||
use file_logger;
|
||||
use output_indented_logger;
|
||||
use output_text_logger;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// Include all the needed stuff
|
||||
@@ -36,9 +48,14 @@ require_once($CFG->dirroot . '/backup/util/loggers/file_logger.class.php');
|
||||
|
||||
|
||||
/**
|
||||
* logger tests (all)
|
||||
* Logger tests (all).
|
||||
*
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backup_logger_testcase extends basic_testcase {
|
||||
class logger_test extends \basic_testcase {
|
||||
|
||||
/**
|
||||
* test base_logger class
|
||||
@@ -65,10 +82,10 @@ class backup_logger_testcase extends basic_testcase {
|
||||
try {
|
||||
$lo1->set_next($lo1); //self
|
||||
$this->assertTrue(false, 'base_logger_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_logger_exception);
|
||||
$this->assertEquals($e->errorcode, 'logger_circular_reference');
|
||||
$this->assertTrue($e->a instanceof stdclass);
|
||||
$this->assertTrue($e->a instanceof \stdClass);
|
||||
$this->assertEquals($e->a->main, get_class($lo1));
|
||||
$this->assertEquals($e->a->alreadyinchain, get_class($lo1));
|
||||
}
|
||||
@@ -81,10 +98,10 @@ class backup_logger_testcase extends basic_testcase {
|
||||
try {
|
||||
$lo3->set_next($lo1);
|
||||
$this->assertTrue(false, 'base_logger_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_logger_exception);
|
||||
$this->assertEquals($e->errorcode, 'logger_circular_reference');
|
||||
$this->assertTrue($e->a instanceof stdclass);
|
||||
$this->assertTrue($e->a instanceof \stdClass);
|
||||
$this->assertEquals($e->a->main, get_class($lo1));
|
||||
$this->assertEquals($e->a->alreadyinchain, get_class($lo3));
|
||||
}
|
||||
@@ -241,7 +258,7 @@ class backup_logger_testcase extends basic_testcase {
|
||||
@remove_dir(dirname($file));
|
||||
// Recreate test dir
|
||||
if (!check_dir_exists(dirname($file), true, true)) {
|
||||
throw new moodle_exception('error_creating_temp_dir', 'error', dirname($file));
|
||||
throw new \moodle_exception('error_creating_temp_dir', 'error', dirname($file));
|
||||
}
|
||||
|
||||
// Instantiate with date and level output, and also use the depth option
|
||||
@@ -308,7 +325,7 @@ class backup_logger_testcase extends basic_testcase {
|
||||
try {
|
||||
$result = @$lo->process($message, backup::LOG_ERROR); // Try to write again
|
||||
$this->assertTrue(false, 'base_logger_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_logger_exception);
|
||||
$this->assertEquals($e->errorcode, 'error_writing_file');
|
||||
}
|
||||
@@ -317,7 +334,7 @@ class backup_logger_testcase extends basic_testcase {
|
||||
try {
|
||||
$lo = new file_logger(backup::LOG_WARNING, true, true, '');
|
||||
$this->assertTrue(false, 'base_logger_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_logger_exception);
|
||||
$this->assertEquals($e->errorcode, 'missing_fullpath_parameter');
|
||||
}
|
||||
@@ -327,7 +344,7 @@ class backup_logger_testcase extends basic_testcase {
|
||||
try {
|
||||
$lo = new file_logger(backup::LOG_WARNING, true, true, $file);
|
||||
$this->assertTrue(false, 'base_logger_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_logger_exception);
|
||||
$this->assertEquals($e->errorcode, 'file_not_writable');
|
||||
$this->assertEquals($e->a, $file);
|
||||
|
||||
@@ -15,12 +15,26 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Setting tests (all).
|
||||
*
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_backup;
|
||||
|
||||
use activity_backup_setting;
|
||||
use backup_setting;
|
||||
use backup_setting_exception;
|
||||
use base_setting;
|
||||
use base_setting_exception;
|
||||
use course_backup_setting;
|
||||
use section_backup_setting;
|
||||
use setting_dependency;
|
||||
use setting_dependency_disabledif_empty;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// Include all the needed stuff
|
||||
@@ -36,11 +50,15 @@ require_once($CFG->dirroot . '/backup/util/settings/section/section_backup_setti
|
||||
require_once($CFG->dirroot . '/backup/util/settings/course/course_backup_setting.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/ui/backup_ui_setting.class.php');
|
||||
|
||||
|
||||
/**
|
||||
* setting tests (all)
|
||||
* Setting tests (all).
|
||||
*
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backp_settings_testcase extends basic_testcase {
|
||||
class settings_test extends \basic_testcase {
|
||||
|
||||
/**
|
||||
* test base_setting class
|
||||
@@ -74,7 +92,7 @@ class backp_settings_testcase extends basic_testcase {
|
||||
try {
|
||||
$bs = new mock_base_setting('test', 'one_wrong_type');
|
||||
$this->assertTrue(false, 'base_setting_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_setting_exception);
|
||||
$this->assertEquals($e->errorcode, 'setting_invalid_type');
|
||||
}
|
||||
@@ -83,7 +101,7 @@ class backp_settings_testcase extends basic_testcase {
|
||||
try {
|
||||
$bs = new mock_base_setting('test', base_setting::IS_INTEGER, 99.99);
|
||||
$this->assertTrue(false, 'base_setting_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_setting_exception);
|
||||
$this->assertEquals($e->errorcode, 'setting_invalid_integer');
|
||||
}
|
||||
@@ -92,7 +110,7 @@ class backp_settings_testcase extends basic_testcase {
|
||||
try {
|
||||
$bs = new mock_base_setting('test', base_setting::IS_FILENAME, '../../filename.txt');
|
||||
$this->assertTrue(false, 'base_setting_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_setting_exception);
|
||||
$this->assertEquals($e->errorcode, 'setting_invalid_filename');
|
||||
}
|
||||
@@ -101,7 +119,7 @@ class backp_settings_testcase extends basic_testcase {
|
||||
try {
|
||||
$bs = new mock_base_setting('test', base_setting::IS_BOOLEAN, null, 'one_wrong_visibility');
|
||||
$this->assertTrue(false, 'base_setting_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_setting_exception);
|
||||
$this->assertEquals($e->errorcode, 'setting_invalid_visibility');
|
||||
}
|
||||
@@ -110,7 +128,7 @@ class backp_settings_testcase extends basic_testcase {
|
||||
try {
|
||||
$bs = new mock_base_setting('test', base_setting::IS_BOOLEAN, null, null, 'one_wrong_status');
|
||||
$this->assertTrue(false, 'base_setting_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_setting_exception);
|
||||
$this->assertEquals($e->errorcode, 'setting_invalid_status');
|
||||
}
|
||||
@@ -119,14 +137,14 @@ class backp_settings_testcase extends basic_testcase {
|
||||
// We need a custom error handler to catch the type hinting error
|
||||
// that should return incorrect_object_passed
|
||||
$bs = new mock_base_setting('test', base_setting::IS_BOOLEAN);
|
||||
set_error_handler('backup_setting_error_handler', E_RECOVERABLE_ERROR);
|
||||
set_error_handler('\core_backup\backup_setting_error_handler', E_RECOVERABLE_ERROR);
|
||||
try {
|
||||
$bs->set_ui('one_wrong_ui_type', 'label', array(), array());
|
||||
$this->assertTrue(false, 'base_setting_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_setting_exception);
|
||||
$this->assertEquals($e->errorcode, 'incorrect_object_passed');
|
||||
} catch (TypeError $e) {
|
||||
} catch (\TypeError $e) {
|
||||
// On PHP7+ we get a TypeError raised, lets check we've the right error.
|
||||
$this->assertMatchesRegularExpression('/must be (of type|an instance of) backup_setting_ui/', $e->getMessage());
|
||||
}
|
||||
@@ -136,14 +154,14 @@ class backp_settings_testcase extends basic_testcase {
|
||||
// We need a custom error handler to catch the type hinting error
|
||||
// that should return incorrect_object_passed
|
||||
$bs = new mock_base_setting('test', base_setting::IS_BOOLEAN);
|
||||
set_error_handler('backup_setting_error_handler', E_RECOVERABLE_ERROR);
|
||||
set_error_handler('\core_backup\backup_setting_error_handler', E_RECOVERABLE_ERROR);
|
||||
try {
|
||||
$bs->set_ui(base_setting::UI_HTML_CHECKBOX, 'one/wrong/label', array(), array());
|
||||
$this->assertTrue(false, 'base_setting_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_setting_exception);
|
||||
$this->assertEquals($e->errorcode, 'incorrect_object_passed');
|
||||
} catch (TypeError $e) {
|
||||
} catch (\TypeError $e) {
|
||||
// On PHP7+ we get a TypeError raised, lets check we've the right error.
|
||||
$this->assertMatchesRegularExpression('/must be (of type|an instance of) backup_setting_ui/', $e->getMessage());
|
||||
}
|
||||
@@ -154,7 +172,7 @@ class backp_settings_testcase extends basic_testcase {
|
||||
try {
|
||||
$bs->set_value(true);
|
||||
$this->assertTrue(false, 'base_setting_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_setting_exception);
|
||||
$this->assertEquals($e->errorcode, 'setting_locked_by_permission');
|
||||
}
|
||||
@@ -164,7 +182,7 @@ class backp_settings_testcase extends basic_testcase {
|
||||
try {
|
||||
$bs->set_value(true);
|
||||
$this->assertTrue(false, 'base_setting_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_setting_exception);
|
||||
$this->assertEquals($e->errorcode, 'setting_locked_by_config');
|
||||
}
|
||||
@@ -176,7 +194,7 @@ class backp_settings_testcase extends basic_testcase {
|
||||
try {
|
||||
$bs1->add_dependency($bs2);
|
||||
$this->assertTrue(false, 'base_setting_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_setting_exception);
|
||||
$this->assertEquals($e->errorcode, 'setting_already_added');
|
||||
}
|
||||
@@ -186,10 +204,10 @@ class backp_settings_testcase extends basic_testcase {
|
||||
try {
|
||||
$bs1->add_dependency($bs1); // self
|
||||
$this->assertTrue(false, 'base_setting_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_setting_exception);
|
||||
$this->assertEquals($e->errorcode, 'setting_circular_reference');
|
||||
$this->assertTrue($e->a instanceof stdclass);
|
||||
$this->assertTrue($e->a instanceof \stdClass);
|
||||
$this->assertEquals($e->a->main, 'test1');
|
||||
$this->assertEquals($e->a->alreadydependent, 'test1');
|
||||
}
|
||||
@@ -204,10 +222,10 @@ class backp_settings_testcase extends basic_testcase {
|
||||
try {
|
||||
$bs4->add_dependency($bs1, null, array('value'=>0));
|
||||
$this->assertTrue(false, 'base_setting_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_setting_exception);
|
||||
$this->assertEquals($e->errorcode, 'setting_circular_reference');
|
||||
$this->assertTrue($e->a instanceof stdclass);
|
||||
$this->assertTrue($e->a instanceof \stdClass);
|
||||
$this->assertEquals($e->a->main, 'test1');
|
||||
$this->assertEquals($e->a->alreadydependent, 'test4');
|
||||
}
|
||||
@@ -219,10 +237,10 @@ class backp_settings_testcase extends basic_testcase {
|
||||
// $bs1 is already dependent on $bs2 so this should fail.
|
||||
$bs2->register_dependency(new setting_dependency_disabledif_empty($bs2, $bs1));
|
||||
$this->assertTrue(false, 'base_setting_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_setting_exception);
|
||||
$this->assertEquals($e->errorcode, 'setting_circular_reference');
|
||||
$this->assertTrue($e->a instanceof stdclass);
|
||||
$this->assertTrue($e->a instanceof \stdClass);
|
||||
$this->assertEquals($e->a->main, 'test1');
|
||||
$this->assertEquals($e->a->alreadydependent, 'test2');
|
||||
}
|
||||
@@ -344,15 +362,15 @@ class backp_settings_testcase extends basic_testcase {
|
||||
$this->assertEquals($bs->get_level(), 1);
|
||||
|
||||
// Instantiate backup setting class and try to add one non backup_setting dependency
|
||||
set_error_handler('backup_setting_error_handler', E_RECOVERABLE_ERROR);
|
||||
set_error_handler('\core_backup\backup_setting_error_handler', E_RECOVERABLE_ERROR);
|
||||
$bs = new mock_backup_setting('test', base_setting::IS_INTEGER, null);
|
||||
try {
|
||||
$bs->add_dependency(new stdclass());
|
||||
$bs->add_dependency(new \stdClass());
|
||||
$this->assertTrue(false, 'backup_setting_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof backup_setting_exception);
|
||||
$this->assertEquals($e->errorcode, 'incorrect_object_passed');
|
||||
} catch (TypeError $e) {
|
||||
} catch (\TypeError $e) {
|
||||
// On PHP7+ we get a TypeError raised, lets check we've the right error.
|
||||
$this->assertMatchesRegularExpression('/must be (an instance of|of type) base_setting/', $e->getMessage());
|
||||
}
|
||||
@@ -366,7 +384,7 @@ class backp_settings_testcase extends basic_testcase {
|
||||
try {
|
||||
$bs2->add_dependency($bs1);
|
||||
$this->assertTrue(false, 'backup_setting_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof backup_setting_exception);
|
||||
$this->assertEquals($e->errorcode, 'cannot_add_upper_level_dependency');
|
||||
}
|
||||
|
||||
@@ -14,12 +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/>.
|
||||
|
||||
/**
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use base_atom_content_exception;
|
||||
use base_atom_struct_exception;
|
||||
use mock_base_atom;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -28,10 +27,16 @@ require_once(__DIR__.'/fixtures/structure_fixtures.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit test case the base_atom class. Note: as it's abstract we are testing
|
||||
* mock_base_atom instantiable class instead
|
||||
* Unit test case the base_atom class.
|
||||
*
|
||||
* Note: as it's abstract we are testing mock_base_atom instantiable class instead
|
||||
*
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backup_base_atom_testcase extends basic_testcase {
|
||||
class baseatom_test extends \basic_testcase {
|
||||
|
||||
/**
|
||||
* Correct base_atom_tests
|
||||
@@ -80,7 +85,7 @@ class backup_base_atom_testcase extends basic_testcase {
|
||||
try {
|
||||
$instance = new mock_base_atom('');
|
||||
$this->fail("Expecting base_atom_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_atom_struct_exception);
|
||||
}
|
||||
|
||||
@@ -88,7 +93,7 @@ class backup_base_atom_testcase extends basic_testcase {
|
||||
try {
|
||||
$instance = new mock_base_atom('TESTING ATOM');
|
||||
$this->fail("Expecting base_atom_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_atom_struct_exception);
|
||||
}
|
||||
|
||||
@@ -96,13 +101,13 @@ class backup_base_atom_testcase extends basic_testcase {
|
||||
try {
|
||||
$instance = new mock_base_atom('TESTING-ATOM');
|
||||
$this->fail("Expecting base_atom_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_atom_struct_exception);
|
||||
}
|
||||
try {
|
||||
$instance = new mock_base_atom('TESTING_ATOM_Á');
|
||||
$this->fail("Expecting base_atom_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_atom_struct_exception);
|
||||
}
|
||||
|
||||
@@ -112,7 +117,7 @@ class backup_base_atom_testcase extends basic_testcase {
|
||||
try {
|
||||
$instance->set_value('test');
|
||||
$this->fail("Expecting base_atom_content_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_atom_content_exception);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,12 +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/>.
|
||||
|
||||
/**
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use mock_base_attribute;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -28,10 +25,17 @@ require_once(__DIR__.'/fixtures/structure_fixtures.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit test case the base_attribute class. Note: No really much to test here as attribute is 100%
|
||||
* Unit test case the base_attribute class.
|
||||
*
|
||||
* Note: No really much to test here as attribute is 100%
|
||||
* atom extension without new functionality (name/value)
|
||||
*
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backup_base_attribute_testcase extends basic_testcase {
|
||||
class baseattribute_test extends \basic_testcase {
|
||||
|
||||
/**
|
||||
* Correct base_attribute tests
|
||||
|
||||
@@ -14,12 +14,13 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use base_atom_struct_exception;
|
||||
use base_attribute;
|
||||
use base_element_attribute_exception;
|
||||
use mock_base_attribute;
|
||||
use mock_base_final_element;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -28,9 +29,16 @@ require_once(__DIR__.'/fixtures/structure_fixtures.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit test case the base_final_element class. Note: highly imbricated with base_nested_element class
|
||||
* Unit test case the base_final_element class.
|
||||
*
|
||||
* Note: highly imbricated with base_nested_element class
|
||||
*
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backup_base_final_element_testcase extends basic_testcase {
|
||||
class basefinalelement_test extends \basic_testcase {
|
||||
|
||||
/**
|
||||
* Correct base_final_element tests
|
||||
@@ -128,27 +136,27 @@ class backup_base_final_element_testcase extends basic_testcase {
|
||||
try {
|
||||
$instance = new mock_base_final_element('');
|
||||
$this->fail("Expecting base_atom_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_atom_struct_exception);
|
||||
}
|
||||
|
||||
// Create instance with incorrect (object) attribute
|
||||
try {
|
||||
$obj = new stdClass;
|
||||
$obj = new \stdClass;
|
||||
$obj->name = 'test_attr';
|
||||
$instance = new mock_base_final_element('TEST', $obj);
|
||||
$this->fail("Expecting base_element_attribute_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_attribute_exception);
|
||||
}
|
||||
|
||||
// Create instance with array containing incorrect (object) attribute
|
||||
try {
|
||||
$obj = new stdClass;
|
||||
$obj = new \stdClass;
|
||||
$obj->name = 'test_attr';
|
||||
$instance = new mock_base_final_element('TEST', array($obj));
|
||||
$this->fail("Expecting base_element_attribute_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_attribute_exception);
|
||||
}
|
||||
|
||||
@@ -156,7 +164,7 @@ class backup_base_final_element_testcase extends basic_testcase {
|
||||
try {
|
||||
$instance = new mock_base_final_element('TEST', array('ATTR1', 'ATTR2', 'ATTR1'));
|
||||
$this->fail("Expecting base_element_attribute_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_attribute_exception);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,12 +14,14 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use base_atom_struct_exception;
|
||||
use base_element_parent_exception;
|
||||
use base_element_struct_exception;
|
||||
use mock_base_attribute;
|
||||
use mock_base_final_element;
|
||||
use mock_base_nested_element;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -28,9 +30,16 @@ require_once(__DIR__.'/fixtures/structure_fixtures.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit test case the base_nested_element class. Note: highly imbricated with base_final_element class
|
||||
* Unit test case the base_nested_element class.
|
||||
*
|
||||
* Note: highly imbricated with base_final_element class
|
||||
*
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backup_base_nested_element_testcase extends basic_testcase {
|
||||
class basenestedelement_test extends \basic_testcase {
|
||||
|
||||
/**
|
||||
* Correct creation tests (attributes and final elements)
|
||||
@@ -179,27 +188,27 @@ class backup_base_nested_element_testcase extends basic_testcase {
|
||||
try {
|
||||
$instance = new mock_base_nested_element('');
|
||||
$this->fail("Expecting base_atom_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_atom_struct_exception);
|
||||
}
|
||||
|
||||
// Create instance with incorrect (object) final element
|
||||
try {
|
||||
$obj = new stdClass;
|
||||
$obj = new \stdClass;
|
||||
$obj->name = 'test_attr';
|
||||
$instance = new mock_base_nested_element('TEST', null, $obj);
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
}
|
||||
|
||||
// Create instance with array containing incorrect (object) final element
|
||||
try {
|
||||
$obj = new stdClass;
|
||||
$obj = new \stdClass;
|
||||
$obj->name = 'test_attr';
|
||||
$instance = new mock_base_nested_element('TEST', null, array($obj));
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
}
|
||||
|
||||
@@ -207,7 +216,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
|
||||
try {
|
||||
$instance = new mock_base_nested_element('TEST', null, array('VAL1', 'VAL2', 'VAL1'));
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
}
|
||||
|
||||
@@ -216,7 +225,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
|
||||
try {
|
||||
$instance->get_value();
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
}
|
||||
|
||||
@@ -225,7 +234,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
|
||||
try {
|
||||
$instance->set_value('some_value');
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
}
|
||||
|
||||
@@ -234,7 +243,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
|
||||
try {
|
||||
$instance->clean_value('some_value');
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
}
|
||||
}
|
||||
@@ -304,17 +313,17 @@ class backup_base_nested_element_testcase extends basic_testcase {
|
||||
try {
|
||||
$parent->add_child($child);
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
}
|
||||
|
||||
// Add non base_element object child
|
||||
$parent = new mock_base_nested_element('PARENT');
|
||||
$child = new stdClass();
|
||||
$child = new \stdClass();
|
||||
try {
|
||||
$parent->add_child($child);
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
}
|
||||
|
||||
@@ -324,7 +333,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
|
||||
try {
|
||||
$parent->add_child($child);
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
}
|
||||
|
||||
@@ -336,7 +345,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
|
||||
try {
|
||||
$parent->add_child($child);
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
}
|
||||
|
||||
@@ -348,7 +357,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
|
||||
try {
|
||||
$grandparent->add_child($parent);
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
}
|
||||
|
||||
@@ -364,7 +373,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
|
||||
try {
|
||||
$grandparent->add_child($parent2);
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
}
|
||||
|
||||
@@ -376,7 +385,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
|
||||
try {
|
||||
$parent2->add_child($child);
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_parent_exception);
|
||||
}
|
||||
|
||||
@@ -386,7 +395,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
|
||||
try {
|
||||
$nested->add_child($child);
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
$this->assertEquals($e->errorcode, 'baseelementchildnameconflict');
|
||||
$this->assertEquals($e->a, 'FINAL2');
|
||||
|
||||
+26
-18
@@ -14,23 +14,31 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use base_atom_struct_exception;
|
||||
use base_element_struct_exception;
|
||||
use mock_base_attribute;
|
||||
use mock_base_final_element;
|
||||
use mock_base_nested_element;
|
||||
use mock_base_optigroup;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// Include all the needed stuff
|
||||
require_once(__DIR__.'/fixtures/structure_fixtures.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit test case the base_optigroup class. Note: highly imbricated with nested/final base elements
|
||||
* Unit test case the base_optigroup class.
|
||||
*
|
||||
* Note: highly imbricated with nested/final base elements
|
||||
*
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backup_base_optigroup_testcase extends basic_testcase {
|
||||
class baseoptigroup_test extends \basic_testcase {
|
||||
|
||||
/**
|
||||
* Correct creation tests (s)
|
||||
@@ -75,27 +83,27 @@ class backup_base_optigroup_testcase extends basic_testcase {
|
||||
try {
|
||||
$instance = new mock_base_nested_element('');
|
||||
$this->fail("Expecting base_atom_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_atom_struct_exception);
|
||||
}
|
||||
|
||||
// Create instance with incorrect (object) final element
|
||||
try {
|
||||
$obj = new stdClass;
|
||||
$obj = new \stdClass;
|
||||
$obj->name = 'test_attr';
|
||||
$instance = new mock_base_nested_element('TEST', null, $obj);
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
}
|
||||
|
||||
// Create instance with array containing incorrect (object) final element
|
||||
try {
|
||||
$obj = new stdClass;
|
||||
$obj = new \stdClass;
|
||||
$obj->name = 'test_attr';
|
||||
$instance = new mock_base_nested_element('TEST', null, array($obj));
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
}
|
||||
|
||||
@@ -103,7 +111,7 @@ class backup_base_optigroup_testcase extends basic_testcase {
|
||||
try {
|
||||
$instance = new mock_base_nested_element('TEST', null, array('VAL1', 'VAL2', 'VAL1'));
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
}
|
||||
|
||||
@@ -112,7 +120,7 @@ class backup_base_optigroup_testcase extends basic_testcase {
|
||||
try {
|
||||
$instance->get_value();
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
}
|
||||
|
||||
@@ -121,7 +129,7 @@ class backup_base_optigroup_testcase extends basic_testcase {
|
||||
try {
|
||||
$instance->set_value('some_value');
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
}
|
||||
|
||||
@@ -130,7 +138,7 @@ class backup_base_optigroup_testcase extends basic_testcase {
|
||||
try {
|
||||
$instance->clean_value('some_value');
|
||||
$this->fail("Expecting base_element_struct_exception exception, none occurred");
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof base_element_struct_exception);
|
||||
}
|
||||
}
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Tests for base_setting_ui class.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2021 Université Rennes 2 {@link https://www.univ-rennes2.fr}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use base_setting;
|
||||
use base_setting_ui;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -31,10 +28,11 @@ require_once($CFG->dirroot.'/backup/util/settings/tests/settings_test.php');
|
||||
/**
|
||||
* Tests for base_setting_ui class.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2021 Université Rennes 2 {@link https://www.univ-rennes2.fr}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class base_setting_ui_test extends advanced_testcase {
|
||||
class base_setting_ui_test extends \advanced_testcase {
|
||||
/**
|
||||
* Tests set_label().
|
||||
*
|
||||
@@ -71,7 +69,7 @@ class base_setting_ui_test extends advanced_testcase {
|
||||
$this->assertSame('<b>label</b>', $bsui->get_label());
|
||||
|
||||
// Should raise an exception when cleaning ends with 100% empty.
|
||||
$this->expectException(base_setting_ui_exception::class);
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('error/setting_invalid_ui_label');
|
||||
$bsui->set_label('<script>alert("test")</script>');
|
||||
}
|
||||
|
||||
@@ -14,19 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Contains user interface tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// Include all the needed stuff.
|
||||
global $CFG;
|
||||
//require_once($CFG->dirroot . '/backup/util/checks/backup_check.class.php');
|
||||
namespace core_backup;
|
||||
|
||||
/**
|
||||
* ui tests (all)
|
||||
@@ -35,7 +23,7 @@ global $CFG;
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backup_ui_testcase extends basic_testcase {
|
||||
class ui_test extends \basic_testcase {
|
||||
|
||||
/**
|
||||
* Test backup_ui class
|
||||
|
||||
@@ -15,12 +15,21 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* xml_output tests (base, memory and file).
|
||||
*
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_backup;
|
||||
|
||||
use file_xml_output;
|
||||
use memory_xml_output;
|
||||
use xml_output;
|
||||
use xml_output_exception;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// Include all the needed stuff
|
||||
@@ -29,10 +38,15 @@ require_once($CFG->dirroot . '/backup/util/xml/output/xml_output.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/xml/output/memory_xml_output.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/xml/output/file_xml_output.class.php');
|
||||
|
||||
/*
|
||||
/**
|
||||
* xml_output tests (base, memory and file)
|
||||
*
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class xml_output_test extends advanced_testcase {
|
||||
class output_test extends \advanced_testcase {
|
||||
|
||||
/*
|
||||
* test memory_xml_output
|
||||
@@ -47,7 +61,7 @@ class xml_output_test extends advanced_testcase {
|
||||
try {
|
||||
$xo->write('test');
|
||||
$this->assertTrue(false, 'xml_output_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_output_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_output_not_started');
|
||||
}
|
||||
@@ -57,7 +71,7 @@ class xml_output_test extends advanced_testcase {
|
||||
try {
|
||||
$xo->set_buffersize(8192);
|
||||
$this->assertTrue(false, 'xml_output_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_output_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_output_buffer_nosupport');
|
||||
}
|
||||
@@ -68,7 +82,7 @@ class xml_output_test extends advanced_testcase {
|
||||
try {
|
||||
$xo->set_buffersize(8192);
|
||||
$this->assertTrue(false, 'xml_output_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_output_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_output_already_started');
|
||||
}
|
||||
@@ -78,7 +92,7 @@ class xml_output_test extends advanced_testcase {
|
||||
try {
|
||||
$xo->stop();
|
||||
$this->assertTrue(false, 'xml_output_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_output_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_output_not_started');
|
||||
}
|
||||
@@ -88,7 +102,7 @@ class xml_output_test extends advanced_testcase {
|
||||
try {
|
||||
$xo->debug_info();
|
||||
$this->assertTrue(false, 'xml_output_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_output_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_output_not_stopped');
|
||||
}
|
||||
@@ -99,7 +113,7 @@ class xml_output_test extends advanced_testcase {
|
||||
try {
|
||||
$xo->start();
|
||||
$this->assertTrue(false, 'xml_output_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_output_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_output_already_started');
|
||||
}
|
||||
@@ -110,7 +124,7 @@ class xml_output_test extends advanced_testcase {
|
||||
try {
|
||||
$xo->debug_info();
|
||||
$this->assertTrue(false, 'xml_output_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_output_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_output_not_stopped');
|
||||
}
|
||||
@@ -122,7 +136,7 @@ class xml_output_test extends advanced_testcase {
|
||||
try {
|
||||
$xo->stop();
|
||||
$this->assertTrue(false, 'xml_output_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_output_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_output_not_started');
|
||||
}
|
||||
@@ -134,7 +148,7 @@ class xml_output_test extends advanced_testcase {
|
||||
try {
|
||||
$xo->start();
|
||||
$this->assertTrue(false, 'xml_output_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_output_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_output_already_stopped');
|
||||
}
|
||||
@@ -145,7 +159,7 @@ class xml_output_test extends advanced_testcase {
|
||||
try {
|
||||
$xo->get_allcontents();
|
||||
$this->assertTrue(false, 'xml_output_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_output_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_output_not_stopped');
|
||||
}
|
||||
@@ -220,7 +234,7 @@ class xml_output_test extends advanced_testcase {
|
||||
@remove_dir(dirname($file));
|
||||
// Recreate test dir
|
||||
if (!check_dir_exists(dirname($file), true, true)) {
|
||||
throw new moodle_exception('error_creating_temp_dir', 'error', dirname($file));
|
||||
throw new \moodle_exception('error_creating_temp_dir', 'error', dirname($file));
|
||||
}
|
||||
|
||||
// Instantiate xml_output
|
||||
@@ -233,7 +247,7 @@ class xml_output_test extends advanced_testcase {
|
||||
try {
|
||||
$xo->start();
|
||||
$this->assertTrue(false, 'xml_output_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_output_exception);
|
||||
$this->assertEquals($e->errorcode, 'directory_not_exists');
|
||||
}
|
||||
@@ -245,7 +259,7 @@ class xml_output_test extends advanced_testcase {
|
||||
try {
|
||||
$xo->start();
|
||||
$this->assertTrue(false, 'xml_output_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_output_exception);
|
||||
$this->assertEquals($e->errorcode, 'file_already_exists');
|
||||
}
|
||||
|
||||
@@ -15,12 +15,22 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Test progressive_parser and progressive_parser_processor tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_backup;
|
||||
|
||||
use grouped_parser_processor;
|
||||
use progressive_parser;
|
||||
use progressive_parser_exception;
|
||||
use progressive_parser_processor;
|
||||
use simplified_parser_processor;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// Include all the needed stuff
|
||||
@@ -30,10 +40,15 @@ require_once($CFG->dirroot . '/backup/util/xml/parser/processors/progressive_par
|
||||
require_once($CFG->dirroot . '/backup/util/xml/parser/processors/simplified_parser_processor.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/xml/parser/processors/grouped_parser_processor.class.php');
|
||||
|
||||
/*
|
||||
* progressive_parser and progressive_parser_processor tests
|
||||
/**
|
||||
* Test progressive_parser and progressive_parser_processor tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class progressive_parser_test extends advanced_testcase {
|
||||
class parser_test extends \advanced_testcase {
|
||||
|
||||
/*
|
||||
* test progressive_parser public methods
|
||||
@@ -50,7 +65,7 @@ class progressive_parser_test extends advanced_testcase {
|
||||
try {
|
||||
$pp->process();
|
||||
$this->assertTrue(false);
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof progressive_parser_exception);
|
||||
$this->assertEquals($e->errorcode, 'undefined_parser_processor');
|
||||
}
|
||||
@@ -62,16 +77,16 @@ class progressive_parser_test extends advanced_testcase {
|
||||
try {
|
||||
$pp->process();
|
||||
$this->assertTrue(false);
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof progressive_parser_exception);
|
||||
$this->assertEquals($e->errorcode, 'undefined_xml_to_parse');
|
||||
}
|
||||
|
||||
// Assign *invalid* processor to parser
|
||||
try {
|
||||
$pp->set_processor(new stdClass());
|
||||
$pp->set_processor(new \stdClass());
|
||||
$this->assertTrue(false);
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof progressive_parser_exception);
|
||||
$this->assertEquals($e->errorcode, 'invalid_parser_processor');
|
||||
}
|
||||
@@ -87,7 +102,7 @@ class progressive_parser_test extends advanced_testcase {
|
||||
try {
|
||||
$pp->set_file($CFG->dirroot . '/backup/util/xml/parser/tests/fixtures/test0.xml');
|
||||
$this->assertTrue(false);
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof progressive_parser_exception);
|
||||
$this->assertEquals($e->errorcode, 'invalid_file_to_parse');
|
||||
}
|
||||
@@ -103,7 +118,7 @@ class progressive_parser_test extends advanced_testcase {
|
||||
try {
|
||||
$pp->set_contents('');
|
||||
$this->assertTrue(false);
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof progressive_parser_exception);
|
||||
$this->assertEquals($e->errorcode, 'invalid_contents_to_parse');
|
||||
}
|
||||
@@ -129,7 +144,7 @@ class progressive_parser_test extends advanced_testcase {
|
||||
$pp->set_file($CFG->dirroot . '/backup/util/xml/parser/tests/fixtures/test2.xml');
|
||||
try {
|
||||
$pp->process();
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof progressive_parser_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_parsing_error');
|
||||
}
|
||||
@@ -143,7 +158,7 @@ class progressive_parser_test extends advanced_testcase {
|
||||
try { // Second process, will throw exception
|
||||
$pp->process();
|
||||
$this->assertTrue(false);
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof progressive_parser_exception);
|
||||
$this->assertEquals($e->errorcode, 'progressive_parser_already_used');
|
||||
}
|
||||
|
||||
@@ -15,12 +15,22 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Test xml_writer tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_backup;
|
||||
|
||||
use memory_xml_output;
|
||||
use xml_contenttransformer;
|
||||
use xml_output;
|
||||
use xml_writer;
|
||||
use xml_writer_exception;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// Include all the needed stuff
|
||||
@@ -31,9 +41,14 @@ require_once($CFG->dirroot . '/backup/util/xml/output/memory_xml_output.class.ph
|
||||
require_once($CFG->dirroot . '/backup/util/xml/contenttransformer/xml_contenttransformer.class.php');
|
||||
|
||||
/**
|
||||
* xml_writer tests
|
||||
* Test xml_writer tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @category test
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class xml_writer_testcase extends basic_testcase {
|
||||
class writer_test extends \basic_testcase {
|
||||
|
||||
/**
|
||||
* test xml_writer public methods
|
||||
@@ -48,25 +63,25 @@ class xml_writer_testcase extends basic_testcase {
|
||||
try {
|
||||
$xw = new mock_xml_writer(null);
|
||||
$this->assertTrue(false, 'xml_writer_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_writer_exception);
|
||||
$this->assertEquals($e->errorcode, 'invalid_xml_output');
|
||||
}
|
||||
|
||||
// Instantiate xml_writer with wrong xml_output object
|
||||
try {
|
||||
$xw = new mock_xml_writer(new stdclass());
|
||||
$xw = new mock_xml_writer(new \stdClass());
|
||||
$this->assertTrue(false, 'xml_writer_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_writer_exception);
|
||||
$this->assertEquals($e->errorcode, 'invalid_xml_output');
|
||||
}
|
||||
|
||||
// Instantiate xml_writer with wrong xml_contenttransformer object
|
||||
try {
|
||||
$xw = new mock_xml_writer($xo, new stdclass());
|
||||
$xw = new mock_xml_writer($xo, new \stdClass());
|
||||
$this->assertTrue(false, 'xml_writer_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_writer_exception);
|
||||
$this->assertEquals($e->errorcode, 'invalid_xml_contenttransformer');
|
||||
}
|
||||
@@ -77,7 +92,7 @@ class xml_writer_testcase extends basic_testcase {
|
||||
try {
|
||||
$xw->start();
|
||||
$this->assertTrue(false, 'xml_writer_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_writer_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_writer_already_started');
|
||||
}
|
||||
@@ -90,7 +105,7 @@ class xml_writer_testcase extends basic_testcase {
|
||||
try {
|
||||
$xw->stop();
|
||||
$this->assertTrue(false, 'xml_writer_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_writer_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_writer_already_stopped');
|
||||
}
|
||||
@@ -101,7 +116,7 @@ class xml_writer_testcase extends basic_testcase {
|
||||
try {
|
||||
$xw->stop();
|
||||
$this->assertTrue(false, 'xml_writer_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_writer_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_writer_not_started');
|
||||
}
|
||||
@@ -114,7 +129,7 @@ class xml_writer_testcase extends basic_testcase {
|
||||
try {
|
||||
$xw->start();
|
||||
$this->assertTrue(false, 'xml_writer_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_writer_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_writer_already_stopped');
|
||||
}
|
||||
@@ -126,14 +141,14 @@ class xml_writer_testcase extends basic_testcase {
|
||||
try {
|
||||
$xw->set_nonamespace_schema('http://moodle.org');
|
||||
$this->assertTrue(false, 'xml_writer_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_writer_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_writer_already_started');
|
||||
}
|
||||
try {
|
||||
$xw->set_prologue('sweet prologue');
|
||||
$this->assertTrue(false, 'xml_writer_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_writer_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_writer_already_started');
|
||||
}
|
||||
@@ -172,7 +187,7 @@ class xml_writer_testcase extends basic_testcase {
|
||||
try {
|
||||
$xw->end_tag('first');
|
||||
$this->assertTrue(false, 'xml_writer_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_writer_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_writer_end_tag_no_match');
|
||||
}
|
||||
@@ -184,7 +199,7 @@ class xml_writer_testcase extends basic_testcase {
|
||||
try {
|
||||
$xw->end_tag('first');
|
||||
$this->assertTrue(false, 'xml_writer_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_writer_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_writer_end_tag_no_match');
|
||||
}
|
||||
@@ -249,7 +264,7 @@ class xml_writer_testcase extends basic_testcase {
|
||||
try {
|
||||
$xw->stop();
|
||||
$this->assertTrue(false, 'xml_writer_exception expected');
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof xml_writer_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_writer_open_tags_remaining');
|
||||
}
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Online users tests
|
||||
*
|
||||
* @package block_myoverview
|
||||
* @category test
|
||||
* @copyright 2019 Juan Leyva <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace block_myoverview;
|
||||
|
||||
/**
|
||||
* Online users testcase
|
||||
@@ -33,7 +24,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2019 Juan Leyva <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class block_myoverview_testcase extends advanced_testcase {
|
||||
class myoverview_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test getting block configuration
|
||||
@@ -64,10 +55,10 @@ class block_myoverview_testcase extends advanced_testcase {
|
||||
set_config('customfiltergrouping', $field->get('shortname'), 'block_myoverview');
|
||||
|
||||
$this->setUser($user);
|
||||
$context = context_user::instance($user->id);
|
||||
$context = \context_user::instance($user->id);
|
||||
|
||||
if (!$currentpage = my_get_page($user->id, MY_PAGE_PUBLIC, MY_PAGE_COURSES)) {
|
||||
throw new moodle_exception('mymoodlesetup');
|
||||
throw new \moodle_exception('mymoodlesetup');
|
||||
}
|
||||
|
||||
$PAGE->set_url('/my/courses.php'); // Need this because some internal API calls require the $PAGE url to be set.
|
||||
|
||||
@@ -14,19 +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/>.
|
||||
|
||||
/**
|
||||
* Online users tests
|
||||
*
|
||||
* @package block_online_users
|
||||
* @category test
|
||||
* @copyright 2015 University of Nottingham <www.nottingham.ac.uk>
|
||||
* @author Barry Oosthuizen <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use block_online_users\fetcher;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace block_online_users;
|
||||
|
||||
/**
|
||||
* Online users testcase
|
||||
@@ -37,7 +25,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @author Barry Oosthuizen <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class block_online_users_testcase extends advanced_testcase {
|
||||
class online_users_test extends \advanced_testcase {
|
||||
|
||||
protected $data;
|
||||
|
||||
@@ -70,7 +58,7 @@ class block_online_users_testcase extends advanced_testcase {
|
||||
$groupid = $this->data['group1']->id;
|
||||
$now = time();
|
||||
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
|
||||
$context = context_course::instance($this->data['course1']->id);
|
||||
$context = \context_course::instance($this->data['course1']->id);
|
||||
$courseid = $this->data['course1']->id;
|
||||
$onlineusers = new fetcher($groupid, $now, $timetoshowusers, $context, false, $courseid);
|
||||
|
||||
@@ -110,7 +98,7 @@ class block_online_users_testcase extends advanced_testcase {
|
||||
$currentgroup = null;
|
||||
$now = time();
|
||||
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
|
||||
$context = context_course::instance($this->data['course1']->id);
|
||||
$context = \context_course::instance($this->data['course1']->id);
|
||||
$courseid = $this->data['course1']->id;
|
||||
$onlineusers = new fetcher($currentgroup, $now, $timetoshowusers, $context, false, $courseid);
|
||||
|
||||
@@ -140,7 +128,7 @@ class block_online_users_testcase extends advanced_testcase {
|
||||
$currentgroup = null;
|
||||
$now = time();
|
||||
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
|
||||
$context = context_system::instance();
|
||||
$context = \context_system::instance();
|
||||
$onlineusers = new fetcher($currentgroup, $now, $timetoshowusers, $context, true);
|
||||
|
||||
$usercount = $onlineusers->count_users();
|
||||
@@ -160,7 +148,7 @@ class block_online_users_testcase extends advanced_testcase {
|
||||
$groupid = $this->data['group1']->id;
|
||||
$now = time();
|
||||
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
|
||||
$context = context_course::instance($this->data['course1']->id);
|
||||
$context = \context_course::instance($this->data['course1']->id);
|
||||
$courseid = $this->data['course1']->id;
|
||||
$user1 = $this->data['user1'];
|
||||
$user2 = $this->data['user2'];
|
||||
@@ -215,7 +203,7 @@ class block_online_users_testcase extends advanced_testcase {
|
||||
$currentgroup = null;
|
||||
$now = time();
|
||||
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
|
||||
$context = context_course::instance($this->data['course1']->id);
|
||||
$context = \context_course::instance($this->data['course1']->id);
|
||||
$courseid = $this->data['course1']->id;
|
||||
$user1 = $this->data['user1'];
|
||||
$user2 = $this->data['user2'];
|
||||
@@ -271,7 +259,7 @@ class block_online_users_testcase extends advanced_testcase {
|
||||
$currentgroup = null;
|
||||
$now = time();
|
||||
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
|
||||
$context = context_system::instance();
|
||||
$context = \context_system::instance();
|
||||
$user1 = $this->data['user1'];
|
||||
$user2 = $this->data['user2'];
|
||||
// Set user2 as logged user.
|
||||
|
||||
@@ -14,27 +14,21 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* PHPunit tests for rss client cron.
|
||||
*
|
||||
* @package block_rss_client
|
||||
* @copyright 2015 University of Nottingham
|
||||
* @author Neill Magill <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace block_rss_client;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once(__DIR__ . '/../../moodleblock.class.php');
|
||||
require_once(__DIR__ . '/../block_rss_client.php');
|
||||
|
||||
/**
|
||||
* Class for the PHPunit tests for rss client cron.
|
||||
* PHPunit tests for rss client cron.
|
||||
*
|
||||
* @package block_rss_client
|
||||
* @copyright 2015 Universit of Nottingham
|
||||
* @author Neill Magill <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class block_rss_client_cron_testcase extends advanced_testcase {
|
||||
class cron_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test that when a record has a skipuntil time that is greater
|
||||
* than the current time the attempt is skipped.
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Block Tag Youtube tests
|
||||
*
|
||||
* @package block_tag_youtube
|
||||
* @category test
|
||||
* @copyright 2015 Jun Pataleta
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace block_tag_youtube;
|
||||
|
||||
/**
|
||||
* Block Tag Youtube test class.
|
||||
@@ -33,7 +24,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2015 Jun Pataleta
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_block_tag_youtube_testcase extends advanced_testcase {
|
||||
class block_tag_youtube_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Testing the tag youtube block's initial state after a new installation.
|
||||
|
||||
+22
-24
@@ -14,17 +14,13 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* PHPunit tests for the cache API and in particular things in locallib.php
|
||||
*
|
||||
* This file is part of Moodle's cache API, affectionately called MUC.
|
||||
* It contains the components that are requried in order to use caching.
|
||||
*
|
||||
* @package core
|
||||
* @category cache
|
||||
* @copyright 2012 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_cache;
|
||||
|
||||
use cache_config_testing;
|
||||
use cache_config_writer;
|
||||
use cache_factory;
|
||||
use cache_helper;
|
||||
use cache_store;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -37,10 +33,12 @@ require_once($CFG->dirroot.'/cache/tests/fixtures/lib.php');
|
||||
/**
|
||||
* PHPunit tests for the cache API and in particular the core_cache\administration_helper
|
||||
*
|
||||
* @package core_cache
|
||||
* @category test
|
||||
* @copyright 2012 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_cache_administration_helper_testcase extends advanced_testcase {
|
||||
class administration_helper_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Set things back to the default before each test.
|
||||
@@ -73,7 +71,7 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
|
||||
cache_store::MODE_REQUEST => array('default_request'),
|
||||
)));
|
||||
|
||||
$storesummaries = core_cache\administration_helper::get_store_instance_summaries();
|
||||
$storesummaries = administration_helper::get_store_instance_summaries();
|
||||
$this->assertIsArray($storesummaries);
|
||||
$this->assertArrayHasKey('summariesstore', $storesummaries);
|
||||
$summary = $storesummaries['summariesstore'];
|
||||
@@ -99,7 +97,7 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
|
||||
}));
|
||||
$this->assertEquals($mappingcount, $summary['mappings']);
|
||||
|
||||
$definitionsummaries = core_cache\administration_helper::get_definition_summaries();
|
||||
$definitionsummaries = administration_helper::get_definition_summaries();
|
||||
$this->assertIsArray($definitionsummaries);
|
||||
$this->assertArrayHasKey('core/eventinvalidation', $definitionsummaries);
|
||||
$summary = $definitionsummaries['core/eventinvalidation'];
|
||||
@@ -119,7 +117,7 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
|
||||
$this->assertIsArray($summary['mappings']);
|
||||
$this->assertContains('summariesstore', $summary['mappings']);
|
||||
|
||||
$pluginsummaries = core_cache\administration_helper::get_store_plugin_summaries();
|
||||
$pluginsummaries = administration_helper::get_store_plugin_summaries();
|
||||
$this->assertIsArray($pluginsummaries);
|
||||
$this->assertArrayHasKey('file', $pluginsummaries);
|
||||
$summary = $pluginsummaries['file'];
|
||||
@@ -131,18 +129,18 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
|
||||
$this->assertArrayHasKey('supports', $summary);
|
||||
$this->assertArrayHasKey('canaddinstance', $summary);
|
||||
|
||||
$locksummaries = core_cache\administration_helper::get_lock_summaries();
|
||||
$locksummaries = administration_helper::get_lock_summaries();
|
||||
$this->assertIsArray($locksummaries);
|
||||
$this->assertTrue(count($locksummaries) > 0);
|
||||
|
||||
$mappings = core_cache\administration_helper::get_default_mode_stores();
|
||||
$mappings = administration_helper::get_default_mode_stores();
|
||||
$this->assertIsArray($mappings);
|
||||
$this->assertCount(3, $mappings);
|
||||
$this->assertArrayHasKey(cache_store::MODE_APPLICATION, $mappings);
|
||||
$this->assertIsArray($mappings[cache_store::MODE_APPLICATION]);
|
||||
$this->assertContains('summariesstore', $mappings[cache_store::MODE_APPLICATION]);
|
||||
|
||||
$potentials = core_cache\administration_helper::get_definition_store_options('core', 'eventinvalidation');
|
||||
$potentials = administration_helper::get_definition_store_options('core', 'eventinvalidation');
|
||||
$this->assertIsArray($potentials); // Currently used, suitable, default
|
||||
$this->assertCount(3, $potentials);
|
||||
$this->assertArrayHasKey('summariesstore', $potentials[0]);
|
||||
@@ -160,7 +158,7 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
|
||||
try {
|
||||
$form = cache_factory::get_administration_display_helper()->get_add_store_form('somethingstupid');
|
||||
$this->fail('You should not be able to create an add form for a store plugin that does not exist.');
|
||||
} catch (moodle_exception $e) {
|
||||
} catch (\moodle_exception $e) {
|
||||
$this->assertInstanceOf('coding_exception', $e, 'Needs to be: ' .get_class($e)." ::: ".$e->getMessage());
|
||||
}
|
||||
}
|
||||
@@ -170,7 +168,7 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
|
||||
*/
|
||||
public function test_get_edit_store_form() {
|
||||
// Always instantiate a new core display helper here.
|
||||
$administrationhelper = new core_cache\local\administration_display_helper;
|
||||
$administrationhelper = new local\administration_display_helper;
|
||||
$config = cache_config_writer::instance();
|
||||
$this->assertTrue($config->add_store_instance('test_get_edit_store_form', 'file'));
|
||||
|
||||
@@ -180,14 +178,14 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
|
||||
try {
|
||||
$form = $administrationhelper->get_edit_store_form('somethingstupid', 'moron');
|
||||
$this->fail('You should not be able to create an edit form for a store plugin that does not exist.');
|
||||
} catch (moodle_exception $e) {
|
||||
} catch (\moodle_exception $e) {
|
||||
$this->assertInstanceOf('coding_exception', $e);
|
||||
}
|
||||
|
||||
try {
|
||||
$form = $administrationhelper->get_edit_store_form('file', 'blisters');
|
||||
$this->fail('You should not be able to create an edit form for a store plugin that does not exist.');
|
||||
} catch (moodle_exception $e) {
|
||||
} catch (\moodle_exception $e) {
|
||||
$this->assertInstanceOf('coding_exception', $e);
|
||||
}
|
||||
}
|
||||
@@ -216,7 +214,7 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
|
||||
try {
|
||||
cache_helper::hash_key('test/test', $definition);
|
||||
$this->fail('Invalid key was allowed, you should see this.');
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertEquals('test/test', $e->debuginfo);
|
||||
}
|
||||
|
||||
@@ -248,7 +246,7 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
|
||||
'area' => 'test',
|
||||
'simplekeys' => true
|
||||
]);
|
||||
$cache = cache::make('phpunit', 'test');
|
||||
$cache = \cache::make('phpunit', 'test');
|
||||
for ($i = 0; $i < 100; $i++) {
|
||||
$cache->set('key' . $i, str_repeat('x', $i));
|
||||
}
|
||||
|
||||
Vendored
+14
-17
@@ -14,17 +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/>.
|
||||
|
||||
/**
|
||||
* PHPunit tests for the cache API and in particular things in locallib.php
|
||||
*
|
||||
* This file is part of Moodle's cache API, affectionately called MUC.
|
||||
* It contains the components that are requried in order to use caching.
|
||||
*
|
||||
* @package core
|
||||
* @category cache
|
||||
* @copyright 2012 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_cache;
|
||||
|
||||
use cache_config_testing;
|
||||
use cache_config_writer;
|
||||
use cache_factory;
|
||||
use cache_store;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -36,10 +31,12 @@ require_once($CFG->dirroot.'/cache/tests/fixtures/lib.php');
|
||||
/**
|
||||
* PHPunit tests for the cache API and in particular the cache config writer.
|
||||
*
|
||||
* @package core_cache
|
||||
* @category test
|
||||
* @copyright 2012 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_cache_config_writer_testcase extends advanced_testcase {
|
||||
class config_writer_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Set things back to the default before each test.
|
||||
@@ -216,14 +213,14 @@ class core_cache_config_writer_testcase extends advanced_testcase {
|
||||
try {
|
||||
$config->delete_store_instance('default_application');
|
||||
$this->fail('Default store deleted. This should not be possible!');
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('cache_exception', $e);
|
||||
}
|
||||
|
||||
try {
|
||||
$config->delete_store_instance('some_crazy_store');
|
||||
$this->fail('You should not be able to delete a store that does not exist.');
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('cache_exception', $e);
|
||||
}
|
||||
|
||||
@@ -231,7 +228,7 @@ class core_cache_config_writer_testcase extends advanced_testcase {
|
||||
// Try with a plugin that does not exist.
|
||||
$config->add_store_instance('storeconfigtest', 'shallowfail', array('test' => 'a', 'one' => 'two'));
|
||||
$this->fail('You should not be able to add an instance of a store that does not exist.');
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('cache_exception', $e);
|
||||
}
|
||||
}
|
||||
@@ -276,14 +273,14 @@ class core_cache_config_writer_testcase extends advanced_testcase {
|
||||
try {
|
||||
$config->set_definition_mappings('phpunit/testdefinition', array('something that does not exist'));
|
||||
$this->fail('You should not be able to set a mapping for a store that does not exist.');
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('coding_exception', $e);
|
||||
}
|
||||
|
||||
try {
|
||||
$config->set_definition_mappings('something/crazy', array('setdefinitiontest'));
|
||||
$this->fail('You should not be able to set a mapping for a definition that does not exist.');
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('coding_exception', $e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace core_calendar;
|
||||
|
||||
use core_calendar\local\event\entities\action_event;
|
||||
use core_calendar\local\event\value_objects\action;
|
||||
@@ -31,13 +31,17 @@ use core_calendar\local\event\value_objects\event_times;
|
||||
use core_calendar\local\event\entities\event_collection_interface;
|
||||
use core_calendar\local\event\entities\event_interface;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
/**
|
||||
* Action event testcase.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @category test
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_action_event_testcase extends advanced_testcase {
|
||||
class action_event_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test event class getters.
|
||||
*
|
||||
@@ -67,7 +71,7 @@ class core_calendar_action_event_testcase extends advanced_testcase {
|
||||
'event' => new core_calendar_action_event_test_event(),
|
||||
'action' => new action(
|
||||
'action 1',
|
||||
new moodle_url('http://example.com'),
|
||||
new \moodle_url('http://example.com'),
|
||||
2,
|
||||
true
|
||||
)
|
||||
@@ -78,7 +82,7 @@ class core_calendar_action_event_testcase extends advanced_testcase {
|
||||
'event' => new core_calendar_action_event_test_event(),
|
||||
'action' => new action(
|
||||
'action 2',
|
||||
new moodle_url('http://example.com'),
|
||||
new \moodle_url('http://example.com'),
|
||||
5,
|
||||
false
|
||||
)
|
||||
|
||||
@@ -14,26 +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/>.
|
||||
|
||||
/**
|
||||
* Action factory test.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_calendar;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core_calendar\action_factory;
|
||||
use core_calendar\local\event\entities\action_interface;
|
||||
|
||||
/**
|
||||
* Action factory testcase.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_action_factory_test extends advanced_testcase {
|
||||
class action_factory_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test action factory.
|
||||
*/
|
||||
|
||||
@@ -14,25 +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/>.
|
||||
|
||||
/**
|
||||
* Action tests.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace core_calendar;
|
||||
|
||||
use core_calendar\local\event\value_objects\action;
|
||||
|
||||
/**
|
||||
* Action testcase.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_action_testcase extends advanced_testcase {
|
||||
class action_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test action class getters.
|
||||
*
|
||||
@@ -64,7 +57,7 @@ class core_calendar_action_testcase extends advanced_testcase {
|
||||
'Dataset 1' => [
|
||||
'constructorparams' => [
|
||||
'name' => 'Hello',
|
||||
'url' => new moodle_url('http://example.com'),
|
||||
'url' => new \moodle_url('http://example.com'),
|
||||
'item_count' => 1,
|
||||
'actionable' => true
|
||||
]
|
||||
@@ -72,7 +65,7 @@ class core_calendar_action_testcase extends advanced_testcase {
|
||||
'Dataset 2' => [
|
||||
'constructorparams' => [
|
||||
'name' => 'Goodbye',
|
||||
'url' => new moodle_url('http://example.com'),
|
||||
'url' => new \moodle_url('http://example.com'),
|
||||
'item_count' => 2,
|
||||
'actionable' => false
|
||||
]
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Calendar event exporter tests tests.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Ryan Wyllie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace core_calendar;
|
||||
|
||||
use core_calendar\external\calendar_event_exporter;
|
||||
use core_calendar\local\event\container;
|
||||
use core_calendar\type_factory;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once(__DIR__ . '/helpers.php');
|
||||
|
||||
/**
|
||||
* Calendar event exporter testcase.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Ryan Wyllie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_event_exporter_testcase extends advanced_testcase {
|
||||
class calendar_event_exporter_test extends \advanced_testcase {
|
||||
/**
|
||||
* Data provider for the timestamp min limit test case to confirm
|
||||
* that the minimum time limit is set correctly on the boundary cases.
|
||||
@@ -46,7 +39,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
|
||||
$todaymidnight = usergetmidnight($now);
|
||||
$tomorrowmidnight = $todaymidnight + DAYSECS;
|
||||
$eightam = $todaymidnight + (60 * 60 * 8);
|
||||
$starttime = (new DateTime())->setTimestamp($eightam);
|
||||
$starttime = (new \DateTime())->setTimestamp($eightam);
|
||||
|
||||
return [
|
||||
'before min' => [
|
||||
@@ -80,12 +73,12 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
|
||||
* @dataProvider get_timestamp_min_limit_test_cases()
|
||||
*/
|
||||
public function test_get_timestamp_min_limit($starttime, $min, $expected) {
|
||||
$class = \core_calendar\external\calendar_event_exporter::class;
|
||||
$class = calendar_event_exporter::class;
|
||||
$mock = $this->getMockBuilder($class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([])
|
||||
->getMock();
|
||||
$reflector = new ReflectionClass($class);
|
||||
$reflector = new \ReflectionClass($class);
|
||||
$method = $reflector->getMethod('get_timestamp_min_limit');
|
||||
$method->setAccessible(true);
|
||||
|
||||
@@ -103,7 +96,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
|
||||
$todaymidnight = usergetmidnight($now);
|
||||
$yesterdaymidnight = $todaymidnight - DAYSECS;
|
||||
$eightam = $todaymidnight + (60 * 60 * 8);
|
||||
$starttime = (new DateTime())->setTimestamp($eightam);
|
||||
$starttime = (new \DateTime())->setTimestamp($eightam);
|
||||
|
||||
return [
|
||||
'before max' => [
|
||||
@@ -137,12 +130,12 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
|
||||
* @dataProvider get_timestamp_max_limit_test_cases()
|
||||
*/
|
||||
public function test_get_timestamp_max_limit($starttime, $max, $expected) {
|
||||
$class = \core_calendar\external\calendar_event_exporter::class;
|
||||
$class = calendar_event_exporter::class;
|
||||
$mock = $this->getMockBuilder($class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([])
|
||||
->getMock();
|
||||
$reflector = new ReflectionClass($class);
|
||||
$reflector = new \ReflectionClass($class);
|
||||
$method = $reflector->getMethod('get_timestamp_max_limit');
|
||||
$method->setAccessible(true);
|
||||
|
||||
@@ -163,7 +156,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
|
||||
$generator = $this->getDataGenerator();
|
||||
$user = $generator->create_user();
|
||||
$course = $generator->create_course();
|
||||
$context = context_course::instance($course->id);
|
||||
$context = \context_course::instance($course->id);
|
||||
$now = time();
|
||||
$mapper = container::get_event_mapper();
|
||||
$legacyevent = create_event([
|
||||
@@ -177,7 +170,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
|
||||
'context' => $context,
|
||||
'course' => $course,
|
||||
'moduleinstance' => null,
|
||||
'daylink' => new moodle_url(''),
|
||||
'daylink' => new \moodle_url(''),
|
||||
'type' => type_factory::get_calendar_instance(),
|
||||
'today' => $now
|
||||
]);
|
||||
@@ -202,7 +195,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
|
||||
$this->setAdminUser();
|
||||
$generator = $this->getDataGenerator();
|
||||
$user = $generator->create_user();
|
||||
$context = context_user::instance($user->id);
|
||||
$context = \context_user::instance($user->id);
|
||||
$now = time();
|
||||
$mapper = container::get_event_mapper();
|
||||
$legacyevent = create_event([
|
||||
@@ -216,7 +209,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
|
||||
'context' => $context,
|
||||
'course' => null,
|
||||
'moduleinstance' => null,
|
||||
'daylink' => new moodle_url(''),
|
||||
'daylink' => new \moodle_url(''),
|
||||
'type' => type_factory::get_calendar_instance(),
|
||||
'today' => $now
|
||||
]);
|
||||
@@ -243,7 +236,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
|
||||
$rawshortname = 'Shortname <a href="#">link</a>';
|
||||
$nolinkshortname = strip_links($rawshortname);
|
||||
$course = $generator->create_course(['shortname' => $rawshortname]);
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
$coursecontext = \context_course::instance($course->id);
|
||||
$now = time();
|
||||
$mapper = container::get_event_mapper();
|
||||
$renderer = $PAGE->get_renderer('core_calendar');
|
||||
@@ -258,7 +251,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
|
||||
'context' => $coursecontext,
|
||||
'course' => $course,
|
||||
'moduleinstance' => null,
|
||||
'daylink' => new moodle_url(''),
|
||||
'daylink' => new \moodle_url(''),
|
||||
'type' => type_factory::get_calendar_instance(),
|
||||
'today' => $now
|
||||
]);
|
||||
@@ -281,7 +274,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
|
||||
$rawshortname = 'Shortname <a href="#">link</a>';
|
||||
$nolinkshortname = strip_links($rawshortname);
|
||||
$course = $generator->create_course(['shortname' => $rawshortname]);
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
$coursecontext = \context_course::instance($course->id);
|
||||
$now = time();
|
||||
$mapper = container::get_event_mapper();
|
||||
$renderer = $PAGE->get_renderer('core_calendar');
|
||||
@@ -296,7 +289,7 @@ class core_calendar_event_exporter_testcase extends advanced_testcase {
|
||||
'context' => $coursecontext,
|
||||
'course' => $course,
|
||||
'moduleinstance' => null,
|
||||
'daylink' => new moodle_url(''),
|
||||
'daylink' => new \moodle_url(''),
|
||||
'type' => type_factory::get_calendar_instance(),
|
||||
'today' => $now
|
||||
]);
|
||||
|
||||
@@ -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 calendar_information.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_calendar;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -33,7 +27,7 @@ require_once(__DIR__ . '/helpers.php');
|
||||
* @copyright 2017 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class calendar_information_testcase extends advanced_testcase {
|
||||
class calendar_information_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Helper to mock a course and category structure.
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_calendar;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
@@ -45,7 +47,7 @@ require_once($CFG->dirroot . '/user/profile/definelib.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.6
|
||||
*/
|
||||
class core_calendar_type_testcase extends advanced_testcase {
|
||||
class calendartype_test extends \advanced_testcase {
|
||||
/** @var MoodleQuickForm Keeps reference of dummy form object */
|
||||
private $mform;
|
||||
|
||||
@@ -284,7 +286,7 @@ class core_calendar_type_testcase extends advanced_testcase {
|
||||
$submissiondata = $form->get_data();
|
||||
// On the user profile field page after get_data, the function define_save is called
|
||||
// in the field base class, which then calls the field's function define_save_preprocess.
|
||||
$field = new profile_define_datetime();
|
||||
$field = new \profile_define_datetime();
|
||||
$submissiondata = $field->define_save_preprocess($submissiondata);
|
||||
|
||||
// Create an array we want to compare with the date passed.
|
||||
@@ -309,7 +311,7 @@ class core_calendar_type_testcase extends advanced_testcase {
|
||||
/**
|
||||
* Form object to be used in test case.
|
||||
*/
|
||||
class temp_form_calendartype extends moodleform {
|
||||
class temp_form_calendartype extends \moodleform {
|
||||
/**
|
||||
* Form definition.
|
||||
*/
|
||||
|
||||
@@ -14,25 +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/>.
|
||||
|
||||
/**
|
||||
* cm_info_proxy tests.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace core_calendar;
|
||||
|
||||
use core_calendar\local\event\proxies\cm_info_proxy;
|
||||
|
||||
/**
|
||||
* cm_info_proxy testcase.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_cm_info_proxy_testcase extends advanced_testcase {
|
||||
class cm_info_proxy_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test creating cm_info_std_proxy, using getter and setter.
|
||||
|
||||
@@ -14,19 +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/>.
|
||||
|
||||
/**
|
||||
* Event container tests.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->dirroot . '/calendar/lib.php');
|
||||
namespace core_calendar;
|
||||
|
||||
use core_calendar\local\event\entities\action_event;
|
||||
use core_calendar\local\event\entities\event;
|
||||
@@ -36,13 +24,20 @@ use core_calendar\local\event\factories\event_factory_interface;
|
||||
use core_calendar\local\event\mappers\event_mapper;
|
||||
use core_calendar\local\event\mappers\event_mapper_interface;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->dirroot . '/calendar/lib.php');
|
||||
|
||||
/**
|
||||
* Core container testcase.
|
||||
* Event container test..
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_container_testcase extends advanced_testcase {
|
||||
class container_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test setup.
|
||||
@@ -435,10 +430,10 @@ class core_calendar_container_testcase extends advanced_testcase {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$group = $this->getDataGenerator()->create_group(['courseid' => $course->id]);
|
||||
|
||||
foreach (core_component::get_plugin_list('mod') as $modname => $unused) {
|
||||
foreach (\core_component::get_plugin_list('mod') as $modname => $unused) {
|
||||
try {
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('mod_'.$modname);
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
// Module generator is not implemented.
|
||||
continue;
|
||||
}
|
||||
@@ -544,7 +539,7 @@ class core_calendar_container_testcase extends advanced_testcase {
|
||||
$record->$name = $value;
|
||||
}
|
||||
|
||||
$event = new calendar_event($record);
|
||||
$event = new \calendar_event($record);
|
||||
return $event->create($record, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,25 +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/>.
|
||||
|
||||
/**
|
||||
* coursecat_proxy tests.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace core_calendar;
|
||||
|
||||
use core_calendar\local\event\proxies\coursecat_proxy;
|
||||
|
||||
/**
|
||||
* coursecat_proxy testcase.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_coursecat_proxy_testcase extends advanced_testcase {
|
||||
class coursecat_proxy_test extends \advanced_testcase {
|
||||
|
||||
public function test_valid_coursecat() {
|
||||
global $DB;
|
||||
@@ -43,7 +36,7 @@ class core_calendar_coursecat_proxy_testcase extends advanced_testcase {
|
||||
$category = $generator->create_category([
|
||||
'name' => $name,
|
||||
]);
|
||||
cache_helper::purge_by_event('changesincoursecat');
|
||||
\cache_helper::purge_by_event('changesincoursecat');
|
||||
|
||||
// Fetch the proxy.
|
||||
$startreads = $DB->perf_get_reads();
|
||||
|
||||
@@ -14,25 +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/>.
|
||||
|
||||
/**
|
||||
* Event description tests.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace core_calendar;
|
||||
|
||||
use core_calendar\local\event\value_objects\event_description;
|
||||
|
||||
/**
|
||||
* Action testcase.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_event_description_testcase extends advanced_testcase {
|
||||
class event_description_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test event description class getters.
|
||||
*
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Event factory test.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_calendar;
|
||||
|
||||
use core_calendar\local\event\factories\event_factory;
|
||||
use core_calendar\local\event\entities\event_interface;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/calendar/lib.php');
|
||||
|
||||
use core_calendar\local\event\factories\event_factory;
|
||||
use core_calendar\local\event\entities\event_interface;
|
||||
|
||||
/**
|
||||
* Event factory testcase.
|
||||
* Event factory test.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_event_factory_testcase extends advanced_testcase {
|
||||
class event_factory_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test event class getters.
|
||||
*
|
||||
@@ -479,7 +474,7 @@ class core_calendar_event_factory_testcase extends advanced_testcase {
|
||||
$record->$name = $value;
|
||||
}
|
||||
|
||||
$event = new calendar_event($record);
|
||||
$event = new \calendar_event($record);
|
||||
return $event->create($record, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,7 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/calendar/lib.php');
|
||||
namespace core_calendar;
|
||||
|
||||
use core_calendar\local\event\mappers\event_mapper;
|
||||
use core_calendar\local\event\value_objects\action;
|
||||
@@ -38,13 +35,19 @@ use core_calendar\local\event\entities\event_interface;
|
||||
use core_calendar\local\event\entities\action_event_interface;
|
||||
use core_calendar\local\event\proxies\proxy_interface;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/calendar/lib.php');
|
||||
|
||||
/**
|
||||
* Event mapper testcase.
|
||||
* Event mapper test.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_event_mapper_testcase extends advanced_testcase {
|
||||
class event_mapper_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test legacy event -> event.
|
||||
*/
|
||||
@@ -71,7 +74,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase {
|
||||
new event_mapper_test_event_factory()
|
||||
);
|
||||
$legacyevent = $mapper->from_event_to_legacy_event($event);
|
||||
$this->assertInstanceOf(calendar_event::class, $legacyevent);
|
||||
$this->assertInstanceOf(\calendar_event::class, $legacyevent);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +88,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase {
|
||||
$mapper = new event_mapper(
|
||||
new event_mapper_test_event_factory()
|
||||
);
|
||||
$obj = $mapper->from_event_to_stdclass($event);
|
||||
$obj = $mapper->from_event_to_stdClass($event);
|
||||
$this->assertInstanceOf(\stdClass::class, $obj);
|
||||
$this->assertEquals($obj->name, $event->get_name());
|
||||
$this->assertEquals($obj->eventtype, $event->get_type());
|
||||
@@ -125,7 +128,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase {
|
||||
);
|
||||
$legacyevent = $mapper->from_event_to_legacy_event($event);
|
||||
|
||||
$this->assertInstanceOf(calendar_event::class, $legacyevent);
|
||||
$this->assertInstanceOf(\calendar_event::class, $legacyevent);
|
||||
$this->assertEquals($legacyevent->actionname, 'test action');
|
||||
$this->assertInstanceOf(\moodle_url::class, $legacyevent->actionurl);
|
||||
$this->assertEquals($legacyevent->actionnum, 1729);
|
||||
@@ -153,7 +156,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase {
|
||||
$record->$name = $value;
|
||||
}
|
||||
|
||||
$event = new calendar_event($record);
|
||||
$event = new \calendar_event($record);
|
||||
return $event->create($record, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,25 +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/>.
|
||||
|
||||
/**
|
||||
* Event times tests.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace core_calendar;
|
||||
|
||||
use core_calendar\local\event\value_objects\event_times;
|
||||
|
||||
/**
|
||||
* Event times testcase.
|
||||
* Event times tests.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Cameron Ball <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_event_times_testcase extends advanced_testcase {
|
||||
class event_times_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test event times class getters.
|
||||
*
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* This file contains the class that handles testing of the calendar event vault.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Ryan Wyllie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_calendar;
|
||||
|
||||
use action_event_test_factory;
|
||||
use core_calendar\local\event\data_access\event_vault;
|
||||
use core_calendar\local\event\strategies\raw_event_retrieval_strategy;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/calendar/tests/helpers.php');
|
||||
|
||||
use core_calendar\local\event\data_access\event_vault;
|
||||
use core_calendar\local\event\strategies\raw_event_retrieval_strategy;
|
||||
|
||||
/**
|
||||
* This file contains the class that handles testing of the calendar event vault.
|
||||
*
|
||||
@@ -37,7 +32,7 @@ use core_calendar\local\event\strategies\raw_event_retrieval_strategy;
|
||||
* @copyright 2017 Ryan Wyllie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_event_vault_testcase extends advanced_testcase {
|
||||
class event_vault_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test that get_action_events_by_timesort returns events after the
|
||||
@@ -517,7 +512,7 @@ class core_calendar_event_vault_testcase extends advanced_testcase {
|
||||
];
|
||||
|
||||
foreach ($events as $event) {
|
||||
calendar_event::create($event, false);
|
||||
\calendar_event::create($event, false);
|
||||
}
|
||||
|
||||
$factory = new action_event_test_factory();
|
||||
@@ -1174,7 +1169,7 @@ class core_calendar_event_vault_testcase extends advanced_testcase {
|
||||
];
|
||||
|
||||
foreach ($events as $event) {
|
||||
calendar_event::create($event, false);
|
||||
\calendar_event::create($event, false);
|
||||
}
|
||||
|
||||
$factory = new action_event_test_factory();
|
||||
|
||||
@@ -14,21 +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/>.
|
||||
|
||||
/**
|
||||
* Tests for the events_related_objects_cache.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Ryan Wyllie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_calendar;
|
||||
|
||||
use core_calendar\external\events_related_objects_cache;
|
||||
use core_calendar\local\event\container;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once(__DIR__ . '/helpers.php');
|
||||
|
||||
use \core_calendar\external\events_related_objects_cache;
|
||||
use \core_calendar\local\event\container;
|
||||
|
||||
/**
|
||||
* Tests for the events_related_objects_cache.
|
||||
*
|
||||
@@ -36,7 +30,7 @@ use \core_calendar\local\event\container;
|
||||
* @copyright 2017 Ryan Wyllie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_events_related_objects_cache_testcase extends advanced_testcase {
|
||||
class events_related_objects_cache_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests set up
|
||||
|
||||
@@ -14,20 +14,14 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Contains the class containing unit tests for the calendar local API.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @copyright 2017 Mark Nelson <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_calendar;
|
||||
|
||||
use core_calendar\local\event\container;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once(__DIR__ . '/helpers.php');
|
||||
|
||||
use \core_calendar\local\event\container;
|
||||
|
||||
/**
|
||||
* Class contaning unit tests for the calendar local API.
|
||||
*
|
||||
@@ -35,7 +29,7 @@ use \core_calendar\local\event\container;
|
||||
* @copyright 2017 Mark Nelson <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_calendar_local_api_testcase extends advanced_testcase {
|
||||
class local_api_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests set up
|
||||
@@ -752,7 +746,7 @@ class core_calendar_local_api_testcase extends advanced_testcase {
|
||||
]
|
||||
];
|
||||
foreach ($events as $event) {
|
||||
calendar_event::create($event, false);
|
||||
\calendar_event::create($event, false);
|
||||
}
|
||||
$timestart = time() - 60;
|
||||
$timeend = time() + 60;
|
||||
@@ -878,7 +872,7 @@ class core_calendar_local_api_testcase extends advanced_testcase {
|
||||
];
|
||||
|
||||
foreach ($events as $event) {
|
||||
calendar_event::create($event, false);
|
||||
\calendar_event::create($event, false);
|
||||
}
|
||||
|
||||
$timestart = $now - 100;
|
||||
@@ -954,7 +948,7 @@ class core_calendar_local_api_testcase extends advanced_testcase {
|
||||
];
|
||||
|
||||
foreach ($repeatingevents as $event) {
|
||||
calendar_event::create($event, false);
|
||||
\calendar_event::create($event, false);
|
||||
}
|
||||
|
||||
// Make sure repeating events are not filtered out.
|
||||
@@ -971,9 +965,9 @@ class core_calendar_local_api_testcase extends advanced_testcase {
|
||||
$user = $generator->create_user();
|
||||
$roleid = $generator->create_role();
|
||||
$context = \context_system::instance();
|
||||
$originalstarttime = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$newstartdate = new DateTimeImmutable('2018-02-2T10:00:00+08:00');
|
||||
$expected = new DateTimeImmutable('2018-02-2T15:00:00+08:00');
|
||||
$originalstarttime = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$newstartdate = new \DateTimeImmutable('2018-02-2T10:00:00+08:00');
|
||||
$expected = new \DateTimeImmutable('2018-02-2T15:00:00+08:00');
|
||||
$mapper = container::get_event_mapper();
|
||||
|
||||
$generator->role_assign($roleid, $user->id, $context->id);
|
||||
@@ -1006,9 +1000,9 @@ class core_calendar_local_api_testcase extends advanced_testcase {
|
||||
$user = $generator->create_user();
|
||||
$roleid = $generator->create_role();
|
||||
$context = \context_system::instance();
|
||||
$originalstarttime = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$newstartdate = new DateTimeImmutable('2018-02-2T10:00:00+08:00');
|
||||
$expected = new DateTimeImmutable('2018-02-2T15:00:00+08:00');
|
||||
$originalstarttime = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$newstartdate = new \DateTimeImmutable('2018-02-2T10:00:00+08:00');
|
||||
$expected = new \DateTimeImmutable('2018-02-2T15:00:00+08:00');
|
||||
$mapper = container::get_event_mapper();
|
||||
|
||||
$generator->role_assign($roleid, $user->id, $context->id);
|
||||
@@ -1043,9 +1037,9 @@ class core_calendar_local_api_testcase extends advanced_testcase {
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
$timeopen = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$newstartdate = new DateTimeImmutable('2018-02-2T10:00:00+08:00');
|
||||
$expected = new DateTimeImmutable('2018-02-2T15:00:00+08:00');
|
||||
$timeopen = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$newstartdate = new \DateTimeImmutable('2018-02-2T10:00:00+08:00');
|
||||
$expected = new \DateTimeImmutable('2018-02-2T15:00:00+08:00');
|
||||
list($feedback, $event) = $this->create_feedback_activity_and_event(
|
||||
[
|
||||
'timeopen' => $timeopen->getTimestamp(),
|
||||
@@ -1078,10 +1072,10 @@ class core_calendar_local_api_testcase extends advanced_testcase {
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
$timeopen = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$timeclose = new DateTimeImmutable('2019-01-1T15:00:00+08:00');
|
||||
$newstartdate = new DateTimeImmutable('2018-02-2T10:00:00+08:00');
|
||||
$expected = new DateTimeImmutable('2018-02-2T15:00:00+08:00');
|
||||
$timeopen = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$timeclose = new \DateTimeImmutable('2019-01-1T15:00:00+08:00');
|
||||
$newstartdate = new \DateTimeImmutable('2018-02-2T10:00:00+08:00');
|
||||
$expected = new \DateTimeImmutable('2018-02-2T15:00:00+08:00');
|
||||
list($feedback, $event) = $this->create_feedback_activity_and_event(
|
||||
[
|
||||
'timeopen' => $timeopen->getTimestamp(),
|
||||
@@ -1115,9 +1109,9 @@ class core_calendar_local_api_testcase extends advanced_testcase {
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
$timeopen = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$timeclose = new DateTimeImmutable('2018-02-2T15:00:00+08:00');
|
||||
$newstartdate = new DateTimeImmutable('2018-02-2T10:00:00+08:00');
|
||||
$timeopen = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$timeclose = new \DateTimeImmutable('2018-02-2T15:00:00+08:00');
|
||||
$newstartdate = new \DateTimeImmutable('2018-02-2T10:00:00+08:00');
|
||||
list($feedback, $event) = $this->create_feedback_activity_and_event(
|
||||
[
|
||||
'timeopen' => $timeopen->getTimestamp(),
|
||||
@@ -1151,9 +1145,9 @@ class core_calendar_local_api_testcase extends advanced_testcase {
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
$timeopen = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$timeclose = new DateTimeImmutable('2017-02-2T15:00:00+08:00');
|
||||
$newstartdate = new DateTimeImmutable('2018-02-2T10:00:00+08:00');
|
||||
$timeopen = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$timeclose = new \DateTimeImmutable('2017-02-2T15:00:00+08:00');
|
||||
$newstartdate = new \DateTimeImmutable('2018-02-2T10:00:00+08:00');
|
||||
list($feedback, $event) = $this->create_feedback_activity_and_event(
|
||||
[
|
||||
'timeopen' => $timeopen->getTimestamp(),
|
||||
@@ -1182,9 +1176,9 @@ class core_calendar_local_api_testcase extends advanced_testcase {
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
$timeclose = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$newstartdate = new DateTimeImmutable('2016-02-2T10:00:00+08:00');
|
||||
$expected = new DateTimeImmutable('2016-02-2T15:00:00+08:00');
|
||||
$timeclose = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$newstartdate = new \DateTimeImmutable('2016-02-2T10:00:00+08:00');
|
||||
$expected = new \DateTimeImmutable('2016-02-2T15:00:00+08:00');
|
||||
list($feedback, $event) = $this->create_feedback_activity_and_event(
|
||||
[
|
||||
'timeopen' => 0,
|
||||
@@ -1218,10 +1212,10 @@ class core_calendar_local_api_testcase extends advanced_testcase {
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
$timeopen = new DateTimeImmutable('2016-01-1T15:00:00+08:00');
|
||||
$timeclose = new DateTimeImmutable('2019-01-1T15:00:00+08:00');
|
||||
$newstartdate = new DateTimeImmutable('2018-02-2T10:00:00+08:00');
|
||||
$expected = new DateTimeImmutable('2018-02-2T15:00:00+08:00');
|
||||
$timeopen = new \DateTimeImmutable('2016-01-1T15:00:00+08:00');
|
||||
$timeclose = new \DateTimeImmutable('2019-01-1T15:00:00+08:00');
|
||||
$newstartdate = new \DateTimeImmutable('2018-02-2T10:00:00+08:00');
|
||||
$expected = new \DateTimeImmutable('2018-02-2T15:00:00+08:00');
|
||||
list($feedback, $event) = $this->create_feedback_activity_and_event(
|
||||
[
|
||||
'timeopen' => $timeopen->getTimestamp(),
|
||||
@@ -1255,10 +1249,10 @@ class core_calendar_local_api_testcase extends advanced_testcase {
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
$timeopen = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$timeclose = new DateTimeImmutable('2018-02-2T15:00:00+08:00');
|
||||
$newstartdate = new DateTimeImmutable('2017-01-1T10:00:00+08:00');
|
||||
$expected = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$timeopen = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$timeclose = new \DateTimeImmutable('2018-02-2T15:00:00+08:00');
|
||||
$newstartdate = new \DateTimeImmutable('2017-01-1T10:00:00+08:00');
|
||||
$expected = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
list($feedback, $event) = $this->create_feedback_activity_and_event(
|
||||
[
|
||||
'timeopen' => $timeopen->getTimestamp(),
|
||||
@@ -1292,9 +1286,9 @@ class core_calendar_local_api_testcase extends advanced_testcase {
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
$timeopen = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$timeclose = new DateTimeImmutable('2017-02-2T15:00:00+08:00');
|
||||
$newstartdate = new DateTimeImmutable('2016-02-2T10:00:00+08:00');
|
||||
$timeopen = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$timeclose = new \DateTimeImmutable('2017-02-2T15:00:00+08:00');
|
||||
$newstartdate = new \DateTimeImmutable('2016-02-2T10:00:00+08:00');
|
||||
list($feedback, $event) = $this->create_feedback_activity_and_event(
|
||||
[
|
||||
'timeopen' => $timeopen->getTimestamp(),
|
||||
@@ -1326,8 +1320,8 @@ class core_calendar_local_api_testcase extends advanced_testcase {
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
$mapper = container::get_event_mapper();
|
||||
$timeopen = new DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$newstartdate = new DateTimeImmutable('2016-02-2T10:00:00+08:00');
|
||||
$timeopen = new \DateTimeImmutable('2017-01-1T15:00:00+08:00');
|
||||
$newstartdate = new \DateTimeImmutable('2016-02-2T10:00:00+08:00');
|
||||
$generator = $this->getDataGenerator();
|
||||
$user = $generator->create_user();
|
||||
$course = $generator->create_course();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user