Skip to content

Commit

Permalink
Merge branch 'MDL-79029-402' of https://github.com/ferranrecio/moodle
Browse files Browse the repository at this point in the history
…into MOODLE_402_STABLE
  • Loading branch information
junpataleta committed Jan 23, 2024
2 parents dbd36ff + 4958cb4 commit 0aa92a4
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 25 deletions.
3 changes: 1 addition & 2 deletions admin/tool/filetypes/tests/behat/add_filetypes.feature
Expand Up @@ -120,8 +120,7 @@ Feature: Add customised file types
| Custom description | Froggy file |
And I press "Save changes"
# Create a resource activity and add it to a course
And I am on "Course 1" course homepage with editing mode on
When I add a "File" to section "1"
When I add a resource activity to course "Course 1" section "1"
And I set the following fields to these values:
| Name | An example of customised file type |
| Description | File description |
Expand Down
3 changes: 1 addition & 2 deletions availability/tests/behat/private_ruleset.feature
Expand Up @@ -21,8 +21,7 @@ Feature: Private rule sets
| Group A | C1 | GA | 0 |
| Group B | C1 | GB | 1 |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add a "Page" to section "1"
And I add a page activity to course "Course 1" section "1"
And I expand all fieldsets

Scenario: Add restriction with visible condition (must match), display option should be active
Expand Down
22 changes: 7 additions & 15 deletions course/tests/behat/add_activities.feature
Expand Up @@ -11,15 +11,13 @@ Feature: Add activities to courses

@javascript
Scenario: Add an activity to a course
Given I am on the "Course 1" Course page logged in as admin
And I am on "Course 1" course homepage with editing mode on
When I add a "Database" to section "3" and I fill the form with:
Given I log in as "admin"
When I add a data activity to course "Course 1" section "3" and I fill the form with:
| Name | Test name |
| Description | Test database description |
| ID number | TESTNAME |
| Allow comments on entries | Yes |
| Force language | English |
And I turn editing mode off
Then I should not see "Adding a new"
And I turn editing mode on
And I open "Test name" actions menu
Expand All @@ -30,32 +28,26 @@ Feature: Add activities to courses
| Allow comments on entries | Yes |
| Force language | English ‎(en)‎ |

@javascript
Scenario: Add an activity supplying only the name
Given I am on the "Course 1" Course page logged in as admin
And I am on "Course 1" course homepage with editing mode on
When I add a "Database" to section "3" and I fill the form with:
Given I log in as "admin"
When I add a data activity to course "Course 1" section "3" and I fill the form with:
| Name | Test name |
Then I should see "Test name"

@javascript
Scenario: Set activity description to required then add an activity supplying only the name
Given the following config values are set as admin:
| requiremodintro | 1 |
And I am on the "Course 1" Course page logged in as admin
And I am on "Course 1" course homepage with editing mode on
And I add a "Database" to section "3" and I fill the form with:
And I log in as "admin"
And I add a data activity to course "Course 1" section "3" and I fill the form with:
| Name | Test name |
Then I should see "Required"

@javascript
Scenario: The activity description should use the user's preferred editor on creation
Given the following "user preferences" exist:
| user | preference | value |
| admin | htmleditor | textarea |
And I am logged in as admin
And I am on "Course 1" course homepage with editing mode on
When I add a "Database" to section "3"
When I add a data activity to course "Course 1" section "3"
Then the field "Description format" matches value "0"

@javascript
Expand Down
116 changes: 111 additions & 5 deletions course/tests/behat/behat_course.php
Expand Up @@ -202,7 +202,7 @@ public function i_add_to_section($activity, $section) {
if ($section) {
// Section 1 represents the contents on the frontpage.
$sectionxpath = "//body[@id='page-site-index']" .
"/descendant::div[contains(concat(' ',normalize-space(@class),' '),' sitetopic ')]";
"/descendant::div[contains(concat(' ',normalize-space(@class),' '),' sitetopic ')]";
} else {
// Section 0 represents "Site main menu" block.
$sectionxpath = "//*[contains(concat(' ',normalize-space(@class),' '),' block_site_main_menu ')]";
Expand All @@ -224,10 +224,116 @@ public function i_add_to_section($activity, $section) {
// Clicks the selected activity if it exists.
$activityliteral = behat_context_helper::escape(ucfirst($activity));
$activityxpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' modchooser ')]" .
"/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' optioninfo ')]" .
"/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' optionname ')]" .
"[normalize-space(.)=$activityliteral]" .
"/parent::a";
"/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' optioninfo ')]" .
"/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' optionname ')]" .
"[normalize-space(.)=$activityliteral]" .
"/parent::a";

$this->execute('behat_general::i_click_on', [$activityxpath, 'xpath']);
}

/**
* Adds the selected activity/resource filling the form data with the specified field/value pairs.
*
* Sections 0 and 1 are also allowed on frontpage.
*
* @Given I add a :activity activity to course :coursefullname section :sectionnum and I fill the form with:
* @Given I add an :activity activity to course :coursefullname section :sectionnum and I fill the form with:
* @param string $activity The activity name
* @param string $coursefullname The course full name of the course.
* @param int $section The section number
* @param TableNode $data The activity field/value data
*/
public function i_add_to_course_section_and_i_fill_the_form_with($activity, $coursefullname, $section, TableNode $data) {

// Add activity to section.
$this->execute(
"behat_course::i_add_to_course_section",
[$this->escape($activity), $this->escape($coursefullname), $this->escape($section)]
);

// Wait to be redirected.
$this->execute('behat_general::wait_until_the_page_is_ready');

// Set form fields.
$this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);

// Save course settings.
$this->execute("behat_forms::press_button", get_string('savechangesandreturntocourse'));
}

/**
* Open a add activity form page.
*
* @Given I add a :activity activity to course :coursefullname section :sectionnum
* @Given I add an :activity activity to course :coursefullname section :sectionnum
* @throws coding_exception
* @param string $activity The activity name.
* @param string $coursefullname The course full name of the course.
* @param string $sectionnum The section number.
*/
public function i_add_to_course_section(string $activity, string $coursefullname, string $sectionnum): void {
$addurl = new moodle_url('/course/modedit.php', [
'add' => $activity,
'course' => $this->get_course_id($coursefullname),
'section' => intval($sectionnum),
]);
$this->execute('behat_general::i_visit', [$addurl]);
}

/**
* Opens the activity chooser and opens the activity/resource link form page.
*
* Sections 0 and 1 are also allowed on frontpage.
*
* This step require javascript enabled and it is used mainly to click activities or resources by name,
* not by plugin name. Use the standard behat_course::i_add_to_course_section step instead unless the
* plugin create extra entries into the activity chooser (like LTI).
*
* @Given I add a :activityname to section :sectionnum using the activity chooser
* @Given I add an :activityname to section :sectionnum using the activity chooser
* @throws ElementNotFoundException Thrown by behat_base::find
* @param string $activityname
* @param int $sectionnum
*/
public function i_add_to_section_using_the_activity_chooser($activityname, $sectionnum) {

$this->require_javascript('Please use the \'the following "activity" exists:\' data generator instead.');

if ($this->getSession()->getPage()->find('css', 'body#page-site-index') && (int) $sectionnum <= 1) {
// We are on the frontpage.
if ($sectionnum) {
// Section 1 represents the contents on the frontpage.
$sectionxpath = "//body[@id='page-site-index']" .
"/descendant::div[contains(concat(' ',normalize-space(@class),' '),' sitetopic ')]";
} else {
// Section 0 represents "Site main menu" block.
$sectionxpath = "//*[contains(concat(' ',normalize-space(@class),' '),' block_site_main_menu ')]";
}
} else {
// We are inside the course.
$sectionxpath = "//li[@id='section-" . $sectionnum . "']";
}

// Clicks add activity or resource section link.
$sectionnode = $this->find('xpath', $sectionxpath);
$this->execute(
'behat_general::i_click_on_in_the',
[
"//button[@data-action='open-chooser' and not(@data-beforemod)]",
'xpath',
$sectionnode,
'NodeElement',
]
);

// Clicks the selected activity if it exists.
$activityliteral = behat_context_helper::escape(ucfirst($activityname));
$activityxpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' modchooser ')]" .
"/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' optioninfo ')]" .
"/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' optionname ')]" .
"[normalize-space(.)=$activityliteral]" .
"/parent::a";

$this->execute('behat_general::i_click_on', [$activityxpath, 'xpath']);
}
Expand Down
4 changes: 4 additions & 0 deletions course/upgrade.txt
Expand Up @@ -2,6 +2,10 @@ This files describes API changes in /course/*,
information provided here is intended especially for developers.

=== 4.3.1 ===
* New behat steps backported to stable versions:
- I add a :activityname to section :sectionnum using the activity chooser
- I add a :activitypluginname activity to course :coursefullname section :sectionnum
- I add a :activitypluginname activity to course :coursefullname section :sectionnum and I fill the form with:
* set_coursemodule_visible() has a new $rebuildcache parameter. If this is being called multiple times in the same request,
consider passing `false` for this parameter and rebuilding the cache once after all the course modules have been updated.
See course_update_section() for an example.
Expand Down
2 changes: 1 addition & 1 deletion media/player/videojs/tests/behat/modules.feature
Expand Up @@ -24,7 +24,7 @@ Feature: Embed videos without the media filter

@javascript
Scenario: Add a video as a File resource. Make sure media filters work
When I add a "File" to section "1"
When I add a "File" to section "1" using the activity chooser
And I set the following fields to these values:
| Name | Video File |
| Description | Example of a video file |
Expand Down

0 comments on commit 0aa92a4

Please sign in to comment.