From 3ea677e39ad9dcd9c23a6d729622ef7acf5165ab Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Thu, 31 Oct 2013 13:27:47 +0800 Subject: [PATCH] MDL-42403 course: Added behat to check visibility of bluk move action --- course/tests/behat/behat_course.php | 55 ++++++++--- .../tests/behat/category_management.feature | 99 ++++++++++++++++++- 2 files changed, 141 insertions(+), 13 deletions(-) diff --git a/course/tests/behat/behat_course.php b/course/tests/behat/behat_course.php index 3b32a9451f9..a35cdddd02c 100644 --- a/course/tests/behat/behat_course.php +++ b/course/tests/behat/behat_course.php @@ -946,7 +946,7 @@ class behat_course extends behat_base { protected function get_management_category_listing_node_by_name($name, $link = false) { $selector = "//div[@id='category-listing']//li[contains(concat(' ', normalize-space(@class), ' '), ' listitem-category ')]//a[text()='{$name}']"; if ($link === false) { - $selector .= "/ancestor::li[@data-id]"; + $selector .= "/ancestor::li[@data-id][1]"; } return $this->find('xpath', $selector); } @@ -1001,39 +1001,70 @@ class behat_course extends behat_base { } /** - * Clicks on a category checkbox in the management interface. + * Clicks on a category checkbox in the management interface, if not checked. * * @Given /^I select category "(?P[^"]*)" in the management interface$/ * @param string $name */ public function i_select_category_in_the_management_interface($name) { $node = $this->get_management_category_listing_node_by_name($name); - $node->checkField('bcat[]'); + $node = $node->findField('bcat[]'); + if (!$node->isChecked()) { + $node->click(); + } } /** - * Clicks course checkbox in the management interface. + * Clicks on a category checkbox in the management interface, if checked. + * + * @Given /^I unselect category "(?P[^"]*)" in the management interface$/ + * @param string $name + */ + public function i_unselect_category_in_the_management_interface($name) { + $node = $this->get_management_category_listing_node_by_name($name); + $node = $node->findField('bcat[]'); + if ($node->isChecked()) { + $node->click(); + } + } + + /** + * Clicks course checkbox in the management interface, if not checked. * * @Given /^I select course "(?P[^"]*)" in the management interface$/ * @param string $name */ public function i_select_course_in_the_management_interface($name) { $node = $this->get_management_course_listing_node_by_name($name); - $node->checkField('bc[]'); + $node = $node->findField('bc[]'); + if (!$node->isChecked()) { + $node->click(); + } + } + + /** + * Clicks course checkbox in the management interface, if checked. + * + * @Given /^I unselect course "(?P[^"]*)" in the management interface$/ + * @param string $name + */ + public function i_unselect_course_in_the_management_interface($name) { + $node = $this->get_management_course_listing_node_by_name($name); + $node = $node->findField('bc[]'); + if ($node->isChecked()) { + $node->click(); + } } /** * Move selected categories to top level in the management interface. * - * @Given /^I move category "(?P[^"]*)" to top level in the management interface$/ - * @param string $idnumber + * @Given /^I move category "(?P[^"]*)" to top level in the management interface$/ + * @param string $name * @return Given[] */ - public function i_move_category_to_top_level_in_the_management_interface($idnumber) { - $id = $this->get_category_id($idnumber); - $selector = sprintf('.listitem-category[data-id="%d"] > div', $id); - $node = $this->find('css', $selector); - $node->checkField('bcat[]'); + public function i_move_category_to_top_level_in_the_management_interface($name) { + $this->i_select_category_in_the_management_interface($name); return array( new Given('I select "' . coursecat::get(0)->get_formatted_name() . '" from "menumovecategoriesto"'), new Given('I press "bulkmovecategories"'), diff --git a/course/tests/behat/category_management.feature b/course/tests/behat/category_management.feature index 5b6693b75a7..baed279b412 100644 --- a/course/tests/behat/category_management.feature +++ b/course/tests/behat/category_management.feature @@ -231,7 +231,104 @@ Feature: Test category management actions And I click on category "Cat 1" in the management interface # Redirect Then I should see category "CAT3" as subcategory of "CAT1" in the management interface - And I move category "CAT3" to top level in the management interface + And I move category "Cat 3" to top level in the management interface # Redirect And I should not see category "CAT3" as subcategory of "CAT1" in the management interface Then I should see category "CAT2" as subcategory of "CAT1" in the management interface + + @javascript + Scenario: Test bulk action is shown only when some category/course is selected + Given the following "categories" exists: + | name | category | idnumber | + | Cat 1 | 0 | CAT1 | + | Cat 2 | 0 | CAT2 | + | Cat 3 | 0 | CAT3 | + And the following "courses" exists: + | category | fullname | shortname | idnumber | + | CAT3 | Course 1 | Course 1 | C1 | + | CAT3 | Course 2 | Course 2 | C2 | + + And I log in as "admin" + And I go to the courses management page + And I should see the "Course categories" management page + And I should see "Cat 1" in the "#category-listing ul.ml" "css_element" + And I should see "Cat 2" in the "#category-listing ul.ml" "css_element" + And I should see "Cat 3" in the "#category-listing ul.ml" "css_element" + And the "movecategoriesto" "select" should be disabled + And the "resortcategoriesby" "select" should be disabled + And the "resortcoursesby" "select" should be disabled + When I select "allcategories" from "selectsortby" + Then the "resortcategoriesby" "select" should be enabled + And the "resortcoursesby" "select" should be enabled + And the "movecategoriesto" "select" should be disabled + And I select category "Cat 2" in the management interface + And the "movecategoriesto" "select" should be enabled + And the "resortcategoriesby" "select" should be enabled + And the "resortcoursesby" "select" should be enabled + And I select "selectedcategories" from "selectsortby" + And the "movecategoriesto" "select" should be enabled + And the "resortcategoriesby" "select" should be enabled + And the "resortcoursesby" "select" should be enabled + And I unselect category "Cat 2" in the management interface + And the "movecategoriesto" "select" should be disabled + And the "resortcategoriesby" "select" should be disabled + And the "resortcoursesby" "select" should be disabled + And I select category "Cat 3" in the management interface + And the "movecategoriesto" "select" should be enabled + And the "resortcategoriesby" "select" should be enabled + And the "resortcoursesby" "select" should be enabled + And I select category "Cat 2" in the management interface + And the "movecategoriesto" "select" should be enabled + And the "resortcategoriesby" "select" should be enabled + And the "resortcoursesby" "select" should be enabled + And I unselect category "Cat 2" in the management interface + And I unselect category "Cat 3" in the management interface + And the "movecategoriesto" "select" should be disabled + And the "resortcategoriesby" "select" should be disabled + And the "resortcoursesby" "select" should be disabled + And I click on category "Cat 1" in the management interface + # Redirect. + And I should see the "Course categories and courses" management page + And the "movecategoriesto" "select" should be disabled + And the "resortcategoriesby" "select" should be disabled + And the "resortcoursesby" "select" should be disabled + And the "movecoursesto" "select" should be disabled + And I click on category "Cat 3" in the management interface + #Redirect + And I should see the "Course categories and courses" management page + And I should see "Course 1" in the "#course-listing ul.ml" "css_element" + And I should see "Course 2" in the "#course-listing ul.ml" "css_element" + And the "movecategoriesto" "select" should be disabled + And the "resortcategoriesby" "select" should be disabled + And the "resortcoursesby" "select" should be disabled + And the "movecoursesto" "select" should be disabled + And I select course "Course 1" in the management interface + And the "movecoursesto" "select" should be enabled + And the "movecategoriesto" "select" should be disabled + And the "resortcategoriesby" "select" should be disabled + And the "resortcoursesby" "select" should be disabled + And I select course "Course 2" in the management interface + And the "movecoursesto" "select" should be enabled + And the "movecategoriesto" "select" should be disabled + And the "resortcategoriesby" "select" should be disabled + And the "resortcoursesby" "select" should be disabled + And I select category "Cat 3" in the management interface + And the "movecoursesto" "select" should be enabled + And the "movecategoriesto" "select" should be enabled + And the "resortcategoriesby" "select" should be enabled + And the "resortcoursesby" "select" should be enabled + And I unselect course "Course 2" in the management interface + And the "movecoursesto" "select" should be enabled + And the "movecategoriesto" "select" should be enabled + And the "resortcategoriesby" "select" should be enabled + And the "resortcoursesby" "select" should be enabled + And I unselect course "Course 1" in the management interface + And the "movecoursesto" "select" should be disabled + And the "movecategoriesto" "select" should be enabled + And the "resortcategoriesby" "select" should be enabled + And the "resortcoursesby" "select" should be enabled + And I unselect category "Cat 3" in the management interface + And the "movecoursesto" "select" should be disabled + And the "movecategoriesto" "select" should be disabled + And the "resortcategoriesby" "select" should be disabled + And the "resortcoursesby" "select" should be disabled