mirror of
https://github.com/moodle/moodle.git
synced 2025-05-06 16:26:08 +02:00
MDL-62945 Quiz: Increase max group of Question type Gap Select
This commit is contained in:
parent
6e8235c7d3
commit
4889d6ac23
81
question/type/ddwtos/tests/edit_form_test.php
Normal file
81
question/type/ddwtos/tests/edit_form_test.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the drag-and-drop words into sentences edit form.
|
||||
*
|
||||
* @package qtype_ddwtos
|
||||
* @copyright 2018 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
|
||||
require_once($CFG->dirroot . '/question/type/edit_question_form.php');
|
||||
require_once($CFG->dirroot . '/question/type/ddwtos/edit_ddwtos_form.php');
|
||||
|
||||
/**
|
||||
* Unit tests for the drag-and-drop words into sentences edit form.
|
||||
*
|
||||
* @copyright 2012 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class qtype_ddwtos_edit_form_test extends advanced_testcase {
|
||||
/**
|
||||
* Helper method.
|
||||
*
|
||||
* @param string $classname the question form class to instantiate.
|
||||
*
|
||||
* @return question_edit_form great a question form instance that can be tested.
|
||||
*/
|
||||
protected function get_form($classname) {
|
||||
$this->setAdminUser();
|
||||
$this->resetAfterTest();
|
||||
|
||||
$syscontext = context_system::instance();
|
||||
$category = question_make_default_categories(array($syscontext));
|
||||
$fakequestion = new stdClass();
|
||||
$fakequestion->qtype = 'stack';
|
||||
$fakequestion->contextid = $syscontext->id;
|
||||
$fakequestion->createdby = 2;
|
||||
$fakequestion->category = $category->id;
|
||||
$fakequestion->questiontext = 'Test [[1]] question [[2]]';
|
||||
$fakequestion->options = new stdClass();
|
||||
$fakequestion->options->answers = array();
|
||||
$fakequestion->formoptions = new stdClass();
|
||||
$fakequestion->formoptions->movecontext = null;
|
||||
$fakequestion->formoptions->repeatelements = true;
|
||||
$fakequestion->inputs = null;
|
||||
return new $classname(new moodle_url('/'), $fakequestion, $category,
|
||||
new question_edit_contexts($syscontext));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the form shows the right number of groups of choices.
|
||||
*/
|
||||
public function test_number_of_choice_groups() {
|
||||
$form = $this->get_form('qtype_ddwtos_edit_form');
|
||||
// Use reflection to get the protected property we need.
|
||||
$property = new ReflectionProperty('qtype_ddwtos_edit_form', '_form');
|
||||
$property->setAccessible(true);
|
||||
$mform = $property->getValue($form);
|
||||
$choices = $mform->getElement('choices[0]');
|
||||
$groupoptions = $choices->_elements[1];
|
||||
$this->assertCount(8, $groupoptions->_options);
|
||||
}
|
||||
}
|
@ -32,10 +32,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class qtype_gapselect_edit_form_base extends question_edit_form {
|
||||
/**
|
||||
* Maximum number of different groups of drag items there can be in a question.
|
||||
*/
|
||||
const MAX_GROUPS = 8;
|
||||
|
||||
/** @var array of HTML tags allowed in choices / drag boxes. */
|
||||
protected $allowedhtmltags = array(
|
||||
@ -166,15 +162,25 @@ class qtype_gapselect_edit_form_base extends question_edit_form {
|
||||
get_string('addmorechoiceblanks', 'qtype_gapselect'), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return how many different groups of choices there should be.
|
||||
*
|
||||
* @return int the maximum group number.
|
||||
*/
|
||||
function get_maximum_choice_group_number() {
|
||||
return 8;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an array with elements for a choice group.
|
||||
*
|
||||
* @param object $mform The Moodle form we are working with
|
||||
* @param int $maxgroup The number of max group generate element select.
|
||||
* @return array Array for form elements
|
||||
*/
|
||||
protected function choice_group($mform) {
|
||||
$options = array();
|
||||
for ($i = 1; $i <= self::MAX_GROUPS; $i += 1) {
|
||||
for ($i = 1; $i <= $this->get_maximum_choice_group_number(); $i += 1) {
|
||||
$options[$i] = $i;
|
||||
}
|
||||
$grouparray = array();
|
||||
|
@ -41,4 +41,8 @@ class qtype_gapselect_edit_form extends qtype_gapselect_edit_form_base {
|
||||
public function qtype() {
|
||||
return 'gapselect';
|
||||
}
|
||||
|
||||
function get_maximum_choice_group_number() {
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the select missing words question definition class.
|
||||
* Unit tests for the select missing words question edit form.
|
||||
*
|
||||
* @package qtype_gapselect
|
||||
* @copyright 2012 The Open University
|
||||
@ -28,7 +28,7 @@ global $CFG;
|
||||
|
||||
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
|
||||
require_once($CFG->dirroot . '/question/type/edit_question_form.php');
|
||||
require_once($CFG->dirroot . '/question/type/gapselect/edit_form_base.php');
|
||||
require_once($CFG->dirroot . '/question/type/gapselect/edit_gapselect_form.php');
|
||||
|
||||
|
||||
/**
|
||||
@ -38,25 +38,6 @@ require_once($CFG->dirroot . '/question/type/gapselect/edit_form_base.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class qtype_gapselect_edit_form_base_testable extends qtype_gapselect_edit_form_base {
|
||||
public function __construct() {
|
||||
$syscontext = context_system::instance();
|
||||
$category = question_make_default_categories(array($syscontext));
|
||||
$fakequestion = new stdClass();
|
||||
$fakequestion->qtype = 'stack';
|
||||
$fakequestion->contextid = $syscontext->id;
|
||||
$fakequestion->createdby = 2;
|
||||
$fakequestion->category = $category->id;
|
||||
$fakequestion->questiontext = 'Test [[1]] question [[2]]';
|
||||
$fakequestion->options = new stdClass();
|
||||
$fakequestion->options->answers = array();
|
||||
$fakequestion->formoptions = new stdClass();
|
||||
$fakequestion->formoptions->movecontext = null;
|
||||
$fakequestion->formoptions->repeatelements = true;
|
||||
$fakequestion->inputs = null;
|
||||
parent::__construct(new moodle_url('/'), $fakequestion, $category,
|
||||
new question_edit_contexts($syscontext));
|
||||
}
|
||||
|
||||
public function get_illegal_tag_error($text) {
|
||||
return parent::get_illegal_tag_error($text);
|
||||
}
|
||||
@ -72,7 +53,7 @@ class qtype_gapselect_edit_form_base_testable extends qtype_gapselect_edit_form_
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for Stack question editing form.
|
||||
* Unit tests for select missing words question edit form.
|
||||
*
|
||||
* @copyright 2012 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
@ -81,17 +62,35 @@ class qtype_gapselect_edit_form_test extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Helper method.
|
||||
* @return qtype_gapselect_edit_form_base_testable a new form instance that can be tested.
|
||||
*
|
||||
* @param string $classname the question form class to instantiate.
|
||||
*
|
||||
* @return question_edit_form great a question form instance that can be tested.
|
||||
*/
|
||||
protected function get_form() {
|
||||
protected function get_form($classname) {
|
||||
$this->setAdminUser();
|
||||
$this->resetAfterTest();
|
||||
|
||||
return new qtype_gapselect_edit_form_base_testable();
|
||||
$syscontext = context_system::instance();
|
||||
$category = question_make_default_categories(array($syscontext));
|
||||
$fakequestion = new stdClass();
|
||||
$fakequestion->qtype = 'stack';
|
||||
$fakequestion->contextid = $syscontext->id;
|
||||
$fakequestion->createdby = 2;
|
||||
$fakequestion->category = $category->id;
|
||||
$fakequestion->questiontext = 'Test [[1]] question [[2]]';
|
||||
$fakequestion->options = new stdClass();
|
||||
$fakequestion->options->answers = array();
|
||||
$fakequestion->formoptions = new stdClass();
|
||||
$fakequestion->formoptions->movecontext = null;
|
||||
$fakequestion->formoptions->repeatelements = true;
|
||||
$fakequestion->inputs = null;
|
||||
return new $classname(new moodle_url('/'), $fakequestion, $category,
|
||||
new question_edit_contexts($syscontext));
|
||||
}
|
||||
|
||||
public function test_get_illegal_tag_error() {
|
||||
$form = $this->get_form();
|
||||
$form = $this->get_form('qtype_gapselect_edit_form_base_testable');
|
||||
|
||||
$this->assertEquals('', $form->get_illegal_tag_error('frog'));
|
||||
$this->assertEquals('', $form->get_illegal_tag_error('<i>toad</i>'));
|
||||
@ -127,4 +126,18 @@ class qtype_gapselect_edit_form_test extends advanced_testcase {
|
||||
$this->assertEquals(get_string('tagsnotallowedatall', 'qtype_gapselect', $a),
|
||||
$form->get_illegal_tag_error('<i><br /></i>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the form shows the right number of groups of choices.
|
||||
*/
|
||||
public function test_number_of_choice_groups() {
|
||||
$form = $this->get_form('qtype_gapselect_edit_form');
|
||||
// Use reflection to get the protected property we need.
|
||||
$property = new ReflectionProperty('qtype_gapselect_edit_form', '_form');
|
||||
$property->setAccessible(true);
|
||||
$mform = $property->getValue($form);
|
||||
$choices = $mform->getElement('choices[0]');
|
||||
$groupoptions = $choices->_elements[1];
|
||||
$this->assertCount(20, $groupoptions->_options);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user