Skip to content

Commit b6b8433

Browse files
committed
iss1757 - Fix Behat for Moodle 5.0
1 parent 8e660d2 commit b6b8433

2 files changed

Lines changed: 8 additions & 31 deletions

File tree

tests/behat/behat_qtype_stack.php

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -170,41 +170,18 @@ public function i_check_element_value($id, $value) {
170170
}
171171
}
172172

173-
/**
174-
* Check an iframe element value contains a substring
175-
*
176-
* @param string $id id of element
177-
* @param string $value the expected substring
178-
*
179-
* @Given /^I check the value of iframe element "(?P<id>[^"]*)" contains '(?P<value>[^']*)'$/
180-
*/
181-
public function i_check_element_value_contains($id, $value) {
182-
$generalcontext = behat_context_helper::get('behat_general');
183-
$generalcontext->switch_to_iframe('stack-iframe-1');
184-
$js = <<<EOF
185-
return (function() {
186-
let el = document.getElementById("$id");
187-
return el ? el.textContent : null;
188-
})();
189-
EOF;
190-
$formvalue = $this->evaluate_script($js);
191-
$this->getSession()->switchToWindow();
192-
$formvalue = str_replace(["\r\n", "\r", "\n"], '\n', $formvalue);
193-
if (strpos($formvalue, $value) === false) {
194-
throw new \Exception("Expected element value to contain '$value' but got '$formvalue'.");
195-
}
196-
}
197173

198174
/**
199-
* Check an iframe element value contains one of two substrings.
175+
* Check an iframe element value contains one of three substrings.
200176
*
201177
* @param string $id id of element
202178
* @param string $value1 first expected substring
203179
* @param string $value2 second expected substring
180+
* @param string $value3 third expected substring
204181
*
205-
* @Given /^I check the value of iframe element "(?P<id>[^"]*)" contains either '(?P<value1>[^']*)' or '(?P<value2>[^']*)'$/
182+
* @Given /^I check the value of iframe element "(?P<id>[^"]*)" contains one of '(?P<value1>[^']*)' or '(?P<value2>[^']*)' or '(?P<value3>[^']*)'$/
206183
*/
207-
public function i_check_element_value_contains_either($id, $value1, $value2) {
184+
public function i_check_element_value_contains_one_of($id, $value1, $value2, $value3) {
208185
$generalcontext = behat_context_helper::get('behat_general');
209186
$generalcontext->switch_to_iframe('stack-iframe-1');
210187
$js = <<<EOF
@@ -216,8 +193,8 @@ public function i_check_element_value_contains_either($id, $value1, $value2) {
216193
$formvalue = $this->evaluate_script($js);
217194
$this->getSession()->switchToWindow();
218195
$formvalue = str_replace(["\r\n", "\r", "\n"], '\n', $formvalue);
219-
if (strpos($formvalue, $value1) === false && strpos($formvalue, $value2) === false) {
220-
throw new \Exception("Expected element value to contain either '$value1' or '$value2' but got '$formvalue'.");
196+
if (strpos($formvalue, $value1) === false && strpos($formvalue, $value2) === false && strpos($formvalue, $value3) === false) {
197+
throw new \Exception("Expected element value to contain one of '$value1', '$value2' or '$value3' but got '$formvalue'.");
221198
}
222199
}
223200

tests/behat/freetext.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ Feature: Test input of correct answers on freetext inputs.
4040
And I check the input "ans3" is 'f(x) = 4sqrt(2x^2+1)+1'
4141
And I check the input "ans4" is 'f(0) = 5 => c = 1'
4242
And I check the input "ans5" is '{"matches":["f(x) = 4sqrt(2x^2+1)+c","f(x) = 4sqrt(2x^2+1)+1"]}'
43-
# MathJax 3 will have rendered, MathJax 2 probably won't.
44-
And I check the value of iframe element "asciiContainerRow" contains either '\begin{align*}\n& & \displaystyle{f{{\left({x}\right)}}}&={4}\sqrt{{{2}{x}^{{2}}+{1}}}+{c}\\\n& & \displaystyle{f{{\left({0}\right)}}}&={5}\Rightarrow{c}={1}\\\n& & \displaystyle{f{{\left({x}\right)}}}&={4}\sqrt{{{2}{x}^{{2}}+{1}}}+{1}\\\n\end{align*}\n' or '𝑓⁡(𝑥)=4⁢√2⁢𝑥2+1+1'
43+
# MathJax 3 will have rendered, MathJax 2 probably won't. Moodle 5 gives us the flattened plain text. Sigh...
44+
And I check the value of iframe element "asciiContainerRow" contains one of '\begin{align*}\n& & \displaystyle{f{{\left({x}\right)}}}&={4}\sqrt{{{2}{x}^{{2}}+{1}}}+{c}\\\n& & \displaystyle{f{{\left({0}\right)}}}&={5}\Rightarrow{c}={1}\\\n& & \displaystyle{f{{\left({x}\right)}}}&={4}\sqrt{{{2}{x}^{{2}}+{1}}}+{1}\\\n\end{align*}\n' or '𝑓⁡(𝑥)=4⁢√2⁢𝑥2+1+1' or 'f(x)=42x2+1+1'

0 commit comments

Comments
 (0)