Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle-qtype_stack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
moodle-qtype_stack
Commits
5b216a63
Commit
5b216a63
authored
8 years ago
by
Tim Hunt
Browse files
Options
Downloads
Patches
Plain Diff
Fix fatal errors during restore with bad PRTs
parent
ba0177a3
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
backup/moodle2/restore_qtype_stack_plugin.class.php
+13
-3
13 additions, 3 deletions
backup/moodle2/restore_qtype_stack_plugin.class.php
tests/helper.php
+339
-0
339 additions, 0 deletions
tests/helper.php
tests/restore_logic_test.php
+105
-0
105 additions, 0 deletions
tests/restore_logic_test.php
with
457 additions
and
3 deletions
backup/moodle2/restore_qtype_stack_plugin.class.php
+
13
−
3
View file @
5b216a63
...
...
@@ -298,7 +298,17 @@ class restore_qtype_stack_plugin extends restore_qtype_plugin {
$graph
->
add_node
(
$node
->
nodename
+
1
,
$left
,
$right
);
}
try
{
$graph
->
layout
();
}
catch
(
coding_exception
$ce
)
{
$question
=
$DB
->
get_record
(
'question'
,
array
(
'id'
=>
$prt
->
questionid
));
$this
->
step
->
log
(
'The PRT named "'
.
$prt
->
name
.
'" is malformed in question id '
.
$prt
->
questionid
.
' and cannot be laid out, (Question name "'
.
$question
->
name
.
'"). Error reported: '
.
$ce
->
getMessage
(),
backup
::
LOG_WARNING
);
continue
;
}
$roots
=
$graph
->
get_roots
();
if
(
count
(
$roots
)
!=
1
||
$graph
->
get_broken_cycles
())
{
$question
=
$DB
->
get_record
(
'question'
,
array
(
'id'
=>
$prt
->
questionid
));
...
...
@@ -309,8 +319,8 @@ class restore_qtype_stack_plugin extends restore_qtype_plugin {
}
$this
->
step
->
log
(
'The PRT named "'
.
$prt
->
name
.
'" is malformed in question id '
.
$prt
->
questionid
.
'
, q
uestion name
d
"'
.
$question
->
name
.
'". Error reported: '
.
$err
,
backup
::
LOG_WARNING
);
'
and does not have a single root, (Q
uestion name "'
.
$question
->
name
.
'"
)
. Error reported: '
.
$err
,
backup
::
LOG_WARNING
);
}
reset
(
$roots
);
$firstnode
=
key
(
$roots
)
-
1
;
...
...
This diff is collapsed.
Click to expand it.
tests/helper.php
+
339
−
0
View file @
5b216a63
...
...
@@ -1427,4 +1427,343 @@ class qtype_stack_test_helper extends question_test_helper {
return
$qdata
;
}
public
function
get_stack_question_form_data_test3
()
{
$formform
=
new
stdClass
();
$formform
->
category
=
'2,14'
;
$formform
->
usecurrentcat
=
'1'
;
$formform
->
categorymoveto
=
'2,14'
;
$formform
->
name
=
'test-3'
;
$formform
->
questionvariables
=
''
;
$formform
->
variantsselectionseed
=
''
;
$formform
->
questiontext
=
array
(
'text'
=>
'<p>1. Give an example of an odd function by typing
an expression which represents it.
$f_1(x)=$ [[input:ans1]].
[[validation:ans1]]
[[feedback:odd]]</p>
<p>2. Give an example of an even function.
$f_2(x)=$ [[input:ans2]].
[[validation:ans2]]
[[feedback:even]]</p>
<p>3. Give an example of a function which is odd and even.
$f_3(x)=$ [[input:ans3]].
[[validation:ans3]]
[[feedback:oddeven]]</p>
<p>4. Is the answer to 3. unique? [[input:ans4]]
(Or are there many different possibilities.)
[[validation:ans4]]
[[feedback:unique]]</p>'
,
'format'
=>
'1'
,
'itemid'
=>
815759888
);
$formform
->
defaultmark
=
4
;
$formform
->
specificfeedback
=
array
(
'text'
=>
''
,
'format'
=>
'1'
,
'itemid'
=>
137873291
);
$formform
->
penalty
=
0.40000000000000002
;
$formform
->
generalfeedback
=
array
(
'text'
=>
''
,
'format'
=>
'1'
,
'itemid'
=>
250226104
);
$formform
->
questionnote
=
''
;
$formform
->
ans1type
=
'algebraic'
;
$formform
->
ans1modelans
=
'x^3'
;
$formform
->
ans1boxsize
=
15
;
$formform
->
ans1strictsyntax
=
'1'
;
$formform
->
ans1insertstars
=
'0'
;
$formform
->
ans1syntaxhint
=
''
;
$formform
->
ans1forbidwords
=
''
;
$formform
->
ans1allowwords
=
''
;
$formform
->
ans1forbidfloat
=
'1'
;
$formform
->
ans1requirelowestterms
=
'0'
;
$formform
->
ans1checkanswertype
=
'0'
;
$formform
->
ans1mustverify
=
'1'
;
$formform
->
ans1showvalidation
=
'1'
;
$formform
->
ans1options
=
''
;
$formform
->
ans2type
=
'algebraic'
;
$formform
->
ans2modelans
=
'x^4'
;
$formform
->
ans2boxsize
=
15
;
$formform
->
ans2strictsyntax
=
'1'
;
$formform
->
ans2insertstars
=
'0'
;
$formform
->
ans2syntaxhint
=
''
;
$formform
->
ans2forbidwords
=
''
;
$formform
->
ans2allowwords
=
''
;
$formform
->
ans2forbidfloat
=
'1'
;
$formform
->
ans2requirelowestterms
=
'0'
;
$formform
->
ans2checkanswertype
=
'0'
;
$formform
->
ans2mustverify
=
'1'
;
$formform
->
ans2showvalidation
=
'1'
;
$formform
->
ans2options
=
''
;
$formform
->
ans3type
=
'algebraic'
;
$formform
->
ans3modelans
=
'0'
;
$formform
->
ans3boxsize
=
15
;
$formform
->
ans3strictsyntax
=
'1'
;
$formform
->
ans3insertstars
=
'0'
;
$formform
->
ans3syntaxhint
=
''
;
$formform
->
ans3forbidwords
=
''
;
$formform
->
ans3allowwords
=
''
;
$formform
->
ans3forbidfloat
=
'1'
;
$formform
->
ans3requirelowestterms
=
'0'
;
$formform
->
ans3checkanswertype
=
'0'
;
$formform
->
ans3mustverify
=
'1'
;
$formform
->
ans3showvalidation
=
'1'
;
$formform
->
ans3options
=
''
;
$formform
->
ans4type
=
'boolean'
;
$formform
->
ans4modelans
=
'true'
;
$formform
->
ans4boxsize
=
15
;
$formform
->
ans4strictsyntax
=
'1'
;
$formform
->
ans4insertstars
=
'0'
;
$formform
->
ans4syntaxhint
=
''
;
$formform
->
ans4forbidwords
=
''
;
$formform
->
ans4allowwords
=
''
;
$formform
->
ans4forbidfloat
=
'1'
;
$formform
->
ans4requirelowestterms
=
'0'
;
$formform
->
ans4checkanswertype
=
'0'
;
$formform
->
ans4mustverify
=
'0'
;
$formform
->
ans4showvalidation
=
'0'
;
$formform
->
ans4options
=
''
;
$formform
->
oddvalue
=
1
;
$formform
->
oddautosimplify
=
'1'
;
$formform
->
oddfeedbackvariables
=
'sa:subst(x=-x,ans1)+ans1'
;
$formform
->
oddanswertest
=
array
(
0
=>
'AlgEquiv'
);
$formform
->
oddsans
=
array
(
0
=>
'sa'
);
$formform
->
oddtans
=
array
(
0
=>
'0'
);
$formform
->
oddtestoptions
=
array
(
0
=>
''
);
$formform
->
oddquiet
=
array
(
0
=>
'0'
);
$formform
->
oddtruescoremode
=
array
(
0
=>
'='
);
$formform
->
oddtruescore
=
array
(
0
=>
'1'
);
$formform
->
oddtruepenalty
=
array
(
0
=>
''
);
$formform
->
oddtruenextnode
=
array
(
0
=>
'-1'
);
$formform
->
oddtrueanswernote
=
array
(
0
=>
'odd-1-T'
);
$formform
->
oddtruefeedback
=
array
(
0
=>
array
(
'text'
=>
''
,
'format'
=>
'1'
,
'itemid'
=>
251659256
,
));
$formform
->
oddfalsescoremode
=
array
(
0
=>
'='
);
$formform
->
oddfalsescore
=
array
(
0
=>
'0'
);
$formform
->
oddfalsepenalty
=
array
(
0
=>
''
);
$formform
->
oddfalsenextnode
=
array
(
0
=>
'-1'
);
$formform
->
oddfalseanswernote
=
array
(
0
=>
'odd-1-F'
);
$formform
->
oddfalsefeedback
=
array
(
0
=>
array
(
'text'
=>
'Your answer is not an odd function. Look, \\[ f(x)+f(-x)=@sa@ \\neq 0.\\]<br>'
,
'format'
=>
'1'
,
'itemid'
=>
352216298
,
));
$formform
->
evenvalue
=
1
;
$formform
->
evenautosimplify
=
'1'
;
$formform
->
evenfeedbackvariables
=
'sa:subst(x=-x,ans2)-ans2'
;
$formform
->
evenanswertest
=
array
(
0
=>
'AlgEquiv'
);
$formform
->
evensans
=
array
(
0
=>
'sa'
);
$formform
->
eventans
=
array
(
0
=>
'0'
);
$formform
->
eventestoptions
=
array
(
0
=>
''
);
$formform
->
evenquiet
=
array
(
0
=>
'0'
);
$formform
->
eventruescoremode
=
array
(
0
=>
'='
);
$formform
->
eventruescore
=
array
(
0
=>
'1'
);
$formform
->
eventruepenalty
=
array
(
0
=>
''
);
$formform
->
eventruenextnode
=
array
(
0
=>
'-1'
);
$formform
->
eventrueanswernote
=
array
(
0
=>
'even-1-T'
);
$formform
->
eventruefeedback
=
array
(
0
=>
array
(
'text'
=>
''
,
'format'
=>
'1'
,
'itemid'
=>
374097881
,
));
$formform
->
evenfalsescoremode
=
array
(
0
=>
'='
);
$formform
->
evenfalsescore
=
array
(
0
=>
'0'
);
$formform
->
evenfalsepenalty
=
array
(
0
=>
''
);
$formform
->
evenfalsenextnode
=
array
(
0
=>
'-1'
);
$formform
->
evenfalseanswernote
=
array
(
0
=>
'even-1-F'
);
$formform
->
evenfalsefeedback
=
array
(
0
=>
array
(
'text'
=>
'<p>Your answer is not an even function. Look, \\[ f(x)-f(-x)=@sa@ \\neq 0.\\]<br></p>'
,
'format'
=>
'1'
,
'itemid'
=>
880424514
,
));
$formform
->
oddevenvalue
=
1
;
$formform
->
oddevenautosimplify
=
'1'
;
$formform
->
oddevenfeedbackvariables
=
'sa1:ans3+subst(x=-x,ans3); sa2:ans3-subst(x=-x,ans3)'
;
$formform
->
oddevenanswertest
=
array
(
0
=>
'AlgEquiv'
,
1
=>
'AlgEquiv'
);
$formform
->
oddevensans
=
array
(
0
=>
'sa1'
,
1
=>
'sa2'
);
$formform
->
oddeventans
=
array
(
0
=>
'0'
,
1
=>
'0'
);
$formform
->
oddeventestoptions
=
array
(
0
=>
''
,
1
=>
''
);
$formform
->
oddevenquiet
=
array
(
0
=>
'0'
,
1
=>
'0'
);
$formform
->
oddeventruescoremode
=
array
(
0
=>
'='
,
1
=>
'+'
);
$formform
->
oddeventruescore
=
array
(
0
=>
'0.5'
,
1
=>
'0.5'
);
$formform
->
oddeventruepenalty
=
array
(
0
=>
''
,
1
=>
''
);
$formform
->
oddeventruenextnode
=
array
(
0
=>
'1'
,
1
=>
'-1'
);
$formform
->
oddeventrueanswernote
=
array
(
0
=>
'oddeven-1-T'
,
1
=>
'oddeven-2-T'
);
$formform
->
oddeventruefeedback
=
array
(
0
=>
array
(
'text'
=>
''
,
'format'
=>
'1'
,
'itemid'
=>
90882068
),
1
=>
array
(
'text'
=>
''
,
'format'
=>
'1'
,
'itemid'
=>
201325868
));
$formform
->
oddevenfalsescoremode
=
array
(
0
=>
'='
,
1
=>
'+'
);
$formform
->
oddevenfalsescore
=
array
(
0
=>
'0'
,
1
=>
'0'
);
$formform
->
oddevenfalsepenalty
=
array
(
0
=>
''
,
1
=>
''
);
$formform
->
oddevenfalsenextnode
=
array
(
0
=>
'1'
,
1
=>
'-1'
);
$formform
->
oddevenfalseanswernote
=
array
(
0
=>
'oddeven-1-F'
,
1
=>
'oddeven-2-F'
);
$formform
->
oddevenfalsefeedback
=
array
(
0
=>
array
(
'text'
=>
'<p>Your answer is not an odd function. Look, \\[ f(x)+f(-x)=@sa1@ \\neq 0.\\]<br></p>'
,
'format'
=>
'1'
,
'itemid'
=>
387904086
),
1
=>
array
(
'text'
=>
'<p>Your answer is not an even function. Look, \\[ f(x)-f(-x)=@sa2@ \\neq 0.\\]<br></p>'
,
'format'
=>
'1'
,
'itemid'
=>
212217540
));
$formform
->
uniquevalue
=
1
;
$formform
->
uniqueautosimplify
=
'1'
;
$formform
->
uniquefeedbackvariables
=
''
;
$formform
->
uniqueanswertest
=
array
(
0
=>
'AlgEquiv'
);
$formform
->
uniquesans
=
array
(
0
=>
'ans4'
);
$formform
->
uniquetans
=
array
(
0
=>
'true'
);
$formform
->
uniquetestoptions
=
array
(
0
=>
''
);
$formform
->
uniquequiet
=
array
(
0
=>
'0'
);
$formform
->
uniquetruescoremode
=
array
(
0
=>
'='
);
$formform
->
uniquetruescore
=
array
(
0
=>
'1'
);
$formform
->
uniquetruepenalty
=
array
(
0
=>
''
);
$formform
->
uniquetruenextnode
=
array
(
0
=>
'-1'
);
$formform
->
uniquetrueanswernote
=
array
(
0
=>
'unique-1-T'
);
$formform
->
uniquetruefeedback
=
array
(
0
=>
array
(
'text'
=>
''
,
'format'
=>
'1'
,
'itemid'
=>
692993996
));
$formform
->
uniquefalsescoremode
=
array
(
0
=>
'='
);
$formform
->
uniquefalsescore
=
array
(
0
=>
'0'
);
$formform
->
uniquefalsepenalty
=
array
(
0
=>
''
);
$formform
->
uniquefalsenextnode
=
array
(
0
=>
'-1'
);
$formform
->
uniquefalseanswernote
=
array
(
0
=>
'unique-1-F'
);
$formform
->
uniquefalsefeedback
=
array
(
0
=>
array
(
'text'
=>
''
,
'format'
=>
'1'
,
'itemid'
=>
55631697
,
));
$formform
->
questionsimplify
=
'1'
;
$formform
->
assumepositive
=
'0'
;
$formform
->
prtcorrect
=
array
(
'text'
=>
'Correct answer, well done!'
,
'format'
=>
'1'
,
'itemid'
=>
847867102
);
$formform
->
prtpartiallycorrect
=
array
(
'text'
=>
'Your answer is partially correct!'
,
'format'
=>
'1'
,
'itemid'
=>
698828552
);
$formform
->
prtincorrect
=
array
(
'text'
=>
'Incorrect answer :-('
,
'format'
=>
'1'
,
'itemid'
=>
56111684
);
$formform
->
multiplicationsign
=
'dot'
;
$formform
->
sqrtsign
=
'1'
;
$formform
->
complexno
=
'i'
;
$formform
->
inversetrig
=
'cos-1'
;
$formform
->
matrixparens
=
'['
;
$formform
->
numhints
=
2
;
$formform
->
hint
=
array
(
0
=>
array
(
'text'
=>
'Hint 1<br>'
,
'format'
=>
'1'
,
'itemid'
=>
'83894244'
),
1
=>
array
(
'text'
=>
'<p>Hint 2<br></p>'
,
'format'
=>
'1'
,
'itemid'
=>
'34635511'
));
$formform
->
qtype
=
'stack'
;
return
$formform
;
}
}
This diff is collapsed.
Click to expand it.
tests/restore_logic_test.php
0 → 100644
+
105
−
0
View file @
5b216a63
<?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/>.
/**
* Unit tests for the restore logic.
*
* @copyright 2017 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
global
$CFG
;
require_once
(
$CFG
->
dirroot
.
'/backup/util/includes/restore_includes.php'
);
require_once
(
$CFG
->
dirroot
.
'/question/type/stack/backup/moodle2/restore_qtype_stack_plugin.class.php'
);
/**
*
*/
class
testable_restore_qtype_stack_plugin
extends
restore_qtype_stack_plugin
{
private
$log
=
''
;
public
function
__construct
()
{
// Passing $this as $step, since we only need some log method, which we implemente below.
parent
::
__construct
(
'qtype'
,
'stack'
,
$this
);
}
/**
* Fake log method.
* @param $message the message.
* @param $level the level.
*/
public
function
log
(
$message
,
$level
)
{
$this
->
log
.
=
$message
.
"
\n
"
;
}
/**
* Fake log method.
* @param $message the message.
* @param $level the level.
*/
public
function
get_task
()
{
return
null
;
}
/**
* Get everything that was logged.
* @return string the log messages, separated by newline.
*/
public
function
get_log
()
{
return
$this
->
log
;
}
public
function
after_execute_question
()
{
// Make method public.
parent
::
after_execute_question
();
}
}
/**
* Unit tests for stack_anstest_numabsolute.
*
* @copyright 2012 The University of Birmingham
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @group qtype_stack
*/
class
qtype_stack_restore_logic_testcase
extends
advanced_testcase
{
public
function
test_fix_prt_roots
()
{
global
$DB
;
$this
->
resetAfterTest
();
$this
->
setAdminUser
();
// Create a test question.
$generator
=
$this
->
getDataGenerator
()
->
get_plugin_generator
(
'core_question'
);
$cat
=
$generator
->
create_question_category
();
$question
=
$generator
->
create_question
(
'stack'
,
'test3'
,
array
(
'category'
=>
$cat
->
id
));
// Break one of its PRTs.
$DB
->
set_field
(
'qtype_stack_prts'
,
'firstnodename'
,
-
1
,
array
(
'questionid'
=>
$question
->
id
,
'name'
=>
'oddeven'
));
$DB
->
set_field
(
'qtype_stack_prt_nodes'
,
'truenextnode'
,
7
,
array
(
'questionid'
=>
$question
->
id
,
'prtname'
=>
'oddeven'
,
'nodename'
=>
0
));
$restoreplugin
=
new
testable_restore_qtype_stack_plugin
();
$restoreplugin
->
after_execute_question
();
$this
->
assertContains
(
'The PRT named "oddeven" is malformed'
,
$restoreplugin
->
get_log
());
$this
->
assertContains
(
'Question name "test-3"'
,
$restoreplugin
->
get_log
());
$this
->
assertContains
(
'Node 8 is not in the graph'
,
$restoreplugin
->
get_log
());
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment