mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 00:42:54 +02:00
MDL-43941 Behat: Section visibility tests should not check if activities are visible
It should be possible for activities to be visible even when the section they are in is hidden. However, when a section is hidden, all activities in that section are also then initially hidden. Therefore, this commit splits out the hidden test to a new test so that the initial state of activities after hiding can still be tested.
This commit is contained in:
parent
db6e9aa8d3
commit
26df91ca57
@ -351,6 +351,23 @@ class behat_course extends behat_base {
|
||||
// Section should be hidden.
|
||||
$exception = new ExpectationException('The section is not hidden', $this->getSession());
|
||||
$this->find('xpath', $sectionxpath . "[contains(concat(' ', normalize-space(@class), ' '), ' hidden ')]", $exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that all actiities in the specified section are hidden. You need to be in the course page. It can be used being logged as a student and as a teacher on editing mode.
|
||||
*
|
||||
* @Then /^all activities in section "(?P<section_number>\d+)" should be hidden$/
|
||||
* @throws ExpectationException
|
||||
* @throws ElementNotFoundException Thrown by behat_base::find
|
||||
* @param int $sectionnumber
|
||||
*/
|
||||
public function section_activities_should_be_hidden($sectionnumber) {
|
||||
$sectionxpath = $this->section_exists($sectionnumber);
|
||||
|
||||
// Preventive in case there is any action in progress.
|
||||
// Adding it here because we are interacting (click) with
|
||||
// the elements, not necessary when we just find().
|
||||
$this->i_wait_until_section_is_available($sectionnumber);
|
||||
|
||||
// The checking are different depending on user permissions.
|
||||
if ($this->is_course_editor()) {
|
||||
@ -362,50 +379,19 @@ class behat_course extends behat_base {
|
||||
if ($activities = $this->get_section_activities($sectionxpath)) {
|
||||
|
||||
$dimmedexception = new ExpectationException('There are activities that are not dimmed', $this->getSession());
|
||||
$visibilityexception = new ExpectationException('There are activities which visibility icons are clickable', $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);
|
||||
|
||||
// Non-JS browsers can not click on img elements.
|
||||
if ($this->running_javascript()) {
|
||||
|
||||
// Expanding the actions menu if it is not shown.
|
||||
$classes = array_flip(explode(' ', $activity->getAttribute('class')));
|
||||
if (empty($classes['action-menu-shown'])) {
|
||||
$actionsmenu = $this->find('css', "a[role='menuitem']", false, $activity);
|
||||
$actionsmenu->click();
|
||||
}
|
||||
|
||||
// To check that the visibility is not clickable we check the funcionality rather than the applied style.
|
||||
$visibilityiconnode = $this->find('css', 'a.editing_show img', false, $activity);
|
||||
$visibilityiconnode->click();
|
||||
}
|
||||
|
||||
// We ensure that we still see the show icon.
|
||||
$visibilityiconnode = $this->find('css', 'a.editing_show img', $visibilityexception, $activity);
|
||||
|
||||
// It is there only when running JS scenarios.
|
||||
if ($this->running_javascript()) {
|
||||
|
||||
// Collapse the actions menu if it is displayed.
|
||||
$classes = array_flip(explode(' ', $activity->getAttribute('class')));
|
||||
if (!empty($classes['action-menu-shown'])) {
|
||||
$actionsmenu = $this->find('css', "a[role='menuitem']", false, $activity);
|
||||
$actionsmenu->click();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// There shouldn't be activities.
|
||||
if ($this->get_section_activities($sectionxpath)) {
|
||||
throw new ExpectationException('There are activities in the section and they should be hidden', $this->getSession());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,6 +77,7 @@ Feature: Course activity controls works as expected
|
||||
And I hide section "1"
|
||||
And "#section-2" "css_element" <should_see_other_sections> exists
|
||||
And section "1" should be hidden
|
||||
And all activities in section "1" should be hidden
|
||||
And I show section "1"
|
||||
And "#section-2" "css_element" <should_see_other_sections> exists
|
||||
And section "1" should be visible
|
||||
@ -151,6 +152,7 @@ Feature: Course activity controls works as expected
|
||||
And I hide section "1"
|
||||
And "#section-2" "css_element" <should_see_other_sections> exists
|
||||
And section "1" should be hidden
|
||||
And all activities in section "1" should be hidden
|
||||
And I show section "1"
|
||||
And "#section-2" "css_element" <should_see_other_sections> exists
|
||||
And section "1" should be visible
|
||||
|
@ -59,11 +59,15 @@ Feature: Show/hide course sections
|
||||
And section "3" should be hidden
|
||||
And I reload the page
|
||||
And section "1" should be hidden
|
||||
And all activities in section "1" should be hidden
|
||||
And section "2" should be visible
|
||||
And section "3" should be hidden
|
||||
And all activities in section "1" should be hidden
|
||||
And I log out
|
||||
And I log in as "student1"
|
||||
And I follow "Course 1"
|
||||
And section "1" should be hidden
|
||||
And all activities in section "1" should be hidden
|
||||
And section "2" should be visible
|
||||
And section "3" should be hidden
|
||||
And all activities in section "1" should be hidden
|
||||
|
Loading…
x
Reference in New Issue
Block a user