MDL-80689 behat: add a transformation to get dirroot
Also, back-port #wwwroot# from MDL-78619 which was not backported at the time.
This commit is contained in:
@@ -133,6 +133,30 @@ class behat_transformations extends behat_base {
|
||||
return $tablenode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert #wwwroot# to the wwwroot config value, so it is
|
||||
* possible to reference fully qualified URLs within the site.
|
||||
*
|
||||
* @Transform /^((.*)#wwwroot#(.*))$/
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public function arg_insert_wwwroot(string $string): string {
|
||||
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.
|
||||
*
|
||||
@@ -176,4 +200,26 @@ class behat_transformations extends behat_base {
|
||||
return $time;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace #wwwroot# with the actual wwwroot config value.
|
||||
*
|
||||
* @param string $string String to attempt the replacement in.
|
||||
* @return string
|
||||
*/
|
||||
protected function replace_wwwroot(string $string): string {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user