weekly release 2.5dev
[moodle.git] / course / tests / behat / behat_course.php
CommitLineData
a1990e50
DM
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 * Behat course-related steps definitions.
19 *
20 * @package core_course
21 * @category test
22 * @copyright 2012 David MonllaĆ³
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__ . '/../../../lib/behat/behat_base.php');
29
30use Behat\Behat\Context\Step\Given as Given,
31 Behat\Gherkin\Node\TableNode as TableNode;
32
33/**
34 * Course-related steps definitions.
35 *
36 * @package core_course
37 * @category test
38 * @copyright 2012 David MonllaĆ³
39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 */
41class behat_course extends behat_base {
42
43 /**
44 * Turns editing mode on.
45 * @Given /^I turn editing mode on$/
46 */
47 public function i_turn_editing_mode_on() {
48 return new Given('I press "Turn editing on"');
49 }
50
51 /**
52 * Turns editing mode off.
53 * @Given /^I turn editing mode off$/
54 */
55 public function i_turn_editing_mode_off() {
56 return new Given('I press "Turn editing off"');
57 }
58
59 /**
60 * Adds the selected activity/resource filling the form data with the specified field/value pairs.
61 *
62 * @When /^I add a "(?P<activity_or_resource_string>(?:[^"]|\\")*)" to section "(?P<section_number>\d+)" and I fill the form with:$/
63 * @param string $activity The activity name
64 * @param string $section The section number
65 * @param TableNode $data The activity field/value data
66 */
67 public function i_add_to_section_and_i_fill_the_form_with($activity, $section, TableNode $data) {
68
a1990e50
DM
69 return array(
70 new Given('I add a "'.$activity.'" to section "'.$section.'"'),
71 new Given('I fill the moodle form with:', $data),
72 new Given('I press "Save and return to course"')
73 );
74 }
75
76 /**
77 * Opens the activity chooser and opens the activity/resource form page.
78 *
79 * @Given /^I add a "(?P<activity_or_resource_string>(?:[^"]|\\")*)" to section "(?P<section_number>\d+)"$/
1f9ffbdb 80 * @throws ElementNotFoundException Thrown by behat_base::find
a1990e50
DM
81 * @param string $activity
82 * @param string $section
83 */
84 public function i_add_to_section($activity, $section) {
85
a1990e50 86 // Clicks add activity or resource section link.
1f9ffbdb
DM
87 $sectionxpath = "//*[@id='section-" . $section . "']/*/*/*/div[@class='section-modchooser']/span/a";
88 $sectionnode = $this->find('xpath', $sectionxpath);
89 $sectionnode->click();
a1990e50
DM
90
91 // Clicks the selected activity if it exists.
92 $activityxpath = ".//label[contains(.,'" . $activity . "')]/input";
1f9ffbdb
DM
93 $activitynode = $this->find('xpath', $activityxpath);
94 $activitynode->doubleClick();
a1990e50
DM
95 }
96
97}