// The argument should be converted to an xpath literal.
$label = $this->getSession()->getSelectorsHandler()->xpathLiteral($label);
- $fieldxpath = "//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]" .
- "[@id=//label[contains(normalize-space(.), $label)]/@for]";
- $fieldnode = $this->find('xpath', $fieldxpath, $exception);
- $formfieldtypenode = $this->find('xpath', $fieldxpath . "/ancestor::div[@class='form-setting']" .
- "/child::div[contains(concat(' ', @class, ' '), ' form-')]/child::*/parent::div");
+ // Single element settings.
+ try {
+ $fieldxpath = "//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]" .
+ "[@id=//label[contains(normalize-space(.), $label)]/@for]";
+ $fieldnode = $this->find('xpath', $fieldxpath, $exception);
+
+ $formfieldtypenode = $this->find('xpath', $fieldxpath . "/ancestor::div[@class='form-setting']" .
+ "/child::div[contains(concat(' ', @class, ' '), ' form-')]/child::*/parent::div");
+
+ } catch (ElementNotFoundException $e) {
+
+ // Multi element settings, interacting only the first one.
+ $fieldxpath = "//descendant::label[.= $label]/ancestor::div[contains(concat(' ', normalize-space(@class), ' '), ' form-item ')]" .
+ "/descendant::div[@class='form-group']/descendant::*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]";
+ $fieldnode = $this->find('xpath', $fieldxpath);
+
+ // It is the same one that contains the type.
+ $formfieldtypenode = $fieldnode;
+ }
// Getting the class which contains the field type.
$classes = explode(' ', $formfieldtypenode->getAttribute('class'));
$this->user_clicks_on_management_listing_action('category', $node, $action);
}
+ /**
+ * Clicks to expand or collapse a category displayed on the frontpage
+ *
+ * @Given /^I toggle "(?P<categoryname_string>(?:[^"]|\\")*)" category children visibility in frontpage$/
+ * @throws ExpectationException
+ * @param string $categoryname
+ */
+ public function i_toggle_category_children_visibility_in_frontpage($categoryname) {
+
+ $headingtags = array();
+ for ($i = 1; $i <= 6; $i++) {
+ $headingtags[] = 'self::h' . $i;
+ }
+
+ $exception = new ExpectationException('"' . $categoryname . '" category can not be found', $this->getSession());
+ $categoryliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($categoryname);
+ $xpath = "//div[@class='info']/descendant::*[" . implode(' or ', $headingtags) . "][@class='categoryname'][./descendant::a[.=$categoryliteral]]";
+ $node = $this->find('xpath', $xpath, $exception);
+ $node->click();
+
+ // Smooth expansion.
+ $this->getSession()->wait(1000, false);
+ }
+
/**
* Finds the node to use for a management listitem action and clicks it.
*
--- /dev/null
+@core @core_course
+Feature: Front page displays items in different modes
+ In order to show a clean and clear list of the site categories and course
+ As an admin
+ I need to set different frontpage display modes
+
+ Background:
+ Given the following "categories" exists:
+ | name | category | idnumber |
+ | Category 1 | 0 | CAT1 |
+ | Category 2 | 0 | CAT2 |
+ | Category 1 child | CAT1 | CAT11 |
+ | Category 2 child | CAT2 | CAT21 |
+ | Category 1 child child | CAT11 | CAT111 |
+ | Category 3 | 0 | CAT3 |
+ And the following "courses" exists:
+ | fullname | shortname | category |
+ | Course 1 1 | COURSE1_1 | CAT1 |
+ | Course 2 1 | COURSE2_1 | CAT2 |
+ | Course 11 1 | COURSE11_1 | CAT11 |
+ | Course 2 2 | COURSE2_2 | CAT2 |
+ | Course 21 1 | COURSE21_1 | CAT21 |
+ | Course 111 1 | COURSE111_1 | CAT111 |
+ | Course 111 2 | COURSE111_2 | CAT111 |
+ And I log in as "admin"
+
+ @javascript
+ Scenario: Displays a list of categories
+ When I set the following administration settings values:
+ | Front page items when logged in | List of categories |
+ | Maximum category depth | 2 |
+ And I am on homepage
+ Then I should see "Category 1" in the "region-main" "region"
+ And I should see "Category 1 child" in the "region-main" "region"
+ And I should not see "Category 1 child child" in the "region-main" "region"
+ And I toggle "Category 1" category children visibility in frontpage
+ And I should not see "Category 1 child" in the "region-main" "region"
+ And I toggle "Category 1" category children visibility in frontpage
+ And I should see "Category 1 child" in the "region-main" "region"
+ And I toggle "Category 1 child" category children visibility in frontpage
+ And I should see "Category 1 child child" in the "region-main" "region"
+
+ @javascript
+ Scenario: Displays a combo list
+ When I set the following administration settings values:
+ | Front page items when logged in | Combo list |
+ | Maximum category depth | 2 |
+ And I am on homepage
+ Then I should see "Category 1" in the "region-main" "region"
+ And I should see "Category 1 child" in the "region-main" "region"
+ And I should not see "Category 1 child child" in the "region-main" "region"
+ And I should see "Course 1 1" in the "region-main" "region"
+ And I should see "Course 2 2" in the "region-main" "region"
+ And I should not see "Course 11 1" in the "region-main" "region"
+ And I toggle "Category 1 child" category children visibility in frontpage
+ And I should see "Course 11 1" in the "region-main" "region"
+ And I should see "Category 1 child child" in the "region-main" "region"
+ And I toggle "Category 1" category children visibility in frontpage
+ And I should not see "Course 1 1" in the "region-main" "region"
+ And I should not see "Category 1 child" in the "region-main" "region"
+ And I toggle "Category 1" category children visibility in frontpage
+ And I should see "Course 11 1" in the "region-main" "region"