Skip to content
Snippets Groups Projects
Commit 2b4a73c0 authored by Chris Sangwin's avatar Chris Sangwin
Browse files

Make sure plot URLs are rendered in full in MCQ options.

parent e6c11e4b
Branches
No related tags found
No related merge requests found
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
</info> </info>
</question> </question>
<!-- question: 19512 --> <!-- question: 19535 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Algebraic input</text> <text>Algebraic input</text>
...@@ -134,7 +134,7 @@ ...@@ -134,7 +134,7 @@
</qtest> </qtest>
</question> </question>
<!-- question: 19513 --> <!-- question: 19536 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Algebraic input (align to the right)</text> <text>Algebraic input (align to the right)</text>
...@@ -271,7 +271,7 @@ ...@@ -271,7 +271,7 @@
</qtest> </qtest>
</question> </question>
<!-- question: 19514 --> <!-- question: 19537 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Algebraic input (answer box sizes test)</text> <text>Algebraic input (answer box sizes test)</text>
...@@ -557,7 +557,7 @@ ...@@ -557,7 +557,7 @@
</qtest> </qtest>
</question> </question>
<!-- question: 19515 --> <!-- question: 19538 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Algebraic input (compact)</text> <text>Algebraic input (compact)</text>
...@@ -681,7 +681,7 @@ ...@@ -681,7 +681,7 @@
</qtest> </qtest>
</question> </question>
<!-- question: 19516 --> <!-- question: 19539 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Algebraic input (empty answer permitted)</text> <text>Algebraic input (empty answer permitted)</text>
...@@ -880,7 +880,7 @@ ...@@ -880,7 +880,7 @@
</qtest> </qtest>
</question> </question>
<!-- question: 19517 --> <!-- question: 19540 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Algebraic input (with simplification)</text> <text>Algebraic input (with simplification)</text>
...@@ -1018,7 +1018,7 @@ ...@@ -1018,7 +1018,7 @@
</qtest> </qtest>
</question> </question>
<!-- question: 19518 --> <!-- question: 19541 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Checkbox</text> <text>Checkbox</text>
...@@ -1148,7 +1148,7 @@ ta:append(ta,[tao]);]]></text> ...@@ -1148,7 +1148,7 @@ ta:append(ta,[tao]);]]></text>
</qtest> </qtest>
</question> </question>
<!-- question: 19519 --> <!-- question: 19542 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Checkbox (no body LaTeX)</text> <text>Checkbox (no body LaTeX)</text>
...@@ -1278,7 +1278,225 @@ ta:append(ta,[tao]);]]></text> ...@@ -1278,7 +1278,225 @@ ta:append(ta,[tao]);]]></text>
</qtest> </qtest>
</question> </question>
<!-- question: 19520 --> <!-- question: 19556 -->
<question type="stack">
<name>
<text>Checkbox (plots in options)</text>
</name>
<questiontext format="html">
<text><![CDATA[<p class="noindent">Which of the following functions are invertible?<br></p>
[[input:ans1]] [[validation:ans1]]
<p>(This question is to test auto-generated images appear in MCQ options.)</p>]]></text>
</questiontext>
<generalfeedback format="html">
<text><![CDATA[<p>A function is invertible if and only if it takes each value in its range precisely once.&nbsp; The functions that are not invertible here are not invertible because they take some values more than once.<br></p>]]></text>
</generalfeedback>
<defaultgrade>1.0000000</defaultgrade>
<penalty>0.1000000</penalty>
<hidden>0</hidden>
<idnumber></idnumber>
<stackversion>
<text>2020020101</text>
</stackversion>
<questionvariables>
<text><![CDATA[cfn1:x^3;
cfn2:atan(x);
cfn3:(1/2)^x;
cfn4:-x^5;
wfn1:x^2-1;
wfn2:(x-1)*x*(x+1);
wfn3:1/x^2;
wfn4:cos(x);
xmax:3;
ymax:3;
cplot1:plot(cfn1,[x,-xmax,xmax],[y,-ymax,ymax],[box, false],[yx_ratio, 1],[axes, solid]);
cplot2:plot(cfn2,[x,-xmax,xmax],[y,-%pi/2,%pi/2],[box, false],[yx_ratio, 1],[axes, solid]);
cplot3:plot(cfn3,[x,-xmax,xmax],[y,0,ymax],[box, false],[yx_ratio, 1],[axes, solid]);
cplot4:plot(cfn4,[x,-xmax,xmax],[y,-ymax,ymax],[box, false],[yx_ratio, 1],[axes, solid]);
wplot1:plot(wfn1,[x,-xmax,xmax],[y,-1,ymax],[box, false],[yx_ratio, 1],[axes, solid]);
wplot2:plot(wfn2,[x,-xmax,xmax],[y,-ymax,ymax],[box, false],[yx_ratio, 1],[axes, solid]);
wplot3:plot(wfn3,[x,-xmax,xmax],[y,0,ymax],[box, false],[yx_ratio, 1],[axes, solid]);
wplot4:plot(wfn4,[x,-xmax,xmax],[y,-1,1],[box, false],[yx_ratio, 1],[axes, solid]);
corbase:[cplot1,cplot2,cplot3,cplot4];
wrongbase:[wplot1,wplot2,wplot3,wplot4];
/* code lifted and adapted from multiselqnalpha */
sel_cor: maplist(lambda([ex], [ex, true]), rand_selection(corbase, 2));
sel_incorr: maplist(lambda([ex], [ex, false]), rand_selection(wrongbase, 2));
opts: random_permutation(append(sel_cor,sel_incorr));
talab: ev(makelist(sconcat("(",ascii(96+i),")"), i, 1, length(opts)), simp);
ta1:zip_with(lambda([ex1, ex2], [ex1, ex2[2], sconcat("<b>", ex1, "</b> ", ex2[1])]), talab, opts);
version: map(first, opts);
corr1:mcq_correct(ta1);
incorr1:mcq_incorrect(ta1);]]></text>
</questionvariables>
<specificfeedback format="html">
<text>[[feedback:prt1]]</text>
</specificfeedback>
<questionnote>
<text>{@f@} {#version#}</text>
</questionnote>
<questionsimplify>1</questionsimplify>
<assumepositive>0</assumepositive>
<assumereal>0</assumereal>
<prtcorrect format="html">
<text><![CDATA[<span style="font-size: 1.5em; color:green;"><i class="fa fa-check"></i></span> Correct answer, well done.]]></text>
</prtcorrect>
<prtpartiallycorrect format="html">
<text><![CDATA[<span style="font-size: 1.5em; color:orange;"><i class="fa fa-adjust"></i></span> Your answer is partially correct.]]></text>
</prtpartiallycorrect>
<prtincorrect format="html">
<text><![CDATA[<span style="font-size: 1.5em; color:red;"><i class="fa fa-times"></i></span> Incorrect answer.]]></text>
</prtincorrect>
<multiplicationsign>none</multiplicationsign>
<sqrtsign>1</sqrtsign>
<complexno>i</complexno>
<inversetrig>cos-1</inversetrig>
<matrixparens>[</matrixparens>
<variantsselectionseed></variantsselectionseed>
<input>
<name>ans1</name>
<type>checkbox</type>
<tans>ta1</tans>
<boxsize>15</boxsize>
<strictsyntax>0</strictsyntax>
<insertstars>0</insertstars>
<syntaxhint></syntaxhint>
<syntaxattribute>0</syntaxattribute>
<forbidwords></forbidwords>
<allowwords></allowwords>
<forbidfloat>1</forbidfloat>
<requirelowestterms>1</requirelowestterms>
<checkanswertype>0</checkanswertype>
<mustverify>0</mustverify>
<showvalidation>0</showvalidation>
<options>LaTeX</options>
</input>
<prt>
<name>prt1</name>
<value>1.0000000</value>
<autosimplify>0</autosimplify>
<feedbackvariables>
<text></text>
</feedbackvariables>
<node>
<name>0</name>
<answertest>AlgEquiv</answertest>
<sans>setify(ans1)</sans>
<tans>setify(corr1)</tans>
<testoptions></testoptions>
<quiet>1</quiet>
<truescoremode>=</truescoremode>
<truescore>1.0000000</truescore>
<truepenalty>0.0000000</truepenalty>
<truenextnode>-1</truenextnode>
<trueanswernote>prt1-0-T</trueanswernote>
<truefeedback format="html">
<text></text>
</truefeedback>
<falsescoremode>=</falsescoremode>
<falsescore>0.0000000</falsescore>
<falsepenalty>0.1000000</falsepenalty>
<falsenextnode>1</falsenextnode>
<falseanswernote>prt1-0-F</falseanswernote>
<falsefeedback format="html">
<text></text>
</falsefeedback>
</node>
<node>
<name>1</name>
<answertest>AlgEquiv</answertest>
<sans>subsetp(setify(ans1),setify(corr1))</sans>
<tans>true</tans>
<testoptions></testoptions>
<quiet>0</quiet>
<truescoremode>+</truescoremode>
<truescore>0.5000000</truescore>
<truepenalty></truepenalty>
<truenextnode>-1</truenextnode>
<trueanswernote>prt1-2-T</trueanswernote>
<truefeedback format="html">
<text><![CDATA[<p>You have correctly identified one of the correct answers, but missed \({@setdifference(setify(corr1),setify(ans1))@}\).<br></p>]]></text>
</truefeedback>
<falsescoremode>-</falsescoremode>
<falsescore>0.0000000</falsescore>
<falsepenalty></falsepenalty>
<falsenextnode>2</falsenextnode>
<falseanswernote>prt1-2-F</falseanswernote>
<falsefeedback format="html">
<text></text>
</falsefeedback>
</node>
<node>
<name>2</name>
<answertest>CasEqual</answertest>
<sans>cardinality(ev(intersection(setify(incorr1),setify(ans1)),simp))</sans>
<tans>0</tans>
<testoptions></testoptions>
<quiet>0</quiet>
<truescoremode>+</truescoremode>
<truescore>0.0000000</truescore>
<truepenalty></truepenalty>
<truenextnode>-1</truenextnode>
<trueanswernote>prt1-3-T</trueanswernote>
<truefeedback format="html">
<text><![CDATA[<p><br></p><p>{@setify(ans1)@}<br></p><p>{@(intersection(setify(incorr),setify(ans1)))@}<br></p><p>{@cardinality(intersection(setify(incorr),setify(ans1)))@}</p>]]></text>
</truefeedback>
<falsescoremode>-</falsescoremode>
<falsescore>0.0000000</falsescore>
<falsepenalty></falsepenalty>
<falsenextnode>-1</falsenextnode>
<falseanswernote>prt1-3-F</falseanswernote>
<falsefeedback format="html">
<text><![CDATA[<p>You incorrectly selected {@(setdifference(setify(ans1),setify(corr1)))@}<br></p>]]></text>
</falsefeedback>
</node>
</prt>
<qtest>
<testcase>1</testcase>
<testinput>
<name>ans1</name>
<value>[incorr1[1]]</value>
</testinput>
<expected>
<name>prt1</name>
<expectedscore>0.0000000</expectedscore>
<expectedpenalty>0.1000000</expectedpenalty>
<expectedanswernote>prt1-3-F</expectedanswernote>
</expected>
</qtest>
<qtest>
<testcase>2</testcase>
<testinput>
<name>ans1</name>
<value>corr1</value>
</testinput>
<expected>
<name>prt1</name>
<expectedscore>1.0000000</expectedscore>
<expectedpenalty>0.0000000</expectedpenalty>
<expectedanswernote>prt1-0-T</expectedanswernote>
</expected>
</qtest>
<qtest>
<testcase>3</testcase>
<testinput>
<name>ans1</name>
<value>[corr1[1],incorr1[1]]</value>
</testinput>
<expected>
<name>prt1</name>
<expectedscore>0.0000000</expectedscore>
<expectedpenalty>0.1000000</expectedpenalty>
<expectedanswernote>prt1-3-F</expectedanswernote>
</expected>
</qtest>
<tags>
<tag><text>multiselqnalpha</text>
</tag>
</tags>
</question>
<!-- question: 19543 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Dropdown (shuffle)</text> <text>Dropdown (shuffle)</text>
...@@ -1423,7 +1641,7 @@ ta:append(ta,[tao]);]]></text> ...@@ -1423,7 +1641,7 @@ ta:append(ta,[tao]);]]></text>
</qtest> </qtest>
</question> </question>
<!-- question: 19521 --> <!-- question: 19544 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Equiv input test (compact)</text> <text>Equiv input test (compact)</text>
...@@ -1535,7 +1753,7 @@ ta:[p,x=(4-7)/3,x=-1]</text> ...@@ -1535,7 +1753,7 @@ ta:[p,x=(4-7)/3,x=-1]</text>
</qtest> </qtest>
</question> </question>
<!-- question: 19522 --> <!-- question: 19545 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Equiv input test (let, or +-)</text> <text>Equiv input test (let, or +-)</text>
...@@ -1672,7 +1890,7 @@ p:first(tal);</text> ...@@ -1672,7 +1890,7 @@ p:first(tal);</text>
</qtest> </qtest>
</question> </question>
<!-- question: 19523 --> <!-- question: 19546 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Matrix</text> <text>Matrix</text>
...@@ -1795,7 +2013,7 @@ p:first(tal);</text> ...@@ -1795,7 +2013,7 @@ p:first(tal);</text>
</qtest> </qtest>
</question> </question>
<!-- question: 19524 --> <!-- question: 19547 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Notes</text> <text>Notes</text>
...@@ -1905,7 +2123,7 @@ p:first(tal);</text> ...@@ -1905,7 +2123,7 @@ p:first(tal);</text>
</qtest> </qtest>
</question> </question>
<!-- question: 19525 --> <!-- question: 19548 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Numerical input (min sf)</text> <text>Numerical input (min sf)</text>
...@@ -2028,7 +2246,7 @@ p:first(tal);</text> ...@@ -2028,7 +2246,7 @@ p:first(tal);</text>
</qtest> </qtest>
</question> </question>
<!-- question: 19526 --> <!-- question: 19549 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Radio</text> <text>Radio</text>
...@@ -2145,7 +2363,7 @@ ta:append(ta,[tao]);]]></text> ...@@ -2145,7 +2363,7 @@ ta:append(ta,[tao]);]]></text>
</qtest> </qtest>
</question> </question>
<!-- question: 19527 --> <!-- question: 19550 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Single char</text> <text>Single char</text>
...@@ -2268,7 +2486,7 @@ ta:append(ta,[tao]);]]></text> ...@@ -2268,7 +2486,7 @@ ta:append(ta,[tao]);]]></text>
</qtest> </qtest>
</question> </question>
<!-- question: 19528 --> <!-- question: 19551 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>String input</text> <text>String input</text>
...@@ -2403,7 +2621,7 @@ This input is not, perhaps it is used to store JSXGraph state? ...@@ -2403,7 +2621,7 @@ This input is not, perhaps it is used to store JSXGraph state?
</qtest> </qtest>
</question> </question>
<!-- question: 19529 --> <!-- question: 19552 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Textarea test</text> <text>Textarea test</text>
...@@ -2513,7 +2731,7 @@ This input is not, perhaps it is used to store JSXGraph state? ...@@ -2513,7 +2731,7 @@ This input is not, perhaps it is used to store JSXGraph state?
</qtest> </qtest>
</question> </question>
<!-- question: 19530 --> <!-- question: 19553 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Textarea test (compact)</text> <text>Textarea test (compact)</text>
...@@ -2623,7 +2841,7 @@ This input is not, perhaps it is used to store JSXGraph state? ...@@ -2623,7 +2841,7 @@ This input is not, perhaps it is used to store JSXGraph state?
</qtest> </qtest>
</question> </question>
<!-- question: 19531 --> <!-- question: 19554 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>True/false</text> <text>True/false</text>
...@@ -2746,7 +2964,7 @@ This input is not, perhaps it is used to store JSXGraph state? ...@@ -2746,7 +2964,7 @@ This input is not, perhaps it is used to store JSXGraph state?
</qtest> </qtest>
</question> </question>
<!-- question: 19532 --> <!-- question: 19555 -->
<question type="stack"> <question type="stack">
<name> <name>
<text>Units</text> <text>Units</text>
......
...@@ -43,7 +43,10 @@ abstract class stack_maths_output_filter_base extends stack_maths_output { ...@@ -43,7 +43,10 @@ abstract class stack_maths_output_filter_base extends stack_maths_output {
} }
public function process_lang_string($string) { public function process_lang_string($string) {
return $this->find_and_render_equations($string); $string = $this->find_and_render_equations($string);
$string = str_replace('!ploturl!',
moodle_url::make_file_url('/question/type/stack/plot.php', '/'), $string);
return $string;
} }
public function post_process_docs_page($html) { public function post_process_docs_page($html) {
......
...@@ -316,7 +316,7 @@ class stack_radio_input_test extends qtype_stack_walkthrough_test_base { ...@@ -316,7 +316,7 @@ class stack_radio_input_test extends qtype_stack_walkthrough_test_base {
// @codingStandardsIgnoreEnd // @codingStandardsIgnoreEnd
$render = $el->render(new stack_input_state( $render = $el->render(new stack_input_state(
stack_input::SCORE, array('2'), '', '', '', '', ''), 'stack1__ans1', false, null); stack_input::SCORE, array('2'), '', '', '', '', ''), 'stack1__ans1', false, null);
$this->assertTrue(is_int(strpos($render, "<img src='!ploturl!stackplot-"))); $this->assertTrue(is_int(strpos($render, "<img src='https://www.example.com/moodle/question/type/stack/plot.php")));
$this->assertTrue(is_int(strpos($render, $this->assertTrue(is_int(strpos($render,
"alt='STACK auto-generated plot of x with parameters [[x,-2,2],[y,-3,3]]'"))); "alt='STACK auto-generated plot of x with parameters [[x,-2,2],[y,-3,3]]'")));
$this->assertTrue(is_int(strpos($render, $this->assertTrue(is_int(strpos($render,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment