52
52
public function i_add_a_question_filling_the_form_with($questiontypename, TableNode $questiondata) {
54
$questiontypexpath = "//span[@class='qtypename'][.='" . $questiontypename . "']" .
54
// Using xpath literal to avoid quotes problems.
55
$questiontypename = $this->getSession()->getSelectorsHandler()->xpathLiteral($questiontypename);
56
$questiontypexpath = "//span[@class='qtypename'][normalize-space(.)=$questiontypename]" .
55
57
"/ancestor::div[@class='qtypeoption']/descendant::input";
58
60
new Given('I follow "' . get_string('questionbank', 'question') . '"'),
59
61
new Given('I press "' . get_string('createnewquestion', 'question') . '"'),
60
new Given('I click on "' . $questiontypexpath . '" "xpath_element"'),
62
new Given('I click on "' . $this->escape($questiontypexpath) . '" "xpath_element"'),
61
63
new Given('I click on "Next" "button" in the "#qtypechoicecontainer" "css_element"'),
62
64
new Given('I fill the moodle form with:', $questiondata),
63
new Given('I press "Save changes"')
65
new Given('I press "' . get_string('savechanges') . '"')
76
78
public function the_state_of_question_is_shown_as($questiondescription, $state) {
80
// Using xpath literal to avoid quotes problems.
81
$questiondescriptionliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($questiondescription);
82
$stateliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($state);
78
84
// Split in two checkings to give more feedback in case of exception.
79
85
$exception = new ElementNotFoundException($this->getSession(), 'Question "' . $questiondescription . '" ');
80
$questionxpath = "//div[contains(concat(' ', @class, ' '), ' qtext ')][contains(., '" . $questiondescription . "')]";
86
$questionxpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' qtext ')][contains(., $questiondescriptionliteral)]";
81
87
$this->find('xpath', $questionxpath, $exception);
83
89
$exception = new ExpectationException('Question "' . $questiondescription . '" state is not "' . $state . '"', $this->getSession());
84
$xpath = $questionxpath . "/ancestor::div[contains(concat(' ', @class, ' '), ' que ')]" .
85
"/descendant::div[@class='state'][contains(., '" . $state . "')]";
90
$xpath = $questionxpath . "/ancestor::div[contains(concat(' ', normalize-space(@class), ' '), ' que ')]" .
91
"/descendant::div[@class='state'][contains(., $stateliteral)]";
86
92
$this->find('xpath', $xpath, $exception);