source: moodle/trunk/fuentes/completion/tests/behat/behat_completion.php @ 1331

Last change on this file since 1331 was 1331, checked in by jrpelegrina, 3 years ago

Updated to moodle 3.0.3

File size: 6.7 KB
Line 
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 * Completion steps definitions.
19 *
20 * @package    core_completion
21 * @category   test
22 * @copyright  2013 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,
31    Behat\Behat\Context\Step\Then,
32    Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
33
34/**
35 * Steps definitions to deal with course and activities completion.
36 *
37 * @package    core_completion
38 * @category   test
39 * @copyright  2013 David Monllaó
40 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41 */
42class behat_completion extends behat_base {
43
44    /**
45     * Checks that the specified user has completed the specified activity of the current course.
46     *
47     * @Then /^"(?P<user_fullname_string>(?:[^"]|\\")*)" user has completed "(?P<activity_name_string>(?:[^"]|\\")*)" activity$/
48     * @param string $userfullname
49     * @param string $activityname
50     */
51    public function user_has_completed_activity($userfullname, $activityname) {
52
53        // Will throw an exception if the element can not be hovered.
54        $titleliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($userfullname . ", " . $activityname . ": Completed");
55        $xpath = "//table[@id='completion-progress']" .
56            "/descendant::img[contains(@title, $titleliteral)]";
57
58        return array(
59            new Given('I go to the current course activity completion report'),
60            new Then('"' . $this->escape($xpath) . '" "xpath_element" should exist')
61        );
62    }
63
64    /**
65     * Checks that the specified user has not completed the specified activity of the current course.
66     *
67     * @Then /^"(?P<user_fullname_string>(?:[^"]|\\")*)" user has not completed "(?P<activity_name_string>(?:[^"]|\\")*)" activity$/
68     * @param string $userfullname
69     * @param string $activityname
70     */
71    public function user_has_not_completed_activity($userfullname, $activityname) {
72
73        // Will throw an exception if the element can not be hovered.
74        $titleliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($userfullname . ", " . $activityname . ": Not completed");
75        $xpath = "//table[@id='completion-progress']" .
76            "/descendant::img[contains(@title, $titleliteral)]";
77        return array(
78            new Given('I go to the current course activity completion report'),
79            new Then('"' . $this->escape($xpath) . '" "xpath_element" should exist')
80        );
81
82        return $steps;
83    }
84
85    /**
86     * Goes to the current course activity completion report.
87     *
88     * @Given /^I go to the current course activity completion report$/
89     */
90    public function go_to_the_current_course_activity_completion_report() {
91
92        $steps = array();
93
94        // Expand reports node if we can't see the link.
95        try {
96            $this->find('xpath', "//div[@id='settingsnav']" .
97                "/descendant::li" .
98                "/descendant::li[not(contains(concat(' ', normalize-space(@class), ' '), ' collapsed '))]" .
99                "/descendant::p[contains(., '" . get_string('pluginname', 'report_progress') . "')]");
100        } catch (ElementNotFoundException $e) {
101            $steps[] = new Given('I expand "' . get_string('reports') . '" node');
102        }
103
104        $steps[] = new Given('I follow "' . get_string('pluginname', 'report_progress') . '"');
105
106        return $steps;
107    }
108
109    /**
110     * Toggles completion tracking for course being in the course page.
111     *
112     * @When /^completion tracking is "(?P<completion_status_string>Enabled|Disabled)" in current course$/
113     * @param string $completionstatus The status, enabled or disabled.
114     */
115    public function completion_is_toggled_in_course($completionstatus) {
116
117        $toggle = strtolower($completionstatus) == 'enabled' ? get_string('yes') : get_string('no');
118
119        return array(
120            new Given('I follow "'.get_string('editsettings').'"'),
121            new Given('I set the field "'.get_string('enablecompletion', 'completion').'" to "'.$toggle.'"'),
122            new Given('I press "'.get_string('savechangesanddisplay').'"')
123        );
124    }
125
126    /**
127     * Checks if the activity with specified name is maked as complete.
128     *
129     * @Given /^the "(?P<activityname_string>(?:[^"]|\\")*)" "(?P<activitytype_string>(?:[^"]|\\")*)" activity with "(manual|auto)" completion should be marked as complete$/
130     * @return array
131     */
132    public function activity_marked_as_complete($activityname, $activitytype, $completiontype) {
133        if ($completiontype == "manual") {
134            $imgalttext = get_string("completion-alt-manual-y", 'core_completion', $activityname);
135        } else {
136            $imgalttext = get_string("completion-alt-auto-y", 'core_completion', $activityname);
137        }
138        $csselementforactivitytype = "li.modtype_".strtolower($activitytype);
139
140        return new Given('"//img[contains(@alt, \''.$imgalttext.'\')]" "xpath_element" ' .
141            'should exist in the "'.$csselementforactivitytype.'" "css_element"');
142    }
143
144    /**
145     * Checks if the activity with specified name is maked as complete.
146     *
147     * @Given /^the "(?P<activityname_string>(?:[^"]|\\")*)" "(?P<activitytype_string>(?:[^"]|\\")*)" activity with "(manual|auto)" completion should be marked as not complete$/
148     * @return array
149     */
150    public function activity_marked_as_not_complete($activityname, $activitytype, $completiontype) {
151        if ($completiontype == "manual") {
152            $imgalttext = get_string("completion-alt-manual-n", 'core_completion', $activityname);
153        } else {
154            $imgalttext = get_string("completion-alt-auto-n", 'core_completion', $activityname);
155        }
156        $csselementforactivitytype = "li.modtype_".strtolower($activitytype);
157
158        return new Given('"//img[contains(@alt, \''.$imgalttext.'\')]" "xpath_element" ' .
159            'should exist in the "'.$csselementforactivitytype.'" "css_element"');
160    }
161}
Note: See TracBrowser for help on using the repository browser.