Permalink
Browse files

Merge branch 'MDL-62370-33' of git://github.com/andrewnicols/moodle i…

…nto MOODLE_33_STABLE
  • Loading branch information...
dmonllao committed May 14, 2018
2 parents 533ef68 + d334974 commit f6d8b2f753f72efb7928a0010e83d461ae6af256
Showing with 97 additions and 0 deletions.
  1. +1 −0 lang/en/privacy.php
  2. +23 −0 privacy/classes/manager.php
  3. +73 −0 privacy/tests/manager_test.php
@@ -32,3 +32,4 @@
$string['trace:fetchcomponents'] = 'Fetching {$a->total} components ({$a->datetime})';
$string['trace:deletingapproved'] = 'Performing removal of approved {$a->total} contexts ({$a->datetime})';
$string['trace:deletingcontext'] = 'Performing removal of context from {$a->total} components ({$a->datetime})';
$string['privacy:subsystem:empty'] = 'This subsystem does not store any data.';
@@ -123,11 +123,17 @@ public function component_is_compliant($component) {
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;
}
@@ -146,6 +152,23 @@ public function get_null_provider_reason($component) {
}
}
/**
* 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.
*
@@ -129,6 +129,38 @@ public function test_component_is_compliant() {
$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 @@ public function test_plugintype_class_callback() {
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,
],
];
}
}

0 comments on commit f6d8b2f

Please sign in to comment.