From 2e8b980985a1bc5bbf491ba31ef91892fa5a448e Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Wed, 30 Oct 2024 13:04:23 +0000 Subject: [PATCH] MDL-80689 behat: add a transformation to get dirroot --- lib/tests/behat/behat_transformations.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/tests/behat/behat_transformations.php b/lib/tests/behat/behat_transformations.php index bbd80ad44d3..106bdc2f7c6 100644 --- a/lib/tests/behat/behat_transformations.php +++ b/lib/tests/behat/behat_transformations.php @@ -151,6 +151,18 @@ class behat_transformations extends behat_base { return $this->replace_wwwroot($string); } + /** + * Convert #dirroot# to the dirroot config value, so it is + * possible to reference files (e.g. fixtures) with an absolute path. + * + * @Transform /^((.*)#dirroot#(.*))$/ + * @param string $string + * @return string + */ + public function arg_insert_dirroot(string $string): string { + return $this->replace_dirroot($string); + } + /** * Replaces $NASTYSTRING vars for a nasty string. * @@ -205,4 +217,15 @@ class behat_transformations extends behat_base { global $CFG; return str_replace('#wwwroot#', $CFG->wwwroot, $string); } + + /** + * Replace #dirroot# with the actual dirroot config value. + * + * @param string $string String to attempt the replacement in. + * @return string + */ + protected function replace_dirroot(string $string): string { + global $CFG; + return str_replace('#dirroot#', $CFG->dirroot, $string); + } }