MDL-58428 theme: Shift templates ready for Bootstrapbase removal
[moodle.git] / theme / bootstrapbase / tests / behat / behat_theme_bootstrapbase_behat_mod_quiz.php
CommitLineData
63e4df60
DW
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
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.
8//
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.
13//
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/>.
16
17/**
18 * Steps definitions related to mod_quiz overrides.
19 *
e3652936
MM
20 * @package theme_bootstrapbase
21 * @category test
63e4df60
DW
22 * @copyright 2016 Damyon Wiese
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
27
28require_once(__DIR__ . '/../../../../mod/quiz/tests/behat/behat_mod_quiz.php');
29
30use Behat\Gherkin\Node\TableNode as TableNode;
31
32use Behat\Mink\Exception\ExpectationException as ExpectationException;
33
34/**
35 * Steps definitions related to mod_quiz overrides.
36 *
e3652936
MM
37 * @package theme_bootstrapbase
38 * @category test
63e4df60
DW
39 * @copyright 2016 Damyon Wiese
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41 */
e3652936 42class behat_theme_bootstrapbase_behat_mod_quiz extends behat_mod_quiz {
63e4df60
DW
43
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'));
e3652936
MM
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 ')]";
63e4df60
DW
51
52 $this->execute('behat_general::click_link', $quizname);
53
e3652936 54 $this->execute("behat_navigation::i_navigate_to_in_current_page_administration", $editquiz);
63e4df60 55
e3652936
MM
56 $this->execute("behat_general::i_click_on", array($menuxpath, "xpath_element"));
57 $this->execute("behat_general::i_click_on", array($itemxpath, "xpath_element"));
63e4df60
DW
58
59 $this->finish_adding_question($questiontype, $questiondata);
60 }
61
62 public function i_should_see_question_in_section_in_the_quiz_navigation($questionnumber, $sectionheading) {
63
64 // Using xpath literal to avoid quotes problems.
65 $questionnumberliteral = behat_context_helper::escape('Question ' . $questionnumber);
66 $headingliteral = behat_context_helper::escape($sectionheading);
67
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());
e3652936 71 $xpath = "//div[@id = 'mod_quiz_navblock']//*[contains(concat(' ', normalize-space(@class), ' '), ' qnbutton ') and " .
63e4df60
DW
72 "contains(., {$questionnumberliteral}) and contains(preceding-sibling::h3[1], {$headingliteral})]";
73 $this->find('xpath', $xpath);
74 }
75
76 public function i_open_the_add_to_quiz_menu_for($pageorlast) {
77
78 if (!$this->running_javascript()) {
79 throw new DriverException('Activities actions menu not available when Javascript is disabled');
80 }
81
82 if ($pageorlast == 'last') {
e3652936 83 $xpath = "//div[@class = 'last-add-menu']//a[contains(@class, 'textmenu') and contains(., 'Add')]";
63e4df60 84 } else if (preg_match('~Page (\d+)~', $pageorlast, $matches)) {
e3652936 85 $xpath = "//li[@id = 'page-{$matches[1]}']//a[contains(@class, 'textmenu') and contains(., 'Add')]";
63e4df60
DW
86 } else {
87 throw new ExpectationException("The I open the add to quiz menu step must specify either 'Page N' or 'last'.");
88 }
89 $this->find('xpath', $xpath)->click();
90 }
91}