Proyectos de Subversion Moodle

Rev

Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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 calendar-related steps definitions.
19
 *
20
 * @package    core_calendar
21
 * @category   test
22
 * @copyright  2013 Mark Nelson <markn@moodle.com>
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
// NOTE: no MOODLE_INTERNAL used, this file may be required by behat before including /config.php.
27
require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
28
 
29
use Behat\Gherkin\Node\TableNode as TableNode;
30
 
31
/**
32
 * Contains functions used by behat to test functionality.
33
 *
34
 * @package    core_calendar
35
 * @category   test
36
 * @copyright  2013 Mark Nelson <markn@moodle.com>
37
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
39
class behat_calendar extends behat_base {
40
 
41
    /**
42
     * Return the list of partial named selectors.
43
     *
44
     * @return array
45
     */
46
    public static function get_partial_named_selectors(): array {
47
        return [
48
            new behat_component_named_selector('mini calendar block', [".//*[@data-block='calendar_month']"]),
49
            new behat_component_named_selector('full calendar page', [".//*[@id='page-calendar-view']"]),
50
            new behat_component_named_selector('calendar day', [".//*[@data-region='day'][@data-day=%locator%]"]),
51
            new behat_component_named_selector(
52
                'responsive calendar day',
53
                [".//*[@data-region='day'][@data-day=%locator%]/div[contains(@class, 'hidden-desktop')]"]
54
            ),
55
        ];
56
    }
57
 
58
    /**
59
     * Create event when starting on the front page.
60
     *
61
     * @Given /^I create a calendar event with form data:$/
62
     * @param TableNode $data
63
     */
64
    public function i_create_a_calendar_event_with_form_data($data) {
65
        // Go to current month page.
66
        $this->execute("behat_general::click_link", get_string('fullcalendar', 'calendar'));
67
 
68
        // Create event.
69
        $this->i_create_a_calendar_event($data);
70
    }
71
 
72
    /**
73
     * Create event.
74
     *
75
     * @Given /^I create a calendar event:$/
76
     * @param TableNode $data
77
     */
78
    public function i_create_a_calendar_event($data) {
79
        // Get the event name.
80
        $eventname = $data->getRow(1);
81
        $eventname = $eventname[1];
82
 
83
        $this->execute("behat_general::wait_until_the_page_is_ready");
84
 
85
        if ($this->running_javascript()) {
86
            // Click to create new event.
87
            $this->execute("behat_general::i_click_on", array(get_string('newevent', 'calendar'), "button"));
88
 
89
            // Set form fields.
90
            $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
91
 
92
            // Save event.
93
            $this->execute("behat_forms::press_button", get_string('save'));
94
        }
95
    }
96
 
97
    /**
98
     * Hover over a specific day in the mini-calendar.
99
     *
100
     * @Given /^I hover over day "(?P<dayofmonth>\d+)" of this month in the mini-calendar block(?P<responsive> responsive view|)$/
101
     * @param int $day The day of the current month
102
     * @param string $responsive If not null, find the responsive version of the link.
103
     */
104
    public function i_hover_over_day_of_this_month_in_mini_calendar_block(int $day, string $responsive = ''): void {
105
        $this->execute(
106
            "behat_general::i_hover_in_the",
107
            [
108
                $day,
109
                empty($responsive) ? 'core_calendar > calendar day' : 'core_calendar > responsive calendar day',
110
                '',
111
                'core_calendar > mini calendar block',
112
            ],
113
        );
114
    }
115
 
116
    /**
117
     * Hover over a specific day in the full calendar page.
118
     *
119
     * @Given /^I hover over day "(?P<dayofmonth>\d+)" of this month in the full calendar page(?P<responsive> responsive view|)$/
120
     * @param int $day The day of the current month
121
     * @param string $responsive If not empty, use the repsonsive view.
122
     */
123
    public function i_hover_over_day_of_this_month_in_full_calendar_page(int $day, string $responsive = ''): void {
124
        $this->execute(
125
            "behat_general::i_hover_in_the",
126
            [
127
                $day,
128
                empty($responsive) ? 'core_calendar > calendar day' : 'core_calendar > responsive calendar day',
129
                '',
130
                'core_calendar > full calendar page',
131
            ],
132
        );
133
    }
134
 
135
    /**
136
     * Hover over today in the mini-calendar.
137
     *
138
     * @Given /^I hover over today in the mini-calendar block( responsive view|)$/
139
     *
140
     * @param string $responsive If not empty, use the responsive calendar link.
141
     */
142
    public function i_hover_over_today_in_mini_calendar_block(string $responsive = ''): void {
143
        $todaysday = date('j');
144
        $this->i_hover_over_day_of_this_month_in_mini_calendar_block($todaysday, $responsive);
145
    }
146
 
147
    /**
148
     * Navigate to a specific month in the calendar.
149
     *
150
     * @Given /^I view the calendar for "(?P<month>\d+)" "(?P<year>\d+)"$/
151
     * @param int $month the month selected as a number
152
     * @param int $year the four digit year
153
     */
154
    public function i_view_the_calendar_for($month, $year) {
155
        $this->view_the_calendar('month', 1, $month, $year);
156
    }
157
 
158
    /**
159
     * Navigate to a specific date in the calendar.
160
     *
161
     * @Given /^I view the calendar for "(?P<day>\d+)" "(?P<month>\d+)" "(?P<year>\d+)"$/
162
     * @param int $day the day selected as a number
163
     * @param int $month the month selected as a number
164
     * @param int $year the four digit year
165
     */
166
    public function i_view_the_calendar_day_view(int $day, int $month, int $year) {
167
        $this->view_the_calendar('day', $day, $month, $year);
168
    }
169
 
170
    /**
171
     * View the correct calendar view with specific day
172
     *
173
     * @param string $type type of calendar view: month or day
174
     * @param int $day the day selected as a number
175
     * @param int $month the month selected as a number
176
     * @param int $year the four digit year
177
     */
178
    private function view_the_calendar(string $type, int $day, int $month, int $year) {
179
        $time = make_timestamp($year, $month, $day);
180
        $this->execute('behat_general::i_visit', ['/calendar/view.php?view=' . $type . '&course=1&time=' . $time]);
181
    }
182
 
183
    /**
184
     * Navigate to site calendar.
185
     *
186
     * @Given /^I am viewing site calendar$/
187
     * @throws coding_exception
188
     * @return void
189
     */
190
    public function i_am_viewing_site_calendar() {
191
        $this->i_am_viewing_calendar_in_view('month');
192
    }
193
 
194
    /**
195
     * Navigate to a specific view in the calendar.
196
     *
197
     * @Given /^I am viewing calendar in "([^"]+)" view$/
198
     * @param string $view The calendar view ('month', 'day' and 'upcoming') to navigate to.
199
     * @return void
200
     */
201
    public function i_am_viewing_calendar_in_view(string $view): void {
202
 
203
        if (!in_array($view, ['month', 'day', 'upcoming'])) {
204
            throw new Exception("Invalid calendar view. Allowed values are: 'month', 'day' and 'upcoming'");
205
        }
206
 
207
        $url = new moodle_url('/calendar/view.php', ['view' => $view]);
208
        $this->execute('behat_general::i_visit', [$url]);
209
    }
210
}