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