mirror of
https://github.com/moodle/moodle.git
synced 2025-08-11 20:06:46 +02:00
Merge branch 'MDL-78474-master' of https://github.com/aydevworks/moodle
This commit is contained in:
commit
d1f45f3b0e
7 changed files with 118 additions and 12 deletions
|
@ -43,6 +43,8 @@ $string['indicator:socialbreadthdef_help'] = 'The participant has reached this p
|
|||
$string['indicator:socialbreadthdef_link'] = 'Learning_analytics_indicators#Social_breadth';
|
||||
$string['label:addinstance'] = 'Add a new Text and media area';
|
||||
$string['label:view'] = 'View Text and media area';
|
||||
$string['labelname'] = 'Name';
|
||||
$string['labelname_help'] = 'Will be shown in course index, activity completion, etc. If left empty, will automatically be generated from the first characters of the text.';
|
||||
$string['labeltext'] = 'Text';
|
||||
$string['modulename'] = 'Text and media area';
|
||||
$string['modulename_help'] = 'The Text and media area enables you to display text and multimedia on the course page.
|
||||
|
|
|
@ -34,6 +34,11 @@ define("LABEL_MAX_NAME_LENGTH", 50);
|
|||
* @return string
|
||||
*/
|
||||
function get_label_name($label) {
|
||||
// Return label name if not empty.
|
||||
if ($label->name) {
|
||||
return $label->name;
|
||||
}
|
||||
|
||||
$context = context_module::instance($label->coursemodule);
|
||||
$intro = format_text($label->intro, $label->introformat, ['filter' => false, 'context' => $context]);
|
||||
$name = html_to_text(format_string($intro, true, ['context' => $context]));
|
||||
|
|
|
@ -37,6 +37,16 @@ class mod_label_mod_form extends moodleform_mod {
|
|||
$mform = $this->_form;
|
||||
|
||||
$mform->addElement('header', 'generalhdr', get_string('general'));
|
||||
|
||||
// Add element for name.
|
||||
$mform->addElement('text', 'name', get_string('labelname', 'label'), array('size' => '64'));
|
||||
if (!empty($CFG->formatstringstriptags)) {
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
} else {
|
||||
$mform->setType('name', PARAM_CLEANHTML);
|
||||
}
|
||||
$mform->addHelpButton('name', 'labelname', 'label');
|
||||
|
||||
$this->standard_intro_elements(get_string('labeltext', 'label'));
|
||||
|
||||
// Label does not add "Show description" checkbox meaning that 'intro' is always shown on the course page.
|
||||
|
@ -51,4 +61,22 @@ class mod_label_mod_form extends moodleform_mod {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Override validation in order to make name field non-required.
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $files
|
||||
* @return array
|
||||
*/
|
||||
public function validation($data, $files) {
|
||||
$errors = parent::validation($data, $files);
|
||||
// Name field should not be required.
|
||||
if (array_key_exists('name', $errors)) {
|
||||
if ($errors['name'] === get_string('required')) {
|
||||
unset($errors['name']);
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
30
mod/label/tests/behat/label_name.feature
Normal file
30
mod/label/tests/behat/label_name.feature
Normal file
|
@ -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'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue