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 /** 18 * Events tests. 19 * 20 * @package assignsubmission_comments 21 * @category test 22 * @copyright 2013 Rajesh Taneja <rajesh@moodle.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 global $CFG; 29 require_once($CFG->dirroot . '/mod/assign/lib.php'); 30 require_once($CFG->dirroot . '/mod/assign/locallib.php'); 31 require_once($CFG->dirroot . '/mod/assign/tests/generator.php'); 32 require_once($CFG->dirroot . '/comment/lib.php'); 33 34 /** 35 * Events tests class. 36 * 37 * @package assignsubmission_comments 38 * @category test 39 * @copyright 2013 Rajesh Taneja <rajesh@moodle.com> 40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 41 */ 42 class assignsubmission_comments_events_testcase extends advanced_testcase { 43 44 // Use the generator helper. 45 use mod_assign_test_generator; 46 47 /** 48 * Test comment_created event. 49 */ 50 public function test_comment_created() { 51 $this->resetAfterTest(); 52 $course = $this->getDataGenerator()->create_course(); 53 $teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher'); 54 $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); 55 56 $assign = $this->create_instance($course); 57 58 $this->setUser($teacher); 59 $submission = $assign->get_user_submission($student->id, true); 60 61 $context = $assign->get_context(); 62 $options = new stdClass(); 63 $options->area = 'submission_comments'; 64 $options->course = $assign->get_course(); 65 $options->context = $context; 66 $options->itemid = $submission->id; 67 $options->component = 'assignsubmission_comments'; 68 $options->showcount = true; 69 $options->displaycancel = true; 70 71 $comment = new comment($options); 72 73 // Triggering and capturing the event. 74 $sink = $this->redirectEvents(); 75 $comment->add('New comment'); 76 $events = $sink->get_events(); 77 $this->assertCount(1, $events); 78 $event = reset($events); 79 $sink->close(); 80 81 // Checking that the event contains the expected values. 82 $this->assertInstanceOf('\assignsubmission_comments\event\comment_created', $event); 83 $this->assertEquals($context, $event->get_context()); 84 $url = new moodle_url('/mod/assign/view.php', array('id' => $assign->get_course_module()->id)); 85 $this->assertEquals($url, $event->get_url()); 86 $this->assertEventContextNotUsed($event); 87 } 88 89 /** 90 * Test comment_deleted event. 91 */ 92 public function test_comment_deleted() { 93 $this->resetAfterTest(); 94 $course = $this->getDataGenerator()->create_course(); 95 $teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher'); 96 $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); 97 98 $assign = $this->create_instance($course); 99 100 $this->setUser($teacher); 101 $submission = $assign->get_user_submission($student->id, true); 102 103 $context = $assign->get_context(); 104 $options = new stdClass(); 105 $options->area = 'submission_comments'; 106 $options->course = $assign->get_course(); 107 $options->context = $context; 108 $options->itemid = $submission->id; 109 $options->component = 'assignsubmission_comments'; 110 $options->showcount = true; 111 $options->displaycancel = true; 112 $comment = new comment($options); 113 $newcomment = $comment->add('New comment 1'); 114 115 // Triggering and capturing the event. 116 $sink = $this->redirectEvents(); 117 $comment->delete($newcomment->id); 118 $events = $sink->get_events(); 119 $this->assertCount(1, $events); 120 $event = reset($events); 121 122 // Checking that the event contains the expected values. 123 $this->assertInstanceOf('\assignsubmission_comments\event\comment_deleted', $event); 124 $this->assertEquals($context, $event->get_context()); 125 $url = new moodle_url('/mod/assign/view.php', array('id' => $assign->get_course_module()->id)); 126 $this->assertEquals($url, $event->get_url()); 127 $this->assertEventContextNotUsed($event); 128 } 129 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body