mirror of
https://github.com/moodle/moodle.git
synced 2025-01-31 12:45:04 +01:00
MDL-45131 course: Add validation for returned parameters in WS tests
This commit is contained in:
parent
52ab107698
commit
bdf9f4d41c
@ -243,6 +243,8 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
// Retrieve categories from parent.
|
||||
$categories = core_course_external::get_categories(array(
|
||||
array('key' => 'parent', 'value' => $category3->id)), 1);
|
||||
$categories = external_api::clean_returnvalue(core_course_external::get_categories_returns(), $categories);
|
||||
|
||||
$this->assertEquals(2, count($categories));
|
||||
|
||||
// Retrieve all categories.
|
||||
@ -937,6 +939,8 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
$courses = array($course1, $course2);
|
||||
|
||||
$updatedcoursewarnings = core_course_external::update_courses($courses);
|
||||
$updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(),
|
||||
$updatedcoursewarnings);
|
||||
$COURSE = $origcourse; // Restore $COURSE. Instead of using the OLD one set by the previous line.
|
||||
|
||||
// Check that right number of courses were created.
|
||||
@ -994,6 +998,8 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
$this->unassignUserCapability('moodle/course:update', $contextid, $roleid);
|
||||
self::getDataGenerator()->enrol_user($user->id, $course1['id'], $roleid);
|
||||
$updatedcoursewarnings = core_course_external::update_courses($courses);
|
||||
$updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(),
|
||||
$updatedcoursewarnings);
|
||||
$this->assertEquals(1, count($updatedcoursewarnings['warnings']));
|
||||
|
||||
// Try update course category without capability.
|
||||
@ -1005,6 +1011,8 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
$course1['categoryid'] = $category2->id;
|
||||
$courses = array($course1);
|
||||
$updatedcoursewarnings = core_course_external::update_courses($courses);
|
||||
$updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(),
|
||||
$updatedcoursewarnings);
|
||||
$this->assertEquals(1, count($updatedcoursewarnings['warnings']));
|
||||
|
||||
// Try update course fullname without capability.
|
||||
@ -1014,10 +1022,14 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
$this->setUser($user);
|
||||
self::getDataGenerator()->enrol_user($user->id, $course1['id'], $roleid);
|
||||
$updatedcoursewarnings = core_course_external::update_courses($courses);
|
||||
$updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(),
|
||||
$updatedcoursewarnings);
|
||||
$this->assertEquals(0, count($updatedcoursewarnings['warnings']));
|
||||
$course1['fullname'] = 'Testing fullname without permission';
|
||||
$courses = array($course1);
|
||||
$updatedcoursewarnings = core_course_external::update_courses($courses);
|
||||
$updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(),
|
||||
$updatedcoursewarnings);
|
||||
$this->assertEquals(1, count($updatedcoursewarnings['warnings']));
|
||||
|
||||
// Try update course shortname without capability.
|
||||
@ -1027,10 +1039,14 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
$this->setUser($user);
|
||||
self::getDataGenerator()->enrol_user($user->id, $course1['id'], $roleid);
|
||||
$updatedcoursewarnings = core_course_external::update_courses($courses);
|
||||
$updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(),
|
||||
$updatedcoursewarnings);
|
||||
$this->assertEquals(0, count($updatedcoursewarnings['warnings']));
|
||||
$course1['shortname'] = 'Testing shortname without permission';
|
||||
$courses = array($course1);
|
||||
$updatedcoursewarnings = core_course_external::update_courses($courses);
|
||||
$updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(),
|
||||
$updatedcoursewarnings);
|
||||
$this->assertEquals(1, count($updatedcoursewarnings['warnings']));
|
||||
|
||||
// Try update course idnumber without capability.
|
||||
@ -1040,10 +1056,14 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
$this->setUser($user);
|
||||
self::getDataGenerator()->enrol_user($user->id, $course1['id'], $roleid);
|
||||
$updatedcoursewarnings = core_course_external::update_courses($courses);
|
||||
$updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(),
|
||||
$updatedcoursewarnings);
|
||||
$this->assertEquals(0, count($updatedcoursewarnings['warnings']));
|
||||
$course1['idnumber'] = 'NEWIDNUMBER';
|
||||
$courses = array($course1);
|
||||
$updatedcoursewarnings = core_course_external::update_courses($courses);
|
||||
$updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(),
|
||||
$updatedcoursewarnings);
|
||||
$this->assertEquals(1, count($updatedcoursewarnings['warnings']));
|
||||
|
||||
// Try update course summary without capability.
|
||||
@ -1053,10 +1073,14 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
$this->setUser($user);
|
||||
self::getDataGenerator()->enrol_user($user->id, $course1['id'], $roleid);
|
||||
$updatedcoursewarnings = core_course_external::update_courses($courses);
|
||||
$updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(),
|
||||
$updatedcoursewarnings);
|
||||
$this->assertEquals(0, count($updatedcoursewarnings['warnings']));
|
||||
$course1['summary'] = 'New summary';
|
||||
$courses = array($course1);
|
||||
$updatedcoursewarnings = core_course_external::update_courses($courses);
|
||||
$updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(),
|
||||
$updatedcoursewarnings);
|
||||
$this->assertEquals(1, count($updatedcoursewarnings['warnings']));
|
||||
|
||||
// Try update course with invalid summary format.
|
||||
@ -1065,10 +1089,14 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
$this->setUser($user);
|
||||
self::getDataGenerator()->enrol_user($user->id, $course1['id'], $roleid);
|
||||
$updatedcoursewarnings = core_course_external::update_courses($courses);
|
||||
$updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(),
|
||||
$updatedcoursewarnings);
|
||||
$this->assertEquals(0, count($updatedcoursewarnings['warnings']));
|
||||
$course1['summaryformat'] = 10;
|
||||
$courses = array($course1);
|
||||
$updatedcoursewarnings = core_course_external::update_courses($courses);
|
||||
$updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(),
|
||||
$updatedcoursewarnings);
|
||||
$this->assertEquals(1, count($updatedcoursewarnings['warnings']));
|
||||
|
||||
// Try update course visibility without capability.
|
||||
@ -1079,10 +1107,14 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
$course1['summaryformat'] = FORMAT_MOODLE;
|
||||
$courses = array($course1);
|
||||
$updatedcoursewarnings = core_course_external::update_courses($courses);
|
||||
$updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(),
|
||||
$updatedcoursewarnings);
|
||||
$this->assertEquals(0, count($updatedcoursewarnings['warnings']));
|
||||
$course1['visible'] = 0;
|
||||
$courses = array($course1);
|
||||
$updatedcoursewarnings = core_course_external::update_courses($courses);
|
||||
$updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(),
|
||||
$updatedcoursewarnings);
|
||||
$this->assertEquals(1, count($updatedcoursewarnings['warnings']));
|
||||
}
|
||||
|
||||
@ -1401,7 +1433,8 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
// Redirect events to the sink, so we can recover them later.
|
||||
$sink = $this->redirectEvents();
|
||||
|
||||
core_course_external::view_course($course->id, 1);
|
||||
$result = core_course_external::view_course($course->id, 1);
|
||||
$result = external_api::clean_returnvalue(core_course_external::view_course_returns(), $result);
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
|
||||
@ -1410,7 +1443,8 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals(context_course::instance($course->id), $event->get_context());
|
||||
$this->assertEquals(1, $event->other['coursesectionnumber']);
|
||||
|
||||
core_course_external::view_course($course->id);
|
||||
$result = core_course_external::view_course($course->id);
|
||||
$result = external_api::clean_returnvalue(core_course_external::view_course_returns(), $result);
|
||||
$events = $sink->get_events();
|
||||
$event = array_pop($events);
|
||||
$sink->close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user