mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-78619 behat: Add wwwroot transformation
This will replace #wwwroot# with the value of the wwwroot config. This is useful where a FQDN within the test instance is required.
This commit is contained in:
parent
9bfcd77d51
commit
cdf17eb7d5
@ -107,6 +107,7 @@ class behat_transformations extends behat_base {
|
||||
* @return TableNode The transformed table
|
||||
*/
|
||||
public function tablenode_transformations(TableNode $tablenode) {
|
||||
global $CFG;
|
||||
// Walk through all values including the optional headers.
|
||||
$rows = $tablenode->getRows();
|
||||
foreach ($rows as $rowkey => $row) {
|
||||
@ -123,6 +124,11 @@ class behat_transformations extends behat_base {
|
||||
$rows[$rowkey][$colkey] = $this->get_transformed_timestamp($match[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// Transform wwwroot.
|
||||
if (preg_match('/#wwwroot#/', $rows[$rowkey][$colkey])) {
|
||||
$rows[$rowkey][$colkey] = $this->replace_wwwroot($rows[$rowkey][$colkey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,6 +139,18 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces $NASTYSTRING vars for a nasty string.
|
||||
*
|
||||
@ -176,4 +194,15 @@ 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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user