~ubuntu-branches/ubuntu/trusty/moodle/trusty-proposed

« back to all changes in this revision

Viewing changes to question/tests/behat/behat_question.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2013-09-09 15:22:35 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20130909152235-d9njbvgugzm380an
Tags: 2.5.2-1
* New upstream version: 2.5.2.
  - Incorporates S3 security patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
     */
52
52
    public function i_add_a_question_filling_the_form_with($questiontypename, TableNode $questiondata) {
53
53
 
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";
56
58
 
57
59
        return array(
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') . '"')
64
66
        );
65
67
    }
66
68
 
75
77
     */
76
78
    public function the_state_of_question_is_shown_as($questiondescription, $state) {
77
79
 
 
80
        // Using xpath literal to avoid quotes problems.
 
81
        $questiondescriptionliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($questiondescription);
 
82
        $stateliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($state);
 
83
 
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);
82
88
 
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);
87
93
    }
88
94