MDL-62370 core_privacy: Directory-less subsystems are compliant

This commit is contained in:
Andrew Nicols
2018-05-14 20:01:35 +08:00
parent 6df0fa92f3
commit 93476477d6
3 changed files with 97 additions and 0 deletions
+1
View File
@@ -23,3 +23,4 @@
*/
$string['privacy:metadata'] = 'The privacy subsystem does not store any data of its own and is designed to act as a channel between components and the interface used to describe, export, and remove their data.';
$string['privacy:subsystem:empty'] = 'This subsystem does not store any data.';
+23
View File
@@ -123,11 +123,17 @@ class manager {
if ($this->component_implements($component, \core_privacy\local\metadata\null_provider::class)) {
return true;
}
if (static::is_empty_subsystem($component)) {
return true;
}
// Components which store user data must implement the local\metadata\provider and the local\request\data_provider.
if ($this->component_implements($component, \core_privacy\local\metadata\provider::class) &&
$this->component_implements($component, \core_privacy\local\request\data_provider::class)) {
return true;
}
return false;
}
@@ -145,6 +151,23 @@ class manager {
}
}
/**
* Return whether this is an 'empty' subsystem - that is, a subsystem without a directory.
*
* @param string $component Frankenstyle component name.
* @return string The key to retrieve the language string for the null provider reason.
*/
public static function is_empty_subsystem($component) {
if (strpos($component, 'core_') === 0) {
if (null === \core_component::get_subsystem_directory(substr($component, 5))) {
// This is a subsystem without a directory.
return true;
}
}
return false;
}
/**
* Get the privacy metadata for all components.
*
+73
View File
@@ -129,6 +129,38 @@ class privacy_manager_testcase extends advanced_testcase {
$this->assertFalse($mockman->component_is_compliant('tool_thisisnotarealtool123'));
}
/**
* Provider for component_is_compliant tests.
*
* @return array
*/
public function component_is_compliant_provider() {
return [
'An empty subsystem' => [
'core_countries',
true,
],
'A real subsystem' => [
'core_privacy',
true,
],
];
}
/**
* Test verifying the output of component_is_compliant with specified
* components.
*
* @dataProvider component_is_compliant_provider
* @param string $component
* @param boolean $expected
*/
public function test_component_is_compliant_examples($component, $expected) {
$manager = new \core_privacy\manager();
$this->assertEquals($expected, $manager->component_is_compliant($component));
}
/**
* Test verifying only approved contextlists can be used with the export_user_data method.
*/
@@ -227,4 +259,45 @@ class privacy_manager_testcase extends advanced_testcase {
public function test_component_class_callback() {
\core_privacy\manager::component_class_callback('foo_bar', 'unusable', 'foo', ['bar']);
}
/**
* Test the manager::is_empty_subsystem function.
*
* @dataProvider is_empty_subsystem_provider
* @param string $component
* @param bool $expected
*/
public function test_is_empty_subsystem($component, $expected) {
$this->assertEquals($expected, \core_privacy\manager::is_empty_subsystem($component));
}
/**
* Test cases for the is_empty_subsystem function.
*
* @return array
*/
public function is_empty_subsystem_provider() {
return [
'A subsystem which has no directory' => [
'core_langconfig',
true,
],
'A subsystem with a directory' => [
'core_portfolio',
false,
],
'A plugin' => [
'mod_forum',
false,
],
'A plugintype' => [
'mod',
false,
],
'An unprefixed subsystem with no directory' => [
'langconfig',
false,
],
];
}
}