diff --git a/backup/moodle2/backup_qtype_varnumeric_plugin.class.php b/backup/moodle2/backup_qtype_varnumeric_plugin.class.php
index 1611297..c10ce95 100644
--- a/backup/moodle2/backup_qtype_varnumeric_plugin.class.php
+++ b/backup/moodle2/backup_qtype_varnumeric_plugin.class.php
@@ -52,15 +52,15 @@ protected function define_question_plugin_structure() {
$this->add_question_qtype_varnumeric_vars($pluginwrapper);
// Now create the qtype own structures.
- $varnumeric = new backup_nested_element('varnumeric', array('id'), array(
- 'randomseed', 'recalculateeverytime', 'requirescinotation'));
+ $varnumeric = new backup_nested_element('varnumeric', ['id'], [
+ 'randomseed', 'recalculateeverytime', 'requirescinotation']);
// Now the own qtype tree.
$pluginwrapper->add_child($varnumeric);
// Set source to populate the data.
$varnumeric->set_source_table('qtype_varnumeric',
- array('questionid' => backup::VAR_PARENTID));
+ ['questionid' => backup::VAR_PARENTID]);
// Don't need to annotate ids nor files.
@@ -75,8 +75,8 @@ protected function add_question_qtype_varnumeric_vars($element) {
// Define the elements.
$vars = new backup_nested_element('vars');
- $var = new backup_nested_element('var', array('id'),
- array('varno', 'nameorassignment'));
+ $var = new backup_nested_element('var', ['id'],
+ ['varno', 'nameorassignment']);
$this->add_question_qtype_varnumeric_variants($var);
@@ -86,7 +86,7 @@ protected function add_question_qtype_varnumeric_vars($element) {
// Set source to populate the data.
$var->set_source_table('qtype_varnumeric_vars',
- array('questionid' => backup::VAR_PARENTID));
+ ['questionid' => backup::VAR_PARENTID]);
}
protected function add_question_qtype_varnumeric_variants($element) {
@@ -98,8 +98,8 @@ protected function add_question_qtype_varnumeric_variants($element) {
// Define the elements.
$variants = new backup_nested_element('variants');
- $variant = new backup_nested_element('variant', array('id'),
- array('varid', 'variantno', 'value'));
+ $variant = new backup_nested_element('variant', ['id'],
+ ['varid', 'variantno', 'value']);
// Build the tree.
$element->add_child($variants);
@@ -107,7 +107,7 @@ protected function add_question_qtype_varnumeric_variants($element) {
// Set source to populate the data.
$variant->set_source_table('qtype_varnumeric_variants',
- array('varid' => backup::VAR_PARENTID));
+ ['varid' => backup::VAR_PARENTID]);
}
protected function add_question_qtype_varnumeric_answers($element) {
// Check $element is one nested_backup_element.
@@ -118,9 +118,9 @@ protected function add_question_qtype_varnumeric_answers($element) {
// Define the elements.
$answers = new backup_nested_element('varnumeric_answers');
- $answer = new backup_nested_element('varnumeric_answer', array('id'), array(
+ $answer = new backup_nested_element('varnumeric_answer', ['id'], [
'answerid', 'error', 'sigfigs', 'checknumerical', 'checkscinotation',
- 'checkpowerof10', 'checkrounding', 'syserrorpenalty', 'checkscinotationformat'));
+ 'checkpowerof10', 'checkrounding', 'syserrorpenalty', 'checkscinotationformat']);
// Build the tree.
$element->add_child($answers);
@@ -133,7 +133,7 @@ protected function add_question_qtype_varnumeric_answers($element) {
JOIN {question_answers} ans ON ans.id = vans.answerid
WHERE ans.question = :question
ORDER BY id',
- array('question' => backup::VAR_PARENTID));
+ ['question' => backup::VAR_PARENTID]);
// Don't need to annotate ids or files.
}
}
diff --git a/backup/moodle2/restore_qtype_varnumeric_plugin.class.php b/backup/moodle2/restore_qtype_varnumeric_plugin.class.php
index 9f02838..41d7509 100644
--- a/backup/moodle2/restore_qtype_varnumeric_plugin.class.php
+++ b/backup/moodle2/restore_qtype_varnumeric_plugin.class.php
@@ -34,15 +34,15 @@ class restore_qtype_varnumeric_plugin extends restore_qtype_plugin {
*/
protected function define_question_plugin_structure() {
- $paths = array();
+ $paths = [];
// This qtype uses question_answers, add them.
$this->add_question_question_answers($paths);
- $elements = array('qtype_varnumeric' => '/varnumeric',
+ $elements = ['qtype_varnumeric' => '/varnumeric',
'qtype_varnumeric_answer' => '/varnumeric_answers/varnumeric_answer',
'qtype_varnumeric_var' => '/vars/var',
- 'qtype_varnumeric_variant' => '/vars/var/variants/variant');
+ 'qtype_varnumeric_variant' => '/vars/var/variants/variant'];
foreach ($elements as $elename => $path) {
$elepath = $this->get_pathfor($path);
$paths[] = new restore_path_element($elename, $elepath);
diff --git a/combinable/combinable.php b/combinable/combinable.php
index 9903f0e..e02a5c0 100644
--- a/combinable/combinable.php
+++ b/combinable/combinable.php
@@ -54,13 +54,13 @@ class qtype_combined_combinable_varnumeric extends qtype_combined_combinable_tex
public function add_form_fragment(moodleform $combinedform, MoodleQuickForm $mform, $repeatenabled) {
- $answergroupels = array();
+ $answergroupels = [];
$answergroupels[] = $mform->createElement('text', $this->form_field_name('answer[0]'),
- get_string('answer', 'question'), array('size' => 25));
+ get_string('answer', 'question'), ['size' => 25]);
$answergroupels[] = $mform->createElement('text',
$this->form_field_name('error[0]'),
get_string('error', 'qtype_varnumericset'),
- array('size' => 16));
+ ['size' => 16]);
$mform->setType($this->form_field_name('answer'), PARAM_RAW);
$mform->setType($this->form_field_name('error'), PARAM_RAW);
$mform->addElement('group',
@@ -78,7 +78,7 @@ public function add_form_fragment(moodleform $combinedform, MoodleQuickForm $mfo
}
public function data_to_form($context, $fileoptions) {
- $numericoptions = array('answer' => array(), 'error' => array());
+ $numericoptions = ['answer' => [], 'error' => []];
if ($this->questionrec !== null) {
foreach ($this->questionrec->options->answers as $answer) {
@@ -94,7 +94,7 @@ public function data_to_form($context, $fileoptions) {
}
public function validate() {
- $errors = array();
+ $errors = [];
$interpret = new qtype_varnumericset_number_interpreter_number_with_optional_sci_notation(false);
if ('' !== trim($this->formdata->error[0])) {
if (!$interpret->match($this->formdata->error[0])) {
diff --git a/edit_varnumeric_form.php b/edit_varnumeric_form.php
index 606f190..efac25f 100644
--- a/edit_varnumeric_form.php
+++ b/edit_varnumeric_form.php
@@ -45,12 +45,12 @@ public function definition_inner($mform) {
protected function add_value_form_fields($mform, $repeated, $repeatedoptions) {
$repeated[] = $mform->createElement('text', "variant0",
- get_string('value', 'qtype_varnumeric'), array('size' => 40));
- $repeatedoptions["variant0"]['disabledif'] = array('vartype', 'eq', 0);
- $repeatedoptions["variant0"]['helpbutton'] = array('value', 'qtype_varnumeric');
+ get_string('value', 'qtype_varnumeric'), ['size' => 40]);
+ $repeatedoptions["variant0"]['disabledif'] = ['vartype', 'eq', 0];
+ $repeatedoptions["variant0"]['helpbutton'] = ['value', 'qtype_varnumeric'];
$mform->setType("variant0", PARAM_RAW_TRIMMED);
$this->add_value_form_last_field($mform, $repeated, $repeatedoptions);
- return array($repeated, $repeatedoptions);
+ return [$repeated, $repeatedoptions];
}
protected function validate_variables(int $countvariable, int $maxvariantno): array {
diff --git a/lib.php b/lib.php
index 553c3e6..e878a2c 100644
--- a/lib.php
+++ b/lib.php
@@ -26,7 +26,7 @@
/**
* Checks file access for varnumeric questions.
*/
-function qtype_varnumeric_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
+function qtype_varnumeric_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options= []) {
global $DB, $CFG;
require_once($CFG->libdir . '/questionlib.php');
question_pluginfile($course, $context, 'qtype_varnumeric', $filearea, $args, $forcedownload, $options);
diff --git a/tests/behat/preview.feature b/tests/behat/preview.feature
index 2aa7b34..f50fc60 100644
--- a/tests/behat/preview.feature
+++ b/tests/behat/preview.feature
@@ -29,7 +29,7 @@ Feature: Preview a Variable numeric question
| Marked out of | 3 |
| Question variant | 1 |
| Marks | Show mark and max |
- And I press "Start again with these options"
+ And I press "id_saverestart"
Then I should see "What is 2 + 8?"
And the state of "What is 2 + 8?" question is shown as "Tries remaining: 3"
When I set the field "Answer:" to "2"
diff --git a/tests/evalmathsclass_test.php b/tests/evalmathsclass_test.php
deleted file mode 100644
index 27932f9..0000000
--- a/tests/evalmathsclass_test.php
+++ /dev/null
@@ -1,70 +0,0 @@
-.
-
-/**
- * @package qtype_varnumeric
- * @copyright 2012 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->libdir . '/evalmath/evalmath.class.php');
-
-
-/**
- * Unit tests for the EvalMath expression evaluator, specific to this question type.
- *
- * @copyright 2012 The Open University
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @group qtype_varnumeric
- */
-class qtype_varnumeric_evalmath_test extends basic_testcase {
-
- public function test_basic_expressions() {
- $ev = new EvalMath(true, true);
-
- $this->assertEquals($ev->evaluate('a=2'), 2);
-
- $this->expectWarning();
- $this->assertFalse($ev->evaluate('b=2+'));
- $this->assertEquals($ev->last_error, get_string('operatorlacksoperand', 'mathslib', '+'));
-
- $this->assertEquals($ev->evaluate('a'), 2);
-
- }
-
- public function test_random_expressions() {
- $ev = new EvalMath(true, true);
- $results = array();
- for ($i = 0; $i < 500; $i++) {
- $ev->evaluate("a$i=rand_float()");
- $results[] = $ev->evaluate("a$i");
- }
- $this->assertTrue(min($results) >= 0);
- $this->assertTrue(max($results) <= 1);
-
- $ev = new EvalMath(true, true);
- $results = array();
- for ($i = 0; $i < 500; $i++) {
- $ev->evaluate("a$i=rand_int(500,1000)");
- $results[] = $ev->evaluate("a$i");
- }
- $this->assertTrue(min($results) >= 500 && max($results) <= 1000);
- }
-}
diff --git a/tests/form_test.php b/tests/form_test.php
index a771b2c..67f2a5c 100644
--- a/tests/form_test.php
+++ b/tests/form_test.php
@@ -71,7 +71,7 @@ public function test_form_validation(array $fromform, array $expectederrors): vo
*
* @return array List of data sets (test cases).
*/
- public function form_validation_testcases(): array {
+ public static function form_validation_testcases(): array {
return [
'1 pre-defined variable' => [
[
@@ -83,7 +83,7 @@ public function form_validation_testcases(): array {
'variant0' => [],
'variant1' => [],
],
- []
+ [],
],
];
}
diff --git a/tests/helper.php b/tests/helper.php
index c5d4a37..edf2d1a 100644
--- a/tests/helper.php
+++ b/tests/helper.php
@@ -31,7 +31,7 @@
*/
class qtype_varnumeric_test_helper extends question_test_helper {
public function get_test_questions() {
- return array('no_accepted_error', 'with_variables');
+ return ['no_accepted_error', 'with_variables'];
}
/**
@@ -40,11 +40,11 @@ public function get_test_questions() {
public function get_varnumeric_question_form_data_no_accepted_error() {
$form = new stdClass();
$form->name = 'Pi to two d.p.';
- $form->questiontext = array();
+ $form->questiontext = [];
$form->questiontext['format'] = '1';
$form->questiontext['text'] = 'What is pi to two d.p.?';
$form->defaultmark = 1;
- $form->generalfeedback = array();
+ $form->generalfeedback = [];
$form->generalfeedback['format'] = '1';
$form->generalfeedback['text'] = 'Generalfeedback: 3.14 is the right answer.';
$form->randomseed = '';
diff --git a/tests/question_test.php b/tests/question_test.php
index 171f602..30dd48b 100644
--- a/tests/question_test.php
+++ b/tests/question_test.php
@@ -14,13 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Unit tests for the varnumeric question definition class.
- *
- * @package qtype_varnumeric
- * @copyright 2012 The Open University
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace qtype_varnumeric;
+
+use basic_testcase;
+use qtype_varnumeric_question;
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -32,12 +29,13 @@
/**
* Unit tests for the varnumeric question definition class.
*
+ * @package qtype_varnumeric
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @group qtype_varnumeric
+ * @covers \qtype_varnumeric_question
*/
-class qtype_varnumeric_question_test extends basic_testcase {
- public function test_wrong_by_a_factor_of_ten() {
+class question_test extends basic_testcase {
+ public function test_wrong_by_a_factor_of_ten(): void {
$this->assertTrue(
qtype_varnumeric_question::wrong_by_a_factor_of_ten('1.23e4', 1.23e5, '', 1));
$this->assertFalse(
@@ -52,7 +50,7 @@ public function test_wrong_by_a_factor_of_ten() {
qtype_varnumeric_question::wrong_by_a_factor_of_ten('152000', 150, 1, 3));
}
- public function test_has_number_of_sig_figs() {
+ public function test_has_number_of_sig_figs(): void {
$this->assertTrue(
qtype_varnumeric_question::has_number_of_sig_figs('1.23e4', 3));
$this->assertTrue(
@@ -75,7 +73,7 @@ public function test_has_number_of_sig_figs() {
qtype_varnumeric_question::has_number_of_sig_figs('152000', 2));
}
- public function test_has_too_many_sig_figs() {
+ public function test_has_too_many_sig_figs(): void {
$this->assertTrue(
qtype_varnumeric_question::has_too_many_sig_figs('1.23456', 1.23456, 2));
$this->assertTrue(
@@ -98,7 +96,7 @@ public function test_has_too_many_sig_figs() {
qtype_varnumeric_question::has_too_many_sig_figs('-1.23456e-12', -1.2346e-12, 4));
}
- public function test_rounding_incorrect() {
+ public function test_rounding_incorrect(): void {
$this->assertTrue(
qtype_varnumeric_question::rounding_incorrect('1.234', 1.2345, 4));
$this->assertTrue(
diff --git a/tests/questiontype_test.php b/tests/questiontype_test.php
index 7564bf0..77cd965 100644
--- a/tests/questiontype_test.php
+++ b/tests/questiontype_test.php
@@ -14,33 +14,27 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Unit tests for the varnumeric question type class.
- *
- * @package qtype_varnumeric
- * @copyright 2012 The Open University
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace qtype_varnumeric;
+use basic_testcase;
+use qtype_varnumeric;
+use question_possible_response;
+use stdClass;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/question/type/varnumeric/questiontype.php');
-
/**
* Unit tests for the varnumeric question type class.
*
+ * @package qtype_varnumeric
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @group qtype_varnumeric
+ * @covers qtype_varnumeric
*/
-class qtype_varnumeric_test extends basic_testcase {
- public static $includecoverage = array(
- 'question/type/questiontype.php',
- 'question/type/varnumeric/questiontype.php',
- );
+class questiontype_test extends basic_testcase {
protected $qtype;
@@ -48,37 +42,37 @@ protected function setUp(): void {
$this->qtype = new qtype_varnumeric();
}
- protected function get_test_question_data() {
+ protected function get_test_question_data(): stdClass {
$q = new stdClass();
$q->id = 1;
$q->options = new stdClass();
- $q->options->answers[1] = (object) array('answer' => 'frog', 'fraction' => 1);
- $q->options->answers[2] = (object) array('answer' => '*', 'fraction' => 0.1);
+ $q->options->answers[1] = (object) ['answer' => 'frog', 'fraction' => 1];
+ $q->options->answers[2] = (object) ['answer' => '*', 'fraction' => 0.1];
return $q;
}
- public function test_name() {
+ public function test_name(): void {
$this->assertEquals($this->qtype->name(), 'varnumeric');
}
- public function test_can_analyse_responses() {
+ public function test_can_analyse_responses(): void {
$this->assertTrue($this->qtype->can_analyse_responses());
}
- public function test_get_random_guess_score() {
+ public function test_get_random_guess_score(): void {
$q = $this->get_test_question_data();
$this->assertEquals(0.1, $this->qtype->get_random_guess_score($q));
}
- public function test_get_possible_responses() {
+ public function test_get_possible_responses(): void {
$q = $this->get_test_question_data();
- $this->assertEquals(array(
- $q->id => array(
+ $this->assertEquals([
+ $q->id => [
1 => new question_possible_response('frog', 1),
2 => new question_possible_response('*', 0.1),
- null => question_possible_response::no_response()),
- ), $this->qtype->get_possible_responses($q));
+ null => question_possible_response::no_response()],
+ ], $this->qtype->get_possible_responses($q));
}
}
diff --git a/tests/stats_from_steps_walkthrough_test.php b/tests/stats_from_steps_walkthrough_test.php
index 72bc4a6..06bca82 100644
--- a/tests/stats_from_steps_walkthrough_test.php
+++ b/tests/stats_from_steps_walkthrough_test.php
@@ -14,17 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Quiz attempt walk through using data from csv file.
- *
- * @package quiz_statistics
- * @category phpunit
- * @copyright 2013 The Open University
- * @author Jamie Pratt
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
+namespace qtype_varnumeric;
use mod_quiz\attempt_walkthrough_from_csv_test;
+use question_attempt;
+use question_bank;
+use quiz_statistics_report;
defined('MOODLE_INTERNAL') || die();
@@ -36,13 +31,12 @@
/**
* Quiz attempt walk through using data from csv file.
*
- * @package quiz_statistics
- * @category phpunit
+ * @package qtype_varnumeric
* @copyright 2013 The Open University
* @author Jamie Pratt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class qtype_varnumeric_statistics_from_steps_testcase extends attempt_walkthrough_from_csv_test {
+class statistics_from_steps_testcase extends attempt_walkthrough_from_csv_test {
/**
* @var quiz_statistics_report object to do stats calculations.
@@ -51,18 +45,18 @@ class qtype_varnumeric_statistics_from_steps_testcase extends attempt_walkthroug
protected function get_full_path_of_csv_file($setname, $test): string {
// Overridden here so that __DIR__ points to the path of this file.
- return __DIR__."/fixtures/{$setname}{$test}.csv";
+ return __DIR__ . "/fixtures/{$setname}{$test}.csv";
}
- protected $files = array('questions', 'steps');
+ protected $files = ['questions', 'steps'];
/**
* Create a quiz add questions to it, walk through quiz attempts and then check results.
*
- * @param PHPUnit_Extensions_Database_DataSet_ITable[] of data read from csv file "questionsXX.csv" and "stepsXX.csv"
+ * @param array of data read from csv file "questionsXX.csv" and "stepsXX.csv"
* @dataProvider get_data_for_walkthrough
*/
- public function test_walkthrough_from_csv($quizsettings, $csvdata) {
+ public function test_walkthrough_from_csv($quizsettings, $csvdata): void {
$this->resetAfterTest(true);
question_bank::get_qtype('random')->clear_caches_before_testing();
@@ -76,7 +70,7 @@ public function test_walkthrough_from_csv($quizsettings, $csvdata) {
$whichtries = question_attempt::LAST_TRY;
$groupstudents = new \core\dml\sql_join();
$questions = $this->report->load_and_initialise_questions_for_calculations($this->quiz);
- list($quizstats, $questionstats) = $this->report->get_all_stats_and_analysis(
+ [, $questionstats] = $this->report->get_all_stats_and_analysis(
$this->quiz, $whichattempts, $whichtries, $groupstudents, $questions);
$qubaids = quiz_statistics_qubaids_condition($this->quiz->id, $groupstudents, $whichattempts);
@@ -95,7 +89,7 @@ public function test_walkthrough_from_csv($quizsettings, $csvdata) {
$analysis = $responesstats->load_cached($qubaids, $whichtries);
$variantsnos = $analysis->get_variant_nos();
- $this->assertEquals(array(1), $variantsnos);
+ $this->assertEquals([1], $variantsnos);
$total = 0;
$subpartids = $analysis->get_subpart_ids(1);
$subpartid = current($subpartids);