case 'resortcategories': $sort = required_param('resort', PARAM_ALPHA); $cattosort = coursecat::get((int) optional_param('categoryid', 0, PARAM_INT)); $redirectback = \core_course\management\helper::action_category_resort_subcategories($cattosort, $sort); break; case 'resortcourses': // They must have specified a category. required_param('categoryid', PARAM_INT); $sort = required_param('resort', PARAM_ALPHA); \core_course\management\helper::action_category_resort_courses($category, $sort); break; case 'showcourse': $redirectback = \core_course\management\helper::action_course_show($course); break; case 'hidecourse': $redirectback = \core_course\management\helper::action_course_hide($course); break; case 'movecourseup': // They must have specified a category and a course. required_param('categoryid', PARAM_INT); required_param('courseid', PARAM_INT); $redirectback = \core_course\management\helper::action_course_change_sortorder_up_one($course, $category); break; case 'movecoursedown': // They must have specified a category and a course. required_param('categoryid', PARAM_INT); required_param('courseid', PARAM_INT); $redirectback = \core_course\management\helper::action_course_change_sortorder_down_one($course, $category); break; case 'showcategory': // They must have specified a category.
/** * Test hiding and showing of a course. * * @see \core_course\management\helper::action_course_hide * @see \core_course\management\helper::action_course_show */ public function test_action_course_hide_show() { $this->resetAfterTest(true); $generator = $this->getDataGenerator(); $category = $generator->create_category(); $course = $generator->create_course(); $coursecontext = context_course::instance($course->id); list($user, $roleid) = $this->get_user_objects($generator, $coursecontext->id); $caps = array(self::COURSE_VIEW, self::COURSE_VIEWHIDDEN); $assignment = course_capability_assignment::allow($caps, $roleid, $coursecontext->id); $course = new course_in_list(get_course($course->id)); // Check it is set to what we think it is. $this->assertEquals('1', $course->visible); $this->assertEquals('1', $course->visibleold); // Test hiding the course. $this->assertTrue(\core_course\management\helper::action_course_hide($course)); // Refresh the course. $course = new course_in_list(get_course($course->id)); $this->assertEquals('0', $course->visible); $this->assertEquals('0', $course->visibleold); // Test hiding the course again. $this->assertTrue(\core_course\management\helper::action_course_hide($course)); // Refresh the course. $course = new course_in_list(get_course($course->id)); $this->assertEquals('0', $course->visible); $this->assertEquals('0', $course->visibleold); // Test showing the course. $this->assertTrue(\core_course\management\helper::action_course_show($course)); // Refresh the course. $course = new course_in_list(get_course($course->id)); $this->assertEquals('1', $course->visible); $this->assertEquals('1', $course->visibleold); // Test showing the course again. Shouldn't change anything. $this->assertTrue(\core_course\management\helper::action_course_show($course)); // Refresh the course. $course = new course_in_list(get_course($course->id)); $this->assertEquals('1', $course->visible); $this->assertEquals('1', $course->visibleold); // Revoke the permissions. $assignment->revoke(); $course = new course_in_list(get_course($course->id)); try { \core_course\management\helper::action_course_show($course); } catch (moodle_exception $exception) { $this->assertEquals('course_in_list::can_change_visbility', $exception->debuginfo); } }