Merge branch 'MDL-75276-master' of https://github.com/sarjona/moodle

This commit is contained in:
Jun Pataleta 2022-10-04 11:50:57 +08:00
commit 389892ad75
17 changed files with 536 additions and 117 deletions

View file

@ -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);
}

View file

@ -0,0 +1,102 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
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 <sara@moodle.com>
* @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;
}
}

View file

@ -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.
*

View file

@ -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';

View file

@ -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;
}
/**

View file

@ -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.
*

View file

@ -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);

View file

@ -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 <http://www.gnu.org/licenses/>.
}}
{{!
@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]]"
}
]
}
}}
<div id="defaulttemplate-addentry">
{{#fields}}
<div class="form-group pt-3">
<span class="font-weight-bold"><label for="[[{{fieldname}}#id]]">{{fieldname}}</label><br/></span>
{{{fieldcontent}}}
</div>
{{/fields}}
{{#tags}}
<div class="form-group pt-3">
<span class="font-weight-bold">{{#str}}tags{{/str}}<br/></span>
{{{.}}}
</div>
{{/tags}}
</div>

View file

@ -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 <http://www.gnu.org/licenses/>.
}}
{{!
@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]]"
}
]
}
}}
<div class="defaulttemplate-asearch container">
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3">
<div class="form-group col">
<span class="font-weight-bold">{{#str}}authorfirstname, mod_data{{/str}}<br/></span>
##firstname##
</div>
<div class="form-group col">
<span class="font-weight-bold">{{#str}}authorlastname, mod_data{{/str}}<br/></span>
##lastname##
</div>
{{#fields}}
<div class="form-group col">
<span class="font-weight-bold"><label for="[[{{fieldname}}#id]]">{{fieldname}}</label><br/></span>
{{fieldcontent}}
</div>
{{/fields}}
{{#tags}}
<div class="form-group col">
<span class="font-weight-bold">{{#str}}tags{{/str}}<br/></span>
{{.}}
</div>
{{/tags}}
</div>
</div>

View file

@ -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 <http://www.gnu.org/licenses/>.
}}
{{!
@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]]"
}
]
}
}}
<div class="defaulttemplate-listentry my-5 p-5 card">
<div class="d-flex">
<div class="ml-auto">##actionsmenu##</div>
</div>
<div class="defaulttemplate-list-body">
{{#fields}}
<div class="row my-3 align-items-start justify-content-start">
<div class="col-4 col-lg-3 font-weight-bold">{{fieldname}}</div>
<div class="col-8 col-lg-9 ml-n3">{{fieldcontent}}</div>
</div>
{{/fields}}
{{#tags}}
<div class="mb-4">
<span class="font-weight-bold">{{#str}}tags{{/str}}</span>
<p class="mt-2">{{.}}</p>
</div>
{{/tags}}
</div>
</div>

View file

@ -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 <http://www.gnu.org/licenses/>.
}}
{{!
@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]]"
}
]
}
}}
<div id="defaulttemplate-rss">
<div class="defaulttemplate-single-body my-5">
{{#fields}}
<div class="mt-4">
<span class="font-weight-bold">{{fieldname}}</span>
<p class="mt-2">{{fieldcontent}}</p>
</div>
{{/fields}}
</div>
</div>

View file

@ -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 <http://www.gnu.org/licenses/>.
}}
{{!
@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]]"
}
]
}
}}
<div id="defaulttemplate-single" class="my-5">
<div class="d-flex">
<div class="ml-auto mt-n6">##actionsmenu##</div>
</div>
<div class="defaulttemplate-single-body my-5">
<div class="mt-4">
<span class="font-weight-bold">{{#str}}addedby, mod_data{{/str}}</span>
<p class="mt-2">##userpicture## ##user##</p>
</div>
<div class="mt-4">
<span class="font-weight-bold">{{#str}}dateadded, mod_data{{/str}}</span>
<p class="mt-2">##timeadded##</p>
</div>
<div class="mt-4">
<span class="font-weight-bold">{{#str}}datemodified, mod_data{{/str}}</span>
<p class="mt-2">##timemodified##</p>
</div>
{{#fields}}
<div class="mt-4">
<span class="font-weight-bold">{{fieldname}}</span>
<p class="mt-2">{{fieldcontent}}</p>
</div>
{{/fields}}
{{#tags}}
<div class="mt-4">
<span class="font-weight-bold">{{#str}}tags{{/str}}</span>
<p class="mt-2">{{.}}</p>
</div>
{{/tags}}
</div>
</div>

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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);