MDL-78474 mod_label: fix phpunit and behat tests
This commit is contained in:
@@ -346,15 +346,29 @@ Feature: Course index depending on role
|
||||
| label | Activity sample 4 | Test label | C1 | sample4 | 2 |
|
||||
# Check resources without URL, as labels, are displayed in the CI and the link goes to the main page when it is clicked.
|
||||
When I am on the "sample1" "Activity" page logged in as "student1"
|
||||
Then I should see "Test label" in the "#courseindex" "css_element"
|
||||
And I click on "Test label" "link" in the "#courseindex" "css_element"
|
||||
Then I should see "Activity sample 4" in the "#courseindex" "css_element"
|
||||
And I click on "Activity sample 4" "link" in the "#courseindex" "css_element"
|
||||
And I should see "Test label" in the "region-main" "region"
|
||||
And I should see "Activity sample 2" in the "region-main" "region"
|
||||
# Check resources without URL, as labels, are displayed for teachers too, and the link is working even when edit mode is on.
|
||||
And I am on the "sample1" "Activity" page logged in as "teacher1"
|
||||
And I should see "Test label" in the "#courseindex" "css_element"
|
||||
And I should see "Activity sample 4" in the "#courseindex" "css_element"
|
||||
And I turn editing mode on
|
||||
And I should see "Test label" in the "#courseindex" "css_element"
|
||||
And I click on "Test label" "link" in the "#courseindex" "css_element"
|
||||
And I should see "Activity sample 4" in the "#courseindex" "css_element"
|
||||
And I click on "Activity sample 4" "link" in the "#courseindex" "css_element"
|
||||
And I should see "Test label" in the "region-main" "region"
|
||||
And I should see "Activity sample 2" in the "region-main" "region"
|
||||
|
||||
@javascript
|
||||
Scenario: Course index behaviour for labels with name or without name
|
||||
# Add two labels to the course (one with name and one without name).
|
||||
Given the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber | section |
|
||||
| label | Activity sample 5 | Test label 1 | C1 | sample4 | 2 |
|
||||
| label | | Test label 2 | C1 | sample5 | 2 |
|
||||
When I am on the "Course 1" course page logged in as teacher1
|
||||
And I should see "Topic 2" in the "courseindex-content" "region"
|
||||
# Label name should be displayed if it is set.
|
||||
And I should see "Activity sample 5" in the "courseindex-content" "region"
|
||||
# Label intro text should be displayed if label name is not set.
|
||||
And I should see "Test label 2" in the "courseindex-content" "region"
|
||||
|
||||
@@ -247,6 +247,10 @@ abstract class testing_module_generator extends component_generator_base {
|
||||
// Fill the name and intro with default values (if missing).
|
||||
if (empty($record->name)) {
|
||||
$record->name = get_string('pluginname', $this->get_modulename()).' '.$this->instancecount;
|
||||
// Module label can be created without name specified. It will get its name from the intro's text.
|
||||
if ($this->get_modulename() === 'label') {
|
||||
$record->name = '';
|
||||
}
|
||||
}
|
||||
if (empty($record->introeditor) && empty($record->intro)) {
|
||||
$record->intro = 'Test '.$this->get_modulename().' ' . $this->instancecount;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
@mod @mod_label
|
||||
|
||||
Feature: Set label name
|
||||
As a teacher
|
||||
I should be able to create a label activity and set a name
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Test | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher | Teacher | Frist | teacher1@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher | C1 | editingteacher |
|
||||
And the following "activities" exist:
|
||||
| activity | course | section | intro | idnumber |
|
||||
| label | C1 | 1 | Intro Text | C1LABEL1 |
|
||||
|
||||
Scenario: label name input box should be shown and can be set
|
||||
When I log in as "teacher"
|
||||
And I am on "Test" course homepage
|
||||
And "Intro Text" activity should be visible
|
||||
And I am on the "Intro Text" "label activity editing" page logged in as teacher
|
||||
And I should see "Name" in the "General" "fieldset"
|
||||
And I set the field "Name" to "Test Label 1"
|
||||
And I press "Save and return to course"
|
||||
And I am on "Test" course homepage
|
||||
Then "Test Label 1" activity should be visible
|
||||
@@ -207,23 +207,26 @@ class lib_test extends \advanced_testcase {
|
||||
/**
|
||||
* Check label name with different content inserted in the label intro.
|
||||
*
|
||||
* @param string $labelcontent
|
||||
* @param string $labelformat
|
||||
* @param string $expectedlabelname
|
||||
* @param string $name
|
||||
* @param string $content
|
||||
* @param string $format
|
||||
* @param string $expectedname
|
||||
* @return void
|
||||
* @covers \get_label_name
|
||||
* @dataProvider label_get_name_data_provider
|
||||
*/
|
||||
public function test_label_get_label_name(string $labelcontent, string $labelformat, string $expectedlabelname): void {
|
||||
public function test_label_get_label_name(string $name, string $content, string $format, string $expectedname): void {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
// When creating the module, get_label_name is called and fills label->name.
|
||||
$label = $this->getDataGenerator()->create_module('label', [
|
||||
'name' => $name,
|
||||
'course' => $course->id,
|
||||
'intro' => $labelcontent,
|
||||
'introformat' => $labelformat
|
||||
'intro' => $content,
|
||||
'introformat' => $format
|
||||
]
|
||||
);
|
||||
$this->assertEquals($expectedlabelname, $label->name);
|
||||
|
||||
$this->assertEquals($expectedname, $label->name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,17 +236,26 @@ class lib_test extends \advanced_testcase {
|
||||
*/
|
||||
public function label_get_name_data_provider(): array {
|
||||
return [
|
||||
'withlabelname' => [
|
||||
'name' => 'Test label 1',
|
||||
'content' => '<p>Simple textual content<p>',
|
||||
'format' => FORMAT_HTML,
|
||||
'expected' => 'Test label 1'
|
||||
],
|
||||
'simple' => [
|
||||
'name' => '',
|
||||
'content' => '<p>Simple textual content<p>',
|
||||
'format' => FORMAT_HTML,
|
||||
'expected' => 'Simple textual content'
|
||||
],
|
||||
'empty' => [
|
||||
'name' => '',
|
||||
'content' => '',
|
||||
'format' => FORMAT_HTML,
|
||||
'expected' => 'Test label 1'
|
||||
],
|
||||
'withaudiocontent' => [
|
||||
'name' => '',
|
||||
'content' => '<p>Test with audio</p>
|
||||
<p> <audio controls="controls">
|
||||
<source src="@@PLUGINFILE@@/moodle-hit-song.mp3">
|
||||
@@ -253,6 +265,7 @@ class lib_test extends \advanced_testcase {
|
||||
'expected' => 'Test with audio'
|
||||
],
|
||||
'withvideo' => [
|
||||
'name' => '',
|
||||
'content' => '<p>Test video</p>
|
||||
<p> <video controls="controls">
|
||||
<source src="https://www.youtube.com/watch?v=xxxyy">
|
||||
@@ -262,6 +275,7 @@ class lib_test extends \advanced_testcase {
|
||||
'expected' => 'Test video https://www.youtube.com/watch?v=xxxyy'
|
||||
],
|
||||
'with video trimming' => [
|
||||
'name' => '',
|
||||
'content' => '<p>Test with video to be trimmed</p>
|
||||
<p> <video controls="controls">
|
||||
<source src="https://www.youtube.com/watch?v=xxxyy">
|
||||
@@ -271,46 +285,55 @@ class lib_test extends \advanced_testcase {
|
||||
'expected' => 'Test with video to be trimmed https://www.youtube....'
|
||||
],
|
||||
'with plain text' => [
|
||||
'name' => '',
|
||||
'content' => 'Content with @@PLUGINFILE@@/moodle-hit-song.mp3 nothing',
|
||||
'format' => FORMAT_HTML,
|
||||
'expected' => 'Content with nothing'
|
||||
],
|
||||
'with several spaces' => [
|
||||
'name' => '',
|
||||
'content' => "Content with @@PLUGINFILE@@/moodle-hit-song.mp3 \r several spaces",
|
||||
'format' => FORMAT_HTML,
|
||||
'expected' => 'Content with several spaces'
|
||||
],
|
||||
'empty spaces' => [
|
||||
'name' => '',
|
||||
'content' => ' ',
|
||||
'format' => FORMAT_HTML,
|
||||
'expected' => 'Text and media area'
|
||||
],
|
||||
'only html' => [
|
||||
'name' => '',
|
||||
'content' => '<audio controls="controls"><source src=""></audio>',
|
||||
'format' => FORMAT_HTML,
|
||||
'expected' => 'Text and media area'
|
||||
],
|
||||
'markdown' => [
|
||||
'name' => '',
|
||||
'content' => "##Simple Title\n simple markdown format",
|
||||
'format' => FORMAT_MARKDOWN,
|
||||
'expected' => 'Simple Title simple markdown format'
|
||||
],
|
||||
'markdown with pluginfile' => [
|
||||
'name' => '',
|
||||
'content' => "##Simple Title\n simple markdown format @@PLUGINFILE@@/moodle-hit-song.mp3",
|
||||
'format' => FORMAT_MARKDOWN,
|
||||
'expected' => 'Simple Title simple markdown format'
|
||||
],
|
||||
'plain text' => [
|
||||
'name' => '',
|
||||
'content' => "Simple plain text @@PLUGINFILE@@/moodle-hit-song.mp3",
|
||||
'format' => FORMAT_PLAIN,
|
||||
'expected' => 'Simple plain text'
|
||||
],
|
||||
'moodle format text' => [
|
||||
'name' => '',
|
||||
'content' => "Simple plain text @@PLUGINFILE@@/moodle-hit-song.mp3",
|
||||
'format' => FORMAT_MOODLE,
|
||||
'expected' => 'Simple plain text'
|
||||
],
|
||||
'html format text' => [
|
||||
'name' => '',
|
||||
'content' => "<h1>Simple plain title</h1><p> with plain text</p> @@PLUGINFILE@@/moodle-hit-song.mp3",
|
||||
'format' => FORMAT_HTML,
|
||||
'expected' => 'Simple plain title with plain text'
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2023042401; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2023042400; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2023041800; // Requires this Moodle version.
|
||||
$plugin->component = 'mod_label'; // Full name of the plugin (used for diagnostics)
|
||||
$plugin->cron = 0;
|
||||
|
||||
Reference in New Issue
Block a user