Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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(
11 efrain 52
                'calendar day detail',
53
                [".//*[@data-region='day'][@data-day=%locator%]//a[@data-action='view-day-link']"]
54
            ),
55
            new behat_component_named_selector(
1 efrain 56
                'responsive calendar day',
57
                [".//*[@data-region='day'][@data-day=%locator%]/div[contains(@class, 'hidden-desktop')]"]
58
            ),
11 efrain 59
            new behat_component_named_selector(
60
                'responsive calendar day detail',
61
                [".//*[@data-region='day'][@data-day=%locator%]" .
62
                    "/div[contains(@class, 'hidden-desktop')]//a[@data-action='view-day-link']"]
63
            ),
1 efrain 64
        ];
65
    }
66
 
67
    /**
68
     * Create event when starting on the front page.
69
     *
70
     * @Given /^I create a calendar event with form data:$/
71
     * @param TableNode $data
72
     */
73
    public function i_create_a_calendar_event_with_form_data($data) {
74
        // Go to current month page.
75
        $this->execute("behat_general::click_link", get_string('fullcalendar', 'calendar'));
76
 
77
        // Create event.
78
        $this->i_create_a_calendar_event($data);
79
    }
80
 
81
    /**
82
     * Create event.
83
     *
84
     * @Given /^I create a calendar event:$/
85
     * @param TableNode $data
86
     */
87
    public function i_create_a_calendar_event($data) {
88
        // Get the event name.
89
        $eventname = $data->getRow(1);
90
        $eventname = $eventname[1];
91
 
92
        $this->execute("behat_general::wait_until_the_page_is_ready");
93
 
94
        if ($this->running_javascript()) {
95
            // Click to create new event.
96
            $this->execute("behat_general::i_click_on", array(get_string('newevent', 'calendar'), "button"));
97
 
98
            // Set form fields.
99
            $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
100
 
101
            // Save event.
102
            $this->execute("behat_forms::press_button", get_string('save'));
103
        }
104
    }
105
 
106
    /**
107
     * Hover over a specific day in the mini-calendar.
108
     *
109
     * @Given /^I hover over day "(?P<dayofmonth>\d+)" of this month in the mini-calendar block(?P<responsive> responsive view|)$/
110
     * @param int $day The day of the current month
111
     * @param string $responsive If not null, find the responsive version of the link.
112
     */
113
    public function i_hover_over_day_of_this_month_in_mini_calendar_block(int $day, string $responsive = ''): void {
114
        $this->execute(
115
            "behat_general::i_hover_in_the",
116
            [
117
                $day,
118
                empty($responsive) ? 'core_calendar > calendar day' : 'core_calendar > responsive calendar day',
119
                '',
120
                'core_calendar > mini calendar block',
121
            ],
122
        );
123
    }
124
 
125
    /**
126
     * Hover over a specific day in the full calendar page.
127
     *
128
     * @Given /^I hover over day "(?P<dayofmonth>\d+)" of this month in the full calendar page(?P<responsive> responsive view|)$/
129
     * @param int $day The day of the current month
130
     * @param string $responsive If not empty, use the repsonsive view.
131
     */
132
    public function i_hover_over_day_of_this_month_in_full_calendar_page(int $day, string $responsive = ''): void {
133
        $this->execute(
134
            "behat_general::i_hover_in_the",
135
            [
136
                $day,
137
                empty($responsive) ? 'core_calendar > calendar day' : 'core_calendar > responsive calendar day',
138
                '',
139
                'core_calendar > full calendar page',
140
            ],
141
        );
142
    }
143
 
144
    /**
11 efrain 145
     * Click on a specific day in the mini-calendar.
146
     *
147
     * @Given /^I click on day "(?P<dayofmonth>\d+)" of this month in the mini-calendar block(?P<responsive> responsive view|)$/
148
     *
149
     * @param int $day The day of the current month.
150
     * @param string $responsive If not null, find the responsive version of the link.
151
     * @param string $detail If not null, find the detail version of the link.
152
     */
153
    public function i_click_on_day_of_this_month_in_mini_calendar_block(
154
        int $day,
155
        string $responsive = '',
156
        string $detail = '',
157
    ): void {
158
        $selectortype = 'core_calendar >';
159
        if (!empty($responsive)) {
160
            $selectortype .= ' responsive';
161
        }
162
        $selectortype .= ' calendar day';
163
        if (!empty($detail)) {
164
            $selectortype .= ' detail';
165
        }
166
        $this->execute(
167
            contextapi: "behat_general::i_click_on_in_the",
168
            params: [
169
                $day,
170
                $selectortype,
171
                '',
172
                'core_calendar > mini calendar block',
173
            ],
174
        );
175
    }
176
 
177
    /**
1 efrain 178
     * Hover over today in the mini-calendar.
179
     *
180
     * @Given /^I hover over today in the mini-calendar block( responsive view|)$/
181
     *
182
     * @param string $responsive If not empty, use the responsive calendar link.
183
     */
184
    public function i_hover_over_today_in_mini_calendar_block(string $responsive = ''): void {
185
        $todaysday = date('j');
186
        $this->i_hover_over_day_of_this_month_in_mini_calendar_block($todaysday, $responsive);
187
    }
188
 
189
    /**
11 efrain 190
     * Click on today in the mini-calendar.
191
     *
192
     * @Given /^I click on today in the mini-calendar block( responsive view|)( to view the detail|)$/
193
     *
194
     * @param string $responsive If not empty, use the responsive calendar link.
195
     * @param string $detail If not empty, use the detail view calendar link.
196
     */
197
    public function i_click_on_today_in_mini_calendar_block(string $responsive = '', string $detail = ''): void {
198
        $this->i_click_on_day_of_this_month_in_mini_calendar_block(
199
            day: date('j'),
200
            responsive: $responsive,
201
            detail: $detail,
202
        );
203
    }
204
 
205
    /**
1 efrain 206
     * Navigate to a specific month in the calendar.
207
     *
208
     * @Given /^I view the calendar for "(?P<month>\d+)" "(?P<year>\d+)"$/
209
     * @param int $month the month selected as a number
210
     * @param int $year the four digit year
211
     */
212
    public function i_view_the_calendar_for($month, $year) {
213
        $this->view_the_calendar('month', 1, $month, $year);
214
    }
215
 
216
    /**
217
     * Navigate to a specific date in the calendar.
218
     *
219
     * @Given /^I view the calendar for "(?P<day>\d+)" "(?P<month>\d+)" "(?P<year>\d+)"$/
220
     * @param int $day the day selected as a number
221
     * @param int $month the month selected as a number
222
     * @param int $year the four digit year
223
     */
224
    public function i_view_the_calendar_day_view(int $day, int $month, int $year) {
225
        $this->view_the_calendar('day', $day, $month, $year);
226
    }
227
 
228
    /**
229
     * View the correct calendar view with specific day
230
     *
231
     * @param string $type type of calendar view: month or day
232
     * @param int $day the day selected as a number
233
     * @param int $month the month selected as a number
234
     * @param int $year the four digit year
235
     */
236
    private function view_the_calendar(string $type, int $day, int $month, int $year) {
237
        $time = make_timestamp($year, $month, $day);
238
        $this->execute('behat_general::i_visit', ['/calendar/view.php?view=' . $type . '&course=1&time=' . $time]);
239
    }
240
 
241
    /**
242
     * Navigate to site calendar.
243
     *
244
     * @Given /^I am viewing site calendar$/
245
     * @throws coding_exception
246
     * @return void
247
     */
248
    public function i_am_viewing_site_calendar() {
249
        $this->i_am_viewing_calendar_in_view('month');
250
    }
251
 
252
    /**
253
     * Navigate to a specific view in the calendar.
254
     *
255
     * @Given /^I am viewing calendar in "([^"]+)" view$/
256
     * @param string $view The calendar view ('month', 'day' and 'upcoming') to navigate to.
257
     * @return void
258
     */
259
    public function i_am_viewing_calendar_in_view(string $view): void {
260
 
261
        if (!in_array($view, ['month', 'day', 'upcoming'])) {
262
            throw new Exception("Invalid calendar view. Allowed values are: 'month', 'day' and 'upcoming'");
263
        }
264
 
265
        $url = new moodle_url('/calendar/view.php', ['view' => $view]);
266
        $this->execute('behat_general::i_visit', [$url]);
267
    }
268
}