Compare commits
216 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b8fd606243 | |||
| 5cb257b4c3 | |||
| 64b6bca053 | |||
| d3d988fcc6 | |||
| bf3f06bb82 | |||
| fb714c7cf6 | |||
| 4ce6dc7b4d | |||
| cd6e0bf763 | |||
| 69ce532809 | |||
| 0f4e8413fc | |||
| 919f5bfb36 | |||
| 46ee4f4062 | |||
| edc7eb06b7 | |||
| 8af0c977d0 | |||
| f1c0f2849b | |||
| 00f0ebf5ea | |||
| 8c87a29d2e | |||
| 26fe42c16e | |||
| d7f72ffdc8 | |||
| 60d8572d4e | |||
| b7d79061f1 | |||
| cc7ccb6c42 | |||
| d16e3a8141 | |||
| 05bc504e4e | |||
| 7197b264b1 | |||
| 83e6407074 | |||
| 93e30fbe3c | |||
| 287d51323f | |||
| 8acd5f7390 | |||
| f7c7b7cb73 | |||
| 1271286cf5 | |||
| fda6e143af | |||
| 03c7f3dc87 | |||
| 985be80d1f | |||
| ef6bb4439d | |||
| 787e36fea8 | |||
| 79af8fb2f5 | |||
| f247f5b048 | |||
| 3176d756e0 | |||
| 5de3c84461 | |||
| b08a9e0b66 | |||
| ef6a03ea51 | |||
| ce8237d5fd | |||
| 8db9ab4908 | |||
| eda6b9ba8f | |||
| f85d5e9e5d | |||
| dd4702ee80 | |||
| ad5e6f00df | |||
| a3af9f65bf | |||
| 3584a14e78 | |||
| 77abe66d2c | |||
| ab22e012d8 | |||
| 758281716e | |||
| 9b64f0afcd | |||
| 9c611755d4 | |||
| 96b7a7d066 | |||
| cc68de58d1 | |||
| 79c83bfcef | |||
| 79e0d92848 | |||
| f7189aea98 | |||
| 58fcbe9678 | |||
| 4751e672e3 | |||
| ba64cce68d | |||
| 0d20c1c2d6 | |||
| 539d1b3c89 | |||
| 6d047756d2 | |||
| 6ba7009a11 | |||
| 56ab65f46a | |||
| ca13d3e05c | |||
| df32c00ab5 | |||
| f375246427 | |||
| 544947c9c7 | |||
| 1f6ab2b676 | |||
| 5f098189dd | |||
| 9e530add9e | |||
| a349ae01e9 | |||
| 99b5fb3a3b | |||
| a47525cbc9 | |||
| 762fb71a1f | |||
| 146d84ebde | |||
| c0b0f6f411 | |||
| 6e6260f6d0 | |||
| d0a2de670b | |||
| d82af28545 | |||
| ad408bbfdf | |||
| 0ff0d1d66a | |||
| 0957e83d8d | |||
| 4dd37348b4 | |||
| c5c6758ed7 | |||
| 78cbd77c0d | |||
| 8303206ae0 | |||
| d13ed5575c | |||
| 1d40ffaf55 | |||
| 146048903b | |||
| 57d119a43f | |||
| 3b18f7884f | |||
| 3cc3d83b7e | |||
| bd2cb3c4e8 | |||
| c8aa905ef0 | |||
| d1e8870fb5 | |||
| e34b09be48 | |||
| 94d025a912 | |||
| 1a87e306e9 | |||
| 9bbeeaa557 | |||
| 598845e3ff | |||
| 0c2cd0de2a | |||
| 170a12537b | |||
| 1662bae0ab | |||
| a0727a15d5 | |||
| 834e634c9f | |||
| ac7eedb851 | |||
| 78a4febfb4 | |||
| 99e43efb1e | |||
| 51c5405e6f | |||
| 01222cbb06 | |||
| df048de49d | |||
| 22dffcd0c2 | |||
| e5ec14cc01 | |||
| fa82e4aa00 | |||
| afa1b6f0ad | |||
| 4cb53f71b3 | |||
| 7e180482ca | |||
| a9af3c9cd4 | |||
| a37caf6126 | |||
| 8e0205ec56 | |||
| 3156398c54 | |||
| 21f43574fd | |||
| f83929ab57 | |||
| faa4d5ab56 | |||
| d89301add2 | |||
| 15e127fe7e | |||
| 79b5632ce9 | |||
| 75715efdfa | |||
| d80a7c43dc | |||
| 439e4edc99 | |||
| a39feaefe7 | |||
| 8c8e5eba2c | |||
| 16b9813aae | |||
| 07a07679a1 | |||
| 1207c31c78 | |||
| c8ade37695 | |||
| 23bb2275d9 | |||
| 1f7a90fbe2 | |||
| 82d55b7455 | |||
| 064c473a4e | |||
| bf6e018f9d | |||
| 5c418c72f3 | |||
| 47e66ef9d1 | |||
| 335b09205b | |||
| 9b779e3d53 | |||
| e084b47f92 | |||
| 44b49b5651 | |||
| 2742b32ed8 | |||
| df6d634d57 | |||
| b2b0d0795e | |||
| 39f39999be | |||
| 088519178f | |||
| 7ee20257b0 | |||
| 4fc3052a73 | |||
| fc056f1aa6 | |||
| 2fe2cd8eab | |||
| 4c0a1ffaab | |||
| c9d14b4ce8 | |||
| 6368b3f055 | |||
| 544d1ab453 | |||
| 4ba43b851d | |||
| fbbb7da0f6 | |||
| e78978ec6b | |||
| 394f65e91e | |||
| 2432ac2c08 | |||
| 986cf06e55 | |||
| 3619147c76 | |||
| de03dfa066 | |||
| bd9c3fd5db | |||
| e6b39085a8 | |||
| 3c982ce134 | |||
| eefd6bbf54 | |||
| b5157c8153 | |||
| 53cc3870e1 | |||
| 72b408772c | |||
| b08d4ea2ed | |||
| 0ed76e9316 | |||
| 3cca8ba5d8 | |||
| bfad8c4dd1 | |||
| da60508071 | |||
| ca14e2d950 | |||
| a7db400e61 | |||
| 59d7b57a7a | |||
| 4bdedd7d56 | |||
| dbe2390e97 | |||
| b24bef6b97 | |||
| 2affa30359 | |||
| 83ccb2913b | |||
| a2a37f3cb5 | |||
| b388341f47 | |||
| 7261abf98d | |||
| 10de05f5d6 | |||
| 4091db771e | |||
| 8978466354 | |||
| 590088f118 | |||
| 796a14a5ce | |||
| 9b302f133a | |||
| b8e9cb31e9 | |||
| 972744ee12 | |||
| 98104be4f4 | |||
| e7e690e3b8 | |||
| 6ded74cc2a | |||
| 1099b3f022 | |||
| 93315ab389 | |||
| 875591f589 | |||
| 1c33085ede | |||
| 464a4cb4d5 | |||
| 8a6e4904bf | |||
| 411416a37a | |||
| 313aedcf13 | |||
| c73673f2f3 |
@@ -13,7 +13,7 @@ env:
|
||||
|
||||
jobs:
|
||||
Grunt:
|
||||
runs-on: ubuntu-18.04
|
||||
runs-on: ubuntu-20.04
|
||||
|
||||
steps:
|
||||
- name: Checking out code
|
||||
@@ -54,11 +54,11 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-18.04
|
||||
- os: ubuntu-20.04
|
||||
php: 7.3
|
||||
extensions:
|
||||
db: mysqli
|
||||
- os: ubuntu-18.04
|
||||
- os: ubuntu-20.04
|
||||
php: 8.0
|
||||
db: pgsql
|
||||
extensions: xmlrpc-beta
|
||||
@@ -111,4 +111,5 @@ jobs:
|
||||
- name: Running PHPUnit tests
|
||||
env:
|
||||
dbtype: ${{ matrix.db }}
|
||||
run: vendor/bin/phpunit -v
|
||||
phpunit_options: ${{ secrets.phpunit_options }}
|
||||
run: vendor/bin/phpunit $phpunit_options
|
||||
|
||||
@@ -36,7 +36,7 @@ jobs:
|
||||
- php: 7.3
|
||||
env: DB=none TASK=CITEST
|
||||
- php: 7.3
|
||||
env: DB=none TASK=GRUNT NVM_VERSION='lts/carbon'
|
||||
env: DB=none TASK=GRUNT NVM_VERSION='lts/gallium'
|
||||
|
||||
- if: env(MOODLE_DATABASE) = "pgsql" OR env(MOODLE_DATABASE) = "all" OR env(MOODLE_DATABASE) IS NOT present
|
||||
php: 7.3
|
||||
@@ -52,7 +52,7 @@ jobs:
|
||||
env: DB=none TASK=CITEST
|
||||
- if: env(MOODLE_PHP) = "all"
|
||||
php: 8.0
|
||||
env: DB=none TASK=GRUNT NVM_VERSION='lts/carbon'
|
||||
env: DB=none TASK=GRUNT NVM_VERSION='lts/gallium'
|
||||
|
||||
- if: env(MOODLE_PHP) = "all" AND (env(MOODLE_DATABASE) = "pgsql" OR env(MOODLE_DATABASE) = "all" OR env(MOODLE_DATABASE) IS NOT present)
|
||||
php: 8.0
|
||||
|
||||
@@ -69,11 +69,11 @@ if ($options['help'] or (!$options['list'] and !$options['execute'])) {
|
||||
die;
|
||||
}
|
||||
|
||||
if ($options['showdebugging']) {
|
||||
if ($options['showdebugging'] || !empty($CFG->showcrondebugging)) {
|
||||
set_debugging(DEBUG_DEVELOPER, true);
|
||||
}
|
||||
|
||||
if ($options['showsql']) {
|
||||
if ($options['showsql'] || !empty($CFG->showcronsql)) {
|
||||
$DB->set_debug(true);
|
||||
}
|
||||
if ($options['list']) {
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -492,7 +492,10 @@ if ($hassiteconfig && !empty($CFG->enableplagiarism)) {
|
||||
$plugin->load_settings($ADMIN, 'plagiarism', $hassiteconfig);
|
||||
}
|
||||
}
|
||||
$ADMIN->add('reports', new admin_externalpage('comments', new lang_string('comments'), $CFG->wwwroot.'/comment/', 'moodle/site:viewreports'));
|
||||
|
||||
// Comments report, note this page is really just a means to delete comments so check that.
|
||||
$ADMIN->add('reports', new admin_externalpage('comments', new lang_string('comments'), $CFG->wwwroot . '/comment/index.php',
|
||||
'moodle/comment:delete'));
|
||||
|
||||
// Course reports settings
|
||||
if ($hassiteconfig) {
|
||||
|
||||
@@ -236,7 +236,8 @@ if ($hassiteconfig
|
||||
if ($field->param2 > 255 || $field->datatype != 'text') {
|
||||
continue;
|
||||
}
|
||||
$fields['profile_field_' . $field->shortname] = $field->name . ' *';
|
||||
$fields['profile_field_' . $field->shortname] = format_string($field->name, true,
|
||||
['context' => context_system::instance()]) . ' *';
|
||||
}
|
||||
|
||||
return $fields;
|
||||
|
||||
@@ -20,9 +20,10 @@ Feature: Forms manipulation
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And I log in as "admin"
|
||||
And I am on "Course 1" course homepage with editing mode on
|
||||
And I add a "Quiz" to section "1"
|
||||
And the following "activities" exist:
|
||||
| activity | course | section | name |
|
||||
| quiz | C1 | 1 | Quiz 1 |
|
||||
And I am on the "Quiz 1" "quiz activity editing" page logged in as admin
|
||||
When I expand all fieldsets
|
||||
Then I should see "Close the quiz"
|
||||
And I should see "Group mode"
|
||||
|
||||
@@ -786,6 +786,18 @@ class api {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user has permission to create data download request for themselves
|
||||
*
|
||||
* @param int|null $userid
|
||||
* @return bool
|
||||
*/
|
||||
public static function can_create_data_download_request_for_self(int $userid = null): bool {
|
||||
global $USER;
|
||||
$userid = $userid ?: $USER->id;
|
||||
return has_capability('tool/dataprivacy:downloadownrequest', \context_user::instance($userid), $userid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user has permisson to create data deletion request for themselves.
|
||||
*
|
||||
@@ -847,7 +859,7 @@ class api {
|
||||
|
||||
$usercontext = \context_user::instance($userid);
|
||||
// If it's your own and you have the right capability, you can download it.
|
||||
if ($userid == $downloaderid && has_capability('tool/dataprivacy:downloadownrequest', $usercontext, $downloaderid)) {
|
||||
if ($userid == $downloaderid && self::can_create_data_download_request_for_self($downloaderid)) {
|
||||
return true;
|
||||
}
|
||||
// If you can download anyone's in that context, you can download it.
|
||||
|
||||
@@ -96,6 +96,11 @@ if ($data = $mform->get_data()) {
|
||||
throw new moodle_exception('nopermissions', 'error', '',
|
||||
get_string('errorcannotrequestdeleteforother', 'tool_dataprivacy'));
|
||||
}
|
||||
} else if ($data->type == \tool_dataprivacy\api::DATAREQUEST_TYPE_EXPORT) {
|
||||
if ($data->userid == $USER->id && !\tool_dataprivacy\api::can_create_data_download_request_for_self()) {
|
||||
throw new moodle_exception('nopermissions', 'error', '',
|
||||
get_string('errorcannotrequestexportforself', 'tool_dataprivacy'));
|
||||
}
|
||||
}
|
||||
|
||||
\tool_dataprivacy\api::create_data_request($data->userid, $data->type, $data->comments);
|
||||
|
||||
@@ -97,10 +97,11 @@ class tool_dataprivacy_data_request_form extends \core\form\persistent {
|
||||
$mform->setType('userid', PARAM_INT);
|
||||
|
||||
// Subject access request type.
|
||||
$options = [
|
||||
api::DATAREQUEST_TYPE_EXPORT => get_string('requesttypeexport', 'tool_dataprivacy'),
|
||||
api::DATAREQUEST_TYPE_DELETE => get_string('requesttypedelete', 'tool_dataprivacy')
|
||||
];
|
||||
$options = [];
|
||||
if ($this->manage || api::can_create_data_download_request_for_self()) {
|
||||
$options[api::DATAREQUEST_TYPE_EXPORT] = get_string('requesttypeexport', 'tool_dataprivacy');
|
||||
}
|
||||
$options[api::DATAREQUEST_TYPE_DELETE] = get_string('requesttypedelete', 'tool_dataprivacy');
|
||||
|
||||
$mform->addElement('select', 'type', get_string('requesttype', 'tool_dataprivacy'), $options);
|
||||
$mform->addHelpButton('type', 'requesttype', 'tool_dataprivacy');
|
||||
@@ -174,7 +175,7 @@ class tool_dataprivacy_data_request_form extends \core\form\persistent {
|
||||
$errors['type'] = get_string('errorrequestalreadyexists', 'tool_dataprivacy');
|
||||
}
|
||||
|
||||
// Check if current user can create data deletion request.
|
||||
// Check if current user can create data requests.
|
||||
if ($data->type == api::DATAREQUEST_TYPE_DELETE) {
|
||||
if ($userid == $USER->id) {
|
||||
if (!api::can_create_data_deletion_request_for_self()) {
|
||||
@@ -184,6 +185,10 @@ class tool_dataprivacy_data_request_form extends \core\form\persistent {
|
||||
&& !api::can_create_data_deletion_request_for_children($userid)) {
|
||||
$errors['type'] = get_string('errorcannotrequestdeleteforother', 'tool_dataprivacy');
|
||||
}
|
||||
} else if ($data->type == api::DATAREQUEST_TYPE_EXPORT) {
|
||||
if ($userid == $USER->id && !api::can_create_data_download_request_for_self()) {
|
||||
$errors['type'] = get_string('errorcannotrequestexportforself', 'tool_dataprivacy');
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
|
||||
@@ -135,6 +135,7 @@ $string['effectiveretentionperioduser'] = '{$a} (since the last time the user ac
|
||||
$string['emailsalutation'] = 'Dear {$a},';
|
||||
$string['errorcannotrequestdeleteforself'] = 'You don\'t have permission to create deletion request for yourself.';
|
||||
$string['errorcannotrequestdeleteforother'] = 'You don\'t have permission to create deletion request for this user.';
|
||||
$string['errorcannotrequestexportforself'] = 'You don\'t have permission to create export request for yourself.';
|
||||
$string['errorcontactdpodisabled'] = 'The option to contact the privacy officer is disabled.';
|
||||
$string['errorinvalidrequestcomments'] = 'The comments field may contain plain text only.';
|
||||
$string['errorinvalidrequestcreationmethod'] = 'Invalid request creation method!';
|
||||
|
||||
@@ -68,8 +68,9 @@ function tool_dataprivacy_myprofile_navigation(tree $tree, $user, $iscurrentuser
|
||||
|
||||
// Check if the user has an ongoing data export request.
|
||||
$hasexportrequest = \tool_dataprivacy\api::has_ongoing_request($user->id, \tool_dataprivacy\api::DATAREQUEST_TYPE_EXPORT);
|
||||
// Show data export link only if the user doesn't have an ongoing data export request.
|
||||
if (!$hasexportrequest) {
|
||||
// Show data export link only if the user doesn't have an ongoing data export request and has permission
|
||||
// to download own data.
|
||||
if (!$hasexportrequest && \tool_dataprivacy\api::can_create_data_download_request_for_self()) {
|
||||
$exportparams = ['type' => \tool_dataprivacy\api::DATAREQUEST_TYPE_EXPORT];
|
||||
$exporturl = new moodle_url('/admin/tool/dataprivacy/createdatarequest.php', $exportparams);
|
||||
$exportnode = new core_user\output\myprofile\node('privacyandpolicies', 'requestdataexport',
|
||||
|
||||
@@ -26,6 +26,7 @@ use tool_dataprivacy\task\process_data_request_task;
|
||||
* API tests.
|
||||
*
|
||||
* @package tool_dataprivacy
|
||||
* @covers \tool_dataprivacy\api
|
||||
* @copyright 2018 Jun Pataleta
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -2174,6 +2175,27 @@ class api_test extends \advanced_testcase {
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether user can create data download request for themselves
|
||||
*/
|
||||
public function test_can_create_data_download_request_for_self(): void {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
|
||||
// The default user role allows for the creation of download data requests.
|
||||
$this->assertTrue(api::can_create_data_download_request_for_self());
|
||||
|
||||
// Prohibit that capability.
|
||||
$userrole = $DB->get_field('role', 'id', ['shortname' => 'user'], MUST_EXIST);
|
||||
assign_capability('tool/dataprivacy:downloadownrequest', CAP_PROHIBIT, $userrole, \context_user::instance($user->id));
|
||||
|
||||
$this->assertFalse(api::can_create_data_download_request_for_self());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test user cannot create data deletion request for themselves if they don't have
|
||||
* "tool/dataprivacy:requestdelete" 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 <andrew@nicols.co.uk>
|
||||
* @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 <andrew@nicols.co.uk>
|
||||
* @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 <andrew@nicols.co.uk>
|
||||
* @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 <andrew@nicols.co.uk>
|
||||
* @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 <andrew@nicols.co.uk>
|
||||
* @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 <andrew@nicols.co.uk>
|
||||
* @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 <andrew@nicols.co.uk>
|
||||
* @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 <andrew@nicols.co.uk>
|
||||
* @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 <mihail@moodle.com>
|
||||
* @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 <mihail@moodle.com>
|
||||
* @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.
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
This file describes API changes in /admin/tool/dataprivacy/*
|
||||
Information provided here is intended especially for developers.
|
||||
|
||||
=== 3.11.8 ===
|
||||
* New `api::can_create_data_download_request_for_self` method for determining whether user has permission to create their
|
||||
own data download requests
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 207 B After Width: | Height: | Size: 329 B |
@@ -1,3 +1,3 @@
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
|
||||
<!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
|
||||
]><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" preserveAspectRatio="xMinYMid meet" overflow="visible"><path d="M16 9v6c0 .5-.5 1-1 1H1c-.5 0-1-.5-1-1V9c0-.5.5-1 1-1h1c.5 0 1 .5 1 1v4h10V9c0-.5.5-1 1-1h1c.5 0 1 .5 1 1zm-3.6-3.9l-.7-.7c-.4-.4-1-.4-1.4 0l-.8.8V1c0-.5-.4-1-1-1h-1c-.5 0-1 .5-1 1v4.2l-.8-.8c-.4-.4-1-.4-1.4 0l-.7.7c-.4.4-.4 1 0 1.4l3.7 3.7c.2.2.5.3.7.3.3 0 .5-.1.7-.3l3.7-3.7c.4-.3.4-1 0-1.4z" fill="#999"/></svg>
|
||||
]><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" preserveAspectRatio="xMinYMid meet" overflow="visible"><path d="M16 9v6c0 .5-.5 1-1 1H1c-.5 0-1-.5-1-1V9c0-.5.5-1 1-1h1c.5 0 1 .5 1 1v4h10V9c0-.5.5-1 1-1h1c.5 0 1 .5 1 1zm-3.6-3.9l-.7-.7c-.4-.4-1-.4-1.4 0l-.8.8V1c0-.5-.4-1-1-1h-1c-.5 0-1 .5-1 1v4.2l-.8-.8c-.4-.4-1-.4-1.4 0l-.7.7c-.4.4-.4 1 0 1.4l3.7 3.7c.2.2.5.3.7.3.3 0 .5-.1.7-.3l3.7-3.7c.4-.3.4-1 0-1.4z" fill="#888"/></svg>
|
||||
|
Before Width: | Height: | Size: 618 B After Width: | Height: | Size: 618 B |
@@ -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 <david@moodle.com>
|
||||
* @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 <david@moodle.com>
|
||||
* @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('');
|
||||
}
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 345 B After Width: | Height: | Size: 510 B |
@@ -9,7 +9,7 @@
|
||||
xml:space="preserve" preserveAspectRatio="xMinYMid meet">
|
||||
<defs>
|
||||
</defs>
|
||||
<path style="fill:#999999;" d="M8.5,9.5C8.8,10,9,10.6,9,11.2c0,0.6-0.3,1.1-0.7,1.6l-2.5,2.5C5.2,15.8,4.7,16,4,16
|
||||
<path style="fill:#888;" d="M8.5,9.5C8.8,10,9,10.6,9,11.2c0,0.6-0.3,1.1-0.7,1.6l-2.5,2.5C5.2,15.8,4.7,16,4,16
|
||||
s-1.3-0.2-1.7-0.7l-1.5-1.5C0.2,13.3,0,12.7,0,12c0-0.7,0.2-1.3,0.7-1.7l2.5-2.5C3.7,7.3,4.3,7,5,7c0.5,0,1,0.2,1.5,0.5l-1,1
|
||||
C5.3,8.5,5.2,8.4,5,8.4c-0.3,0-0.5,0.1-0.8,0.3l-2.5,2.5c-0.2,0.2-0.3,0.5-0.3,0.7c0,0.3,0.1,0.5,0.3,0.7l1.5,1.5
|
||||
c0.2,0.2,0.5,0.3,0.7,0.3s0.5-0.1,0.7-0.3l2.5-2.5c0.2-0.2,0.3-0.5,0.3-0.8c0-0.2,0-0.3-0.1-0.4L8.5,9.5z M5,10L10,5
|
||||
|
||||
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
@@ -27,7 +27,8 @@ require_once($CFG->libdir . '/externallib.php');
|
||||
|
||||
$userid = required_param('userid', PARAM_INT); // The user id the key belongs to (for double-checking).
|
||||
$key = required_param('key', PARAM_ALPHANUMEXT); // The key generated by the tool_mobile_external::get_autologin_key() external function.
|
||||
$urltogo = optional_param('urltogo', $CFG->wwwroot, PARAM_URL); // URL to redirect.
|
||||
$urltogo = optional_param('urltogo', $CFG->wwwroot, PARAM_LOCALURL); // URL to redirect.
|
||||
$urltogo = $urltogo ?: $CFG->wwwroot;
|
||||
|
||||
$context = context_system::instance();
|
||||
$PAGE->set_context($context);
|
||||
|
||||
@@ -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 <ankit.agrr@gmail.com>
|
||||
* @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 <ankit.agrr@gmail.com>
|
||||
* @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 <simey@moodle.com>
|
||||
* @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 <simey@moodle.com>
|
||||
* @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 <jrhdallimore@gmail.com>
|
||||
* @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 <jrhdallimore@gmail.com>
|
||||
* @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 <markn@moodle.com>
|
||||
* @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 <adrian@moodle.com>
|
||||
* @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 <adrian@moodle.com>
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 345 B After Width: | Height: | Size: 294 B |
@@ -56,5 +56,5 @@
|
||||
d="m 10.60981,13.748496 q -0.42076,-0.2046 -0.42076,-0.6595 v -2.1834 H 0.36389001 q -0.15919999,0 -0.26154001,-0.102297 Q 0,10.700897 0,10.541796 V 2.5361969 q 0,-0.2388 0.20469002,-0.3297 0.22743999,-0.091 0.39800999,0.045 L 2.7860701,4.0708971 q 0.1250916,0.1024 0.1250916,0.2842998 v 3.639 H 10.18905 V 5.810797 q 0,-0.4548999 0.42076,-0.6596001 0.42075,-0.1932998 0.77327,0.1024 L 15.749821,8.892496 Q 16,9.0971966 16,9.4496973 16,9.8022974 15.749821,10.006998 l -4.366741,3.638798 q -0.36389,0.307 -0.77327,0.102297 z"
|
||||
id="path4552"
|
||||
inkscape:connector-curvature="0"
|
||||
style="fill:#999999;fill-opacity:1;stroke-width:0.9999997" />
|
||||
style="fill:#888;fill-opacity:1;stroke-width:0.9999997" />
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
@@ -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 <david@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_policy;
|
||||
|
||||
use tool_policy\api;
|
||||
use tool_policy\policy_version;
|
||||
use tool_policy\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 <david@moodle.com>
|
||||
* @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.
|
||||
|
||||
|
Before Width: | Height: | Size: 229 B After Width: | Height: | Size: 247 B |
@@ -9,7 +9,7 @@
|
||||
xml:space="preserve" preserveAspectRatio="xMinYMid meet">
|
||||
<defs>
|
||||
</defs>
|
||||
<path style="fill:#999999;" d="M2,5v9c0,1.1,0.9,2,2,2h8c1.1,0,2-0.9,2-2V5H2z M5,13.5C5,13.8,4.8,14,4.5,14S4,13.8,4,13.5v-6
|
||||
<path style="fill:#888;" d="M2,5v9c0,1.1,0.9,2,2,2h8c1.1,0,2-0.9,2-2V5H2z M5,13.5C5,13.8,4.8,14,4.5,14S4,13.8,4,13.5v-6
|
||||
C4,7.2,4.2,7,4.5,7S5,7.2,5,7.5V13.5z M8.5,13.5C8.5,13.8,8.3,14,8,14s-0.5-0.2-0.5-0.5v-6C7.5,7.2,7.7,7,8,7s0.5,0.2,0.5,0.5V13.5z
|
||||
M12,13.5c0,0.3-0.2,0.5-0.5,0.5S11,13.8,11,13.5v-6C11,7.2,11.2,7,11.5,7S12,7.2,12,7.5V13.5z M0,4c0-1.1,0.9-2,2-2h4v0
|
||||
c0-1.1,0.9-2,2-2s2,0.9,2,2v0h4c1.1,0,2,0.9,2,2H0z"/>
|
||||
|
||||
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
@@ -19,14 +19,13 @@ Feature: Backup user data
|
||||
And the following config values are set as admin:
|
||||
| coursebinenable | 1 | tool_recyclebin |
|
||||
| autohide | 0 | tool_recyclebin |
|
||||
And the following "activities" exist:
|
||||
| activity | course | section | name | intro |
|
||||
| quiz | C1 | 1 | Quiz 1 | Test quiz description |
|
||||
|
||||
@javascript
|
||||
Scenario: Delete and restore a quiz with user data
|
||||
Given I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage with editing mode on
|
||||
And I add a "Quiz" to section "1" and I fill the form with:
|
||||
| Name | Quiz 1 |
|
||||
| Description | Test quiz description |
|
||||
Given I am on the "Quiz 1" "quiz activity" page logged in as teacher1
|
||||
And I add a "True/False" question to the "Quiz 1" quiz with:
|
||||
| Question name | TF1 |
|
||||
| Question text | First question |
|
||||
@@ -41,6 +40,8 @@ Feature: Backup user data
|
||||
| Correct answer | False |
|
||||
| Feedback for the response 'True'. | So you think it is true |
|
||||
| Feedback for the response 'False'. | So you think it is false |
|
||||
And I set the field "maxgrade" to "10.0"
|
||||
And I press "savechanges"
|
||||
And I log out
|
||||
When I am on the "Quiz 1" "quiz activity" page logged in as student1
|
||||
And I press "Attempt quiz now"
|
||||
|
||||
@@ -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 <ankit.agrr@gmail.com>
|
||||
* @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 <ankit.agrr@gmail.com>
|
||||
* @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().
|
||||
|
||||
|
Before Width: | Height: | Size: 257 B After Width: | Height: | Size: 511 B |
@@ -1,3 +1,3 @@
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
|
||||
<!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
|
||||
]><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" preserveAspectRatio="xMinYMid meet" overflow="visible"><path d="M7.9 16c4 0 7.4-3 7.8-7h-3c-.5 2-2.5 4-4.9 4-2.8 0-5-2.2-5-5s2.2-5 5-5c1.1 0 2.1 0 3 1h-1c-.5 0-.8.5-.8 1.1v1c0 .5.3.9.8.9h5c.6 0 1.2-.4 1.2-.9v-5c0-.6-.6-1.1-1.2-1.1h-1c-.5 0-.8.5-.8 1.1V2C12 .9 9.9.2 8 .2 3.6.2 0 3.7 0 8.1 0 12.4 3.5 16 7.9 16z" fill="#999"/></svg>
|
||||
]><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" preserveAspectRatio="xMinYMid meet" overflow="visible"><path d="M7.9 16c4 0 7.4-3 7.8-7h-3c-.5 2-2.5 4-4.9 4-2.8 0-5-2.2-5-5s2.2-5 5-5c1.1 0 2.1 0 3 1h-1c-.5 0-.8.5-.8 1.1v1c0 .5.3.9.8.9h5c.6 0 1.2-.4 1.2-.9v-5c0-.6-.6-1.1-1.2-1.1h-1c-.5 0-.8.5-.8 1.1V2C12 .9 9.9.2 8 .2 3.6.2 0 3.7 0 8.1 0 12.4 3.5 16 7.9 16z" fill="#888"/></svg>
|
||||
|
Before Width: | Height: | Size: 569 B After Width: | Height: | Size: 569 B |
|
Before Width: | Height: | Size: 266 B After Width: | Height: | Size: 342 B |
@@ -9,7 +9,7 @@
|
||||
xml:space="preserve" preserveAspectRatio="xMinYMid meet">
|
||||
<defs>
|
||||
</defs>
|
||||
<path style="fill:#999999;" d="M12,7v4c0,0.5-0.5,1-1,1h-0.5l0,0H1c-0.5,0-1-0.5-1-1V7c0-0.5,0.5-1,1-1h0.5c0.5,0,1,0.5,1,1l0,2.5h7
|
||||
<path style="fill:#888;" d="M12,7v4c0,0.5-0.5,1-1,1h-0.5l0,0H1c-0.5,0-1-0.5-1-1V7c0-0.5,0.5-1,1-1h0.5c0.5,0,1,0.5,1,1l0,2.5h7
|
||||
V7c0-0.5,0.5-1,1-1H11C11.5,6,12,6.5,12,7z M9.9,3.6L6.6,0.3C6.4,0.1,6.2,0,5.9,0C5.7,0,5.4,0.1,5.2,0.3L1.9,3.6
|
||||
C1.5,4,1.5,4.6,1.9,5l0.3,0.3c0.4,0.4,1,0.4,1.4,0l1-1.1l0,2.7c0,0.5,0.5,1,1,1l0.5,0c0.5,0,1-0.5,1-1l0-2.7l1,1
|
||||
c0.4,0.4,1,0.4,1.4,0L10,5C10.3,4.6,10.3,4,9.9,3.6z"/>
|
||||
|
||||
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
@@ -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 <tomdickman@catalyst-au.net>
|
||||
* @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 <tomdickman@catalyst-au.net>
|
||||
* @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 <andrew@nicols.co.uk>
|
||||
* @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 <andrew@nicols.co.uk>
|
||||
* @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 <andrew@nicols.co.uk>
|
||||
* @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 <andrew@nicols.co.uk>
|
||||
* @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 <andrew@nicols.co.uk>
|
||||
* @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 <andrew@nicols.co.uk>
|
||||
* @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'=>'u3@example.com',
|
||||
'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 <gilles-philippe.leblanc@umontreal.ca>
|
||||
* @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 <gilles-philippe.leblanc@umontreal.ca>
|
||||
* @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 <shamim@moodle.com>
|
||||
* @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;
|
||||
|
||||
@@ -684,7 +684,7 @@ class tree extends tree_node {
|
||||
} else {
|
||||
unset($this->children[$index]);
|
||||
unset($this->showchildren[$index]);
|
||||
$this->showchildren = array_values($this->showchildren);
|
||||
$this->showchildren = !is_null($this->showchildren) ? array_values($this->showchildren) : null;
|
||||
$changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -111,8 +111,13 @@ abstract class base_controller extends backup implements loggable {
|
||||
*
|
||||
* @param \stdClass $data The course copy data.
|
||||
* @throws backup_controller_exception
|
||||
* @deprecated since Moodle 4.1 MDL-74548 - please do not use this method anymore.
|
||||
* @todo MDL-75025 This method will be deleted in Moodle 4.5
|
||||
* @see restore_controller::__construct()
|
||||
*/
|
||||
public function set_copy(\stdClass $data): void {
|
||||
debugging('The method base_controller::set_copy() is deprecated.
|
||||
Please use the restore_controller class instead.', DEBUG_DEVELOPER);
|
||||
// Only allow setting of copy data when controller is in copy mode.
|
||||
if ($this->mode != backup::MODE_COPY) {
|
||||
throw new backup_controller_exception('cannot_set_copy_vars_wrong_mode');
|
||||
@@ -124,8 +129,13 @@ abstract class base_controller extends backup implements loggable {
|
||||
* Get the course copy data.
|
||||
*
|
||||
* @return \stdClass
|
||||
* @deprecated since Moodle 4.1 MDL-74548 - please do not use this method anymore.
|
||||
* @todo MDL-75026 This method will be deleted in Moodle 4.5
|
||||
* @see restore_controller::get_copy()
|
||||
*/
|
||||
public function get_copy(): \stdClass {
|
||||
debugging('The method base_controller::get_copy() is deprecated.
|
||||
Please use restore_controller::get_copy() instead.', DEBUG_DEVELOPER);
|
||||
return $this->copy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,13 @@ class restore_controller extends base_controller {
|
||||
/** @var int Number of restore_controllers that are currently executing */
|
||||
protected static $executing = 0;
|
||||
|
||||
/**
|
||||
* Holds the relevant destination information for course copy operations.
|
||||
*
|
||||
* @var \stdClass.
|
||||
*/
|
||||
protected $copy;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -79,10 +86,17 @@ class restore_controller extends base_controller {
|
||||
* @param int $userid
|
||||
* @param int $target backup::TARGET_[ NEW_COURSE | CURRENT_ADDING | CURRENT_DELETING | EXISTING_ADDING | EXISTING_DELETING ]
|
||||
* @param \core\progress\base $progress Optional progress monitor
|
||||
* @param \stdClass $copydata Course copy data, required when in MODE_COPY
|
||||
* @param bool $releasesession Should release the session? backup::RELEASESESSION_YES or backup::RELEASESESSION_NO
|
||||
*/
|
||||
public function __construct($tempdir, $courseid, $interactive, $mode, $userid, $target,
|
||||
\core\progress\base $progress = null, $releasesession = backup::RELEASESESSION_NO) {
|
||||
\core\progress\base $progress = null, $releasesession = backup::RELEASESESSION_NO, ?\stdClass $copydata = null) {
|
||||
|
||||
if ($mode == backup::MODE_COPY && is_null($copydata)) {
|
||||
throw new restore_controller_exception('cannot_instantiate_missing_copydata');
|
||||
}
|
||||
|
||||
$this->copy = $copydata;
|
||||
$this->tempdir = $tempdir;
|
||||
$this->courseid = $courseid;
|
||||
$this->interactive = $interactive;
|
||||
@@ -563,6 +577,19 @@ class restore_controller extends base_controller {
|
||||
$this->progress->end_progress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the course copy data.
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get_copy(): \stdClass {
|
||||
if ($this->mode != backup::MODE_COPY) {
|
||||
throw new restore_controller_exception('cannot_get_copy_wrong_mode');
|
||||
}
|
||||
|
||||
return $this->copy;
|
||||
}
|
||||
|
||||
// Protected API starts here
|
||||
|
||||
protected function calculate_restoreid() {
|
||||
|
||||
@@ -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
|
||||
@@ -61,17 +72,28 @@ class core_backup_controller_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test set copy method.
|
||||
* Test get_copy
|
||||
*
|
||||
* @covers \restore_controller::get_copy
|
||||
*/
|
||||
public function test_base_controller_set_copy() {
|
||||
$this->expectException(\backup_controller_exception::class);
|
||||
$copy = new \stdClass();
|
||||
public function test_restore_controller_get_copy() {
|
||||
$copydata = (object)["some" => "copydata"];
|
||||
$rc = new \restore_controller(1729, $this->courseid, backup::INTERACTIVE_NO, backup::MODE_COPY,
|
||||
$this->userid, backup::TARGET_NEW_COURSE, null, backup::RELEASESESSION_NO, $copydata);
|
||||
|
||||
// Set up controller as a non-copy operation.
|
||||
$bc = new \backup_controller(backup::TYPE_1COURSE, $this->courseid, backup::FORMAT_MOODLE,
|
||||
backup::INTERACTIVE_NO, backup::MODE_GENERAL, $this->userid, backup::RELEASESESSION_YES);
|
||||
$this->assertEquals($copydata, $rc->get_copy());
|
||||
}
|
||||
|
||||
$bc->set_copy($copy);
|
||||
/**
|
||||
* Test instantiating a restore controller for a course copy without providing copy data.
|
||||
*
|
||||
* @covers \restore_controller::__construct
|
||||
*/
|
||||
public function test_restore_controller_copy_without_copydata() {
|
||||
$this->expectException(\restore_controller_exception::class);
|
||||
|
||||
new \restore_controller(1729, $this->courseid, backup::INTERACTIVE_NO, backup::MODE_COPY,
|
||||
$this->userid, backup::TARGET_NEW_COURSE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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 <mark@moodlerooms.com>
|
||||
* @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 <mark@moodlerooms.com>
|
||||
* @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']);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -70,8 +71,8 @@ if ($mform->is_cancelled()) {
|
||||
} else if ($mdata = $mform->get_data()) {
|
||||
|
||||
// Process the form and create the copy task.
|
||||
$backupcopy = new \core_backup\copy\copy($mdata);
|
||||
$backupcopy->create_copy();
|
||||
$copydata = \copy_helper::process_formdata($mdata);
|
||||
\copy_helper::create_copy($copydata);
|
||||
|
||||
if (!empty($mdata->submitdisplay)) {
|
||||
// Redirect to the copy progress overview.
|
||||
|
||||
@@ -388,8 +388,8 @@ class core_backup_external extends external_api {
|
||||
|
||||
if ($mdata) {
|
||||
// Create the copy task.
|
||||
$backupcopy = new \core_backup\copy\copy($mdata);
|
||||
$copyids = $backupcopy->create_copy();
|
||||
$copydata = \copy_helper::process_formdata($mdata);
|
||||
$copyids = \copy_helper::create_copy($copydata);
|
||||
} else {
|
||||
throw new moodle_exception('copyformfail', 'backup');
|
||||
}
|
||||
|
||||
@@ -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 (dmitriim@catalyst-au.net)
|
||||
* @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 (dmitriim@catalyst-au.net)
|
||||
* @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 = format_base::instance($course->id);
|
||||
$courseobject = \format_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 = format_base::instance($course->id);
|
||||
$courseobject = \format_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 = format_base::instance($course->id);
|
||||
$courseobject = \format_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 = format_base::instance($newcourse->id);
|
||||
$newcourseobject = \format_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 <andrew@nicols.co.uk>
|
||||
* @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 <andrew@nicols.co.uk>
|
||||
* @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 <adrian@moodle.com>
|
||||
* @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 <adrian@moodle.com>
|
||||
* @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 <mattp@catalyst-au.net>
|
||||
* @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 <mattp@catalyst-au.net>
|
||||
* @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 <mattp@catalyst-au.net>
|
||||
* @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 <mattp@catalyst-au.net>
|
||||
* @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 <johnyao@catalyst-au.net>
|
||||
* @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]);
|
||||
|
||||
@@ -141,12 +146,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);
|
||||
@@ -157,7 +162,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);
|
||||
@@ -188,7 +193,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;
|
||||
@@ -201,7 +206,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]);
|
||||
|
||||
@@ -221,7 +226,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;
|
||||
@@ -236,7 +241,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]);
|
||||
|
||||
@@ -256,7 +261,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;
|
||||
@@ -271,7 +276,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]);
|
||||
|
||||
@@ -288,28 +293,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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -321,21 +326,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();
|
||||
@@ -343,7 +348,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 <mikhailgolenkov@catalyst-au.net>
|
||||
* @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 <mikhailgolenkov@catalyst-au.net>
|
||||
* @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 <tomotsuyuki@catalyst-au.net>
|
||||
* @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 <tomotsuyuki@catalyst-au.net>
|
||||
* @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();
|
||||
|
||||
|
||||
@@ -82,8 +82,8 @@ class externallib_test extends externallib_advanced_testcase {
|
||||
$formdata->role_3 = 3;
|
||||
$formdata->role_5 = 5;
|
||||
|
||||
$coursecopy = new \core_backup\copy\copy($formdata);
|
||||
$copydetails = $coursecopy->create_copy();
|
||||
$copydata = \copy_helper::process_formdata($formdata);
|
||||
$copydetails = \copy_helper::create_copy($copydata);
|
||||
$copydetails['operation'] = \backup::OPERATION_BACKUP;
|
||||
|
||||
$params = array('copies' => $copydetails);
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
/**
|
||||
* Decode links quiz restore tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2020 Ilya Tregubov <mattp@catalyst-au.net>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -31,9 +25,13 @@ require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
|
||||
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
|
||||
|
||||
/**
|
||||
* restore_decode tests (both rule and content)
|
||||
* Decode links quiz restore tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2020 Ilya Tregubov <mattp@catalyst-au.net>
|
||||
* @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
|
||||
@@ -55,14 +53,14 @@ 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);
|
||||
|
||||
$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,
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
This files describes API changes in /backup/*,
|
||||
information provided here is intended especially for developers.
|
||||
|
||||
=== 3.11.7 ===
|
||||
|
||||
* The class core_backup\copy\copy in backup/util/ui/classes/copy.php has been deprecated, please use copy_helper
|
||||
from backup/util/helper/copy_helper.class.php instead.
|
||||
* The method set_copy() in backup/controller/base_controller.class.php has been deprecated, please use a restore
|
||||
controller for storing copy information instead.
|
||||
* The method get_copy() in backup/controller/base_controller.class.php has been deprecated, please use get_copy()
|
||||
from backup/controller/restore_controller.class.php instead.
|
||||
|
||||
=== 3.11.6 ===
|
||||
|
||||
* Backup UI labels now accept empty/whitespace-only contents.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -77,6 +77,7 @@ abstract class backup_cron_automated_helper {
|
||||
* First backup courses that do not have an entry in backup_courses first,
|
||||
* as they are likely new and never been backed up. Do the oldest modified courses first.
|
||||
* Then backup courses that have previously been backed up starting with the oldest next start time.
|
||||
* Finally, all else being equal, defer to the sortorder of the courses.
|
||||
*
|
||||
* @param null|int $now timestamp to use in course selection.
|
||||
* @return moodle_recordset The recordset of matching courses.
|
||||
@@ -93,7 +94,8 @@ abstract class backup_cron_automated_helper {
|
||||
LEFT JOIN {backup_courses} bc ON bc.courseid = c.id
|
||||
WHERE bc.nextstarttime IS NULL OR bc.nextstarttime < ?
|
||||
ORDER BY nextstarttime ASC,
|
||||
c.timemodified DESC';
|
||||
c.timemodified DESC,
|
||||
c.sortorder';
|
||||
|
||||
$params = array(
|
||||
$now, // Only get courses where the backup start time is in the past.
|
||||
|
||||
@@ -0,0 +1,310 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
|
||||
|
||||
/**
|
||||
* Copy helper class.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2022 Catalyst IT Australia Pty Ltd
|
||||
* @author Cameron Ball <cameron@cameron1729.xyz>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
final class copy_helper {
|
||||
|
||||
/**
|
||||
* Process raw form data from copy_form.
|
||||
*
|
||||
* @param \stdClass $formdata Raw formdata
|
||||
* @return \stdClass Processed data for use with create_copy
|
||||
*/
|
||||
public static function process_formdata(\stdClass $formdata): \stdClass {
|
||||
$requiredfields = [
|
||||
'courseid', // Course id integer.
|
||||
'fullname', // Fullname of the destination course.
|
||||
'shortname', // Shortname of the destination course.
|
||||
'category', // Category integer ID that contains the destination course.
|
||||
'visible', // Integer to detrmine of the copied course will be visible.
|
||||
'startdate', // Integer timestamp of the start of the destination course.
|
||||
'enddate', // Integer timestamp of the end of the destination course.
|
||||
'idnumber', // ID of the destination course.
|
||||
'userdata', // Integer to determine if the copied course will contain user data.
|
||||
];
|
||||
|
||||
$missingfields = array_diff($requiredfields, array_keys((array)$formdata));
|
||||
if ($missingfields) {
|
||||
throw new \moodle_exception('copyfieldnotfound', 'backup', '', null, implode(", ", $missingfields));
|
||||
}
|
||||
|
||||
// Remove any extra stuff in the form data.
|
||||
$processed = (object)array_intersect_key((array)$formdata, array_flip($requiredfields));
|
||||
$processed->keptroles = [];
|
||||
|
||||
// Extract roles from the form data and add to keptroles.
|
||||
foreach ($formdata as $key => $value) {
|
||||
if ((substr($key, 0, 5) === 'role_') && ($value != 0)) {
|
||||
$processed->keptroles[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $processed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a course copy.
|
||||
* Sets up relevant controllers and adhoc task.
|
||||
*
|
||||
* @param \stdClass $copydata Course copy data from process_formdata
|
||||
* @return array $copyids The backup and restore controller ids
|
||||
*/
|
||||
public static function create_copy(\stdClass $copydata): array {
|
||||
global $USER;
|
||||
$copyids = [];
|
||||
|
||||
// Create the initial backupcontoller.
|
||||
$bc = new \backup_controller(\backup::TYPE_1COURSE, $copydata->courseid, \backup::FORMAT_MOODLE,
|
||||
\backup::INTERACTIVE_NO, \backup::MODE_COPY, $USER->id, \backup::RELEASESESSION_YES);
|
||||
$copyids['backupid'] = $bc->get_backupid();
|
||||
|
||||
// Create the initial restore contoller.
|
||||
list($fullname, $shortname) = \restore_dbops::calculate_course_names(
|
||||
0, get_string('copyingcourse', 'backup'), get_string('copyingcourseshortname', 'backup'));
|
||||
$newcourseid = \restore_dbops::create_new_course($fullname, $shortname, $copydata->category);
|
||||
$rc = new \restore_controller($copyids['backupid'], $newcourseid, \backup::INTERACTIVE_NO,
|
||||
\backup::MODE_COPY, $USER->id, \backup::TARGET_NEW_COURSE, null,
|
||||
\backup::RELEASESESSION_NO, $copydata);
|
||||
$copyids['restoreid'] = $rc->get_restoreid();
|
||||
|
||||
$bc->set_status(\backup::STATUS_AWAITING);
|
||||
$bc->get_status();
|
||||
$rc->save_controller();
|
||||
|
||||
// Create the ad-hoc task to perform the course copy.
|
||||
$asynctask = new \core\task\asynchronous_copy_task();
|
||||
$asynctask->set_blocking(false);
|
||||
$asynctask->set_custom_data($copyids);
|
||||
\core\task\manager::queue_adhoc_task($asynctask);
|
||||
|
||||
// Clean up the controller.
|
||||
$bc->destroy();
|
||||
|
||||
return $copyids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the in progress course copy operations for a user.
|
||||
*
|
||||
* @param int $userid User id to get the course copies for.
|
||||
* @param int|null $courseid The optional source course id to get copies for.
|
||||
* @return array $copies Details of the inprogress copies.
|
||||
*/
|
||||
public static function get_copies(int $userid, ?int $courseid = null): array {
|
||||
global $DB;
|
||||
$copies = [];
|
||||
[$insql, $inparams] = $DB->get_in_or_equal([\backup::STATUS_FINISHED_OK, \backup::STATUS_FINISHED_ERR]);
|
||||
$params = [
|
||||
$userid,
|
||||
\backup::EXECUTION_DELAYED,
|
||||
\backup::MODE_COPY,
|
||||
\backup::OPERATION_BACKUP,
|
||||
\backup::STATUS_FINISHED_OK,
|
||||
\backup::OPERATION_RESTORE
|
||||
];
|
||||
|
||||
// We exclude backups that finished with OK. Therefore if a backup is missing,
|
||||
// we can assume it finished properly.
|
||||
//
|
||||
// We exclude both failed and successful restores because both of those indicate that the whole
|
||||
// operation has completed.
|
||||
$sql = 'SELECT backupid, itemid, operation, status, timecreated, purpose
|
||||
FROM {backup_controllers}
|
||||
WHERE userid = ?
|
||||
AND execution = ?
|
||||
AND purpose = ?
|
||||
AND ((operation = ? AND status <> ?) OR (operation = ? AND status NOT ' . $insql .'))
|
||||
ORDER BY timecreated DESC';
|
||||
|
||||
$copyrecords = $DB->get_records_sql($sql, array_merge($params, $inparams));
|
||||
$idtorc = self::map_backupids_to_restore_controller($copyrecords);
|
||||
|
||||
// Our SQL only gets controllers that have not finished successfully.
|
||||
// So, no restores => all restores have finished (either failed or OK) => all backups have too
|
||||
// Therefore there are no in progress copy operations, return early.
|
||||
if (empty($idtorc)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
foreach ($copyrecords as $copyrecord) {
|
||||
try {
|
||||
$isbackup = $copyrecord->operation == \backup::OPERATION_BACKUP;
|
||||
|
||||
// The mapping is guaranteed to exist for restore controllers, but not
|
||||
// backup controllers.
|
||||
//
|
||||
// When processing backups we don't actually need it, so we just coalesce
|
||||
// to null.
|
||||
$rc = $idtorc[$copyrecord->backupid] ?? null;
|
||||
|
||||
$cid = $isbackup ? $copyrecord->itemid : $rc->get_copy()->courseid;
|
||||
$course = get_course($cid);
|
||||
$copy = clone ($copyrecord);
|
||||
$copy->backupid = $isbackup ? $copyrecord->backupid : null;
|
||||
$copy->restoreid = $rc ? $rc->get_restoreid() : null;
|
||||
$copy->destination = $rc ? $rc->get_copy()->shortname : null;
|
||||
$copy->source = $course->shortname;
|
||||
$copy->sourceid = $course->id;
|
||||
} catch (\Exception $e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Filter out anything that's not relevant.
|
||||
if ($courseid) {
|
||||
if ($isbackup && $copyrecord->itemid != $courseid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$isbackup && $rc->get_copy()->courseid != $courseid) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// A backup here means that the associated restore controller has not started.
|
||||
//
|
||||
// There's a few situations to consider:
|
||||
//
|
||||
// 1. The backup is waiting or in progress
|
||||
// 2. The backup failed somehow
|
||||
// 3. Something went wrong (e.g., solar flare) and the backup controller saved, but the restore controller didn't
|
||||
// 4. The restore hasn't been created yet (race condition)
|
||||
//
|
||||
// In the case of 1, we add it to the return list. In the case of 2, 3 and 4 we just ignore it and move on.
|
||||
// The backup cleanup task will take care of updating/deleting invalid controllers.
|
||||
if ($isbackup) {
|
||||
if ($copyrecord->status != \backup::STATUS_FINISHED_ERR && !is_null($rc)) {
|
||||
$copies[] = $copy;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// A backup in copyrecords, indicates that the associated backup has not
|
||||
// successfully finished. We shouldn't do anything with this restore record.
|
||||
if ($copyrecords[$rc->get_tempdir()] ?? null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// This is a restore record, and the backup has finished. Return it.
|
||||
$copies[] = $copy;
|
||||
}
|
||||
|
||||
return $copies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a mapping between copy controller IDs and the restore controller.
|
||||
* For example if there exists a copy with backup ID abc and restore ID 123
|
||||
* then this mapping will map both keys abc and 123 to the same (instantiated)
|
||||
* restore controller.
|
||||
*
|
||||
* @param array $backuprecords An array of records from {backup_controllers}
|
||||
* @return array An array of mappings between backup ids and restore controllers
|
||||
*/
|
||||
private static function map_backupids_to_restore_controller(array $backuprecords): array {
|
||||
// Needed for PHP 7.3 - array_merge only accepts 0 parameters in PHP >= 7.4.
|
||||
if (empty($backuprecords)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_merge(
|
||||
...array_map(
|
||||
function (\stdClass $backuprecord): array {
|
||||
$iscopyrestore = $backuprecord->operation == \backup::OPERATION_RESTORE &&
|
||||
$backuprecord->purpose == \backup::MODE_COPY;
|
||||
$isfinished = $backuprecord->status == \backup::STATUS_FINISHED_OK;
|
||||
|
||||
if (!$iscopyrestore || $isfinished) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$rc = \restore_controller::load_controller($backuprecord->backupid);
|
||||
return [$backuprecord->backupid => $rc, $rc->get_tempdir() => $rc];
|
||||
},
|
||||
array_values($backuprecords)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects and deletes/fails controllers associated with a course copy that are
|
||||
* in an invalid state.
|
||||
*
|
||||
* @param array $backuprecords An array of records from {backup_controllers}
|
||||
* @param int $age How old a controller needs to be (in seconds) before its considered for cleaning
|
||||
* @return void
|
||||
*/
|
||||
public static function cleanup_orphaned_copy_controllers(array $backuprecords, int $age = MINSECS): void {
|
||||
global $DB;
|
||||
|
||||
$idtorc = self::map_backupids_to_restore_controller($backuprecords);
|
||||
|
||||
// Helpful to test if a backup exists in $backuprecords.
|
||||
$bidstorecord = array_combine(
|
||||
array_column($backuprecords, 'backupid'),
|
||||
$backuprecords
|
||||
);
|
||||
|
||||
foreach ($backuprecords as $record) {
|
||||
if ($record->purpose != \backup::MODE_COPY || $record->status == \backup::STATUS_FINISHED_OK) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$isbackup = $record->operation == \backup::OPERATION_BACKUP;
|
||||
$restoreexists = isset($idtorc[$record->backupid]);
|
||||
$nsecondsago = time() - $age;
|
||||
|
||||
if ($isbackup) {
|
||||
// Sometimes the backup controller gets created, ""something happens"" (like a solar flare)
|
||||
// and the restore controller (and hence adhoc task) don't.
|
||||
//
|
||||
// If more than one minute has passed and the restore controller doesn't exist, it's likely that
|
||||
// this backup controller is orphaned, so we should remove it as the adhoc task to process it will
|
||||
// never be created.
|
||||
if (!$restoreexists && $record->timecreated <= $nsecondsago) {
|
||||
// It would be better to mark the backup as failed by loading the controller
|
||||
// and marking it as failed with $bc->set_status(), but we can't: MDL-74711.
|
||||
//
|
||||
// Deleting it isn't ideal either as maybe we want to inspect the backup
|
||||
// for debugging. So manually updating the column seems to be the next best.
|
||||
$record->status = \backup::STATUS_FINISHED_ERR;
|
||||
$DB->update_record('backup_controllers', $record);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($rc = $idtorc[$record->backupid] ?? null) {
|
||||
$backuprecord = $bidstorecord[$rc->get_tempdir()] ?? null;
|
||||
|
||||
// Check the status of the associated backup. If it's failed, then mark this
|
||||
// restore as failed too.
|
||||
if ($backuprecord && $backuprecord->status == \backup::STATUS_FINISHED_ERR) {
|
||||
$rc->set_status(\backup::STATUS_FINISHED_ERR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 <mattp@catalyst-au.net>
|
||||
* @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 <mattp@catalyst-au.net>
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 <mattp@catalyst-au.net>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_backup;
|
||||
|
||||
use backup;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
@@ -36,8 +32,9 @@ require_once($CFG->libdir . '/completionlib.php');
|
||||
* @copyright 2020 onward The Moodle Users Association <https://moodleassociation.org/>
|
||||
* @author Matt Porritt <mattp@catalyst-au.net>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \copy_helper
|
||||
*/
|
||||
class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
class copy_helper_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -88,7 +85,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.
|
||||
@@ -147,8 +144,150 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
$CFG->backup_file_logger_level_extra = backup::LOG_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test process form data with invalid data.
|
||||
*
|
||||
* @covers ::process_formdata
|
||||
*/
|
||||
public function test_process_formdata_missing_fields() {
|
||||
$this->expectException(\moodle_exception::class);
|
||||
\copy_helper::process_formdata(new \stdClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test processing form data.
|
||||
*
|
||||
* @covers ::process_formdata
|
||||
*/
|
||||
public function test_process_formdata() {
|
||||
$validformdata = [
|
||||
'courseid' => 1729,
|
||||
'fullname' => 'Taxicab Numbers',
|
||||
'shortname' => 'Taxi101',
|
||||
'category' => 2,
|
||||
'visible' => 1,
|
||||
'startdate' => 87539319,
|
||||
'enddate' => 6963472309248,
|
||||
'idnumber' => 1730,
|
||||
'userdata' => 1
|
||||
];
|
||||
|
||||
$roles = [
|
||||
'role_one' => 1,
|
||||
'role_two' => 2,
|
||||
'role_three' => 0
|
||||
];
|
||||
|
||||
$expected = (object)array_merge($validformdata, ['keptroles' => []]);
|
||||
$expected->keptroles = [1, 2];
|
||||
$processed = \copy_helper::process_formdata(
|
||||
(object)array_merge(
|
||||
$validformdata,
|
||||
$roles,
|
||||
['extra' => 'stuff', 'remove' => 'this'])
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $processed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test orphaned controller cleanup.
|
||||
*
|
||||
* @covers ::cleanup_orphaned_copy_controllers
|
||||
*/
|
||||
public function test_cleanup_orphaned_copy_controllers() {
|
||||
global $DB;
|
||||
|
||||
// Mock up the form data.
|
||||
$formdata = new \stdClass;
|
||||
$formdata->courseid = $this->course->id;
|
||||
$formdata->fullname = 'foo';
|
||||
$formdata->shortname = 'data1';
|
||||
$formdata->category = 1;
|
||||
$formdata->visible = 1;
|
||||
$formdata->startdate = 1582376400;
|
||||
$formdata->enddate = 0;
|
||||
$formdata->idnumber = 123;
|
||||
$formdata->userdata = 1;
|
||||
$formdata->role_1 = 1;
|
||||
$formdata->role_3 = 3;
|
||||
$formdata->role_5 = 5;
|
||||
|
||||
$copies = [];
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$formdata->shortname = 'data' . $i;
|
||||
$copies[] = \copy_helper::create_copy($formdata);
|
||||
}
|
||||
|
||||
// Delete one of the restore controllers. Simulates a situation where copy creation
|
||||
// interrupted and the restore controller never gets created.
|
||||
$DB->delete_records('backup_controllers', ['backupid' => $copies[0]['restoreid']]);
|
||||
|
||||
// Set a backup/restore controller pair to be in an intermediate state.
|
||||
\backup_controller::load_controller($copies[2]['backupid'])->set_status(backup::STATUS_FINISHED_OK);
|
||||
|
||||
// Set a backup/restore controller pair to completed.
|
||||
\backup_controller::load_controller($copies[3]['backupid'])->set_status(backup::STATUS_FINISHED_OK);
|
||||
\restore_controller::load_controller($copies[3]['restoreid'])->set_status(backup::STATUS_FINISHED_OK);
|
||||
|
||||
// Set a backup/restore controller pair to have a failed backup.
|
||||
\backup_controller::load_controller($copies[4]['backupid'])->set_status(backup::STATUS_FINISHED_ERR);
|
||||
|
||||
// Create some backup/restore controllers that are unrelated to course copies.
|
||||
$bc = new \backup_controller(backup::TYPE_1COURSE, 1, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_ASYNC,
|
||||
2, backup::RELEASESESSION_YES);
|
||||
$rc = new \restore_controller('restore-test-1729', 1, backup::INTERACTIVE_NO, backup::MODE_ASYNC, 1, 2);
|
||||
$rc->save_controller();
|
||||
$unrelatedvanillacontrollers = ['backupid' => $bc->get_backupid(), 'restoreid' => $rc->get_restoreid()];
|
||||
|
||||
$bc = new \backup_controller(backup::TYPE_1COURSE, 1, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_ASYNC,
|
||||
2, backup::RELEASESESSION_YES);
|
||||
$rc = new \restore_controller('restore-test-1729', 1, backup::INTERACTIVE_NO, backup::MODE_ASYNC, 1, 2);
|
||||
$bc->set_status(backup::STATUS_FINISHED_OK);
|
||||
$rc->set_status(backup::STATUS_FINISHED_OK);
|
||||
$unrelatedfinishedcontrollers = ['backupid' => $bc->get_backupid(), 'restoreid' => $rc->get_restoreid()];
|
||||
|
||||
$bc = new \backup_controller(backup::TYPE_1COURSE, 1, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_ASYNC,
|
||||
2, backup::RELEASESESSION_YES);
|
||||
$rc = new \restore_controller('restore-test-1729', 1, backup::INTERACTIVE_NO, backup::MODE_ASYNC, 1, 2);
|
||||
$bc->set_status(backup::STATUS_FINISHED_ERR);
|
||||
$rc->set_status(backup::STATUS_FINISHED_ERR);
|
||||
$unrelatedfailedcontrollers = ['backupid' => $bc->get_backupid(), 'restoreid' => $rc->get_restoreid()];
|
||||
|
||||
// Clean up the backup_controllers table.
|
||||
$records = $DB->get_records('backup_controllers', null, '', 'id, backupid, status, operation, purpose, timecreated');
|
||||
\copy_helper::cleanup_orphaned_copy_controllers($records, 0);
|
||||
|
||||
// Retrieve them again and check.
|
||||
$records = $DB->get_records('backup_controllers', null, '', 'backupid, status');
|
||||
|
||||
// Verify the backup associated with the deleted restore is marked as failed.
|
||||
$this->assertEquals(backup::STATUS_FINISHED_ERR, $records[$copies[0]['backupid']]->status);
|
||||
|
||||
// Verify other controllers remain untouched.
|
||||
$this->assertEquals(backup::STATUS_AWAITING, $records[$copies[1]['backupid']]->status);
|
||||
$this->assertEquals(backup::STATUS_REQUIRE_CONV, $records[$copies[1]['restoreid']]->status);
|
||||
$this->assertEquals(backup::STATUS_FINISHED_OK, $records[$copies[2]['backupid']]->status);
|
||||
$this->assertEquals(backup::STATUS_REQUIRE_CONV, $records[$copies[2]['restoreid']]->status);
|
||||
$this->assertEquals(backup::STATUS_FINISHED_OK, $records[$copies[3]['restoreid']]->status);
|
||||
$this->assertEquals(backup::STATUS_FINISHED_OK, $records[$copies[3]['backupid']]->status);
|
||||
|
||||
// Verify that the restore associated with the failed backup is also marked as failed.
|
||||
$this->assertEquals(backup::STATUS_FINISHED_ERR, $records[$copies[4]['restoreid']]->status);
|
||||
|
||||
// Verify that the unrelated controllers remain unchanged.
|
||||
$this->assertEquals(backup::STATUS_AWAITING, $records[$unrelatedvanillacontrollers['backupid']]->status);
|
||||
$this->assertEquals(backup::STATUS_REQUIRE_CONV, $records[$unrelatedvanillacontrollers['restoreid']]->status);
|
||||
$this->assertEquals(backup::STATUS_FINISHED_OK, $records[$unrelatedfinishedcontrollers['backupid']]->status);
|
||||
$this->assertEquals(backup::STATUS_FINISHED_OK, $records[$unrelatedfinishedcontrollers['restoreid']]->status);
|
||||
$this->assertEquals(backup::STATUS_FINISHED_ERR, $records[$unrelatedfailedcontrollers['backupid']]->status);
|
||||
$this->assertEquals(backup::STATUS_FINISHED_ERR, $records[$unrelatedfailedcontrollers['restoreid']]->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creating a course copy.
|
||||
*
|
||||
* @covers ::create_copy
|
||||
*/
|
||||
public function test_create_copy() {
|
||||
|
||||
@@ -167,15 +306,14 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
$formdata->role_3 = 3;
|
||||
$formdata->role_5 = 5;
|
||||
|
||||
$coursecopy = new \core_backup\copy\copy($formdata);
|
||||
$result = $coursecopy->create_copy();
|
||||
$copydata = \copy_helper::process_formdata($formdata);
|
||||
$result = \copy_helper::create_copy($copydata);
|
||||
|
||||
// Load the controllers, to extract the data we need.
|
||||
$bc = \backup_controller::load_controller($result['backupid']);
|
||||
$rc = \restore_controller::load_controller($result['restoreid']);
|
||||
|
||||
// Check the backup controller.
|
||||
$this->assertEquals($result, $bc->get_copy()->copyids);
|
||||
$this->assertEquals(backup::MODE_COPY, $bc->get_mode());
|
||||
$this->assertEquals($this->course->id, $bc->get_courseid());
|
||||
$this->assertEquals(backup::TYPE_1COURSE, $bc->get_type());
|
||||
@@ -184,7 +322,6 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
$newcourseid = $rc->get_courseid();
|
||||
$newcourse = get_course($newcourseid);
|
||||
|
||||
$this->assertEquals($result, $rc->get_copy()->copyids);
|
||||
$this->assertEquals(get_string('copyingcourse', 'backup'), $newcourse->fullname);
|
||||
$this->assertEquals(get_string('copyingcourseshortname', 'backup'), $newcourse->shortname);
|
||||
$this->assertEquals(backup::MODE_COPY, $rc->get_mode());
|
||||
@@ -203,6 +340,8 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test getting the current copies.
|
||||
*
|
||||
* @covers ::get_copies
|
||||
*/
|
||||
public function test_get_copies() {
|
||||
global $USER;
|
||||
@@ -226,11 +365,11 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
$formdata2->shortname = 'tree';
|
||||
|
||||
// Create some copies.
|
||||
$coursecopy = new \core_backup\copy\copy($formdata);
|
||||
$result = $coursecopy->create_copy();
|
||||
$copydata = \copy_helper::process_formdata($formdata);
|
||||
$result = \copy_helper::create_copy($copydata);
|
||||
|
||||
// Backup, awaiting.
|
||||
$copies = \core_backup\copy\copy::get_copies($USER->id);
|
||||
$copies = \copy_helper::get_copies($USER->id);
|
||||
$this->assertEquals($result['backupid'], $copies[0]->backupid);
|
||||
$this->assertEquals($result['restoreid'], $copies[0]->restoreid);
|
||||
$this->assertEquals(\backup::STATUS_AWAITING, $copies[0]->status);
|
||||
@@ -240,7 +379,7 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
|
||||
// Backup, in progress.
|
||||
$bc->set_status(\backup::STATUS_EXECUTING);
|
||||
$copies = \core_backup\copy\copy::get_copies($USER->id);
|
||||
$copies = \copy_helper::get_copies($USER->id);
|
||||
$this->assertEquals($result['backupid'], $copies[0]->backupid);
|
||||
$this->assertEquals($result['restoreid'], $copies[0]->restoreid);
|
||||
$this->assertEquals(\backup::STATUS_EXECUTING, $copies[0]->status);
|
||||
@@ -248,19 +387,19 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
|
||||
// Restore, ready to process.
|
||||
$bc->set_status(\backup::STATUS_FINISHED_OK);
|
||||
$copies = \core_backup\copy\copy::get_copies($USER->id);
|
||||
$this->assertEquals($result['backupid'], $copies[0]->backupid);
|
||||
$copies = \copy_helper::get_copies($USER->id);
|
||||
$this->assertEquals(null, $copies[0]->backupid);
|
||||
$this->assertEquals($result['restoreid'], $copies[0]->restoreid);
|
||||
$this->assertEquals(\backup::STATUS_REQUIRE_CONV, $copies[0]->status);
|
||||
$this->assertEquals(\backup::OPERATION_RESTORE, $copies[0]->operation);
|
||||
|
||||
// No records.
|
||||
$bc->set_status(\backup::STATUS_FINISHED_ERR);
|
||||
$copies = \core_backup\copy\copy::get_copies($USER->id);
|
||||
$copies = \copy_helper::get_copies($USER->id);
|
||||
$this->assertEmpty($copies);
|
||||
|
||||
$coursecopy2 = new \core_backup\copy\copy($formdata2);
|
||||
$result2 = $coursecopy2->create_copy();
|
||||
$copydata2 = \copy_helper::process_formdata($formdata2);
|
||||
$result2 = \copy_helper::create_copy($copydata2);
|
||||
// Set the second copy to be complete.
|
||||
$bc = \backup_controller::load_controller($result2['backupid']);
|
||||
$bc->set_status(\backup::STATUS_FINISHED_OK);
|
||||
@@ -269,12 +408,73 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
$rc->set_status(\backup::STATUS_FINISHED_OK);
|
||||
|
||||
// No records.
|
||||
$copies = \core_backup\copy\copy::get_copies($USER->id);
|
||||
$copies = \copy_helper::get_copies($USER->id);
|
||||
$this->assertEmpty($copies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting the current copies when they are in an invalid state.
|
||||
*
|
||||
* @covers ::get_copies
|
||||
*/
|
||||
public function test_get_copies_invalid_state() {
|
||||
global $DB, $USER;
|
||||
|
||||
// Mock up the form data.
|
||||
$formdata = new \stdClass;
|
||||
$formdata->courseid = $this->course->id;
|
||||
$formdata->fullname = 'foo';
|
||||
$formdata->shortname = 'bar';
|
||||
$formdata->category = 1;
|
||||
$formdata->visible = 1;
|
||||
$formdata->startdate = 1582376400;
|
||||
$formdata->enddate = 0;
|
||||
$formdata->idnumber = '';
|
||||
$formdata->userdata = 1;
|
||||
$formdata->role_1 = 1;
|
||||
$formdata->role_3 = 3;
|
||||
$formdata->role_5 = 5;
|
||||
|
||||
$formdata2 = clone ($formdata);
|
||||
$formdata2->shortname = 'tree';
|
||||
|
||||
// Create some copies.
|
||||
$copydata = \copy_helper::process_formdata($formdata);
|
||||
$result = \copy_helper::create_copy($copydata);
|
||||
$copydata2 = \copy_helper::process_formdata($formdata2);
|
||||
$result2 = \copy_helper::create_copy($copydata2);
|
||||
|
||||
$copies = \copy_helper::get_copies($USER->id);
|
||||
|
||||
// Verify get_copies gives back both backup controllers.
|
||||
$this->assertEqualsCanonicalizing([$result['backupid'], $result2['backupid']], array_column($copies, 'backupid'));
|
||||
|
||||
// Set one of the backup controllers to failed, this should cause it to not be present.
|
||||
\backup_controller::load_controller($result['backupid'])->set_status(backup::STATUS_FINISHED_ERR);
|
||||
$copies = \copy_helper::get_copies($USER->id);
|
||||
|
||||
// Verify there is only one backup listed, and that it is not the failed one.
|
||||
$this->assertEqualsCanonicalizing([$result2['backupid']], array_column($copies, 'backupid'));
|
||||
|
||||
// Set the controller back to awaiting.
|
||||
\backup_controller::load_controller($result['backupid'])->set_status(backup::STATUS_AWAITING);
|
||||
$copies = \copy_helper::get_copies($USER->id);
|
||||
|
||||
// Verify both backup controllers are back.
|
||||
$this->assertEqualsCanonicalizing([$result['backupid'], $result2['backupid']], array_column($copies, 'backupid'));
|
||||
|
||||
// Delete the restore controller for one of the copies, this should cause it to not be present.
|
||||
$DB->delete_records('backup_controllers', ['backupid' => $result['restoreid']]);
|
||||
$copies = \copy_helper::get_copies($USER->id);
|
||||
|
||||
// Verify there is only one backup listed, and that it is not the failed one.
|
||||
$this->assertEqualsCanonicalizing([$result2['backupid']], array_column($copies, 'backupid'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting the current copies for specific course.
|
||||
*
|
||||
* @covers ::get_copies
|
||||
*/
|
||||
public function test_get_copies_course() {
|
||||
global $USER;
|
||||
@@ -295,16 +495,18 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
$formdata->role_5 = 5;
|
||||
|
||||
// Create some copies.
|
||||
$coursecopy = new \core_backup\copy\copy($formdata);
|
||||
$coursecopy->create_copy();
|
||||
$copydata = \copy_helper::process_formdata($formdata);
|
||||
\copy_helper::create_copy($copydata);
|
||||
|
||||
// No copies match this course id.
|
||||
$copies = \core_backup\copy\copy::get_copies($USER->id, ($this->course->id + 1));
|
||||
$copies = \copy_helper::get_copies($USER->id, ($this->course->id + 1));
|
||||
$this->assertEmpty($copies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting the current copies if course has been deleted.
|
||||
*
|
||||
* @covers ::get_copies
|
||||
*/
|
||||
public function test_get_copies_course_deleted() {
|
||||
global $USER;
|
||||
@@ -325,17 +527,17 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
$formdata->role_5 = 5;
|
||||
|
||||
// Create some copies.
|
||||
$coursecopy = new \core_backup\copy\copy($formdata);
|
||||
$coursecopy->create_copy();
|
||||
$copydata = \copy_helper::process_formdata($formdata);
|
||||
\copy_helper::create_copy($copydata);
|
||||
|
||||
delete_course($this->course->id, false);
|
||||
|
||||
// No copies match this course id as it has been deleted.
|
||||
$copies = \core_backup\copy\copy::get_copies($USER->id, ($this->course->id));
|
||||
$copies = \copy_helper::get_copies($USER->id, ($this->course->id));
|
||||
$this->assertEmpty($copies);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Test course copy.
|
||||
*/
|
||||
public function test_course_copy() {
|
||||
@@ -357,8 +559,8 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
$formdata->role_5 = 5;
|
||||
|
||||
// Create the course copy records and associated ad-hoc task.
|
||||
$coursecopy = new \core_backup\copy\copy($formdata);
|
||||
$copyids = $coursecopy->create_copy();
|
||||
$copydata = \copy_helper::process_formdata($formdata);
|
||||
$copyids = \copy_helper::create_copy($copydata);
|
||||
|
||||
$courseid = $this->course->id;
|
||||
|
||||
@@ -384,7 +586,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);
|
||||
@@ -412,7 +614,7 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
$this->assertEquals(2, count($discussions));
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Test course copy, not including any users (or data).
|
||||
*/
|
||||
public function test_course_copy_no_users() {
|
||||
@@ -434,8 +636,8 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
$formdata->role_5 = 0;
|
||||
|
||||
// Create the course copy records and associated ad-hoc task.
|
||||
$coursecopy = new \core_backup\copy\copy($formdata);
|
||||
$copyids = $coursecopy->create_copy();
|
||||
$copydata = \copy_helper::process_formdata($formdata);
|
||||
$copyids = \copy_helper::create_copy($copydata);
|
||||
|
||||
$courseid = $this->course->id;
|
||||
|
||||
@@ -452,7 +654,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);
|
||||
@@ -481,7 +683,7 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Test course copy, including students and their data.
|
||||
*/
|
||||
public function test_course_copy_students_data() {
|
||||
@@ -503,8 +705,8 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
$formdata->role_5 = 5;
|
||||
|
||||
// Create the course copy records and associated ad-hoc task.
|
||||
$coursecopy = new \core_backup\copy\copy($formdata);
|
||||
$copyids = $coursecopy->create_copy();
|
||||
$copydata = \copy_helper::process_formdata($formdata);
|
||||
$copyids = \copy_helper::create_copy($copydata);
|
||||
|
||||
$courseid = $this->course->id;
|
||||
|
||||
@@ -521,7 +723,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);
|
||||
@@ -550,7 +752,7 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
$this->assertEquals($this->courseusers[0], $users[$this->courseusers[0]]->id);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Test course copy, not including any users (or data).
|
||||
*/
|
||||
public function test_course_copy_no_data() {
|
||||
@@ -572,8 +774,8 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
$formdata->role_5 = 5;
|
||||
|
||||
// Create the course copy records and associated ad-hoc task.
|
||||
$coursecopy = new \core_backup\copy\copy($formdata);
|
||||
$copyids = $coursecopy->create_copy();
|
||||
$copydata = \copy_helper::process_formdata($formdata);
|
||||
$copyids = \copy_helper::create_copy($copydata);
|
||||
|
||||
$courseid = $this->course->id;
|
||||
|
||||
@@ -590,7 +792,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);
|
||||
@@ -618,7 +820,7 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
$this->assertEquals(count($this->courseusers), count($users));
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Test instantiation with incomplete formdata.
|
||||
*/
|
||||
public function test_malformed_instantiation() {
|
||||
@@ -631,6 +833,7 @@ class core_backup_course_copy_testcase extends advanced_testcase {
|
||||
|
||||
// Expect and exception as form data is incomplete.
|
||||
$this->expectException(\moodle_exception::class);
|
||||
new \core_backup\copy\copy($formdata);
|
||||
$copydata = \copy_helper::process_formdata($formdata);
|
||||
\copy_helper::create_copy($copydata);
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,16 @@
|
||||
* Unit tests for backups cron helper.
|
||||
*
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @category test
|
||||
* @copyright 2012 Frédéric Massart <fred@moodle.com>
|
||||
* @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 <fred@moodle.com>
|
||||
* @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;
|
||||
$backupcourse3->nextstarttime = 1554822160;
|
||||
$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;
|
||||
|
||||