[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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_file 19 * 20 * @package assignfeedback_file 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/base_test.php'); 29 30 /** 31 * Unit tests for assignfeedback_file 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_file_testcase extends mod_assign_base_testcase { 37 38 /** 39 * Create an assign object and submit an online text submission. 40 */ 41 protected function create_assign_and_submit_text() { 42 $assign = $this->create_instance(array('assignsubmission_onlinetext_enabled' => 1, 43 'assignfeedback_comments_enabled' => 1)); 44 45 $user = $this->students[0]; 46 $this->setUser($user); 47 48 // Create an online text submission. 49 $submission = $assign->get_user_submission($user->id, true); 50 51 $data = new stdClass(); 52 $data->onlinetext_editor = array( 53 'text' => '<p>This is some text.</p>', 54 'format' => 1, 55 'itemid' => file_get_unused_draft_itemid()); 56 $plugin = $assign->get_submission_plugin_by_type('onlinetext'); 57 $plugin->save($submission, $data); 58 59 return $assign; 60 } 61 62 /** 63 * Test the is_feedback_modified() method for the file feedback. 64 */ 65 public function test_is_feedback_modified() { 66 $assign = $this->create_assign_and_submit_text(); 67 68 $this->setUser($this->teachers[0]); 69 70 $fs = get_file_storage(); 71 $context = context_user::instance($this->teachers[0]->id); 72 $draftitemid = file_get_unused_draft_itemid(); 73 file_prepare_draft_area($draftitemid, $context->id, 'assignfeedback_file', 'feedback_files', 1); 74 75 $dummy = array( 76 'contextid' => $context->id, 77 'component' => 'user', 78 'filearea' => 'draft', 79 'itemid' => $draftitemid, 80 'filepath' => '/', 81 'filename' => 'feedback1.txt' 82 ); 83 84 $file = $fs->create_file_from_string($dummy, 'This is the first feedback file'); 85 86 // Create formdata. 87 $data = new stdClass(); 88 $data->{'files_' . $this->students[0]->id . '_filemanager'} = $draftitemid; 89 90 $grade = $assign->get_user_grade($this->students[0]->id, true); 91 92 // This is the first time that we are submitting feedback, so it is modified. 93 $plugin = $assign->get_feedback_plugin_by_type('file'); 94 $this->assertTrue($plugin->is_feedback_modified($grade, $data)); 95 // Save the feedback. 96 $plugin->save($grade, $data); 97 // Try again with the same data. 98 $draftitemid = file_get_unused_draft_itemid(); 99 file_prepare_draft_area($draftitemid, $context->id, 'assignfeedback_file', 'feedback_files', 1); 100 101 $dummy['itemid'] = $draftitemid; 102 103 $file = $fs->create_file_from_string($dummy, 'This is the first feedback file'); 104 105 // Create formdata. 106 $data = new stdClass(); 107 $data->{'files_' . $this->students[0]->id . '_filemanager'} = $draftitemid; 108 109 $this->assertFalse($plugin->is_feedback_modified($grade, $data)); 110 111 // Same name for the file but different content. 112 $draftitemid = file_get_unused_draft_itemid(); 113 file_prepare_draft_area($draftitemid, $context->id, 'assignfeedback_file', 'feedback_files', 1); 114 115 $dummy['itemid'] = $draftitemid; 116 117 $file = $fs->create_file_from_string($dummy, 'This is different feedback'); 118 119 // Create formdata. 120 $data = new stdClass(); 121 $data->{'files_' . $this->students[0]->id . '_filemanager'} = $draftitemid; 122 123 $this->assertTrue($plugin->is_feedback_modified($grade, $data)); 124 $plugin->save($grade, $data); 125 126 // Add another file. 127 $draftitemid = file_get_unused_draft_itemid(); 128 file_prepare_draft_area($draftitemid, $context->id, 'assignfeedback_file', 'feedback_files', 1); 129 130 $dummy['itemid'] = $draftitemid; 131 132 $file = $fs->create_file_from_string($dummy, 'This is different feedback'); 133 $dummy['filename'] = 'feedback2.txt'; 134 $file = $fs->create_file_from_string($dummy, 'A second feedback file'); 135 136 // Create formdata. 137 $data = new stdClass(); 138 $data->{'files_' . $this->students[0]->id . '_filemanager'} = $draftitemid; 139 140 $this->assertTrue($plugin->is_feedback_modified($grade, $data)); 141 $plugin->save($grade, $data); 142 143 // Deleting a file. 144 $draftitemid = file_get_unused_draft_itemid(); 145 file_prepare_draft_area($draftitemid, $context->id, 'assignfeedback_file', 'feedback_files', 1); 146 147 $dummy['itemid'] = $draftitemid; 148 149 $file = $fs->create_file_from_string($dummy, 'This is different feedback'); 150 151 // Create formdata. 152 $data = new stdClass(); 153 $data->{'files_' . $this->students[0]->id . '_filemanager'} = $draftitemid; 154 155 $this->assertTrue($plugin->is_feedback_modified($grade, $data)); 156 $plugin->save($grade, $data); 157 158 // The file was moved to a folder. 159 $draftitemid = file_get_unused_draft_itemid(); 160 file_prepare_draft_area($draftitemid, $context->id, 'assignfeedback_file', 'feedback_files', 1); 161 162 $dummy['itemid'] = $draftitemid; 163 $dummy['filepath'] = '/testdir/'; 164 165 $file = $fs->create_file_from_string($dummy, 'This is different feedback'); 166 167 // Create formdata. 168 $data = new stdClass(); 169 $data->{'files_' . $this->students[0]->id . '_filemanager'} = $draftitemid; 170 171 $this->assertTrue($plugin->is_feedback_modified($grade, $data)); 172 $plugin->save($grade, $data); 173 174 // No modification to the file in the folder. 175 $draftitemid = file_get_unused_draft_itemid(); 176 file_prepare_draft_area($draftitemid, $context->id, 'assignfeedback_file', 'feedback_files', 1); 177 178 $dummy['itemid'] = $draftitemid; 179 $dummy['filepath'] = '/testdir/'; 180 181 $file = $fs->create_file_from_string($dummy, 'This is different feedback'); 182 183 // Create formdata. 184 $data = new stdClass(); 185 $data->{'files_' . $this->students[0]->id . '_filemanager'} = $draftitemid; 186 187 $this->assertFalse($plugin->is_feedback_modified($grade, $data)); 188 } 189 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |