diff --git a/availability/tests/behat/display_availability.feature b/availability/tests/behat/display_availability.feature index a270d2be08a..c5bcb8c2c9b 100644 --- a/availability/tests/behat/display_availability.feature +++ b/availability/tests/behat/display_availability.feature @@ -102,8 +102,8 @@ Feature: display_availability And I log in as "student1" And I am on "Course 1" course homepage - # Page 1 display still there but should be dimmed and not a link. - Then I should see "Page 1" in the "#section-1 .dimmed_text" "css_element" + # Page 1 display still there but should not be a link. + Then I should see "Page 1" in the "#section-1" "css_element" And ".activity-instance a" "css_element" should not exist in the "Topic 1" "section" # Date display should be present. diff --git a/completion/tests/behat/restrict_activity_by_date.feature b/completion/tests/behat/restrict_activity_by_date.feature index c0e7b46dc65..a29c0b6847e 100644 --- a/completion/tests/behat/restrict_activity_by_date.feature +++ b/completion/tests/behat/restrict_activity_by_date.feature @@ -41,7 +41,6 @@ Feature: Restrict activity availability through date conditions When I am on the "Course 1" course page logged in as student1 Then I should see "Available from 31 December 2037" And "Test assignment 1" "link" should not exist in the "page" "region" - And "Test assignment 1" activity should be dimmed @javascript Scenario: Show activity hidden to students when available until date is in past diff --git a/completion/tests/behat/restrict_activity_by_grade.feature b/completion/tests/behat/restrict_activity_by_grade.feature index 8812610aebd..9ca3560a028 100644 --- a/completion/tests/behat/restrict_activity_by_grade.feature +++ b/completion/tests/behat/restrict_activity_by_grade.feature @@ -44,7 +44,7 @@ Feature: Restrict activity availability through grade conditions When I am on the "Course 1" course page logged in as student1 Then I should see "Not available unless: You achieve a required score in Grade assignment" - And "Test page name" activity should be dimmed + And I should see "Test page name" And "Test page name" "link" should not exist And I am on the "Grade assignment" "assign activity" page And I press "Add submission" diff --git a/course/tests/behat/activities_edit_name.feature b/course/tests/behat/activities_edit_name.feature index 1a98500d687..54c2e755ebd 100644 --- a/course/tests/behat/activities_edit_name.feature +++ b/course/tests/behat/activities_edit_name.feature @@ -34,7 +34,7 @@ Feature: Edit activity name in-place And I should see "Good news" And I should not see "Test forum name" # Cancel renaming - And I click on "Edit title" "link" in the "//div[contains(@class,'activityinstance') and contains(.,'Good news')]" "xpath_element" + And I click on "Edit title" "link" in the "[data-value='Good news']" "css_element" And I type "Terrible news" And I press the escape key And "New name for activity Good news" "field" should not exist diff --git a/course/tests/behat/activities_group_icons.feature b/course/tests/behat/activities_group_icons.feature deleted file mode 100644 index 53a165cd049..00000000000 --- a/course/tests/behat/activities_group_icons.feature +++ /dev/null @@ -1,38 +0,0 @@ -@core @core_course @_cross_browser -Feature: Toggle activities groups mode from the course page - In order to split activities in groups - As a teacher - I need to change quickly the group mode of an activity - - @javascript - Scenario: Groups mode toggle with javascript enabled - Given the following "users" exist: - | username | firstname | lastname | email | - | teacher1 | Teacher | 1 | teacher1@example.com | - And the following "courses" exist: - | fullname | shortname | format | - | Course 1 | C1 | topics | - And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | - And I log in as "teacher1" - And I am on "Course 1" course homepage with editing mode on - And I add a "Forum" to section "1" and I fill the form with: - | Forum name | Test forum name | - | Description | Test forum description | - And I navigate to "Settings" in current page administration - And I set the following fields to these values: - | Group mode | No groups | - | Force group mode | No | - When I press "Save and display" - Then "No groups (Click to change)" "link" should exist - And I click on "No groups (Click to change)" "link" in the "Test forum name" activity - And "Separate groups (Click to change)" "link" should exist - And I reload the page - And "Separate groups (Click to change)" "link" should exist - And I click on "Separate groups (Click to change)" "link" in the "Test forum name" activity - And "Visible groups (Click to change)" "link" should exist - And I reload the page - And "Visible groups (Click to change)" "link" should exist - And I click on "Visible groups (Click to change)" "link" in the "Test forum name" activity - And "No groups (Click to change)" "link" should exist diff --git a/course/tests/behat/behat_course.php b/course/tests/behat/behat_course.php index ee3878125ba..261ae7cd76d 100644 --- a/course/tests/behat/behat_course.php +++ b/course/tests/behat/behat_course.php @@ -408,7 +408,7 @@ class behat_course extends behat_base { // Click on un-highlight topic link. $this->execute('behat_general::i_click_on_in_the', - array($stredit, "link", "#section-" . $sectionnumber, "css_element") + array($stredit, "link", "#section-" . $sectionnumber . " .action-menu", "css_element") ); } @@ -515,11 +515,10 @@ class behat_course extends behat_base { // If there are activities they should be hidden and the visibility icon should not be available. if ($activities = $this->get_section_activities($sectionxpath)) { - $dimmedexception = new ExpectationException('There are activities that are not dimmed', $this->getSession()); + $dimmedexception = new ExpectationException('There are activities that are not hidden', $this->getSession()); foreach ($activities as $activity) { - // Dimmed. - $this->find('xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), ' activityinstance ')]" . - "//a[contains(concat(' ', normalize-space(@class), ' '), ' dimmed ')]", $dimmedexception, $activity); + // Hidden from students. + $this->find('named_partial', array('badge', get_string('hiddenfromstudents')), $dimmedexception, $activity); } } } else { @@ -625,11 +624,9 @@ class behat_course extends behat_base { if ($this->is_course_editor()) { - // The activity should not be dimmed. + // The activity should not be hidden from students. try { - $xpath = "/descendant-or-self::a[contains(concat(' ', normalize-space(@class), ' '), ' dimmed ')] | ". - "/descendant-or-self::div[contains(concat(' ', normalize-space(@class), ' '), ' dimmed_text ')]"; - $this->find('xpath', $xpath, false, $activitynode); + $this->find('named_partial', array('badge', get_string('hiddenfromstudents')), null, $activitynode); throw new ExpectationException('"' . $activityname . '" is hidden', $this->getSession()); } catch (ElementNotFoundException $e) { // All ok. @@ -660,20 +657,17 @@ class behat_course extends behat_base { // The activity must exists and be visible. $activitynode = $this->get_activity_node($activityname); - // The activity should not be dimmed. + // Should not have the "Hidden from students" badge. try { - $xpath = "/descendant-or-self::a[contains(concat(' ', normalize-space(@class), ' '), ' dimmed ')] | " . - "/descendant-or-self::div[contains(concat(' ', normalize-space(@class), ' '), ' dimmed_text ')]"; - $this->find('xpath', $xpath, false, $activitynode); + $this->find('named_partial', array('badge', get_string('hiddenfromstudents')), null, $activitynode); throw new ExpectationException('"' . $activityname . '" is hidden', $this->getSession()); } catch (ElementNotFoundException $e) { // All ok. } - // Should has "stealth" class. - $exception = new ExpectationException('"' . $activityname . '" does not have CSS class "stealth"', $this->getSession()); - $xpath = "/descendant-or-self::a[contains(concat(' ', normalize-space(@class), ' '), ' stealth ')]"; - $this->find('xpath', $xpath, $exception, $activitynode); + // Should have the "Available but not shown on course page" badge. + $exception = new ExpectationException('"' . $activityname . '" is not Available', $this->getSession()); + $this->find('named_partial', array('badge', get_string('hiddenoncoursepage')), $exception, $activitynode); // Additional check if this is a teacher in editing mode. if ($this->is_editing_on()) { @@ -712,10 +706,8 @@ class behat_course extends behat_base { $activitynode = $this->get_activity_node($activityname); // Should be hidden. - $exception = new ExpectationException('"' . $activityname . '" is not dimmed', $this->getSession()); - $xpath = "/descendant-or-self::a[contains(concat(' ', normalize-space(@class), ' '), ' dimmed ')] | ". - "/descendant-or-self::div[contains(concat(' ', normalize-space(@class), ' '), ' dimmed_text ')]"; - $this->find('xpath', $xpath, $exception, $activitynode); + $exception = new ExpectationException('"' . $activityname . '" is not hidden', $this->getSession()); + $this->find('named_partial', array('badge', get_string('hiddenfromstudents')), $exception, $activitynode); // Additional check if this is a teacher in editing mode. if ($this->is_editing_on()) { @@ -742,23 +734,21 @@ class behat_course extends behat_base { } /** - * Checks that the specified activity is dimmed. You need to be in the course page. + * Checks that the specified label is hidden from students. You need to be in the course page. * - * @Then /^"(?P(?:[^"]|\\")*)" activity should be dimmed$/ + * @Then /^"(?P(?:[^"]|\\")*)" label should be hidden$/ * @param string $activityname * @throws ExpectationException */ - public function activity_should_be_dimmed($activityname) { - - // The activity should exist. - $activitynode = $this->get_activity_node($activityname); - - // Should be hidden. - $exception = new ExpectationException('"' . $activityname . '" is not dimmed', $this->getSession()); - $xpath = "/descendant-or-self::a[contains(concat(' ', normalize-space(@class), ' '), ' dimmed ')] | ". - "/descendant-or-self::div[contains(concat(' ', normalize-space(@class), ' '), ' dimmed_text ')]"; - $this->find('xpath', $xpath, $exception, $activitynode); + public function label_should_be_hidden($activityname) { + if ($this->is_course_editor()) { + // The activity should exist. + $activitynode = $this->get_activity_node($activityname); + // Should be hidden. + $exception = new ExpectationException('"' . $activityname . '" is not hidden', $this->getSession()); + $this->find('named_partial', array('badge', get_string('hiddenfromstudents')), $exception, $activitynode); + } } /** @@ -2006,8 +1996,8 @@ class behat_course extends behat_base { * @param string $text The text to be searched in the activity date. */ public function activity_date_in_activity_should_contain_text(string $activityname, string $text): void { - $containerselector = "//div[@data-region='activity-information'][@data-activityname='$activityname']"; - $containerselector .= " /div[@data-region='activity-dates']"; + $containerselector = "//div[@data-activityname='$activityname']"; + $containerselector .= "//div[@data-region='activity-dates']"; $params = [$text, $containerselector, 'xpath_element']; $this->execute("behat_general::assert_element_contains_text", $params); @@ -2020,8 +2010,8 @@ class behat_course extends behat_base { * @param string $activityname The activity name. */ public function activity_dates_information_in_activity_should_exist(string $activityname): void { - $containerselector = "//div[@data-region='activity-information'][@data-activityname='$activityname']"; - $elementselector = "/div[@data-region='activity-dates']"; + $containerselector = "//div[@data-activityname='$activityname']"; + $elementselector = "//div[@data-region='activity-dates']"; $params = [$elementselector, "xpath_element", $containerselector, "xpath_element"]; $this->execute("behat_general::should_exist_in_the", $params); } diff --git a/course/tests/behat/course_collapse_sections.feature b/course/tests/behat/course_collapse_sections.feature index 79d4d83e527..96ac0f5980e 100644 --- a/course/tests/behat/course_collapse_sections.feature +++ b/course/tests/behat/course_collapse_sections.feature @@ -68,7 +68,7 @@ Feature: Collapse course sections And I should see "Available until" in the "#section-4 .availabilityinfo" "css_element" And I should see "2013" in the "#section-4 .availabilityinfo" "css_element" And I should not see "Forum 4" - And I should see "Not available" in the "#section-5 .availabilityinfo" "css_element" + And I should see "Not available" in the "#section-5" "css_element" And I should not see "Forum 5" When I click on "#collapssesection3" "css_element" And I should see "Assignment 1" in the "region-main" "region" @@ -84,7 +84,6 @@ Feature: Collapse course sections And I should not see "Book 2" in the "region-main" "region" And I should not see "Book 3" in the "region-main" "region" And I should not see "Available until" in the "#section-4 .availabilityinfo" "css_element" - And I should not see "Not available" in the "#section-5 .availabilityinfo" "css_element" And I click on "#collapssesection1" "css_element" And I click on "#collapssesection2" "css_element" And I click on "#collapssesection3" "css_element" @@ -95,7 +94,6 @@ Feature: Collapse course sections And I should see "Book 2" in the "region-main" "region" And I should see "Book 3" in the "region-main" "region" And I should see "Available until" in the "#section-4 .availabilityinfo" "css_element" - And I should see "Not available" in the "#section-5 .availabilityinfo" "css_element" @javascript Scenario: Expand/collapse sections for Weeks format. @@ -113,7 +111,7 @@ Feature: Collapse course sections And I should see "Available until" in the "#section-4 .availabilityinfo" "css_element" And I should see "2013" in the "#section-4 .availabilityinfo" "css_element" And I should see "Forum 4" - And I should see "Hidden from students" in the "#section-5 .availabilityinfo" "css_element" + And I should see "Hidden from students" in the "#section-5" "css_element" And I should see "Forum 5" When I click on "#collapssesection3" "css_element" And I should see "Assignment 1" in the "region-main" "region" @@ -129,7 +127,7 @@ Feature: Collapse course sections And I should not see "Book 2" in the "region-main" "region" And I should not see "Book 3" in the "region-main" "region" And I should not see "Available until" in the "#section-4 .availabilityinfo" "css_element" - And I should not see "Not available" in the "#section-5 .availabilityinfo" "css_element" + And I should not see "Not available" in the "#section-5" "css_element" And I click on "#collapssesection1" "css_element" And I click on "#collapssesection2" "css_element" And I click on "#collapssesection3" "css_element" @@ -142,7 +140,7 @@ Feature: Collapse course sections And I should see "Available until" in the "#section-4 .availabilityinfo" "css_element" And I should see "2013" in the "#section-4 .availabilityinfo" "css_element" And I should see "Forum 4" - And I should see "Hidden from students" in the "#section-5 .availabilityinfo" "css_element" + And I should see "Hidden from students" in the "#section-5" "css_element" And I should see "Forum 5" @javascript @@ -164,7 +162,7 @@ Feature: Collapse course sections And I should see "Available until" in the "#section-4 .availabilityinfo" "css_element" And I should see "2013" in the "#section-4 .availabilityinfo" "css_element" And I should see "Forum 4" - And I should see "Hidden from students" in the "#section-5 .availabilityinfo" "css_element" + And I should see "Hidden from students" in the "#section-5" "css_element" And I should see "Forum 5" @javascript @@ -189,5 +187,5 @@ Feature: Collapse course sections And I should see "Available until" in the "#section-4 .availabilityinfo" "css_element" And I should see "2013" in the "#section-4 .availabilityinfo" "css_element" And I should not see "Forum 4" - And I should see "Not available" in the "#section-5 .availabilityinfo" "css_element" + And I should see "Not available" in the "#section-5" "css_element" And I should not see "Forum 5" diff --git a/lib/behat/classes/partial_named_selector.php b/lib/behat/classes/partial_named_selector.php index a67765ee40a..4cd7b9ad375 100644 --- a/lib/behat/classes/partial_named_selector.php +++ b/lib/behat/classes/partial_named_selector.php @@ -86,6 +86,7 @@ class behat_partial_named_selector extends \Behat\Mink\Selector\PartialNamedSele */ protected static $allowedselectors = array( 'activity' => 'activity', + 'badge' => 'badge', 'block' => 'block', 'button' => 'button', 'checkbox' => 'checkbox', @@ -136,6 +137,9 @@ class behat_partial_named_selector extends \Behat\Mink\Selector\PartialNamedSele protected static $moodleselectors = array( 'activity' => << << <<