Navigation Menu

Skip to content

Commit

Permalink
Merge branch 'MDL-62370-34' of git://github.com/andrewnicols/moodle i…
Browse files Browse the repository at this point in the history
…nto MOODLE_34_STABLE
  • Loading branch information
David Monllao committed May 14, 2018
2 parents 862b48e + 9347647 commit 285d723
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions lang/en/privacy.php
Expand Up @@ -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.';
23 changes: 23 additions & 0 deletions privacy/classes/manager.php
Expand Up @@ -123,11 +123,17 @@ public function component_is_compliant(string $component) : bool {
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;
}

Expand All @@ -145,6 +151,23 @@ public function get_null_provider_reason(string $component) : string {
}
}

/**
* 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.
*
Expand Down
73 changes: 73 additions & 0 deletions privacy/tests/manager_test.php
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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 285d723

Please sign in to comment.