Differences Between: [Versions 310 and 311] [Versions 39 and 311]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 namespace block_recentlyaccesseditems; 18 19 /** 20 * Block Recently accessed helper class tests. 21 * 22 * @package block_recentlyaccesseditems 23 * @copyright 2019 University of Nottingham 24 * @author Neill Magill <neill.magill@nottingham.ac.uk> 25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 26 */ 27 class helper_test extends \advanced_testcase { 28 /** 29 * Tests that the get recent items method can handle getting records when courses have been deleted. 30 */ 31 public function test_get_recent_items() { 32 $this->resetAfterTest(); 33 $course = self::getDataGenerator()->create_course(); 34 $coursetodelete = self::getDataGenerator()->create_course(); 35 $user = self::getDataGenerator()->create_and_enrol($course, 'student'); 36 self::getDataGenerator()->enrol_user($user->id, $coursetodelete->id, 'student'); 37 38 // Add an activity to each course. 39 $forum = self::getDataGenerator()->create_module('forum', ['course' => $course]); 40 $glossary = self::getDataGenerator()->create_module('glossary', ['course' => $coursetodelete]); 41 self::setUser($user); 42 43 // Get the user to visit the activities. 44 $event1params = ['context' => \context_module::instance($forum->cmid), 'objectid' => $forum->id]; 45 $event1 = \mod_forum\event\course_module_viewed::create($event1params); 46 $event1->trigger(); 47 $event2params = ['context' => \context_module::instance($glossary->cmid), 'objectid' => $glossary->id]; 48 $event2 = \mod_glossary\event\course_module_viewed::create($event2params); 49 $event2->trigger(); 50 $recent1 = helper::get_recent_items(); 51 self::assertCount(2, $recent1); 52 $recentlimited = helper::get_recent_items(1); 53 self::assertCount(1, $recentlimited); 54 delete_course($coursetodelete, false); 55 56 // There should be no errors if a course has been deleted. 57 $recent2 = helper::get_recent_items(); 58 self::assertCount(1, $recent2); 59 } 60 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body