From 5efa9f4653c4fb8f848472cc7483869d34f5e363 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 25 Oct 2018 11:04:08 +0800 Subject: [PATCH] MDL-62601 core_privacy: Ensure providers can handle deleted users --- privacy/tests/provider_test.php | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/privacy/tests/provider_test.php b/privacy/tests/provider_test.php index 0ca9768083b..f59b042cd92 100644 --- a/privacy/tests/provider_test.php +++ b/privacy/tests/provider_test.php @@ -178,6 +178,29 @@ class provider_testcase extends advanced_testcase { $this->assertTrue($manager->component_is_compliant($component)); } + /** + * Ensure that providers do not throw an error when processing a deleted user. + * + * @dataProvider is_user_data_provider + * @param string $component + */ + public function test_component_understands_deleted_users($component) { + $this->resetAfterTest(); + + // Create a user. + $user = $this->getDataGenerator()->create_user(); + + // Delete the user and their context. + delete_user($user); + $usercontext = \context_user::instance($user->id); + $usercontext->delete(); + + $contextlist = manager::component_class_callback($component, \core_privacy\local\request\core_user_data_provider::class, + 'get_contexts_for_userid', [$user->id]); + + $this->assertInstanceOf(\core_privacy\local\request\contextlist::class, $contextlist); + } + /** * Data provider for the metadata\provider tests. * @@ -192,6 +215,20 @@ class provider_testcase extends advanced_testcase { }); } + /** + * List of providers which implement the core_user_data_provider. + * + * @return array + */ + public function is_user_data_provider() { + return array_filter($this->get_component_list(), function($component) { + return static::component_implements( + $component['classname'], + \core_privacy\local\request\core_user_data_provider::class + ); + }); + } + /** * Checks whether the component's provider class implements the specified interface, either directly or as a grandchild. * -- 2.43.0