diff --git a/admin/tool/cohortroles/tests/api_test.php b/admin/tool/cohortroles/tests/api_test.php
index 27c4cd8227ba7..2fa061b4ca0d3 100644
--- a/admin/tool/cohortroles/tests/api_test.php
+++ b/admin/tool/cohortroles/tests/api_test.php
@@ -62,9 +62,10 @@ protected function setUp() {
cohort_add_member($this->cohort->id, $this->userassignover->id);
}
-
+ /**
+ * @expectedException required_capability_exception
+ */
public function test_create_cohort_role_assignment_without_permission() {
- $this->setExpectedException('required_capability_exception');
$this->setUser($this->userassignto);
$params = (object) array(
'userid' => $this->userassignto->id,
@@ -74,8 +75,10 @@ public function test_create_cohort_role_assignment_without_permission() {
api::create_cohort_role_assignment($params);
}
+ /**
+ * @expectedException core_competency\invalid_persistent_exception
+ */
public function test_create_cohort_role_assignment_with_invalid_data() {
- $this->setExpectedException('core_competency\invalid_persistent_exception');
$this->setAdminUser();
$params = (object) array(
'userid' => $this->userassignto->id,
@@ -99,6 +102,9 @@ public function test_create_cohort_role_assignment() {
$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(
@@ -107,11 +113,13 @@ public function test_delete_cohort_role_assignment_without_permission() {
'cohortid' => $this->cohort->id
);
$result = api::create_cohort_role_assignment($params);
- $this->setExpectedException('required_capability_exception');
$this->setUser($this->userassignto);
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(
@@ -120,7 +128,6 @@ public function test_delete_cohort_role_assignment_with_invalid_data() {
'cohortid' => $this->cohort->id
);
$result = api::create_cohort_role_assignment($params);
- $this->setExpectedException('dml_missing_record_exception');
api::delete_cohort_role_assignment($result->get_id() + 1);
}
diff --git a/admin/tool/langimport/tests/events_test.php b/admin/tool/langimport/tests/events_test.php
index 0a75b3487205a..d2164cf443c70 100644
--- a/admin/tool/langimport/tests/events_test.php
+++ b/admin/tool/langimport/tests/events_test.php
@@ -56,8 +56,11 @@ public function test_langpack_updated() {
$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->setExpectedException('coding_exception', 'The \'langcode\' value must be set to a valid language code');
\tool_langimport\event\langpack_updated::event_with_langcode('broken langcode');
}
@@ -75,8 +78,11 @@ public function test_langpack_installed() {
$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->setExpectedException('coding_exception', 'The \'langcode\' value must be set to a valid language code');
\tool_langimport\event\langpack_imported::event_with_langcode('broken langcode');
}
@@ -94,8 +100,11 @@ public function test_langpack_removed() {
$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->setExpectedException('coding_exception', 'The \'langcode\' value must be set to a valid language code');
\tool_langimport\event\langpack_removed::event_with_langcode('broken langcode');
}
diff --git a/admin/tool/monitor/tests/generator_test.php b/admin/tool/monitor/tests/generator_test.php
index ca7f0034d6b34..7c4ae86587d49 100644
--- a/admin/tool/monitor/tests/generator_test.php
+++ b/admin/tool/monitor/tests/generator_test.php
@@ -89,7 +89,7 @@ public function test_create_subscription() {
$this->assertEquals(0, $subscription->cmid);
// Make sure rule id is always required.
- $this->setExpectedException('coding_exception');
+ $this->expectException('coding_exception');
unset($record->ruleid);
$monitorgenerator->create_subscription($record);
}
diff --git a/admin/tool/monitor/tests/subscription_test.php b/admin/tool/monitor/tests/subscription_test.php
index 3548c7f563dfd..b3511b5e846f1 100644
--- a/admin/tool/monitor/tests/subscription_test.php
+++ b/admin/tool/monitor/tests/subscription_test.php
@@ -42,7 +42,10 @@ public function setUp() {
$sub->id = 100;
$sub->name = 'My test rule';
$sub->courseid = 20;
- $this->subscription = $this->getMock('\tool_monitor\subscription',null, array($sub));
+ $mockbuilder = $this->getMockBuilder('\tool_monitor\subscription');
+ $mockbuilder->setMethods(null);
+ $mockbuilder->setConstructorArgs(array($sub));
+ $this->subscription = $mockbuilder->getMock();
}
/**
@@ -56,10 +59,11 @@ public function test_magic_isset() {
/**
* Test for the magic __get method.
+ *
+ * @expectedException coding_exception
*/
public function test_magic_get() {
$this->assertEquals(20, $this->subscription->courseid);
- $this->setExpectedException('coding_exception');
$this->subscription->ruleid;
}
}
diff --git a/admin/tool/uploadcourse/tests/course_test.php b/admin/tool/uploadcourse/tests/course_test.php
index 0b62e87938b7c..26dc5568a24b9 100644
--- a/admin/tool/uploadcourse/tests/course_test.php
+++ b/admin/tool/uploadcourse/tests/course_test.php
@@ -35,16 +35,21 @@
*/
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->setExpectedException('coding_exception');
$co->proceed();
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_proceed_when_prepare_failed() {
$this->resetAfterTest(true);
$mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
@@ -52,7 +57,6 @@ public function test_proceed_when_prepare_failed() {
$data = array();
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
$this->assertFalse($co->prepare());
- $this->setExpectedException('moodle_exception');
$co->proceed();
}
@@ -64,7 +68,7 @@ public function test_proceed_when_already_started() {
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
$this->assertTrue($co->prepare());
$co->proceed();
- $this->setExpectedException('coding_exception');
+ $this->expectException('coding_exception');
$co->proceed();
}
diff --git a/admin/tool/uploadcourse/tests/processor_test.php b/admin/tool/uploadcourse/tests/processor_test.php
index 1dd20dc1927f9..109c2434c23d3 100644
--- a/admin/tool/uploadcourse/tests/processor_test.php
+++ b/admin/tool/uploadcourse/tests/processor_test.php
@@ -160,6 +160,9 @@ public function test_shortname_template() {
$this->assertEquals('ID123: Course 1', $c->shortname);
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_empty_csv() {
$this->resetAfterTest(true);
@@ -171,10 +174,12 @@ public function test_empty_csv() {
$cir->init();
$options = array('mode' => tool_uploadcourse_processor::MODE_CREATE_NEW);
- $this->setExpectedException('moodle_exception');
$p = new tool_uploadcourse_processor($cir, $options, array());
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_not_enough_columns() {
$this->resetAfterTest(true);
@@ -189,7 +194,6 @@ public function test_not_enough_columns() {
$cir->init();
$options = array('mode' => tool_uploadcourse_processor::MODE_CREATE_NEW);
- $this->setExpectedException('moodle_exception');
$p = new tool_uploadcourse_processor($cir, $options, array());
}
diff --git a/backup/converter/moodle1/tests/moodle1_converter_test.php b/backup/converter/moodle1/tests/moodle1_converter_test.php
index 3209287216464..88681b8080248 100644
--- a/backup/converter/moodle1/tests/moodle1_converter_test.php
+++ b/backup/converter/moodle1/tests/moodle1_converter_test.php
@@ -88,18 +88,22 @@ public function test_convert_factory() {
$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->setExpectedException('moodle1_convert_storage_exception');
$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);
$converter->create_stash_storage();
$converter->set_stash('tempinfo', 12);
- $this->setExpectedException('moodle1_convert_empty_storage_exception');
try {
$converter->get_stash('anothertempinfo');
@@ -432,6 +436,9 @@ public function test_convert_path_explicit_recipes() {
$this->assertSame(null, $data['nothing']);
}
+ /**
+ * @expectedException convert_path_exception
+ */
public function test_grouped_data_on_nongrouped_convert_path() {
// prepare some grouped data
$data = array(
@@ -457,10 +464,12 @@ public function test_grouped_data_on_nongrouped_convert_path() {
$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->setExpectedException('convert_path_exception');
$data = $path->apply_recipes($data);
}
+ /**
+ * @expectedException convert_path_exception
+ */
public function test_grouped_convert_path_with_recipes() {
// prepare some grouped data
$data = array(
@@ -488,7 +497,6 @@ public function test_grouped_convert_path_with_recipes() {
$this->assertEquals('Heineken', $data['beers'][1]['beer']['name']);
// an attempt to provide explicit recipes on grouped elements throws exception
- $this->setExpectedException('convert_path_exception');
$path = new convert_path(
'beer_style', '/ROOT/BEER_STYLES/BEER_STYLE',
array(
@@ -573,7 +581,7 @@ public function test_inforef_manager() {
$inforef->add_ref('file', 45);
$inforef->add_refs('file', array(46, 47));
// todo test the write_refs() via some dummy xml_writer
- $this->setExpectedException('coding_exception');
+ $this->expectException('coding_exception');
$inforef->add_ref('unknown_referenced_item_name', 76);
}
}
diff --git a/backup/util/xml/parser/tests/parser_test.php b/backup/util/xml/parser/tests/parser_test.php
index 39bf2d75a7c27..7f9ea28b874f6 100644
--- a/backup/util/xml/parser/tests/parser_test.php
+++ b/backup/util/xml/parser/tests/parser_test.php
@@ -787,7 +787,7 @@ function helper_check_notifications_order_integrity($notifications) {
* - equal to "value" attribute of the tag (if present)
* - else, equal to tag name
*
- * We pass the whole UnitTestCase object to the processor in order to be
+ * We pass the whole advanced_testcase object to the processor in order to be
* able to perform the tests in the straight in the process
*/
class mock_auto_parser_processor extends progressive_parser_processor {
diff --git a/calendar/tests/externallib_test.php b/calendar/tests/externallib_test.php
index dc5041a49f44b..b25406863a959 100644
--- a/calendar/tests/externallib_test.php
+++ b/calendar/tests/externallib_test.php
@@ -131,6 +131,8 @@ public function test_create_calendar_events () {
/**
* Test delete_calendar_events
+ *
+ * @expectedException moodle_exception
*/
public function test_delete_calendar_events() {
global $DB, $USER;
@@ -247,7 +249,7 @@ public function test_delete_calendar_events() {
$groupevent = $this->create_calendar_event('group', $USER->id, 'group', 0, time(), $record);
$this->setGuestUser();
- $this->setExpectedException('moodle_exception');
+
$events = array(
array('eventid' => $siteevent->id, 'repeat' => 0),
array('eventid' => $courseevent->id, 'repeat' => 0),
diff --git a/calendar/tests/ical_test.php b/calendar/tests/ical_test.php
index cfc5bb3523d09..2fc3c02b68cb4 100644
--- a/calendar/tests/ical_test.php
+++ b/calendar/tests/ical_test.php
@@ -45,6 +45,9 @@ protected function setUp() {
require_once($CFG->dirroot . '/calendar/lib.php');
}
+ /**
+ * @expectedException coding_exception
+ */
public function test_calendar_update_subscription() {
$this->resetAfterTest(true);
@@ -71,7 +74,6 @@ public function test_calendar_update_subscription() {
$subscription = new stdClass();
$subscription->name = 'awesome4';
- $this->setExpectedException('coding_exception');
calendar_update_subscription($subscription);
}
diff --git a/calendar/tests/rrule_manager_tests.php b/calendar/tests/rrule_manager_tests.php
index 5232ab70ace64..a68d615673338 100644
--- a/calendar/tests/rrule_manager_tests.php
+++ b/calendar/tests/rrule_manager_tests.php
@@ -86,22 +86,24 @@ public function test_parse_rrule() {
/**
* Test exception is thrown for invalid property.
+ *
+ * @expectedException moodle_exception
*/
public function test_parse_rrule_validation() {
$rrule = "RANDOM=PROPERTY;";
- $this->setExpectedException('moodle_exception');
$mang = new core_tests_calendar_rrule_manager($rrule);
$mang->parse_rrule();
}
/**
* Test exception is thrown for invalid frequency.
+ *
+ * @expectedException moodle_exception
*/
public function test_freq_validation() {
$rrule = "FREQ=RANDOMLY;";
- $this->setExpectedException('moodle_exception');
$mang = new core_tests_calendar_rrule_manager($rrule);
$mang->parse_rrule();
}
diff --git a/cohort/tests/cohortlib_test.php b/cohort/tests/cohortlib_test.php
index 7403355493a70..04b37b1938520 100644
--- a/cohort/tests/cohortlib_test.php
+++ b/cohort/tests/cohortlib_test.php
@@ -64,6 +64,10 @@ public function test_cohort_add_cohort() {
$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;
@@ -72,7 +76,6 @@ public function test_cohort_add_cohort_missing_name() {
$cohort->description = 'test cohort desc';
$cohort->descriptionformat = FORMAT_HTML;
- $this->setExpectedException('coding_exception', 'Missing cohort name in cohort_add_cohort().');
cohort_add_cohort($cohort);
}
diff --git a/cohort/tests/externallib_test.php b/cohort/tests/externallib_test.php
index 3ca5fa2124826..f55eb1fa2c84f 100644
--- a/cohort/tests/externallib_test.php
+++ b/cohort/tests/externallib_test.php
@@ -34,6 +34,8 @@ 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;
@@ -97,12 +99,13 @@ public function test_create_cohorts() {
// Call without required capability.
$this->unassignUserCapability('moodle/cohort:manage', $contextid, $roleid);
- $this->setExpectedException('required_capability_exception');
$createdcohorts = core_cohort_external::create_cohorts(array($cohort3));
}
/**
* Test delete_cohorts
+ *
+ * @expectedException required_capability_exception
*/
public function test_delete_cohorts() {
global $USER, $CFG, $DB;
@@ -129,7 +132,6 @@ public function test_delete_cohorts() {
$cohort1 = self::getDataGenerator()->create_cohort();
$cohort2 = self::getDataGenerator()->create_cohort();
$this->unassignUserCapability('moodle/cohort:manage', $contextid, $roleid);
- $this->setExpectedException('required_capability_exception');
core_cohort_external::delete_cohorts(array($cohort1->id, $cohort2->id));
}
@@ -183,6 +185,8 @@ public function test_get_cohorts() {
/**
* Test update_cohorts
+ *
+ * @expectedException required_capability_exception
*/
public function test_update_cohorts() {
global $USER, $CFG, $DB;
@@ -224,7 +228,6 @@ public function test_update_cohorts() {
// Call without required capability.
$this->unassignUserCapability('moodle/cohort:manage', $context->id, $roleid);
- $this->setExpectedException('required_capability_exception');
core_cohort_external::update_cohorts(array($cohort1));
}
@@ -260,6 +263,8 @@ public function test_update_cohorts_invalid_id_param() {
/**
* Test update_cohorts without permission on the dest category.
+ *
+ * @expectedException required_capability_exception
*/
public function test_update_cohorts_missing_dest() {
global $USER, $CFG, $DB;
@@ -295,12 +300,13 @@ public function test_update_cohorts_missing_dest() {
// Call the external function.
// Should fail because we don't have permission on the dest category
- $this->setExpectedException('required_capability_exception');
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;
@@ -336,12 +342,13 @@ public function test_update_cohorts_missing_src() {
// Call the external function.
// Should fail because we don't have permission on the src category
- $this->setExpectedException('required_capability_exception');
core_cohort_external::update_cohorts(array($cohortupdate));
}
/**
* Test add_cohort_members
+ *
+ * @expectedException required_capability_exception
*/
public function test_add_cohort_members() {
global $DB;
@@ -387,12 +394,13 @@ public function test_add_cohort_members() {
'usertype' => array('type' => 'id', 'value' => '2')
);
$this->unassignUserCapability('moodle/cohort:assign', $contextid, $roleid);
- $this->setExpectedException('required_capability_exception');
$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;
@@ -444,7 +452,6 @@ public function test_delete_cohort_members() {
// Call without required capability.
$this->unassignUserCapability('moodle/cohort:assign', $context->id, $roleid);
- $this->setExpectedException('required_capability_exception');
core_cohort_external::delete_cohort_members(array($cohortdel1, $cohortdel2));
}
}
diff --git a/competency/tests/api_test.php b/competency/tests/api_test.php
index cc96253ee2dbf..cb815aaa0e602 100644
--- a/competency/tests/api_test.php
+++ b/competency/tests/api_test.php
@@ -166,6 +166,8 @@ public function test_get_template_related_contexts_with_capabilities() {
/**
* Test updating a template.
+ *
+ * @expectedException coding_exception
*/
public function test_update_template() {
$cat = $this->getDataGenerator()->create_category();
@@ -184,7 +186,6 @@ public function test_update_template() {
$this->assertEquals('success', $template->get_shortname());
// Trying to change the context.
- $this->setExpectedException('coding_exception');
api::update_template((object) array('id' => $template->get_id(), 'contextid' => context_coursecat::instance($cat->id)));
}
@@ -510,6 +511,9 @@ public function test_update_plan() {
}
}
+ /**
+ * @expectedException coding_exception
+ */
public function test_create_plan_from_template() {
$this->resetAfterTest(true);
$this->setAdminUser();
@@ -531,7 +535,6 @@ public function test_create_plan_from_template() {
$this->assertFalse($plan);
// Check that api::create_plan cannot be used.
- $this->setExpectedException('coding_exception');
unset($record->id);
$plan = api::create_plan($record);
}
@@ -753,6 +756,8 @@ public function test_update_template_updates_plans() {
/**
* Test that the method to complete a plan.
+ *
+ * @expectedException coding_exception
*/
public function test_complete_plan() {
global $DB;
@@ -833,7 +838,6 @@ public function test_complete_plan() {
}
// Completing a plan that is completed throws an exception.
- $this->setExpectedException('coding_exception');
api::complete_plan($plan);
}
@@ -4430,6 +4434,9 @@ public function test_delete_evidence() {
$this->assertTrue(evidence::record_exists($ev2->get_id()));
}
+ /**
+ * @expectedException required_capability_exception
+ */
public function test_delete_evidence_without_permissions() {
$this->resetAfterTest();
$dg = $this->getDataGenerator();
@@ -4442,7 +4449,6 @@ public function test_delete_evidence_without_permissions() {
$ev1 = $ccg->create_evidence(['usercompetencyid' => $uc1->get_id()]);
$this->setUser($u1);
- $this->setExpectedException('required_capability_exception');
api::delete_evidence($ev1);
}
diff --git a/competency/tests/course_competency_settings_test.php b/competency/tests/course_competency_settings_test.php
index 1897e8105f697..31f5e486c13ac 100644
--- a/competency/tests/course_competency_settings_test.php
+++ b/competency/tests/course_competency_settings_test.php
@@ -120,7 +120,7 @@ public function test_who_can_change_settings() {
$this->assertEquals(2, $usercompcourse->get_grade());
$this->setUser($u3);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
api::update_course_competency_settings($c1->id, (object) array('pushratingstouserplans' => false));
}
diff --git a/competency/tests/event_test.php b/competency/tests/event_test.php
index 95223a3a88aab..4554c29a32dbc 100644
--- a/competency/tests/event_test.php
+++ b/competency/tests/event_test.php
@@ -1360,6 +1360,9 @@ public function test_evidence_created() {
/**
* 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);
@@ -1385,7 +1388,6 @@ public function test_evidence_created_with_invalid_user_competency() {
'commentincontext', 'core', null, $recommend, null, 1);
// We expect this to fail and throw a coding exception.
- $this->setExpectedException('coding_exception', 'The user competency linked with this evidence is invalid.');
\core\event\competency_evidence_created::create_from_evidence($evidence, $otheruc, $recommend)->trigger();
}
diff --git a/competency/tests/exporter_test.php b/competency/tests/exporter_test.php
index eb4830b882d5d..101e1b46e6604 100644
--- a/competency/tests/exporter_test.php
+++ b/competency/tests/exporter_test.php
@@ -82,18 +82,22 @@ public function test_get_update_structure() {
$this->assertArrayNotHasKey('otherstrings', $structure->keys);
}
+ /**
+ * @expectedException coding_exception
+ */
public function test_invalid_data() {
global $PAGE;
- $this->setExpectedException('coding_exception');
$exporter = new core_competency_testable_exporter($this->invaliddata, $this->validrelated);
$output = $PAGE->get_renderer('tool_lp');
$result = $exporter->export($output);
}
+ /**
+ * @expectedException coding_exception
+ */
public function test_invalid_related() {
global $PAGE;
- $this->setExpectedException('coding_exception');
$exporter = new core_competency_testable_exporter($this->validdata, $this->invalidrelated);
$output = $PAGE->get_renderer('tool_lp');
diff --git a/competency/tests/external_test.php b/competency/tests/external_test.php
index 6be6bf0775df3..0b989bfee4ac7 100644
--- a/competency/tests/external_test.php
+++ b/competency/tests/external_test.php
@@ -303,9 +303,10 @@ protected function update_competency($id, $number) {
/**
* 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->setExpectedException('required_capability_exception');
$this->setUser($this->user);
$result = $this->create_competency_framework(1, true);
@@ -313,9 +314,10 @@ public function test_create_competency_frameworks_with_read_permissions() {
/**
* 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->setExpectedException('required_capability_exception');
$this->setUser($this->catuser);
$result = $this->create_competency_framework(1, false);
}
@@ -367,10 +369,11 @@ public function test_create_competency_frameworks_with_manage_permissions_in_cat
/**
* 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);
- $this->setExpectedException('invalid_parameter_exception');
$framework = array(
'shortname' => 'short',
'idnumber' => 'id;"number',
@@ -543,9 +546,10 @@ public function test_delete_competency_frameworks_with_manage_permissions_in_cat
/**
* Test we can delete a competency framework with read permissions.
+ *
+ * @expectedException required_capability_exception
*/
public function test_delete_competency_frameworks_with_read_permissions() {
- $this->setExpectedException('required_capability_exception');
$this->setUser($this->creator);
$result = $this->create_competency_framework(1, true);
@@ -624,9 +628,10 @@ public function test_update_framework_scale() {
/**
* Test we can update a competency framework with read permissions.
+ *
+ * @expectedException required_capability_exception
*/
public function test_update_competency_frameworks_with_read_permissions() {
- $this->setExpectedException('required_capability_exception');
$this->setUser($this->creator);
$result = $this->create_competency_framework(1, true);
@@ -757,9 +762,10 @@ public function test_list_and_count_competency_frameworks_with_read_permissions(
/**
* Test we can't create a competency with only read permissions.
+ *
+ * @expectedException required_capability_exception
*/
public function test_create_competency_with_read_permissions() {
- $this->setExpectedException('required_capability_exception');
$framework = $this->getDataGenerator()->get_plugin_generator('core_competency')->create_framework();
$this->setUser($this->user);
$competency = $this->create_competency(1, $framework->get_id());
@@ -818,11 +824,12 @@ public function test_create_competency_with_manage_permissions_in_category() {
/**
* 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);
$framework = $this->create_competency_framework(1, true);
- $this->setExpectedException('invalid_parameter_exception');
$competency = array(
'shortname' => 'shortname',
'idnumber' => 'id;"number',
@@ -995,9 +1002,10 @@ public function test_delete_competency_with_manage_permissions_in_category() {
/**
* Test we can delete a competency with read permissions.
+ *
+ * @expectedException required_capability_exception
*/
public function test_delete_competency_with_read_permissions() {
- $this->setExpectedException('required_capability_exception');
$this->setUser($this->creator);
$framework = $this->create_competency_framework(1, true);
$result = $this->create_competency(1, $framework->id);
@@ -1048,9 +1056,10 @@ public function test_update_competency_with_manage_permissions_in_category() {
/**
* Test we can update a competency with read permissions.
+ *
+ * @expectedException required_capability_exception
*/
public function test_update_competency_with_read_permissions() {
- $this->setExpectedException('required_capability_exception');
$this->setUser($this->creator);
$framework = $this->create_competency_framework(1, true);
$result = $this->create_competency(1, $framework->id);
@@ -1717,7 +1726,7 @@ public function test_reorder_template_competencies() {
$this->assertEquals($competency1->id, $r2->id);
$this->assertEquals($competency2->id, $r3->id);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
$this->setUser($this->user);
external::reorder_template_competency($template->id, $competency1->id, $competency2->id);
}
@@ -2694,7 +2703,7 @@ public function test_grade_competency_in_plan() {
$this->setUser($this->user);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
$evidence = external::grade_competency_in_plan($plan->get_id(), $c1->get_id(), 1);
}
@@ -2738,7 +2747,7 @@ public function test_update_course_competency_settings() {
$this->assertFalse((bool)$settings->get_pushratingstouserplans());
$this->setUser($compnoob);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
$result = external::update_course_competency_settings($course->id, array('pushratingstouserplans' => true));
}
diff --git a/competency/tests/persistent_test.php b/competency/tests/persistent_test.php
index b9dc0fda24b6e..fc8966c40993b 100644
--- a/competency/tests/persistent_test.php
+++ b/competency/tests/persistent_test.php
@@ -178,12 +178,15 @@ public function test_from_record() {
$this->assertEquals($data, $p->to_record());
}
+ /**
+ * @expectedException coding_exception
+ */
public function test_from_record_invalid_param() {
$p = new core_competency_testable_persistent();
$data = (object) array(
'invalidparam' => 'abc'
);
- $this->setExpectedException('coding_exception');
+
$p->from_record($data);
}
diff --git a/competency/tests/plan_test.php b/competency/tests/plan_test.php
index 865a5e2cdb516..6e9972fc12287 100644
--- a/competency/tests/plan_test.php
+++ b/competency/tests/plan_test.php
@@ -526,6 +526,10 @@ public function test_get_by_user_and_competency() {
$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();
@@ -567,7 +571,6 @@ public function test_get_competency() {
$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->setExpectedException('coding_exception', 'The competency does not belong to this template: ');
$p3->get_competency($c4->get_id());
}
}
diff --git a/course/tests/externallib_test.php b/course/tests/externallib_test.php
index 71372e7a4a3ec..ba7ed166a951f 100644
--- a/course/tests/externallib_test.php
+++ b/course/tests/externallib_test.php
@@ -120,7 +120,7 @@ public function test_create_categories() {
// Call without required capability
$this->unassignUserCapability('moodle/category:manage', $contextid, $roleid);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
$createdsubcats = core_course_external::create_categories($subcategories);
}
@@ -163,7 +163,7 @@ public function test_delete_categories() {
// Call without required capability
$this->unassignUserCapability('moodle/category:manage', $contextid, $roleid);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
$createdsubcats = core_course_external::delete_categories(
array(array('id' => $category3->id)));
}
@@ -261,7 +261,7 @@ public function test_get_categories() {
// Call without required capability (it will fail cause of the search on idnumber).
$this->unassignUserCapability('moodle/category:manage', $context->id, $roleid);
- $this->setExpectedException('moodle_exception');
+ $this->expectException('moodle_exception');
$categories = core_course_external::get_categories(array(
array('key' => 'id', 'value' => $category1->id),
array('key' => 'idnumber', 'value' => $category1->idnumber),
@@ -327,7 +327,7 @@ public function test_update_categories() {
// Call without required capability.
$this->unassignUserCapability('moodle/category:manage', $contextid, $roleid);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
core_course_external::update_categories($categories);
}
@@ -457,7 +457,7 @@ public function test_create_courses() {
// Call without required capability
$this->unassignUserCapability('moodle/course:create', $contextid, $roleid);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
$createdsubcats = core_course_external::create_courses($courses);
}
@@ -515,7 +515,7 @@ public function test_delete_courses() {
// Fail when the user is not allow to access the course (enrolled) or is not admin.
$this->setGuestUser();
- $this->setExpectedException('require_login_exception');
+ $this->expectException('require_login_exception');
$result = core_course_external::delete_courses(array($course3->id));
$result = external_api::clean_returnvalue(core_course_external::delete_courses_returns(), $result);
@@ -690,7 +690,7 @@ public function test_search_courses () {
$this->assertEquals($coursedata2['fullname'], $results['courses'][0]['fullname']);
// Search by block (use news_items default block). Should fail (only admins allowed).
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
$results = core_course_external::search_courses('blocklist', $blockid);
}
@@ -1518,7 +1518,8 @@ public function test_import_course_invalid_deletecontent_option() {
$course1 = self::getDataGenerator()->create_course();
$course2 = self::getDataGenerator()->create_course();
- $this->setExpectedException('moodle_exception', get_string('invalidextparam', 'webservice', -1));
+ $this->expectException('moodle_exception');
+ $this->expectExceptionMessage(get_string('invalidextparam', 'webservice', -1));
// Import from course1 to course2, with invalid option
core_course_external::import_course($course1->id, $course2->id, -1);;
}
diff --git a/enrol/tests/externallib_test.php b/enrol/tests/externallib_test.php
index a7d35ad4a385b..7695e3c7bc70b 100644
--- a/enrol/tests/externallib_test.php
+++ b/enrol/tests/externallib_test.php
@@ -316,7 +316,8 @@ public function test_get_enrolled_users_visibility($settings, $results) {
}
} else if (isset($expectations['exception'])) {
$exception = $expectations['exception'];
- $this->setExpectedException($exception['type'], $exception['message']);
+ $this->expectException($exception['type']);
+ $this->expectExceptionMessage($exception['message']);
} else {
// Failed, only canview and exception are supported.
$this->markTestIncomplete('Incomplete, only canview and exception are supported');
@@ -565,6 +566,8 @@ public function test_get_enrolled_users_with_parameters() {
/**
* 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';
@@ -572,7 +575,6 @@ public function test_get_enrolled_users_without_capability() {
// Call without required capability.
$this->unassignUserCapability($capability, $data->context->id, $data->roleid);
- $this->setExpectedException('moodle_exception');
$categories = core_enrol_external::get_enrolled_users($data->course->id);
}
diff --git a/enrol/tests/role_external_test.php b/enrol/tests/role_external_test.php
index 2a8c4a877ebe8..4009101fbf528 100644
--- a/enrol/tests/role_external_test.php
+++ b/enrol/tests/role_external_test.php
@@ -84,7 +84,7 @@ public function test_assign_roles() {
// Call without required capability.
$this->unassignUserCapability('moodle/role:assign', $context->id, $roleid);
- $this->setExpectedException('moodle_exception');
+ $this->expectException('moodle_exception');
$categories = core_role_external::assign_roles(
array('roleid' => 3, 'userid' => $USER->id, 'contextid' => $context->id));
}
@@ -138,7 +138,7 @@ public function test_unassign_roles() {
// Call without required capability.
$this->unassignUserCapability('moodle/role:assign', $context->id, $roleid);
- $this->setExpectedException('moodle_exception');
+ $this->expectException('moodle_exception');
$categories = core_role_external::unassign_roles(
array('roleid' => 3, 'userid' => $USER->id, 'contextid' => $context->id));
}
diff --git a/files/tests/externallib_test.php b/files/tests/externallib_test.php
index c464856ac282f..4f197775f319d 100644
--- a/files/tests/externallib_test.php
+++ b/files/tests/externallib_test.php
@@ -95,7 +95,7 @@ public function test_upload() {
$this->assertNotEmpty($file);
// Make sure the same file cannot be created again.
- $this->setExpectedException("moodle_exception");
+ $this->expectException("moodle_exception");
core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath,
$filename, $filecontent, $contextlevel, $instanceid);
}
@@ -120,7 +120,7 @@ public function test_upload_param_component() {
$instanceid = null;
// Make sure exception is thrown.
- $this->setExpectedException("coding_exception");
+ $this->expectException("coding_exception");
core_files_external::upload($contextid, $component, $filearea, $itemid,
$filepath, $filename, $filecontent, $contextlevel, $instanceid);
}
diff --git a/grade/grading/tests/grading_manager_test.php b/grade/grading/tests/grading_manager_test.php
index 0e806e812e8f9..b4907241312af 100644
--- a/grade/grading/tests/grading_manager_test.php
+++ b/grade/grading/tests/grading_manager_test.php
@@ -67,6 +67,8 @@ public function test_basic_instantiation() {
/**
* Unit test to set and get grading areas
+ *
+ * @expectedException moodle_exception
*/
public function test_set_and_get_grading_area() {
global $DB;
@@ -103,7 +105,6 @@ public function test_set_and_get_grading_area() {
$this->assertEquals('rubric', $gradingman->get_active_method());
// attempting to set an invalid method
- $this->setExpectedException('moodle_exception');
$gradingman->set_active_method('no_one_should_ever_try_to_implement_a_method_with_this_silly_name');
}
diff --git a/group/tests/externallib_test.php b/group/tests/externallib_test.php
index 547437925a9d4..97a6cf931847d 100644
--- a/group/tests/externallib_test.php
+++ b/group/tests/externallib_test.php
@@ -36,6 +36,8 @@ class core_group_externallib_testcase extends externallib_advanced_testcase {
/**
* Test create_groups
+ *
+ * @expectedException required_capability_exception
*/
public function test_create_groups() {
global $DB;
@@ -111,12 +113,13 @@ public function test_create_groups() {
// Call without required capability
$this->unassignUserCapability('moodle/course:managegroups', $context->id, $roleid);
- $this->setExpectedException('required_capability_exception');
$froups = core_group_external::create_groups(array($group4));
}
/**
* Test get_groups
+ *
+ * @expectedException required_capability_exception
*/
public function test_get_groups() {
global $DB;
@@ -175,12 +178,13 @@ public function test_get_groups() {
// Call without required capability
$this->unassignUserCapability('moodle/course:managegroups', $context->id, $roleid);
- $this->setExpectedException('required_capability_exception');
$groups = core_group_external::get_groups(array($group1->id, $group2->id));
}
/**
* Test delete_groups
+ *
+ * @expectedException required_capability_exception
*/
public function test_delete_groups() {
global $DB;
@@ -223,7 +227,6 @@ public function test_delete_groups() {
// Call without required capability
$this->unassignUserCapability('moodle/course:managegroups', $context->id, $roleid);
- $this->setExpectedException('required_capability_exception');
$froups = core_group_external::delete_groups(array($group3->id));
}
diff --git a/lib/external/tests/external_test.php b/lib/external/tests/external_test.php
index 4ff82b0282c93..2ceec65921584 100644
--- a/lib/external/tests/external_test.php
+++ b/lib/external/tests/external_test.php
@@ -72,7 +72,7 @@ public function test_get_string() {
$this->assertSame($corestring, $returnedstring);
// String with two parameter but one is invalid (not named).
- $this->setExpectedException('moodle_exception');
+ $this->expectException('moodle_exception');
$returnedstring = core_external::get_string('addservice', 'webservice', null,
array(array('value' => $service->name),
array('name' => 'id', 'value' => $service->id)));
diff --git a/lib/filestorage/tests/file_storage_test.php b/lib/filestorage/tests/file_storage_test.php
index f453f345171fb..45b89cbf8a4c9 100644
--- a/lib/filestorage/tests/file_storage_test.php
+++ b/lib/filestorage/tests/file_storage_test.php
@@ -236,7 +236,7 @@ public function test_get_file_preview(stored_file $file) {
$this->assertInstanceOf('stored_file', $previewtinyicon);
$this->assertEquals('6b9864ae1536a8eeef54e097319175a8be12f07c', $previewtinyicon->get_filename());
- $this->setExpectedException('file_exception');
+ $this->expectException('file_exception');
$fs->get_file_preview($file, 'amodewhichdoesntexist');
}
@@ -300,8 +300,8 @@ public function test_file_renaming() {
$this->assertEquals($contenthash, $file->get_contenthash());
// Try break it.
- $this->setExpectedException('file_exception',
- 'Can not create file "1/core/unittest/0/test/newtest.txt" (file exists, cannot rename)');
+ $this->expectException('file_exception');
+ $this->expectExceptionMessage('Can not create file "1/core/unittest/0/test/newtest.txt" (file exists, cannot rename)');
// This shall throw exception.
$originalfile->rename($newpath, $newname);
}
@@ -621,14 +621,14 @@ public function test_get_external_files() {
public function test_create_directory_contextid_negative() {
$fs = get_file_storage();
- $this->setExpectedException('file_exception');
+ $this->expectException('file_exception');
$fs->create_directory(-1, 'core', 'unittest', 0, '/');
}
public function test_create_directory_contextid_invalid() {
$fs = get_file_storage();
- $this->setExpectedException('file_exception');
+ $this->expectException('file_exception');
$fs->create_directory('not an int', 'core', 'unittest', 0, '/');
}
@@ -636,7 +636,7 @@ public function test_create_directory_component_invalid() {
$fs = get_file_storage();
$syscontext = context_system::instance();
- $this->setExpectedException('file_exception');
+ $this->expectException('file_exception');
$fs->create_directory($syscontext->id, 'bad/component', 'unittest', 0, '/');
}
@@ -644,7 +644,7 @@ public function test_create_directory_filearea_invalid() {
$fs = get_file_storage();
$syscontext = context_system::instance();
- $this->setExpectedException('file_exception');
+ $this->expectException('file_exception');
$fs->create_directory($syscontext->id, 'core', 'bad-filearea', 0, '/');
}
@@ -652,7 +652,7 @@ public function test_create_directory_itemid_negative() {
$fs = get_file_storage();
$syscontext = context_system::instance();
- $this->setExpectedException('file_exception');
+ $this->expectException('file_exception');
$fs->create_directory($syscontext->id, 'core', 'unittest', -1, '/');
}
@@ -660,7 +660,7 @@ public function test_create_directory_itemid_invalid() {
$fs = get_file_storage();
$syscontext = context_system::instance();
- $this->setExpectedException('file_exception');
+ $this->expectException('file_exception');
$fs->create_directory($syscontext->id, 'core', 'unittest', 'notanint', '/');
}
@@ -668,7 +668,7 @@ public function test_create_directory_filepath_invalid() {
$fs = get_file_storage();
$syscontext = context_system::instance();
- $this->setExpectedException('file_exception');
+ $this->expectException('file_exception');
$fs->create_directory($syscontext->id, 'core', 'unittest', 0, '/not-with-trailing/or-leading-slash');
}
@@ -1062,17 +1062,24 @@ private function generate_file_record() {
return $filerecord;
}
+ /**
+ * @expectedException file_exception
+ */
public function test_create_file_from_storedfile_file_invalid() {
$this->resetAfterTest(true);
$filerecord = $this->generate_file_record();
$fs = get_file_storage();
- $this->setExpectedException('file_exception');
+
// Create a file from a file id which doesn't exist.
$fs->create_file_from_storedfile($filerecord, 9999);
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid contextid
+ */
public function test_create_file_from_storedfile_contextid_invalid() {
$this->resetAfterTest(true);
@@ -1085,10 +1092,13 @@ public function test_create_file_from_storedfile_contextid_invalid() {
$filerecord->filename = 'invalid.txt';
$filerecord->contextid = 'invalid';
- $this->setExpectedException('file_exception', 'Invalid contextid');
$fs->create_file_from_storedfile($filerecord, $file1->get_id());
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid component
+ */
public function test_create_file_from_storedfile_component_invalid() {
$this->resetAfterTest(true);
@@ -1101,10 +1111,13 @@ public function test_create_file_from_storedfile_component_invalid() {
$filerecord->filename = 'invalid.txt';
$filerecord->component = 'bad/component';
- $this->setExpectedException('file_exception', 'Invalid component');
$fs->create_file_from_storedfile($filerecord, $file1->get_id());
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid filearea
+ */
public function test_create_file_from_storedfile_filearea_invalid() {
$this->resetAfterTest(true);
@@ -1117,10 +1130,13 @@ public function test_create_file_from_storedfile_filearea_invalid() {
$filerecord->filename = 'invalid.txt';
$filerecord->filearea = 'bad-filearea';
- $this->setExpectedException('file_exception', 'Invalid filearea');
$fs->create_file_from_storedfile($filerecord, $file1->get_id());
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid itemid
+ */
public function test_create_file_from_storedfile_itemid_invalid() {
$this->resetAfterTest(true);
@@ -1133,10 +1149,13 @@ public function test_create_file_from_storedfile_itemid_invalid() {
$filerecord->filename = 'invalid.txt';
$filerecord->itemid = 'bad-itemid';
- $this->setExpectedException('file_exception', 'Invalid itemid');
$fs->create_file_from_storedfile($filerecord, $file1->get_id());
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid file path
+ */
public function test_create_file_from_storedfile_filepath_invalid() {
$this->resetAfterTest(true);
@@ -1149,10 +1168,13 @@ public function test_create_file_from_storedfile_filepath_invalid() {
$filerecord->filename = 'invalid.txt';
$filerecord->filepath = 'a-/bad/-filepath';
- $this->setExpectedException('file_exception', 'Invalid file path');
$fs->create_file_from_storedfile($filerecord, $file1->get_id());
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid file name
+ */
public function test_create_file_from_storedfile_filename_invalid() {
$this->resetAfterTest(true);
@@ -1164,10 +1186,13 @@ public function test_create_file_from_storedfile_filename_invalid() {
$filerecord->filename = '';
- $this->setExpectedException('file_exception', 'Invalid file name');
$fs->create_file_from_storedfile($filerecord, $file1->get_id());
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid file timecreated
+ */
public function test_create_file_from_storedfile_timecreated_invalid() {
$this->resetAfterTest(true);
@@ -1180,10 +1205,13 @@ public function test_create_file_from_storedfile_timecreated_invalid() {
$filerecord->filename = 'invalid.txt';
$filerecord->timecreated = 'today';
- $this->setExpectedException('file_exception', 'Invalid file timecreated');
$fs->create_file_from_storedfile($filerecord, $file1->get_id());
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid file timemodified
+ */
public function test_create_file_from_storedfile_timemodified_invalid() {
$this->resetAfterTest(true);
@@ -1196,10 +1224,13 @@ public function test_create_file_from_storedfile_timemodified_invalid() {
$filerecord->filename = 'invalid.txt';
$filerecord->timemodified = 'today';
- $this->setExpectedException('file_exception', '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"
+ */
public function test_create_file_from_storedfile_duplicate() {
$this->resetAfterTest(true);
@@ -1210,7 +1241,6 @@ public function test_create_file_from_storedfile_duplicate() {
$this->assertInstanceOf('stored_file', $file1);
// Creating a file validating unique constraint.
- $this->setExpectedException('stored_file_creation_exception', 'Can not create file "1/core/phpunit/0/testfile.txt"');
$fs->create_file_from_storedfile($filerecord, $file1->get_id());
}
@@ -1248,6 +1278,10 @@ public function test_create_file_from_storedfile() {
$this->assertNotEquals($file3->get_timecreated(), $filerecord->timecreated);
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid contextid
+ */
public function test_create_file_from_string_contextid_invalid() {
$this->resetAfterTest(true);
@@ -1256,10 +1290,13 @@ public function test_create_file_from_string_contextid_invalid() {
$filerecord->contextid = 'invalid';
- $this->setExpectedException('file_exception', 'Invalid contextid');
$file1 = $fs->create_file_from_string($filerecord, 'text contents');
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid component
+ */
public function test_create_file_from_string_component_invalid() {
$this->resetAfterTest(true);
@@ -1268,10 +1305,13 @@ public function test_create_file_from_string_component_invalid() {
$filerecord->component = 'bad/component';
- $this->setExpectedException('file_exception', 'Invalid component');
$file1 = $fs->create_file_from_string($filerecord, 'text contents');
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid filearea
+ */
public function test_create_file_from_string_filearea_invalid() {
$this->resetAfterTest(true);
@@ -1280,10 +1320,13 @@ public function test_create_file_from_string_filearea_invalid() {
$filerecord->filearea = 'bad-filearea';
- $this->setExpectedException('file_exception', 'Invalid filearea');
$file1 = $fs->create_file_from_string($filerecord, 'text contents');
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid itemid
+ */
public function test_create_file_from_string_itemid_invalid() {
$this->resetAfterTest(true);
@@ -1292,10 +1335,13 @@ public function test_create_file_from_string_itemid_invalid() {
$filerecord->itemid = 'bad-itemid';
- $this->setExpectedException('file_exception', 'Invalid itemid');
$file1 = $fs->create_file_from_string($filerecord, 'text contents');
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid file path
+ */
public function test_create_file_from_string_filepath_invalid() {
$this->resetAfterTest(true);
@@ -1304,10 +1350,13 @@ public function test_create_file_from_string_filepath_invalid() {
$filerecord->filepath = 'a-/bad/-filepath';
- $this->setExpectedException('file_exception', 'Invalid file path');
$file1 = $fs->create_file_from_string($filerecord, 'text contents');
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid file name
+ */
public function test_create_file_from_string_filename_invalid() {
$this->resetAfterTest(true);
@@ -1316,10 +1365,13 @@ public function test_create_file_from_string_filename_invalid() {
$filerecord->filename = '';
- $this->setExpectedException('file_exception', 'Invalid file name');
$file1 = $fs->create_file_from_string($filerecord, 'text contents');
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid file timecreated
+ */
public function test_create_file_from_string_timecreated_invalid() {
$this->resetAfterTest(true);
@@ -1328,10 +1380,15 @@ public function test_create_file_from_string_timecreated_invalid() {
$filerecord->timecreated = 'today';
- $this->setExpectedException('file_exception', 'Invalid file timecreated');
+ $this->expectException('file_exception');
+ $this->expectExceptionMessage('Invalid file timecreated');
$file1 = $fs->create_file_from_string($filerecord, 'text contents');
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid file timemodified
+ */
public function test_create_file_from_string_timemodified_invalid() {
$this->resetAfterTest(true);
@@ -1340,7 +1397,6 @@ public function test_create_file_from_string_timemodified_invalid() {
$filerecord->timemodified = 'today';
- $this->setExpectedException('file_exception', 'Invalid file timemodified');
$file1 = $fs->create_file_from_string($filerecord, 'text contents');
}
@@ -1353,10 +1409,14 @@ public function test_create_file_from_string_duplicate() {
$file1 = $fs->create_file_from_string($filerecord, 'text contents');
// Creating a file validating unique constraint.
- $this->setExpectedException('stored_file_creation_exception');
+ $this->expectException('stored_file_creation_exception');
$file2 = $fs->create_file_from_string($filerecord, 'text contents');
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid contextid
+ */
public function test_create_file_from_pathname_contextid_invalid() {
global $CFG;
$path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
@@ -1368,10 +1428,13 @@ public function test_create_file_from_pathname_contextid_invalid() {
$filerecord->contextid = 'invalid';
- $this->setExpectedException('file_exception', 'Invalid contextid');
$file1 = $fs->create_file_from_pathname($filerecord, $path);
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid component
+ */
public function test_create_file_from_pathname_component_invalid() {
global $CFG;
$path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
@@ -1383,10 +1446,13 @@ public function test_create_file_from_pathname_component_invalid() {
$filerecord->component = 'bad/component';
- $this->setExpectedException('file_exception', 'Invalid component');
$file1 = $fs->create_file_from_pathname($filerecord, $path);
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid filearea
+ */
public function test_create_file_from_pathname_filearea_invalid() {
global $CFG;
$path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
@@ -1398,10 +1464,13 @@ public function test_create_file_from_pathname_filearea_invalid() {
$filerecord->filearea = 'bad-filearea';
- $this->setExpectedException('file_exception', 'Invalid filearea');
$file1 = $fs->create_file_from_pathname($filerecord, $path);
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid itemid
+ */
public function test_create_file_from_pathname_itemid_invalid() {
global $CFG;
$path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
@@ -1413,10 +1482,13 @@ public function test_create_file_from_pathname_itemid_invalid() {
$filerecord->itemid = 'bad-itemid';
- $this->setExpectedException('file_exception', 'Invalid itemid');
- $file1 = $fs->create_file_from_pathname($filerecord, $path);
+ $file1 = $fs->create_file_from_pathname($filerecord, $path);
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid file path
+ */
public function test_create_file_from_pathname_filepath_invalid() {
global $CFG;
$path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
@@ -1428,10 +1500,13 @@ public function test_create_file_from_pathname_filepath_invalid() {
$filerecord->filepath = 'a-/bad/-filepath';
- $this->setExpectedException('file_exception', 'Invalid file path');
$file1 = $fs->create_file_from_pathname($filerecord, $path);
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid file name
+ */
public function test_create_file_from_pathname_filename_invalid() {
global $CFG;
$path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
@@ -1443,10 +1518,13 @@ public function test_create_file_from_pathname_filename_invalid() {
$filerecord->filename = '';
- $this->setExpectedException('file_exception', 'Invalid file name');
$file1 = $fs->create_file_from_pathname($filerecord, $path);
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid file timecreated
+ */
public function test_create_file_from_pathname_timecreated_invalid() {
global $CFG;
$path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
@@ -1458,10 +1536,13 @@ public function test_create_file_from_pathname_timecreated_invalid() {
$filerecord->timecreated = 'today';
- $this->setExpectedException('file_exception', 'Invalid file timecreated');
$file1 = $fs->create_file_from_pathname($filerecord, $path);
}
+ /**
+ * @expectedException file_exception
+ * @expectedExceptionMessage Invalid file timemodified
+ */
public function test_create_file_from_pathname_timemodified_invalid() {
global $CFG;
$path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
@@ -1473,10 +1554,13 @@ public function test_create_file_from_pathname_timemodified_invalid() {
$filerecord->timemodified = 'today';
- $this->setExpectedException('file_exception', '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"
+ */
public function test_create_file_from_pathname_duplicate_file() {
global $CFG;
$this->resetAfterTest(true);
@@ -1490,7 +1574,6 @@ public function test_create_file_from_pathname_duplicate_file() {
$this->assertInstanceOf('stored_file', $file1);
// Creating a file validating unique constraint.
- $this->setExpectedException('stored_file_creation_exception', 'Can not create file "1/core/phpunit/0/testfile.txt"');
$file2 = $fs->create_file_from_pathname($filerecord, $path);
}
@@ -1515,7 +1598,7 @@ public function test_delete_reference_on_nonreference() {
$this->assertInstanceOf('stored_file', $file);
$this->assertFalse($file->is_external_file());
- $this->setExpectedException('coding_exception');
+ $this->expectException('coding_exception');
$file->delete_reference();
}
@@ -1745,7 +1828,7 @@ public function test_get_unused_filename() {
$newfilename = $fs->get_unused_filename($contextid, $component, $filearea, $itemid, $filepath, 'Hurray! (1).php');
$this->assertEquals('Hurray! (3).php', $newfilename);
- $this->setExpectedException('coding_exception');
+ $this->expectException('coding_exception');
$fs->get_unused_filename($contextid, $component, $filearea, $itemid, $filepath, '');
}
}
diff --git a/lib/phpunit/classes/unittestcase.php b/lib/phpunit/classes/unittestcase.php
deleted file mode 100644
index 6058cc6eb9307..0000000000000
--- a/lib/phpunit/classes/unittestcase.php
+++ /dev/null
@@ -1,193 +0,0 @@
-.
-
-/**
- * Legacy SimpleTest layer.
- *
- * @deprecated since 2.3
- * @package core
- * @category phpunit
- * @author Petr Skoda
- * @copyright 2012 Petr Skoda {@link http://skodak.org}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-
-/**
- * Simplified emulation test case for legacy SimpleTest.
- *
- * Note: this is supposed to work for very simple tests only.
- *
- * @deprecated since 2.3
- * @package core
- * @category phpunit
- * @author Petr Skoda
- * @copyright 2012 Petr Skoda {@link http://skodak.org}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-abstract class UnitTestCase extends PHPUnit_Framework_TestCase {
-
- /**
- * @deprecated since 2.3
- * @param bool $expected
- * @param string $message
- * @return void
- */
- public function expectException($expected, $message = '') {
- // alternatively use phpdocs: @expectedException ExceptionClassName
- if (!$expected) {
- return;
- }
- $this->setExpectedException('moodle_exception', $message);
- }
-
- /**
- * @deprecated since 2.3
- * @param bool $expected
- * @param string $message
- * @return void
- */
- public function expectError($expected = false, $message = '') {
- // alternatively use phpdocs: @expectedException PHPUnit_Framework_Error
- if (!$expected) {
- return;
- }
- $this->setExpectedException('PHPUnit_Framework_Error', $message);
- }
-
- /**
- * @deprecated since 2.3
- * @static
- * @param mixed $actual
- * @param string $messages
- * @return void
- */
- public static function assertTrue($actual, $messages = '') {
- parent::assertTrue((bool)$actual, $messages);
- }
-
- /**
- * @deprecated since 2.3
- * @static
- * @param mixed $actual
- * @param string $messages
- * @return void
- */
- public static function assertFalse($actual, $messages = '') {
- parent::assertFalse((bool)$actual, $messages);
- }
-
- /**
- * @deprecated since 2.3
- * @static
- * @param mixed $expected
- * @param mixed $actual
- * @param string $message
- * @return void
- */
- public static function assertEqual($expected, $actual, $message = '') {
- parent::assertEquals($expected, $actual, $message);
- }
-
- /**
- * @deprecated since 2.3
- * @static
- * @param mixed $expected
- * @param mixed $actual
- * @param float|int $margin
- * @param string $message
- * @return void
- */
- public static function assertWithinMargin($expected, $actual, $margin, $message = '') {
- parent::assertEquals($expected, $actual, '', $margin, $message);
- }
-
- /**
- * @deprecated since 2.3
- * @static
- * @param mixed $expected
- * @param mixed $actual
- * @param string $message
- * @return void
- */
- public static function assertNotEqual($expected, $actual, $message = '') {
- parent::assertNotEquals($expected, $actual, $message);
- }
-
- /**
- * @deprecated since 2.3
- * @static
- * @param mixed $expected
- * @param mixed $actual
- * @param string $message
- * @return void
- */
- public static function assertIdentical($expected, $actual, $message = '') {
- parent::assertSame($expected, $actual, $message);
- }
-
- /**
- * @deprecated since 2.3
- * @static
- * @param mixed $expected
- * @param mixed $actual
- * @param string $message
- * @return void
- */
- public static function assertNotIdentical($expected, $actual, $message = '') {
- parent::assertNotSame($expected, $actual, $message);
- }
-
- /**
- * @deprecated since 2.3
- * @static
- * @param mixed $actual
- * @param mixed $expected
- * @param string $message
- * @return void
- */
- public static function assertIsA($actual, $expected, $message = '') {
- if ($expected === 'array') {
- parent::assertEquals('array', gettype($actual), $message);
- } else {
- parent::assertInstanceOf($expected, $actual, $message);
- }
- }
-
- /**
- * @deprecated since 2.3
- * @static
- * @param mixed $pattern
- * @param mixed $string
- * @param string $message
- * @return void
- */
- public static function assertPattern($pattern, $string, $message = '') {
- parent::assertRegExp($pattern, $string, $message);
- }
-
- /**
- * @deprecated since 2.3
- * @static
- * @param mixed $pattern
- * @param mixed $string
- * @param string $message
- * @return void
- */
- public static function assertNotPattern($pattern, $string, $message = '') {
- parent::assertNotRegExp($pattern, $string, $message);
- }
-}
diff --git a/lib/phpunit/lib.php b/lib/phpunit/lib.php
index f271690da516a..3a70ac0ac3d31 100644
--- a/lib/phpunit/lib.php
+++ b/lib/phpunit/lib.php
@@ -35,7 +35,6 @@
require_once(__DIR__.'/classes/database_driver_testcase.php');
require_once(__DIR__.'/classes/arraydataset.php');
require_once(__DIR__.'/classes/advanced_testcase.php');
-require_once(__DIR__.'/classes/unittestcase.php');
require_once(__DIR__.'/classes/hint_resultprinter.php'); // Loaded here because phpunit.xml does not support relative links for printerFile.
require_once(__DIR__.'/classes/constraint_object_is_equal_with_exceptions.php');
require_once(__DIR__.'/../testing/classes/test_lock.php');
diff --git a/lib/phpunit/tests/advanced_test.php b/lib/phpunit/tests/advanced_test.php
index cf00787a6ab95..36fde30f29aa6 100644
--- a/lib/phpunit/tests/advanced_test.php
+++ b/lib/phpunit/tests/advanced_test.php
@@ -296,7 +296,7 @@ public function test_database_mock1() {
} catch (moodle_exception $e) {
$this->assertInstanceOf('dml_exception', $e);
}
- $DB = $this->getMock(get_class($DB));
+ $DB = $this->createMock(get_class($DB));
$this->assertNull($DB->get_record('pokus', array()));
// Rest continues after reset.
}
diff --git a/lib/testing/tests/generator_test.php b/lib/testing/tests/generator_test.php
index c80d600b92229..ba6e012edc2b6 100644
--- a/lib/testing/tests/generator_test.php
+++ b/lib/testing/tests/generator_test.php
@@ -47,9 +47,13 @@ public function test_get_plugin_generator_sloppy_name() {
$this->assertInstanceOf('mod_quiz_generator', $generator);
}
+ /**
+ * 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->setExpectedException('coding_exception', 'Component core_completion does not support ' .
- 'generators yet. Missing tests/generator/lib.php.');
$generator = $this->getDataGenerator()->get_plugin_generator('core_completion');
}
diff --git a/lib/tests/ajaxlib_test.php b/lib/tests/ajaxlib_test.php
index f32f84e562f15..18b459463a245 100644
--- a/lib/tests/ajaxlib_test.php
+++ b/lib/tests/ajaxlib_test.php
@@ -70,7 +70,7 @@ protected function helper_test_dirty_output($expectexception = false) {
echo $content;
if ($expectexception) {
- $this->setExpectedException('coding_exception');
+ $this->expectException('coding_exception');
ajax_check_captured_output();
} else {
$result = ajax_check_captured_output();
diff --git a/lib/tests/completionlib_test.php b/lib/tests/completionlib_test.php
index d9a75de7af5df..ee008efa4c57f 100644
--- a/lib/tests/completionlib_test.php
+++ b/lib/tests/completionlib_test.php
@@ -40,7 +40,7 @@ protected function mock_setup() {
$this->resetAfterTest();
- $DB = $this->getMock(get_class($DB));
+ $DB = $this->createMock(get_class($DB));
$CFG->enablecompletion = COMPLETION_ENABLED;
$USER = (object)array('id' =>314159);
}
@@ -127,7 +127,11 @@ public function test_is_enabled() {
public function test_update_state() {
$this->mock_setup();
- $c = $this->getMock('completion_info', array('is_enabled', 'get_data', 'internal_get_state', 'internal_set_data'), array((object)array('id'=>42)));
+ $mockbuilder = $this->getMockBuilder('completion_info');
+ $mockbuilder->setMethods(array('is_enabled', 'get_data', 'internal_get_state', 'internal_set_data'));
+ $mockbuilder->setConstructorArgs(array((object)array('id' => 42)));
+ $c = $mockbuilder->getMock();
+
$cm = (object)array('id'=>13, 'course'=>42);
// Not enabled, should do nothing.
@@ -223,7 +227,11 @@ public function test_internal_get_state() {
global $DB;
$this->mock_setup();
- $c = $this->getMock('completion_info', array('internal_get_grade_state'), array((object)array('id'=>42)));
+ $mockbuilder = $this->getMockBuilder('completion_info');
+ $mockbuilder->setMethods(array('internal_get_grade_state'));
+ $mockbuilder->setConstructorArgs(array((object)array('id' => 42)));
+ $c = $mockbuilder->getMock();
+
$cm = (object)array('id'=>13, 'course'=>42, 'completiongradeitemnumber'=>null);
// If view is required, but they haven't viewed it yet.
@@ -256,9 +264,10 @@ public function test_internal_get_state() {
public function test_set_module_viewed() {
$this->mock_setup();
- $c = $this->getMock('completion_info',
- array('delete_all_state', 'get_tracked_users', 'update_state', 'internal_get_grade_state', 'is_enabled', 'get_data', 'internal_get_state', 'internal_set_data'),
- array((object)array('id'=>42)));
+ $mockbuilder = $this->getMockBuilder('completion_info');
+ $mockbuilder->setMethods(array('is_enabled', 'get_data', 'internal_set_data', 'update_state'));
+ $mockbuilder->setConstructorArgs(array((object)array('id' => 42)));
+ $c = $mockbuilder->getMock();
$cm = (object)array('id'=>13, 'course'=>42);
// Not tracking completion, should do nothing.
@@ -341,9 +350,10 @@ public function test_reset_all_state() {
global $DB;
$this->mock_setup();
- $c = $this->getMock('completion_info',
- array('delete_all_state', 'get_tracked_users', 'update_state', 'internal_get_grade_state', 'is_enabled', 'get_data', 'internal_get_state', 'internal_set_data'),
- array((object)array('id'=>42)));
+ $mockbuilder = $this->getMockBuilder('completion_info');
+ $mockbuilder->setMethods(array('delete_all_state', 'get_tracked_users', 'update_state'));
+ $mockbuilder->setConstructorArgs(array((object)array('id' => 42)));
+ $c = $mockbuilder->getMock();
$cm = (object)array('id'=>13, 'course'=>42, 'completion'=>COMPLETION_TRACKING_AUTOMATIC);
@@ -516,9 +526,10 @@ public function test_get_progress_all() {
global $DB;
$this->mock_setup();
- $c = $this->getMock('completion_info',
- array('delete_all_state', 'get_tracked_users', 'update_state', 'internal_get_grade_state', 'is_enabled', 'get_data', 'internal_get_state', 'internal_set_data'),
- array((object)array('id'=>42)));
+ $mockbuilder = $this->getMockBuilder('completion_info');
+ $mockbuilder->setMethods(array('get_tracked_users'));
+ $mockbuilder->setConstructorArgs(array((object)array('id' => 42)));
+ $c = $mockbuilder->getMock();
// 1) Basic usage.
$c->expects($this->at(0))
@@ -593,9 +604,10 @@ public function test_get_progress_all() {
public function test_inform_grade_changed() {
$this->mock_setup();
- $c = $this->getMock('completion_info',
- array('delete_all_state', 'get_tracked_users', 'update_state', 'internal_get_grade_state', 'is_enabled', 'get_data', 'internal_get_state', 'internal_set_data'),
- array((object)array('id'=>42)));
+ $mockbuilder = $this->getMockBuilder('completion_info');
+ $mockbuilder->setMethods(array('is_enabled', 'update_state'));
+ $mockbuilder->setConstructorArgs(array((object)array('id' => 42)));
+ $c = $mockbuilder->getMock();
$cm = (object)array('course'=>42, 'id'=>13, 'completion'=>0, 'completiongradeitemnumber'=>null);
$item = (object)array('itemnumber'=>3, 'gradepass'=>1, 'hidden'=>0);
diff --git a/lib/tests/externallib_test.php b/lib/tests/externallib_test.php
index f67947d75f529..d6a922c0a0033 100644
--- a/lib/tests/externallib_test.php
+++ b/lib/tests/externallib_test.php
@@ -258,7 +258,7 @@ public function test_clean_returnvalue() {
$singlestructure['object'] = $object;
$singlestructure['value2'] = 'Some text';
$testdata = array($singlestructure);
- $this->setExpectedException('invalid_response_exception');
+ $this->expectException('invalid_response_exception');
$cleanedvalue = external_api::clean_returnvalue($returndesc, $testdata);
}
/*
@@ -305,7 +305,7 @@ public function test_get_context_from_params() {
$this->assertEquals($realcontext, $fetchedcontext);
// Passing wrong level.
- $this->setExpectedException('invalid_parameter_exception');
+ $this->expectException('invalid_parameter_exception');
$fetchedcontext = test_exernal_api::get_context_wrapper(array("contextlevel" => "random", "instanceid" => $course->id));
}
@@ -316,7 +316,7 @@ public function test_get_context_params() {
global $USER;
// Call without correct context details.
- $this->setExpectedException('invalid_parameter_exception');
+ $this->expectException('invalid_parameter_exception');
test_exernal_api::get_context_wrapper(array('roleid' => 3, 'userid' => $USER->id));
}
@@ -327,7 +327,7 @@ public function test_get_context_params2() {
global $USER;
// Call without correct context details.
- $this->setExpectedException('invalid_parameter_exception');
+ $this->expectException('invalid_parameter_exception');
test_exernal_api::get_context_wrapper(array('roleid' => 3, 'userid' => $USER->id, 'contextlevel' => "course"));
}
@@ -340,7 +340,7 @@ public function test_get_context_params3() {
// Call without correct context details.
$this->resetAfterTest(true);
$course = self::getDataGenerator()->create_course();
- $this->setExpectedException('invalid_parameter_exception');
+ $this->expectException('invalid_parameter_exception');
test_exernal_api::get_context_wrapper(array('roleid' => 3, 'userid' => $USER->id, 'instanceid' => $course->id));
}
diff --git a/lib/tests/grading_externallib_test.php b/lib/tests/grading_externallib_test.php
index 300ec24a049ec..7d2984facd18b 100644
--- a/lib/tests/grading_externallib_test.php
+++ b/lib/tests/grading_externallib_test.php
@@ -536,7 +536,7 @@ public function test_save_definitions_rubric() {
$this->assertEquals(2, $DB->count_records('gradingform_rubric_levels', array('criterionid' => $criterion1->id)));
$gradingarea['activemethod'] = 'invalid';
- $this->setExpectedException('moodle_exception');
+ $this->expectException('moodle_exception');
$results = core_grading_external::save_definitions(array($gradingarea));
}
@@ -637,7 +637,7 @@ public function test_save_definitions_marking_guide() {
// Test an invalid method in the definition.
$guidedefinition['method'] = 'invalid';
$gradingarea['definitions'] = array($guidedefinition);
- $this->setExpectedException('invalid_parameter_exception');
+ $this->expectException('invalid_parameter_exception');
$results = core_grading_external::save_definitions(array($gradingarea));
}
}
diff --git a/lib/tests/moodle_page_test.php b/lib/tests/moodle_page_test.php
index 8132ac0abff33..1f4091e1aef05 100644
--- a/lib/tests/moodle_page_test.php
+++ b/lib/tests/moodle_page_test.php
@@ -83,32 +83,38 @@ public function test_global_course_not_changed_with_non_global_page() {
$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();
- // Set expectation.
- $this->setExpectedException('coding_exception');
+
// Exercise SUT.
$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);
- // Set expectation.
- $this->setExpectedException('coding_exception');
+
// Exercise SUT.
$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();
$this->testpage->set_context(context_system::instance()); // Avoid trying to set the context.
$this->testpage->set_course($course);
- // Set expectation.
- $this->setExpectedException('coding_exception');
+
// Exercise SUT.
$this->testpage->set_category_by_id(123);
}
@@ -139,9 +145,10 @@ public function test_set_state_normal_path() {
$this->assertEquals(moodle_page::STATE_DONE, $this->testpage->state);
}
+ /**
+ * @expectedException coding_exception
+ */
public function test_set_state_cannot_skip_one() {
- // Set expectation.
- $this->setExpectedException('coding_exception');
// Exercise SUT.
$this->testpage->set_state(moodle_page::STATE_IN_BODY);
}
@@ -381,13 +388,14 @@ public function test_set_cm() {
$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);
- // Set expectation.
- $this->setExpectedException('coding_exception');
// Exercise SUT.
$this->testpage->set_activity_record($forum);
}
@@ -428,27 +436,29 @@ public function test_set_activity_record() {
$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();
$forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
$cm = get_coursemodule_from_id('forum', $forum->cmid);
$this->testpage->set_cm($cm);
- // Set expectation.
- $this->setExpectedException('coding_exception');
// Exercise SUT.
$forum->course = 13;
$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();
$forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
$cm = get_coursemodule_from_id('forum', $forum->cmid);
$this->testpage->set_cm($cm);
- // Set expectation.
- $this->setExpectedException('coding_exception');
// Exercise SUT.
$forum->id = 13;
$this->testpage->set_activity_record($forum);
@@ -480,13 +490,14 @@ public function test_set_cm_with_course_and_activity_no_db() {
$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();
$forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
$cm = get_coursemodule_from_id('forum', $forum->cmid);
- // Set expectation.
- $this->setExpectedException('coding_exception');
// Exercise SUT.
$cm->course = 13;
$this->testpage->set_cm($cm, $course);
diff --git a/lib/tests/outputrequirementslib_test.php b/lib/tests/outputrequirementslib_test.php
index 717520565e7e4..a517c5dbdbb31 100644
--- a/lib/tests/outputrequirementslib_test.php
+++ b/lib/tests/outputrequirementslib_test.php
@@ -36,7 +36,7 @@ public function test_string_for_js() {
$page = new moodle_page();
$page->requires->string_for_js('course', 'moodle', 1);
$page->requires->string_for_js('course', 'moodle', 1);
- $this->setExpectedException('coding_exception');
+ $this->expectException('coding_exception');
$page->requires->string_for_js('course', 'moodle', 2);
// Note: we can not switch languages in phpunit yet,
@@ -52,7 +52,7 @@ public function test_one_time_output_normal_case() {
public function test_one_time_output_repeat_output_throws() {
$page = new moodle_page();
$page->requires->set_one_time_item_created('test_item');
- $this->setExpectedException('coding_exception');
+ $this->expectException('coding_exception');
$page->requires->set_one_time_item_created('test_item');
}
diff --git a/lib/tests/setuplib_test.php b/lib/tests/setuplib_test.php
index 10d2cee69e4e4..5097fd631491d 100644
--- a/lib/tests/setuplib_test.php
+++ b/lib/tests/setuplib_test.php
@@ -181,9 +181,8 @@ public function test_make_unique_directory_basedir_is_file() {
$this->assertFalse(make_unique_writable_directory($base, false));
// Now check for exception.
- $this->setExpectedException('invalid_dataroot_permissions',
- $base . ' is not writable. Unable to create a unique directory within it.'
- );
+ $this->expectException('invalid_dataroot_permissions');
+ $this->expectExceptionMessage($base . ' is not writable. Unable to create a unique directory within it.');
make_unique_writable_directory($base);
unlink($base);
diff --git a/lib/tests/update_checker_test.php b/lib/tests/update_checker_test.php
index 4139f18890acf..08052c8bf56b8 100644
--- a/lib/tests/update_checker_test.php
+++ b/lib/tests/update_checker_test.php
@@ -55,12 +55,13 @@ public function test_core_available_update() {
/**
* 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->setExpectedException('\core\update\testable_checker_cron_executed');
$provider->cron();
}
@@ -77,12 +78,13 @@ public function test_cron_has_fresh_fetch() {
/**
* 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->setExpectedException('\core\update\testable_checker_cron_executed');
$provider->cron();
}
@@ -257,12 +259,14 @@ public function test_compare_responses_modified_update() {
$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->setExpectedException('\core\update\checker_exception');
$cmp = $provider->compare_responses($broken, $broken);
}
diff --git a/lib/tests/update_code_manager_test.php b/lib/tests/update_code_manager_test.php
index cbf4717cdeebf..b127c714a8be9 100644
--- a/lib/tests/update_code_manager_test.php
+++ b/lib/tests/update_code_manager_test.php
@@ -111,12 +111,14 @@ public function test_unzip_plugin_file() {
$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->setExpectedException('moodle_exception');
$files = $codeman->unzip_plugin_file($zipfilepath, $targetdir, 'foo');
}
diff --git a/lib/tests/user_test.php b/lib/tests/user_test.php
index 7aea5a4ec534b..626f270ba44b3 100644
--- a/lib/tests/user_test.php
+++ b/lib/tests/user_test.php
@@ -308,10 +308,11 @@ public function test_get_property_type() {
// Try to fetch type of a non-existent properties.
$nonexistingproperty = 'userfullname';
- $this->setExpectedException('coding_exception', 'Invalid property requested: ' . $nonexistingproperty);
+ $this->expectException('coding_exception');
+ $this->expectExceptionMessage('Invalid property requested: ' . $nonexistingproperty);
core_user::get_property_type($nonexistingproperty);
$nonexistingproperty = 'mobilenumber';
- $this->setExpectedException('coding_exception', 'Invalid property requested: ' . $nonexistingproperty);
+ $this->expectExceptionMessage('Invalid property requested: ' . $nonexistingproperty);
core_user::get_property_type($nonexistingproperty);
}
@@ -331,10 +332,11 @@ public function test_get_property_null() {
// Try to fetch type of a non-existent properties.
$nonexistingproperty = 'lastnamefonetic';
- $this->setExpectedException('coding_exception', 'Invalid property requested: ' . $nonexistingproperty);
+ $this->expectException('coding_exception');
+ $this->expectExceptionMessage('Invalid property requested: ' . $nonexistingproperty);
core_user::get_property_null($nonexistingproperty);
$nonexistingproperty = 'midlename';
- $this->setExpectedException('coding_exception', 'Invalid property requested: ' . $nonexistingproperty);
+ $this->expectExceptionMessage('Invalid property requested: ' . $nonexistingproperty);
core_user::get_property_null($nonexistingproperty);
}
@@ -365,15 +367,20 @@ public function test_get_property_choices() {
// Try to fetch type of a non-existent properties.
$nonexistingproperty = 'language';
- $this->setExpectedException('coding_exception', 'Invalid property requested: ' . $nonexistingproperty);
+ $this->expectException('coding_exception');
+ $this->expectExceptionMessage('Invalid property requested: ' . $nonexistingproperty);
core_user::get_property_null($nonexistingproperty);
$nonexistingproperty = 'coutries';
- $this->setExpectedException('coding_exception', 'Invalid property requested: ' . $nonexistingproperty);
+ $this->expectExceptionMessage('Invalid property requested: ' . $nonexistingproperty);
core_user::get_property_null($nonexistingproperty);
}
/**
* 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;
@@ -401,7 +408,6 @@ public function test_get_property_default() {
$timezone = core_user::get_property_default('timezone');
$this->assertEquals('Pacific/Auckland', $timezone);
- $this->setExpectedException('coding_exception', 'Invalid property requested, or the property does not has a default value.');
core_user::get_property_default('firstname');
}
diff --git a/lib/tests/weblib_test.php b/lib/tests/weblib_test.php
index 73165b37bb4a2..a8c10f62ad99e 100644
--- a/lib/tests/weblib_test.php
+++ b/lib/tests/weblib_test.php
@@ -258,10 +258,11 @@ public function test_moodle_url_set_good_scheme() {
/**
* 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->setExpectedException('coding_exception');
$url->set_scheme('not a valid $ scheme');
}
diff --git a/lib/upgrade.txt b/lib/upgrade.txt
index 31babe8f0257d..eac7cad5a1f67 100644
--- a/lib/upgrade.txt
+++ b/lib/upgrade.txt
@@ -18,6 +18,10 @@ information provided here is intended especially for developers.
External function gradereport_user_external::get_grades_table can be used for retrieving the course grades table.
Please note that the information returned from that WS is intended for displaying (not for data consumption).
* New option 'escape' added to format_string. When true (default), escapes HTML entities from the string
+* Phpunit has been upgraded to 5.4.x and following has been deprecated and is not used any more:
+ - setExpectedException(), use @expectedException or $this->expectException() and $this->expectExceptionMessage()
+ - getMock(), use createMock() or getMockBuilder()->getMock()
+ - UnitTestCase class is removed.
=== 3.1 ===
diff --git a/message/tests/externallib_test.php b/message/tests/externallib_test.php
index f1e555b0e9f10..e2bf202bf68bd 100644
--- a/message/tests/externallib_test.php
+++ b/message/tests/externallib_test.php
@@ -339,6 +339,7 @@ public function test_get_contacts() {
/**
* Test search_contacts.
+ * @expectedException moodle_exception
*/
public function test_search_contacts() {
global $DB;
@@ -400,7 +401,6 @@ public function test_search_contacts() {
$this->assertEquals($user5->id, $result['id']);
// Empty query, will throw an exception.
- $this->setExpectedException('moodle_exception');
$results = core_message_external::search_contacts('');
}
diff --git a/mod/assign/tests/externallib_test.php b/mod/assign/tests/externallib_test.php
index 22cd5616fac66..0816e9a160965 100644
--- a/mod/assign/tests/externallib_test.php
+++ b/mod/assign/tests/externallib_test.php
@@ -517,6 +517,8 @@ public function test_get_user_mappings() {
/**
* Test lock_submissions
+ *
+ * @expectedException moodle_exception
*/
public function test_lock_submissions() {
global $DB, $USER;
@@ -576,7 +578,6 @@ public function test_lock_submissions() {
'text'=>'Submission text',
'format'=>FORMAT_MOODLE);
$notices = array();
- $this->setExpectedException('moodle_exception');
$assign->save_submission($data, $notices);
}
@@ -781,6 +782,8 @@ public function test_save_user_extensions() {
/**
* Test reveal_identities
+ *
+ * @expectedException required_capability_exception
*/
public function test_reveal_identities() {
global $DB, $USER;
@@ -814,7 +817,6 @@ public function test_reveal_identities() {
$studentrole->id);
$this->setUser($student1);
- $this->setExpectedException('required_capability_exception');
$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));
@@ -1229,6 +1231,8 @@ public function test_save_grades_with_advanced_grading() {
/**
* Test save grades for a team submission
+ *
+ * @expectedException invalid_parameter_exception
*/
public function test_save_grades_with_group_submission() {
global $DB, $USER, $CFG;
@@ -1321,7 +1325,6 @@ public function test_save_grades_with_group_submission() {
$student2gradeinfo['plugindata'] = $feedbackpluginparams;
$grades1[] = $student2gradeinfo;
- $this->setExpectedException('invalid_parameter_exception');
// Expect an exception since 2 grades have been submitted for the same team.
$result = mod_assign_external::save_grades($instance->id, true, $grades1);
$result = external_api::clean_returnvalue(mod_assign_external::save_grades_returns(), $result);
@@ -1533,6 +1536,8 @@ public function test_set_user_flags() {
/**
* Test view_grading_table
+ *
+ * @expectedException dml_missing_record_exception
*/
public function test_view_grading_table_invalid_instance() {
global $DB;
@@ -1546,12 +1551,13 @@ public function test_view_grading_table_invalid_instance() {
$cm = get_coursemodule_from_instance('assign', $assign->id);
// Test invalid instance id.
- $this->setExpectedExceptionRegexp('dml_missing_record_exception');
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;
@@ -1568,7 +1574,6 @@ public function test_view_grading_table_not_enrolled() {
$user = self::getDataGenerator()->create_user();
$this->setUser($user);
- $this->setExpectedException('require_login_exception');
mod_assign_external::view_grading_table($assign->id);
}
@@ -1613,6 +1618,9 @@ public function test_view_grading_table_correct() {
/**
* 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;
@@ -1638,7 +1646,6 @@ public function test_view_grading_table_without_capability() {
accesslib_clear_all_caches_for_unit_testing();
course_modinfo::clear_instance_cache();
- $this->setExpectedException('require_login_exception', 'Course or activity not accessible. (Activity is hidden)');
mod_assign_external::view_grading_table($assign->id);
}
@@ -2029,6 +2036,8 @@ public function test_get_submission_status_in_reopened_status() {
/**
* Test access control for get_submission_status.
+ *
+ * @expectedException required_capability_exception
*/
public function test_get_submission_status_access_control() {
$this->resetAfterTest(true);
@@ -2038,23 +2047,25 @@ public function test_get_submission_status_access_control() {
$this->setUser($student2);
// Access control test.
- $this->setExpectedException('required_capability_exception');
mod_assign_external::get_submission_status($assign->get_instance()->id, $student1->id);
}
/**
* 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->setExpectedException('moodle_exception');
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;
@@ -2070,13 +2081,14 @@ public function test_get_participant_no_view_capability() {
$this->setUser($student);
assign_capability('mod/assign:view', CAP_PROHIBIT, $studentrole->id, $context->id, true);
- $this->setExpectedException('require_login_exception');
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;
@@ -2095,12 +2107,13 @@ public function test_get_participant_no_grade_capability() {
assign_capability('mod/assign:grade', CAP_PROHIBIT, $teacherrole->id, $context->id, true);
accesslib_clear_all_caches_for_unit_testing();
- $this->setExpectedException('required_capability_exception');
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;
@@ -2113,7 +2126,6 @@ public function test_get_participant_no_participant() {
$this->setUser($teacher);
- $this->setExpectedException('moodle_exception');
$result = mod_assign_external::get_participant($assign->id, $student->id, false);
}
diff --git a/mod/assign/tests/locallib_test.php b/mod/assign/tests/locallib_test.php
index 1e0095a444d95..e3c3adb5a03d6 100644
--- a/mod/assign/tests/locallib_test.php
+++ b/mod/assign/tests/locallib_test.php
@@ -85,7 +85,7 @@ public function test_is_blind_marking() {
$nopermission = false;
$this->students[0]->ignoresesskey = true;
$this->setUser($this->students[0]);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
$assign->reveal_identities();
$this->students[0]->ignoresesskey = false;
@@ -93,13 +93,13 @@ public function test_is_blind_marking() {
$nopermission = false;
$this->teachers[0]->ignoresesskey = true;
$this->setUser($this->teachers[0]);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
$assign->reveal_identities();
$this->teachers[0]->ignoresesskey = false;
// Test sesskey is required.
$this->setUser($this->editingteachers[0]);
- $this->setExpectedException('moodle_exception');
+ $this->expectException('moodle_exception');
$assign->reveal_identities();
// Test editingteacher can reveal identities if sesskey is ignored.
@@ -2149,8 +2149,9 @@ public function test_markerallocation() {
$this->assertNotEquals(true, strpos($output, $this->students[0]->lastname));
}
-
-
+ /**
+ * @expectedException moodle_exception
+ */
public function test_teacher_submit_for_student() {
global $PAGE;
@@ -2229,7 +2230,6 @@ public function test_teacher_submit_for_student() {
'format'=>FORMAT_MOODLE);
$notices = array();
- $this->setExpectedException('moodle_exception');
$assign->save_submission($data, $notices);
$sink->close();
diff --git a/mod/choice/tests/events_test.php b/mod/choice/tests/events_test.php
index d383ed47d8aec..febe209d46a22 100644
--- a/mod/choice/tests/events_test.php
+++ b/mod/choice/tests/events_test.php
@@ -126,6 +126,8 @@ public function test_answer_submitted_multiple() {
/**
* Test custom validations.
+ *
+ * @expectedException coding_exception
*/
public function test_answer_submitted_other_exception() {
// Generate user data.
@@ -139,7 +141,6 @@ public function test_answer_submitted_other_exception() {
$eventdata['other'] = array();
// Make sure content identifier is always set.
- $this->setExpectedException('coding_exception');
$event = \mod_choice\event\answer_submitted::create($eventdata);
$event->trigger();
$this->assertEventContextNotUsed($event);
@@ -180,8 +181,9 @@ public function test_answer_updated() {
}
/**
- * Test custom validations
- * for answer_updated event.
+ * Test custom validations for answer_updated event.
+ *
+ * @expectedException coding_exception
*/
public function test_answer_updated_other_exception() {
// Generate user data.
@@ -195,7 +197,6 @@ public function test_answer_updated_other_exception() {
$eventdata['other'] = array();
// Make sure content identifier is always set.
- $this->setExpectedException('coding_exception');
$event = \mod_choice\event\answer_updated::create($eventdata);
$event->trigger();
$this->assertEventContextNotUsed($event);
diff --git a/mod/choice/tests/lib_test.php b/mod/choice/tests/lib_test.php
index dec8a9fdecb82..a4d2ec64c2498 100644
--- a/mod/choice/tests/lib_test.php
+++ b/mod/choice/tests/lib_test.php
@@ -131,6 +131,9 @@ public function test_choice_can_view_results() {
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_choice_user_submit_response_validation() {
global $USER;
@@ -149,7 +152,6 @@ public function test_choice_user_submit_response_validation() {
$optionids2 = array_keys($choicewithoptions2->option);
// Make sure we cannot submit options from a different choice instance.
- $this->setExpectedException('moodle_exception');
choice_user_submit_response($optionids2[0], $choice1, $USER->id, $course, $cm);
}
diff --git a/mod/forum/tests/events_test.php b/mod/forum/tests/events_test.php
index 96bd188f25de7..9bbd159c7e0c3 100644
--- a/mod/forum/tests/events_test.php
+++ b/mod/forum/tests/events_test.php
@@ -54,6 +54,9 @@ public function tearDown() {
/**
* 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();
@@ -62,12 +65,14 @@ public function test_course_searched_searchterm_validation() {
'context' => $coursectx,
);
- $this->setExpectedException('coding_exception', '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();
@@ -78,7 +83,6 @@ public function test_course_searched_context_validation() {
'other' => array('searchterm' => 'testing'),
);
- $this->setExpectedException('coding_exception', 'Context level must be CONTEXT_COURSE.');
\mod_forum\event\course_searched::create($params);
}
@@ -119,6 +123,9 @@ public function test_course_searched() {
/**
* 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();
@@ -129,12 +136,14 @@ public function test_discussion_created_forumid_validation() {
'context' => $context,
);
- $this->setExpectedException('coding_exception', '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();
@@ -145,7 +154,6 @@ public function test_discussion_created_context_validation() {
'other' => array('forumid' => $forum->id),
);
- $this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
\mod_forum\event\discussion_created::create($params);
}
@@ -196,6 +204,9 @@ public function test_discussion_created() {
/**
* 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();
@@ -206,12 +217,14 @@ public function test_discussion_updated_forumid_validation() {
'context' => $context,
);
- $this->setExpectedException('coding_exception', '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();
@@ -222,7 +235,6 @@ public function test_discussion_updated_context_validation() {
'other' => array('forumid' => $forum->id),
);
- $this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
\mod_forum\event\discussion_updated::create($params);
}
@@ -271,6 +283,9 @@ public function test_discussion_updated() {
/**
* 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();
@@ -281,12 +296,14 @@ public function test_discussion_deleted_forumid_validation() {
'context' => $context,
);
- $this->setExpectedException('coding_exception', '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();
@@ -297,7 +314,6 @@ public function test_discussion_deleted_context_validation() {
'other' => array('forumid' => $forum->id),
);
- $this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
\mod_forum\event\discussion_deleted::create($params);
}
@@ -347,6 +363,9 @@ public function test_discussion_deleted() {
/**
* 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();
@@ -359,12 +378,14 @@ public function test_discussion_moved_fromforumid_validation() {
'other' => array('toforumid' => $toforum->id)
);
- $this->setExpectedException('coding_exception', '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();
@@ -377,12 +398,14 @@ public function test_discussion_moved_toforumid_validation() {
'other' => array('fromforumid' => $fromforum->id)
);
- $this->setExpectedException('coding_exception', '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();
@@ -403,7 +426,6 @@ public function test_discussion_moved_context_validation() {
'other' => array('fromforumid' => $fromforum->id, 'toforumid' => $toforum->id)
);
- $this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
\mod_forum\event\discussion_moved::create($params);
}
@@ -455,6 +477,9 @@ public function test_discussion_moved() {
/**
* 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();
@@ -473,7 +498,6 @@ public function test_discussion_viewed_context_validation() {
'objectid' => $discussion->id,
);
- $this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
\mod_forum\event\discussion_viewed::create($params);
}
@@ -522,6 +546,9 @@ public function test_discussion_viewed() {
/**
* 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();
@@ -532,7 +559,6 @@ public function test_course_module_viewed_context_validation() {
'objectid' => $forum->id,
);
- $this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
\mod_forum\event\course_module_viewed::create($params);
}
@@ -574,6 +600,9 @@ public function test_course_module_viewed() {
/**
* 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();
@@ -585,12 +614,14 @@ public function test_subscription_created_forumid_validation() {
'relateduserid' => $user->id,
);
- $this->setExpectedException('coding_exception', '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();
@@ -601,12 +632,14 @@ public function test_subscription_created_relateduserid_validation() {
'objectid' => $forum->id,
);
- $this->setExpectedException('coding_exception', '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();
@@ -619,7 +652,6 @@ public function test_subscription_created_contextlevel_validation() {
'relateduserid' => $user->id,
);
- $this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
\mod_forum\event\subscription_created::create($params);
}
@@ -671,6 +703,9 @@ public function test_subscription_created() {
/**
* 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();
@@ -682,12 +717,14 @@ public function test_subscription_deleted_forumid_validation() {
'relateduserid' => $user->id,
);
- $this->setExpectedException('coding_exception', '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();
@@ -698,12 +735,14 @@ public function test_subscription_deleted_relateduserid_validation() {
'objectid' => $forum->id,
);
- $this->setExpectedException('coding_exception', '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();
@@ -716,7 +755,6 @@ public function test_subscription_deleted_contextlevel_validation() {
'relateduserid' => $user->id,
);
- $this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
\mod_forum\event\subscription_deleted::create($params);
}
@@ -768,6 +806,9 @@ public function test_subscription_deleted() {
/**
* 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();
@@ -779,12 +820,14 @@ public function test_readtracking_enabled_forumid_validation() {
'relateduserid' => $user->id,
);
- $this->setExpectedException('coding_exception', '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();
@@ -795,12 +838,14 @@ public function test_readtracking_enabled_relateduserid_validation() {
'objectid' => $forum->id,
);
- $this->setExpectedException('coding_exception', '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();
@@ -813,7 +858,6 @@ public function test_readtracking_enabled_contextlevel_validation() {
'relateduserid' => $user->id,
);
- $this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
\mod_forum\event\readtracking_enabled::create($params);
}
@@ -856,6 +900,9 @@ public function test_readtracking_enabled() {
/**
* 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();
@@ -867,12 +914,14 @@ public function test_readtracking_disabled_forumid_validation() {
'relateduserid' => $user->id,
);
- $this->setExpectedException('coding_exception', '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();
@@ -883,12 +932,14 @@ public function test_readtracking_disabled_relateduserid_validation() {
'objectid' => $forum->id,
);
- $this->setExpectedException('coding_exception', '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();
@@ -901,7 +952,6 @@ public function test_readtracking_disabled_contextlevel_validation() {
'relateduserid' => $user->id,
);
- $this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
\mod_forum\event\readtracking_disabled::create($params);
}
@@ -944,6 +994,9 @@ public function test_readtracking_disabled() {
/**
* 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();
@@ -955,12 +1008,14 @@ public function test_subscribers_viewed_forumid_validation() {
'relateduserid' => $user->id,
);
- $this->setExpectedException('coding_exception', '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();
@@ -973,7 +1028,6 @@ public function test_subscribers_viewed_contextlevel_validation() {
'relateduserid' => $user->id,
);
- $this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
\mod_forum\event\subscribers_viewed::create($params);
}
@@ -1011,7 +1065,10 @@ public function test_subscribers_viewed() {
}
/**
- * Ensure user_report_viewed event validates that the reportmode is set.
+ * 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();
@@ -1022,12 +1079,14 @@ public function test_user_report_viewed_reportmode_validation() {
'relateduserid' => $user->id,
);
- $this->setExpectedException('coding_exception', '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.
+ * 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();
@@ -1040,13 +1099,14 @@ public function test_user_report_viewed_contextlevel_validation() {
'relateduserid' => $user->id,
);
- $this->setExpectedException('coding_exception',
- '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() {
@@ -1055,7 +1115,6 @@ public function test_user_report_viewed_relateduserid_validation() {
'other' => array('reportmode' => 'posts'),
);
- $this->setExpectedException('coding_exception', 'The \'relateduserid\' must be set.');
\mod_forum\event\user_report_viewed::create($params);
}
@@ -1118,7 +1177,10 @@ public function test_post_created_postid_validation() {
}
/**
- * Ensure post_created event validates that the discussionid is set.
+ * 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();
@@ -1144,12 +1206,14 @@ public function test_post_created_discussionid_validation() {
'other' => array('forumid' => $forum->id, 'forumtype' => $forum->type)
);
- $this->setExpectedException('coding_exception', '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();
@@ -1175,12 +1239,14 @@ public function test_post_created_forumid_validation() {
'other' => array('discussionid' => $discussion->id, 'forumtype' => $forum->type)
);
- $this->setExpectedException('coding_exception', '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.
+ * 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();
@@ -1206,12 +1272,14 @@ public function test_post_created_forumtype_validation() {
'other' => array('discussionid' => $discussion->id, 'forumid' => $forum->id)
);
- $this->setExpectedException('coding_exception', '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();
@@ -1237,7 +1305,6 @@ public function test_post_created_context_validation() {
'other' => array('discussionid' => $discussion->id, 'forumid' => $forum->id, 'forumtype' => $forum->type)
);
- $this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE');
\mod_forum\event\post_created::create($params);
}
@@ -1371,7 +1438,10 @@ public function test_post_deleted_postid_validation() {
}
/**
- * Ensure post_deleted event validates that the discussionid is set.
+ * 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();
@@ -1397,12 +1467,14 @@ public function test_post_deleted_discussionid_validation() {
'other' => array('forumid' => $forum->id, 'forumtype' => $forum->type)
);
- $this->setExpectedException('coding_exception', '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();
@@ -1428,12 +1500,14 @@ public function test_post_deleted_forumid_validation() {
'other' => array('discussionid' => $discussion->id, 'forumtype' => $forum->type)
);
- $this->setExpectedException('coding_exception', '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.
+ * 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();
@@ -1459,12 +1533,14 @@ public function test_post_deleted_forumtype_validation() {
'other' => array('discussionid' => $discussion->id, 'forumid' => $forum->id)
);
- $this->setExpectedException('coding_exception', '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();
@@ -1490,7 +1566,6 @@ public function test_post_deleted_context_validation() {
'other' => array('discussionid' => $discussion->id, 'forumid' => $forum->id, 'forumtype' => $forum->type)
);
- $this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE');
\mod_forum\event\post_deleted::create($params);
}
@@ -1622,7 +1697,10 @@ public function test_post_deleted_single() {
}
/**
- * Ensure post_updated event validates that the discussionid is set.
+ * 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();
@@ -1648,12 +1726,14 @@ public function test_post_updated_discussionid_validation() {
'other' => array('forumid' => $forum->id, 'forumtype' => $forum->type)
);
- $this->setExpectedException('coding_exception', '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.
+ * 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();
@@ -1679,12 +1759,14 @@ public function test_post_updated_forumid_validation() {
'other' => array('discussionid' => $discussion->id, 'forumtype' => $forum->type)
);
- $this->setExpectedException('coding_exception', '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.
+ * 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();
@@ -1710,12 +1792,14 @@ public function test_post_updated_forumtype_validation() {
'other' => array('discussionid' => $discussion->id, 'forumid' => $forum->id)
);
- $this->setExpectedException('coding_exception', '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();
@@ -1741,7 +1825,6 @@ public function test_post_updated_context_validation() {
'other' => array('discussionid' => $discussion->id, 'forumid' => $forum->id, 'forumtype' => $forum->type)
);
- $this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE');
\mod_forum\event\post_updated::create($params);
}
@@ -1968,6 +2051,9 @@ public function test_discussion_subscription_created_validation() {
/**
* 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;
@@ -2016,12 +2102,14 @@ public function test_discussion_subscription_created_validation_contextlevel() {
);
// Without an invalid context.
- $this->setExpectedException('coding_exception', '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;
@@ -2067,12 +2155,14 @@ public function test_discussion_subscription_created_validation_discussion() {
)
);
- $this->setExpectedException('coding_exception', "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;
@@ -2118,12 +2208,14 @@ public function test_discussion_subscription_created_validation_forumid() {
)
);
- $this->setExpectedException('coding_exception', "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;
@@ -2171,7 +2263,6 @@ public function test_discussion_subscription_created_validation_relateduserid()
)
);
- $this->setExpectedException('coding_exception', "The 'relateduserid' must be set.");
\mod_forum\event\discussion_subscription_created::create($params);
}
@@ -2291,27 +2382,34 @@ public function test_discussion_subscription_deleted_validation() {
// Without an invalid context.
$params['context'] = \context_course::instance($course->id);
- $this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
+ $this->expectException('coding_exception');
+ $this->expectExceptionMessage('Context level must be CONTEXT_MODULE.');
\mod_forum\event\discussion_deleted::create($params);
// Without the discussion.
unset($params['discussion']);
- $this->setExpectedException('coding_exception', 'The \'discussion\' value must be set in other.');
+ $this->expectException('coding_exception');
+ $this->expectExceptionMessage('The \'discussion\' value must be set in other.');
\mod_forum\event\discussion_deleted::create($params);
// Without the forumid.
unset($params['forumid']);
- $this->setExpectedException('coding_exception', 'The \'forumid\' value must be set in other.');
+ $this->expectException('coding_exception');
+ $this->expectExceptionMessage('The \'forumid\' value must be set in other.');
\mod_forum\event\discussion_deleted::create($params);
// Without the relateduserid.
unset($params['relateduserid']);
- $this->setExpectedException('coding_exception', 'The \'relateduserid\' value must be set in other.');
+ $this->expectException('coding_exception');
+ $this->expectExceptionMessage('The \'relateduserid\' value must be set in other.');
\mod_forum\event\discussion_deleted::create($params);
}
/**
* 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;
@@ -2360,12 +2458,14 @@ public function test_discussion_subscription_deleted_validation_contextlevel() {
);
// Without an invalid context.
- $this->setExpectedException('coding_exception', '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;
@@ -2411,12 +2511,14 @@ public function test_discussion_subscription_deleted_validation_discussion() {
)
);
- $this->setExpectedException('coding_exception', "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;
@@ -2462,12 +2564,14 @@ public function test_discussion_subscription_deleted_validation_forumid() {
)
);
- $this->setExpectedException('coding_exception', "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;
@@ -2515,7 +2619,6 @@ public function test_discussion_subscription_deleted_validation_relateduserid()
)
);
- $this->setExpectedException('coding_exception', "The 'relateduserid' must be set.");
\mod_forum\event\discussion_subscription_deleted::create($params);
}
diff --git a/mod/forum/tests/lib_test.php b/mod/forum/tests/lib_test.php
index 8e551a584d36b..3453534017d38 100644
--- a/mod/forum/tests/lib_test.php
+++ b/mod/forum/tests/lib_test.php
@@ -1422,7 +1422,7 @@ public function test_forum_get_neighbours_with_groups() {
$this->assertEmpty($neighbours['next']);
// Querying the neighbours of a discussion passing the wrong CM.
- $this->setExpectedException('coding_exception');
+ $this->expectException('coding_exception');
forum_get_discussion_neighbours($cm2, $disc11, $forum2);
}
@@ -1622,7 +1622,7 @@ public function test_forum_get_neighbours_with_groups_blog() {
$this->assertEmpty($neighbours['next']);
// Querying the neighbours of a discussion passing the wrong CM.
- $this->setExpectedException('coding_exception');
+ $this->expectException('coding_exception');
forum_get_discussion_neighbours($cm2, $disc11, $forum2);
}
@@ -3035,12 +3035,14 @@ public function test_forum_is_author_hidden() {
$this->assertFalse(forum_is_author_hidden($post, $forum));
// Incorrect parameters: $post.
- $this->setExpectedException('coding_exception', '$post->parent must be set.');
+ $this->expectException('coding_exception');
+ $this->expectExceptionMessage('$post->parent must be set.');
unset($post->parent);
forum_is_author_hidden($post, $forum);
// Incorrect parameters: $forum.
- $this->setExpectedException('coding_exception', '$forum->type must be set.');
+ $this->expectException('coding_exception');
+ $this->expectExceptionMessage('$forum->type must be set.');
unset($forum->type);
forum_is_author_hidden($post, $forum);
}
diff --git a/mod/forum/tests/maildigest_test.php b/mod/forum/tests/maildigest_test.php
index b6940078c93cd..8dbb5e1738f66 100644
--- a/mod/forum/tests/maildigest_test.php
+++ b/mod/forum/tests/maildigest_test.php
@@ -229,7 +229,7 @@ public function test_set_maildigest() {
$this->assertFalse($currentsetting);
// Try with an invalid value.
- $this->setExpectedException('moodle_exception');
+ $this->expectException('moodle_exception');
forum_set_user_maildigest($forum1, 42, $user);
}
diff --git a/mod/glossary/tests/external_test.php b/mod/glossary/tests/external_test.php
index f05275b983f01..be9c9892ecfe7 100644
--- a/mod/glossary/tests/external_test.php
+++ b/mod/glossary/tests/external_test.php
@@ -108,6 +108,10 @@ public function test_view_glossary() {
$sink->close();
}
+ /**
+ * @expectedException require_login_exception
+ * @expectedExceptionMessage Activity is hidden
+ */
public function test_view_glossary_without_permission() {
$this->resetAfterTest(true);
@@ -126,10 +130,13 @@ public function test_view_glossary_without_permission() {
// Assertion.
$this->setUser($u1);
- $this->setExpectedException('require_login_exception', '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);
@@ -177,7 +184,6 @@ public function test_view_entry() {
}
// Test non-readable entry.
- $this->setExpectedException('require_login_exception', 'Activity is hidden');
mod_glossary_external::view_entry($e4->id);
}
@@ -1034,7 +1040,7 @@ public function test_get_entries_to_approve() {
// Permissions are checked.
$this->setUser($u1);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
mod_glossary_external::get_entries_to_approve($g1->id, 'ALL', 'CONCEPT', 'ASC', 0, 1);
$this->fail('Do not test anything else after this.');
}
diff --git a/mod/lti/tests/externallib_test.php b/mod/lti/tests/externallib_test.php
index 07fc5b47ce454..ee5ae39e76ad0 100644
--- a/mod/lti/tests/externallib_test.php
+++ b/mod/lti/tests/externallib_test.php
@@ -299,7 +299,7 @@ public function test_mod_lti_create_tool_proxy() {
* Test create tool proxy with duplicate url
*/
public function test_mod_lti_create_tool_proxy_duplicateurl() {
- $this->setExpectedException('moodle_exception');
+ $this->expectException('moodle_exception');
$proxy = mod_lti_external::create_tool_proxy('Test proxy 1', $this->getExternalTestFileUrl('/test.html'), array(), array());
$proxy = mod_lti_external::create_tool_proxy('Test proxy 2', $this->getExternalTestFileUrl('/test.html'), array(), array());
}
@@ -309,7 +309,7 @@ public function test_mod_lti_create_tool_proxy_duplicateurl() {
*/
public function test_mod_lti_create_tool_proxy_without_capability() {
self::setUser($this->teacher);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
$proxy = mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), array(), array());
}
@@ -382,7 +382,7 @@ public function test_mod_lti_create_tool_type() {
* Test create tool type failure from non existant file
*/
public function test_mod_lti_create_tool_type_nonexistant_file() {
- $this->setExpectedException('moodle_exception');
+ $this->expectException('moodle_exception');
$type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/doesntexist.xml'), '', '');
}
@@ -390,7 +390,7 @@ public function test_mod_lti_create_tool_type_nonexistant_file() {
* Test create tool type failure from xml that is not a cartridge
*/
public function test_mod_lti_create_tool_type_bad_file() {
- $this->setExpectedException('moodle_exception');
+ $this->expectException('moodle_exception');
$type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/rsstest.xml'), '', '');
}
@@ -399,7 +399,7 @@ public function test_mod_lti_create_tool_type_bad_file() {
*/
public function test_mod_lti_create_tool_type_without_capability() {
self::setUser($this->teacher);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
$type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
}
@@ -430,7 +430,7 @@ public function test_mod_lti_delete_tool_type() {
public function test_mod_lti_delete_tool_type_without_capability() {
$type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
$this->assertNotEmpty(lti_get_type($type['id']));
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
self::setUser($this->teacher);
$type = mod_lti_external::delete_tool_type($type['id']);
}
diff --git a/mod/quiz/tests/structure_test.php b/mod/quiz/tests/structure_test.php
index a8e39f82752d7..dd13daad62334 100644
--- a/mod/quiz/tests/structure_test.php
+++ b/mod/quiz/tests/structure_test.php
@@ -259,6 +259,9 @@ public function test_remove_section_heading() {
), $structure);
}
+ /**
+ * @expectedException coding_exception
+ */
public function test_cannot_remove_first_section() {
$quizobj = $this->create_test_quiz(array(
'Heading 1',
@@ -269,7 +272,6 @@ public function test_cannot_remove_first_section() {
$sections = $structure->get_sections();
$section = reset($sections);
- $this->setExpectedException('coding_exception');
$structure->remove_section_heading($section->id);
}
@@ -416,6 +418,9 @@ public function test_move_slot_emptying_a_page_renumbers_pages() {
), $structure);
}
+ /**
+ * @expectedException coding_exception
+ */
public function test_move_slot_too_small_page_number_detected() {
$quizobj = $this->create_test_quiz(array(
array('TF1', 1, 'truefalse'),
@@ -426,10 +431,12 @@ public function test_move_slot_too_small_page_number_detected() {
$idtomove = $structure->get_question_in_slot(3)->slotid;
$idmoveafter = $structure->get_question_in_slot(2)->slotid;
- $this->setExpectedException('coding_exception');
$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'),
@@ -440,7 +447,6 @@ public function test_move_slot_too_large_page_number_detected() {
$idtomove = $structure->get_question_in_slot(1)->slotid;
$idmoveafter = $structure->get_question_in_slot(2)->slotid;
- $this->setExpectedException('coding_exception');
$structure->move_slot($idtomove, $idmoveafter, '4');
}
@@ -668,6 +674,9 @@ public function test_quiz_removing_a_random_question_deletes_the_question() {
$this->assertFalse($DB->record_exists('question', array('id' => $randomq->id)));
}
+ /**
+ * @expectedException coding_exception
+ */
public function test_cannot_remove_last_slot_in_a_section() {
$quizobj = $this->create_test_quiz(array(
array('TF1', 1, 'truefalse'),
@@ -677,7 +686,6 @@ public function test_cannot_remove_last_slot_in_a_section() {
));
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
- $this->setExpectedException('coding_exception');
$structure->remove_slot(3);
}
diff --git a/mod/scorm/tests/events_test.php b/mod/scorm/tests/events_test.php
index a52cb0505fd5f..bf44adf56bf00 100644
--- a/mod/scorm/tests/events_test.php
+++ b/mod/scorm/tests/events_test.php
@@ -57,7 +57,11 @@ protected function setUp() {
$this->eventcm = get_coursemodule_from_instance('scorm', $this->eventscorm->id);
}
- /** Tests for attempt deleted event */
+ /**
+ * Tests for attempt deleted event
+ *
+ * @expectedException coding_exception
+ */
public function test_attempt_deleted_event() {
global $USER;
@@ -83,7 +87,6 @@ public function test_attempt_deleted_event() {
$this->assertEventContextNotUsed($event);
// Test event validations.
- $this->setExpectedException('coding_exception');
\mod_scorm\event\attempt_deleted::create(array(
'contextid' => 5,
'relateduserid' => 2
@@ -228,6 +231,8 @@ public function test_report_viewed_event() {
/** 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();
@@ -251,7 +256,6 @@ public function test_sco_launched_event() {
$this->assertEventContextNotUsed($event);
// Test validations.
- $this->setExpectedException('coding_exception');
\mod_scorm\event\sco_launched::create(array(
'objectid' => $this->eventscorm->id,
'context' => context_module::instance($this->eventcm->id),
diff --git a/mod/scorm/tests/externallib_test.php b/mod/scorm/tests/externallib_test.php
index 53aaeea1c3399..f081ae9d9ab2b 100644
--- a/mod/scorm/tests/externallib_test.php
+++ b/mod/scorm/tests/externallib_test.php
@@ -172,6 +172,9 @@ public function test_mod_scorm_get_scorm_attempt_count_others_as_teacher() {
$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();
@@ -181,24 +184,27 @@ public function test_mod_scorm_get_scorm_attempt_count_others_as_student() {
self::setUser($student2);
// I should not be able to view the attempts of another student.
- $this->setExpectedException('required_capability_exception');
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->setExpectedException('moodle_exception');
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->setExpectedException('moodle_exception');
mod_scorm_external::get_scorm_attempt_count($this->scorm->id, -1);
}
diff --git a/mod/scorm/tests/lib_test.php b/mod/scorm/tests/lib_test.php
index e5db5f1a089eb..174e567636ffe 100644
--- a/mod/scorm/tests/lib_test.php
+++ b/mod/scorm/tests/lib_test.php
@@ -170,14 +170,16 @@ public function test_scorm_check_and_require_available() {
// Check exceptions does not broke anything.
scorm_require_available($this->scorm, true, $this->context);
// Now, expect exceptions.
- $this->setExpectedException('moodle_exception', get_string("notopenyet", "scorm", userdate($this->scorm->timeopen)));
+ $this->expectException('moodle_exception');
+ $this->expectExceptionMessage(get_string("notopenyet", "scorm", userdate($this->scorm->timeopen)));
// Now as student other condition.
self::setUser($this->student);
$this->scorm->timeopen = 0;
$this->scorm->timeclose = time() - DAYSECS;
- $this->setExpectedException('moodle_exception', get_string("expired", "scorm", userdate($this->scorm->timeclose)));
+ $this->expectException('moodle_exception');
+ $this->expectExceptionMessage(get_string("expired", "scorm", userdate($this->scorm->timeclose)));
scorm_require_available($this->scorm, false);
}
diff --git a/mod/wiki/tests/externallib_test.php b/mod/wiki/tests/externallib_test.php
index f1ff9e829c621..2e1660bba59c8 100644
--- a/mod/wiki/tests/externallib_test.php
+++ b/mod/wiki/tests/externallib_test.php
@@ -448,26 +448,30 @@ public function test_get_subwikis() {
/**
* Test get_subwiki_pages using an invalid wiki instance.
+ *
+ * @expectedException moodle_exception
*/
public function test_get_subwiki_pages_invalid_instance() {
- $this->setExpectedException('moodle_exception');
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->setExpectedException('require_login_exception');
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.
@@ -475,12 +479,13 @@ public function test_get_subwiki_pages_hidden_wiki_as_student() {
array('course' => $this->course->id, 'visible' => false));
$this->setUser($this->student);
- $this->setExpectedException('require_login_exception');
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.
@@ -489,35 +494,38 @@ public function test_get_subwiki_pages_without_viewpage_capability() {
accesslib_clear_all_caches_for_unit_testing();
$this->setUser($this->student);
- $this->setExpectedException('moodle_exception');
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->setExpectedException('moodle_exception');
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->setExpectedException('moodle_exception');
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.
@@ -525,59 +533,62 @@ public function test_get_subwiki_pages_individual_student_see_other_user() {
array('course' => $this->course->id, 'wikimode' => 'individual'));
$this->setUser($this->student);
- $this->setExpectedException('moodle_exception');
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->setExpectedException('moodle_exception');
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->setExpectedException('moodle_exception');
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->setExpectedException('moodle_exception');
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->setExpectedException('moodle_exception');
mod_wiki_external::get_subwiki_pages($this->wikisepind->id, 0, $this->teacher->id);
}
@@ -882,26 +893,30 @@ public function test_get_subwiki_pages_visible_groups_individual() {
/**
* Test get_page_contents using an invalid pageid.
+ *
+ * @expectedException moodle_exception
*/
public function test_get_page_contents_invalid_pageid() {
- $this->setExpectedException('moodle_exception');
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->setExpectedException('require_login_exception');
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.
@@ -910,12 +925,13 @@ public function test_get_page_contents_hidden_wiki_as_student() {
$hiddenpage = $this->getDataGenerator()->get_plugin_generator('mod_wiki')->create_page($hiddenwiki);
$this->setUser($this->student);
- $this->setExpectedException('require_login_exception');
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.
@@ -924,20 +940,20 @@ public function test_get_page_contents_without_viewpage_capability() {
accesslib_clear_all_caches_for_unit_testing();
$this->setUser($this->student);
- $this->setExpectedException('moodle_exception');
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->setExpectedException('moodle_exception');
mod_wiki_external::get_page_contents($this->fpsepg2indt->id);
}
@@ -1027,13 +1043,14 @@ public function test_get_subwiki_files_no_files() {
/**
* 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->setExpectedException('moodle_exception');
mod_wiki_external::get_subwiki_files($this->wikisep->id, $this->group2->id);
}
diff --git a/mod/workshop/allocation/random/tests/allocator_test.php b/mod/workshop/allocation/random/tests/allocator_test.php
index 07327f5e20c83..9beeff1a7dd27 100644
--- a/mod/workshop/allocation/random/tests/allocator_test.php
+++ b/mod/workshop/allocation/random/tests/allocator_test.php
@@ -114,14 +114,15 @@ public function test_index_submissions_by_authors() {
), $submissions);
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_index_submissions_by_authors_duplicate_author() {
// fixture setup
$submissions = array(
14 => (object)array('id' => 676, 'authorid' => 3),
87 => (object)array('id' => 121, 'authorid' => 3),
);
- // set expectation
- $this->setExpectedException('moodle_exception');
// exercise SUT
$submissions = $this->allocator->index_submissions_by_authors($submissions);
}
diff --git a/mod/workshop/form/accumulative/tests/lib_test.php b/mod/workshop/form/accumulative/tests/lib_test.php
index 97a52ff89a660..e61d73b0402f0 100644
--- a/mod/workshop/form/accumulative/tests/lib_test.php
+++ b/mod/workshop/form/accumulative/tests/lib_test.php
@@ -78,11 +78,13 @@ public function test_calculate_peer_grade_one_numerical() {
$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');
- $this->setExpectedException('coding_exception');
// exercise SUT
$suggested = $this->strategy->calculate_peer_grade($grades);
}
@@ -176,6 +178,9 @@ public function test_calculate_peer_grade_two_scales_weighted() {
$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
@@ -183,8 +188,7 @@ public function test_calculate_peer_grade_scale_exception() {
$this->strategy->dimensions[1012] = (object)array('grade' => (-$scale13->id), 'weight' => 1);
$grades[] = (object)array('dimensionid' => 1012, 'grade' => '4.00000'); // exceeds the number of scale items
- // exercise SUT
- $this->setExpectedException('coding_exception');
+ // Exercise SUT.
$suggested = $this->strategy->calculate_peer_grade($grades);
}
}
diff --git a/mod/workshop/tests/locallib_test.php b/mod/workshop/tests/locallib_test.php
index ee4c476cf5f51..2c43f63c2422b 100644
--- a/mod/workshop/tests/locallib_test.php
+++ b/mod/workshop/tests/locallib_test.php
@@ -317,24 +317,28 @@ public function test_percent_to_value() {
$this->assertEquals($part, $total * $percent / 100);
}
+ /**
+ * @expectedException coding_exception
+ */
public function test_percent_to_value_negative() {
$this->resetAfterTest(true);
// fixture setup
$total = 185;
$percent = -7.098;
- // set expectation
- $this->setExpectedException('coding_exception');
+
// exercise SUT
$part = workshop::percent_to_value($percent, $total);
}
+ /**
+ * @expectedException coding_exception
+ */
public function test_percent_to_value_over_hundred() {
$this->resetAfterTest(true);
// fixture setup
$total = 185;
$percent = 121.08;
- // set expectation
- $this->setExpectedException('coding_exception');
+
// exercise SUT
$part = workshop::percent_to_value($percent, $total);
}
@@ -383,7 +387,7 @@ public function test_prepare_example_assessment() {
// modify setup
$fakerawrecord->weight = 1;
- $this->setExpectedException('coding_exception');
+ $this->expectException('coding_exception');
// excersise SUT
$a = $this->workshop->prepare_example_assessment($fakerawrecord);
}
@@ -412,7 +416,7 @@ public function test_prepare_example_reference_assessment() {
// modify setup
$fakerawrecord->weight = 0;
- $this->setExpectedException('coding_exception');
+ $this->expectException('coding_exception');
// excersise SUT
$a = $this->workshop->prepare_example_reference_assessment($fakerawrecord);
}
diff --git a/notes/tests/externallib_test.php b/notes/tests/externallib_test.php
index 62ee5684fd7b8..353b88c2eae6f 100644
--- a/notes/tests/externallib_test.php
+++ b/notes/tests/externallib_test.php
@@ -72,7 +72,7 @@ public function test_create_notes() {
// Call without required capability.
$this->unassignUserCapability('moodle/notes:manage', $contextid, $roleid);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
$creatednotes = core_notes_external::create_notes($notes);
}
@@ -123,7 +123,7 @@ public function test_delete_notes() {
$dnotes3 = array($creatednotes[0]['noteid']);
$this->unassignUserCapability('moodle/notes:manage', $contextid, $roleid);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
$deletednotes = core_notes_external::delete_notes($dnotes3);
$deletednotes = external_api::clean_returnvalue(core_notes_external::delete_notes_returns(), $deletednotes);
}
@@ -178,7 +178,7 @@ public function test_get_notes() {
// Call without required capability.
$this->unassignUserCapability('moodle/notes:view', $contextid, $roleid);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
$creatednotes = core_notes_external::get_notes($gnotes);
}
@@ -234,7 +234,7 @@ public function test_update_notes() {
$creatednotes = core_notes_external::create_notes($notes1);
$creatednotes = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes);
$this->unassignUserCapability('moodle/notes:manage', $contextid, $roleid);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
$note2 = array();
$note2["id"] = $creatednotes[0]['noteid'];
$note2['publishstate'] = 'personal';
diff --git a/question/behaviour/informationitem/tests/walkthrough_test.php b/question/behaviour/informationitem/tests/walkthrough_test.php
index 52382b17628a6..27896e27d5abb 100644
--- a/question/behaviour/informationitem/tests/walkthrough_test.php
+++ b/question/behaviour/informationitem/tests/walkthrough_test.php
@@ -88,7 +88,7 @@ public function test_informationitem_feedback_description() {
new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
// Check that trying to process a manual comment with a grade causes an exception.
- $this->setExpectedException('moodle_exception');
+ $this->expectException('moodle_exception');
$this->manual_grade('Not good enough!', 1, FORMAT_HTML);
}
}
diff --git a/question/behaviour/manualgraded/tests/walkthrough_test.php b/question/behaviour/manualgraded/tests/walkthrough_test.php
index 4494d3f5a4708..837797cf8e8e9 100644
--- a/question/behaviour/manualgraded/tests/walkthrough_test.php
+++ b/question/behaviour/manualgraded/tests/walkthrough_test.php
@@ -533,7 +533,7 @@ public function test_manual_graded_invalid_value_throws_exception() {
$this->quba->get_response_summary($this->slot));
// Try to process a an invalid grade.
- $this->setExpectedException('coding_exception');
+ $this->expectException('coding_exception');
$this->manual_grade('Comment', 'frog', FORMAT_HTML);
}
@@ -580,7 +580,7 @@ public function test_manual_graded_out_of_range_throws_exception() {
$this->quba->get_response_summary($this->slot));
// Try to process a an invalid grade.
- $this->setExpectedException('coding_exception');
+ $this->expectException('coding_exception');
$this->manual_grade('Comment', '10.1', FORMAT_HTML);
}
}
diff --git a/question/behaviour/missing/tests/missingbehaviour_test.php b/question/behaviour/missing/tests/missingbehaviour_test.php
index 31328b9434609..bf42694f8903b 100644
--- a/question/behaviour/missing/tests/missingbehaviour_test.php
+++ b/question/behaviour/missing/tests/missingbehaviour_test.php
@@ -39,31 +39,40 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
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->setExpectedException('moodle_exception');
$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->setExpectedException('moodle_exception');
$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->setExpectedException('moodle_exception');
$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->setExpectedException('moodle_exception');
$behaviour->get_max_fraction();
}
diff --git a/question/engine/tests/questionattempt_with_steps_test.php b/question/engine/tests/questionattempt_with_steps_test.php
index 05f745c8b8741..e8febb6dfeb73 100644
--- a/question/engine/tests/questionattempt_with_steps_test.php
+++ b/question/engine/tests/questionattempt_with_steps_test.php
@@ -57,8 +57,10 @@ protected function tearDown() {
$this->qa = null;
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_get_step_before_start() {
- $this->setExpectedException('moodle_exception');
$step = $this->qa->get_step(-1);
}
@@ -72,8 +74,10 @@ public function test_get_step_at_end() {
$this->assertEquals(2, $step->get_qt_var('i'));
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_get_step_past_end() {
- $this->setExpectedException('moodle_exception');
$step = $this->qa->get_step(3);
}
@@ -151,7 +155,7 @@ public function test_get_min_fraction() {
public function test_cannot_get_min_fraction_before_start() {
$qa = new question_attempt($this->question, 0);
- $this->setExpectedException('moodle_exception');
+ $this->expectException('moodle_exception');
$qa->get_min_fraction();
}
@@ -162,7 +166,7 @@ public function test_get_max_fraction() {
public function test_cannot_get_max_fraction_before_start() {
$qa = new question_attempt($this->question, 0);
- $this->setExpectedException('moodle_exception');
+ $this->expectException('moodle_exception');
$qa->get_max_fraction();
}
diff --git a/question/engine/tests/questionattemptiterator_test.php b/question/engine/tests/questionattemptiterator_test.php
index 71ed67c382058..81f20cab8e034 100644
--- a/question/engine/tests/questionattemptiterator_test.php
+++ b/question/engine/tests/questionattemptiterator_test.php
@@ -87,8 +87,10 @@ public function test_offsetExists_past_end() {
$this->assertFalse(isset($this->iterator[3]));
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_offsetGet_before_start() {
- $this->setExpectedException('moodle_exception');
$step = $this->iterator[0];
}
@@ -100,18 +102,24 @@ public function test_offsetGet_at_end() {
$this->assertSame($this->qas[2], $this->iterator[2]);
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_offsetGet_past_end() {
- $this->setExpectedException('moodle_exception');
$step = $this->iterator[3];
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_cannot_set() {
- $this->setExpectedException('moodle_exception');
$this->iterator[0] = null;
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_cannot_unset() {
- $this->setExpectedException('moodle_exception');
unset($this->iterator[2]);
}
}
\ No newline at end of file
diff --git a/question/engine/tests/questionattemptstep_test.php b/question/engine/tests/questionattemptstep_test.php
index 4c6955dd0b55a..9c55790701d3a 100644
--- a/question/engine/tests/questionattemptstep_test.php
+++ b/question/engine/tests/questionattemptstep_test.php
@@ -85,13 +85,13 @@ public function test_set_var() {
public function test_cannot_set_qt_var_without_underscore() {
$step = new question_attempt_step();
- $this->setExpectedException('moodle_exception');
+ $this->expectException('moodle_exception');
$step->set_qt_var('x', 1);
}
public function test_cannot_set_behaviour_var_without_underscore() {
$step = new question_attempt_step();
- $this->setExpectedException('moodle_exception');
+ $this->expectException('moodle_exception');
$step->set_behaviour_var('x', 1);
}
diff --git a/question/engine/tests/questionattemptstepiterator_test.php b/question/engine/tests/questionattemptstepiterator_test.php
index c3715af85f46c..9d90654b65ad4 100644
--- a/question/engine/tests/questionattemptstepiterator_test.php
+++ b/question/engine/tests/questionattemptstepiterator_test.php
@@ -104,8 +104,10 @@ public function test_offsetExists_past_end() {
$this->assertFalse(isset($this->iterator[3]));
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_offsetGet_before_start() {
- $this->setExpectedException('moodle_exception');
$step = $this->iterator[-1];
}
@@ -119,18 +121,24 @@ public function test_offsetGet_at_end() {
$this->assertEquals(2, $step->get_qt_var('i'));
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_offsetGet_past_end() {
- $this->setExpectedException('moodle_exception');
$step = $this->iterator[3];
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_cannot_set() {
- $this->setExpectedException('moodle_exception');
$this->iterator[0] = null;
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_cannot_unset() {
- $this->setExpectedException('moodle_exception');
unset($this->iterator[2]);
}
}
\ No newline at end of file
diff --git a/question/engine/tests/questionengine_test.php b/question/engine/tests/questionengine_test.php
index a4f7f2692ad8b..9e800b194b850 100644
--- a/question/engine/tests/questionengine_test.php
+++ b/question/engine/tests/questionengine_test.php
@@ -45,9 +45,10 @@ public function test_load_behaviour_class() {
$this->assertTrue(class_exists('qbehaviour_deferredfeedback'));
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_load_behaviour_class_missing() {
- // Set expectation.
- $this->setExpectedException('moodle_exception');
// Exercise SUT
question_engine::load_behaviour_class('nonexistantbehaviour');
}
diff --git a/question/engine/tests/questionusage_autosave_test.php b/question/engine/tests/questionusage_autosave_test.php
index cb7d7c294deb7..aa3b03fcd0383 100644
--- a/question/engine/tests/questionusage_autosave_test.php
+++ b/question/engine/tests/questionusage_autosave_test.php
@@ -566,7 +566,7 @@ public function test_concurrent_autosaves() {
$transaction->allow_commit();
// Now commit the other transaction.
- $this->setExpectedException('dml_write_exception');
+ $this->expectException('dml_write_exception');
$this->save_quba($DB2);
$transaction2->allow_commit();
diff --git a/question/engine/tests/questionusagebyactivity_test.php b/question/engine/tests/questionusagebyactivity_test.php
index 7f82f3d011888..38562a0ac8bca 100644
--- a/question/engine/tests/questionusagebyactivity_test.php
+++ b/question/engine/tests/questionusagebyactivity_test.php
@@ -94,7 +94,7 @@ public function test_get_question() {
// Exercise SUT and verify.
$this->assertSame($tf, $quba->get_question($slot));
- $this->setExpectedException('moodle_exception');
+ $this->expectException('moodle_exception');
$quba->get_question($slot + 1);
}
@@ -155,7 +155,7 @@ public function test_access_out_of_sequence_throws_exception() {
);
// Exercise SUT - now it should fail.
- $this->setExpectedException('question_out_of_sequence_exception');
+ $this->expectException('question_out_of_sequence_exception');
$quba->process_all_actions($slot, $postdata);
}
}
diff --git a/question/engine/tests/questionutils_test.php b/question/engine/tests/questionutils_test.php
index 84c5673c8f9a8..b9db0ece6758f 100644
--- a/question/engine/tests/questionutils_test.php
+++ b/question/engine/tests/questionutils_test.php
@@ -177,18 +177,24 @@ public function test_int_to_roman() {
$this->assertSame('mmmcmxcix', question_utils::int_to_roman(3999));
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_int_to_roman_too_small() {
- $this->setExpectedException('moodle_exception');
question_utils::int_to_roman(0);
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_int_to_roman_too_big() {
- $this->setExpectedException('moodle_exception');
question_utils::int_to_roman(4000);
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_int_to_roman_not_int() {
- $this->setExpectedException('moodle_exception');
question_utils::int_to_roman(1.5);
}
diff --git a/question/type/calculated/tests/variablesubstituter_test.php b/question/type/calculated/tests/variablesubstituter_test.php
index b67030652fe59..0a66ad866f427 100644
--- a/question/type/calculated/tests/variablesubstituter_test.php
+++ b/question/type/calculated/tests/variablesubstituter_test.php
@@ -48,30 +48,38 @@ public function test_simple_expression_negatives() {
$this->assertEquals(1, $vs->calculate('{a}-{b}'));
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_cannot_use_nonnumbers() {
- $this->setExpectedException('moodle_exception');
$vs = new qtype_calculated_variable_substituter(array('a' => 'frog', 'b' => -2), '.');
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_invalid_expression() {
- $this->setExpectedException('moodle_exception');
$vs = new qtype_calculated_variable_substituter(array('a' => 1, 'b' => 2), '.');
$vs->calculate('{a} + {b}?');
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_tricky_invalid_expression() {
- $this->setExpectedException('moodle_exception');
$vs = new qtype_calculated_variable_substituter(array('a' => 1, 'b' => 2), '.');
$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) {
$this->markTestSkipped('Division by zero triggers a PHP warning before PHP 7.');
}
- $this->setExpectedException('moodle_exception');
$vs = new qtype_calculated_variable_substituter(array('a' => 1, 'b' => 0), '.');
$vs->calculate('{a} / {b}');
}
diff --git a/question/type/missingtype/tests/missingtype_test.php b/question/type/missingtype/tests/missingtype_test.php
index 541436d6994c7..76b289f243a3e 100644
--- a/question/type/missingtype/tests/missingtype_test.php
+++ b/question/type/missingtype/tests/missingtype_test.php
@@ -66,14 +66,18 @@ protected function get_unknown_questiondata() {
return $questiondata;
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_cannot_grade() {
$q = new qtype_missingtype_question();
- $this->setExpectedException('moodle_exception');
$q->grade_response(array());
}
+ /**
+ * @expectedException moodle_exception
+ */
public function test_load_qtype_strict() {
- $this->setExpectedException('moodle_exception');
$qtype = question_bank::get_qtype('strange_unknown');
}
diff --git a/repository/tests/generator_test.php b/repository/tests/generator_test.php
index 9f24d63f1dcc8..71fd7a0ed15a5 100644
--- a/repository/tests/generator_test.php
+++ b/repository/tests/generator_test.php
@@ -185,7 +185,7 @@ public function test_create_instance() {
$this->assertEquals($record->contextid, $instance->contextid);
// Invalid context.
- $this->setExpectedException('coding_exception');
+ $this->expectException('coding_exception');
$record->contextid = context_block::instance($block->id)->id;
$instance = $this->getDataGenerator()->create_repository('webdav', $record);
}
diff --git a/user/tests/externallib_test.php b/user/tests/externallib_test.php
index c965b4208f97c..b87d30162fc96 100644
--- a/user/tests/externallib_test.php
+++ b/user/tests/externallib_test.php
@@ -523,7 +523,7 @@ public function test_create_users() {
// Call without required capability
$this->unassignUserCapability('moodle/user:create', $context->id, $roleid);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
$createdusers = core_user_external::create_users(array($user1));
}
@@ -554,7 +554,7 @@ public function test_delete_users() {
// Call without required capability.
$this->unassignUserCapability('moodle/user:delete', $context->id, $roleid);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
core_user_external::delete_users(array($user1->id, $user2->id));
}
@@ -634,7 +634,7 @@ public function test_update_users() {
// Call without required capability.
$this->unassignUserCapability('moodle/user:update', $context->id, $roleid);
- $this->setExpectedException('required_capability_exception');
+ $this->expectException('required_capability_exception');
core_user_external::update_users(array($user1));
}
diff --git a/user/tests/myprofile_test.php b/user/tests/myprofile_test.php
index f273192f71eee..6d94bc7a19a26 100644
--- a/user/tests/myprofile_test.php
+++ b/user/tests/myprofile_test.php
@@ -88,6 +88,9 @@ public function test_category__construct() {
$this->assertSame('class1 class2', $category->classes);
}
+ /**
+ * @expectedException coding_exception
+ */
public function test_validate_after_order1() {
$category = new \phpunit_fixture_myprofile_category('category', 'title', null);
@@ -100,11 +103,13 @@ public function test_validate_after_order1() {
$category->add_node($node2);
$category->add_node($node1);
- $this->setExpectedException('coding_exception');
$category->validate_after_order();
}
+ /**
+ * @expectedException coding_exception
+ */
public function test_validate_after_order2() {
$category = new \phpunit_fixture_myprofile_category('category', 'title', null);
@@ -117,7 +122,6 @@ public function test_validate_after_order2() {
$category->add_node($node2);
$category->add_node($node1);
- $this->setExpectedException('coding_exception');
$category->validate_after_order();
}
@@ -167,6 +171,8 @@ public function test_find_nodes_after() {
/**
* Test category::sort_nodes().
+ *
+ * @expectedException coding_exception
*/
public function test_sort_nodes1() {
$category = new \phpunit_fixture_myprofile_category('category', 'title', null);
@@ -213,7 +219,6 @@ public function test_sort_nodes1() {
// 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->setExpectedException('coding_exception');
$category->sort_nodes();
}
@@ -259,6 +264,8 @@ public function test_sort_nodes2() {
/**
* Test tree::add_node().
+ *
+ * @expectedException coding_exception
*/
public function test_tree_add_node() {
$tree = new \phpunit_fixture_myprofile_tree();
@@ -269,12 +276,13 @@ public function test_tree_add_node() {
$this->assertEquals($node1, $node);
// Can't add node with same name.
- $this->setExpectedException('coding_exception');
$tree->add_node($node1);
}
/**
* Test tree::add_category().
+ *
+ * @expectedException coding_exception
*/
public function test_tree_add_category() {
$tree = new \phpunit_fixture_myprofile_tree();
@@ -285,7 +293,6 @@ public function test_tree_add_category() {
$this->assertEquals($category1, $category);
// Can't add node with same name.
- $this->setExpectedException('coding_exception');
$tree->add_category($category1);
}
@@ -334,6 +341,8 @@ public function test_find_categories_after() {
/**
* Test tree::sort_categories().
+ *
+ * @expectedException coding_exception
*/
public function test_sort_categories() {
$tree = new \phpunit_fixture_myprofile_tree('category', 'title', null);
@@ -372,7 +381,6 @@ public function test_sort_categories() {
$this->assertEquals($category6, $category);
// Can't add category with same name.
- $this->setExpectedException('coding_exception');
$tree->add_category($category1);
}
}
diff --git a/webservice/xmlrpc/tests/lib_test.php b/webservice/xmlrpc/tests/lib_test.php
index 8f38a54648276..8adc4384f5d91 100644
--- a/webservice/xmlrpc/tests/lib_test.php
+++ b/webservice/xmlrpc/tests/lib_test.php
@@ -85,7 +85,7 @@ public function test_client_with_fault_response() {
$client = new webservice_xmlrpc_client_mock('/webservice/xmlrpc/server.php', 'anytoken');
$mockresponse = file_get_contents($CFG->dirroot . '/webservice/xmlrpc/tests/fixtures/fault_response.xml');
$client->set_mock_response($mockresponse);
- $this->setExpectedException('moodle_exception');
+ $this->expectException('moodle_exception');
$client->call('testfunction');
}
}