| Línea 25... |
Línea 25... |
| 25 |
* @covers \tool_uploadcourse_course
|
25 |
* @covers \tool_uploadcourse_course
|
| 26 |
* @package tool_uploadcourse
|
26 |
* @package tool_uploadcourse
|
| 27 |
* @copyright 2013 Frédéric Massart
|
27 |
* @copyright 2013 Frédéric Massart
|
| 28 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late
|
28 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late
|
| 29 |
*/
|
29 |
*/
|
| 30 |
class course_test extends \advanced_testcase {
|
30 |
final class course_test extends \advanced_testcase {
|
| Línea 31... |
Línea 31... |
| 31 |
|
31 |
|
| 32 |
/** @var \testing_data_generator $datagenerator */
|
32 |
/** @var \testing_data_generator $datagenerator */
|
| 33 |
protected $datagenerator;
|
33 |
protected $datagenerator;
|
| 34 |
/** @var \stdClass $user */
|
34 |
/** @var \stdClass $user */
|
| Línea 965... |
Línea 965... |
| 965 |
$c1f1 = $this->getDataGenerator()->create_module('forum', array('course' => $c1->id));
|
965 |
$c1f1 = $this->getDataGenerator()->create_module('forum', array('course' => $c1->id));
|
| Línea 966... |
Línea 966... |
| 966 |
|
966 |
|
| 967 |
// Restore from a file, checking that the file takes priority over the templatecourse.
|
967 |
// Restore from a file, checking that the file takes priority over the templatecourse.
|
| 968 |
$mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
|
968 |
$mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
|
| - |
|
969 |
$updatemode = tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY;
|
| - |
|
970 |
$data = [
|
| 969 |
$updatemode = tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY;
|
971 |
'shortname' => 'A1',
|
| - |
|
972 |
'backupfile' => self::get_fixture_path(__NAMESPACE__, 'backup.mbz'),
|
| - |
|
973 |
'summary' => 'A',
|
| - |
|
974 |
'category' => 1,
|
| 970 |
$data = array('shortname' => 'A1', 'backupfile' => __DIR__ . '/fixtures/backup.mbz',
|
975 |
'fullname' => 'A1',
|
| - |
|
976 |
'templatecourse' => $c1->shortname,
|
| 971 |
'summary' => 'A', 'category' => 1, 'fullname' => 'A1', 'templatecourse' => $c1->shortname);
|
977 |
];
|
| 972 |
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
|
978 |
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
|
| 973 |
$this->assertTrue($co->prepare());
|
979 |
$this->assertTrue($co->prepare());
|
| 974 |
$co->proceed();
|
980 |
$co->proceed();
|
| 975 |
$course = $DB->get_record('course', array('shortname' => 'A1'));
|
981 |
$course = $DB->get_record('course', array('shortname' => 'A1'));
|
| Línea 984... |
Línea 990... |
| 984 |
}
|
990 |
}
|
| 985 |
}
|
991 |
}
|
| 986 |
$this->assertTrue($found);
|
992 |
$this->assertTrue($found);
|
| Línea 987... |
Línea 993... |
| 987 |
|
993 |
|
| - |
|
994 |
// Restoring twice from the same file should work.
|
| - |
|
995 |
$data = [
|
| 988 |
// Restoring twice from the same file should work.
|
996 |
'shortname' => 'B1',
|
| - |
|
997 |
'backupfile' => self::get_fixture_path(__NAMESPACE__, 'backup.mbz'),
|
| - |
|
998 |
'summary' => 'B',
|
| 989 |
$data = array('shortname' => 'B1', 'backupfile' => __DIR__ . '/fixtures/backup.mbz',
|
999 |
'category' => 1,
|
| - |
|
1000 |
'fullname' => 'B1',
|
| 990 |
'summary' => 'B', 'category' => 1, 'fullname' => 'B1');
|
1001 |
];
|
| 991 |
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
|
1002 |
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
|
| 992 |
$this->assertTrue($co->prepare());
|
1003 |
$this->assertTrue($co->prepare());
|
| 993 |
$co->proceed();
|
1004 |
$co->proceed();
|
| 994 |
$course = $DB->get_record('course', array('shortname' => 'B1'));
|
1005 |
$course = $DB->get_record('course', array('shortname' => 'B1'));
|
| Línea 1018... |
Línea 1029... |
| 1018 |
|
1029 |
|
| Línea 1019... |
Línea 1030... |
| 1019 |
$c1 = $this->getDataGenerator()->create_course();
|
1030 |
$c1 = $this->getDataGenerator()->create_course();
|
| 1020 |
|
1031 |
|
| - |
|
1032 |
$mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
|
| - |
|
1033 |
$updatemode = tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY;
|
| 1021 |
$mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
|
1034 |
$data = [
|
| - |
|
1035 |
'shortname' => 'A1',
|
| - |
|
1036 |
'backupfile' => self::get_fixture_path(__NAMESPACE__, 'backup.mbz'),
|
| - |
|
1037 |
'summary' => 'A',
|
| 1022 |
$updatemode = tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY;
|
1038 |
'category' => 1,
|
| - |
|
1039 |
'fullname' => 'A1',
|
| 1023 |
$data = array('shortname' => 'A1', 'backupfile' => __DIR__ . '/fixtures/backup.mbz',
|
1040 |
'templatecourse' => $c1->shortname,
|
| 1024 |
'summary' => 'A', 'category' => 1, 'fullname' => 'A1', 'templatecourse' => $c1->shortname);
|
1041 |
];
|
| 1025 |
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
|
1042 |
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
|
| 1026 |
$this->assertTrue($co->prepare());
|
1043 |
$this->assertTrue($co->prepare());
|
| Línea 1257... |
Línea 1274... |
| 1257 |
/**
|
1274 |
/**
|
| 1258 |
* Data provider for testing enrolment errors
|
1275 |
* Data provider for testing enrolment errors
|
| 1259 |
*
|
1276 |
*
|
| 1260 |
* @return array
|
1277 |
* @return array
|
| 1261 |
*/
|
1278 |
*/
|
| 1262 |
public function enrolment_uploaddata_error_provider(): array {
|
1279 |
public static function enrolment_uploaddata_error_provider(): array {
|
| 1263 |
return [
|
1280 |
return [
|
| 1264 |
['errorcannotcreateorupdateenrolment', [
|
1281 |
['errorcannotcreateorupdateenrolment', [
|
| 1265 |
'shortname' => 'C1',
|
1282 |
'shortname' => 'C1',
|
| 1266 |
'enrolment_1' => 'manual',
|
1283 |
'enrolment_1' => 'manual',
|
| 1267 |
]],
|
1284 |
]],
|
| Línea 1485... |
Línea 1502... |
| 1485 |
$course = $this->getDataGenerator()->create_course(['shortname' => 'C1']);
|
1502 |
$course = $this->getDataGenerator()->create_course(['shortname' => 'C1']);
|
| Línea 1486... |
Línea 1503... |
| 1486 |
|
1503 |
|
| 1487 |
// Create our custom field.
|
1504 |
// Create our custom field.
|
| 1488 |
$category = $this->get_customfield_generator()->create_category();
|
1505 |
$category = $this->get_customfield_generator()->create_category();
|
| 1489 |
$this->create_custom_field($category, 'date', 'mydate',
|
1506 |
$this->create_custom_field($category, 'date', 'mydate',
|
| Línea 1490... |
Línea 1507... |
| 1490 |
['mindate' => strtotime('2020-04-01'), 'maxdate' => '2020-04-30']);
|
1507 |
['mindate' => strtotime('2020-04-01'), 'maxdate' => strtotime('2020-04-30')]);
|
| 1491 |
|
1508 |
|
| 1492 |
$mode = tool_uploadcourse_processor::MODE_UPDATE_ONLY;
|
1509 |
$mode = tool_uploadcourse_processor::MODE_UPDATE_ONLY;
|
| 1493 |
$updatemode = tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY;
|
1510 |
$updatemode = tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY;
|