MDL-37661 behat: Add activities to courses
[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
69 $activity = $this->fixStepArgument($activity);
70 $section = $this->fixStepArgument($section);
71
72 // The 'I wait until the page is ready' is just in case.
73 return array(
74 new Given('I add a "'.$activity.'" to section "'.$section.'"'),
75 new Given('I fill the moodle form with:', $data),
76 new Given('I press "Save and return to course"')
77 );
78 }
79
80 /**
81 * Opens the activity chooser and opens the activity/resource form page.
82 *
83 * @Given /^I add a "(?P<activity_or_resource_string>(?:[^"]|\\")*)" to section "(?P<section_number>\d+)"$/
84 * @param string $activity
85 * @param string $section
86 */
87 public function i_add_to_section($activity, $section) {
88
89 $activity = $this->fixStepArgument($activity);
90 $section = $this->fixStepArgument($section);
91
92 // Clicks add activity or resource section link.
93 $sectionxpath = "//*[@id='section-" . $section . "']/*/*/*/div[@class='section-modchooser']/*/*";
94 $section = $this->getSession()->getPage()->find('xpath', $sectionxpath);
95 $section->click();
96
97 // Clicks the selected activity if it exists.
98 $activityxpath = ".//label[contains(.,'" . $activity . "')]/input";
99 $activity = $this->getSession()->getPage()->find('xpath', $activityxpath);
100 $activity->doubleClick();
101 }
102
103}