diff --git a/lib/tests/behat/behat_transformations.php b/lib/tests/behat/behat_transformations.php index cd5c4a41221..bbd80ad44d3 100644 --- a/lib/tests/behat/behat_transformations.php +++ b/lib/tests/behat/behat_transformations.php @@ -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); + } }