MDL-65056 completion: Hide checkboxes on course page for teachers

This commit is contained in:
Alexander Bias 2019-03-27 21:18:42 +01:00
parent 019004dcc7
commit d6cea5ccd9
5 changed files with 174 additions and 29 deletions

View file

@ -152,4 +152,72 @@ class behat_completion extends behat_base {
array($imgalttext, "icon", $activityxpath, "xpath_element")
);
}
/**
* Checks if the activity with specified name shows a information completion checkbox (i.e. showing the completion tracking
* configuration).
*
* @Given /^the "(?P<activityname_string>(?:[^"]|\\")*)" "(?P<activitytype_string>(?:[^"]|\\")*)" activity with "(manual|auto)" completion shows a configuration completion checkbox/
* @param string $activityname The activity name.
* @param string $activitytype The activity type.
* @param string $completiontype The completion type.
*/
public function activity_has_configuration_completion_checkbox($activityname, $activitytype, $completiontype) {
if ($completiontype == "manual") {
$imgname = 'i/completion-manual-enabled';
} else {
$imgname = 'i/completion-auto-enabled';
}
$iconxpath = "//li[contains(concat(' ', @class, ' '), ' modtype_" . strtolower($activitytype) . " ')]";
$iconxpath .= "[descendant::*[contains(text(), '" . $activityname . "')]]";
$iconxpath .= "/descendant::span[@class='actions']/descendant::img[contains(@src, 'i/completion-')]";
$this->execute("behat_general::the_attribute_of_should_contain",
array("src", $iconxpath, "xpath_element", $imgname)
);
}
/**
* Checks if the activity with specified name shows a tracking completion checkbox (i.e. showing my completion tracking status)
*
* @Given /^the "(?P<activityname_string>(?:[^"]|\\")*)" "(?P<activitytype_string>(?:[^"]|\\")*)" activity with "(manual|auto)" completion shows a status completion checkbox/
* @param string $activityname The activity name.
* @param string $activitytype The activity type.
* @param string $completiontype The completion type.
*/
public function activity_has_status_completion_checkbox($activityname, $activitytype, $completiontype) {
if ($completiontype == "manual") {
$imgname = 'i/completion-manual-';
} else {
$imgname = 'i/completion-auto-';
}
$iconxpath = "//li[contains(concat(' ', @class, ' '), ' modtype_" . strtolower($activitytype) . " ')]";
$iconxpath .= "[descendant::*[contains(text(), '" . $activityname . "')]]";
$iconxpath .= "/descendant::span[@class='actions']/descendant::img[contains(@src, 'i/completion-')]";
$this->execute("behat_general::the_attribute_of_should_contain",
array("src", $iconxpath, "xpath_element", $imgname)
);
$this->execute("behat_general::the_attribute_of_should_not_contain",
array("src", $iconxpath, "xpath_element", '-enabled')
);
}
/**
* Checks if the activity with specified name does not show any completion checkbox.
*
* @Given /^the "(?P<activityname_string>(?:[^"]|\\")*)" "(?P<activitytype_string>(?:[^"]|\\")*)" activity does not show any completion checkbox/
* @param string $activityname The activity name.
* @param string $activitytype The activity type.
*/
public function activity_has_not_any_completion_checkbox($activityname, $activitytype) {
$iconxpath = "//li[contains(concat(' ', @class, ' '), ' modtype_" . strtolower($activitytype) . " ')]";
$iconxpath .= "[descendant::*[contains(text(), '" . $activityname . "')]]";
$iconxpath .= "/descendant::img[contains(@src, 'i/completion-')]";
$this->execute("behat_general::should_not_exist",
array($iconxpath, "xpath_element")
);
}
}

View file

@ -0,0 +1,65 @@
@core @core_completion
Feature: Show activity completion status or activity completion configuration on the course page
In order to understand the configuration or status of an activity's completion
As a user
I want to see an appropriate checkbox icon besides the activity
Background:
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | First | teacher1@example.com |
| teacher2 | Teacher | Second | teacher2@example.com |
| student1 | Student | First | student1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| teacher2 | C1 | teacher |
| student1 | C1 | student |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I navigate to "Edit settings" in current page administration
And I set the following fields to these values:
| Enable completion tracking | Yes |
And I press "Save and display"
And the following "activities" exist:
| activity | course | idnumber | name | intro | completion | completionview | completionexpected |
| forum | C1 | forum1 | Test forum name | Test forum description | 1 | 0 | 0 |
And the following "activities" exist:
| activity | course | idnumber | name | intro | completion | completionview | completionexpected |
| assign | C1 | assign1 | Test assignment name | Test assignment description | 2 | 1 | 0 |
And the following "activities" exist:
| activity | course | idnumber | name | intro | completion | completionview | completionexpected |
| quiz | C1 | quiz1 | Test quiz name | Test quiz description | 0 | 0 | 0 |
And I log out
Scenario: Show completion status to students
Given I log in as "student1"
And I am on "Course 1" course homepage
Then I should see "Your progress"
And the "Test forum name" "Forum" activity with "manual" completion shows a status completion checkbox
And the "Test assignment name" "Assign" activity with "auto" completion shows a status completion checkbox
And the "Test quiz name" "Quiz" activity does not show any completion checkbox
Scenario: Show completion configuration to editing teachers
Given I log in as "teacher1"
And I am on "Course 1" course homepage
Then I should not see "Your progress"
And the "Test forum name" "Forum" activity with "manual" completion shows a configuration completion checkbox
And the "Test assignment name" "Assign" activity with "auto" completion shows a configuration completion checkbox
And the "Test quiz name" "Quiz" activity does not show any completion checkbox
And I am on "Course 1" course homepage with editing mode on
And I should not see "Your progress"
And the "Test forum name" "Forum" activity with "manual" completion shows a configuration completion checkbox
And the "Test assignment name" "Assign" activity with "auto" completion shows a configuration completion checkbox
And the "Test quiz name" "Quiz" activity does not show any completion checkbox
Scenario: Show completion configuration to non-editing teachers
Given I log in as "teacher2"
And I am on "Course 1" course homepage
Then I should not see "Your progress"
And the "Test forum name" "Forum" activity with "manual" completion shows a configuration completion checkbox
And the "Test assignment name" "Assign" activity with "auto" completion shows a configuration completion checkbox
And the "Test quiz name" "Quiz" activity does not show any completion checkbox