Ignore:
Timestamp:
May 2, 2016, 12:09:23 PM (3 years ago)
Author:
jrpelegrina
Message:

Updated to moodle 3.0.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • moodle/trunk/fuentes/course/tests/behat/behat_course.php

    r136 r1331  
    109109        }
    110110
    111         $steps[] = new Given('I press "' . get_string('savechanges') . '"');
     111        $steps[] = new Given('I press "' . get_string('savechangesanddisplay') . '"');
    112112
    113113        return $steps;
     
    140140        return array(
    141141            new Given('I add a "' . $this->escape($activity) . '" to section "' . $this->escape($section) . '"'),
     142            new Given('I wait to be redirected'),
    142143            new Given('I set the following fields to these values:', $data),
    143144            new Given('I press "' . get_string('savechangesandreturntocourse') . '"')
     
    181182            $activityxpath = "//div[@id='chooseform']/descendant::label" .
    182183                "/descendant::span[contains(concat(' ', normalize-space(@class), ' '), ' typename ')]" .
    183                 "[contains(., $activityliteral)]" .
     184                "[normalize-space(.)=$activityliteral]" .
    184185                "/parent::label/child::input";
    185186            $activitynode = $this->find('xpath', $activityxpath);
     
    191192            // Selecting the option from the select box which contains the option.
    192193            $selectxpath = $sectionxpath . "/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' section_add_menus ')]" .
    193                 "/descendant::select[contains(., $activityliteral)]";
     194                "/descendant::select[option[normalize-space(.)=$activityliteral]]";
    194195            $selectnode = $this->find('xpath', $selectxpath);
    195196            $selectnode->selectOption($activity);
     
    203204    }
    204205
     206
     207    /**
     208     * Opens a section edit menu if it is not already opened.
     209     *
     210     * @Given /^I open section "(?P<section_number>\d+)" edit menu$/
     211     * @throws DriverException The step is not available when Javascript is disabled
     212     * @param string $sectionnumber
     213     */
     214    public function i_open_section_edit_menu($sectionnumber) {
     215        if (!$this->running_javascript()) {
     216            throw new DriverException('Section edit menu not available when Javascript is disabled');
     217        }
     218
     219        // Wait for section to be available, before clicking on the menu.
     220        $this->i_wait_until_section_is_available($sectionnumber);
     221
     222        // If it is already opened we do nothing.
     223        $xpath = $this->section_exists($sectionnumber);
     224        $xpath .= "/descendant::div[contains(@class, 'section-actions')]/descendant::a[contains(@class, 'textmenu')]";
     225
     226        $exception = new ExpectationException('Section "' . $sectionnumber . '" was not found', $this->getSession());
     227        $menu = $this->find('xpath', $xpath, $exception);
     228        $menu->click();
     229        $this->i_wait_until_section_is_available($sectionnumber);
     230    }
     231
     232    /**
     233     * Deletes course section.
     234     *
     235     * @Given /^I delete section "(?P<section_number>\d+)"$/
     236     * @param int $sectionnumber The section number
     237     * @return Given[]
     238     */
     239    public function i_delete_section($sectionnumber) {
     240        // Ensures the section exists.
     241        $xpath = $this->section_exists($sectionnumber);
     242
     243        // We need to know the course format as the text strings depends on them.
     244        $courseformat = $this->get_course_format();
     245        if (get_string_manager()->string_exists('deletesection', $courseformat)) {
     246            $strdelete = get_string('deletesection', $courseformat);
     247        } else {
     248            $strdelete = get_string('deletesection');
     249        }
     250
     251        // If javascript is on, link is inside a menu.
     252        if ($this->running_javascript()) {
     253            $this->i_open_section_edit_menu($sectionnumber);
     254        }
     255
     256        return new Given('I click on "' . $strdelete . '" "link" in the "' . $this->escape($xpath) . '" "xpath_element"');
     257    }
     258
    205259    /**
    206260     * Turns course section highlighting on.
     
    215269        $xpath = $this->section_exists($sectionnumber);
    216270
     271        // If javascript is on, link is inside a menu.
     272        if ($this->running_javascript()) {
     273            $this->i_open_section_edit_menu($sectionnumber);
     274        }
     275
    217276        return new Given('I click on "' . get_string('markthistopic') . '" "link" in the "' . $this->escape($xpath) . '" "xpath_element"');
    218277    }
     
    230289        $xpath = $this->section_exists($sectionnumber);
    231290
     291        // If javascript is on, link is inside a menu.
     292        if ($this->running_javascript()) {
     293            $this->i_open_section_edit_menu($sectionnumber);
     294        }
     295
    232296        return new Given('I click on "' . get_string('markedthistopic') . '" "link" in the "' . $this->escape($xpath) . '" "xpath_element"');
    233297    }
     
    241305    public function i_show_section($sectionnumber) {
    242306        $showlink = $this->show_section_icon_exists($sectionnumber);
     307
     308        // Ensure section edit menu is open before interacting with it.
     309        if ($this->running_javascript()) {
     310            $this->i_open_section_edit_menu($sectionnumber);
     311        }
    243312        $showlink->click();
    244313
     
    257326    public function i_hide_section($sectionnumber) {
    258327        $hidelink = $this->hide_section_icon_exists($sectionnumber);
     328
     329        // Ensure section edit menu is open before interacting with it.
     330        if ($this->running_javascript()) {
     331            $this->i_open_section_edit_menu($sectionnumber);
     332        }
    259333        $hidelink->click();
    260334
     
    272346     */
    273347    public function i_edit_the_section($sectionnumber) {
    274         return new Given('I click on "' . get_string('editsummary') . '" "link" in the "#section-' . $sectionnumber . '" "css_element"');
     348        // If javascript is on, link is inside a menu.
     349        if ($this->running_javascript()) {
     350            $this->i_open_section_edit_menu($sectionnumber);
     351        }
     352
     353        // We need to know the course format as the text strings depends on them.
     354        $courseformat = $this->get_course_format();
     355        if (get_string_manager()->string_exists('editsection', $courseformat)) {
     356            $stredit = get_string('editsection', $courseformat);
     357        } else {
     358            $stredit = get_string('editsection');
     359        }
     360
     361        return new Given('I click on "' . $stredit . '" "link" in the "#section-' . $sectionnumber . '" "css_element"');
    275362    }
    276363
     
    305392
    306393        // The important checking, we can not check the img.
    307         $xpath = $xpath . "/descendant::img[@alt='" . get_string('markedthistopic') . "'][contains(@src, 'marked')]";
     394        $xpath = $xpath . "/descendant::img[contains(@src, 'marked')]";
    308395        $exception = new ExpectationException('The "' . $sectionnumber . '" section is not highlighted', $this->getSession());
    309396        $this->find('xpath', $xpath, $exception);
     
    410497        }
    411498
    412         // Hide section button should be visible.
     499        // Edit menu should be visible.
    413500        if ($this->is_course_editor()) {
    414             $this->hide_section_icon_exists($sectionnumber);
     501            $xpath = $sectionxpath .
     502                     "/descendant::div[contains(@class, 'section-actions')]" .
     503                     "/descendant::a[contains(@class, 'textmenu')]";
     504            if (!$this->getSession()->getPage()->find('xpath', $xpath)) {
     505                throw new ExpectationException('The section edit menu is not available', $this->getSession());
     506            }
    415507        }
    416508    }
     
    432524        $sectionxpath = $this->section_exists($sectionnumber);
    433525
     526        // If javascript is on, link is inside a menu.
     527        if ($this->running_javascript()) {
     528            $this->i_open_section_edit_menu($sectionnumber);
     529        }
     530
    434531        // Follows the link
    435532        $moveuplink = $this->get_node_in_container('link', get_string('moveup'), 'xpath_element', $sectionxpath);
     
    453550        $sectionxpath = $this->section_exists($sectionnumber);
    454551
     552        // If javascript is on, link is inside a menu.
     553        if ($this->running_javascript()) {
     554            $this->i_open_section_edit_menu($sectionnumber);
     555        }
     556
    455557        // Follows the link
    456558        $movedownlink = $this->get_node_in_container('link', get_string('movedown'), 'xpath_element', $sectionxpath);
     
    474576            // The activity should not be dimmed.
    475577            try {
    476                 $this->find('css', 'a.dimmed', false, $activitynode);
     578                $xpath = "/descendant-or-self::a[contains(concat(' ', normalize-space(@class), ' '), ' dimmed ')] | ".
     579                         "/descendant-or-self::div[contains(concat(' ', normalize-space(@class), ' '), ' dimmed_text ')]";
     580                $this->find('xpath', $xpath, false, $activitynode);
    477581                throw new ExpectationException('"' . $activityname . '" is hidden', $this->getSession());
    478582            } catch (ElementNotFoundException $e) {
     
    502606            // Should be hidden.
    503607            $exception = new ExpectationException('"' . $activityname . '" is not dimmed', $this->getSession());
    504             $this->find('css', 'a.dimmed', $exception, $activitynode);
     608            $xpath = "/descendant-or-self::a[contains(concat(' ', normalize-space(@class), ' '), ' dimmed ')] | ".
     609                     "/descendant-or-self::div[contains(concat(' ', normalize-space(@class), ' '), ' dimmed_text ')]";
     610            $this->find('xpath', $xpath, $exception, $activitynode);
    505611
    506612            // Also 'Show' icon.
     
    876982        $showtext = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('showfromothers', $courseformat));
    877983        $linkxpath = $xpath . "/descendant::a[@title=$showtext]";
    878         $imgxpath = $linkxpath . "/descendant::img[@alt=$showtext][contains(@src, 'show')]";
     984        $imgxpath = $linkxpath . "/descendant::img[contains(@src, 'show')]";
    879985
    880986        $exception = new ElementNotFoundException($this->getSession(), 'Show section icon ');
     
    9031009        $hidetext = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('hidefromothers', $courseformat));
    9041010        $linkxpath = $xpath . "/descendant::a[@title=$hidetext]";
    905         $imgxpath = $linkxpath . "/descendant::img[@alt=$hidetext][contains(@src, 'hide')]";
     1011        $imgxpath = $linkxpath . "/descendant::img[contains(@src, 'hide')]";
    9061012
    9071013        $exception = new ElementNotFoundException($this->getSession(), 'Hide section icon ');
Note: See TracChangeset for help on using the changeset viewer.