/** * Test that we can restore recycle bin items. */ public function test_restore() { global $DB; $startcount = $DB->count_records('course_modules'); // Delete the course module. course_delete_module($this->quiz->cmid); // Try restoring. $recyclebin = new \tool_recyclebin\course_bin($this->course->id); foreach ($recyclebin->get_items() as $item) { $recyclebin->restore_item($item); } // Check that it was restored and removed from the recycle bin. $this->assertEquals($startcount, $DB->count_records('course_modules')); $this->assertEquals(0, count($recyclebin->get_items())); }
/** * Test the course bin item restored event. */ public function test_course_bin_item_restored() { // Create a course. $course = $this->getDataGenerator()->create_course(); // Create the assignment. $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign'); $instance = $generator->create_instance(array('course' => $course->id)); course_delete_module($instance->cmid); // Get the item from the recycle bin. $rb = new \tool_recyclebin\course_bin($course->id); $items = $rb->get_items(); $item = reset($items); // Trigger and capture the event. $sink = $this->redirectEvents(); $rb->restore_item($item); $events = $sink->get_events(); $event = reset($events); // Check that the event contains the expected values. $this->assertInstanceOf('\\tooL_recyclebin\\event\\course_bin_item_restored', $event); $this->assertEquals(context_course::instance($course->id), $event->get_context()); $this->assertEquals($item->id, $event->objectid); $this->assertEventContextNotUsed($event); }