MDL-80689 behat: add a transformation to get dirroot

This commit is contained in:
Tim Hunt 2024-10-30 13:04:23 +00:00
parent fc96ef2937
commit 899f9908db

View File

@ -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);
}
}