2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Steps definitions related to mod_quiz overrides.
20 * @package theme_bootstrapbase
22 * @copyright 2016 Damyon Wiese
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
28 require_once(__DIR__ . '/../../../../mod/quiz/tests/behat/behat_mod_quiz.php');
30 use Behat\Gherkin\Node\TableNode as TableNode;
32 use Behat\Mink\Exception\ExpectationException as ExpectationException;
35 * Steps definitions related to mod_quiz overrides.
37 * @package theme_bootstrapbase
39 * @copyright 2016 Damyon Wiese
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42 class behat_theme_bootstrapbase_behat_mod_quiz extends behat_mod_quiz {
44 public function i_add_question_to_the_quiz_with($questiontype, $quizname, TableNode $questiondata) {
45 $quizname = $this->escape($quizname);
46 $editquiz = $this->escape(get_string('editquiz', 'quiz'));
47 $quizadmin = $this->escape(get_string('pluginadministration', 'quiz'));
48 $addaquestion = $this->escape(get_string('addaquestion', 'quiz'));
49 $menuxpath = "//div[contains(@class, ' page-add-actions ')][last()]//a[contains(@class, ' textmenu')]";
50 $itemxpath = "//div[contains(@class, ' page-add-actions ')][last()]//a[contains(@class, ' addquestion ')]";
52 $this->execute('behat_general::click_link', $quizname);
54 $this->execute("behat_navigation::i_navigate_to_in_current_page_administration", $editquiz);
56 $this->execute("behat_general::i_click_on", array($menuxpath, "xpath_element"));
57 $this->execute("behat_general::i_click_on", array($itemxpath, "xpath_element"));
59 $this->finish_adding_question($questiontype, $questiondata);
62 public function i_should_see_question_in_section_in_the_quiz_navigation($questionnumber, $sectionheading) {
64 // Using xpath literal to avoid quotes problems.
65 $questionnumberliteral = behat_context_helper::escape('Question ' . $questionnumber);
66 $headingliteral = behat_context_helper::escape($sectionheading);
68 // Split in two checkings to give more feedback in case of exception.
69 $exception = new ExpectationException('Question "' . $questionnumber . '" is not in section "' .
70 $sectionheading . '" in the quiz navigation.', $this->getSession());
71 $xpath = "//div[@id = 'mod_quiz_navblock']//*[contains(concat(' ', normalize-space(@class), ' '), ' qnbutton ') and " .
72 "contains(., {$questionnumberliteral}) and contains(preceding-sibling::h3[1], {$headingliteral})]";
73 $this->find('xpath', $xpath);
76 public function i_open_the_add_to_quiz_menu_for($pageorlast) {
78 if (!$this->running_javascript()) {
79 throw new DriverException('Activities actions menu not available when Javascript is disabled');
82 if ($pageorlast == 'last') {
83 $xpath = "//div[@class = 'last-add-menu']//a[contains(@class, 'textmenu') and contains(., 'Add')]";
84 } else if (preg_match('~Page (\d+)~', $pageorlast, $matches)) {
85 $xpath = "//li[@id = 'page-{$matches[1]}']//a[contains(@class, 'textmenu') and contains(., 'Add')]";
87 throw new ExpectationException("The I open the add to quiz menu step must specify either 'Page N' or 'last'.");
89 $this->find('xpath', $xpath)->click();