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 * This is the external method for submit selected courses. 19 * 20 * @package tool_dataprivacy 21 * @copyright 2021 The Open University 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace tool_dataprivacy\external; 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 global $CFG; 30 require_once($CFG->dirroot . '/webservice/tests/helpers.php'); 31 32 use tool_dataprivacy\api; 33 34 /** 35 * External function submit_selected_courses_form_test. 36 * 37 * @package tool_dataprivacy 38 * @copyright 2021 The Open University 39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 40 * @covers \tool_dataprivacy\api 41 */ 42 class submit_selected_courses_form_test extends \externallib_advanced_testcase { 43 /** 44 * Test for submit_selected_courses_form(). 45 */ 46 public function test_submit_selected_courses_form() { 47 global $DB; 48 $this->resetAfterTest(); 49 50 set_config('allowfiltering', 1, 'tool_dataprivacy'); 51 $generator = new \testing_data_generator(); 52 $s1 = $generator->create_user(); 53 $s1->ignoresesskey = true; 54 $u1 = $generator->create_user(); 55 $u1->ignoresesskey = true; 56 57 $context = \context_system::instance(); 58 $course = $this->getDataGenerator()->create_course([]); 59 60 $coursecontext1 = \context_course::instance($course->id); 61 62 $this->getDataGenerator()->enrol_user($s1->id, $course->id, 'student'); 63 64 // Manager role. 65 $managerroleid = $DB->get_field('role', 'id', array('shortname' => 'manager')); 66 // Give the manager role with the capability to manage data requests. 67 assign_capability('tool/dataprivacy:managedatarequests', CAP_ALLOW, $managerroleid, $context->id, true); 68 // Assign u1 as a manager. 69 role_assign($managerroleid, $u1->id, $context->id); 70 71 // Map the manager role to the DPO role. 72 set_config('dporoles', $managerroleid, 'tool_dataprivacy'); 73 74 // Create the sample data request. 75 $this->setUser($s1); 76 $datarequest = api::create_data_request($s1->id, api::DATAREQUEST_TYPE_EXPORT); 77 $requestid = $datarequest->get('id'); 78 79 // Make this ready for approval. 80 api::update_request_status($requestid, api::DATAREQUEST_STATUS_AWAITING_APPROVAL); 81 82 $this->setUser($u1); 83 $jsonstring = "requestid=" . $requestid . "&sesskey=" . sesskey() . 84 "&_qf__tool_dataprivacy_form_exportfilter_form=1&coursecontextids%5B%5D=" . $coursecontext1->id; 85 $results = submit_selected_courses_form::execute($requestid, json_encode($jsonstring)); 86 $this->assertTrue($results["result"]); 87 } 88 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body