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 * Unit tests for assignfeedback_comments 19 * 20 * @package assignfeedback_comments 21 * @copyright 2016 Adrian Greeve <adrian@moodle.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 global $CFG; 28 require_once($CFG->dirroot . '/mod/assign/tests/generator.php'); 29 30 /** 31 * Unit tests for assignfeedback_comments 32 * 33 * @copyright 2016 Adrian Greeve <adrian@moodle.com> 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class assignfeedback_comments_testcase extends advanced_testcase { 37 38 // Use the generator helper. 39 use mod_assign_test_generator; 40 41 /** 42 * Test the is_feedback_modified() method for the comments feedback. 43 */ 44 public function test_is_feedback_modified() { 45 $this->resetAfterTest(); 46 $course = $this->getDataGenerator()->create_course(); 47 $teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher'); 48 $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); 49 50 $assign = $this->create_instance($course, [ 51 'assignsubmission_onlinetext_enabled' => 1, 52 'assignfeedback_comments_enabled' => 1, 53 ]); 54 55 // Create an online text submission. 56 $this->add_submission($student, $assign); 57 58 $this->setUser($teacher); 59 60 // Create formdata. 61 $grade = $assign->get_user_grade($student->id, true); 62 $data = (object) [ 63 'assignfeedbackcomments_editor' => [ 64 'text' => '<p>first comment for this test</p>', 65 'format' => 1, 66 ] 67 ]; 68 69 // This is the first time that we are submitting feedback, so it is modified. 70 $plugin = $assign->get_feedback_plugin_by_type('comments'); 71 $this->assertTrue($plugin->is_feedback_modified($grade, $data)); 72 73 // Save the feedback. 74 $plugin->save($grade, $data); 75 76 // Try again with the same data. 77 $this->assertFalse($plugin->is_feedback_modified($grade, $data)); 78 79 // Change the data. 80 $data->assignfeedbackcomments_editor = [ 81 'text' => '<p>Altered comment for this test</p>', 82 'format' => 1, 83 ]; 84 $this->assertTrue($plugin->is_feedback_modified($grade, $data)); 85 } 86 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body