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_numerrors\privacy\provider_test} class. 19 * 20 * @package workshopform_numerrors 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_numerrors\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_numerrors\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_numerrors', [ 62 'workshopid' => $this->workshop11->id, 63 'sort' => 1, 64 'description' => 'Assertion 1 description', 65 'descriptionformat' => FORMAT_MARKDOWN, 66 'descriptiontrust' => 0, 67 'grade0' => 'No', 68 'grade1' => 'Yes', 69 'weight' => 1, 70 ]); 71 72 $this->dim2 = $DB->insert_record('workshopform_numerrors', [ 73 'workshopid' => $this->workshop11->id, 74 'sort' => 2, 75 'description' => 'Assertion 2 description', 76 'descriptionformat' => FORMAT_MARKDOWN, 77 'descriptiontrust' => 0, 78 'grade0' => 'Missing', 79 'grade1' => 'Present', 80 'weight' => 1, 81 ]); 82 83 $this->student1 = $this->generator->create_user(); 84 $this->student2 = $this->generator->create_user(); 85 86 $this->submission111 = $this->workshopgenerator->create_submission($this->workshop11->id, $this->student1->id); 87 88 $this->assessment1112 = $this->workshopgenerator->create_assessment($this->submission111, $this->student2->id, [ 89 'grade' => 92, 90 ]); 91 92 $DB->insert_record('workshop_grades', [ 93 'assessmentid' => $this->assessment1112, 94 'strategy' => 'numerrors', 95 'dimensionid' => $this->dim1, 96 'grade' => 1, 97 'peercomment' => 'Awesome', 98 'peercommentformat' => FORMAT_PLAIN, 99 ]); 100 101 $DB->insert_record('workshop_grades', [ 102 'assessmentid' => $this->assessment1112, 103 'strategy' => 'numerrors', 104 'dimensionid' => $this->dim2, 105 'grade' => 0, 106 'peercomment' => 'Missing', 107 'peercommentformat' => FORMAT_PLAIN, 108 ]); 109 110 $contextlist = new \core_privacy\local\request\approved_contextlist($this->student2, 'mod_workshop', [ 111 \context_module::instance($this->workshop11->cmid)->id, 112 ]); 113 114 \mod_workshop\privacy\provider::export_user_data($contextlist); 115 116 $writer = writer::with_context(\context_module::instance($this->workshop11->cmid)); 117 118 $form = $writer->get_data([ 119 get_string('myassessments', 'mod_workshop'), 120 $this->assessment1112, 121 get_string('assessmentform', 'mod_workshop'), 122 get_string('pluginname', 'workshopform_numerrors'), 123 ]); 124 125 $this->assertEquals('Assertion 1 description', $form->assertions[0]->description); 126 $this->assertEquals(0, $form->assertions[1]->grade); 127 $this->assertEquals('Missing', $form->assertions[1]->peercomment); 128 } 129 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body