MDL-67673 phpunit: Remove expectedException annotations
While this is not strictly required, because removal will happen in PHPUnit 9.0, we are already getting rid of all uses in core. From release notes:https://phpunit.de/announcements/phpunit-8.html The annotations `@expectedException`, `@expectedExceptionCode`, `@expectedExceptionMessage`, and `@expectedExceptionMessageRegExp` are now deprecated. Using these annotations will trigger a deprecation warning in PHPUnit 8 and in PHPUnit 9 these annotations will be removed. Also, all uses of expectExceptionMessageRegExp() has been moved to expectExceptionMessageMatches(). See https://github.com/sebastianbergmann/phpunit/issues/3957 TODO: Various weirdness found while doing the changes with these tests: - vendor/bin/phpunit lib/tests/exporter_test.php (created MDL-69700) - vendor/bin/phpunit competency/tests/external_test.php (same issue than prev one) - vendor/bin/phpunit question/engine/tests/questionengine_test.php (created MDL-69624) - vendor/bin/phpunit lib/tests/event_test.php (created MDL-69688)
This commit is contained in:
@@ -66,8 +66,6 @@ class tool_analytics_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* test_potential_contexts description
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_potential_contexts_no_manager() {
|
||||
$this->resetAfterTest();
|
||||
@@ -75,6 +73,7 @@ class tool_analytics_external_testcase extends externallib_advanced_testcase {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
|
||||
$this->expectException(required_capability_exception::class);
|
||||
$this->assertCount(2, \tool_analytics\external::potential_contexts());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,9 +60,6 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
|
||||
cohort_add_member($this->cohort->id, $this->userassignover->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_create_cohort_role_assignment_without_permission() {
|
||||
$this->setUser($this->userassignto);
|
||||
$params = (object) array(
|
||||
@@ -70,12 +67,10 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
|
||||
'roleid' => $this->roleid,
|
||||
'cohortid' => $this->cohort->id
|
||||
);
|
||||
$this->expectException(required_capability_exception::class);
|
||||
api::create_cohort_role_assignment($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException core_competency\invalid_persistent_exception
|
||||
*/
|
||||
public function test_create_cohort_role_assignment_with_invalid_data() {
|
||||
$this->setAdminUser();
|
||||
$params = (object) array(
|
||||
@@ -83,6 +78,7 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
|
||||
'roleid' => -8,
|
||||
'cohortid' => $this->cohort->id
|
||||
);
|
||||
$this->expectException(\core_competency\invalid_persistent_exception::class);
|
||||
api::create_cohort_role_assignment($params);
|
||||
}
|
||||
|
||||
@@ -100,9 +96,6 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
|
||||
$this->assertEquals($result->get('cohortid'), $this->cohort->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_delete_cohort_role_assignment_without_permission() {
|
||||
$this->setAdminUser();
|
||||
$params = (object) array(
|
||||
@@ -112,12 +105,10 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
|
||||
);
|
||||
$result = api::create_cohort_role_assignment($params);
|
||||
$this->setUser($this->userassignto);
|
||||
$this->expectException(required_capability_exception::class);
|
||||
api::delete_cohort_role_assignment($result->get('id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException dml_missing_record_exception
|
||||
*/
|
||||
public function test_delete_cohort_role_assignment_with_invalid_data() {
|
||||
$this->setAdminUser();
|
||||
$params = (object) array(
|
||||
@@ -126,6 +117,7 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
|
||||
'cohortid' => $this->cohort->id
|
||||
);
|
||||
$result = api::create_cohort_role_assignment($params);
|
||||
$this->expectException(dml_missing_record_exception::class);
|
||||
api::delete_cohort_role_assignment($result->get('id') + 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,12 +56,10 @@ class tool_langimport_events_testcase extends advanced_testcase {
|
||||
$this->assertEquals(context_system::instance(), $event->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'langcode' value must be set to a valid language code
|
||||
*/
|
||||
public function test_langpack_updated_validation() {
|
||||
|
||||
$this->expectException('coding_exception');
|
||||
$this->expectExceptionMessage("The 'langcode' value must be set to a valid language code");
|
||||
\tool_langimport\event\langpack_updated::event_with_langcode('broken langcode');
|
||||
}
|
||||
|
||||
@@ -78,12 +76,10 @@ class tool_langimport_events_testcase extends advanced_testcase {
|
||||
$this->assertEquals(context_system::instance(), $event->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'langcode' value must be set to a valid language code
|
||||
*/
|
||||
public function test_langpack_installed_validation() {
|
||||
|
||||
$this->expectException('coding_exception');
|
||||
$this->expectExceptionMessage("The 'langcode' value must be set to a valid language code");
|
||||
\tool_langimport\event\langpack_imported::event_with_langcode('broken langcode');
|
||||
}
|
||||
|
||||
@@ -100,12 +96,10 @@ class tool_langimport_events_testcase extends advanced_testcase {
|
||||
$this->assertEquals(context_system::instance(), $event->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'langcode' value must be set to a valid language code
|
||||
*/
|
||||
public function test_langpack_removed_validation() {
|
||||
|
||||
$this->expectException('coding_exception');
|
||||
$this->expectExceptionMessage("The 'langcode' value must be set to a valid language code");
|
||||
\tool_langimport\event\langpack_removed::event_with_langcode('broken langcode');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,10 @@ class tool_monitor_subscription_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for the magic __get method.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_magic_get() {
|
||||
$this->assertEquals(20, $this->subscription->courseid);
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->subscription->ruleid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,21 +35,16 @@ global $CFG;
|
||||
*/
|
||||
class tool_uploadcourse_course_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_proceed_without_prepare() {
|
||||
$this->resetAfterTest(true);
|
||||
$mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
|
||||
$updatemode = tool_uploadcourse_processor::UPDATE_NOTHING;
|
||||
$data = array();
|
||||
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
|
||||
$this->expectException(coding_exception::class);
|
||||
$co->proceed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_proceed_when_prepare_failed() {
|
||||
$this->resetAfterTest(true);
|
||||
$mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
|
||||
@@ -57,6 +52,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
|
||||
$data = array();
|
||||
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
|
||||
$this->assertFalse($co->prepare());
|
||||
$this->expectException(moodle_exception::class);
|
||||
$co->proceed();
|
||||
}
|
||||
|
||||
@@ -1504,4 +1500,4 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
|
||||
'configdata' => $configdata,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,9 +160,6 @@ class tool_uploadcourse_processor_testcase extends advanced_testcase {
|
||||
$this->assertEquals('ID123: Course 1', $c->shortname);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_empty_csv() {
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
@@ -174,12 +171,10 @@ class tool_uploadcourse_processor_testcase extends advanced_testcase {
|
||||
$cir->init();
|
||||
|
||||
$options = array('mode' => tool_uploadcourse_processor::MODE_CREATE_NEW);
|
||||
$this->expectException(moodle_exception::class);
|
||||
$p = new tool_uploadcourse_processor($cir, $options, array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_not_enough_columns() {
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
@@ -194,6 +189,7 @@ class tool_uploadcourse_processor_testcase extends advanced_testcase {
|
||||
$cir->init();
|
||||
|
||||
$options = array('mode' => tool_uploadcourse_processor::MODE_CREATE_NEW);
|
||||
$this->expectException(moodle_exception::class);
|
||||
$p = new tool_uploadcourse_processor($cir, $options, array());
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,6 @@ class analytics_indicator_testcase extends advanced_testcase {
|
||||
* @param string $indicatorclass
|
||||
* @param string $willreturn
|
||||
* @dataProvider validate_calculated_value_exceptions
|
||||
* @expectedException \coding_exception
|
||||
* @return null
|
||||
*/
|
||||
public function test_validate_calculated_value_exceptions($indicatorclass, $willreturn) {
|
||||
@@ -80,6 +79,7 @@ class analytics_indicator_testcase extends advanced_testcase {
|
||||
->setMethods(['calculate_sample'])
|
||||
->getMock();
|
||||
$indicatormock->method('calculate_sample')->willReturn($willreturn);
|
||||
$this->expectException(coding_exception::class);
|
||||
list($values, $unused) = $indicatormock->calculate([1], 'notrelevanthere');
|
||||
|
||||
}
|
||||
|
||||
@@ -92,17 +92,12 @@ class core_backup_moodle1_converter_testcase extends advanced_testcase {
|
||||
$this->assertInstanceOf('moodle1_converter', $converter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle1_convert_storage_exception
|
||||
*/
|
||||
public function test_stash_storage_not_created() {
|
||||
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
|
||||
$this->expectException(moodle1_convert_storage_exception::class);
|
||||
$converter->set_stash('tempinfo', 12);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle1_convert_empty_storage_exception
|
||||
*/
|
||||
public function test_stash_requiring_empty_stash() {
|
||||
$this->resetAfterTest(true);
|
||||
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
|
||||
@@ -113,6 +108,7 @@ class core_backup_moodle1_converter_testcase extends advanced_testcase {
|
||||
|
||||
} catch (moodle1_convert_empty_storage_exception $e) {
|
||||
// we must drop the storage here so we are able to re-create it in the next test
|
||||
$this->expectException(moodle1_convert_empty_storage_exception::class);
|
||||
$converter->drop_stash_storage();
|
||||
throw new moodle1_convert_empty_storage_exception('rethrowing');
|
||||
}
|
||||
@@ -440,9 +436,6 @@ class core_backup_moodle1_converter_testcase extends advanced_testcase {
|
||||
$this->assertSame(null, $data['nothing']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException convert_path_exception
|
||||
*/
|
||||
public function test_grouped_data_on_nongrouped_convert_path() {
|
||||
// prepare some grouped data
|
||||
$data = array(
|
||||
@@ -468,12 +461,10 @@ class core_backup_moodle1_converter_testcase extends advanced_testcase {
|
||||
$path = new convert_path('beer_style', '/ROOT/BEER_STYLES/BEER_STYLE');
|
||||
|
||||
// an attempt to apply recipes throws exception because we do not expect grouped data
|
||||
$this->expectException(convert_path_exception::class);
|
||||
$data = $path->apply_recipes($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException convert_path_exception
|
||||
*/
|
||||
public function test_grouped_convert_path_with_recipes() {
|
||||
// prepare some grouped data
|
||||
$data = array(
|
||||
@@ -501,6 +492,7 @@ class core_backup_moodle1_converter_testcase extends advanced_testcase {
|
||||
$this->assertEquals('Heineken', $data['beers'][1]['beer']['name']);
|
||||
|
||||
// an attempt to provide explicit recipes on grouped elements throws exception
|
||||
$this->expectException(convert_path_exception::class);
|
||||
$path = new convert_path(
|
||||
'beer_style', '/ROOT/BEER_STYLES/BEER_STYLE',
|
||||
array(
|
||||
|
||||
@@ -157,8 +157,6 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test delete_calendar_events
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_delete_calendar_events() {
|
||||
global $DB, $USER;
|
||||
@@ -282,6 +280,7 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase {
|
||||
array('eventid' => $userevent->id, 'repeat' => 0),
|
||||
array('eventid' => $groupevent->id, 'repeat' => 0)
|
||||
);
|
||||
$this->expectException(moodle_exception::class);
|
||||
core_calendar_external::delete_calendar_events($events);
|
||||
}
|
||||
|
||||
|
||||
@@ -65,10 +65,6 @@ class core_cohort_cohortlib_testcase extends advanced_testcase {
|
||||
$this->assertSame($newcohort->timecreated, $newcohort->timemodified);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Missing cohort name in cohort_add_cohort().
|
||||
*/
|
||||
public function test_cohort_add_cohort_missing_name() {
|
||||
$cohort = new stdClass();
|
||||
$cohort->contextid = context_system::instance()->id;
|
||||
@@ -77,6 +73,8 @@ class core_cohort_cohortlib_testcase extends advanced_testcase {
|
||||
$cohort->description = 'test cohort desc';
|
||||
$cohort->descriptionformat = FORMAT_HTML;
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Missing cohort name in cohort_add_cohort()');
|
||||
cohort_add_cohort($cohort);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,6 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test create_cohorts
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_create_cohorts() {
|
||||
global $USER, $CFG, $DB;
|
||||
@@ -131,13 +129,12 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// Call without required capability.
|
||||
$this->unassignUserCapability('moodle/cohort:manage', $contextid, $roleid);
|
||||
$this->expectException(required_capability_exception::class);
|
||||
$createdcohorts = core_cohort_external::create_cohorts(array($cohort3));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete_cohorts
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_delete_cohorts() {
|
||||
global $USER, $CFG, $DB;
|
||||
@@ -164,6 +161,7 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
$cohort1 = self::getDataGenerator()->create_cohort();
|
||||
$cohort2 = self::getDataGenerator()->create_cohort();
|
||||
$this->unassignUserCapability('moodle/cohort:manage', $contextid, $roleid);
|
||||
$this->expectException(required_capability_exception::class);
|
||||
core_cohort_external::delete_cohorts(array($cohort1->id, $cohort2->id));
|
||||
}
|
||||
|
||||
@@ -232,8 +230,6 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test update_cohorts
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_update_cohorts() {
|
||||
global $USER, $CFG, $DB;
|
||||
@@ -291,6 +287,7 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// Call without required capability.
|
||||
$this->unassignUserCapability('moodle/cohort:manage', $context->id, $roleid);
|
||||
$this->expectException(required_capability_exception::class);
|
||||
core_cohort_external::update_cohorts(array($cohort1));
|
||||
}
|
||||
|
||||
@@ -326,8 +323,6 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test update_cohorts without permission on the dest category.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_update_cohorts_missing_dest() {
|
||||
global $USER, $CFG, $DB;
|
||||
@@ -363,13 +358,12 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// Call the external function.
|
||||
// Should fail because we don't have permission on the dest category
|
||||
$this->expectException(required_capability_exception::class);
|
||||
core_cohort_external::update_cohorts(array($cohortupdate));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test update_cohorts without permission on the src category.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_update_cohorts_missing_src() {
|
||||
global $USER, $CFG, $DB;
|
||||
@@ -405,13 +399,12 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// Call the external function.
|
||||
// Should fail because we don't have permission on the src category
|
||||
$this->expectException(required_capability_exception::class);
|
||||
core_cohort_external::update_cohorts(array($cohortupdate));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add_cohort_members
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_add_cohort_members() {
|
||||
global $DB;
|
||||
@@ -457,13 +450,12 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
'usertype' => array('type' => 'id', 'value' => '2')
|
||||
);
|
||||
$this->unassignUserCapability('moodle/cohort:assign', $contextid, $roleid);
|
||||
$this->expectException(required_capability_exception::class);
|
||||
$addcohortmembers = core_cohort_external::add_cohort_members(array($cohort2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete_cohort_members
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_delete_cohort_members() {
|
||||
global $DB;
|
||||
@@ -515,6 +507,7 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// Call without required capability.
|
||||
$this->unassignUserCapability('moodle/cohort:assign', $context->id, $roleid);
|
||||
$this->expectException(required_capability_exception::class);
|
||||
core_cohort_external::delete_cohort_members(array($cohortdel1, $cohortdel2));
|
||||
}
|
||||
|
||||
|
||||
@@ -166,8 +166,6 @@ class core_competency_api_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test updating a template.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_update_template() {
|
||||
$cat = $this->getDataGenerator()->create_category();
|
||||
@@ -186,6 +184,7 @@ class core_competency_api_testcase extends advanced_testcase {
|
||||
$this->assertEquals('success', $template->get('shortname'));
|
||||
|
||||
// Trying to change the context.
|
||||
$this->expectException(coding_exception::class);
|
||||
api::update_template((object) array('id' => $template->get('id'), 'contextid' => context_coursecat::instance($cat->id)));
|
||||
}
|
||||
|
||||
@@ -511,9 +510,6 @@ class core_competency_api_testcase extends advanced_testcase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_create_plan_from_template() {
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
@@ -536,6 +532,7 @@ class core_competency_api_testcase extends advanced_testcase {
|
||||
|
||||
// Check that api::create_plan cannot be used.
|
||||
unset($record->id);
|
||||
$this->expectException(coding_exception::class);
|
||||
$plan = api::create_plan($record);
|
||||
}
|
||||
|
||||
@@ -756,8 +753,6 @@ class core_competency_api_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test that the method to complete a plan.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_complete_plan() {
|
||||
global $DB;
|
||||
@@ -838,6 +833,7 @@ class core_competency_api_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
// Completing a plan that is completed throws an exception.
|
||||
$this->expectException(coding_exception::class);
|
||||
api::complete_plan($plan);
|
||||
}
|
||||
|
||||
@@ -4513,9 +4509,6 @@ class core_competency_api_testcase extends advanced_testcase {
|
||||
$this->assertTrue(evidence::record_exists($ev2->get('id')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_delete_evidence_without_permissions() {
|
||||
$this->resetAfterTest();
|
||||
$dg = $this->getDataGenerator();
|
||||
@@ -4529,6 +4522,7 @@ class core_competency_api_testcase extends advanced_testcase {
|
||||
|
||||
$this->setUser($u1);
|
||||
|
||||
$this->expectException(required_capability_exception::class);
|
||||
api::delete_evidence($ev1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1360,9 +1360,6 @@ class core_competency_event_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test evidence_created event by linking an invalid user competency to an evidence.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The user competency linked with this evidence is invalid.
|
||||
*/
|
||||
public function test_evidence_created_with_invalid_user_competency() {
|
||||
$this->resetAfterTest(true);
|
||||
@@ -1388,6 +1385,8 @@ class core_competency_event_testcase extends advanced_testcase {
|
||||
'commentincontext', 'core', null, $recommend, null, 1);
|
||||
|
||||
// We expect this to fail and throw a coding exception.
|
||||
$this->expectException('coding_exception');
|
||||
$this->expectExceptionMessage('The user competency linked with this evidence is invalid.');
|
||||
\core\event\competency_evidence_created::create_from_evidence($evidence, $otheruc, $recommend)->trigger();
|
||||
}
|
||||
|
||||
|
||||
@@ -299,22 +299,20 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test we can't create a competency framework with only read permissions.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_create_competency_frameworks_with_read_permissions() {
|
||||
$this->setUser($this->user);
|
||||
|
||||
$this->expectException(required_capability_exception::class);
|
||||
$result = $this->create_competency_framework(1, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test we can't create a competency framework with only read permissions.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_create_competency_frameworks_with_read_permissions_in_category() {
|
||||
$this->setUser($this->catuser);
|
||||
$this->expectException(required_capability_exception::class);
|
||||
$result = $this->create_competency_framework(1, false);
|
||||
}
|
||||
|
||||
@@ -365,8 +363,6 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test we cannot create a competency framework with nasty data.
|
||||
*
|
||||
* @expectedException invalid_parameter_exception
|
||||
*/
|
||||
public function test_create_competency_frameworks_with_nasty_data() {
|
||||
$this->setUser($this->creator);
|
||||
@@ -380,6 +376,7 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
'visible' => true,
|
||||
'contextid' => context_system::instance()->id
|
||||
);
|
||||
$this->expectException(invalid_parameter_exception::class);
|
||||
$result = external::create_competency_framework($framework);
|
||||
}
|
||||
|
||||
@@ -542,8 +539,6 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test we can delete a competency framework with read permissions.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_delete_competency_frameworks_with_read_permissions() {
|
||||
$this->setUser($this->creator);
|
||||
@@ -552,6 +547,7 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
$id = $result->id;
|
||||
// Switch users to someone with less permissions.
|
||||
$this->setUser($this->user);
|
||||
$this->expectException(required_capability_exception::class);
|
||||
$result = external::delete_competency_framework($id);
|
||||
}
|
||||
|
||||
@@ -624,14 +620,13 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test we can update a competency framework with read permissions.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_update_competency_frameworks_with_read_permissions() {
|
||||
$this->setUser($this->creator);
|
||||
$result = $this->create_competency_framework(1, true);
|
||||
|
||||
$this->setUser($this->user);
|
||||
$this->expectException(required_capability_exception::class);
|
||||
$result = $this->update_competency_framework($result->id, 2, true);
|
||||
}
|
||||
|
||||
@@ -758,12 +753,11 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test we can't create a competency with only read permissions.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_create_competency_with_read_permissions() {
|
||||
$framework = $this->getDataGenerator()->get_plugin_generator('core_competency')->create_framework();
|
||||
$this->setUser($this->user);
|
||||
$this->expectException(required_capability_exception::class);
|
||||
$competency = $this->create_competency(1, $framework->get('id'));
|
||||
}
|
||||
|
||||
@@ -820,8 +814,6 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test we cannot create a competency with nasty data.
|
||||
*
|
||||
* @expectedException invalid_parameter_exception
|
||||
*/
|
||||
public function test_create_competency_with_nasty_data() {
|
||||
$this->setUser($this->creator);
|
||||
@@ -834,6 +826,10 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
'competencyframeworkid' => $framework->id,
|
||||
'sortorder' => 0
|
||||
);
|
||||
// TODO: MDL-69700 - Analyse if the throw exception is happening
|
||||
// in the correct place and decide what happens with the trailing
|
||||
// code that is never executed.
|
||||
$this->expectException(invalid_parameter_exception::class);
|
||||
$result = external::create_competency($competency);
|
||||
$result = (object) external_api::clean_returnvalue(external::create_competency_returns(), $result);
|
||||
}
|
||||
@@ -998,8 +994,6 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test we can delete a competency with read permissions.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_delete_competency_with_read_permissions() {
|
||||
$this->setUser($this->creator);
|
||||
@@ -1009,6 +1003,7 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
$id = $result->id;
|
||||
// Switch users to someone with less permissions.
|
||||
$this->setUser($this->user);
|
||||
$this->expectException(required_capability_exception::class);
|
||||
$result = external::delete_competency($id);
|
||||
}
|
||||
|
||||
@@ -1052,8 +1047,6 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test we can update a competency with read permissions.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_update_competency_with_read_permissions() {
|
||||
$this->setUser($this->creator);
|
||||
@@ -1061,6 +1054,7 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
$result = $this->create_competency(1, $framework->id);
|
||||
|
||||
$this->setUser($this->user);
|
||||
$this->expectException(required_capability_exception::class);
|
||||
$result = $this->update_competency($result->id, 2);
|
||||
}
|
||||
|
||||
|
||||
@@ -526,10 +526,6 @@ class core_competency_plan_testcase extends advanced_testcase {
|
||||
$this->assertCount(0, $plans);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The competency does not belong to this template:
|
||||
*/
|
||||
public function test_get_competency() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
@@ -571,6 +567,8 @@ class core_competency_plan_testcase extends advanced_testcase {
|
||||
$this->assertEquals($c4->to_record(), $p4->get_competency($c4->get('id'))->to_record());
|
||||
|
||||
// Getting the competency 4 from the non-completed plan based on a template p4, will throw an exception.
|
||||
$this->expectException('coding_exception');
|
||||
$this->expectExceptionMessage('The competency does not belong to this template:');
|
||||
$p3->get_competency($c4->get('id'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -596,7 +596,7 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
$course['categoryid'] = $this->getDataGenerator()->create_category()->id;
|
||||
|
||||
$this->expectException(moodle_exception::class);
|
||||
$this->expectExceptionMessageRegExp("/{$expectedemptyfield}/");
|
||||
$this->expectExceptionMessageMatches("/{$expectedemptyfield}/");
|
||||
core_course_external::create_courses([$course]);
|
||||
}
|
||||
|
||||
|
||||
@@ -767,8 +767,6 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase {
|
||||
/**
|
||||
* Test get_enrolled_users from core_enrol_external with capability to
|
||||
* viewparticipants removed.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_enrolled_users_without_capability() {
|
||||
$capability = 'moodle/course:viewparticipants';
|
||||
@@ -776,6 +774,7 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// Call without required capability.
|
||||
$this->unassignUserCapability($capability, $data->context->id, $data->roleid);
|
||||
$this->expectException(moodle_exception::class);
|
||||
$categories = core_enrol_external::get_enrolled_users($data->course->id);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,8 +67,6 @@ class core_grade_grading_manager_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Unit test to set and get grading areas
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_set_and_get_grading_area() {
|
||||
global $DB;
|
||||
@@ -105,6 +103,7 @@ class core_grade_grading_manager_testcase extends advanced_testcase {
|
||||
$this->assertEquals('rubric', $gradingman->get_active_method());
|
||||
|
||||
// attempting to set an invalid method
|
||||
$this->expectException(moodle_exception::class);
|
||||
$gradingman->set_active_method('no_one_should_ever_try_to_implement_a_method_with_this_silly_name');
|
||||
}
|
||||
|
||||
|
||||
@@ -1291,7 +1291,6 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @covers ::create_file_from_storedfile
|
||||
*/
|
||||
public function test_create_file_from_storedfile_file_invalid() {
|
||||
@@ -1302,12 +1301,11 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$fs = get_file_storage();
|
||||
|
||||
// Create a file from a file id which doesn't exist.
|
||||
$this->expectException(file_exception::class);
|
||||
$fs->create_file_from_storedfile($filerecord, 9999);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid contextid
|
||||
* @covers ::create_file_from_storedfile
|
||||
*/
|
||||
public function test_create_file_from_storedfile_contextid_invalid() {
|
||||
@@ -1322,12 +1320,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$filerecord->filename = 'invalid.txt';
|
||||
$filerecord->contextid = 'invalid';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid contextid');
|
||||
$fs->create_file_from_storedfile($filerecord, $file1->get_id());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid component
|
||||
* @covers ::create_file_from_storedfile
|
||||
*/
|
||||
public function test_create_file_from_storedfile_component_invalid() {
|
||||
@@ -1342,12 +1340,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$filerecord->filename = 'invalid.txt';
|
||||
$filerecord->component = 'bad/component';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid component');
|
||||
$fs->create_file_from_storedfile($filerecord, $file1->get_id());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid filearea
|
||||
* @covers ::create_file_from_storedfile
|
||||
*/
|
||||
public function test_create_file_from_storedfile_filearea_invalid() {
|
||||
@@ -1362,12 +1360,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$filerecord->filename = 'invalid.txt';
|
||||
$filerecord->filearea = 'bad-filearea';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid filearea');
|
||||
$fs->create_file_from_storedfile($filerecord, $file1->get_id());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid itemid
|
||||
* @covers ::create_file_from_storedfile
|
||||
*/
|
||||
public function test_create_file_from_storedfile_itemid_invalid() {
|
||||
@@ -1382,12 +1380,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$filerecord->filename = 'invalid.txt';
|
||||
$filerecord->itemid = 'bad-itemid';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid itemid');
|
||||
$fs->create_file_from_storedfile($filerecord, $file1->get_id());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid file path
|
||||
* @covers ::create_file_from_storedfile
|
||||
*/
|
||||
public function test_create_file_from_storedfile_filepath_invalid() {
|
||||
@@ -1402,12 +1400,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$filerecord->filename = 'invalid.txt';
|
||||
$filerecord->filepath = 'a-/bad/-filepath';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid file path');
|
||||
$fs->create_file_from_storedfile($filerecord, $file1->get_id());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid file name
|
||||
* @covers ::create_file_from_storedfile
|
||||
*/
|
||||
public function test_create_file_from_storedfile_filename_invalid() {
|
||||
@@ -1421,12 +1419,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$filerecord->filename = '';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid file name');
|
||||
$fs->create_file_from_storedfile($filerecord, $file1->get_id());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid file timecreated
|
||||
* @covers ::create_file_from_storedfile
|
||||
*/
|
||||
public function test_create_file_from_storedfile_timecreated_invalid() {
|
||||
@@ -1441,12 +1439,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$filerecord->filename = 'invalid.txt';
|
||||
$filerecord->timecreated = 'today';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid file timecreated');
|
||||
$fs->create_file_from_storedfile($filerecord, $file1->get_id());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid file timemodified
|
||||
* @covers ::create_file_from_storedfile
|
||||
*/
|
||||
public function test_create_file_from_storedfile_timemodified_invalid() {
|
||||
@@ -1461,12 +1459,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$filerecord->filename = 'invalid.txt';
|
||||
$filerecord->timemodified = 'today';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid file timemodified');
|
||||
$fs->create_file_from_storedfile($filerecord, $file1->get_id());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException stored_file_creation_exception
|
||||
* @expectedExceptionMessage Can not create file "1/core/phpunit/0/testfile.txt"
|
||||
* @covers ::create_file_from_storedfile
|
||||
*/
|
||||
public function test_create_file_from_storedfile_duplicate() {
|
||||
@@ -1479,6 +1477,8 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$this->assertInstanceOf('stored_file', $file1);
|
||||
|
||||
// Creating a file validating unique constraint.
|
||||
$this->expectException(stored_file_creation_exception::class);
|
||||
$this->expectExceptionMessage('Can not create file "1/core/phpunit/0/testfile.txt"');
|
||||
$fs->create_file_from_storedfile($filerecord, $file1->get_id());
|
||||
}
|
||||
|
||||
@@ -1522,8 +1522,6 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid contextid
|
||||
* @covers ::create_file_from_string
|
||||
*/
|
||||
public function test_create_file_from_string_contextid_invalid() {
|
||||
@@ -1534,12 +1532,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$filerecord->contextid = 'invalid';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid contextid');
|
||||
$file1 = $fs->create_file_from_string($filerecord, 'text contents');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid component
|
||||
* @covers ::create_file_from_string
|
||||
*/
|
||||
public function test_create_file_from_string_component_invalid() {
|
||||
@@ -1550,12 +1548,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$filerecord->component = 'bad/component';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid component');
|
||||
$file1 = $fs->create_file_from_string($filerecord, 'text contents');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid filearea
|
||||
* @covers ::create_file_from_string
|
||||
*/
|
||||
public function test_create_file_from_string_filearea_invalid() {
|
||||
@@ -1566,12 +1564,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$filerecord->filearea = 'bad-filearea';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid filearea');
|
||||
$file1 = $fs->create_file_from_string($filerecord, 'text contents');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid itemid
|
||||
* @covers ::create_file_from_string
|
||||
*/
|
||||
public function test_create_file_from_string_itemid_invalid() {
|
||||
@@ -1582,12 +1580,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$filerecord->itemid = 'bad-itemid';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid itemid');
|
||||
$file1 = $fs->create_file_from_string($filerecord, 'text contents');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid file path
|
||||
* @covers ::create_file_from_string
|
||||
*/
|
||||
public function test_create_file_from_string_filepath_invalid() {
|
||||
@@ -1598,12 +1596,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$filerecord->filepath = 'a-/bad/-filepath';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid file path');
|
||||
$file1 = $fs->create_file_from_string($filerecord, 'text contents');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid file name
|
||||
* @covers ::create_file_from_string
|
||||
*/
|
||||
public function test_create_file_from_string_filename_invalid() {
|
||||
@@ -1614,12 +1612,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$filerecord->filename = '';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid file name');
|
||||
$file1 = $fs->create_file_from_string($filerecord, 'text contents');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid file timecreated
|
||||
* @covers ::create_file_from_string
|
||||
*/
|
||||
public function test_create_file_from_string_timecreated_invalid() {
|
||||
@@ -1636,8 +1634,6 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid file timemodified
|
||||
* @covers ::create_file_from_string
|
||||
*/
|
||||
public function test_create_file_from_string_timemodified_invalid() {
|
||||
@@ -1648,6 +1644,8 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$filerecord->timemodified = 'today';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid file timemodified');
|
||||
$file1 = $fs->create_file_from_string($filerecord, 'text contents');
|
||||
}
|
||||
|
||||
@@ -1669,8 +1667,6 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid contextid
|
||||
* @covers ::create_file_from_pathname
|
||||
*/
|
||||
public function test_create_file_from_pathname_contextid_invalid() {
|
||||
@@ -1684,12 +1680,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$filerecord->contextid = 'invalid';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid contextid');
|
||||
$file1 = $fs->create_file_from_pathname($filerecord, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid component
|
||||
* @covers ::create_file_from_pathname
|
||||
*/
|
||||
public function test_create_file_from_pathname_component_invalid() {
|
||||
@@ -1703,12 +1699,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$filerecord->component = 'bad/component';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid component');
|
||||
$file1 = $fs->create_file_from_pathname($filerecord, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid filearea
|
||||
* @covers ::create_file_from_pathname
|
||||
*/
|
||||
public function test_create_file_from_pathname_filearea_invalid() {
|
||||
@@ -1722,12 +1718,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$filerecord->filearea = 'bad-filearea';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid filearea');
|
||||
$file1 = $fs->create_file_from_pathname($filerecord, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid itemid
|
||||
* @covers ::create_file_from_pathname
|
||||
*/
|
||||
public function test_create_file_from_pathname_itemid_invalid() {
|
||||
@@ -1741,12 +1737,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$filerecord->itemid = 'bad-itemid';
|
||||
|
||||
$file1 = $fs->create_file_from_pathname($filerecord, $path);
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid itemid');
|
||||
$file1 = $fs->create_file_from_pathname($filerecord, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid file path
|
||||
* @covers ::create_file_from_pathname
|
||||
*/
|
||||
public function test_create_file_from_pathname_filepath_invalid() {
|
||||
@@ -1760,12 +1756,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$filerecord->filepath = 'a-/bad/-filepath';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid file path');
|
||||
$file1 = $fs->create_file_from_pathname($filerecord, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid file name
|
||||
* @covers ::create_file_from_pathname
|
||||
*/
|
||||
public function test_create_file_from_pathname_filename_invalid() {
|
||||
@@ -1779,12 +1775,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$filerecord->filename = '';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid file name');
|
||||
$file1 = $fs->create_file_from_pathname($filerecord, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid file timecreated
|
||||
* @covers ::create_file_from_pathname
|
||||
*/
|
||||
public function test_create_file_from_pathname_timecreated_invalid() {
|
||||
@@ -1798,12 +1794,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$filerecord->timecreated = 'today';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid file timecreated');
|
||||
$file1 = $fs->create_file_from_pathname($filerecord, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException file_exception
|
||||
* @expectedExceptionMessage Invalid file timemodified
|
||||
* @covers ::create_file_from_pathname
|
||||
*/
|
||||
public function test_create_file_from_pathname_timemodified_invalid() {
|
||||
@@ -1817,12 +1813,12 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$filerecord->timemodified = 'today';
|
||||
|
||||
$this->expectException(file_exception::class);
|
||||
$this->expectExceptionMessage('Invalid file timemodified');
|
||||
$file1 = $fs->create_file_from_pathname($filerecord, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException stored_file_creation_exception
|
||||
* @expectedExceptionMessage Can not create file "1/core/phpunit/0/testfile.txt"
|
||||
* @covers ::create_file_from_pathname
|
||||
*/
|
||||
public function test_create_file_from_pathname_duplicate_file() {
|
||||
@@ -1838,6 +1834,8 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$this->assertInstanceOf('stored_file', $file1);
|
||||
|
||||
// Creating a file validating unique constraint.
|
||||
$this->expectException(stored_file_creation_exception::class);
|
||||
$this->expectExceptionMessage('Can not create file "1/core/phpunit/0/testfile.txt"');
|
||||
$file2 = $fs->create_file_from_pathname($filerecord, $path);
|
||||
}
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ class core_files_file_system_filedir_testcase extends advanced_testcase {
|
||||
|
||||
// This should generate an exception.
|
||||
$this->expectException('file_exception');
|
||||
$this->expectExceptionMessageRegExp(
|
||||
$this->expectExceptionMessageMatches(
|
||||
'/Can not create local file pool directories, please verify permissions in dataroot./');
|
||||
|
||||
new file_system_filedir();
|
||||
@@ -177,7 +177,7 @@ class core_files_file_system_filedir_testcase extends advanced_testcase {
|
||||
|
||||
// This should generate an exception.
|
||||
$this->expectException('file_exception');
|
||||
$this->expectExceptionMessageRegExp(
|
||||
$this->expectExceptionMessageMatches(
|
||||
'/Can not create local file pool directories, please verify permissions in dataroot./');
|
||||
|
||||
new file_system_filedir();
|
||||
@@ -735,7 +735,7 @@ class core_files_file_system_filedir_testcase extends advanced_testcase {
|
||||
$vfileroot = $this->setup_vfile_root();
|
||||
|
||||
$this->expectException('file_exception');
|
||||
$this->expectExceptionMessageRegExp(
|
||||
$this->expectExceptionMessageMatches(
|
||||
'/Cannot read file\. Either the file does not exist or there is a permission problem\./');
|
||||
|
||||
$fs = new file_system_filedir();
|
||||
@@ -834,7 +834,7 @@ class core_files_file_system_filedir_testcase extends advanced_testcase {
|
||||
->chown(\org\bovigo\vfs\vfsStream::OWNER_USER_2);
|
||||
|
||||
$this->expectException('file_exception');
|
||||
$this->expectExceptionMessageRegExp(
|
||||
$this->expectExceptionMessageMatches(
|
||||
"/Can not create local file pool directories, please verify permissions in dataroot./");
|
||||
|
||||
// Attempt to add the file to the file pool.
|
||||
@@ -892,7 +892,7 @@ class core_files_file_system_filedir_testcase extends advanced_testcase {
|
||||
->chown(\org\bovigo\vfs\vfsStream::OWNER_USER_2);
|
||||
|
||||
$this->expectException('file_exception');
|
||||
$this->expectExceptionMessageRegExp(
|
||||
$this->expectExceptionMessageMatches(
|
||||
"/Can not create local file pool directories, please verify permissions in dataroot./");
|
||||
|
||||
// Attempt to add the file to the file pool.
|
||||
|
||||
@@ -69,7 +69,7 @@ class core_form_duration_testcase extends basic_testcase {
|
||||
public function test_constructor_rejects_invalid_unit(): void {
|
||||
// Test trying to create with an invalid unit.
|
||||
$mform = $this->get_test_form();
|
||||
$this->expectException('coding_exception');
|
||||
$this->expectException(coding_exception::class);
|
||||
$mform->addElement('duration', 'testel', null, ['defaultunit' => 123, 'optional' => false]);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,11 +49,10 @@ class core_test_generator_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test plugin generator, with no component directory.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Component core_completion does not support generators yet. Missing tests/generator/lib.php.
|
||||
*/
|
||||
public function test_get_plugin_generator_no_component_dir() {
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Component core_completion does not support generators yet. Missing tests/generator/lib.php.');
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('core_completion');
|
||||
}
|
||||
|
||||
|
||||
@@ -95,19 +95,15 @@ class core_admintree_testcase extends advanced_testcase {
|
||||
$this->assertEquals(array('zero', 'one', 'two', 'three', 'four', 'five', 'six'), $map);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_add_nodes_before_invalid1() {
|
||||
$tree = new admin_root(true);
|
||||
$this->expectException(coding_exception::class);
|
||||
$tree->add('root', new admin_externalpage('foo', 'Foo', 'http://foo.bar'), array('moodle:site/config'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_add_nodes_before_invalid2() {
|
||||
$tree = new admin_root(true);
|
||||
$this->expectException(coding_exception::class);
|
||||
$tree->add('root', new admin_category('bar', 'Bar'), '');
|
||||
}
|
||||
|
||||
|
||||
@@ -109,13 +109,11 @@ class core_blocklib_testcase extends advanced_testcase {
|
||||
$this->assertEquals(array('a-region-name', 'another-region'), $this->blockmanager->get_regions(), '', 0, 10, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_add_region_after_loaded() {
|
||||
// Set up fixture.
|
||||
$this->blockmanager->mark_loaded();
|
||||
// Exercise SUT.
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->blockmanager->add_region('too-late', false);
|
||||
}
|
||||
|
||||
@@ -167,12 +165,12 @@ class core_blocklib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test to ensure that we cannot add a region after the blocks have been loaded.
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_add_custom_region_after_loaded() {
|
||||
// Set up fixture.
|
||||
$this->blockmanager->mark_loaded();
|
||||
// Exercise SUT.
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->blockmanager->add_region('too-late');
|
||||
}
|
||||
|
||||
@@ -185,21 +183,17 @@ class core_blocklib_testcase extends advanced_testcase {
|
||||
$this->assertEquals('a-region-name', $this->blockmanager->get_default_region());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_set_unknown_region_as_default() {
|
||||
// Exercise SUT.
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->blockmanager->set_default_region('a-region-name');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_change_default_region_after_loaded() {
|
||||
// Set up fixture.
|
||||
$this->blockmanager->mark_loaded();
|
||||
// Exercise SUT.
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->blockmanager->set_default_region('too-late');
|
||||
}
|
||||
|
||||
|
||||
@@ -849,10 +849,15 @@ class core_event_testcase extends advanced_testcase {
|
||||
$this->assertSame($event->get_data(), $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit\Framework\Error\Notice
|
||||
*/
|
||||
public function test_context_not_used() {
|
||||
// TODO: MDL-69688 - This test is far away from my understanding. It throws a
|
||||
// "Trying to get property 'instanceid' of non-object" notice, so
|
||||
// it's not clear for me what the test is doing. This was detected
|
||||
// when preparing tests for PHPUnit 8 (MDL-67673) and, at the end
|
||||
// all that was done is to move the annotation (deprecated) to
|
||||
// explicit expectation. Still try commenting it out and you'll see
|
||||
// the notice.
|
||||
$this->expectException(\PHPUnit\Framework\Error\Notice::class);
|
||||
$event = \core_tests\event\context_used_in_event::create(array('other' => array('sample' => 1, 'xx' => 10)));
|
||||
$this->assertEventContextNotUsed($event);
|
||||
|
||||
|
||||
@@ -98,22 +98,21 @@ class core_exporter_testcase extends advanced_testcase {
|
||||
$this->assertArrayNotHasKey('otherstrings', $structure->keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_invalid_data() {
|
||||
global $PAGE;
|
||||
$exporter = new core_testable_exporter($this->invaliddata, $this->validrelated);
|
||||
$output = $PAGE->get_renderer('core');
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$result = $exporter->export($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_invalid_related() {
|
||||
global $PAGE;
|
||||
// TODO: MDL-69700 - Analyse if the throw exception is happening
|
||||
// in the correct place and decide what happens with the trailing
|
||||
// code that is never executed.
|
||||
$this->expectException(coding_exception::class);
|
||||
$exporter = new core_testable_exporter($this->validdata, $this->invalidrelated);
|
||||
$output = $PAGE->get_renderer('core');
|
||||
|
||||
|
||||
@@ -91,11 +91,9 @@ class core_filterlib_testcase extends advanced_testcase {
|
||||
$this->assert_only_one_filter_globally('name', TEXTFILTER_DISABLED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_global_config_exception_on_invalid_state() {
|
||||
$this->resetAfterTest();
|
||||
$this->expectException(coding_exception::class);
|
||||
filter_set_global_state('name', 0);
|
||||
}
|
||||
|
||||
@@ -248,21 +246,17 @@ class core_filterlib_testcase extends advanced_testcase {
|
||||
$this->assert_no_local_setting();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_local_invalid_state_throws_exception() {
|
||||
$this->resetAfterTest();
|
||||
// Exercise SUT.
|
||||
$this->expectException(coding_exception::class);
|
||||
filter_set_local_state('name', 123, -9999);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_throws_exception_when_setting_global() {
|
||||
$this->resetAfterTest();
|
||||
// Exercise SUT.
|
||||
$this->expectException(coding_exception::class);
|
||||
filter_set_local_state('name', context_system::instance()->id, TEXTFILTER_INHERIT);
|
||||
}
|
||||
|
||||
@@ -543,15 +537,13 @@ class core_filterlib_testcase extends advanced_testcase {
|
||||
$this->assertEquals(array(), $filters);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_available_in_context_exception_with_syscontext() {
|
||||
$this->resetAfterTest();
|
||||
[
|
||||
'syscontext' => $syscontext
|
||||
] = $this->setup_available_in_context_tests();
|
||||
// Exercise SUT.
|
||||
$this->expectException(coding_exception::class);
|
||||
filter_get_available_in_context($syscontext);
|
||||
}
|
||||
|
||||
|
||||
@@ -83,32 +83,25 @@ class core_moodle_page_testcase extends advanced_testcase {
|
||||
$this->assertSame($originalcourse, $COURSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_set_course_once_theme_set() {
|
||||
// Setup fixture.
|
||||
$this->testpage->force_theme(theme_config::DEFAULT_THEME);
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
|
||||
// Exercise SUT.
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->testpage->set_course($course);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_set_category_once_theme_set() {
|
||||
// Setup fixture.
|
||||
$this->testpage->force_theme(theme_config::DEFAULT_THEME);
|
||||
|
||||
// Exercise SUT.
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->testpage->set_category_by_id(123);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_set_category_once_course_set() {
|
||||
// Setup fixture.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -116,6 +109,7 @@ class core_moodle_page_testcase extends advanced_testcase {
|
||||
$this->testpage->set_course($course);
|
||||
|
||||
// Exercise SUT.
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->testpage->set_category_by_id(123);
|
||||
}
|
||||
|
||||
@@ -145,11 +139,9 @@ class core_moodle_page_testcase extends advanced_testcase {
|
||||
$this->assertEquals(moodle_page::STATE_DONE, $this->testpage->state);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_set_state_cannot_skip_one() {
|
||||
// Exercise SUT.
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->testpage->set_state(moodle_page::STATE_IN_BODY);
|
||||
}
|
||||
|
||||
@@ -396,15 +388,13 @@ class core_moodle_page_testcase extends advanced_testcase {
|
||||
$this->assertEquals($cm->id, $this->testpage->cm->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_set_activity_record_before_cm() {
|
||||
// Setup fixture.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
|
||||
$cm = get_coursemodule_from_id('forum', $forum->cmid);
|
||||
// Exercise SUT.
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->testpage->set_activity_record($forum);
|
||||
}
|
||||
|
||||
@@ -444,9 +434,6 @@ class core_moodle_page_testcase extends advanced_testcase {
|
||||
$this->assertEquals($forum, $this->testpage->activityrecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_set_inconsistent_activity_record_course() {
|
||||
// Setup fixture.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -455,12 +442,10 @@ class core_moodle_page_testcase extends advanced_testcase {
|
||||
$this->testpage->set_cm($cm);
|
||||
// Exercise SUT.
|
||||
$forum->course = 13;
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->testpage->set_activity_record($forum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_set_inconsistent_activity_record_instance() {
|
||||
// Setup fixture.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -469,6 +454,7 @@ class core_moodle_page_testcase extends advanced_testcase {
|
||||
$this->testpage->set_cm($cm);
|
||||
// Exercise SUT.
|
||||
$forum->id = 13;
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->testpage->set_activity_record($forum);
|
||||
}
|
||||
|
||||
@@ -498,9 +484,6 @@ class core_moodle_page_testcase extends advanced_testcase {
|
||||
$this->assertEquals($forum, $this->testpage->activityrecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_set_cm_with_inconsistent_course() {
|
||||
// Setup fixture.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -508,6 +491,7 @@ class core_moodle_page_testcase extends advanced_testcase {
|
||||
$cm = get_coursemodule_from_id('forum', $forum->cmid);
|
||||
// Exercise SUT.
|
||||
$cm->course = 13;
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->testpage->set_cm($cm, $course);
|
||||
}
|
||||
|
||||
|
||||
@@ -121,11 +121,10 @@ class core_moodle_url_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test set bad scheme on Moodle URL objects.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_moodle_url_set_bad_scheme() {
|
||||
$url = new moodle_url('http://moodle.org/foo/bar');
|
||||
$this->expectException(coding_exception::class);
|
||||
$url->set_scheme('not a valid $ scheme');
|
||||
}
|
||||
|
||||
@@ -200,36 +199,30 @@ class core_moodle_url_testcase extends advanced_testcase {
|
||||
$this->assertSame('/', $url3->out_as_local_url());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
* @return void
|
||||
*/
|
||||
public function test_out_as_local_url_error() {
|
||||
$url2 = new moodle_url('http://www.google.com/lib/tests/weblib_test.php');
|
||||
$this->expectException(coding_exception::class);
|
||||
$url2->out_as_local_url();
|
||||
}
|
||||
|
||||
/**
|
||||
* You should get error with modified url
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @return void
|
||||
*/
|
||||
public function test_modified_url_out_as_local_url_error() {
|
||||
global $CFG;
|
||||
|
||||
$modifiedurl = $CFG->wwwroot.'1';
|
||||
$url3 = new moodle_url($modifiedurl.'/login/profile.php');
|
||||
$this->expectException(coding_exception::class);
|
||||
$url3->out_as_local_url();
|
||||
}
|
||||
|
||||
/**
|
||||
* Try get local url from external https url and you should get error
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_https_out_as_local_url_error() {
|
||||
$url4 = new moodle_url('https://www.google.com/lib/tests/weblib_test.php');
|
||||
$this->expectException(coding_exception::class);
|
||||
$url4->out_as_local_url();
|
||||
}
|
||||
|
||||
|
||||
@@ -2225,12 +2225,10 @@ class core_moodlelib_testcase extends advanced_testcase {
|
||||
$COURSE->lang = $originallang;
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit\Framework\Error\Warning
|
||||
*/
|
||||
public function test_get_string_limitation() {
|
||||
// This is one of the limitations to the lang_string class. It can't be
|
||||
// used as a key.
|
||||
$this->expectException(\PHPUnit\Framework\Error\Warning::class);
|
||||
$array = array(get_string('yes', null, null, true) => 'yes');
|
||||
}
|
||||
|
||||
|
||||
@@ -102,11 +102,10 @@ class core_output_mustache_template_finder_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests for get_template_directories_for_component when dealing with an invalid component.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_invalid_component_get_template_directories_for_component() {
|
||||
// Test something invalid.
|
||||
$this->expectException(coding_exception::class);
|
||||
mustache_template_finder::get_template_directories_for_component('octopus', 'classic');
|
||||
}
|
||||
|
||||
@@ -191,10 +190,9 @@ class core_output_mustache_template_finder_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests for get_template_filepath when dealing with an invalid component.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_invalid_component_get_template_filepath() {
|
||||
$this->expectException(moodle_exception::class);
|
||||
mustache_template_finder::get_template_filepath('core/octopus', 'classic');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,15 +174,13 @@ class core_persistent_testcase extends advanced_testcase {
|
||||
$this->assertEquals($data, $p->to_record());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_from_record_invalid_param() {
|
||||
$p = new core_testable_persistent();
|
||||
$data = (object) array(
|
||||
'invalidparam' => 'abc'
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$p->from_record($data);
|
||||
}
|
||||
|
||||
@@ -439,11 +437,9 @@ class core_persistent_testcase extends advanced_testcase {
|
||||
$this->assertEquals($expected, core_testable_persistent::get_sql_fields('c', 'prefix_'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessageRegExp /The alias .+ exceeds 30 characters/
|
||||
*/
|
||||
public function test_get_sql_fields_too_long() {
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessageMatches('/The alias .+ exceeds 30 characters/');
|
||||
core_testable_persistent::get_sql_fields('c');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,11 +370,10 @@ class core_plugin_manager_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* The combination of ANY_VERSION + $exactmatch is illegal.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_remote_plugin_info_exception() {
|
||||
$pluginman = testable_core_plugin_manager::instance();
|
||||
$this->expectException(moodle_exception::class);
|
||||
$pluginman->get_remote_plugin_info('any_thing', ANY_VERSION, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,13 +55,12 @@ class core_update_checker_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* If there are no fetched data yet, the first cron should fetch them.
|
||||
*
|
||||
* @expectedException \core\update\testable_checker_cron_executed
|
||||
*/
|
||||
public function test_cron_initial_fetch() {
|
||||
$provider = testable_checker::instance();
|
||||
$provider->fakerecentfetch = null;
|
||||
$provider->fakecurrenttimestamp = -1;
|
||||
$this->expectException(\core\update\testable_checker_cron_executed::class);
|
||||
$provider->cron();
|
||||
}
|
||||
|
||||
@@ -78,13 +77,12 @@ class core_update_checker_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* If there is an outdated fetch, the cron execution is expected.
|
||||
*
|
||||
* @expectedException \core\update\testable_checker_cron_executed
|
||||
*/
|
||||
public function test_cron_has_outdated_fetch() {
|
||||
$provider = testable_checker::instance();
|
||||
$provider->fakerecentfetch = time() - 49 * HOURSECS; // Fetched 49 hours ago.
|
||||
$provider->fakecurrenttimestamp = -1;
|
||||
$this->expectException(\core\update\testable_checker_cron_executed::class);
|
||||
$provider->cron();
|
||||
}
|
||||
|
||||
@@ -259,14 +257,12 @@ class core_update_checker_testcase extends advanced_testcase {
|
||||
$this->assertEquals(2011010102, $cmp['mod_foo'][0]['version']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \core\update\checker_exception
|
||||
*/
|
||||
public function test_compare_responses_invalid_format() {
|
||||
$provider = testable_checker::instance();
|
||||
$broken = array(
|
||||
'status' => 'ERROR' // No 'updates' key here.
|
||||
);
|
||||
$this->expectException(\core\update\checker_exception::class);
|
||||
$cmp = $provider->compare_responses($broken, $broken);
|
||||
}
|
||||
|
||||
|
||||
@@ -111,14 +111,12 @@ class core_update_code_manager_testcase extends advanced_testcase {
|
||||
$files = $codeman->unzip_plugin_file($zipfilepath, $targetdir, 'bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_unzip_plugin_file_multidir() {
|
||||
$codeman = new \core\update\testable_code_manager();
|
||||
$zipfilepath = __DIR__.'/fixtures/update_validator/zips/multidir.zip';
|
||||
$targetdir = make_request_directory();
|
||||
// Attempting to rename the root folder if there are multiple ones should lead to exception.
|
||||
$this->expectException(moodle_exception::class);
|
||||
$files = $codeman->unzip_plugin_file($zipfilepath, $targetdir, 'foo');
|
||||
}
|
||||
|
||||
|
||||
@@ -675,10 +675,6 @@ class core_user_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test get_property_default().
|
||||
*
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Invalid property requested, or the property does not has a default value.
|
||||
*/
|
||||
public function test_get_property_default() {
|
||||
global $CFG;
|
||||
@@ -706,6 +702,8 @@ class core_user_testcase extends advanced_testcase {
|
||||
$timezone = core_user::get_property_default('timezone');
|
||||
$this->assertEquals('Pacific/Auckland', $timezone);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Invalid property requested, or the property does not has a default value.');
|
||||
core_user::get_property_default('firstname');
|
||||
}
|
||||
|
||||
|
||||
@@ -1188,7 +1188,6 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test search_contacts.
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_search_contacts() {
|
||||
global $DB;
|
||||
@@ -1250,6 +1249,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals($user5->id, $result['id']);
|
||||
|
||||
// Empty query, will throw an exception.
|
||||
$this->expectException(moodle_exception::class);
|
||||
$results = core_message_external::search_contacts('');
|
||||
}
|
||||
|
||||
|
||||
@@ -630,8 +630,6 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test lock_submissions
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_lock_submissions() {
|
||||
global $DB, $USER;
|
||||
@@ -691,6 +689,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
'text'=>'Submission text',
|
||||
'format'=>FORMAT_MOODLE);
|
||||
$notices = array();
|
||||
$this->expectException(moodle_exception::class);
|
||||
$assign->save_submission($data, $notices);
|
||||
}
|
||||
|
||||
@@ -895,8 +894,6 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test reveal_identities
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_reveal_identities() {
|
||||
global $DB, $USER;
|
||||
@@ -930,6 +927,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
$studentrole->id);
|
||||
|
||||
$this->setUser($student1);
|
||||
$this->expectException(required_capability_exception::class);
|
||||
$result = mod_assign_external::reveal_identities($instance->id);
|
||||
$result = external_api::clean_returnvalue(mod_assign_external::reveal_identities_returns(), $result);
|
||||
$this->assertEquals(1, count($result));
|
||||
@@ -1344,8 +1342,6 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test save grades for a team submission
|
||||
*
|
||||
* @expectedException invalid_parameter_exception
|
||||
*/
|
||||
public function test_save_grades_with_group_submission() {
|
||||
global $DB, $USER, $CFG;
|
||||
@@ -1439,6 +1435,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
$grades1[] = $student2gradeinfo;
|
||||
|
||||
// Expect an exception since 2 grades have been submitted for the same team.
|
||||
$this->expectException(invalid_parameter_exception::class);
|
||||
$result = mod_assign_external::save_grades($instance->id, true, $grades1);
|
||||
$result = external_api::clean_returnvalue(mod_assign_external::save_grades_returns(), $result);
|
||||
|
||||
@@ -1649,8 +1646,6 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test view_grading_table
|
||||
*
|
||||
* @expectedException dml_missing_record_exception
|
||||
*/
|
||||
public function test_view_grading_table_invalid_instance() {
|
||||
global $DB;
|
||||
@@ -1664,13 +1659,12 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
$cm = get_coursemodule_from_instance('assign', $assign->id);
|
||||
|
||||
// Test invalid instance id.
|
||||
$this->expectException(dml_missing_record_exception::class);
|
||||
mod_assign_external::view_grading_table(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test view_grading_table
|
||||
*
|
||||
* @expectedException require_login_exception
|
||||
*/
|
||||
public function test_view_grading_table_not_enrolled() {
|
||||
global $DB;
|
||||
@@ -1687,6 +1681,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
$user = self::getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
|
||||
$this->expectException(require_login_exception::class);
|
||||
mod_assign_external::view_grading_table($assign->id);
|
||||
}
|
||||
|
||||
@@ -1731,9 +1726,6 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test view_grading_table
|
||||
*
|
||||
* @expectedException require_login_exception
|
||||
* @expectedExceptionMessage Course or activity not accessible. (Activity is hidden)
|
||||
*/
|
||||
public function test_view_grading_table_without_capability() {
|
||||
global $DB;
|
||||
@@ -1759,6 +1751,8 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
course_modinfo::clear_instance_cache();
|
||||
|
||||
$this->expectException(require_login_exception::class);
|
||||
$this->expectExceptionMessage('Course or activity not accessible. (Activity is hidden)');
|
||||
mod_assign_external::view_grading_table($assign->id);
|
||||
}
|
||||
|
||||
@@ -2204,8 +2198,6 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test access control for get_submission_status.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_get_submission_status_access_control() {
|
||||
$this->resetAfterTest(true);
|
||||
@@ -2215,6 +2207,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
$this->setUser($student2);
|
||||
|
||||
// Access control test.
|
||||
$this->expectException(required_capability_exception::class);
|
||||
mod_assign_external::get_submission_status($assign->get_instance()->id, $student1->id);
|
||||
|
||||
}
|
||||
@@ -2338,19 +2331,16 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* get_participant should throw an excaption if the requested assignment doesn't exist.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_participant_no_assignment() {
|
||||
$this->resetAfterTest(true);
|
||||
$this->expectException(moodle_exception::class);
|
||||
mod_assign_external::get_participant('-1', '-1', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* get_participant should throw a require_login_exception if the user doesn't have access
|
||||
* to view assignments.
|
||||
*
|
||||
* @expectedException require_login_exception
|
||||
*/
|
||||
public function test_get_participant_no_view_capability() {
|
||||
global $DB;
|
||||
@@ -2366,14 +2356,13 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
$this->setUser($student);
|
||||
assign_capability('mod/assign:view', CAP_PROHIBIT, $studentrole->id, $context->id, true);
|
||||
|
||||
$this->expectException(require_login_exception::class);
|
||||
mod_assign_external::get_participant($assign->id, $student->id, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* get_participant should throw a required_capability_exception if the user doesn't have access
|
||||
* to view assignment grades.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_get_participant_no_grade_capability() {
|
||||
global $DB;
|
||||
@@ -2392,13 +2381,12 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
assign_capability('mod/assign:grade', CAP_PROHIBIT, $teacherrole->id, $context->id, true);
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
|
||||
$this->expectException(required_capability_exception::class);
|
||||
mod_assign_external::get_participant($assign->id, $student->id, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* get_participant should throw an exception if the user isn't enrolled in the course.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_participant_no_participant() {
|
||||
global $DB;
|
||||
@@ -2411,6 +2399,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
$this->setUser($teacher);
|
||||
|
||||
$this->expectException(moodle_exception::class);
|
||||
$result = mod_assign_external::get_participant($assign->id, $student->id, false);
|
||||
$result = external_api::clean_returnvalue(mod_assign_external::get_participant_returns(), $result);
|
||||
}
|
||||
|
||||
@@ -168,8 +168,6 @@ class mod_choice_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test custom validations.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_answer_created_other_exception() {
|
||||
// Generate user data.
|
||||
@@ -183,6 +181,7 @@ class mod_choice_events_testcase extends advanced_testcase {
|
||||
$eventdata['other'] = array();
|
||||
|
||||
// Make sure content identifier is always set.
|
||||
$this->expectException(coding_exception::class);
|
||||
$event = \mod_choice\event\answer_created::create($eventdata);
|
||||
$event->trigger();
|
||||
$this->assertEventContextNotUsed($event);
|
||||
|
||||
@@ -138,9 +138,6 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_choice_user_submit_response_validation() {
|
||||
global $USER;
|
||||
|
||||
@@ -159,6 +156,7 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase {
|
||||
$optionids2 = array_keys($choicewithoptions2->option);
|
||||
|
||||
// Make sure we cannot submit options from a different choice instance.
|
||||
$this->expectException(moodle_exception::class);
|
||||
choice_user_submit_response($optionids2[0], $choice1, $USER->id, $course, $cm);
|
||||
}
|
||||
|
||||
|
||||
+100
-152
@@ -54,9 +54,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure course_searched event validates that searchterm is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'searchterm' value must be set in other.
|
||||
*/
|
||||
public function test_course_searched_searchterm_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -65,14 +62,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'context' => $coursectx,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'searchterm' value must be set in other.");
|
||||
\mod_forum\event\course_searched::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure course_searched event validates that context is the correct level.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_COURSE.
|
||||
*/
|
||||
public function test_course_searched_context_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -83,6 +79,8 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('searchterm' => 'testing'),
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Context level must be CONTEXT_COURSE.');
|
||||
\mod_forum\event\course_searched::create($params);
|
||||
}
|
||||
|
||||
@@ -123,9 +121,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure discussion_created event validates that forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_discussion_created_forumid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -136,14 +131,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'context' => $context,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'forumid' value must be set in other.");
|
||||
\mod_forum\event\discussion_created::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure discussion_created event validates that the context is the correct level.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_discussion_created_context_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -154,6 +148,8 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('forumid' => $forum->id),
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\discussion_created::create($params);
|
||||
}
|
||||
|
||||
@@ -204,9 +200,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure discussion_updated event validates that forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_discussion_updated_forumid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -217,14 +210,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'context' => $context,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'forumid' value must be set in other.");
|
||||
\mod_forum\event\discussion_updated::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure discussion_created event validates that the context is the correct level.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_discussion_updated_context_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -235,6 +227,8 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('forumid' => $forum->id),
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\discussion_updated::create($params);
|
||||
}
|
||||
|
||||
@@ -283,9 +277,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure discussion_deleted event validates that forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_discussion_deleted_forumid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -296,14 +287,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'context' => $context,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'forumid' value must be set in other.");
|
||||
\mod_forum\event\discussion_deleted::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure discussion_deleted event validates that context is of the correct level.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_discussion_deleted_context_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -314,6 +304,8 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('forumid' => $forum->id),
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\discussion_deleted::create($params);
|
||||
}
|
||||
|
||||
@@ -363,9 +355,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure discussion_moved event validates that fromforumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'fromforumid' value must be set in other.
|
||||
*/
|
||||
public function test_discussion_moved_fromforumid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -378,14 +367,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('toforumid' => $toforum->id)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'fromforumid' value must be set in other.");
|
||||
\mod_forum\event\discussion_moved::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure discussion_moved event validates that toforumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'toforumid' value must be set in other.
|
||||
*/
|
||||
public function test_discussion_moved_toforumid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -398,14 +386,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('fromforumid' => $fromforum->id)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'toforumid' value must be set in other.");
|
||||
\mod_forum\event\discussion_moved::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure discussion_moved event validates that the context level is correct.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_discussion_moved_context_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -426,6 +413,8 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('fromforumid' => $fromforum->id, 'toforumid' => $toforum->id)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\discussion_moved::create($params);
|
||||
}
|
||||
|
||||
@@ -477,9 +466,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure discussion_viewed event validates that the contextlevel is correct.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_discussion_viewed_context_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -498,6 +484,8 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'objectid' => $discussion->id,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\discussion_viewed::create($params);
|
||||
}
|
||||
|
||||
@@ -546,9 +534,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure course_module_viewed event validates that the contextlevel is correct.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_course_module_viewed_context_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -559,6 +544,8 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'objectid' => $forum->id,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\course_module_viewed::create($params);
|
||||
}
|
||||
|
||||
@@ -600,9 +587,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure subscription_created event validates that the forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_subscription_created_forumid_validation() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
@@ -614,14 +598,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'forumid' value must be set in other.");
|
||||
\mod_forum\event\subscription_created::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure subscription_created event validates that the relateduserid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'relateduserid' must be set.
|
||||
*/
|
||||
public function test_subscription_created_relateduserid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -632,14 +615,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'objectid' => $forum->id,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'relateduserid' must be set.");
|
||||
\mod_forum\event\subscription_created::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure subscription_created event validates that the contextlevel is correct.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_subscription_created_contextlevel_validation() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
@@ -652,6 +634,8 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\subscription_created::create($params);
|
||||
}
|
||||
|
||||
@@ -703,9 +687,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure subscription_deleted event validates that the forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_subscription_deleted_forumid_validation() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
@@ -717,14 +698,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'forumid' value must be set in other.");
|
||||
\mod_forum\event\subscription_deleted::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure subscription_deleted event validates that the relateduserid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'relateduserid' must be set.
|
||||
*/
|
||||
public function test_subscription_deleted_relateduserid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -735,14 +715,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'objectid' => $forum->id,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'relateduserid' must be set.");
|
||||
\mod_forum\event\subscription_deleted::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure subscription_deleted event validates that the contextlevel is correct.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_subscription_deleted_contextlevel_validation() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
@@ -755,6 +734,8 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\subscription_deleted::create($params);
|
||||
}
|
||||
|
||||
@@ -806,9 +787,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure readtracking_enabled event validates that the forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_readtracking_enabled_forumid_validation() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
@@ -820,14 +798,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'forumid' value must be set in other.");
|
||||
\mod_forum\event\readtracking_enabled::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure readtracking_enabled event validates that the relateduserid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'relateduserid' must be set.
|
||||
*/
|
||||
public function test_readtracking_enabled_relateduserid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -838,14 +815,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'objectid' => $forum->id,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'relateduserid' must be set.");
|
||||
\mod_forum\event\readtracking_enabled::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure readtracking_enabled event validates that the contextlevel is correct.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_readtracking_enabled_contextlevel_validation() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
@@ -858,6 +834,8 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\readtracking_enabled::create($params);
|
||||
}
|
||||
|
||||
@@ -900,9 +878,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure readtracking_disabled event validates that the forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_readtracking_disabled_forumid_validation() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
@@ -914,14 +889,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'forumid' value must be set in other.");
|
||||
\mod_forum\event\readtracking_disabled::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure readtracking_disabled event validates that the relateduserid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'relateduserid' must be set.
|
||||
*/
|
||||
public function test_readtracking_disabled_relateduserid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -932,14 +906,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'objectid' => $forum->id,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'relateduserid' must be set.");
|
||||
\mod_forum\event\readtracking_disabled::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure readtracking_disabled event validates that the contextlevel is correct
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_readtracking_disabled_contextlevel_validation() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
@@ -952,6 +925,8 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\readtracking_disabled::create($params);
|
||||
}
|
||||
|
||||
@@ -994,9 +969,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure subscribers_viewed event validates that the forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_subscribers_viewed_forumid_validation() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
@@ -1008,14 +980,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'forumid' value must be set in other.");
|
||||
\mod_forum\event\subscribers_viewed::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure subscribers_viewed event validates that the contextlevel is correct.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_subscribers_viewed_contextlevel_validation() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
@@ -1028,6 +999,8 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\subscribers_viewed::create($params);
|
||||
}
|
||||
|
||||
@@ -1066,9 +1039,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure user_report_viewed event validates that the reportmode is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'reportmode' value must be set in other.
|
||||
*/
|
||||
public function test_user_report_viewed_reportmode_validation() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
@@ -1079,14 +1049,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'reportmode' value must be set in other.");
|
||||
\mod_forum\event\user_report_viewed::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure user_report_viewed event validates that the contextlevel is correct.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be either CONTEXT_SYSTEM, CONTEXT_COURSE or CONTEXT_USER.
|
||||
*/
|
||||
public function test_user_report_viewed_contextlevel_validation() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
@@ -1099,14 +1068,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Context level must be either CONTEXT_SYSTEM, CONTEXT_COURSE or CONTEXT_USER.');
|
||||
\mod_forum\event\user_report_viewed::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure user_report_viewed event validates that the relateduserid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'relateduserid' must be set.
|
||||
*/
|
||||
public function test_user_report_viewed_relateduserid_validation() {
|
||||
|
||||
@@ -1115,6 +1083,8 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('reportmode' => 'posts'),
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'relateduserid' must be set.");
|
||||
\mod_forum\event\user_report_viewed::create($params);
|
||||
}
|
||||
|
||||
@@ -1178,9 +1148,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure post_created event validates that the discussionid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'discussionid' value must be set in other.
|
||||
*/
|
||||
public function test_post_created_discussionid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -1206,14 +1173,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('forumid' => $forum->id, 'forumtype' => $forum->type)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'discussionid' value must be set in other.");
|
||||
\mod_forum\event\post_created::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure post_created event validates that the forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_post_created_forumid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -1239,14 +1205,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('discussionid' => $discussion->id, 'forumtype' => $forum->type)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'forumid' value must be set in other.");
|
||||
\mod_forum\event\post_created::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure post_created event validates that the forumtype is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumtype' value must be set in other.
|
||||
*/
|
||||
public function test_post_created_forumtype_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -1272,14 +1237,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('discussionid' => $discussion->id, 'forumid' => $forum->id)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'forumtype' value must be set in other.");
|
||||
\mod_forum\event\post_created::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure post_created event validates that the contextlevel is correct.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_post_created_context_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -1305,6 +1269,8 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('discussionid' => $discussion->id, 'forumid' => $forum->id, 'forumtype' => $forum->type)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\post_created::create($params);
|
||||
}
|
||||
|
||||
@@ -1439,9 +1405,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure post_deleted event validates that the discussionid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'discussionid' value must be set in other.
|
||||
*/
|
||||
public function test_post_deleted_discussionid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -1467,14 +1430,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('forumid' => $forum->id, 'forumtype' => $forum->type)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'discussionid' value must be set in other.");
|
||||
\mod_forum\event\post_deleted::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure post_deleted event validates that the forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_post_deleted_forumid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -1500,14 +1462,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('discussionid' => $discussion->id, 'forumtype' => $forum->type)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'forumid' value must be set in other.");
|
||||
\mod_forum\event\post_deleted::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure post_deleted event validates that the forumtype is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumtype' value must be set in other.
|
||||
*/
|
||||
public function test_post_deleted_forumtype_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -1533,14 +1494,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('discussionid' => $discussion->id, 'forumid' => $forum->id)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'forumtype' value must be set in other.");
|
||||
\mod_forum\event\post_deleted::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure post_deleted event validates that the contextlevel is correct.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_post_deleted_context_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -1566,6 +1526,8 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('discussionid' => $discussion->id, 'forumid' => $forum->id, 'forumtype' => $forum->type)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\post_deleted::create($params);
|
||||
}
|
||||
|
||||
@@ -1711,9 +1673,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure post_updated event validates that the discussionid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'discussionid' value must be set in other.
|
||||
*/
|
||||
public function test_post_updated_discussionid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -1739,14 +1698,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('forumid' => $forum->id, 'forumtype' => $forum->type)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'discussionid' value must be set in other.");
|
||||
\mod_forum\event\post_updated::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure post_updated event validates that the forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_post_updated_forumid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -1772,14 +1730,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('discussionid' => $discussion->id, 'forumtype' => $forum->type)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'forumid' value must be set in other.");
|
||||
\mod_forum\event\post_updated::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure post_updated event validates that the forumtype is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumtype' value must be set in other.
|
||||
*/
|
||||
public function test_post_updated_forumtype_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -1805,14 +1762,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('discussionid' => $discussion->id, 'forumid' => $forum->id)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'forumtype' value must be set in other.");
|
||||
\mod_forum\event\post_updated::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure post_updated event validates that the contextlevel is correct.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_post_updated_context_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -1838,6 +1794,8 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'other' => array('discussionid' => $discussion->id, 'forumid' => $forum->id, 'forumtype' => $forum->type)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\post_updated::create($params);
|
||||
}
|
||||
|
||||
@@ -1988,7 +1946,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
// Checking that the event contains the expected values.
|
||||
$this->assertInstanceOf('\mod_forum\event\discussion_subscription_created', $event);
|
||||
|
||||
|
||||
$cm = get_coursemodule_from_instance('forum', $discussion->forum);
|
||||
$context = \context_module::instance($cm->id);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
@@ -2064,9 +2021,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test contextlevel validation of discussion_subscription_created event.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_discussion_subscription_created_validation_contextlevel() {
|
||||
global $CFG, $DB;
|
||||
@@ -2115,14 +2069,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
);
|
||||
|
||||
// Without an invalid context.
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\discussion_subscription_created::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test discussion validation of discussion_subscription_created event.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'discussion' value must be set in other.
|
||||
*/
|
||||
public function test_discussion_subscription_created_validation_discussion() {
|
||||
global $CFG, $DB;
|
||||
@@ -2168,14 +2121,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'discussion' value must be set in other.");
|
||||
\mod_forum\event\discussion_subscription_created::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test forumid validation of discussion_subscription_created event.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_discussion_subscription_created_validation_forumid() {
|
||||
global $CFG, $DB;
|
||||
@@ -2221,14 +2173,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'forumid' value must be set in other.");
|
||||
\mod_forum\event\discussion_subscription_created::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test relateduserid validation of discussion_subscription_created event.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'relateduserid' must be set.
|
||||
*/
|
||||
public function test_discussion_subscription_created_validation_relateduserid() {
|
||||
global $CFG, $DB;
|
||||
@@ -2276,6 +2227,8 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'relateduserid' must be set.");
|
||||
\mod_forum\event\discussion_subscription_created::create($params);
|
||||
}
|
||||
|
||||
@@ -2320,7 +2273,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
// Checking that the event contains the expected values.
|
||||
$this->assertInstanceOf('\mod_forum\event\discussion_subscription_deleted', $event);
|
||||
|
||||
|
||||
$cm = get_coursemodule_from_instance('forum', $discussion->forum);
|
||||
$context = \context_module::instance($cm->id);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
@@ -2420,9 +2372,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test contextlevel validation of discussion_subscription_deleted event.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_discussion_subscription_deleted_validation_contextlevel() {
|
||||
global $CFG, $DB;
|
||||
@@ -2471,14 +2420,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
);
|
||||
|
||||
// Without an invalid context.
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage('Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\discussion_subscription_deleted::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test discussion validation of discussion_subscription_deleted event.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'discussion' value must be set in other.
|
||||
*/
|
||||
public function test_discussion_subscription_deleted_validation_discussion() {
|
||||
global $CFG, $DB;
|
||||
@@ -2524,14 +2472,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'discussion' value must be set in other.");
|
||||
\mod_forum\event\discussion_subscription_deleted::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test forumid validation of discussion_subscription_deleted event.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_discussion_subscription_deleted_validation_forumid() {
|
||||
global $CFG, $DB;
|
||||
@@ -2577,14 +2524,13 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'forumid' value must be set in other.");
|
||||
\mod_forum\event\discussion_subscription_deleted::create($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test relateduserid validation of discussion_subscription_deleted event.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'relateduserid' must be set.
|
||||
*/
|
||||
public function test_discussion_subscription_deleted_validation_relateduserid() {
|
||||
global $CFG, $DB;
|
||||
@@ -2632,6 +2578,8 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$this->expectExceptionMessage("The 'relateduserid' must be set.");
|
||||
\mod_forum\event\discussion_subscription_deleted::create($params);
|
||||
}
|
||||
|
||||
|
||||
@@ -112,10 +112,6 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
$sink->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException require_login_exception
|
||||
* @expectedExceptionMessage Activity is hidden
|
||||
*/
|
||||
public function test_view_glossary_without_permission() {
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
@@ -134,13 +130,11 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// Assertion.
|
||||
$this->setUser($u1);
|
||||
$this->expectException(require_login_exception::class);
|
||||
$this->expectExceptionMessage('Activity is hidden');
|
||||
mod_glossary_external::view_glossary($g1->id, 'letter');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException require_login_exception
|
||||
* @expectedExceptionMessage Activity is hidden
|
||||
*/
|
||||
public function test_view_entry() {
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
@@ -188,6 +182,8 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
}
|
||||
|
||||
// Test non-readable entry.
|
||||
$this->expectException(require_login_exception::class);
|
||||
$this->expectExceptionMessage('Activity is hidden');
|
||||
mod_glossary_external::view_entry($e4->id);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ class quizaccess_seb_link_generator_testcase extends advanced_testcase {
|
||||
*/
|
||||
public function test_course_module_does_not_exist() {
|
||||
$this->expectException(dml_exception::class);
|
||||
$this->expectExceptionMessageRegExp("/^Can't find data record in database.*/");
|
||||
$this->expectExceptionMessageMatches("/^Can't find data record in database.*/");
|
||||
$generator = link_generator::get_link(123456, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,9 +259,6 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
), $structure);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_remove_first_section() {
|
||||
$quizobj = $this->create_test_quiz(array(
|
||||
'Heading 1',
|
||||
@@ -272,6 +269,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
$sections = $structure->get_sections();
|
||||
$section = reset($sections);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$structure->remove_section_heading($section->id);
|
||||
}
|
||||
|
||||
@@ -436,9 +434,6 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
), $structure);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_move_slot_too_small_page_number_detected() {
|
||||
$quizobj = $this->create_test_quiz(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
@@ -449,12 +444,10 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(3)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(2)->slotid;
|
||||
$this->expectException(coding_exception::class);
|
||||
$structure->move_slot($idtomove, $idmoveafter, '1');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_move_slot_too_large_page_number_detected() {
|
||||
$quizobj = $this->create_test_quiz(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
@@ -465,6 +458,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(1)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(2)->slotid;
|
||||
$this->expectException(coding_exception::class);
|
||||
$structure->move_slot($idtomove, $idmoveafter, '4');
|
||||
}
|
||||
|
||||
@@ -722,8 +716,6 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Unit test to make sue it is not possible to remove all slots in a section at once.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_remove_all_slots_in_a_section() {
|
||||
$quizobj = $this->create_test_quiz(array(
|
||||
@@ -735,12 +727,10 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
|
||||
$structure->remove_slot(1);
|
||||
$this->expectException(coding_exception::class);
|
||||
$structure->remove_slot(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_remove_last_slot_in_a_section() {
|
||||
$quizobj = $this->create_test_quiz(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
@@ -750,6 +740,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$structure->remove_slot(3);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,8 +59,6 @@ class mod_scorm_event_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests for attempt deleted event
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_attempt_deleted_event() {
|
||||
|
||||
@@ -87,11 +85,11 @@ class mod_scorm_event_testcase extends advanced_testcase {
|
||||
$this->assertEventContextNotUsed($event);
|
||||
|
||||
// Test event validations.
|
||||
$this->expectException(coding_exception::class);
|
||||
\mod_scorm\event\attempt_deleted::create(array(
|
||||
'contextid' => 5,
|
||||
'relateduserid' => 2
|
||||
));
|
||||
$this->fail('event \\mod_scorm\\event\\attempt_deleted is not validating events properly');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,8 +229,6 @@ class mod_scorm_event_testcase extends advanced_testcase {
|
||||
/** Tests for sco launched event.
|
||||
*
|
||||
* There is no api involved so the best we can do is test legacy data and validations by triggering event manually.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_sco_launched_event() {
|
||||
$this->resetAfterTest();
|
||||
@@ -256,12 +252,12 @@ class mod_scorm_event_testcase extends advanced_testcase {
|
||||
$this->assertEventContextNotUsed($event);
|
||||
|
||||
// Test validations.
|
||||
$this->expectException(coding_exception::class);
|
||||
\mod_scorm\event\sco_launched::create(array(
|
||||
'objectid' => $this->eventscorm->id,
|
||||
'context' => context_module::instance($this->eventcm->id),
|
||||
'courseid' => $this->eventcourse->id,
|
||||
));
|
||||
$this->fail('Event \\mod_scorm\\event\\sco_launched is not validating "loadedcontent" properly');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -174,9 +174,6 @@ class mod_scorm_external_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals(1, $result['attemptscount']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_mod_scorm_get_scorm_attempt_count_others_as_student() {
|
||||
// Create a second student.
|
||||
$student2 = self::getDataGenerator()->create_user();
|
||||
@@ -186,27 +183,24 @@ class mod_scorm_external_testcase extends externallib_advanced_testcase {
|
||||
self::setUser($student2);
|
||||
|
||||
// I should not be able to view the attempts of another student.
|
||||
$this->expectException(required_capability_exception::class);
|
||||
mod_scorm_external::get_scorm_attempt_count($this->scorm->id, $this->student->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_mod_scorm_get_scorm_attempt_count_invalid_instanceid() {
|
||||
// As student.
|
||||
self::setUser($this->student);
|
||||
|
||||
// Test invalid instance id.
|
||||
$this->expectException(moodle_exception::class);
|
||||
mod_scorm_external::get_scorm_attempt_count(0, $this->student->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_mod_scorm_get_scorm_attempt_count_invalid_userid() {
|
||||
// As student.
|
||||
self::setUser($this->student);
|
||||
|
||||
$this->expectException(moodle_exception::class);
|
||||
mod_scorm_external::get_scorm_attempt_count($this->scorm->id, -1);
|
||||
}
|
||||
|
||||
|
||||
@@ -459,30 +459,26 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test get_subwiki_pages using an invalid wiki instance.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_subwiki_pages_invalid_instance() {
|
||||
$this->expectException(moodle_exception::class);
|
||||
mod_wiki_external::get_subwiki_pages(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_subwiki_pages using a user not enrolled in the course.
|
||||
*
|
||||
* @expectedException require_login_exception
|
||||
*/
|
||||
public function test_get_subwiki_pages_unenrolled_user() {
|
||||
// Create and use the user.
|
||||
$usernotenrolled = self::getDataGenerator()->create_user();
|
||||
$this->setUser($usernotenrolled);
|
||||
|
||||
$this->expectException(require_login_exception::class);
|
||||
mod_wiki_external::get_subwiki_pages($this->wiki->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_subwiki_pages using a hidden wiki as student.
|
||||
*
|
||||
* @expectedException require_login_exception
|
||||
*/
|
||||
public function test_get_subwiki_pages_hidden_wiki_as_student() {
|
||||
// Create a hidden wiki and try to get the list of pages.
|
||||
@@ -490,13 +486,12 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
|
||||
array('course' => $this->course->id, 'visible' => false));
|
||||
|
||||
$this->setUser($this->student);
|
||||
$this->expectException(require_login_exception::class);
|
||||
mod_wiki_external::get_subwiki_pages($hiddenwiki->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_subwiki_pages without the viewpage capability.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_subwiki_pages_without_viewpage_capability() {
|
||||
// Prohibit capability = mod/wiki:viewpage on the course for students.
|
||||
@@ -505,38 +500,35 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
|
||||
$this->setUser($this->student);
|
||||
$this->expectException(moodle_exception::class);
|
||||
mod_wiki_external::get_subwiki_pages($this->wiki->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_subwiki_pages using an invalid userid.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_subwiki_pages_invalid_userid() {
|
||||
// Create an individual wiki.
|
||||
$indwiki = $this->getDataGenerator()->create_module('wiki',
|
||||
array('course' => $this->course->id, 'wikimode' => 'individual'));
|
||||
|
||||
$this->expectException(moodle_exception::class);
|
||||
mod_wiki_external::get_subwiki_pages($indwiki->id, 0, -10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_subwiki_pages using an invalid groupid.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_subwiki_pages_invalid_groupid() {
|
||||
// Create testing data.
|
||||
$this->create_collaborative_wikis_with_groups();
|
||||
|
||||
$this->expectException(moodle_exception::class);
|
||||
mod_wiki_external::get_subwiki_pages($this->wikisep->id, -111);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_subwiki_pages, check that a student can't see another user pages in an individual wiki without groups.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_subwiki_pages_individual_student_see_other_user() {
|
||||
// Create an individual wiki.
|
||||
@@ -544,62 +536,59 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
|
||||
array('course' => $this->course->id, 'wikimode' => 'individual'));
|
||||
|
||||
$this->setUser($this->student);
|
||||
$this->expectException(moodle_exception::class);
|
||||
mod_wiki_external::get_subwiki_pages($indwiki->id, 0, $this->teacher->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_subwiki_pages, check that a student can't get the pages from another group in
|
||||
* a collaborative wiki using separate groups.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_subwiki_pages_collaborative_separate_groups_student_see_other_group() {
|
||||
// Create testing data.
|
||||
$this->create_collaborative_wikis_with_groups();
|
||||
|
||||
$this->setUser($this->student);
|
||||
$this->expectException(moodle_exception::class);
|
||||
mod_wiki_external::get_subwiki_pages($this->wikisep->id, $this->group2->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_subwiki_pages, check that a student can't get the pages from another group in
|
||||
* an individual wiki using separate groups.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_subwiki_pages_individual_separate_groups_student_see_other_group() {
|
||||
// Create testing data.
|
||||
$this->create_individual_wikis_with_groups();
|
||||
|
||||
$this->setUser($this->student);
|
||||
$this->expectException(moodle_exception::class);
|
||||
mod_wiki_external::get_subwiki_pages($this->wikisepind->id, $this->group2->id, $this->teacher->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_subwiki_pages, check that a student can't get the pages from all participants in
|
||||
* a collaborative wiki using separate groups.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_subwiki_pages_collaborative_separate_groups_student_see_all_participants() {
|
||||
// Create testing data.
|
||||
$this->create_collaborative_wikis_with_groups();
|
||||
|
||||
$this->setUser($this->student);
|
||||
$this->expectException(moodle_exception::class);
|
||||
mod_wiki_external::get_subwiki_pages($this->wikisep->id, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_subwiki_pages, check that a student can't get the pages from all participants in
|
||||
* an individual wiki using separate groups.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_subwiki_pages_individual_separate_groups_student_see_all_participants() {
|
||||
// Create testing data.
|
||||
$this->create_individual_wikis_with_groups();
|
||||
|
||||
$this->setUser($this->student);
|
||||
$this->expectException(moodle_exception::class);
|
||||
mod_wiki_external::get_subwiki_pages($this->wikisepind->id, 0, $this->teacher->id);
|
||||
}
|
||||
|
||||
@@ -921,30 +910,26 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test get_page_contents using an invalid pageid.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_page_contents_invalid_pageid() {
|
||||
$this->expectException(moodle_exception::class);
|
||||
mod_wiki_external::get_page_contents(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_page_contents using a user not enrolled in the course.
|
||||
*
|
||||
* @expectedException require_login_exception
|
||||
*/
|
||||
public function test_get_page_contents_unenrolled_user() {
|
||||
// Create and use the user.
|
||||
$usernotenrolled = self::getDataGenerator()->create_user();
|
||||
$this->setUser($usernotenrolled);
|
||||
|
||||
$this->expectException(require_login_exception::class);
|
||||
mod_wiki_external::get_page_contents($this->firstpage->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_page_contents using a hidden wiki as student.
|
||||
*
|
||||
* @expectedException require_login_exception
|
||||
*/
|
||||
public function test_get_page_contents_hidden_wiki_as_student() {
|
||||
// Create a hidden wiki and try to get a page contents.
|
||||
@@ -953,13 +938,12 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
|
||||
$hiddenpage = $this->getDataGenerator()->get_plugin_generator('mod_wiki')->create_page($hiddenwiki);
|
||||
|
||||
$this->setUser($this->student);
|
||||
$this->expectException(require_login_exception::class);
|
||||
mod_wiki_external::get_page_contents($hiddenpage->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_page_contents without the viewpage capability.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_page_contents_without_viewpage_capability() {
|
||||
// Prohibit capability = mod/wiki:viewpage on the course for students.
|
||||
@@ -968,20 +952,20 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
|
||||
$this->setUser($this->student);
|
||||
$this->expectException(moodle_exception::class);
|
||||
mod_wiki_external::get_page_contents($this->firstpage->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_page_contents, check that a student can't get a page from another group when
|
||||
* using separate groups.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_page_contents_separate_groups_student_see_other_group() {
|
||||
// Create testing data.
|
||||
$this->create_individual_wikis_with_groups();
|
||||
|
||||
$this->setUser($this->student);
|
||||
$this->expectException(moodle_exception::class);
|
||||
mod_wiki_external::get_page_contents($this->fpsepg2indt->id);
|
||||
}
|
||||
|
||||
@@ -1079,14 +1063,13 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
|
||||
/**
|
||||
* Test get_subwiki_files, check that a student can't get files from another group's subwiki when
|
||||
* using separate groups.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_subwiki_files_separate_groups_student_see_other_group() {
|
||||
// Create testing data.
|
||||
$this->create_collaborative_wikis_with_groups();
|
||||
|
||||
$this->setUser($this->student);
|
||||
$this->expectException(moodle_exception::class);
|
||||
mod_wiki_external::get_subwiki_files($this->wikisep->id, $this->group2->id);
|
||||
}
|
||||
|
||||
|
||||
@@ -114,9 +114,6 @@ class workshopallocation_random_testcase extends advanced_testcase {
|
||||
), $submissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_index_submissions_by_authors_duplicate_author() {
|
||||
// fixture setup
|
||||
$submissions = array(
|
||||
@@ -124,6 +121,7 @@ class workshopallocation_random_testcase extends advanced_testcase {
|
||||
87 => (object)array('id' => 121, 'authorid' => 3),
|
||||
);
|
||||
// exercise SUT
|
||||
$this->expectException(moodle_exception::class);
|
||||
$submissions = $this->allocator->index_submissions_by_authors($submissions);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,14 +78,12 @@ class workshop_accumulative_strategy_testcase extends advanced_testcase {
|
||||
$this->assertEquals(grade_floatval(5/20 * 100), $suggested);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_calculate_peer_grade_negative_weight() {
|
||||
// fixture set-up
|
||||
$this->strategy->dimensions[1003] = (object)array('grade' => '20', 'weight' => '-1');
|
||||
$grades[] = (object)array('dimensionid' => 1003, 'grade' => '20');
|
||||
// exercise SUT
|
||||
$this->expectException(coding_exception::class);
|
||||
$suggested = $this->strategy->calculate_peer_grade($grades);
|
||||
}
|
||||
|
||||
@@ -178,9 +176,6 @@ class workshop_accumulative_strategy_testcase extends advanced_testcase {
|
||||
$this->assertEquals(grade_floatval((1/2*2 + 4/6*3)/5 * 100), $suggested);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_calculate_peer_grade_scale_exception() {
|
||||
$this->resetAfterTest(true);
|
||||
// fixture set-up
|
||||
@@ -189,6 +184,7 @@ class workshop_accumulative_strategy_testcase extends advanced_testcase {
|
||||
$grades[] = (object)array('dimensionid' => 1012, 'grade' => '4.00000'); // exceeds the number of scale items
|
||||
|
||||
// Exercise SUT.
|
||||
$this->expectException(coding_exception::class);
|
||||
$suggested = $this->strategy->calculate_peer_grade($grades);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,9 +320,6 @@ class mod_workshop_internal_api_testcase extends advanced_testcase {
|
||||
$this->assertEquals($part, $total * $percent / 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_percent_to_value_negative() {
|
||||
$this->resetAfterTest(true);
|
||||
// fixture setup
|
||||
@@ -330,12 +327,10 @@ class mod_workshop_internal_api_testcase extends advanced_testcase {
|
||||
$percent = -7.098;
|
||||
|
||||
// exercise SUT
|
||||
$this->expectException(coding_exception::class);
|
||||
$part = workshop::percent_to_value($percent, $total);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_percent_to_value_over_hundred() {
|
||||
$this->resetAfterTest(true);
|
||||
// fixture setup
|
||||
@@ -343,6 +338,7 @@ class mod_workshop_internal_api_testcase extends advanced_testcase {
|
||||
$percent = 121.08;
|
||||
|
||||
// exercise SUT
|
||||
$this->expectException(coding_exception::class);
|
||||
$part = workshop::percent_to_value($percent, $total);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,39 +40,31 @@ require_once(__DIR__ . '/../behaviour.php');
|
||||
*/
|
||||
class qbehaviour_missing_test extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_missing_cannot_start() {
|
||||
$qa = new question_attempt(test_question_maker::make_question('truefalse', 'true'), 0);
|
||||
$behaviour = new qbehaviour_missing($qa, 'deferredfeedback');
|
||||
$this->expectException(moodle_exception::class);
|
||||
$behaviour->init_first_step(new question_attempt_step(array()), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_missing_cannot_process() {
|
||||
$qa = new question_attempt(test_question_maker::make_question('truefalse', 'true'), 0);
|
||||
$behaviour = new qbehaviour_missing($qa, 'deferredfeedback');
|
||||
$this->expectException(moodle_exception::class);
|
||||
$behaviour->process_action(new question_attempt_pending_step(array()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_missing_cannot_get_min_fraction() {
|
||||
$qa = new question_attempt(test_question_maker::make_question('truefalse', 'true'), 0);
|
||||
$behaviour = new qbehaviour_missing($qa, 'deferredfeedback');
|
||||
$this->expectException(moodle_exception::class);
|
||||
$behaviour->get_min_fraction();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_missing_cannot_get_max_fraction() {
|
||||
$qa = new question_attempt(test_question_maker::make_question('truefalse', 'true'), 0);
|
||||
$behaviour = new qbehaviour_missing($qa, 'deferredfeedback');
|
||||
$this->expectException(moodle_exception::class);
|
||||
$behaviour->get_max_fraction();
|
||||
}
|
||||
|
||||
|
||||
@@ -57,10 +57,8 @@ class question_attempt_with_steps_test extends advanced_testcase {
|
||||
$this->qa = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_step_before_start() {
|
||||
$this->expectException(moodle_exception::class);
|
||||
$step = $this->qa->get_step(-1);
|
||||
}
|
||||
|
||||
@@ -74,10 +72,8 @@ class question_attempt_with_steps_test extends advanced_testcase {
|
||||
$this->assertEquals(2, $step->get_qt_var('i'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_step_past_end() {
|
||||
$this->expectException(moodle_exception::class);
|
||||
$step = $this->qa->get_step(3);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,10 +87,8 @@ class question_attempt_iterator_test extends advanced_testcase {
|
||||
$this->assertFalse(isset($this->iterator[3]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_offsetGet_before_start() {
|
||||
$this->expectException(moodle_exception::class);
|
||||
$step = $this->iterator[0];
|
||||
}
|
||||
|
||||
@@ -102,24 +100,18 @@ class question_attempt_iterator_test extends advanced_testcase {
|
||||
$this->assertSame($this->qas[2], $this->iterator[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_offsetGet_past_end() {
|
||||
$this->expectException(moodle_exception::class);
|
||||
$step = $this->iterator[3];
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_cannot_set() {
|
||||
$this->expectException(moodle_exception::class);
|
||||
$this->iterator[0] = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_cannot_unset() {
|
||||
$this->expectException(moodle_exception::class);
|
||||
unset($this->iterator[2]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,10 +104,8 @@ class question_attempt_step_iterator_test extends advanced_testcase {
|
||||
$this->assertFalse(isset($this->iterator[3]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_offsetGet_before_start() {
|
||||
$this->expectException(moodle_exception::class);
|
||||
$step = $this->iterator[-1];
|
||||
}
|
||||
|
||||
@@ -121,24 +119,18 @@ class question_attempt_step_iterator_test extends advanced_testcase {
|
||||
$this->assertEquals(2, $step->get_qt_var('i'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_offsetGet_past_end() {
|
||||
$this->expectException(moodle_exception::class);
|
||||
$step = $this->iterator[3];
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_cannot_set() {
|
||||
$this->expectException(moodle_exception::class);
|
||||
$this->iterator[0] = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_cannot_unset() {
|
||||
$this->expectException(moodle_exception::class);
|
||||
unset($this->iterator[2]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,11 +45,9 @@ class question_engine_test extends advanced_testcase {
|
||||
$this->assertTrue(class_exists('qbehaviour_deferredfeedback'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_load_behaviour_class_missing() {
|
||||
// Exercise SUT
|
||||
$this->expectException(moodle_exception::class);
|
||||
question_engine::load_behaviour_class('nonexistantbehaviour');
|
||||
}
|
||||
|
||||
|
||||
@@ -206,24 +206,18 @@ class question_utils_test extends advanced_testcase {
|
||||
$this->assertEquals('Z', question_utils::int_to_letter(26));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_int_to_roman_too_small() {
|
||||
$this->expectException(moodle_exception::class);
|
||||
question_utils::int_to_roman(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_int_to_roman_too_big() {
|
||||
$this->expectException(moodle_exception::class);
|
||||
question_utils::int_to_roman(4000);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_int_to_roman_not_int() {
|
||||
$this->expectException(moodle_exception::class);
|
||||
question_utils::int_to_roman(1.5);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,32 +48,23 @@ class qtype_calculated_variable_substituter_test extends advanced_testcase {
|
||||
$this->assertEquals(1, $vs->calculate('{a}-{b}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_cannot_use_nonnumbers() {
|
||||
$this->expectException(moodle_exception::class);
|
||||
$vs = new qtype_calculated_variable_substituter(array('a' => 'frog', 'b' => -2), '.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_invalid_expression() {
|
||||
$vs = new qtype_calculated_variable_substituter(array('a' => 1, 'b' => 2), '.');
|
||||
$this->expectException(moodle_exception::class);
|
||||
$vs->calculate('{a} + {b}?');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_tricky_invalid_expression() {
|
||||
$vs = new qtype_calculated_variable_substituter(array('a' => 1, 'b' => 2), '.');
|
||||
$this->expectException(moodle_exception::class);
|
||||
$vs->calculate('{a}{b}'); // Have to make sure this does not just evaluate to 12.
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_division_by_zero_expression() {
|
||||
|
||||
if (intval(PHP_VERSION) < 7) {
|
||||
@@ -81,6 +72,7 @@ class qtype_calculated_variable_substituter_test extends advanced_testcase {
|
||||
}
|
||||
|
||||
$vs = new qtype_calculated_variable_substituter(array('a' => 1, 'b' => 0), '.');
|
||||
$this->expectException(moodle_exception::class);
|
||||
$vs->calculate('{a} / {b}');
|
||||
}
|
||||
|
||||
|
||||
@@ -67,18 +67,14 @@ class qtype_missing_test extends question_testcase {
|
||||
return $questiondata;
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_cannot_grade() {
|
||||
$q = new qtype_missingtype_question();
|
||||
$this->expectException(moodle_exception::class);
|
||||
$q->grade_response(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_load_qtype_strict() {
|
||||
$this->expectException(moodle_exception::class);
|
||||
$qtype = question_bank::get_qtype('strange_unknown');
|
||||
}
|
||||
|
||||
|
||||
@@ -88,9 +88,6 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
$this->assertSame('class1 class2', $category->classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_validate_after_order1() {
|
||||
$category = new \phpunit_fixture_myprofile_category('category', 'title', null);
|
||||
|
||||
@@ -103,13 +100,11 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
$category->add_node($node2);
|
||||
$category->add_node($node1);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$category->validate_after_order();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_validate_after_order2() {
|
||||
$category = new \phpunit_fixture_myprofile_category('category', 'title', null);
|
||||
|
||||
@@ -122,6 +117,7 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
$category->add_node($node2);
|
||||
$category->add_node($node1);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$category->validate_after_order();
|
||||
|
||||
}
|
||||
@@ -171,8 +167,6 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test category::sort_nodes().
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_sort_nodes1() {
|
||||
$category = new \phpunit_fixture_myprofile_category('category', 'title', null);
|
||||
@@ -219,6 +213,7 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
// Add a node with invalid 'after' and make sure an exception is thrown.
|
||||
$node7 = new \core_user\output\myprofile\node('category', 'node7', 'nodetitle', 'noderandom');
|
||||
$category->add_node($node7);
|
||||
$this->expectException(coding_exception::class);
|
||||
$category->sort_nodes();
|
||||
}
|
||||
|
||||
@@ -264,8 +259,6 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test tree::add_node().
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_tree_add_node() {
|
||||
$tree = new \phpunit_fixture_myprofile_tree();
|
||||
@@ -276,13 +269,12 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
$this->assertEquals($node1, $node);
|
||||
|
||||
// Can't add node with same name.
|
||||
$this->expectException(coding_exception::class);
|
||||
$tree->add_node($node1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test tree::add_category().
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_tree_add_category() {
|
||||
$tree = new \phpunit_fixture_myprofile_tree();
|
||||
@@ -293,6 +285,7 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
$this->assertEquals($category1, $category);
|
||||
|
||||
// Can't add node with same name.
|
||||
$this->expectException(coding_exception::class);
|
||||
$tree->add_category($category1);
|
||||
}
|
||||
|
||||
@@ -341,8 +334,6 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test tree::sort_categories().
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_sort_categories() {
|
||||
$tree = new \phpunit_fixture_myprofile_tree('category', 'title', null);
|
||||
@@ -381,6 +372,7 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
$this->assertEquals($category6, $category);
|
||||
|
||||
// Can't add category with same name.
|
||||
$this->expectException(coding_exception::class);
|
||||
$tree->add_category($category1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user