Differences Between: [Versions 400 and 402] [Versions 400 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 /** 43 * Test {@link workshopform_rubric\privacy\provider::export_assessment_form()} implementation. 44 */ 45 public function test_export_assessment_form() { 46 global $DB; 47 $this->resetAfterTest(); 48 $this->setAdminUser(); 49 50 $this->generator = $this->getDataGenerator(); 51 $this->workshopgenerator = $this->generator->get_plugin_generator('mod_workshop'); 52 53 $this->course1 = $this->generator->create_course(); 54 55 $this->workshop11 = $this->generator->create_module('workshop', [ 56 'course' => $this->course1, 57 'name' => 'Workshop11', 58 ]); 59 $DB->set_field('workshop', 'phase', 50, ['id' => $this->workshop11->id]); 60 61 $this->dim1 = $DB->insert_record('workshopform_rubric', [ 62 'workshopid' => $this->workshop11->id, 63 'sort' => 1, 64 'description' => 'Criterion 1 description', 65 'descriptionformat' => FORMAT_MARKDOWN, 66 ]); 67 68 $DB->insert_record('workshopform_rubric_levels', [ 69 'dimensionid' => $this->dim1, 70 'grade' => 0, 71 'definition' => 'Missing', 72 'definitionformat' => FORMAT_PLAIN, 73 ]); 74 75 $DB->insert_record('workshopform_rubric_levels', [ 76 'dimensionid' => $this->dim1, 77 'grade' => 1, 78 'definition' => 'Poor', 79 'definitionformat' => FORMAT_PLAIN, 80 ]); 81 82 $DB->insert_record('workshopform_rubric_levels', [ 83 'dimensionid' => $this->dim1, 84 'grade' => 2, 85 'definition' => 'Good', 86 'definitionformat' => FORMAT_PLAIN, 87 ]); 88 89 $this->dim2 = $DB->insert_record('workshopform_rubric', [ 90 'workshopid' => $this->workshop11->id, 91 'sort' => 2, 92 'description' => 'Criterion 2 description', 93 'descriptionformat' => FORMAT_MARKDOWN, 94 ]); 95 96 $DB->insert_record('workshopform_rubric_levels', [ 97 'dimensionid' => $this->dim2, 98 'grade' => 0, 99 'definition' => 'Missing', 100 'definitionformat' => FORMAT_PLAIN, 101 ]); 102 103 $DB->insert_record('workshopform_rubric_levels', [ 104 'dimensionid' => $this->dim2, 105 'grade' => 5, 106 'definition' => 'Great', 107 'definitionformat' => FORMAT_PLAIN, 108 ]); 109 110 $this->student1 = $this->generator->create_user(); 111 $this->student2 = $this->generator->create_user(); 112 113 $this->submission111 = $this->workshopgenerator->create_submission($this->workshop11->id, $this->student1->id); 114 115 $this->assessment1112 = $this->workshopgenerator->create_assessment($this->submission111, $this->student2->id, [ 116 'grade' => 92, 117 ]); 118 119 $DB->insert_record('workshop_grades', [ 120 'assessmentid' => $this->assessment1112, 121 'strategy' => 'rubric', 122 'dimensionid' => $this->dim1, 123 'grade' => 1, 124 'peercomment' => '', 125 'peercommentformat' => FORMAT_PLAIN, 126 ]); 127 128 $DB->insert_record('workshop_grades', [ 129 'assessmentid' => $this->assessment1112, 130 'strategy' => 'rubric', 131 'dimensionid' => $this->dim2, 132 'grade' => 5, 133 'peercomment' => '', 134 'peercommentformat' => FORMAT_PLAIN, 135 ]); 136 137 $contextlist = new \core_privacy\local\request\approved_contextlist($this->student2, 'mod_workshop', [ 138 \context_module::instance($this->workshop11->cmid)->id, 139 ]); 140 141 \mod_workshop\privacy\provider::export_user_data($contextlist); 142 143 $writer = writer::with_context(\context_module::instance($this->workshop11->cmid)); 144 145 $form = $writer->get_data([ 146 get_string('myassessments', 'mod_workshop'), 147 $this->assessment1112, 148 get_string('assessmentform', 'mod_workshop'), 149 get_string('pluginname', 'workshopform_rubric'), 150 ]); 151 152 $this->assertEquals('Criterion 1 description', $form->criteria[0]->description); 153 $this->assertEquals(3, count($form->criteria[0]->levels)); 154 $this->assertEquals(2, count($form->criteria[1]->levels)); 155 $this->assertEquals(5, $form->criteria[1]->grade); 156 } 157 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body