Differences Between: [Versions 311 and 403] [Versions 400 and 403] [Versions 401 and 403]
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 * Provides the {@see workshopform_rubric\privacy\provider_test} class. 19 * 20 * @package workshopform_rubric 21 * @category test 22 * @copyright 2018 David Mudrák <david@moodle.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 namespace workshopform_rubric\privacy; 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 global $CFG; 30 31 use core_privacy\local\request\writer; 32 use core_privacy\tests\provider_testcase; 33 34 /** 35 * Unit tests for the privacy API implementation. 36 * 37 * @copyright 2018 David Mudrák <david@moodle.com> 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 39 */ 40 class provider_test extends provider_testcase { 41 42 /** @var \testing_data_generator data generator. */ 43 protected $generator; 44 45 /** @var \mod_workshop_generator workshop generator. */ 46 protected $workshopgenerator; 47 48 /** @var \stdClass course data. */ 49 protected $course1; 50 51 /** @var \stdClass student data. */ 52 protected $student1; 53 54 /** @var \stdClass student data. */ 55 protected $student2; 56 57 /** @var \stdClass first workshop in course1 */ 58 protected $workshop11; 59 60 /** @var int ID of the submission in workshop11 by student1 */ 61 protected $submission111; 62 63 /** @var int ID of the assessment of submission111 by student2 */ 64 protected $assessment1112; 65 66 /** @var bool|int true or new id */ 67 protected $dim1; 68 69 /** @var bool|int true or new id */ 70 protected $dim2; 71 72 /** 73 * Test {@link workshopform_rubric\privacy\provider::export_assessment_form()} implementation. 74 */ 75 public function test_export_assessment_form() { 76 global $DB; 77 $this->resetAfterTest(); 78 $this->setAdminUser(); 79 80 $this->generator = $this->getDataGenerator(); 81 $this->workshopgenerator = $this->generator->get_plugin_generator('mod_workshop'); 82 83 $this->course1 = $this->generator->create_course(); 84 85 $this->workshop11 = $this->generator->create_module('workshop', [ 86 'course' => $this->course1, 87 'name' => 'Workshop11', 88 ]); 89 $DB->set_field('workshop', 'phase', 50, ['id' => $this->workshop11->id]); 90 91 $this->dim1 = $DB->insert_record('workshopform_rubric', [ 92 'workshopid' => $this->workshop11->id, 93 'sort' => 1, 94 'description' => 'Criterion 1 description', 95 'descriptionformat' => FORMAT_MARKDOWN, 96 ]); 97 98 $DB->insert_record('workshopform_rubric_levels', [ 99 'dimensionid' => $this->dim1, 100 'grade' => 0, 101 'definition' => 'Missing', 102 'definitionformat' => FORMAT_PLAIN, 103 ]); 104 105 $DB->insert_record('workshopform_rubric_levels', [ 106 'dimensionid' => $this->dim1, 107 'grade' => 1, 108 'definition' => 'Poor', 109 'definitionformat' => FORMAT_PLAIN, 110 ]); 111 112 $DB->insert_record('workshopform_rubric_levels', [ 113 'dimensionid' => $this->dim1, 114 'grade' => 2, 115 'definition' => 'Good', 116 'definitionformat' => FORMAT_PLAIN, 117 ]); 118 119 $this->dim2 = $DB->insert_record('workshopform_rubric', [ 120 'workshopid' => $this->workshop11->id, 121 'sort' => 2, 122 'description' => 'Criterion 2 description', 123 'descriptionformat' => FORMAT_MARKDOWN, 124 ]); 125 126 $DB->insert_record('workshopform_rubric_levels', [ 127 'dimensionid' => $this->dim2, 128 'grade' => 0, 129 'definition' => 'Missing', 130 'definitionformat' => FORMAT_PLAIN, 131 ]); 132 133 $DB->insert_record('workshopform_rubric_levels', [ 134 'dimensionid' => $this->dim2, 135 'grade' => 5, 136 'definition' => 'Great', 137 'definitionformat' => FORMAT_PLAIN, 138 ]); 139 140 $this->student1 = $this->generator->create_user(); 141 $this->student2 = $this->generator->create_user(); 142 143 $this->submission111 = $this->workshopgenerator->create_submission($this->workshop11->id, $this->student1->id); 144 145 $this->assessment1112 = $this->workshopgenerator->create_assessment($this->submission111, $this->student2->id, [ 146 'grade' => 92, 147 ]); 148 149 $DB->insert_record('workshop_grades', [ 150 'assessmentid' => $this->assessment1112, 151 'strategy' => 'rubric', 152 'dimensionid' => $this->dim1, 153 'grade' => 1, 154 'peercomment' => '', 155 'peercommentformat' => FORMAT_PLAIN, 156 ]); 157 158 $DB->insert_record('workshop_grades', [ 159 'assessmentid' => $this->assessment1112, 160 'strategy' => 'rubric', 161 'dimensionid' => $this->dim2, 162 'grade' => 5, 163 'peercomment' => '', 164 'peercommentformat' => FORMAT_PLAIN, 165 ]); 166 167 $contextlist = new \core_privacy\local\request\approved_contextlist($this->student2, 'mod_workshop', [ 168 \context_module::instance($this->workshop11->cmid)->id, 169 ]); 170 171 \mod_workshop\privacy\provider::export_user_data($contextlist); 172 173 $writer = writer::with_context(\context_module::instance($this->workshop11->cmid)); 174 175 $form = $writer->get_data([ 176 get_string('myassessments', 'mod_workshop'), 177 $this->assessment1112, 178 get_string('assessmentform', 'mod_workshop'), 179 get_string('pluginname', 'workshopform_rubric'), 180 ]); 181 182 $this->assertEquals('Criterion 1 description', $form->criteria[0]->description); 183 $this->assertEquals(3, count($form->criteria[0]->levels)); 184 $this->assertEquals(2, count($form->criteria[1]->levels)); 185 $this->assertEquals(5, $form->criteria[1]->grade); 186 } 187 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body