Skip to content

Commit f6d8b2f

Browse files
author
David Monllao
committed
Merge branch 'MDL-62370-33' of git://github.com/andrewnicols/moodle into MOODLE_33_STABLE
2 parents 533ef68 + d334974 commit f6d8b2f

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

lang/en/privacy.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@
3232
$string['trace:fetchcomponents'] = 'Fetching {$a->total} components ({$a->datetime})';
3333
$string['trace:deletingapproved'] = 'Performing removal of approved {$a->total} contexts ({$a->datetime})';
3434
$string['trace:deletingcontext'] = 'Performing removal of context from {$a->total} components ({$a->datetime})';
35+
$string['privacy:subsystem:empty'] = 'This subsystem does not store any data.';

privacy/classes/manager.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,17 @@ public function component_is_compliant($component) {
123123
if ($this->component_implements($component, \core_privacy\local\metadata\null_provider::class)) {
124124
return true;
125125
}
126+
127+
if (static::is_empty_subsystem($component)) {
128+
return true;
129+
}
130+
126131
// Components which store user data must implement the local\metadata\provider and the local\request\data_provider.
127132
if ($this->component_implements($component, \core_privacy\local\metadata\provider::class) &&
128133
$this->component_implements($component, \core_privacy\local\request\data_provider::class)) {
129134
return true;
130135
}
136+
131137
return false;
132138
}
133139

@@ -146,6 +152,23 @@ public function get_null_provider_reason($component) {
146152
}
147153
}
148154

155+
/**
156+
* Return whether this is an 'empty' subsystem - that is, a subsystem without a directory.
157+
*
158+
* @param string $component Frankenstyle component name.
159+
* @return string The key to retrieve the language string for the null provider reason.
160+
*/
161+
public static function is_empty_subsystem($component) {
162+
if (strpos($component, 'core_') === 0) {
163+
if (null === \core_component::get_subsystem_directory(substr($component, 5))) {
164+
// This is a subsystem without a directory.
165+
return true;
166+
}
167+
}
168+
169+
return false;
170+
}
171+
149172
/**
150173
* Get the privacy metadata for all components.
151174
*

privacy/tests/manager_test.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,38 @@ public function test_component_is_compliant() {
129129
$this->assertFalse($mockman->component_is_compliant('tool_thisisnotarealtool123'));
130130
}
131131

132+
/**
133+
* Provider for component_is_compliant tests.
134+
*
135+
* @return array
136+
*/
137+
public function component_is_compliant_provider() {
138+
return [
139+
'An empty subsystem' => [
140+
'core_countries',
141+
true,
142+
],
143+
'A real subsystem' => [
144+
'core_privacy',
145+
true,
146+
],
147+
];
148+
}
149+
150+
/**
151+
* Test verifying the output of component_is_compliant with specified
152+
* components.
153+
*
154+
* @dataProvider component_is_compliant_provider
155+
* @param string $component
156+
* @param boolean $expected
157+
*/
158+
public function test_component_is_compliant_examples($component, $expected) {
159+
$manager = new \core_privacy\manager();
160+
161+
$this->assertEquals($expected, $manager->component_is_compliant($component));
162+
}
163+
132164
/**
133165
* Test verifying only approved contextlists can be used with the export_user_data method.
134166
*/
@@ -227,4 +259,45 @@ public function test_plugintype_class_callback() {
227259
public function test_component_class_callback() {
228260
\core_privacy\manager::component_class_callback('foo_bar', 'unusable', 'foo', ['bar']);
229261
}
262+
263+
/**
264+
* Test the manager::is_empty_subsystem function.
265+
*
266+
* @dataProvider is_empty_subsystem_provider
267+
* @param string $component
268+
* @param bool $expected
269+
*/
270+
public function test_is_empty_subsystem($component, $expected) {
271+
$this->assertEquals($expected, \core_privacy\manager::is_empty_subsystem($component));
272+
}
273+
274+
/**
275+
* Test cases for the is_empty_subsystem function.
276+
*
277+
* @return array
278+
*/
279+
public function is_empty_subsystem_provider() {
280+
return [
281+
'A subsystem which has no directory' => [
282+
'core_langconfig',
283+
true,
284+
],
285+
'A subsystem with a directory' => [
286+
'core_portfolio',
287+
false,
288+
],
289+
'A plugin' => [
290+
'mod_forum',
291+
false,
292+
],
293+
'A plugintype' => [
294+
'mod',
295+
false,
296+
],
297+
'An unprefixed subsystem with no directory' => [
298+
'langconfig',
299+
false,
300+
],
301+
];
302+
}
230303
}

0 commit comments

Comments
 (0)