Skip to content

Commit

Permalink
MDL-56586 behat: fix behat tests to work with new add block
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Nov 25, 2016
1 parent 0d9d55a commit 392367c
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 12 deletions.
1 change: 1 addition & 0 deletions backup/util/ui/tests/behat/import_course.feature
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Feature: Import course's contents into another course
| Description | Test forum description |
And I add the "Comments" block
And I add the "Recent blog entries" block
And I turn editing mode off
When I import "Course 1" course into "Course 2" course using this options:
Then I should see "Test database name"
And I should see "Test forum name"
Expand Down
1 change: 0 additions & 1 deletion backup/util/ui/tests/behat/import_groups.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Feature: Option to include groups and groupings when importing a course to anoth
| Grouping 2 | C1 | GROUPING2 |
And I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on

Scenario: Include groups and groupings when importing a course to another course
Given I import "Course 1" course into "Course 2" course using this options:
Expand Down
20 changes: 20 additions & 0 deletions blocks/tests/behat/behat_blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,24 @@ public function i_configure_the_block($blockname) {
array("Configure", "link", $this->escape($blockname), "block")
);
}

/**
* Ensures that block can be added to the page but does not actually add it.
*
* @Then /^the add block selector should contain "(?P<block_name_string>(?:[^"]|\\")*)" block$/
* @param string $blockname
*/
public function the_add_block_selector_should_contain_block($blockname) {
$this->execute('behat_forms::the_select_box_should_contain', [get_string('addblock'), $blockname]);
}

/**
* Ensures that block can not be added to the page.
*
* @Then /^the add block selector should not contain "(?P<block_name_string>(?:[^"]|\\")*)" block$/
* @param string $blockname
*/
public function the_add_block_selector_should_not_contain_block($blockname) {
$this->execute('behat_forms::the_select_box_should_not_contain', [get_string('addblock'), $blockname]);
}
}
4 changes: 2 additions & 2 deletions blocks/tests/behat/restrict_available_blocks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ Feature: Allowed blocks controls
When I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
Then the "Add a block" select box should not contain "Activities"
And the "Add a block" select box should not contain "Course completion status"
Then the add block selector should not contain "Activities" block
And the add block selector should not contain "Course completion status" block
2 changes: 1 addition & 1 deletion course/tests/behat/category_management.feature
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Feature: Test category management actions
And I click on "Back to Category: Cat 1" "link"
# Redirect
And I should see the "Course categories and courses" management page
And I should see "Cat 1" in the "#course-listing h3" "css_element"
And "Cat 1" "link" should exist in the "#category-listing" "css_element"

Scenario: Test I can set access permissions for a category through the management interface.
Given the following "categories" exist:
Expand Down
16 changes: 8 additions & 8 deletions my/tests/behat/restrict_available_blocks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ Feature: Restrict which blocks can be added to Dashboard
And I log in as "student1"
And I click on "Dashboard" "link" in the "Navigation" "block"
And I press "Customise this page"
Then the "Add a block" select box should contain "Comments"
And the "Add a block" select box should contain "Courses"
And the "Add a block" select box should contain "HTML"
And the "Add a block" select box should contain "Tags"
Then the add block selector should contain "Comments" block
And the add block selector should contain "Courses" block
And the add block selector should contain "HTML" block
And the add block selector should contain "Tags" block

Scenario: Remove the ability to add the comments block to Dashboard
When I log in as "admin"
Expand All @@ -35,7 +35,7 @@ Feature: Restrict which blocks can be added to Dashboard
And I log in as "student1"
And I click on "Dashboard" "link" in the "Navigation" "block"
And I press "Customise this page"
Then the "Add a block" select box should not contain "Comments"
And the "Add a block" select box should not contain "Courses"
And the "Add a block" select box should not contain "HTML"
And the "Add a block" select box should contain "Tags"
Then the add block selector should not contain "Comments" block
And the add block selector should not contain "Courses" block
And the add block selector should not contain "HTML" block
And the add block selector should contain "Tags" block
26 changes: 26 additions & 0 deletions theme/boost/tests/behat/behat_theme_boost_behat_blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,30 @@ public function i_open_the_blocks_action_menu($blockname) {
);
}

public function the_add_block_selector_should_contain_block($blockname) {
$this->execute('behat_navigation::i_select_from_flat_navigation_drawer', get_string('addblock'));

$cancelstr = get_string('cancel');
if (!$this->running_javascript()) {
$this->execute('behat_general::should_exist_in_the', [$blockname, 'link', '#region-main', 'css_element']);
$this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'link', '#region-main', 'css_element']);
} else {
$this->execute('behat_general::should_exist_in_the', [$blockname, 'link', '.modal-body', 'css_element']);
$this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'link', '.modal-body', 'css_element']);
}
}

public function the_add_block_selector_should_not_contain_block($blockname) {
$this->execute('behat_navigation::i_select_from_flat_navigation_drawer', get_string('addblock'));

$cancelstr = get_string('cancel');
if (!$this->running_javascript()) {
$this->execute('behat_general::should_not_exist_in_the', [$blockname, 'link', '#region-main', 'css_element']);
$this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'link', '#region-main', 'css_element']);
} else {
$this->execute('behat_general::should_not_exist_in_the', [$blockname, 'link', '.modal-body', 'css_element']);
$this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'link', '.modal-body', 'css_element']);
}
}

}

0 comments on commit 392367c

Please sign in to comment.