From ef936717eee2c6b8fa313021040d41a8b633150b Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Mon, 13 Mar 2023 09:30:35 +0100 Subject: [PATCH] MDL-77607 core_component: Fix wrong component for the grade api The correct component (subsystem) for the "grade" API is "core_grades" not "core_grade". Let's fix that and cover it with tests. --- lib/apis.json | 2 +- lib/tests/component_test.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/apis.json b/lib/apis.json index 68813539c23..39e51882265 100644 --- a/lib/apis.json +++ b/lib/apis.json @@ -110,7 +110,7 @@ "allowedspread": true }, "grade": { - "component": "core_grade", + "component": "core_grades", "allowedlevel2": false, "allowedspread": false }, diff --git a/lib/tests/component_test.php b/lib/tests/component_test.php index d86d446b5de..a7461c80788 100644 --- a/lib/tests/component_test.php +++ b/lib/tests/component_test.php @@ -892,6 +892,9 @@ class component_test extends advanced_testcase { $apis = $sortedapis = core_component::get_core_apis(); ksort($sortedapis); // We'll need this later. + $subsystems = core_component::get_core_subsystems(); // To verify all apis are pointing to valid subsystems. + $subsystems['core'] = 'anything'; // Let's add 'core' because it's a valid component for apis. + // General structure validations. $this->assertIsArray($apis); $this->assertGreaterThan(25, count($apis)); @@ -911,11 +914,16 @@ class component_test extends advanced_testcase { // Verify attributes. if ($apiname !== 'core') { // Exception for core api, it doesn't have component. + // Check that component attribute looks correct. $this->assertMatchesRegularExpression('/^(core|[a-z][a-z0-9_]+)$/', $attributes->component, $message); + // Ensure that the api component (without the core_ prefix) is a correct subsystem. + $this->assertArrayHasKey(str_replace('core_', '', $attributes->component), $subsystems, $message); } else { $this->assertNull($attributes->component, $message); } + + // Now check for the rest of attributes. $this->assertIsBool($attributes->allowedlevel2, $message); $this->assertIsBool($attributes->allowedspread, $message);