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
cf1a3fb4
Commit
cf1a3fb4
authored
2 years ago
by
Chris Sangwin
Browse files
Options
Downloads
Patches
Plain Diff
Move test result HTML creation to stack/questiontestresult.php.
parent
92155f16
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
questiontestrun.php
+1
-115
1 addition, 115 deletions
questiontestrun.php
stack/questiontestresult.php
+123
-0
123 additions, 0 deletions
stack/questiontestresult.php
with
124 additions
and
115 deletions
questiontestrun.php
+
1
−
115
View file @
cf1a3fb4
...
@@ -465,124 +465,10 @@ if ($canedit) {
...
@@ -465,124 +465,10 @@ if ($canedit) {
}
}
foreach
(
$testresults
as
$key
=>
$result
)
{
foreach
(
$testresults
as
$key
=>
$result
)
{
if
(
$result
->
passed
())
{
$outcome
=
html_writer
::
tag
(
'span'
,
stack_string
(
'testsuitepass'
),
array
(
'class'
=>
'pass'
));
}
else
{
$outcome
=
html_writer
::
tag
(
'span'
,
stack_string
(
'testsuitefail'
),
array
(
'class'
=>
'fail'
));
}
echo
$OUTPUT
->
heading
(
stack_string
(
'testcasexresult'
,
array
(
'no'
=>
$key
,
'result'
=>
$outcome
)),
3
);
if
(
$result
->
emptytestcase
)
{
echo
html_writer
::
tag
(
'p'
,
stack_string_error
(
'questiontestempty'
));
}
// Display the information about the inputs.
$inputstable
=
new
html_table
();
$inputstable
->
head
=
array
(
stack_string
(
'inputname'
),
stack_string
(
'inputexpression'
),
stack_string
(
'inputentered'
),
stack_string
(
'inputdisplayed'
),
stack_string
(
'inputstatus'
),
stack_string
(
'errors'
),
);
$inputstable
->
attributes
[
'class'
]
=
'generaltable stacktestsuite'
;
$typeininputs
=
array
();
foreach
(
$result
->
get_input_states
()
as
$inputname
=>
$inputstate
)
{
$inputval
=
$inputstate
->
input
;
if
(
false
===
$inputstate
->
input
)
{
$inputval
=
''
;
}
else
{
if
(
$inputval
!==
''
)
{
$typeininputs
[
$inputname
]
=
$inputname
.
':'
.
$inputstate
->
modified
.
";
\n
"
;
}
}
$inputstable
->
data
[]
=
array
(
s
(
$inputname
),
s
(
$inputstate
->
rawinput
),
s
(
$inputval
),
stack_ouput_castext
(
$inputstate
->
display
),
stack_string
(
'inputstatusname'
.
$inputstate
->
status
),
$inputstate
->
errors
,
);
}
echo
html_writer
::
table
(
$inputstable
);
echo
$result
->
html_output
(
$question
,
$key
);
flush
();
// Force output to prevent timeouts and to make progress clear.
flush
();
// Force output to prevent timeouts and to make progress clear.
// Display the information about the PRTs.
$prtstable
=
new
html_table
();
$prtstable
->
head
=
array
(
stack_string
(
'prtname'
),
stack_string
(
'score'
),
stack_string
(
'expectedscore'
),
stack_string
(
'penalty'
),
stack_string
(
'expectedpenalty'
),
stack_string
(
'answernote'
),
stack_string
(
'expectedanswernote'
),
get_string
(
'feedback'
,
'question'
),
stack_string
(
'testsuitecolpassed'
),
);
$prtstable
->
attributes
[
'class'
]
=
'generaltable stacktestsuite'
;
$debuginfo
=
''
;
$inputsneeded
=
$question
->
get_cached
(
'required'
);
foreach
(
$result
->
get_prt_states
()
as
$prtname
=>
$state
)
{
$prtinputs
=
array
();
if
(
$inputsneeded
!=
null
)
{
foreach
(
array_keys
(
$inputsneeded
[
$prtname
])
as
$inputname
)
{
if
(
array_key_exists
(
$inputname
,
$typeininputs
))
{
$prtinputs
[]
=
$typeininputs
[
$inputname
];
}
}
}
if
(
$state
->
testoutcome
)
{
$prtstable
->
rowclasses
[]
=
'pass'
;
$passedcol
=
stack_string
(
'testsuitepass'
);
}
else
{
$prtstable
->
rowclasses
[]
=
'fail'
;
$passedcol
=
stack_string
(
'testsuitefail'
)
.
$state
->
reason
;
}
// Sort out excessive decimal places from the DB.
if
(
is_null
(
$state
->
expectedscore
)
||
''
===
$state
->
expectedscore
)
{
$expectedscore
=
''
;
}
else
{
$expectedscore
=
$state
->
expectedscore
+
0
;
}
if
(
is_null
(
$state
->
expectedpenalty
)
||
''
===
$state
->
expectedpenalty
)
{
$expectedpenalty
=
stack_string
(
'questiontestsdefault'
);
}
else
{
// Single PRTs only work to four decimal places, so we only expect that level.
$expectedpenalty
=
round
(
$state
->
expectedpenalty
+
0
,
4
);
}
$answernotedisplay
=
html_writer
::
tag
(
'summary'
,
s
(
$state
->
answernote
))
.
html_writer
::
tag
(
'pre'
,
implode
(
''
,
$prtinputs
)
.
$state
->
trace
);
$answernotedisplay
=
html_writer
::
tag
(
'details'
,
$answernotedisplay
);
$prtstable
->
data
[]
=
array
(
$prtname
,
$state
->
score
,
$expectedscore
,
$state
->
penalty
,
$expectedpenalty
,
$answernotedisplay
,
s
(
$state
->
expectedanswernote
),
format_text
(
$state
->
feedback
),
$passedcol
,
);
// TODO: reinstate debuginfo here.
}
echo
html_writer
::
table
(
$prtstable
);
flush
();
// Force output to prevent timeouts and to make progress clear.
echo
$debuginfo
;
if
(
$canedit
)
{
if
(
$canedit
)
{
echo
html_writer
::
start_tag
(
'div'
,
array
(
'class'
=>
'testcasebuttons'
));
echo
html_writer
::
start_tag
(
'div'
,
array
(
'class'
=>
'testcasebuttons'
));
echo
$OUTPUT
->
single_button
(
new
moodle_url
(
'/question/type/stack/questiontestedit.php'
,
echo
$OUTPUT
->
single_button
(
new
moodle_url
(
'/question/type/stack/questiontestedit.php'
,
...
...
This diff is collapsed.
Click to expand it.
stack/questiontestresult.php
+
123
−
0
View file @
cf1a3fb4
...
@@ -226,4 +226,127 @@ class stack_question_test_result {
...
@@ -226,4 +226,127 @@ class stack_question_test_result {
}
}
return
true
;
return
true
;
}
}
/**
* Create an HTML output of the test result.
*/
public
function
html_output
(
$question
,
$key
=
null
)
{
$html
=
''
;
if
(
$this
->
passed
())
{
$outcome
=
html_writer
::
tag
(
'span'
,
stack_string
(
'testsuitepass'
),
array
(
'class'
=>
'pass'
));
}
else
{
$outcome
=
html_writer
::
tag
(
'span'
,
stack_string
(
'testsuitefail'
),
array
(
'class'
=>
'fail'
));
}
if
(
$key
!==
null
)
{
$html
.
=
html_writer
::
tag
(
'h3'
,
stack_string
(
'testcasexresult'
,
array
(
'no'
=>
$key
,
'result'
=>
$outcome
)));
}
if
(
$this
->
emptytestcase
)
{
$html
.
=
html_writer
::
tag
(
'p'
,
stack_string_error
(
'questiontestempty'
));
}
// Display the information about the inputs.
$inputstable
=
new
html_table
();
$inputstable
->
head
=
array
(
stack_string
(
'inputname'
),
stack_string
(
'inputexpression'
),
stack_string
(
'inputentered'
),
stack_string
(
'inputdisplayed'
),
stack_string
(
'inputstatus'
),
stack_string
(
'errors'
),
);
$inputstable
->
attributes
[
'class'
]
=
'generaltable stacktestsuite'
;
$typeininputs
=
array
();
foreach
(
$this
->
get_input_states
()
as
$inputname
=>
$inputstate
)
{
$inputval
=
$inputstate
->
input
;
if
(
false
===
$inputstate
->
input
)
{
$inputval
=
''
;
}
else
{
if
(
$inputval
!==
''
)
{
$typeininputs
[
$inputname
]
=
$inputname
.
':'
.
$inputstate
->
modified
.
";
\n
"
;
}
}
$inputstable
->
data
[]
=
array
(
s
(
$inputname
),
s
(
$inputstate
->
rawinput
),
s
(
$inputval
),
stack_ouput_castext
(
$inputstate
->
display
),
stack_string
(
'inputstatusname'
.
$inputstate
->
status
),
$inputstate
->
errors
,
);
}
$html
.
=
html_writer
::
table
(
$inputstable
);
// Display the information about the PRTs.
$prtstable
=
new
html_table
();
$prtstable
->
head
=
array
(
stack_string
(
'prtname'
),
stack_string
(
'score'
),
stack_string
(
'expectedscore'
),
stack_string
(
'penalty'
),
stack_string
(
'expectedpenalty'
),
stack_string
(
'answernote'
),
stack_string
(
'expectedanswernote'
),
get_string
(
'feedback'
,
'question'
),
stack_string
(
'testsuitecolpassed'
),
);
$prtstable
->
attributes
[
'class'
]
=
'generaltable stacktestsuite'
;
$debuginfo
=
''
;
$inputsneeded
=
$question
->
get_cached
(
'required'
);
foreach
(
$this
->
get_prt_states
()
as
$prtname
=>
$state
)
{
$prtinputs
=
array
();
if
(
$inputsneeded
!=
null
)
{
foreach
(
array_keys
(
$inputsneeded
[
$prtname
])
as
$inputname
)
{
if
(
array_key_exists
(
$inputname
,
$typeininputs
))
{
$prtinputs
[]
=
$typeininputs
[
$inputname
];
}
}
}
if
(
$state
->
testoutcome
)
{
$prtstable
->
rowclasses
[]
=
'pass'
;
$passedcol
=
stack_string
(
'testsuitepass'
);
}
else
{
$prtstable
->
rowclasses
[]
=
'fail'
;
$passedcol
=
stack_string
(
'testsuitefail'
)
.
$state
->
reason
;
}
// Sort out excessive decimal places from the DB.
if
(
is_null
(
$state
->
expectedscore
)
||
''
===
$state
->
expectedscore
)
{
$expectedscore
=
''
;
}
else
{
$expectedscore
=
$state
->
expectedscore
+
0
;
}
if
(
is_null
(
$state
->
expectedpenalty
)
||
''
===
$state
->
expectedpenalty
)
{
$expectedpenalty
=
stack_string
(
'questiontestsdefault'
);
}
else
{
// Single PRTs only work to four decimal places, so we only expect that level.
$expectedpenalty
=
round
(
$state
->
expectedpenalty
+
0
,
4
);
}
$answernotedisplay
=
html_writer
::
tag
(
'summary'
,
s
(
$state
->
answernote
))
.
html_writer
::
tag
(
'pre'
,
implode
(
''
,
$prtinputs
)
.
$state
->
trace
);
$answernotedisplay
=
html_writer
::
tag
(
'details'
,
$answernotedisplay
);
$prtstable
->
data
[]
=
array
(
$prtname
,
$state
->
score
,
$expectedscore
,
$state
->
penalty
,
$expectedpenalty
,
$answernotedisplay
,
s
(
$state
->
expectedanswernote
),
format_text
(
$state
->
feedback
),
$passedcol
,
);
// TODO: reinstate debuginfo here.
}
$html
.
=
html_writer
::
table
(
$prtstable
);
return
(
$html
);
}
}
}
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