mirrored from git://git.moodle.org/moodle.git
/
privacy_provider_test.php
122 lines (101 loc) · 4.39 KB
/
privacy_provider_test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Provides the {@link workshopform_accumulative_privacy_provider_testcase} class.
*
* @package workshopform_accumulative
* @category test
* @copyright 2018 David Mudrák <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
use core_privacy\local\request\writer;
/**
* Unit tests for the privacy API implementation.
*
* @copyright 2018 David Mudrák <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class workshopform_accumulative_privacy_provider_testcase extends advanced_testcase {
/**
* Test {@link workshopform_accumulative\privacy\provider::export_assessment_form()} implementation.
*/
public function test_export_assessment_form() {
global $DB;
$this->resetAfterTest();
$this->setAdminUser();
$this->generator = $this->getDataGenerator();
$this->workshopgenerator = $this->generator->get_plugin_generator('mod_workshop');
$this->course1 = $this->generator->create_course();
$this->workshop11 = $this->generator->create_module('workshop', [
'course' => $this->course1,
'name' => 'Workshop11',
]);
$DB->set_field('workshop', 'phase', 50, ['id' => $this->workshop11->id]);
$this->dim1 = $DB->insert_record('workshopform_accumulative', [
'workshopid' => $this->workshop11->id,
'sort' => 1,
'description' => 'Aspect 1 description',
'descriptionformat' => FORMAT_MARKDOWN,
'grade' => 6,
'weight' => 1,
]);
$this->dim2 = $DB->insert_record('workshopform_accumulative', [
'workshopid' => $this->workshop11->id,
'sort' => 2,
'description' => 'Aspect 2 description',
'descriptionformat' => FORMAT_MARKDOWN,
'grade' => 4,
'weight' => 1,
]);
$this->student1 = $this->generator->create_user();
$this->student2 = $this->generator->create_user();
$this->submission111 = $this->workshopgenerator->create_submission($this->workshop11->id, $this->student1->id);
$this->assessment1112 = $this->workshopgenerator->create_assessment($this->submission111, $this->student2->id, [
'grade' => 92,
]);
$DB->insert_record('workshop_grades', [
'assessmentid' => $this->assessment1112,
'strategy' => 'accumulative',
'dimensionid' => $this->dim1,
'grade' => 3,
'peercomment' => 'Not awesome',
'peercommentformat' => FORMAT_PLAIN,
]);
$DB->insert_record('workshop_grades', [
'assessmentid' => $this->assessment1112,
'strategy' => 'accumulative',
'dimensionid' => $this->dim2,
'grade' => 4,
'peercomment' => 'All good',
'peercommentformat' => FORMAT_PLAIN,
]);
$contextlist = new \core_privacy\local\request\approved_contextlist($this->student2, 'mod_workshop', [
\context_module::instance($this->workshop11->cmid)->id,
]);
\mod_workshop\privacy\provider::export_user_data($contextlist);
$writer = writer::with_context(\context_module::instance($this->workshop11->cmid));
$form = $writer->get_data([
get_string('myassessments', 'mod_workshop'),
$this->assessment1112,
get_string('assessmentform', 'mod_workshop'),
get_string('pluginname', 'workshopform_accumulative'),
]);
$this->assertEquals('Aspect 1 description', $form->aspects[0]->description);
$this->assertEquals(4, $form->aspects[1]->grade);
}
}