Skip to content

Commit

Permalink
MDL-53129 mod_feedback: forms cleanup and behat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Feb 23, 2016
1 parent 83a9510 commit 4275619
Show file tree
Hide file tree
Showing 15 changed files with 236 additions and 53 deletions.
4 changes: 2 additions & 2 deletions mod/feedback/analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
}
}

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

echo $OUTPUT->footer();
Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/complete.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@
//print the items
if (is_array($feedbackitems)) {
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 $OUTPUT->box_start('feedback_anonymousinfo');
switch ($feedback->anonymous) {
Expand Down
9 changes: 4 additions & 5 deletions mod/feedback/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@
$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
$use_template_form = new feedback_edit_use_template_form('use_templ.php');
$use_template_form->set_feedbackdata(array('course' => $course));
Expand Down Expand Up @@ -237,7 +233,10 @@
///////////////////////////////////////////////////////////////////////////
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)) {
$itemnr = 0;
Expand Down
23 changes: 0 additions & 23 deletions mod/feedback/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,6 @@

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 {
private $feedbackdata;

Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/item/label/label_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function definition() {
$mform->setType('label', PARAM_ALPHA);

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

parent::definition();
Expand Down
6 changes: 3 additions & 3 deletions mod/feedback/item/multichoice/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ public function print_analysed($item, $itemnr = '', $groupid = false, $courseid
$quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous);
$str_quotient = '';
if ($val->quotient > 0) {
$str_quotient = '&nbsp;('. $quotient . '&nbsp;%)';
$str_quotient = ' ('. $quotient . ' %)';
}
echo '<tr>';
echo '<td align="left" valign="top">
-&nbsp;&nbsp;'.trim($val->answertext).':
</td>
<td align="left" style="width:'.FEEDBACK_MAX_PIX_LENGTH.';">
<img class="feedback_bar_image" alt="'.$intvalue.'" src="'.$pix.'" height="5" width="'.$pixwidth.'" />
&nbsp;'.$val->answercount.$str_quotient.'
'.$val->answercount.$str_quotient.'
</td>';
echo '</tr>';
}
Expand Down Expand Up @@ -717,7 +717,7 @@ private function print_item_radio($presentation, $item, $value, $info, $align) {
</span>
<span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>">
<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>
</span>
</li>
Expand Down
8 changes: 3 additions & 5 deletions mod/feedback/item/multichoice/multichoice_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ public function definition() {
'hidenoselect',
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'));
$mform->addElement('textarea', 'values', get_string('multichoice_values', 'feedback'),
'wrap="virtual" rows="10" cols="65"');

$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();
$this->set_data($item);
Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/item/multichoicerated/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function print_analysed($item, $itemnr = '', $groupid = false, $courseid
echo '<img class="feedback_bar_image" alt="'.$intvalue.'" src="'.$pix.'" height="5" width="'.$pixwidth.'" />';
echo $val->answercount;
if ($val->quotient > 0) {
echo '&nbsp;('.$quotient.'&nbsp;%)';
echo ' ('.$quotient.' %)';
} else {
echo '';
}
Expand Down
12 changes: 6 additions & 6 deletions mod/feedback/item/multichoicerated/multichoicerated_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ public function definition() {
'hidenoselect',
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',
'values',
'',
get_string('multichoice_values', 'feedback'),
'wrap="virtual" rows="10" cols="65"');

$mform->addElement('static',
'hint',
'',
get_string('use_one_line_for_each_value', 'feedback'));

parent::definition();
$this->set_data($item);

Expand Down
4 changes: 1 addition & 3 deletions mod/feedback/item/textarea/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,8 @@ public function print_analysed($item, $itemnr = '', $groupid = false, $courseid
echo '</th></tr>';
foreach ($values as $value) {
echo '<tr>';
echo '<td valign="top" align="left">';
echo '<td colspan="2" valign="top" align="left">';
echo '-&nbsp;&nbsp;';
echo '</td>';
echo '<td align="left" valign="top">';
echo str_replace("\n", '<br />', $value->value);
echo '</td>';
echo '</tr>';
Expand Down
3 changes: 2 additions & 1 deletion mod/feedback/lang/en/feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @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['adjustment'] = 'Adjustment';
$string['after_submit'] = 'After submission';
Expand Down Expand Up @@ -143,6 +143,7 @@
$string['item_label'] = 'Label';
$string['item_name'] = 'Question';
$string['label'] = 'Label';
$string['labelcontents'] = 'Contents';
$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['mapcoursenone'] = 'No courses mapped. Feedback available to all courses';
Expand Down
1 change: 0 additions & 1 deletion mod/feedback/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,6 @@ function feedback_load_feedback_items_options() {
$feedback_options[$fn] = get_string($fn, 'feedback');
}
asort($feedback_options);
$feedback_options = array_merge( array(' ' => get_string('select')), $feedback_options );
return $feedback_options;
}

Expand Down
72 changes: 72 additions & 0 deletions mod/feedback/tests/behat/behat_mod_feedback.php
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading

0 comments on commit 4275619

Please sign in to comment.