Skip to content
Snippets Groups Projects
Commit 6a3b33bd authored by Tim Hunt's avatar Tim Hunt
Browse files

Start filling in the skeleton of the question test script.

parent bdf9a694
Branches
No related tags found
No related merge requests found
......@@ -200,6 +200,15 @@ $string['true'] = 'True';
$string['ddl_empty'] = 'No choices were provided for this drop-down. Please input a set of values link a,b,c,d';
// Strings used by the question test script
$string['inputdisplayed'] = 'Displayed as';
$string['inputentered'] = 'Value entered';
$string['inputname'] = 'Input name';
$string['inputstatus'] = 'Status';
$string['inputstatusname'] = 'Blank';
$string['inputstatusnameinvalid'] = 'Invalid';
$string['inputstatusnamevalid'] = 'Valid';
$string['inputstatusnamescore'] = 'Score';
$string['notestcasesyet'] = 'No test cases have been defined yet.';
$string['questiontests'] = 'Question tests';
$string['runquestiontests'] = 'Run the question tests...';
$string['testcasex'] = 'Test case {$a}';
......
......@@ -438,4 +438,12 @@ class qtype_stack_question extends question_graded_automatically {
public function user_can_edit() {
return $this->has_question_capability('edit');
}
public function get_all_question_vars() {
$vars = array();
foreach ($this->session->get_all_keys() as $key) {
$vars[$key] = $this->session->get_value_key($key);
}
return $vars;
}
}
<?php
// This file is part of Stack - http://stack.bham.ac.uk/
//
// Stack 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.
//
// Stack 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 Stack. If not, see <http://www.gnu.org/licenses/>.
/**
* Holds the data defining one question test.
*
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__) . '/questiontestresult.php');
/**
* One question test.
*
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class stack_question_test {
/**
* @var array input name => value to be entered.
*/
public $inputs;
/**
* @var array prt name => stack_potentialresponse_tree_state object
*/
public $expectedresults;
/**
* Constructor
* @param array $inputs input name => value to enter.
*/
public function __construct($inputs) {
$this->inputs = $inputs;
}
/**
* Set the expected result for one of the PRTs.
* @param string $prtname which PRT.
* @param stack_potentialresponse_tree_state $expectedresult the expected result
* for this PRT. Only the mark, penalty and answernote fields are used.
*/
public function add_expected_result($prtname, stack_potentialresponse_tree_state $expectedresult) {
$this->expectedresults[$prtname] = $expectedresult;
}
/**
* Run this test against a particular question.
* @param question_usage_by_activity $quba the useage to use when running the test.
* @param qtype_stack_question $question the question to test.
* @param int $seed the random seed to use.
* @return stack_question_test_result the test results.
*/
public function test_question(question_usage_by_activity $quba, qtype_stack_question $question, $seed) {
$response = array();
foreach ($this->inputs as $name => $value) {
$response[$name] = $value;
$response[$name . '_val'] = $value;
}
$slot = $quba->add_question($question, $question->defaultmark);
$quba->start_question($slot, $seed);
$quba->process_action($slot, $response);
$results = new stack_question_test_result($this);
foreach ($this->inputs as $inputname => $notused) {
$inputstate = $question->get_input_state($inputname, $response);
$results->set_input_state($inputname,
$inputstate->contentsinterpreted, $inputstate->status);
}
foreach ($this->expectedresults as $prtname => $expectedresult) {
$result = $question->get_prt_result($prtname, $response);
$results->set_prt_result($prtname, new stack_potentialresponse_tree_state(
'', $result['feedback'], $result['answernote'],
$result['valid'], $result['score'], $result['penalty']));
}
return $results;
}
/**
* @param string $inputname the name of one of the inputs.
* @return string the value to be entered into that input.
*/
public function get_input($inputname) {
return $this->inputs[$inputname];
}
}
<?php
// This file is part of Stack - http://stack.bham.ac.uk/
//
// Stack 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.
//
// Stack 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 Stack. If not, see <http://www.gnu.org/licenses/>.
/**
* Holds the results of one {@link stack_question_test).
*
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__) . '/questiontestresult.php');
/**
* Holds the results of one {@link stack_question_test).
*
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class stack_question_test_result {
/**
* @var stack_question_test the test case that this is the results for.
*/
public $testcase;
/**
* @var array input name => the displayed value of that input.
*/
public $inputvalues;
/**
* @var array input name => the input statues. One of the stack_input::STATUS_... constants.
*/
public $inputstatuses;
/**
* @var array prt name => stack_potentialresponse_tree_state object
*/
public $actualresults;
/**
* Constructor
* @param stack_question_test $testcase the testcase this is the results for.
*/
public function __construct(stack_question_test $testcase) {
$this->testcase = $testcase;
}
/**
* Set the part of the results data that describes the state of one of the inputs.
* @param string $inputname the input name.
* @param string $displayvalue the displayed version of the value that was input.
* @param string $status one of the stack_input::STATUS_... constants.
*/
public function set_input_state($inputname, $displayvalue, $status) {
$this->inputvalues[$inputname] = $displayvalue;
$this->inputstatuses[$inputname] = $status;
}
public function set_prt_result($prtname, stack_potentialresponse_tree_state $actualresult) {
$this->actualresults[$prtname] = $actualresult;
}
/**
* @return array input name => object with fields ->input, ->display and ->status.
*/
public function get_input_states() {
$states = array();
foreach ($this->inputvalues as $inputname => $inputvalue) {
$state = new stdClass();
$state->input = $this->testcase->get_input($inputname);
$state->display = $inputvalue;
$state->status = $this->inputstatuses[$inputname];
$states[$inputname] = $state;
}
return $states;
}
/**
* @return bool whether the test passed successfully.
*/
public function passed() {
// TODO
return true;
}
}
......@@ -35,11 +35,7 @@ require_once(dirname(__FILE__).'/../../../config.php');
require_once($CFG->libdir . '/questionlib.php');
require_once(dirname(__FILE__) . '/locallib.php');
require_once(dirname(__FILE__) . '/stack/utils.class.php');
require_once(dirname(__FILE__) . '/stack/options.class.php');
require_once(dirname(__FILE__) . '/stack/cas/castext.class.php');
require_once(dirname(__FILE__) . '/stack/cas/casstring.class.php');
require_once(dirname(__FILE__) . '/stack/cas/cassession.class.php');
require_once(dirname(__FILE__) . '/stack/questiontest.php');
// Get the parameters from the URL.
......@@ -79,11 +75,14 @@ $options->flags = question_display_options::HIDDEN;
$options->suppressruntestslink = true;
// Load the list of test cases.
$testscases = array(null);
$testscases = array();
// TODO
// Exectue the tests.
// TODO
$testresults = array();
foreach ($testscases as $key => $testcase) {
$testresults[$key] = $testcase->test_question($quba, $question, $seed);
}
// Start output.
echo $OUTPUT->header();
......@@ -101,15 +100,42 @@ echo html_writer::tag('p', $question->get_question_summary());
// Display the question variables.
echo $OUTPUT->heading(get_string('questionvariables', 'qtype_stack'), 3);
foreach ($question->get_all_question_vars() as $key => $value) {
echo html_writer::tag('p', s($key) . ' = ' . s($value));
}
// Display the controls to add another question test.
echo $OUTPUT->heading(get_string('questiontests', 'qtype_stack'), 3);
// TODO
// Display the test results.
foreach ($testscases as $key => $results) {
if (empty($testresults)) {
echo html_writer::tag('p', get_string('notestcasesyet', 'qtype_stack'));
}
foreach ($testresults as $key => $result) {
echo $OUTPUT->heading(get_string('testcasex', 'qtype_stack', $key + 1), 3);
// TODO
$inputstable = new html_table();
$inputstable->head = array(
get_string('inputname', 'qtype_stack'),
get_string('inputentered', 'qtype_stack'),
get_string('inputdisplayed', 'qtype_stack'),
get_string('inputstatus', 'qtype_stack'),
);
$inputstable->attributes['class'] = 'generaltable qtype_stack-question-test';
foreach ($result->get_input_states() as $inputname => $inputstate) {
$inputstable->data[] = array(
s($inputname),
s($inputstate->input),
$inputstate->display,
get_string('inputstatusname' . $inputstate->status, 'qtype_stack'),
);
}
echo html_writer::table($inputstable);
// TODO display the PRT results.
}
// Finish output.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment