MDL-53129 mod_feedback: forms cleanup and behat tests

This commit is contained in:
Marina Glancy 2016-02-16 15:08:19 +08:00
parent 83a951023e
commit 42756192d7
15 changed files with 236 additions and 53 deletions

View File

@ -133,7 +133,7 @@ if ($mygroupid > 0 AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES) {
} }
} }
echo '<div><table width="80%" cellpadding="10"><tr><td>'; echo '<div>';
if ($check_anonymously) { if ($check_anonymously) {
$itemnr = 0; $itemnr = 0;
//print the items in an analysed form //print the items in an analysed form
@ -160,7 +160,7 @@ if ($check_anonymously) {
'insufficient_responses', 'insufficient_responses',
'feedback', '', '', 3); 'feedback', '', '', 3);
} }
echo '</td></tr></table></div>'; echo '</div>';
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
echo $OUTPUT->footer(); echo $OUTPUT->footer();

View File

@ -417,7 +417,7 @@ if ($feedback_can_submit) {
//print the items //print the items
if (is_array($feedbackitems)) { if (is_array($feedbackitems)) {
echo $OUTPUT->box_start('feedback_form'); echo $OUTPUT->box_start('feedback_form');
echo '<form action="complete.php" class="mform" method="post" onsubmit=" ">'; echo '<form action="complete.php" class="feedback_complete" method="post">';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo $OUTPUT->box_start('feedback_anonymousinfo'); echo $OUTPUT->box_start('feedback_anonymousinfo');
switch ($feedback->anonymous) { switch ($feedback->anonymous) {

View File

@ -140,10 +140,6 @@ if (is_array($feedbackitems)) {
$lastposition++; $lastposition++;
//The add_item-form
$add_item_form = new feedback_edit_add_question_form('edit_item.php');
$add_item_form->set_data(array('cmid'=>$id, 'position'=>$lastposition));
//The use_template-form //The use_template-form
$use_template_form = new feedback_edit_use_template_form('use_templ.php'); $use_template_form = new feedback_edit_use_template_form('use_templ.php');
$use_template_form->set_feedbackdata(array('course' => $course)); $use_template_form->set_feedbackdata(array('course' => $course));
@ -237,7 +233,10 @@ if ($do_show == 'templates') {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
if ($do_show == 'edit') { if ($do_show == 'edit') {
$add_item_form->display(); $select = new single_select(new moodle_url('/mod/feedback/edit_item.php', array('cmid' => $id, 'position' => $lastposition)),
'typ', feedback_load_feedback_items_options());
$select->label = get_string('add_item', 'mod_feedback');
echo $OUTPUT->render($select);
if (is_array($feedbackitems)) { if (is_array($feedbackitems)) {
$itemnr = 0; $itemnr = 0;

View File

@ -29,29 +29,6 @@ if (!defined('MOODLE_INTERNAL')) {
require_once($CFG->libdir.'/formslib.php'); require_once($CFG->libdir.'/formslib.php');
class feedback_edit_add_question_form extends moodleform {
public function definition() {
$mform = $this->_form;
//headline
$mform->addElement('header', 'general', get_string('content'));
// visible elements
$feedback_names_options = feedback_load_feedback_items_options();
$attributes = 'onChange="M.core_formchangechecker.set_form_submitted(); this.form.submit()"';
$mform->addElement('select', 'typ', '', $feedback_names_options, $attributes);
// hidden elements
$mform->addElement('hidden', 'cmid');
$mform->setType('cmid', PARAM_INT);
$mform->addElement('hidden', 'position');
$mform->setType('position', PARAM_INT);
// buttons
$mform->addElement('submit', 'add_item', get_string('add_item', 'feedback'), array('class' => 'hiddenifjs'));
}
}
class feedback_edit_use_template_form extends moodleform { class feedback_edit_use_template_form extends moodleform {
private $feedbackdata; private $feedbackdata;

View File

@ -39,7 +39,7 @@ class feedback_label_form extends feedback_item_form {
$mform->setType('label', PARAM_ALPHA); $mform->setType('label', PARAM_ALPHA);
$mform->addElement('header', 'general', get_string($this->type, 'feedback')); $mform->addElement('header', 'general', get_string($this->type, 'feedback'));
$mform->addElement('editor', 'presentation_editor', '', null, $presentationoptions); $mform->addElement('editor', 'presentation_editor', get_string('labelcontents', 'feedback'), null, $presentationoptions);
$mform->setType('presentation_editor', PARAM_RAW); $mform->setType('presentation_editor', PARAM_RAW);
parent::definition(); parent::definition();

View File

@ -244,7 +244,7 @@ class feedback_item_multichoice extends feedback_item_base {
$quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous); $quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous);
$str_quotient = ''; $str_quotient = '';
if ($val->quotient > 0) { if ($val->quotient > 0) {
$str_quotient = '&nbsp;('. $quotient . '&nbsp;%)'; $str_quotient = ' ('. $quotient . ' %)';
} }
echo '<tr>'; echo '<tr>';
echo '<td align="left" valign="top"> echo '<td align="left" valign="top">
@ -252,7 +252,7 @@ class feedback_item_multichoice extends feedback_item_base {
</td> </td>
<td align="left" style="width:'.FEEDBACK_MAX_PIX_LENGTH.';"> <td align="left" style="width:'.FEEDBACK_MAX_PIX_LENGTH.';">
<img class="feedback_bar_image" alt="'.$intvalue.'" src="'.$pix.'" height="5" width="'.$pixwidth.'" /> <img class="feedback_bar_image" alt="'.$intvalue.'" src="'.$pix.'" height="5" width="'.$pixwidth.'" />
&nbsp;'.$val->answercount.$str_quotient.' '.$val->answercount.$str_quotient.'
</td>'; </td>';
echo '</tr>'; echo '</tr>';
} }
@ -717,7 +717,7 @@ class feedback_item_multichoice extends feedback_item_base {
</span> </span>
<span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>"> <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>">
<label for="<?php echo $inputid;?>"> <label for="<?php echo $inputid;?>">
<?php echo format_text($radio, FORMAT_HTML, array('noclean' => true, 'para' => false));?>&nbsp; <?php echo format_text($radio, FORMAT_HTML, array('noclean' => true, 'para' => false));?>
</label> </label>
</span> </span>
</li> </li>

View File

@ -64,12 +64,10 @@ class feedback_multichoice_form extends feedback_item_form {
'hidenoselect', 'hidenoselect',
get_string('hide_no_select_option', 'feedback')); get_string('hide_no_select_option', 'feedback'));
$mform->addElement('static', $mform->addElement('textarea', 'values', get_string('multichoice_values', 'feedback'),
'hint', 'wrap="virtual" rows="10" cols="65"');
get_string('multichoice_values', 'feedback'),
get_string('use_one_line_for_each_value', 'feedback'));
$mform->addElement('textarea', 'values', '', 'wrap="virtual" rows="10" cols="65"'); $mform->addElement('static', 'hint', '', get_string('use_one_line_for_each_value', 'feedback'));
parent::definition(); parent::definition();
$this->set_data($item); $this->set_data($item);

View File

@ -226,7 +226,7 @@ class feedback_item_multichoicerated extends feedback_item_base {
echo '<img class="feedback_bar_image" alt="'.$intvalue.'" src="'.$pix.'" height="5" width="'.$pixwidth.'" />'; echo '<img class="feedback_bar_image" alt="'.$intvalue.'" src="'.$pix.'" height="5" width="'.$pixwidth.'" />';
echo $val->answercount; echo $val->answercount;
if ($val->quotient > 0) { if ($val->quotient > 0) {
echo '&nbsp;('.$quotient.'&nbsp;%)'; echo ' ('.$quotient.' %)';
} else { } else {
echo ''; echo '';
} }

View File

@ -63,16 +63,16 @@ class feedback_multichoicerated_form extends feedback_item_form {
'hidenoselect', 'hidenoselect',
get_string('hide_no_select_option', 'feedback')); get_string('hide_no_select_option', 'feedback'));
$mform->addElement('static',
'hint',
get_string('multichoice_values', 'feedback'),
get_string('use_one_line_for_each_value', 'feedback'));
$this->values = $mform->addElement('textarea', $this->values = $mform->addElement('textarea',
'values', 'values',
'', get_string('multichoice_values', 'feedback'),
'wrap="virtual" rows="10" cols="65"'); 'wrap="virtual" rows="10" cols="65"');
$mform->addElement('static',
'hint',
'',
get_string('use_one_line_for_each_value', 'feedback'));
parent::definition(); parent::definition();
$this->set_data($item); $this->set_data($item);

View File

@ -155,10 +155,8 @@ class feedback_item_textarea extends feedback_item_base {
echo '</th></tr>'; echo '</th></tr>';
foreach ($values as $value) { foreach ($values as $value) {
echo '<tr>'; echo '<tr>';
echo '<td valign="top" align="left">'; echo '<td colspan="2" valign="top" align="left">';
echo '-&nbsp;&nbsp;'; echo '-&nbsp;&nbsp;';
echo '</td>';
echo '<td align="left" valign="top">';
echo str_replace("\n", '<br />', $value->value); echo str_replace("\n", '<br />', $value->value);
echo '</td>'; echo '</td>';
echo '</tr>'; echo '</tr>';

View File

@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
$string['add_item'] = 'Add question to activity'; $string['add_item'] = 'Add question';
$string['add_pagebreak'] = 'Add a page break'; $string['add_pagebreak'] = 'Add a page break';
$string['adjustment'] = 'Adjustment'; $string['adjustment'] = 'Adjustment';
$string['after_submit'] = 'After submission'; $string['after_submit'] = 'After submission';
@ -143,6 +143,7 @@ To keep the feedback anonymous, a minimum of 2 responses must be done.';
$string['item_label'] = 'Label'; $string['item_label'] = 'Label';
$string['item_name'] = 'Question'; $string['item_name'] = 'Question';
$string['label'] = 'Label'; $string['label'] = 'Label';
$string['labelcontents'] = 'Contents';
$string['line_values'] = 'Rating'; $string['line_values'] = 'Rating';
$string['mapcourseinfo'] = 'This is a site-wide feedback that is available to all courses using the feedback block. You can however limit the courses to which it will appear by mapping them. Search the course and map it to this feedback.'; $string['mapcourseinfo'] = 'This is a site-wide feedback that is available to all courses using the feedback block. You can however limit the courses to which it will appear by mapping them. Search the course and map it to this feedback.';
$string['mapcoursenone'] = 'No courses mapped. Feedback available to all courses'; $string['mapcoursenone'] = 'No courses mapped. Feedback available to all courses';

View File

@ -1418,7 +1418,6 @@ function feedback_load_feedback_items_options() {
$feedback_options[$fn] = get_string($fn, 'feedback'); $feedback_options[$fn] = get_string($fn, 'feedback');
} }
asort($feedback_options); asort($feedback_options);
$feedback_options = array_merge( array(' ' => get_string('select')), $feedback_options );
return $feedback_options; return $feedback_options;
} }

View File

@ -0,0 +1,72 @@
<?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/>.
/**
* Steps definitions related to mod_feedback.
*
* @package mod_feedback
* @category test
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
use Behat\Behat\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode,
Behat\Mink\Exception\ExpectationException as ExpectationException;
/**
* Steps definitions related to mod_feedback.
*
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_mod_feedback extends behat_base {
/**
* Adds a question to the existing feedback with filling the form.
*
* The form for creating a question should be on one page.
*
* @When /^I add a "(?P<question_type_string>(?:[^"]|\\")*)" question to the feedback with:$/
* @param string $questiontype
* @param TableNode $questiondata with data for filling the add question form
*/
public function i_add_question_to_the_feedback_with($questiontype, TableNode $questiondata) {
$rv = array();
$questiontype = $this->escape($questiontype);
$additem = $this->escape(get_string('add_item', 'feedback'));
$rv[] = new Given("I select \"{$questiontype}\" from the \"{$additem}\" singleselect");
$newdata = new TableNode();
$rows = $questiondata->getRows();
foreach ($rows as $row) {
foreach ($row as $key => $value) {
$row[$key] = preg_replace('|\\\\n|', "\n", $value);
}
$newdata->addRow($row);
}
$rv[] = new Given('I set the following fields to these values:', $newdata);
$saveitem = $this->escape(get_string('save_item', 'feedback'));
$rv[] = new Given("I press \"{$saveitem}\"");
return $rv;
}
}

View File

@ -0,0 +1,139 @@
@mod @mod_feedback
Feature: Test creating different types of feedback questions
In order to create feedbacks
As a teacher
I need to be able to add different question types
Background:
Given the following "users" exist:
| username | firstname | lastname |
| teacher1 | Teacher | 1 |
| student1 | Student | 1 |
| student2 | Student | 2 |
And the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
| student2 | C1 | student |
And I log in as "admin"
And I navigate to "Manage activities" node in "Site administration > Plugins > Activity modules"
And I click on "Show" "link" in the "Feedback" "table_row"
And I log out
And the following "activities" exist:
| activity | name | course | idnumber |
| feedback | Learning experience | C1 | feedback0 |
When I log in as "teacher1"
And I follow "Course 1"
And I follow "Learning experience"
And I follow "Edit questions"
And I add a "Information" question to the feedback with:
| Question | this is an information question |
| Label | info |
| Information-Type | Course |
And I add a "Label" question to the feedback with:
| Contents | label text |
And I add a "Longer text answer" question to the feedback with:
| Question | this is a longer text answer |
| Label | longertext |
And I add a "Multiple choice" question to the feedback with:
| Question | this is a multiple choice 1 |
| Label | multichoice1 |
| Multiple choice type | Multiple choice - single answer |
| Multiple choice values | option a\noption b\noption c |
And I add a "Multiple choice" question to the feedback with:
| Question | this is a multiple choice 2 |
| Label | multichoice2 |
| Multiple choice type | Multiple choice - multiple answers |
| Hide the "Not selected" option | Yes |
| Multiple choice values | option d\noption e\noption f |
And I add a "Multiple choice" question to the feedback with:
| Question | this is a multiple choice 3 |
| Label | multichoice3 |
| Multiple choice type | Multiple choice - single answer allowed (dropdownlist) |
| Multiple choice values | option g\noption h\noption i |
And I add a "Multiple choice (rated)" question to the feedback with:
| Question | this is a multiple choice rated |
| Label | multichoice4 |
| Multiple choice type | Multiple choice - single answer |
| Multiple choice values | 0/option k\n1/option l\n5/option m |
And I add a "Numeric answer" question to the feedback with:
| Question | this is a numeric answer |
| Label | numeric |
| Range to | 100 |
And I add a "Short text answer" question to the feedback with:
| Question | this is a short text answer |
| Label | shorttext |
| Maximum characters accepted | 200 |
And I log out
And I log in as "student1"
And I follow "Course 1"
And I follow "Learning experience"
And I follow "Answer the questions..."
And I set the following fields to these values:
| this is a longer text answer | my long answer |
| option b | 1 |
| option d | 1 |
| option f | 1 |
| this is a multiple choice 3 | option h |
| option l | 1 |
| this is a numeric answer (0 - 100) | 35 |
| this is a short text answer | hello |
And I press "Submit your answers"
And I log out
And I log in as "student2"
And I follow "Course 1"
And I follow "Learning experience"
And I follow "Answer the questions..."
And I set the following fields to these values:
| this is a longer text answer | lots of feedbacks |
| option a | 1 |
| option d | 1 |
| option e | 1 |
| this is a multiple choice 3 | option i |
| option m | 1 |
| this is a numeric answer (0 - 100) | 71 |
| this is a short text answer | no way |
And I press "Submit your answers"
And I log out
When I log in as "teacher1"
And I follow "Course 1"
And I follow "Learning experience"
And I follow "Analysis"
And I should see "Submitted answers: 2"
And I should see "Questions: 8"
And I log out
And I log in as "teacher1"
And I follow "Course 1"
And I follow "Learning experience"
And I follow "Analysis"
And I should see "C1" in the "(info)" "table"
And I should see "my long answer" in the "(longertext)" "table"
And I should see "lots of feedbacks" in the "(longertext)" "table"
#And I should see "1 (50.00 %)" in the "option a:" "table_row" // TODO: MDL-46891
#And I should see "1 (50.00 %)" in the "option b:" "table_row" // TODO: MDL-46891
And I should see "2 (100.00 %)" in the "option d:" "table_row"
And I should see "1 (50.00 %)" in the "option e:" "table_row"
And I should see "1 (50.00 %)" in the "option f:" "table_row"
And I should see "0" in the "option g:" "table_row"
And I should not see "%" in the "option g:" "table_row"
And I should see "1 (50.00 %)" in the "option h:" "table_row"
And I should see "1 (50.00 %)" in the "option i:" "table_row"
And I should see "0" in the "option k (0):" "table_row"
And I should not see "%" in the "option k (0):" "table_row"
And I should see "1 (50.00 %)" in the "option l (1):" "table_row"
And I should see "1 (50.00 %)" in the "option m (5):" "table_row"
And I should see "Average: 3.00" in the "(multichoice4)" "table"
And I should see "35.00" in the "(numeric)" "table"
And I should see "71.00" in the "(numeric)" "table"
And I should see "Average: 53.00" in the "(numeric)" "table"
And I should see "no way" in the "(shorttext)" "table"
And I should see "hello" in the "(shorttext)" "table"
And I log out
Scenario: Create different types of questions in feedback with javascript disabled
@javascript
Scenario: Create different types of questions in feedback with javascript enabled

View File

@ -51,7 +51,7 @@ Feature: Show users who have not responded to the feedback survey
| Access restrictions | Grouping: GX1 | | Access restrictions | Grouping: GX1 |
And I follow "Frogs" And I follow "Frogs"
And I follow "Edit questions" And I follow "Edit questions"
And I set the field "id_typ" to "Short text answer" And I set the field "Add question" to "Short text answer"
And I set the following fields to these values: And I set the following fields to these values:
| Question | Y/N? | | Question | Y/N? |
And I press "Save question" And I press "Save question"