Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 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 * Metadata registry tests. 19 * 20 * @package tool_dataprivacy 21 * @copyright 2018 Adrian Greeve <adriangreeve.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 global $CFG; 27 28 /** 29 * Metadata registry tests. 30 * 31 * @package tool_dataprivacy 32 * @copyright 2018 Adrian Greeve <adriangreeve.com> 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class tool_dataprivacy_metadata_registry_testcase extends advanced_testcase { 36 37 /** 38 * Fetch the meta data and return it in a form that we can easily unit test. 39 * 40 * @return array the meta data. 41 */ 42 protected function get_meta_data() { 43 $metadataregistry = new \tool_dataprivacy\metadata_registry(); 44 $data = $metadataregistry->get_registry_metadata(); 45 $newdata = []; 46 foreach ($data as $value) { 47 $additional = []; 48 foreach ($value['plugins'] as $moredata) { 49 $additional[$moredata['raw_component']] = $moredata; 50 } 51 $newdata[$value['plugin_type_raw']] = $additional; 52 } 53 return $newdata; 54 } 55 56 /** 57 * Test that we can fetch metadata about users for the whole system and that it matches the system count. 58 */ 59 public function test_get_registry_metadata_count() { 60 $data = $this->get_meta_data(); 61 62 $plugintypes = \core_component::get_plugin_types(); 63 64 // Check that we have the correct number of plugin types. 65 $plugincount = count($plugintypes) + 1; // Plus one for core. 66 $this->assertEquals($plugincount, count($data)); 67 68 // Check that each plugin count matches. 69 foreach ($plugintypes as $plugintype => $notused) { 70 $plugins = \core_component::get_plugin_list($plugintype); 71 $this->assertEquals(count($plugins), count($data[$plugintype])); 72 } 73 74 // Let's check core subsystems. 75 // The Privacy API adds an extra component in the form of 'core'. 76 $coresubsystems = \core_component::get_core_subsystems(); 77 $this->assertEquals(count($coresubsystems) + 1, count($data['core'])); 78 } 79 80 /** 81 * Check that the expected null provider information is returned. 82 */ 83 public function test_get_registry_metadata_null_provider_details() { 84 $data = $this->get_meta_data(); 85 86 // Check details of core privacy (a null privder) are correct. 87 $coreprivacy = $data['core']['core_privacy']; 88 $this->assertEquals(1, $coreprivacy['compliant']); 89 $this->assertNotEmpty($coreprivacy['nullprovider']); 90 } 91 92 /** 93 * Check that the expected privacy provider information is returned. 94 */ 95 public function test_get_registry_metadata_provider_details() { 96 $data = $this->get_meta_data(); 97 98 // Check details of core rating (a normal provider) are correct. 99 $corerating = $data['core']['core_rating']; 100 $this->assertEquals(1, $corerating['compliant']); 101 $this->assertNotEmpty($corerating['metadata']); 102 $this->assertEquals('database_table', $corerating['metadata'][0]['type']); 103 $this->assertNotEmpty($corerating['metadata'][0]['fields']); 104 } 105 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body