Merge branch 'wip-mdl-55091-m' of https://github.com/rajeshtaneja/moodle
Conflicts: lib/upgrade.txt
This commit is contained in:
@@ -62,9 +62,10 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
|
||||
cohort_add_member($this->cohort->id, $this->userassignover->id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_create_cohort_role_assignment_without_permission() {
|
||||
$this->setExpectedException('required_capability_exception');
|
||||
$this->setUser($this->userassignto);
|
||||
$params = (object) array(
|
||||
'userid' => $this->userassignto->id,
|
||||
@@ -74,8 +75,10 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
|
||||
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 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
|
||||
$this->assertEquals($result->get_cohortid(), $this->cohort->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_delete_cohort_role_assignment_without_permission() {
|
||||
$this->setAdminUser();
|
||||
$params = (object) array(
|
||||
@@ -107,11 +113,13 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
|
||||
'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 @@ class tool_cohortroles_api_testcase extends advanced_testcase {
|
||||
'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);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,11 @@ class tool_langimport_events_testcase extends advanced_testcase {
|
||||
$this->assertEquals(context_system::instance(), $event->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'langcode' value must be set to a valid language code
|
||||
*/
|
||||
public function test_langpack_updated_validation() {
|
||||
$this->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 @@ class tool_langimport_events_testcase extends advanced_testcase {
|
||||
$this->assertEquals(context_system::instance(), $event->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'langcode' value must be set to a valid language code
|
||||
*/
|
||||
public function test_langpack_installed_validation() {
|
||||
$this->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 @@ class tool_langimport_events_testcase extends advanced_testcase {
|
||||
$this->assertEquals(context_system::instance(), $event->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'langcode' value must be set to a valid language code
|
||||
*/
|
||||
public function test_langpack_removed_validation() {
|
||||
$this->setExpectedException('coding_exception', 'The \'langcode\' value must be set to a valid language code');
|
||||
|
||||
\tool_langimport\event\langpack_removed::event_with_langcode('broken langcode');
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ class tool_monitor_generator_testcase extends advanced_testcase {
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,10 @@ class tool_monitor_subscription_testcase extends advanced_testcase {
|
||||
$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 @@ class tool_monitor_subscription_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for the magic __get method.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_magic_get() {
|
||||
$this->assertEquals(20, $this->subscription->courseid);
|
||||
$this->setExpectedException('coding_exception');
|
||||
$this->subscription->ruleid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,16 +35,21 @@ global $CFG;
|
||||
*/
|
||||
class tool_uploadcourse_course_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_proceed_without_prepare() {
|
||||
$this->resetAfterTest(true);
|
||||
$mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
|
||||
$updatemode = tool_uploadcourse_processor::UPDATE_NOTHING;
|
||||
$data = array();
|
||||
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
|
||||
$this->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 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
|
||||
$data = array();
|
||||
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
|
||||
$this->assertFalse($co->prepare());
|
||||
$this->setExpectedException('moodle_exception');
|
||||
$co->proceed();
|
||||
}
|
||||
|
||||
@@ -64,7 +68,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
|
||||
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
|
||||
$this->assertTrue($co->prepare());
|
||||
$co->proceed();
|
||||
$this->setExpectedException('coding_exception');
|
||||
$this->expectException('coding_exception');
|
||||
$co->proceed();
|
||||
}
|
||||
|
||||
|
||||
@@ -160,6 +160,9 @@ class tool_uploadcourse_processor_testcase extends advanced_testcase {
|
||||
$this->assertEquals('ID123: Course 1', $c->shortname);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_empty_csv() {
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
@@ -171,10 +174,12 @@ class tool_uploadcourse_processor_testcase extends advanced_testcase {
|
||||
$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 @@ class tool_uploadcourse_processor_testcase extends advanced_testcase {
|
||||
$cir->init();
|
||||
|
||||
$options = array('mode' => tool_uploadcourse_processor::MODE_CREATE_NEW);
|
||||
$this->setExpectedException('moodle_exception');
|
||||
$p = new tool_uploadcourse_processor($cir, $options, array());
|
||||
}
|
||||
|
||||
|
||||
@@ -88,18 +88,22 @@ class core_backup_moodle1_converter_testcase extends advanced_testcase {
|
||||
$this->assertInstanceOf('moodle1_converter', $converter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle1_convert_storage_exception
|
||||
*/
|
||||
public function test_stash_storage_not_created() {
|
||||
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
|
||||
$this->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 @@ class core_backup_moodle1_converter_testcase extends advanced_testcase {
|
||||
$this->assertSame(null, $data['nothing']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException convert_path_exception
|
||||
*/
|
||||
public function test_grouped_data_on_nongrouped_convert_path() {
|
||||
// prepare some grouped data
|
||||
$data = array(
|
||||
@@ -457,10 +464,12 @@ class core_backup_moodle1_converter_testcase extends advanced_testcase {
|
||||
$path = new convert_path('beer_style', '/ROOT/BEER_STYLES/BEER_STYLE');
|
||||
|
||||
// an attempt to apply recipes throws exception because we do not expect grouped data
|
||||
$this->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 @@ class core_backup_moodle1_converter_testcase extends advanced_testcase {
|
||||
$this->assertEquals('Heineken', $data['beers'][1]['beer']['name']);
|
||||
|
||||
// an attempt to provide explicit recipes on grouped elements throws exception
|
||||
$this->setExpectedException('convert_path_exception');
|
||||
$path = new convert_path(
|
||||
'beer_style', '/ROOT/BEER_STYLES/BEER_STYLE',
|
||||
array(
|
||||
@@ -573,7 +581,7 @@ as it is parsed from the backup file. <br /><br /><img border="0" width="110" vs
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -787,7 +787,7 @@ class progressive_parser_test extends advanced_testcase {
|
||||
* - 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 {
|
||||
|
||||
@@ -131,6 +131,8 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test delete_calendar_events
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_delete_calendar_events() {
|
||||
global $DB, $USER;
|
||||
@@ -247,7 +249,7 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase {
|
||||
$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),
|
||||
|
||||
@@ -45,6 +45,9 @@ class core_calendar_ical_testcase extends advanced_testcase {
|
||||
require_once($CFG->dirroot . '/calendar/lib.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_calendar_update_subscription() {
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
@@ -71,7 +74,6 @@ class core_calendar_ical_testcase extends advanced_testcase {
|
||||
|
||||
$subscription = new stdClass();
|
||||
$subscription->name = 'awesome4';
|
||||
$this->setExpectedException('coding_exception');
|
||||
calendar_update_subscription($subscription);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,22 +86,24 @@ class core_calendar_rrule_manager_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
@@ -64,6 +64,10 @@ class core_cohort_cohortlib_testcase extends advanced_testcase {
|
||||
$this->assertSame($newcohort->timecreated, $newcohort->timemodified);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Missing cohort name in cohort_add_cohort().
|
||||
*/
|
||||
public function test_cohort_add_cohort_missing_name() {
|
||||
$cohort = new stdClass();
|
||||
$cohort->contextid = context_system::instance()->id;
|
||||
@@ -72,7 +76,6 @@ class core_cohort_cohortlib_testcase extends advanced_testcase {
|
||||
$cohort->description = 'test cohort desc';
|
||||
$cohort->descriptionformat = FORMAT_HTML;
|
||||
|
||||
$this->setExpectedException('coding_exception', 'Missing cohort name in cohort_add_cohort().');
|
||||
cohort_add_cohort($cohort);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
$cohort1 = self::getDataGenerator()->create_cohort();
|
||||
$cohort2 = self::getDataGenerator()->create_cohort();
|
||||
$this->unassignUserCapability('moodle/cohort:manage', $contextid, $roleid);
|
||||
$this->setExpectedException('required_capability_exception');
|
||||
core_cohort_external::delete_cohorts(array($cohort1->id, $cohort2->id));
|
||||
}
|
||||
|
||||
@@ -183,6 +185,8 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test update_cohorts
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_update_cohorts() {
|
||||
global $USER, $CFG, $DB;
|
||||
@@ -224,7 +228,6 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test update_cohorts without permission on the dest category.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_update_cohorts_missing_dest() {
|
||||
global $USER, $CFG, $DB;
|
||||
@@ -295,12 +300,13 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// Call the external function.
|
||||
// Should fail because we don't have permission on the dest category
|
||||
$this->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 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// Call the external function.
|
||||
// Should fail because we don't have permission on the src category
|
||||
$this->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 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
'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 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,6 +166,8 @@ class core_competency_api_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test updating a template.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_update_template() {
|
||||
$cat = $this->getDataGenerator()->create_category();
|
||||
@@ -184,7 +186,6 @@ class core_competency_api_testcase extends advanced_testcase {
|
||||
$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 @@ class core_competency_api_testcase extends advanced_testcase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_create_plan_from_template() {
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
@@ -531,7 +535,6 @@ class core_competency_api_testcase extends advanced_testcase {
|
||||
$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 @@ class core_competency_api_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test that the method to complete a plan.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_complete_plan() {
|
||||
global $DB;
|
||||
@@ -833,7 +838,6 @@ class core_competency_api_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
// Completing a plan that is completed throws an exception.
|
||||
$this->setExpectedException('coding_exception');
|
||||
api::complete_plan($plan);
|
||||
}
|
||||
|
||||
@@ -4430,6 +4434,9 @@ class core_competency_api_testcase extends advanced_testcase {
|
||||
$this->assertTrue(evidence::record_exists($ev2->get_id()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_delete_evidence_without_permissions() {
|
||||
$this->resetAfterTest();
|
||||
$dg = $this->getDataGenerator();
|
||||
@@ -4442,7 +4449,6 @@ class core_competency_api_testcase extends advanced_testcase {
|
||||
$ev1 = $ccg->create_evidence(['usercompetencyid' => $uc1->get_id()]);
|
||||
|
||||
$this->setUser($u1);
|
||||
$this->setExpectedException('required_capability_exception');
|
||||
|
||||
api::delete_evidence($ev1);
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ class core_competency_course_competency_settings_testcase extends advanced_testc
|
||||
$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));
|
||||
}
|
||||
|
||||
|
||||
@@ -1360,6 +1360,9 @@ class core_competency_event_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test evidence_created event by linking an invalid user competency to an evidence.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The user competency linked with this evidence is invalid.
|
||||
*/
|
||||
public function test_evidence_created_with_invalid_user_competency() {
|
||||
$this->resetAfterTest(true);
|
||||
@@ -1385,7 +1388,6 @@ class core_competency_event_testcase extends advanced_testcase {
|
||||
'commentincontext', 'core', null, $recommend, null, 1);
|
||||
|
||||
// We expect this to fail and throw a coding exception.
|
||||
$this->setExpectedException('coding_exception', 'The user competency linked with this evidence is invalid.');
|
||||
\core\event\competency_evidence_created::create_from_evidence($evidence, $otheruc, $recommend)->trigger();
|
||||
}
|
||||
|
||||
|
||||
@@ -82,18 +82,22 @@ class core_competency_exporter_testcase extends advanced_testcase {
|
||||
$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');
|
||||
|
||||
|
||||
@@ -303,9 +303,10 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test we can't create a competency framework with only read permissions.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_create_competency_frameworks_with_read_permissions() {
|
||||
$this->setExpectedException('required_capability_exception');
|
||||
$this->setUser($this->user);
|
||||
|
||||
$result = $this->create_competency_framework(1, true);
|
||||
@@ -313,9 +314,10 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test we can't create a competency framework with only read permissions.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_create_competency_frameworks_with_read_permissions_in_category() {
|
||||
$this->setExpectedException('required_capability_exception');
|
||||
$this->setUser($this->catuser);
|
||||
$result = $this->create_competency_framework(1, false);
|
||||
}
|
||||
@@ -367,10 +369,11 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test we cannot create a competency framework with nasty data.
|
||||
*
|
||||
* @expectedException invalid_parameter_exception
|
||||
*/
|
||||
public function test_create_competency_frameworks_with_nasty_data() {
|
||||
$this->setUser($this->creator);
|
||||
$this->setExpectedException('invalid_parameter_exception');
|
||||
$framework = array(
|
||||
'shortname' => 'short<a href="">',
|
||||
'idnumber' => 'id;"number',
|
||||
@@ -543,9 +546,10 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test we can delete a competency framework with read permissions.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_delete_competency_frameworks_with_read_permissions() {
|
||||
$this->setExpectedException('required_capability_exception');
|
||||
$this->setUser($this->creator);
|
||||
$result = $this->create_competency_framework(1, true);
|
||||
|
||||
@@ -624,9 +628,10 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test we can update a competency framework with read permissions.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_update_competency_frameworks_with_read_permissions() {
|
||||
$this->setExpectedException('required_capability_exception');
|
||||
$this->setUser($this->creator);
|
||||
$result = $this->create_competency_framework(1, true);
|
||||
|
||||
@@ -757,9 +762,10 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test we can't create a competency with only read permissions.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_create_competency_with_read_permissions() {
|
||||
$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 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test we cannot create a competency with nasty data.
|
||||
*
|
||||
* @expectedException invalid_parameter_exception
|
||||
*/
|
||||
public function test_create_competency_with_nasty_data() {
|
||||
$this->setUser($this->creator);
|
||||
$framework = $this->create_competency_framework(1, true);
|
||||
$this->setExpectedException('invalid_parameter_exception');
|
||||
$competency = array(
|
||||
'shortname' => 'shortname<a href="">',
|
||||
'idnumber' => 'id;"number',
|
||||
@@ -995,9 +1002,10 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test we can delete a competency with read permissions.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_delete_competency_with_read_permissions() {
|
||||
$this->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 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test we can update a competency with read permissions.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_update_competency_with_read_permissions() {
|
||||
$this->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 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
$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 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
$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 @@ class core_competency_external_testcase extends externallib_advanced_testcase {
|
||||
$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));
|
||||
}
|
||||
|
||||
|
||||
@@ -178,12 +178,15 @@ class core_competency_persistent_testcase extends advanced_testcase {
|
||||
$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);
|
||||
}
|
||||
|
||||
|
||||
@@ -526,6 +526,10 @@ class core_competency_plan_testcase extends advanced_testcase {
|
||||
$this->assertCount(0, $plans);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The competency does not belong to this template:
|
||||
*/
|
||||
public function test_get_competency() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
@@ -567,7 +571,6 @@ class core_competency_plan_testcase extends advanced_testcase {
|
||||
$this->assertEquals($c4->to_record(), $p4->get_competency($c4->get_id())->to_record());
|
||||
|
||||
// Getting the competency 4 from the non-completed plan based on a template p4, will throw an exception.
|
||||
$this->setExpectedException('coding_exception', 'The competency does not belong to this template: ');
|
||||
$p3->get_competency($c4->get_id());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
"type": "project",
|
||||
"homepage": "https://moodle.org",
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "4.8.*",
|
||||
"phpunit/phpunit": "5.4.*",
|
||||
"phpunit/dbUnit": "1.4.*",
|
||||
"moodlehq/behat-extension": "3.32.1"
|
||||
}
|
||||
|
||||
Generated
+623
-320
File diff suppressed because it is too large
Load Diff
@@ -120,7 +120,7 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
$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);
|
||||
|
||||
}
|
||||
@@ -1519,7 +1519,8 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
$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);;
|
||||
}
|
||||
|
||||
@@ -316,7 +316,8 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase {
|
||||
}
|
||||
} 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 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase {
|
||||
/**
|
||||
* Test get_enrolled_users from core_enrol_external with capability to
|
||||
* viewparticipants removed.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_enrolled_users_without_capability() {
|
||||
$capability = 'moodle/course:viewparticipants';
|
||||
@@ -572,7 +575,6 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class core_enrol_role_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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 @@ class core_enrol_role_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ class core_files_externallib_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_externallib_testcase extends advanced_testcase {
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -67,6 +67,8 @@ class core_grade_grading_manager_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Unit test to set and get grading areas
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_set_and_get_grading_area() {
|
||||
global $DB;
|
||||
@@ -103,7 +105,6 @@ class core_grade_grading_manager_testcase extends advanced_testcase {
|
||||
$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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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 @@ class core_group_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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 @@ class core_group_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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 @@ class core_group_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -72,7 +72,7 @@ class core_external_testcase extends externallib_advanced_testcase {
|
||||
$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)));
|
||||
|
||||
@@ -236,7 +236,7 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$filerecord->timemodified = 'today';
|
||||
|
||||
$this->setExpectedException('file_exception', 'Invalid file timemodified');
|
||||
$file1 = $fs->create_file_from_string($filerecord, 'text contents');
|
||||
}
|
||||
|
||||
@@ -1353,10 +1409,14 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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 @@ class core_files_file_storage_testcase extends advanced_testcase {
|
||||
$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, '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,10 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
abstract class base_testcase extends PHPUnit_Framework_TestCase {
|
||||
// @codingStandardsIgnoreStart
|
||||
// Following code is legacy code from phpunit to support assertTag
|
||||
// and assertNotTag.
|
||||
|
||||
/**
|
||||
* Note: we are overriding this method to remove the deprecated error
|
||||
* @see https://tracker.moodle.org/browse/MDL-47129
|
||||
@@ -50,7 +54,7 @@ abstract class base_testcase extends PHPUnit_Framework_TestCase {
|
||||
*/
|
||||
public static function assertTag($matcher, $actual, $message = '', $ishtml = true) {
|
||||
$dom = PHPUnit_Util_XML::load($actual, $ishtml);
|
||||
$tags = PHPUnit_Util_XML::findNodes($dom, $matcher, $ishtml);
|
||||
$tags = self::findNodes($dom, $matcher, $ishtml);
|
||||
$matched = count($tags) > 0 && $tags[0] instanceof DOMNode;
|
||||
self::assertTrue($matched, $message);
|
||||
}
|
||||
@@ -68,8 +72,503 @@ abstract class base_testcase extends PHPUnit_Framework_TestCase {
|
||||
*/
|
||||
public static function assertNotTag($matcher, $actual, $message = '', $ishtml = true) {
|
||||
$dom = PHPUnit_Util_XML::load($actual, $ishtml);
|
||||
$tags = PHPUnit_Util_XML::findNodes($dom, $matcher, $ishtml);
|
||||
$tags = self::findNodes($dom, $matcher, $ishtml);
|
||||
$matched = count($tags) > 0 && $tags[0] instanceof DOMNode;
|
||||
self::assertFalse($matched, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate list of keys in the associative array.
|
||||
*
|
||||
* @param array $hash
|
||||
* @param array $validKeys
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws PHPUnit_Framework_Exception
|
||||
*/
|
||||
public static function assertValidKeys(array $hash, array $validKeys) {
|
||||
$valids = array();
|
||||
|
||||
// Normalize validation keys so that we can use both indexed and
|
||||
// associative arrays.
|
||||
foreach ($validKeys as $key => $val) {
|
||||
is_int($key) ? $valids[$val] = null : $valids[$key] = $val;
|
||||
}
|
||||
|
||||
$validKeys = array_keys($valids);
|
||||
|
||||
// Check for invalid keys.
|
||||
foreach ($hash as $key => $value) {
|
||||
if (!in_array($key, $validKeys)) {
|
||||
$unknown[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($unknown)) {
|
||||
throw new PHPUnit_Framework_Exception(
|
||||
'Unknown key(s): ' . implode(', ', $unknown)
|
||||
);
|
||||
}
|
||||
|
||||
// Add default values for any valid keys that are empty.
|
||||
foreach ($valids as $key => $value) {
|
||||
if (!isset($hash[$key])) {
|
||||
$hash[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse out the options from the tag using DOM object tree.
|
||||
*
|
||||
* @param DOMDocument $dom
|
||||
* @param array $options
|
||||
* @param bool $isHtml
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function findNodes(DOMDocument $dom, array $options, $isHtml = true) {
|
||||
$valid = array(
|
||||
'id', 'class', 'tag', 'content', 'attributes', 'parent',
|
||||
'child', 'ancestor', 'descendant', 'children', 'adjacent-sibling'
|
||||
);
|
||||
|
||||
$filtered = array();
|
||||
$options = self::assertValidKeys($options, $valid);
|
||||
|
||||
// find the element by id
|
||||
if ($options['id']) {
|
||||
$options['attributes']['id'] = $options['id'];
|
||||
}
|
||||
|
||||
if ($options['class']) {
|
||||
$options['attributes']['class'] = $options['class'];
|
||||
}
|
||||
|
||||
$nodes = array();
|
||||
|
||||
// find the element by a tag type
|
||||
if ($options['tag']) {
|
||||
if ($isHtml) {
|
||||
$elements = self::getElementsByCaseInsensitiveTagName(
|
||||
$dom,
|
||||
$options['tag']
|
||||
);
|
||||
} else {
|
||||
$elements = $dom->getElementsByTagName($options['tag']);
|
||||
}
|
||||
|
||||
foreach ($elements as $element) {
|
||||
$nodes[] = $element;
|
||||
}
|
||||
|
||||
if (empty($nodes)) {
|
||||
return false;
|
||||
}
|
||||
} // no tag selected, get them all
|
||||
else {
|
||||
$tags = array(
|
||||
'a', 'abbr', 'acronym', 'address', 'area', 'b', 'base', 'bdo',
|
||||
'big', 'blockquote', 'body', 'br', 'button', 'caption', 'cite',
|
||||
'code', 'col', 'colgroup', 'dd', 'del', 'div', 'dfn', 'dl',
|
||||
'dt', 'em', 'fieldset', 'form', 'frame', 'frameset', 'h1', 'h2',
|
||||
'h3', 'h4', 'h5', 'h6', 'head', 'hr', 'html', 'i', 'iframe',
|
||||
'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'link',
|
||||
'map', 'meta', 'noframes', 'noscript', 'object', 'ol', 'optgroup',
|
||||
'option', 'p', 'param', 'pre', 'q', 'samp', 'script', 'select',
|
||||
'small', 'span', 'strong', 'style', 'sub', 'sup', 'table',
|
||||
'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'title',
|
||||
'tr', 'tt', 'ul', 'var',
|
||||
// HTML5
|
||||
'article', 'aside', 'audio', 'bdi', 'canvas', 'command',
|
||||
'datalist', 'details', 'dialog', 'embed', 'figure', 'figcaption',
|
||||
'footer', 'header', 'hgroup', 'keygen', 'mark', 'meter', 'nav',
|
||||
'output', 'progress', 'ruby', 'rt', 'rp', 'track', 'section',
|
||||
'source', 'summary', 'time', 'video', 'wbr'
|
||||
);
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
if ($isHtml) {
|
||||
$elements = self::getElementsByCaseInsensitiveTagName(
|
||||
$dom,
|
||||
$tag
|
||||
);
|
||||
} else {
|
||||
$elements = $dom->getElementsByTagName($tag);
|
||||
}
|
||||
|
||||
foreach ($elements as $element) {
|
||||
$nodes[] = $element;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($nodes)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// filter by attributes
|
||||
if ($options['attributes']) {
|
||||
foreach ($nodes as $node) {
|
||||
$invalid = false;
|
||||
|
||||
foreach ($options['attributes'] as $name => $value) {
|
||||
// match by regexp if like "regexp:/foo/i"
|
||||
if (preg_match('/^regexp\s*:\s*(.*)/i', $value, $matches)) {
|
||||
if (!preg_match($matches[1], $node->getAttribute($name))) {
|
||||
$invalid = true;
|
||||
}
|
||||
} // class can match only a part
|
||||
elseif ($name == 'class') {
|
||||
// split to individual classes
|
||||
$findClasses = explode(
|
||||
' ',
|
||||
preg_replace("/\s+/", ' ', $value)
|
||||
);
|
||||
|
||||
$allClasses = explode(
|
||||
' ',
|
||||
preg_replace("/\s+/", ' ', $node->getAttribute($name))
|
||||
);
|
||||
|
||||
// make sure each class given is in the actual node
|
||||
foreach ($findClasses as $findClass) {
|
||||
if (!in_array($findClass, $allClasses)) {
|
||||
$invalid = true;
|
||||
}
|
||||
}
|
||||
} // match by exact string
|
||||
else {
|
||||
if ($node->getAttribute($name) != $value) {
|
||||
$invalid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if every attribute given matched
|
||||
if (!$invalid) {
|
||||
$filtered[] = $node;
|
||||
}
|
||||
}
|
||||
|
||||
$nodes = $filtered;
|
||||
$filtered = array();
|
||||
|
||||
if (empty($nodes)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// filter by content
|
||||
if ($options['content'] !== null) {
|
||||
foreach ($nodes as $node) {
|
||||
$invalid = false;
|
||||
|
||||
// match by regexp if like "regexp:/foo/i"
|
||||
if (preg_match('/^regexp\s*:\s*(.*)/i', $options['content'], $matches)) {
|
||||
if (!preg_match($matches[1], self::getNodeText($node))) {
|
||||
$invalid = true;
|
||||
}
|
||||
} // match empty string
|
||||
elseif ($options['content'] === '') {
|
||||
if (self::getNodeText($node) !== '') {
|
||||
$invalid = true;
|
||||
}
|
||||
} // match by exact string
|
||||
elseif (strstr(self::getNodeText($node), $options['content']) === false) {
|
||||
$invalid = true;
|
||||
}
|
||||
|
||||
if (!$invalid) {
|
||||
$filtered[] = $node;
|
||||
}
|
||||
}
|
||||
|
||||
$nodes = $filtered;
|
||||
$filtered = array();
|
||||
|
||||
if (empty($nodes)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// filter by parent node
|
||||
if ($options['parent']) {
|
||||
$parentNodes = self::findNodes($dom, $options['parent'], $isHtml);
|
||||
$parentNode = isset($parentNodes[0]) ? $parentNodes[0] : null;
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
if ($parentNode !== $node->parentNode) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$filtered[] = $node;
|
||||
}
|
||||
|
||||
$nodes = $filtered;
|
||||
$filtered = array();
|
||||
|
||||
if (empty($nodes)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// filter by child node
|
||||
if ($options['child']) {
|
||||
$childNodes = self::findNodes($dom, $options['child'], $isHtml);
|
||||
$childNodes = !empty($childNodes) ? $childNodes : array();
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
foreach ($node->childNodes as $child) {
|
||||
foreach ($childNodes as $childNode) {
|
||||
if ($childNode === $child) {
|
||||
$filtered[] = $node;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$nodes = $filtered;
|
||||
$filtered = array();
|
||||
|
||||
if (empty($nodes)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// filter by adjacent-sibling
|
||||
if ($options['adjacent-sibling']) {
|
||||
$adjacentSiblingNodes = self::findNodes($dom, $options['adjacent-sibling'], $isHtml);
|
||||
$adjacentSiblingNodes = !empty($adjacentSiblingNodes) ? $adjacentSiblingNodes : array();
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
$sibling = $node;
|
||||
|
||||
while ($sibling = $sibling->nextSibling) {
|
||||
if ($sibling->nodeType !== XML_ELEMENT_NODE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($adjacentSiblingNodes as $adjacentSiblingNode) {
|
||||
if ($sibling === $adjacentSiblingNode) {
|
||||
$filtered[] = $node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$nodes = $filtered;
|
||||
$filtered = array();
|
||||
|
||||
if (empty($nodes)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// filter by ancestor
|
||||
if ($options['ancestor']) {
|
||||
$ancestorNodes = self::findNodes($dom, $options['ancestor'], $isHtml);
|
||||
$ancestorNode = isset($ancestorNodes[0]) ? $ancestorNodes[0] : null;
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
$parent = $node->parentNode;
|
||||
|
||||
while ($parent && $parent->nodeType != XML_HTML_DOCUMENT_NODE) {
|
||||
if ($parent === $ancestorNode) {
|
||||
$filtered[] = $node;
|
||||
}
|
||||
|
||||
$parent = $parent->parentNode;
|
||||
}
|
||||
}
|
||||
|
||||
$nodes = $filtered;
|
||||
$filtered = array();
|
||||
|
||||
if (empty($nodes)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// filter by descendant
|
||||
if ($options['descendant']) {
|
||||
$descendantNodes = self::findNodes($dom, $options['descendant'], $isHtml);
|
||||
$descendantNodes = !empty($descendantNodes) ? $descendantNodes : array();
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
foreach (self::getDescendants($node) as $descendant) {
|
||||
foreach ($descendantNodes as $descendantNode) {
|
||||
if ($descendantNode === $descendant) {
|
||||
$filtered[] = $node;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$nodes = $filtered;
|
||||
$filtered = array();
|
||||
|
||||
if (empty($nodes)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// filter by children
|
||||
if ($options['children']) {
|
||||
$validChild = array('count', 'greater_than', 'less_than', 'only');
|
||||
$childOptions = self::assertValidKeys(
|
||||
$options['children'],
|
||||
$validChild
|
||||
);
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
$childNodes = $node->childNodes;
|
||||
|
||||
foreach ($childNodes as $childNode) {
|
||||
if ($childNode->nodeType !== XML_CDATA_SECTION_NODE &&
|
||||
$childNode->nodeType !== XML_TEXT_NODE) {
|
||||
$children[] = $childNode;
|
||||
}
|
||||
}
|
||||
|
||||
// we must have children to pass this filter
|
||||
if (!empty($children)) {
|
||||
// exact count of children
|
||||
if ($childOptions['count'] !== null) {
|
||||
if (count($children) !== $childOptions['count']) {
|
||||
break;
|
||||
}
|
||||
} // range count of children
|
||||
elseif ($childOptions['less_than'] !== null &&
|
||||
$childOptions['greater_than'] !== null) {
|
||||
if (count($children) >= $childOptions['less_than'] ||
|
||||
count($children) <= $childOptions['greater_than']) {
|
||||
break;
|
||||
}
|
||||
} // less than a given count
|
||||
elseif ($childOptions['less_than'] !== null) {
|
||||
if (count($children) >= $childOptions['less_than']) {
|
||||
break;
|
||||
}
|
||||
} // more than a given count
|
||||
elseif ($childOptions['greater_than'] !== null) {
|
||||
if (count($children) <= $childOptions['greater_than']) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// match each child against a specific tag
|
||||
if ($childOptions['only']) {
|
||||
$onlyNodes = self::findNodes(
|
||||
$dom,
|
||||
$childOptions['only'],
|
||||
$isHtml
|
||||
);
|
||||
|
||||
// try to match each child to one of the 'only' nodes
|
||||
foreach ($children as $child) {
|
||||
$matched = false;
|
||||
|
||||
foreach ($onlyNodes as $onlyNode) {
|
||||
if ($onlyNode === $child) {
|
||||
$matched = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$matched) {
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$filtered[] = $node;
|
||||
}
|
||||
}
|
||||
|
||||
$nodes = $filtered;
|
||||
|
||||
if (empty($nodes)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// return the first node that matches all criteria
|
||||
return !empty($nodes) ? $nodes : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively get flat array of all descendants of this node.
|
||||
*
|
||||
* @param DOMNode $node
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function getDescendants(DOMNode $node) {
|
||||
$allChildren = array();
|
||||
$childNodes = $node->childNodes ? $node->childNodes : array();
|
||||
|
||||
foreach ($childNodes as $child) {
|
||||
if ($child->nodeType === XML_CDATA_SECTION_NODE ||
|
||||
$child->nodeType === XML_TEXT_NODE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$children = self::getDescendants($child);
|
||||
$allChildren = array_merge($allChildren, $children, array($child));
|
||||
}
|
||||
|
||||
return isset($allChildren) ? $allChildren : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets elements by case insensitive tagname.
|
||||
*
|
||||
* @param DOMDocument $dom
|
||||
* @param string $tag
|
||||
*
|
||||
* @return DOMNodeList
|
||||
*/
|
||||
protected static function getElementsByCaseInsensitiveTagName(DOMDocument $dom, $tag) {
|
||||
$elements = $dom->getElementsByTagName(strtolower($tag));
|
||||
|
||||
if ($elements->length == 0) {
|
||||
$elements = $dom->getElementsByTagName(strtoupper($tag));
|
||||
}
|
||||
|
||||
return $elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text value of this node's child text node.
|
||||
*
|
||||
* @param DOMNode $node
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getNodeText(DOMNode $node) {
|
||||
if (!$node->childNodes instanceof DOMNodeList) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$result = '';
|
||||
|
||||
foreach ($node->childNodes as $childNode) {
|
||||
if ($childNode->nodeType === XML_TEXT_NODE ||
|
||||
$childNode->nodeType === XML_CDATA_SECTION_NODE) {
|
||||
$result .= trim($childNode->data) . ' ';
|
||||
} else {
|
||||
$result .= self::getNodeText($childNode);
|
||||
}
|
||||
}
|
||||
|
||||
return str_replace(' ', ' ', $result);
|
||||
}
|
||||
|
||||
// @codingStandardsIgnoreEnd
|
||||
}
|
||||
|
||||
@@ -1,193 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,6 @@ require_once(__DIR__.'/classes/basic_testcase.php');
|
||||
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');
|
||||
|
||||
+34
-37
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<xs:annotation>
|
||||
<xs:documentation source="https://phpunit.de/manual/4.7/en/appendixes.configuration.html">
|
||||
This Schema file defines the rules by which the XML configuration file of PHPUnit 4.7 may be structured.
|
||||
<xs:documentation source="https://phpunit.de/manual/5.4/en/appendixes.configuration.html">
|
||||
This Schema file defines the rules by which the XML configuration file of PHPUnit 5.4 may be structured.
|
||||
</xs:documentation>
|
||||
<xs:appinfo source="http://www.phpunit.de/manual/current/en/appendixes.configuration.html"/>
|
||||
</xs:annotation>
|
||||
@@ -14,7 +14,6 @@
|
||||
<xs:complexType name="filtersType">
|
||||
<xs:choice>
|
||||
<xs:sequence>
|
||||
<xs:element name="blacklist" type="filterType"/>
|
||||
<xs:element name="whitelist" type="whiteListType" minOccurs="0"/>
|
||||
</xs:sequence>
|
||||
<xs:sequence>
|
||||
@@ -118,20 +117,23 @@
|
||||
<xs:enumeration value="coverage-text"/>
|
||||
<xs:enumeration value="coverage-clover"/>
|
||||
<xs:enumeration value="coverage-crap4j"/>
|
||||
<xs:enumeration value="coverage-xml"/>
|
||||
<xs:enumeration value="json"/>
|
||||
<xs:enumeration value="plain"/>
|
||||
<xs:enumeration value="tap"/>
|
||||
<xs:enumeration value="teamcity"/>
|
||||
<xs:enumeration value="junit"/>
|
||||
<xs:enumeration value="testdox-html"/>
|
||||
<xs:enumeration value="testdox-text"/>
|
||||
<xs:enumeration value="testdox-xml"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="target" type="xs:anyURI"/>
|
||||
<xs:attribute name="lowUpperBound" type="xs:nonNegativeInteger" default="35"/>
|
||||
<xs:attribute name="highLowerBound" type="xs:nonNegativeInteger" default="70"/>
|
||||
<xs:attribute name="logIncompleteSkipped" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="showUncoveredFiles" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="threshold" type="xs:nonNegativeInteger" default="30"/>
|
||||
</xs:complexType>
|
||||
<xs:group name="pathGroup">
|
||||
<xs:sequence>
|
||||
@@ -160,17 +162,19 @@
|
||||
</xs:attributeGroup>
|
||||
<xs:complexType name="phpType">
|
||||
<xs:sequence>
|
||||
<xs:element name="includePath" type="xs:anyURI" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="ini" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="const" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="var" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="env" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="post" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="get" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="cookie" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="server" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="files" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="request" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:choice maxOccurs="unbounded">
|
||||
<xs:element name="includePath" type="xs:anyURI" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="ini" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="const" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="var" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="env" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="post" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="get" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="cookie" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="server" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="files" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="request" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
|
||||
</xs:choice>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="namedValueType">
|
||||
@@ -195,53 +199,46 @@
|
||||
<xs:attribute name="convertNoticesToExceptions" type="xs:boolean" default="true"/>
|
||||
<xs:attribute name="convertWarningsToExceptions" type="xs:boolean" default="true"/>
|
||||
<xs:attribute name="forceCoversAnnotation" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="mapTestClassNameToCoveredClassName" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="printerClass" type="xs:string" default="PHPUnit_TextUI_ResultPrinter"/>
|
||||
<xs:attribute name="printerFile" type="xs:anyURI"/>
|
||||
<xs:attribute name="processIsolation" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="stopOnError" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="stopOnFailure" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="stopOnWarning" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="stopOnIncomplete" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="stopOnRisky" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="stopOnSkipped" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="beStrictAboutTestsThatDoNotTestAnything" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="beStrictAboutOutputDuringTests" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="beStrictAboutTestSize" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="beStrictAboutTodoAnnotatedTests" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="failOnRisky" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="failOnWarning" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="beStrictAboutChangesToGlobalState" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="beStrictAboutOutputDuringTests" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="beStrictAboutResourceUsageDuringSmallTests" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="beStrictAboutTestsThatDoNotTestAnything" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="beStrictAboutTodoAnnotatedTests" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="beStrictAboutCoversAnnotation" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="checkForUnintentionallyCoveredCode" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="strict" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="testSuiteLoaderClass" type="xs:string" default="PHPUnit_Runner_StandardTestSuiteLoader"/>
|
||||
<xs:attribute name="testSuiteLoaderFile" type="xs:anyURI"/>
|
||||
<xs:attribute name="enforceTimeLimit" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="timeoutForSmallTests" type="xs:integer" default="1"/>
|
||||
<xs:attribute name="timeoutForMediumTests" type="xs:integer" default="10"/>
|
||||
<xs:attribute name="timeoutForLargeTests" type="xs:integer" default="60"/>
|
||||
<xs:attribute name="testSuiteLoaderClass" type="xs:string" default="PHPUnit_Runner_StandardTestSuiteLoader"/>
|
||||
<xs:attribute name="testSuiteLoaderFile" type="xs:anyURI"/>
|
||||
<xs:attribute name="verbose" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="stderr" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="reverseDefectList" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="registerMockObjectsFromTestArgumentsRecursively" type="xs:boolean" default="false"/>
|
||||
</xs:attributeGroup>
|
||||
<xs:group name="configGroup">
|
||||
<xs:all>
|
||||
<xs:element ref="testSuiteFacet" minOccurs="0"/>
|
||||
<xs:element name="groups" type="groupsType" minOccurs="0"/>
|
||||
<xs:element name="testdoxGroups" type="groupsType" minOccurs="0"/>
|
||||
<xs:element name="filter" type="filtersType" minOccurs="0"/>
|
||||
<xs:element name="logging" type="loggersType" minOccurs="0"/>
|
||||
<xs:element name="listeners" type="listenersType" minOccurs="0"/>
|
||||
<xs:element name="php" type="phpType" minOccurs="0"/>
|
||||
<xs:element name="selenium" type="seleniumType" minOccurs="0"/>
|
||||
</xs:all>
|
||||
</xs:group>
|
||||
<xs:complexType name="seleniumType">
|
||||
<xs:sequence>
|
||||
<xs:element name="browser" type="browserType"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="browserType">
|
||||
<xs:attribute name="name" type="xs:string"/>
|
||||
<xs:attribute name="browser" type="xs:string"/>
|
||||
<xs:attribute name="host" type="xs:anyURI"/>
|
||||
<xs:attribute name="port" type="xs:nonNegativeInteger"/>
|
||||
<xs:attribute name="timeout" type="xs:nonNegativeInteger"/>
|
||||
</xs:complexType>
|
||||
<xs:element name="testSuiteFacet" abstract="true"/>
|
||||
<xs:element name="testsuite" type="testSuiteType" substitutionGroup="testSuiteFacet"/>
|
||||
<xs:element name="testsuites" type="testSuitesType" substitutionGroup="testSuiteFacet"/>
|
||||
|
||||
@@ -296,7 +296,7 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
|
||||
} 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.
|
||||
}
|
||||
|
||||
@@ -47,9 +47,13 @@ class core_test_generator_testcase extends advanced_testcase {
|
||||
$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');
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ class core_ajaxlib_testcase extends advanced_testcase {
|
||||
echo $content;
|
||||
|
||||
if ($expectexception) {
|
||||
$this->setExpectedException('coding_exception');
|
||||
$this->expectException('coding_exception');
|
||||
ajax_check_captured_output();
|
||||
} else {
|
||||
$result = ajax_check_captured_output();
|
||||
|
||||
@@ -40,7 +40,7 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
|
||||
$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 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
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 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
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 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
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 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
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 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
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 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
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);
|
||||
|
||||
@@ -258,7 +258,7 @@ class core_externallib_testcase extends advanced_testcase {
|
||||
$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 @@ class core_externallib_testcase extends advanced_testcase {
|
||||
$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 @@ class core_externallib_testcase extends advanced_testcase {
|
||||
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 @@ class core_externallib_testcase extends advanced_testcase {
|
||||
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 @@ class core_externallib_testcase extends advanced_testcase {
|
||||
// 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));
|
||||
}
|
||||
|
||||
|
||||
@@ -536,7 +536,7 @@ class core_grading_externallib_testcase extends externallib_advanced_testcase {
|
||||
$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 @@ class core_grading_externallib_testcase extends externallib_advanced_testcase {
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,32 +83,38 @@ class core_moodle_page_testcase extends advanced_testcase {
|
||||
$this->assertSame($originalcourse, $COURSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_set_course_once_theme_set() {
|
||||
// Setup fixture.
|
||||
$this->testpage->force_theme(theme_config::DEFAULT_THEME);
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
// 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 @@ class core_moodle_page_testcase extends advanced_testcase {
|
||||
$this->assertEquals(moodle_page::STATE_DONE, $this->testpage->state);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_set_state_cannot_skip_one() {
|
||||
// Set expectation.
|
||||
$this->setExpectedException('coding_exception');
|
||||
// Exercise SUT.
|
||||
$this->testpage->set_state(moodle_page::STATE_IN_BODY);
|
||||
}
|
||||
@@ -381,13 +388,14 @@ class core_moodle_page_testcase extends advanced_testcase {
|
||||
$this->assertEquals($cm->id, $this->testpage->cm->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_set_activity_record_before_cm() {
|
||||
// Setup fixture.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
|
||||
$cm = get_coursemodule_from_id('forum', $forum->cmid);
|
||||
// Set expectation.
|
||||
$this->setExpectedException('coding_exception');
|
||||
// Exercise SUT.
|
||||
$this->testpage->set_activity_record($forum);
|
||||
}
|
||||
@@ -428,27 +436,29 @@ class core_moodle_page_testcase extends advanced_testcase {
|
||||
$this->assertEquals($forum, $this->testpage->activityrecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_set_inconsistent_activity_record_course() {
|
||||
// Setup fixture.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$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 @@ class core_moodle_page_testcase extends advanced_testcase {
|
||||
$this->assertEquals($forum, $this->testpage->activityrecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_set_cm_with_inconsistent_course() {
|
||||
// Setup fixture.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$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);
|
||||
|
||||
@@ -36,7 +36,7 @@ class core_outputrequirementslib_testcase extends advanced_testcase {
|
||||
$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 @@ class core_outputrequirementslib_testcase extends advanced_testcase {
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
@@ -181,9 +181,8 @@ class core_setuplib_testcase extends advanced_testcase {
|
||||
$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);
|
||||
|
||||
@@ -55,12 +55,13 @@ class core_update_checker_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* If there are no fetched data yet, the first cron should fetch them.
|
||||
*
|
||||
* @expectedException \core\update\testable_checker_cron_executed
|
||||
*/
|
||||
public function test_cron_initial_fetch() {
|
||||
$provider = testable_checker::instance();
|
||||
$provider->fakerecentfetch = null;
|
||||
$provider->fakecurrenttimestamp = -1;
|
||||
$this->setExpectedException('\core\update\testable_checker_cron_executed');
|
||||
$provider->cron();
|
||||
}
|
||||
|
||||
@@ -77,12 +78,13 @@ class core_update_checker_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* If there is an outdated fetch, the cron execution is expected.
|
||||
*
|
||||
* @expectedException \core\update\testable_checker_cron_executed
|
||||
*/
|
||||
public function test_cron_has_outdated_fetch() {
|
||||
$provider = testable_checker::instance();
|
||||
$provider->fakerecentfetch = time() - 49 * HOURSECS; // Fetched 49 hours ago.
|
||||
$provider->fakecurrenttimestamp = -1;
|
||||
$this->setExpectedException('\core\update\testable_checker_cron_executed');
|
||||
$provider->cron();
|
||||
}
|
||||
|
||||
@@ -257,12 +259,14 @@ class core_update_checker_testcase extends advanced_testcase {
|
||||
$this->assertEquals(2011010102, $cmp['mod_foo'][0]['version']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \core\update\checker_exception
|
||||
*/
|
||||
public function test_compare_responses_invalid_format() {
|
||||
$provider = testable_checker::instance();
|
||||
$broken = array(
|
||||
'status' => 'ERROR' // No 'updates' key here.
|
||||
);
|
||||
$this->setExpectedException('\core\update\checker_exception');
|
||||
$cmp = $provider->compare_responses($broken, $broken);
|
||||
}
|
||||
|
||||
|
||||
@@ -111,12 +111,14 @@ class core_update_code_manager_testcase extends advanced_testcase {
|
||||
$files = $codeman->unzip_plugin_file($zipfilepath, $targetdir, 'bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_unzip_plugin_file_multidir() {
|
||||
$codeman = new \core\update\testable_code_manager();
|
||||
$zipfilepath = __DIR__.'/fixtures/update_validator/zips/multidir.zip';
|
||||
$targetdir = make_request_directory();
|
||||
// Attempting to rename the root folder if there are multiple ones should lead to exception.
|
||||
$this->setExpectedException('moodle_exception');
|
||||
$files = $codeman->unzip_plugin_file($zipfilepath, $targetdir, 'foo');
|
||||
}
|
||||
|
||||
|
||||
+13
-7
@@ -308,10 +308,11 @@ class core_user_testcase extends advanced_testcase {
|
||||
|
||||
// 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 @@ class core_user_testcase extends advanced_testcase {
|
||||
|
||||
// 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 @@ class core_user_testcase extends advanced_testcase {
|
||||
|
||||
// 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 @@ class core_user_testcase extends advanced_testcase {
|
||||
$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');
|
||||
}
|
||||
|
||||
|
||||
@@ -258,10 +258,11 @@ class core_weblib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test set bad scheme on Moodle URL objects.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_moodle_url_set_bad_scheme() {
|
||||
$url = new moodle_url('http://moodle.org/foo/bar');
|
||||
$this->setExpectedException('coding_exception');
|
||||
$url->set_scheme('not a valid $ scheme');
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,10 @@ information provided here is intended especially for developers.
|
||||
- get_records_csv() Please use csv_import_reader::load_csv_content() instead.
|
||||
- put_records_csv() Please use download_as_dataformat (lib/dataformatlib.php) instead.
|
||||
* The password_compat library was removed as it is no longer required.
|
||||
* 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 ===
|
||||
|
||||
|
||||
@@ -339,6 +339,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test search_contacts.
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_search_contacts() {
|
||||
global $DB;
|
||||
@@ -400,7 +401,6 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals($user5->id, $result['id']);
|
||||
|
||||
// Empty query, will throw an exception.
|
||||
$this->setExpectedException('moodle_exception');
|
||||
$results = core_message_external::search_contacts('');
|
||||
}
|
||||
|
||||
|
||||
@@ -517,6 +517,8 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test lock_submissions
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_lock_submissions() {
|
||||
global $DB, $USER;
|
||||
@@ -576,7 +578,6 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
'text'=>'Submission text',
|
||||
'format'=>FORMAT_MOODLE);
|
||||
$notices = array();
|
||||
$this->setExpectedException('moodle_exception');
|
||||
$assign->save_submission($data, $notices);
|
||||
}
|
||||
|
||||
@@ -781,6 +782,8 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test reveal_identities
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_reveal_identities() {
|
||||
global $DB, $USER;
|
||||
@@ -814,7 +817,6 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
$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 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test save grades for a team submission
|
||||
*
|
||||
* @expectedException invalid_parameter_exception
|
||||
*/
|
||||
public function test_save_grades_with_group_submission() {
|
||||
global $DB, $USER, $CFG;
|
||||
@@ -1321,7 +1325,6 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
$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 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test view_grading_table
|
||||
*
|
||||
* @expectedException dml_missing_record_exception
|
||||
*/
|
||||
public function test_view_grading_table_invalid_instance() {
|
||||
global $DB;
|
||||
@@ -1546,12 +1551,13 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
$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 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
$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 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test view_grading_table
|
||||
*
|
||||
* @expectedException require_login_exception
|
||||
* @expectedExceptionMessage Course or activity not accessible. (Activity is hidden)
|
||||
*/
|
||||
public function test_view_grading_table_without_capability() {
|
||||
global $DB;
|
||||
@@ -1638,7 +1646,6 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
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 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test access control for get_submission_status.
|
||||
*
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_get_submission_status_access_control() {
|
||||
$this->resetAfterTest(true);
|
||||
@@ -2038,23 +2047,25 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
$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 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
$this->setUser($student);
|
||||
assign_capability('mod/assign:view', CAP_PROHIBIT, $studentrole->id, $context->id, true);
|
||||
|
||||
$this->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 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
assign_capability('mod/assign:grade', CAP_PROHIBIT, $teacherrole->id, $context->id, true);
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
|
||||
$this->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 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
$this->setUser($teacher);
|
||||
|
||||
$this->setExpectedException('moodle_exception');
|
||||
$result = mod_assign_external::get_participant($assign->id, $student->id, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase {
|
||||
$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 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase {
|
||||
$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 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase {
|
||||
$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 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase {
|
||||
'format'=>FORMAT_MOODLE);
|
||||
|
||||
$notices = array();
|
||||
$this->setExpectedException('moodle_exception');
|
||||
$assign->save_submission($data, $notices);
|
||||
|
||||
$sink->close();
|
||||
|
||||
@@ -126,6 +126,8 @@ class mod_choice_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test custom validations.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_answer_submitted_other_exception() {
|
||||
// Generate user data.
|
||||
@@ -139,7 +141,6 @@ class mod_choice_events_testcase extends advanced_testcase {
|
||||
$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 @@ class mod_choice_events_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 @@ class mod_choice_events_testcase extends advanced_testcase {
|
||||
$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);
|
||||
|
||||
@@ -131,6 +131,9 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_choice_user_submit_response_validation() {
|
||||
global $USER;
|
||||
|
||||
@@ -149,7 +152,6 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase {
|
||||
$optionids2 = array_keys($choicewithoptions2->option);
|
||||
|
||||
// Make sure we cannot submit options from a different choice instance.
|
||||
$this->setExpectedException('moodle_exception');
|
||||
choice_user_submit_response($optionids2[0], $choice1, $USER->id, $course, $cm);
|
||||
}
|
||||
|
||||
|
||||
+167
-64
@@ -54,6 +54,9 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure course_searched event validates that searchterm is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'searchterm' value must be set in other.
|
||||
*/
|
||||
public function test_course_searched_searchterm_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -62,12 +65,14 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure discussion_created event validates that forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_discussion_created_forumid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -129,12 +136,14 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure discussion_updated event validates that forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_discussion_updated_forumid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -206,12 +217,14 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure discussion_deleted event validates that forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_discussion_deleted_forumid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -281,12 +296,14 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure discussion_moved event validates that fromforumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'fromforumid' value must be set in other.
|
||||
*/
|
||||
public function test_discussion_moved_fromforumid_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -359,12 +378,14 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure discussion_viewed event validates that the contextlevel is correct.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_discussion_viewed_context_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -473,7 +498,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'objectid' => $discussion->id,
|
||||
);
|
||||
|
||||
$this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\discussion_viewed::create($params);
|
||||
}
|
||||
|
||||
@@ -522,6 +546,9 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure course_module_viewed event validates that the contextlevel is correct.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_course_module_viewed_context_validation() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@@ -532,7 +559,6 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure subscription_created event validates that the forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_subscription_created_forumid_validation() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
@@ -585,12 +614,14 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
|
||||
$this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\subscription_created::create($params);
|
||||
}
|
||||
|
||||
@@ -671,6 +703,9 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure subscription_deleted event validates that the forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_subscription_deleted_forumid_validation() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
@@ -682,12 +717,14 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
|
||||
$this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\subscription_deleted::create($params);
|
||||
}
|
||||
|
||||
@@ -768,6 +806,9 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure readtracking_enabled event validates that the forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_readtracking_enabled_forumid_validation() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
@@ -779,12 +820,14 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
|
||||
$this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\readtracking_enabled::create($params);
|
||||
}
|
||||
|
||||
@@ -856,6 +900,9 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure readtracking_disabled event validates that the forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_readtracking_disabled_forumid_validation() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
@@ -867,12 +914,14 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
|
||||
$this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\readtracking_disabled::create($params);
|
||||
}
|
||||
|
||||
@@ -944,6 +994,9 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Ensure subscribers_viewed event validates that the forumid is set.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage The 'forumid' value must be set in other.
|
||||
*/
|
||||
public function test_subscribers_viewed_forumid_validation() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
@@ -955,12 +1008,14 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'relateduserid' => $user->id,
|
||||
);
|
||||
|
||||
$this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
|
||||
\mod_forum\event\subscribers_viewed::create($params);
|
||||
}
|
||||
|
||||
@@ -1011,7 +1065,10 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
'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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test contextlevel validation of discussion_subscription_created event.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
* @expectedExceptionMessage Context level must be CONTEXT_MODULE.
|
||||
*/
|
||||
public function test_discussion_subscription_created_validation_contextlevel() {
|
||||
global $CFG, $DB;
|
||||
@@ -2016,12 +2102,14 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
);
|
||||
|
||||
// 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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
)
|
||||
);
|
||||
|
||||
$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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
)
|
||||
);
|
||||
|
||||
$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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->setExpectedException('coding_exception', "The 'relateduserid' must be set.");
|
||||
\mod_forum\event\discussion_subscription_created::create($params);
|
||||
}
|
||||
|
||||
@@ -2291,27 +2382,34 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
|
||||
// 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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
);
|
||||
|
||||
// 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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
)
|
||||
);
|
||||
|
||||
$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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
)
|
||||
);
|
||||
|
||||
$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 @@ class mod_forum_events_testcase extends advanced_testcase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->setExpectedException('coding_exception', "The 'relateduserid' must be set.");
|
||||
\mod_forum\event\discussion_subscription_deleted::create($params);
|
||||
}
|
||||
|
||||
|
||||
@@ -1422,7 +1422,7 @@ class mod_forum_lib_testcase extends advanced_testcase {
|
||||
$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 @@ class mod_forum_lib_testcase extends advanced_testcase {
|
||||
$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 @@ class mod_forum_lib_testcase extends advanced_testcase {
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ class mod_forum_maildigest_testcase extends advanced_testcase {
|
||||
$this->assertFalse($currentsetting);
|
||||
|
||||
// Try with an invalid value.
|
||||
$this->setExpectedException('moodle_exception');
|
||||
$this->expectException('moodle_exception');
|
||||
forum_set_user_maildigest($forum1, 42, $user);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,10 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
$sink->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException require_login_exception
|
||||
* @expectedExceptionMessage Activity is hidden
|
||||
*/
|
||||
public function test_view_glossary_without_permission() {
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
@@ -126,10 +130,13 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
}
|
||||
|
||||
// Test non-readable entry.
|
||||
$this->setExpectedException('require_login_exception', 'Activity is hidden');
|
||||
mod_glossary_external::view_entry($e4->id);
|
||||
}
|
||||
|
||||
@@ -1034,7 +1040,7 @@ class mod_glossary_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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.');
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ class mod_lti_external_testcase extends externallib_advanced_testcase {
|
||||
* 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 @@ class mod_lti_external_testcase extends externallib_advanced_testcase {
|
||||
*/
|
||||
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 @@ class mod_lti_external_testcase extends externallib_advanced_testcase {
|
||||
* 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 @@ class mod_lti_external_testcase extends externallib_advanced_testcase {
|
||||
* 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 @@ class mod_lti_external_testcase extends externallib_advanced_testcase {
|
||||
*/
|
||||
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 @@ class mod_lti_external_testcase extends externallib_advanced_testcase {
|
||||
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']);
|
||||
}
|
||||
|
||||
@@ -259,6 +259,9 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
), $structure);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_cannot_remove_first_section() {
|
||||
$quizobj = $this->create_test_quiz(array(
|
||||
'Heading 1',
|
||||
@@ -269,7 +272,6 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
$sections = $structure->get_sections();
|
||||
$section = reset($sections);
|
||||
|
||||
$this->setExpectedException('coding_exception');
|
||||
$structure->remove_section_heading($section->id);
|
||||
}
|
||||
|
||||
@@ -416,6 +418,9 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
), $structure);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_move_slot_too_small_page_number_detected() {
|
||||
$quizobj = $this->create_test_quiz(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
@@ -426,10 +431,12 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(3)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(2)->slotid;
|
||||
$this->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 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(1)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(2)->slotid;
|
||||
$this->setExpectedException('coding_exception');
|
||||
$structure->move_slot($idtomove, $idmoveafter, '4');
|
||||
}
|
||||
|
||||
@@ -668,6 +674,9 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
$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 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
|
||||
$this->setExpectedException('coding_exception');
|
||||
$structure->remove_slot(3);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,11 @@ class mod_scorm_event_testcase extends advanced_testcase {
|
||||
$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 @@ class mod_scorm_event_testcase extends advanced_testcase {
|
||||
$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 @@ class mod_scorm_event_testcase extends advanced_testcase {
|
||||
/** Tests for sco launched event.
|
||||
*
|
||||
* There is no api involved so the best we can do is test legacy data and validations by triggering event manually.
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_sco_launched_event() {
|
||||
$this->resetAfterTest();
|
||||
@@ -251,7 +256,6 @@ class mod_scorm_event_testcase extends advanced_testcase {
|
||||
$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),
|
||||
|
||||
@@ -172,6 +172,9 @@ class mod_scorm_external_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals(1, $result['attemptscount']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException required_capability_exception
|
||||
*/
|
||||
public function test_mod_scorm_get_scorm_attempt_count_others_as_student() {
|
||||
// Create a second student.
|
||||
$student2 = self::getDataGenerator()->create_user();
|
||||
@@ -181,24 +184,27 @@ class mod_scorm_external_testcase extends externallib_advanced_testcase {
|
||||
self::setUser($student2);
|
||||
|
||||
// I should not be able to view the attempts of another student.
|
||||
$this->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);
|
||||
}
|
||||
|
||||
|
||||
@@ -170,14 +170,16 @@ class mod_scorm_lib_testcase extends externallib_advanced_testcase {
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -448,26 +448,30 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test get_subwiki_pages using an invalid wiki instance.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_subwiki_pages_invalid_instance() {
|
||||
$this->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 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
|
||||
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 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
|
||||
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 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
|
||||
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 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test get_page_contents using an invalid pageid.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_page_contents_invalid_pageid() {
|
||||
$this->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 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
|
||||
$hiddenpage = $this->getDataGenerator()->get_plugin_generator('mod_wiki')->create_page($hiddenwiki);
|
||||
|
||||
$this->setUser($this->student);
|
||||
$this->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 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
|
||||
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 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
|
||||
/**
|
||||
* Test get_subwiki_files, check that a student can't get files from another group's subwiki when
|
||||
* using separate groups.
|
||||
*
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_subwiki_files_separate_groups_student_see_other_group() {
|
||||
// Create testing data.
|
||||
$this->create_collaborative_wikis_with_groups();
|
||||
|
||||
$this->setUser($this->student);
|
||||
$this->setExpectedException('moodle_exception');
|
||||
mod_wiki_external::get_subwiki_files($this->wikisep->id, $this->group2->id);
|
||||
}
|
||||
|
||||
|
||||
@@ -114,14 +114,15 @@ class workshopallocation_random_testcase extends advanced_testcase {
|
||||
), $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);
|
||||
}
|
||||
|
||||
@@ -78,11 +78,13 @@ class workshop_accumulative_strategy_testcase extends advanced_testcase {
|
||||
$this->assertEquals(grade_floatval(5/20 * 100), $suggested);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_calculate_peer_grade_negative_weight() {
|
||||
// fixture set-up
|
||||
$this->strategy->dimensions[1003] = (object)array('grade' => '20', 'weight' => '-1');
|
||||
$grades[] = (object)array('dimensionid' => 1003, 'grade' => '20');
|
||||
$this->setExpectedException('coding_exception');
|
||||
// exercise SUT
|
||||
$suggested = $this->strategy->calculate_peer_grade($grades);
|
||||
}
|
||||
@@ -176,6 +178,9 @@ class workshop_accumulative_strategy_testcase extends advanced_testcase {
|
||||
$this->assertEquals(grade_floatval((1/2*2 + 4/6*3)/5 * 100), $suggested);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_calculate_peer_grade_scale_exception() {
|
||||
$this->resetAfterTest(true);
|
||||
// fixture set-up
|
||||
@@ -183,8 +188,7 @@ class workshop_accumulative_strategy_testcase extends advanced_testcase {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,24 +317,28 @@ class mod_workshop_internal_api_testcase extends advanced_testcase {
|
||||
$this->assertEquals($part, $total * $percent / 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_percent_to_value_negative() {
|
||||
$this->resetAfterTest(true);
|
||||
// fixture setup
|
||||
$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 @@ class mod_workshop_internal_api_testcase extends advanced_testcase {
|
||||
|
||||
// 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 @@ class mod_workshop_internal_api_testcase extends advanced_testcase {
|
||||
|
||||
// modify setup
|
||||
$fakerawrecord->weight = 0;
|
||||
$this->setExpectedException('coding_exception');
|
||||
$this->expectException('coding_exception');
|
||||
// excersise SUT
|
||||
$a = $this->workshop->prepare_example_reference_assessment($fakerawrecord);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class core_notes_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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 @@ class core_notes_externallib_testcase extends externallib_advanced_testcase {
|
||||
$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 @@ class core_notes_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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 @@ class core_notes_externallib_testcase extends externallib_advanced_testcase {
|
||||
$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';
|
||||
|
||||
@@ -88,7 +88,7 @@ class qbehaviour_informationitem_walkthrough_testcase extends qbehaviour_walkthr
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -533,7 +533,7 @@ class qbehaviour_manualgraded_walkthrough_testcase extends qbehaviour_walkthroug
|
||||
$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 @@ class qbehaviour_manualgraded_walkthrough_testcase extends qbehaviour_walkthroug
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,31 +39,40 @@ require_once(__DIR__ . '/../behaviour.php');
|
||||
* @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();
|
||||
}
|
||||
|
||||
|
||||
@@ -57,8 +57,10 @@ class question_attempt_with_steps_test extends advanced_testcase {
|
||||
$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 @@ class question_attempt_with_steps_test extends advanced_testcase {
|
||||
$this->assertEquals(2, $step->get_qt_var('i'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_get_step_past_end() {
|
||||
$this->setExpectedException('moodle_exception');
|
||||
$step = $this->qa->get_step(3);
|
||||
}
|
||||
|
||||
@@ -151,7 +155,7 @@ class question_attempt_with_steps_test extends advanced_testcase {
|
||||
|
||||
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 @@ class question_attempt_with_steps_test extends advanced_testcase {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -87,8 +87,10 @@ class question_attempt_iterator_test extends advanced_testcase {
|
||||
$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 @@ class question_attempt_iterator_test extends advanced_testcase {
|
||||
$this->assertSame($this->qas[2], $this->iterator[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_offsetGet_past_end() {
|
||||
$this->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]);
|
||||
}
|
||||
}
|
||||
@@ -85,13 +85,13 @@ class question_attempt_step_test extends advanced_testcase {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -104,8 +104,10 @@ class question_attempt_step_iterator_test extends advanced_testcase {
|
||||
$this->assertFalse(isset($this->iterator[3]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_offsetGet_before_start() {
|
||||
$this->setExpectedException('moodle_exception');
|
||||
$step = $this->iterator[-1];
|
||||
}
|
||||
|
||||
@@ -119,18 +121,24 @@ class question_attempt_step_iterator_test extends advanced_testcase {
|
||||
$this->assertEquals(2, $step->get_qt_var('i'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_offsetGet_past_end() {
|
||||
$this->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]);
|
||||
}
|
||||
}
|
||||
@@ -45,9 +45,10 @@ class question_engine_test extends advanced_testcase {
|
||||
$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');
|
||||
}
|
||||
|
||||
@@ -566,7 +566,7 @@ class question_usage_autosave_test extends qbehaviour_walkthrough_test_base {
|
||||
$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();
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ class question_usage_by_activity_test extends advanced_testcase {
|
||||
// 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 @@ class question_usage_by_activity_test extends advanced_testcase {
|
||||
);
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,18 +177,24 @@ class question_utils_test extends advanced_testcase {
|
||||
$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);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,30 +48,38 @@ class qtype_calculated_variable_substituter_test extends advanced_testcase {
|
||||
$this->assertEquals(1, $vs->calculate('{a}-{b}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
public function test_cannot_use_nonnumbers() {
|
||||
$this->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}');
|
||||
}
|
||||
|
||||
@@ -66,14 +66,18 @@ class qtype_missing_test extends question_testcase {
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ class core_repository_generator_testcase extends advanced_testcase {
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -523,7 +523,7 @@ class core_user_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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 @@ class core_user_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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 @@ class core_user_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,9 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
$this->assertSame('class1 class2', $category->classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_validate_after_order1() {
|
||||
$category = new \phpunit_fixture_myprofile_category('category', 'title', null);
|
||||
|
||||
@@ -100,11 +103,13 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
$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 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
$category->add_node($node2);
|
||||
$category->add_node($node1);
|
||||
|
||||
$this->setExpectedException('coding_exception');
|
||||
$category->validate_after_order();
|
||||
|
||||
}
|
||||
@@ -167,6 +171,8 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test category::sort_nodes().
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_sort_nodes1() {
|
||||
$category = new \phpunit_fixture_myprofile_category('category', 'title', null);
|
||||
@@ -213,7 +219,6 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
// Add a node with invalid 'after' and make sure an exception is thrown.
|
||||
$node7 = new \core_user\output\myprofile\node('category', 'node7', 'nodetitle', 'noderandom');
|
||||
$category->add_node($node7);
|
||||
$this->setExpectedException('coding_exception');
|
||||
$category->sort_nodes();
|
||||
}
|
||||
|
||||
@@ -259,6 +264,8 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test tree::add_node().
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_tree_add_node() {
|
||||
$tree = new \phpunit_fixture_myprofile_tree();
|
||||
@@ -269,12 +276,13 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
$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 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
$this->assertEquals($category1, $category);
|
||||
|
||||
// Can't add node with same name.
|
||||
$this->setExpectedException('coding_exception');
|
||||
$tree->add_category($category1);
|
||||
}
|
||||
|
||||
@@ -334,6 +341,8 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test tree::sort_categories().
|
||||
*
|
||||
* @expectedException coding_exception
|
||||
*/
|
||||
public function test_sort_categories() {
|
||||
$tree = new \phpunit_fixture_myprofile_tree('category', 'title', null);
|
||||
@@ -372,7 +381,6 @@ class core_user_myprofile_testcase extends advanced_testcase {
|
||||
$this->assertEquals($category6, $category);
|
||||
|
||||
// Can't add category with same name.
|
||||
$this->setExpectedException('coding_exception');
|
||||
$tree->add_category($category1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class webservice_xmlrpc_test extends advanced_testcase {
|
||||
$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');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user