From 6277853eb36bafc8241949c0089b371a5d7c8820 Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Fri, 26 Aug 2022 16:46:14 +0200 Subject: [PATCH] MDL-75276 mod_data: Update default templates Apart from updating the default templates, to make them look better, they have been also moved to mustache files, in order to make it easier to edit them. --- mod/data/classes/manager.php | 24 +++-- mod/data/classes/output/defaulttemplate.php | 102 ++++++++++++++++++ mod/data/classes/template.php | 63 +++++++++++ mod/data/lang/en/data.php | 3 + mod/data/lib.php | 91 ++++------------ mod/data/renderer.php | 11 ++ mod/data/styles.css | 8 ++ .../defaulttemplate_addtemplate.mustache | 49 +++++++++ .../defaulttemplate_asearchtemplate.mustache | 61 +++++++++++ .../defaulttemplate_listtemplate.mustache | 54 ++++++++++ .../defaulttemplate_rsstemplate.mustache | 45 ++++++++ .../defaulttemplate_singletemplate.mustache | 67 ++++++++++++ mod/data/tests/behat/add_entries.feature | 16 ++- mod/data/tests/behat/manageapproved.feature | 6 +- mod/data/tests/behat/required_entries.feature | 48 +++++---- mod/data/tests/behat/view_entries.feature | 3 +- mod/data/tests/lib_test.php | 2 +- 17 files changed, 536 insertions(+), 117 deletions(-) create mode 100644 mod/data/classes/output/defaulttemplate.php create mode 100644 mod/data/templates/defaulttemplate_addtemplate.mustache create mode 100644 mod/data/templates/defaulttemplate_asearchtemplate.mustache create mode 100644 mod/data/templates/defaulttemplate_listtemplate.mustache create mode 100644 mod/data/templates/defaulttemplate_rsstemplate.mustache create mode 100644 mod/data/templates/defaulttemplate_singletemplate.mustache diff --git a/mod/data/classes/manager.php b/mod/data/classes/manager.php index c501d669fd9..a2a18c17ba9 100644 --- a/mod/data/classes/manager.php +++ b/mod/data/classes/manager.php @@ -24,6 +24,8 @@ use mod_data\event\course_module_viewed; use mod_data\event\template_viewed; use mod_data\event\template_updated; use core_component; +use mod_data_renderer; +use moodle_page; use stdClass; /** @@ -155,6 +157,18 @@ class manager { return $this->cm; } + /** + * Return the current module renderer. + * + * @param moodle_page|null $page the current page + * @return mod_data_renderer the module renderer + */ + public function get_renderer(?moodle_page $page = null): mod_data_renderer { + global $PAGE; + $page = $page ?? $PAGE; + return $page->get_renderer(self::PLUGINNAME); + } + /** * Trigger module viewed event and set the module viewed for completion. * @@ -277,14 +291,8 @@ class manager { } $options['templatename'] = $templatename; // Some templates have extra options. - if ($templatename === 'singletemplate') { - $options['comments'] = true; - $options['ratings'] = true; - } - if ($templatename === 'listtemplate') { - // The "Show more" button should be only displayed in the listtemplate. - $options['showmore'] = true; - } + $options = array_merge($options, template::get_default_display_options($templatename)); + return new template($this, $templatecontent, $options); } diff --git a/mod/data/classes/output/defaulttemplate.php b/mod/data/classes/output/defaulttemplate.php new file mode 100644 index 00000000000..41d95abfb16 --- /dev/null +++ b/mod/data/classes/output/defaulttemplate.php @@ -0,0 +1,102 @@ +. + +namespace mod_data\output; + +use core_tag_tag; +use mod_data\manager; +use templatable; +use renderable; + +/** + * Renderable class for the default templates in the database activity. + * + * @package mod_data + * @copyright 2022 Sara Arjona + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class defaulttemplate implements templatable, renderable { + + /** @var array $fields The array containing the existing fields. */ + private $fields; + + /** @var string $templatename The template name (addtemplate, listtemplate...). */ + private $templatename; + + /** @var bool $isform Whether a form should be displayed instead of data. */ + private $isform; + + /** + * The class constructor. + * + * @param array $fields The array containing the existing fields. + * @param string $templatename The template name (addtemplate, listtemplate...). + * @param bool $isform Whether a form should be displayed instead of data. + */ + public function __construct(array $fields, string $templatename, bool $isform) { + $this->fields = $fields; + $this->templatename = $templatename; + $this->isform = $isform; + } + + /** + * Obtains the mustache template name for this database template. + * + * @return string the file mustache path for this template. + */ + public function get_templatename(): string { + return 'mod_data/defaulttemplate_' . $this->templatename; + } + + /** + * Export the data for the mustache template. + * + * @param \renderer_base $output The renderer to be used to render the action bar elements. + * @return array The data to display. + */ + public function export_for_template(\renderer_base $output): array { + $result = []; + $exportedfields = []; + foreach ($this->fields as $field) { + $fieldname = $field->field->name; + if ($this->isform) { + $fieldcontent = $field->display_add_field(); + } else { + $fieldcontent = '[[' . $fieldname . ']]'; + } + $exportedfields[] = [ + 'fieldname' => $fieldname, + 'fieldcontent' => $fieldcontent, + ]; + } + + if (!empty($exportedfields)) { + $result['fields'] = $exportedfields; + } + + if (core_tag_tag::is_enabled(manager::PLUGINNAME, 'data_records')) { + // Add tags information only if they are enabled. + if ($this->isform) { + $tags = data_generate_tag_form(); + } else { + $tags = '##tags##'; + } + $result['tags'] = $tags; + } + + return $result; + } +} diff --git a/mod/data/classes/template.php b/mod/data/classes/template.php index 369aba2c315..5fac87b9f21 100644 --- a/mod/data/classes/template.php +++ b/mod/data/classes/template.php @@ -102,6 +102,69 @@ class template { $this->load_template_tags($templatecontent); } + /** + * Create a template class with the default template content. + * + * @param manager $manager the current instance manager. + * @param string $templatename the template name. + * @param bool $form whether the fields should be displayed as form instead of data. + * @return self The template with the default content (to be displayed when no template is defined). + */ + public static function create_default_template( + manager $manager, + string $templatename, + bool $form = false + ): self { + $renderer = $manager->get_renderer(); + $content = ''; + switch ($templatename) { + case 'addtemplate': + case 'asearchtemplate': + case 'listtemplate': + case 'rsstemplate': + case 'singletemplate': + $template = new \mod_data\output\defaulttemplate($manager->get_fields(), $templatename, $form); + $content = $renderer->render_defaulttemplate($template); + } + + // Some templates have extra options. + $options = self::get_default_display_options($templatename); + + return new self($manager, $content, $options); + } + + /** + * Get default options for templates. + * + * For instance, the list template supports the show more button. + * + * @param string $templatename the template name. + * @return array an array of extra diplay options. + */ + public static function get_default_display_options(string $templatename): array { + $options = []; + + if ($templatename === 'singletemplate') { + $options['comments'] = true; + $options['ratings'] = true; + } + if ($templatename === 'listtemplate') { + // The "Show more" button should be only displayed in the listtemplate. + $options['showmore'] = true; + } + + return $options; + } + + /** + * Return the raw template content. + * + * @return string the template content before parsing + */ + public function get_template_content(): string { + return $this->templatecontent; + } + /** * Add extra display options. * diff --git a/mod/data/lang/en/data.php b/mod/data/lang/en/data.php index 60aebc1ea88..93c419360c0 100644 --- a/mod/data/lang/en/data.php +++ b/mod/data/lang/en/data.php @@ -27,6 +27,7 @@ $string['action'] = 'Action'; $string['actionsmenu'] = 'Actions menu'; $string['add'] = 'Add entry'; $string['addcomment'] = 'Add comment'; +$string['addedby'] = 'Added by'; $string['addentries'] = 'Add entries'; $string['addtemplate'] = 'Add entry template'; $string['advancedsearch'] = 'Advanced search'; @@ -107,7 +108,9 @@ $string['data:viewrating'] = 'View the total rating you received'; $string['data:writeentry'] = 'Write entries'; $string['data:view'] = 'View database activity'; $string['date'] = 'Date'; +$string['dateadded'] = 'Date added'; $string['dateentered'] = 'Date entered'; +$string['datemodified'] = 'Date modified'; $string['defaultfielddelimiter'] = '(default is the comma character)'; $string['defaultfieldenclosure'] = '(default is none)'; $string['defaultsortfield'] = 'Default sort field'; diff --git a/mod/data/lib.php b/mod/data/lib.php index de9e52ef913..ceaf98cc83b 100644 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -682,89 +682,36 @@ function data_generate_default_template(&$data, $template, $recordid = 0, $form } // These templates are empty by default (they have no content). - $defaulttemplates = [ + $emptytemplates = [ 'csstemplate', 'jstemplate', 'listtemplateheader', 'listtemplatefooter', 'rsstitletemplate', ]; - if (in_array($template, $defaulttemplates)) { + if (in_array($template, $emptytemplates)) { return ''; } - // Get all the fields for that database. - $str = ''; - if ($fields = $DB->get_records('data_fields', array('dataid'=>$data->id), 'id')) { - - $table = new html_table(); - $table->attributes['class'] = 'mod-data-default-template ##approvalstatusclass##'; - $table->colclasses = array('template-field', 'template-token'); - $table->data = array(); - foreach ($fields as $field) { - if ($form) { // Print forms instead of data - $fieldobj = data_get_field($field, $data); - $token = $fieldobj->display_add_field($recordid, null); - } else { // Just print the tag - $token = '[['.$field->name.']]'; - } - $table->data[] = array( - $field->name.': ', - $token - ); - } - - if (core_tag_tag::is_enabled('mod_data', 'data_records')) { - $label = new html_table_cell(get_string('tags') . ':'); - if ($form) { - $cell = data_generate_tag_form(); - } else { - $cell = new html_table_cell('##tags##'); - } - $table->data[] = new html_table_row(array($label, $cell)); - } - - if ($template == 'listtemplate') { - $cell = new html_table_cell('##edit## ##more## ##delete## ##approve## ##disapprove## ##export##'); - $cell->colspan = 2; - $cell->attributes['class'] = 'controls'; - $table->data[] = new html_table_row(array($cell)); - } else if ($template == 'singletemplate') { - $cell = new html_table_cell('##edit## ##delete## ##approve## ##disapprove## ##export##'); - $cell->colspan = 2; - $cell->attributes['class'] = 'controls'; - $table->data[] = new html_table_row(array($cell)); - } else if ($template == 'asearchtemplate') { - $row = new html_table_row(array(get_string('authorfirstname', 'data').': ', '##firstname##')); - $row->attributes['class'] = 'searchcontrols'; - $table->data[] = $row; - $row = new html_table_row(array(get_string('authorlastname', 'data').': ', '##lastname##')); - $row->attributes['class'] = 'searchcontrols'; - $table->data[] = $row; - } - - if ($template == 'listtemplate'){ - $str .= '##delcheck##'; - $str .= html_writer::empty_tag('br'); - } - - $str .= html_writer::start_tag('div', array('class' => 'defaulttemplate')); - $str .= html_writer::table($table); - $str .= html_writer::end_tag('div'); - if ($template == 'listtemplate'){ - $str .= html_writer::empty_tag('hr'); - } - - if ($update) { - $newdata = new stdClass(); - $newdata->id = $data->id; - $newdata->{$template} = $str; - $DB->update_record('data', $newdata); - $data->{$template} = $str; - } + $manager = manager::create_from_instance($data); + if (empty($manager->get_fields())) { + // No template will be returned if there are no fields. + return ''; } - return $str; + $templateclass = \mod_data\template::create_default_template($manager, $template, $form); + $templatecontent = $templateclass->get_template_content(); + + if ($update) { + // Update the database instance. + $newdata = new stdClass(); + $newdata->id = $data->id; + $newdata->{$template} = $templatecontent; + $DB->update_record('data', $newdata); + $data->{$template} = $templatecontent; + } + + return $templatecontent; } /** diff --git a/mod/data/renderer.php b/mod/data/renderer.php index 19159450aba..4ef29b05f62 100644 --- a/mod/data/renderer.php +++ b/mod/data/renderer.php @@ -140,6 +140,17 @@ class mod_data_renderer extends plugin_renderer_base { return $this->render_from_template('mod_data/presets', $data); } + /** + * Renders the default template. + * + * @param \mod_data\output\defaulttemplate $template + * @return string The HTML output + */ + public function render_defaulttemplate(\mod_data\output\defaulttemplate $template): string { + $data = $template->export_for_template($this); + return $this->render_from_template($template->get_templatename(), $data); + } + /** * Renders the action bar for the zero state (no fields created) page. * diff --git a/mod/data/styles.css b/mod/data/styles.css index 6eae7625943..d0dd50bccc9 100644 --- a/mod/data/styles.css +++ b/mod/data/styles.css @@ -150,6 +150,14 @@ display: none; } +.defaulttemplate-single-body img.list_picture { + max-width: 100%; +} + +.defaulttemplate-list-body img.list_picture { + max-width: 100%; +} + /* Preset preview styles */ #page-mod-data-preset .nopreview { border: 1px solid var(--secondary); diff --git a/mod/data/templates/defaulttemplate_addtemplate.mustache b/mod/data/templates/defaulttemplate_addtemplate.mustache new file mode 100644 index 00000000000..3cd7bdc89ed --- /dev/null +++ b/mod/data/templates/defaulttemplate_addtemplate.mustache @@ -0,0 +1,49 @@ +{{! + This file is part of Moodle - http://moodle.org/ + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template mod_data/defaulttemplate_addtemplate + + Default template for the add page in the database activity. + + Context variables required for this template: + * fields - The database fields to display + + Example context (json): + { + "fields": [ + { + "fieldname": "Field1", + "fieldcontent": "[[Field1]]" + }, + { + "fieldname": "Field2", + "fieldcontent": "[[Field2]]" + } + ] + } +}} +
+ {{#fields}} +
+
+ {{{fieldcontent}}} +
+ {{/fields}} + {{#tags}} +
+ {{#str}}tags{{/str}}
+ {{{.}}} +
+ {{/tags}} +
diff --git a/mod/data/templates/defaulttemplate_asearchtemplate.mustache b/mod/data/templates/defaulttemplate_asearchtemplate.mustache new file mode 100644 index 00000000000..01b70f67d14 --- /dev/null +++ b/mod/data/templates/defaulttemplate_asearchtemplate.mustache @@ -0,0 +1,61 @@ +{{! + This file is part of Moodle - http://moodle.org/ + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template mod_data/defaulttemplate_asearchtemplate + + Default template for the advanced search view in the database activity. + + Context variables required for this template: + * fields - The database fields to display + + Example context (json): + { + "fields": [ + { + "fieldname": "Field1", + "fieldcontent": "[[Field1]]" + }, + { + "fieldname": "Field2", + "fieldcontent": "[[Field2]]" + } + ] + } +}} +
+
+
+ {{#str}}authorfirstname, mod_data{{/str}}
+ ##firstname## +
+
+ {{#str}}authorlastname, mod_data{{/str}}
+ ##lastname## +
+ + {{#fields}} +
+
+ {{fieldcontent}} +
+ {{/fields}} + + {{#tags}} +
+ {{#str}}tags{{/str}}
+ {{.}} +
+ {{/tags}} +
+
diff --git a/mod/data/templates/defaulttemplate_listtemplate.mustache b/mod/data/templates/defaulttemplate_listtemplate.mustache new file mode 100644 index 00000000000..112dc468d37 --- /dev/null +++ b/mod/data/templates/defaulttemplate_listtemplate.mustache @@ -0,0 +1,54 @@ +{{! + This file is part of Moodle - http://moodle.org/ + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template mod_data/defaulttemplate_listtemplate + + Default template for the list view page in the database activity. + + Context variables required for this template: + * fields - The database fields to display + + Example context (json): + { + "fields": [ + { + "fieldname": "Field1", + "fieldcontent": "[[Field1]]" + }, + { + "fieldname": "Field2", + "fieldcontent": "[[Field2]]" + } + ] + } +}} +
+
+
##actionsmenu##
+
+
+ {{#fields}} +
+
{{fieldname}}
+
{{fieldcontent}}
+
+ {{/fields}} + {{#tags}} +
+ {{#str}}tags{{/str}} +

{{.}}

+
+ {{/tags}} +
+
diff --git a/mod/data/templates/defaulttemplate_rsstemplate.mustache b/mod/data/templates/defaulttemplate_rsstemplate.mustache new file mode 100644 index 00000000000..c20129801e9 --- /dev/null +++ b/mod/data/templates/defaulttemplate_rsstemplate.mustache @@ -0,0 +1,45 @@ +{{! + This file is part of Moodle - http://moodle.org/ + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template mod_data/defaulttemplate_rsstemplate + + Default template for the RSS page in the database activity. + + Context variables required for this template: + * fields - The database fields to display + + Example context (json): + { + "fields": [ + { + "fieldname": "Field1", + "fieldcontent": "[[Field1]]" + }, + { + "fieldname": "Field2", + "fieldcontent": "[[Field2]]" + } + ] + } +}} +
+
+ {{#fields}} +
+ {{fieldname}} +

{{fieldcontent}}

+
+ {{/fields}} +
+
diff --git a/mod/data/templates/defaulttemplate_singletemplate.mustache b/mod/data/templates/defaulttemplate_singletemplate.mustache new file mode 100644 index 00000000000..e155596de0d --- /dev/null +++ b/mod/data/templates/defaulttemplate_singletemplate.mustache @@ -0,0 +1,67 @@ +{{! + This file is part of Moodle - http://moodle.org/ + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template mod_data/defaulttemplate_singletemplate + + Default template for the single view page in the database activity. + + Context variables required for this template: + * fields - The database fields to display + + Example context (json): + { + "fields": [ + { + "fieldname": "Field1", + "fieldcontent": "[[Field1]]" + }, + { + "fieldname": "Field2", + "fieldcontent": "[[Field2]]" + } + ] + } +}} +
+
+
##actionsmenu##
+
+
+
+ {{#str}}addedby, mod_data{{/str}} +

##userpicture## ##user##

+
+
+ {{#str}}dateadded, mod_data{{/str}} +

##timeadded##

+
+
+ {{#str}}datemodified, mod_data{{/str}} +

##timemodified##

+
+ + {{#fields}} +
+ {{fieldname}} +

{{fieldcontent}}

+
+ {{/fields}} + {{#tags}} +
+ {{#str}}tags{{/str}} +

{{.}}

+
+ {{/tags}} +
+
diff --git a/mod/data/tests/behat/add_entries.feature b/mod/data/tests/behat/add_entries.feature index 782f2df0f96..4de1eb6668d 100644 --- a/mod/data/tests/behat/add_entries.feature +++ b/mod/data/tests/behat/add_entries.feature @@ -39,13 +39,15 @@ Feature: Users can add entries to database activities | Test field 2 name | Student original entry 2 | And I press "Save" Then I should see "Student original entry" - And I follow "Edit" + And I open the action menu in "#defaulttemplate-single" "css_element" + And I choose "Edit" in the open action menu And I set the following fields to these values: | Test field name | Student original entry | | Test field 2 name | | And I press "Save" Then I should not see "Student original entry 2" - And I follow "Edit" + And I open the action menu in "#defaulttemplate-single" "css_element" + And I choose "Edit" in the open action menu And I set the following fields to these values: | Test field name | Student edited entry | And I press "Save" @@ -62,18 +64,12 @@ Feature: Users can add entries to database activities And I should see "Student second entry" And I should see "Student third entry" # Will delete the first one. - And I follow "Delete" + And I open the action menu in ".defaulttemplate-listentry" "css_element" + And I choose "Delete" in the open action menu And I press "Delete" And I should not see "Student edited entry" And I should see "Student second entry" And I should see "Student third entry" - # Now I will bulk delete the rest of the entries. - And I log out - And I am on the "Test database name" "data activity" page logged in as teacher1 - And I press "Select all" - And I press "Delete selected" - And I press "Delete" - And I should see "No entries yet" @javascript @editor @editor_atto @atto @atto_h5p Scenario: If a new text area entry is added, the filepicker is displayed in the H5P Atto button diff --git a/mod/data/tests/behat/manageapproved.feature b/mod/data/tests/behat/manageapproved.feature index 4f86ecba5a7..8257db07da1 100644 --- a/mod/data/tests/behat/manageapproved.feature +++ b/mod/data/tests/behat/manageapproved.feature @@ -41,7 +41,8 @@ Feature: Users can edit approved entries in database activities And I log out # Approve the student's entry as a teacher. And I am on the "Test database name" "data activity" page logged in as teacher1 - And I follow "Approve" + And I open the action menu in ".defaulttemplate-listentry" "css_element" + And I choose "Approve" in the open action menu And I log out # Make sure the student can still edit their entry after it's approved. When I am on the "Test database name" "data activity" page logged in as student1 @@ -73,7 +74,8 @@ Feature: Users can edit approved entries in database activities And I log out # Approve the student's entry as a teacher. And I am on the "Test database name" "data activity" page logged in as teacher1 - And I follow "Approve" + And I open the action menu in ".defaulttemplate-listentry" "css_element" + And I choose "Approve" in the open action menu And I log out # Make sure the student isn't able to edit their entry after it's approved. When I am on the "Test database name" "data activity" page logged in as student1 diff --git a/mod/data/tests/behat/required_entries.feature b/mod/data/tests/behat/required_entries.feature index 1123a1602a0..289dac8533a 100644 --- a/mod/data/tests/behat/required_entries.feature +++ b/mod/data/tests/behat/required_entries.feature @@ -129,26 +129,27 @@ Feature: Users can be required to specify certain fields when adding entries to And I add an entry to "Test database name" database with: | Base Text input | Some input to allow us to submit the otherwise empty form | And I press "Save" - Then ".alert" "css_element" should exist in the "Required Checkbox" "table_row" - And ".alert" "css_element" should exist in the "Required Two-Option Checkbox" "table_row" - And ".alert" "css_element" should exist in the "Required Coordinates" "table_row" - And ".alert" "css_element" should exist in the "Required Menu" "table_row" - And ".alert" "css_element" should exist in the "Required Number" "table_row" - And ".alert" "css_element" should exist in the "Required Radio" "table_row" - And ".alert" "css_element" should exist in the "Required Text input" "table_row" - And ".alert" "css_element" should exist in the "Required Text area" "table_row" - And ".alert" "css_element" should exist in the "Required URL" "table_row" - And ".alert" "css_element" should exist in the "Required Multimenu" "table_row" - And ".alert" "css_element" should exist in the "Required Two-Option Multimenu" "table_row" - And ".alert" "css_element" should not exist in the "Not required Checkbox" "table_row" - And ".alert" "css_element" should not exist in the "Not required Coordinates" "table_row" - And ".alert" "css_element" should not exist in the "Not required Menu" "table_row" - And ".alert" "css_element" should not exist in the "Not required Number" "table_row" - And ".alert" "css_element" should not exist in the "Not required Radio" "table_row" - And ".alert" "css_element" should not exist in the "Not required Text input" "table_row" - And ".alert" "css_element" should not exist in the "Not required Text area" "table_row" - And ".alert" "css_element" should not exist in the "Not required URL" "table_row" - And ".alert" "css_element" should not exist in the "Not required Multimenu" "table_row" +# Then ".alert" "css_element" should exist in the "//div[contains(@id,'defaulttemplate-addentry']//div[position()=1]]" "xpath_element" + Then ".alert" "css_element" should appear after "Checkbox" "text" + And ".alert" "css_element" should appear before "Required Checkbox" "text" + And ".alert" "css_element" should appear after "Two-Option Checkbox" "text" + And ".alert" "css_element" should appear before "Required Two-Option Checkbox" "text" + And ".alert" "css_element" should appear after "Coordinates" "text" + And ".alert" "css_element" should appear before "Required Coordinates" "text" + And ".alert" "css_element" should appear after "Menu" "text" + And ".alert" "css_element" should appear before "Required Menu" "text" + And ".alert" "css_element" should appear after "Radio" "text" + And ".alert" "css_element" should appear before "Required Radio" "text" + And ".alert" "css_element" should appear after "Text input" "text" + And ".alert" "css_element" should appear before "Required Text input" "text" + And ".alert" "css_element" should appear after "Text area" "text" + And ".alert" "css_element" should appear before "Required Text area" "text" + And ".alert" "css_element" should appear after "URL" "text" + And ".alert" "css_element" should appear before "Required URL" "text" + And ".alert" "css_element" should appear after "Multimenu" "text" + And ".alert" "css_element" should appear before "Required Multimenu" "text" + And ".alert" "css_element" should appear after "Two-Option Multimenu" "text" + And ".alert" "css_element" should appear before "Required Two-Option Multimenu" "text" And I am on "Course 1" course homepage And I follow "Test database name" And I should see "No entries yet" @@ -204,6 +205,7 @@ Feature: Users can be required to specify certain fields when adding entries to | Required Multimenu | Option 1 | | Required Two-Option Multimenu | Option 1 | + @javascript Scenario: A student fills in Latitude but not Longitude will see an error Given I log in as "student1" And I am on "Course 1" course homepage @@ -220,10 +222,10 @@ Feature: Users can be required to specify certain fields when adding entries to | Required URL | http://example.com/ | | Required Multimenu | 1 | | Required Two-Option Multimenu | 1 | - And I set the field with xpath "//div[@title='Not required Coordinates']//tr[td/label[normalize-space(.)='Latitude']]/td/input" to "20" + And I set the field "Latitude" to "20" + #And I set the field with xpath "//div[@title='Not required Coordinates']//tr[td/label[normalize-space(.)='Latitude']]/td/input" to "20" And I press "Save" - Then ".alert" "css_element" should exist in the "Required Coordinates" "table_row" - And ".alert" "css_element" should exist in the "Not required Coordinates" "table_row" + Then I should see "Both latitude and longitude are required." Scenario: A student filling in number and text fields with zero will not see an error. Given I log in as "student1" diff --git a/mod/data/tests/behat/view_entries.feature b/mod/data/tests/behat/view_entries.feature index 79be35b744d..7412309d03e 100644 --- a/mod/data/tests/behat/view_entries.feature +++ b/mod/data/tests/behat/view_entries.feature @@ -97,7 +97,8 @@ Feature: Users can view and search database entries And I press "Save" And I should see "Student original entry" And I should see "Tag1" in the "div.tag_list" "css_element" - And I follow "Edit" + And I open the action menu in "#defaulttemplate-single" "css_element" + And I choose "Edit" in the open action menu And I should see "Tag1" in the ".form-autocomplete-selection" "css_element" And I follow "Cancel" And I select "List view" from the "jump" singleselect diff --git a/mod/data/tests/lib_test.php b/mod/data/tests/lib_test.php index 84b09dd9026..0f24e1c20e2 100644 --- a/mod/data/tests/lib_test.php +++ b/mod/data/tests/lib_test.php @@ -2011,7 +2011,7 @@ class lib_test extends \advanced_testcase { 'singletemplate', 'asearchtemplate', ]; - // Check the result is empty when the database has no entries. + // Check the result is empty when the database has no fields. foreach ($templates as $template) { $result = data_generate_default_template($activity, $template, 0, false, false); $this->assertEmpty($result);