From 0e1de8d591937b73c8e8ff89c9512acb75147d94 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Wed, 11 Jun 2025 18:45:09 +0100 Subject: [PATCH] MDL-85743 user: correct debugging for missing user picture fields. --- lib/classes/output/user_picture.php | 2 +- lib/tests/output/user_picture_test.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/classes/output/user_picture.php b/lib/classes/output/user_picture.php index ed6266d8a2b..84ee0343a4a 100644 --- a/lib/classes/output/user_picture.php +++ b/lib/classes/output/user_picture.php @@ -106,7 +106,7 @@ class user_picture implements renderable { if (!property_exists($user, $field)) { $needrec = true; debugging( - "Missing {$field} property in {$user} object, " + "Missing '{$field}' property in \$user object, " . "this is a performance problem that needs to be fixed by a developer. " . 'Please use the \core_user\fields API to get the full list of required fields.', DEBUG_DEVELOPER, diff --git a/lib/tests/output/user_picture_test.php b/lib/tests/output/user_picture_test.php index 8c49d383650..b88be2d908f 100644 --- a/lib/tests/output/user_picture_test.php +++ b/lib/tests/output/user_picture_test.php @@ -25,6 +25,20 @@ namespace core\output; * @covers \core\output\user_picture */ final class user_picture_test extends \advanced_testcase { + + /** + * Assert appropriate debugging is emitted if required user fields are absent + */ + public function test_constructor_missing_fields(): void { + $user = get_admin(); + unset($user->picture); + + // Assert debugging notice when required field isn't present. + $userpicture = new user_picture($user); + $this->assertDebuggingCalled('Missing \'picture\' property in $user object, this is a performance problem that needs ' . + 'to be fixed by a developer. Please use the \core_user\fields API to get the full list of required fields.'); + } + /** * Tests {@see user_picture::allow_view()} for a not-logged-in request. */