Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
18
 
19
require_once(__DIR__ . '/../../../lib/behat/behat_deprecated_base.php');
20
 
21
use Behat\Gherkin\Node\TableNode as TableNode;
22
 
23
/**
24
 * Steps definitions that are now deprecated and will be removed in the next releases.
25
 *
26
 * This file only contains the steps that previously were in the behat_*.php files in the SAME DIRECTORY.
27
 * When deprecating steps from other components or plugins, create a behat_COMPONENT_deprecated.php
28
 * file in the same directory where the steps were defined.
29
 *
30
 * @package    core_course
31
 * @category   test
32
 * @copyright  2024 Amaia Anabitarte <amaia@moodle.com>
33
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class behat_course_deprecated extends behat_deprecated_base {
36
    /**
37
     * Opens the activity chooser and opens the activity/resource form page. Sections 0 and 1 are also allowed on frontpage.
38
     *
39
     * @Given /^I add a "(?P<activity_or_resource_name_string>(?:[^"]|\\")*)" to section "(?P<section_number>\d+)"$/
40
     * @param string $activity
41
     * @param int $section
42
     * @throws \Behat\Mink\Exception\ElementNotFoundException Thrown by behat_base::find
43
     * @deprecated Since Moodle 4.4
44
     */
45
    public function i_add_to_section($activity, $section) {
46
        $this->deprecated_message([
47
            'behat_course::i_add_to_course_section',
48
            'behat_course::i_add_to_section_using_the_activity_chooser',
49
        ]);
50
 
51
        $this->require_javascript('Please use the \'the following "activity" exists:\' data generator instead.');
52
 
53
        if ($this->getSession()->getPage()->find('css', 'body#page-site-index') && (int)$section <= 1) {
54
            // We are on the frontpage.
55
            if ($section) {
56
                // Section 1 represents the contents on the frontpage.
57
                $sectionxpath = "//body[@id='page-site-index']" .
58
                    "/descendant::div[contains(concat(' ',normalize-space(@class),' '),' sitetopic ')]";
59
            } else {
60
                // Section 0 represents "Site main menu" block.
61
                $sectionxpath = "//*[contains(concat(' ',normalize-space(@class),' '),' block_site_main_menu ')]";
62
            }
63
        } else {
64
            // We are inside the course.
65
            $sectionxpath = "//li[@id='section-" . $section . "']";
66
        }
67
 
68
        // Clicks add activity or resource section link.
69
        $sectionnode = $this->find('xpath', $sectionxpath);
70
        $this->execute('behat_general::i_click_on_in_the', [
71
            "//button[@data-action='open-chooser' and not(@data-beforemod)]",
72
            'xpath',
73
            $sectionnode,
74
            'NodeElement',
75
        ]);
76
 
77
        // Clicks the selected activity if it exists.
78
        $activityliteral = behat_context_helper::escape(ucfirst($activity));
79
        $activityxpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' modchooser ')]" .
80
            "/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' optioninfo ')]" .
81
            "/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' optionname ')]" .
82
            "[normalize-space(.)=$activityliteral]" .
83
            "/parent::a";
84
 
85
        $this->execute('behat_general::i_click_on', [$activityxpath, 'xpath']);
86
    }
87
 
88
    /**
89
     * Adds the selected activity/resource filling the form data with the specified field/value pairs.
90
     *
91
     * Sections 0 and 1 are also allowed on frontpage.
92
     *
93
     * @When /^I add a "(?P<activity_or_resource_name_string>(?:[^"]|\\")*)" to section "(?P<section_number>\d+)" and I fill the form with:$/
94
     * @param string $activity The activity name
95
     * @param int $section The section number
96
     * @param TableNode $data The activity field/value data
97
     * @deprecated Since Moodle 4.4
98
     */
99
    public function i_add_to_section_and_i_fill_the_form_with($activity, $section, TableNode $data) {
100
        $this->deprecated_message(['behat_course::i_add_to_course_section_and_i_fill_the_form_with']);
101
 
102
        // Add activity to section.
103
        $this->execute(
104
            "behat_course::i_add_to_section",
105
            [$this->escape($activity), $this->escape($section)]
106
        );
107
 
108
        // Wait to be redirected.
109
        $this->execute('behat_general::wait_until_the_page_is_ready');
110
 
111
        // Set form fields.
112
        $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
113
 
114
        // Save course settings.
115
        $this->execute("behat_forms::press_button", get_string('savechangesandreturntocourse'));
116
    }
117
}