. /** * Tests for the progress report sorting. * * @package report_progress * @copyright 2021 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. */ defined('MOODLE_INTERNAL') || die(); /** * Class for testing report progress helper. * * @copyright 2021 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. */ class report_progress_helper_testcase extends advanced_testcase { /** * Set up testcase. */ public function setUp(): void { global $CFG; $CFG->enablecompletion = true; $this->setAdminUser(); $this->resetAfterTest(); $this->generator = $this->getDataGenerator(); } /** * Test process_activities_by_filter_options function. */ public function test_sort_activities() { $expectedactivitytypes = ['all' => 'All activities and resources', 'assign' => 'Assignments', 'quiz' => 'Quizzes']; // Generate test data. $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); $quiz2 = $this->generator->create_module('quiz', ['course' => $course->id, 'name' => 'Quiz 2'], ['completion' => 1]); $quiz1 = $this->generator->create_module('quiz', ['course' => $course->id, 'name' => 'Quiz 1'], ['completion' => 1]); $assign1 = $this->generator->create_module('assign', ['course' => $course->id, 'name' => 'Assignment'], ['completion' => 1]); $completion = new completion_info($course); // Sort the activities by name. list($activitytypes, $activities) = \report_progress\local\helper::get_activities_to_show($completion, 'quiz', 'alphabetical'); // Check weather the result is filtered and sorted. $this->assertEquals(2, count($activities)); $this->assertEquals('Quiz 1', $activities[0]->name); $this->assertEquals('Quiz 2', $activities[1]->name); $this->assertEquals($activitytypes, $expectedactivitytypes); } }