Skip to content

Commit

Permalink
Merge branch 'MDL-79029-main' of https://github.com/ferranrecio/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Jan 23, 2024
2 parents 2893dc7 + f4adbc8 commit 1074455
Show file tree
Hide file tree
Showing 38 changed files with 223 additions and 171 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
Expand Up @@ -6,8 +6,8 @@ Feature: Confirm that conditions on completion no longer cause a bug

Background:
Given the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
| fullname | shortname | format | enablecompletion |
| Course 1 | C1 | topics | 1 |
And the following "users" exist:
| username |
| teacher1 |
Expand All @@ -17,21 +17,14 @@ Feature: Confirm that conditions on completion no longer cause a bug

@javascript
Scenario: Multiple completion conditions on glossary
# Set up course.
Given I am on the "Course 1" "course" page logged in as "teacher1"
And I navigate to "Settings" in current page administration
And I expand all fieldsets
And I set the field "Enable completion tracking" to "Yes"
And I press "Save and display"
And I turn editing mode on
# Add a couple of Pages with manual completion.
And the following "activities" exist:
| activity | course | name | completion |
| page | C1 | Page1 | 1 |
| page | C1 | Page2 | 1 |

And I log in as "teacher1"
# Add a Glossary.
When I add a "Glossary" to section "1"
When I add a glossary activity to course "Course 1" section "1"
And I set the following fields to these values:
| Name | TestGlossary |
And I expand all fieldsets
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
Expand Up @@ -17,8 +17,7 @@ Feature: Allow admins to edit the default activity completion rules at site leve
| course | C1 |
| name | Test assignment one |
| completion | 1 |
And I am on "Course 1" course homepage with editing mode on
When I add a "Assignment" to section "0"
When I add a assign activity to course "Course 1" section "0"
And I expand all fieldsets
# Completion tracking 0 = Do not indicate activity completion.
Then the field "None" matches value "1"
Expand All @@ -39,8 +38,7 @@ Feature: Allow admins to edit the default activity completion rules at site leve
And the following "core_completion > Course default" exist:
| course | module | completion | completionview | completionusegrade | completionsubmit |
| Acceptance test site | assign | 2 | 0 | 1 | 1 |
And I am on "Course 1" course homepage with editing mode on
When I add a "Assignment" to section "0"
When I add a assign activity to course "Course 1" section "0"
And I expand all fieldsets
Then the field "Add requirements" matches value "1"
And the field "completionview" matches value "0"
Expand All @@ -64,8 +62,7 @@ Feature: Allow admins to edit the default activity completion rules at site leve
| course | module | completion | completionview | completionusegrade | completionsubmit |
| Acceptance test site | assign | 2 | 0 | 1 | 1 |
| C1 | assign | 2 | 1 | 0 | 1 |
And I am on "Course 1" course homepage with editing mode on
When I add a "Assignment" to section "0"
When I add a assign activity to course "Course 1" section "0"
And I expand all fieldsets
Then the field "Add requirements" matches value "1"
And the field "completionview" matches value "1"
Expand Down
Expand Up @@ -93,7 +93,7 @@ Feature: Sections can be edited and deleted in custom sections format
@javascript
Scenario: Add a topic and then add an activity in it
When I click on "Add section" "link" in the "Topic 5" "section"
And I add a "Assignment" to section "6" and I fill the form with:
And I add an assign activity to course "Course 1" section "6" and I fill the form with:
| Assignment name | Very new activity |
| Description | Test |
Then I should see "Very new activity" in the "Topic 6" "section"
Expand Down
39 changes: 11 additions & 28 deletions course/tests/behat/add_activities.feature
Expand Up @@ -9,56 +9,44 @@ Feature: Add activities to courses
| fullname | shortname | format |
| Course 1 | Course 1 | topics |

@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 "New"
And I turn editing mode on
And I open "Test name" actions menu
And I click on "Edit settings" "link" in the "Test name" activity
Then I should not see "Adding a new"
And I am on the "Test name" "data activity editing" page
And the following fields match these values:
| Name | Test name |
| ID number | TESTNAME |
| 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
Scenario: The activity description should preserve the format used once edited (markdown version)
Given the following "activities" exist:
| activity | name | intro | introformat | course |
Expand All @@ -67,12 +55,9 @@ Feature: Add activities to courses
| 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
And I open "A4" actions menu
When I click on "Edit settings" "link" in the "A4" activity
When I am on the "A4" "assign activity editing" page
Then the field "Description format" matches value "4"

@javascript
Scenario: The activity description should preserve the format used once edited (plain text version)
Given the following "activities" exist:
| activity | name | intro | introformat | course |
Expand All @@ -81,7 +66,5 @@ Feature: Add activities to courses
| 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
And I open "A2" actions menu
When I click on "Edit settings" "link" in the "A2" activity
When I am on the "A2" "assign activity editing" page
Then the field "Description format" matches value "2"
68 changes: 49 additions & 19 deletions course/tests/behat/behat_course.php
Expand Up @@ -162,18 +162,23 @@ public function i_go_to_the_courses_management_page() {
}

/**
* Adds the selected activity/resource filling the form data with the specified field/value pairs. Sections 0 and 1 are also allowed on frontpage.
* Adds the selected activity/resource filling the form data with the specified field/value pairs.
*
* @When /^I add a "(?P<activity_or_resource_name_string>(?:[^"]|\\")*)" to section "(?P<section_number>\d+)" and I fill the form with:$/
* 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_section_and_i_fill_the_form_with($activity, $section, TableNode $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_section",
array($this->escape($activity), $this->escape($section))
$this->execute(
"behat_course::i_add_to_course_section",
[$this->escape($activity), $this->escape($coursefullname), $this->escape($section)]
);

// Wait to be redirected.
Expand All @@ -187,29 +192,54 @@ public function i_add_to_section_and_i_fill_the_form_with($activity, $section, T
}

/**
* Opens the activity chooser and opens the activity/resource form page. Sections 0 and 1 are also allowed on frontpage.
* 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 "(?P<activity_or_resource_name_string>(?:[^"]|\\")*)" to section "(?P<section_number>\d+)"$/
* @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 $activity
* @param int $section
* @param string $activityname
* @param int $sectionnum
*/
public function i_add_to_section($activity, $section) {
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) $section <= 1) {
if ($this->getSession()->getPage()->find('css', 'body#page-site-index') && (int) $sectionnum <= 1) {
// We are on the frontpage.
if ($section) {
if ($sectionnum) {
// 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 ')]";
}
} else {
// We are inside the course.
$sectionxpath = "//li[@id='section-" . $section . "']";
$sectionxpath = "//li[@id='section-" . $sectionnum . "']";
}

// Clicks add activity or resource section link.
Expand All @@ -222,12 +252,12 @@ public function i_add_to_section($activity, $section) {
]);

// Clicks the selected activity if it exists.
$activityliteral = behat_context_helper::escape(ucfirst($activity));
$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";
"/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: 1 addition & 3 deletions course/tests/behat/restrict_available_activities.feature
Expand Up @@ -18,11 +18,9 @@ Feature: Restrict activities availability
| activity | course | name |
| chat | C1 | Test chat name |

@javascript
Scenario: Activities can be added with the default permissions
Given I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
When I add a "Glossary" to section "1" and I fill the form with:
When I add a glossary activity to course "Course 1" section "1" and I fill the form with:
| Name | Test glossary name |
| Description | Test glossary description |
Then I should see "Test glossary name"
Expand Down
7 changes: 7 additions & 0 deletions course/upgrade.txt
Expand Up @@ -2,6 +2,13 @@ This files describes API changes in /course/*,
information provided here is intended especially for developers.

=== 4.4 ===
* The following behat steps are now deprecated and replaced by new ones with no Javascript dependencies:
- I add a ":activityname" to section ":sectionnum"
- I add a ":activityname" to section ":sectionnum and I fill the form with:"
The new steps are:
- 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
31 changes: 15 additions & 16 deletions files/tests/behat/add_custom_file_type.feature
Expand Up @@ -8,32 +8,31 @@ Feature: Add a new custom file type
Scenario: Add custom file type
Given the following "courses" exist:
| fullname | shortname | category | legacyfiles |
| Course 1 | C1 | 0 | 2 |
| Course 1 | C1 | 0 | 2 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| user | course | role |
| teacher1 | C1 | editingteacher |
And I log in as "admin"
And I navigate to "Server > File types" in site administration
And I press "Add a new file type"
And I set the following fields to these values:
| Extension | mdlr |
| MIME type | application/x-moodle-rules |
| File icon | document |
| Description type | Custom description specified in this form |
| Custom description | Moodle rules |
| Extension | mdlr |
| MIME type | application/x-moodle-rules |
| File icon | document |
| Description type | Custom description specified in this form |
| Custom description | Moodle rules |
And I press "Save changes"
And I should see "application/x-moodle-rules"
And I am on the "Course 1" course page logged in as teacher1
And I turn editing mode on
When I add a "File" to section "1" and I fill the form with:
| Name | Test file |
| Select files | files/tests/fixtures/custom_filetype.mdlr |
| Show size | 1 |
| Show type | 1 |
| Display resource description | 1 |
And I log in as "teacher1"
When I add a resource activity to course "Course 1" section "1" and I fill the form with:
| Name | Test file |
| Select files | files/tests/fixtures/custom_filetype.mdlr |
| Show size | 1 |
| Show type | 1 |
| Display resource description | 1 |
And I am on "Course 1" course homepage
Then I should see "Test file"
And I should see "MDLR" in the "span.activitybadge" "css_element"
Expand Down

0 comments on commit 1074455

Please sign in to comment.