2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Completion steps definitions.
20 * @package core_completion
22 * @copyright 2013 David MonllaĆ³
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
28 require_once(__DIR__
. '/../../../lib/behat/behat_base.php');
30 use Behat\Behat\Context\Step\Given
as Given
,
31 Behat\Mink\Exception\ElementNotFoundException
as ElementNotFoundException
;
34 * Steps definitions to deal with course and activities completion.
36 * @package core_completion
38 * @copyright 2013 David MonllaĆ³
39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41 class behat_completion
extends behat_base
{
44 * Checks that the specified user has completed the specified activity of the current course.
46 * @Then /^"(?P<user_fullname_string>(?:[^"]|\\")*)" user has completed "(?P<activity_name_string>(?:[^"]|\\")*)" activity$/
47 * @param string $userfullname
48 * @param string $activityname
50 public function user_has_completed_activity($userfullname, $activityname) {
52 // Will throw an exception if the element can not be hovered.
53 $xpath = "//table[@id='completion-progress']" .
54 "/descendant::img[contains(@title, '" . $userfullname . ", " . $activityname . ": Completed')]";
57 new Given('I go to the current course activity completion report'),
58 new Given('I hover "' . $xpath . '" "xpath_element"')
63 * Checks that the specified user has not completed the specified activity of the current course.
65 * @Then /^"(?P<user_fullname_string>(?:[^"]|\\")*)" user has not completed "(?P<activity_name_string>(?:[^"]|\\")*)" activity$/
66 * @param string $userfullname
67 * @param string $activityname
69 public function user_has_not_completed_activity($userfullname, $activityname) {
71 $xpath = "//table[@id='completion-progress']" .
72 "/descendant::img[contains(@title, '" . $userfullname . ", " . $activityname . ": Not completed')]";
74 new Given('I go to the current course activity completion report'),
75 new Given('I hover "' . $xpath . '" "xpath_element"')
82 * Goes to the current course activity completion report.
84 * @Given /^I go to the current course activity completion report$/
86 public function go_to_the_current_course_activity_completion_report() {
90 // Expand reports node if we can't see the link.
92 $this->find('xpath', "//*[@id='settingsnav']" .
94 "/descendant::li[not(contains(@class,'collapsed'))]" .
95 "/descendant::p[contains(., 'Activity completion')]");
96 } catch (ElementNotFoundException
$e) {
97 $steps[] = new Given('I expand "Reports" node');
100 $steps[] = new Given('I follow "Activity completion"');