From e5c6443bd8ff2ec45aca99e7c58be0a8b4dddf01 Mon Sep 17 00:00:00 2001 From: Amanda Doughty Date: Fri, 7 Feb 2025 08:52:01 +0000 Subject: [PATCH] MDL-84448 lib: Fixed behat context check for grandchild themes --- lib/behat/classes/behat_context_helper.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/behat/classes/behat_context_helper.php b/lib/behat/classes/behat_context_helper.php index 76851230042..399a3a9b6b7 100644 --- a/lib/behat/classes/behat_context_helper.php +++ b/lib/behat/classes/behat_context_helper.php @@ -148,6 +148,23 @@ class behat_context_helper { return $overrideclassname; } + try { + $themeconfig = theme_config::load($suitename); + } catch (Exception $e) { + // This theme has no theme config. + return []; + } + + // The theme will use all core contexts, except the one overridden by theme or its parent. + if (isset($themeconfig->parents)) { + foreach ($themeconfig->parents as $parent) { + $overrideclassname = "behat_theme_{$parent}_{$classname}"; + if (self::$environment->hasContextClass($overrideclassname)) { + return $overrideclassname; + } + } + } + if (self::$environment->hasContextClass($classname)) { return $classname; }