public function test_maths_rendering() { if (!stack_maths_output_maths::filter_is_installed()) { $this->markTestSkipped('The OU maths filter is not installed.'); } if (!defined('FILTER_MATHS_TEST_SERVICE_URL_BASE')) { $this->markTestSkipped('To run the OU maths filter output tests, ' . 'you must define FILTER_MATHS_TEST_SERVICE_URL_BASE in config.php.'); } $this->resetAfterTest(); set_config('mathsdisplay', 'maths', 'qtype_stack'); set_config('texservice', FILTER_MATHS_TEST_SERVICE_URL_BASE . 'tex', 'filter_maths'); set_config('imageservice', FILTER_MATHS_TEST_SERVICE_URL_BASE . 'imagetex', 'filter_maths'); set_config('englishservice', FILTER_MATHS_TEST_SERVICE_URL_BASE . 'english', 'filter_maths'); stack_utils::clear_config_cache(); filter_set_global_state('mathjaxloader', TEXTFILTER_DISABLED); // Test language string. $this->assertRegExp('~^Your answer needs to be a single fraction of the form <a .*alt="a over b".*</a>\\. $~', stack_string('ATSingleFrac_part')); // Test docs - make sure maths inside <code> is not rendered. $this->assertRegExp('~^<p><code>\\\\\\(x\\^2\\\\\\)</code> gives <a .*alt="x squared".*</a>\\.</p>\\n$~', stack_docs_render_markdown('<code>\\(x^2\\)</code> gives \\(x^2\\).', '')); // Test docs - make sure maths inside <textarea> is not rendered. $this->assertRegExp('~^<p>\\n' . 'Differentiate \\\\\\\\\\[x\\^2 \\+ y\\^2\\\\\\\\\\] with respect to \\\\\\\\\\(x\\\\\\\\\\).</p>\\n$~', stack_docs_render_markdown('<textarea readonly="readonly" rows="3" cols="50">' . "\n" . 'Differentiate \\[x^2 + y^2\\] with respect to \\(x\\).</textarea>', '')); // Test CAS text with inline maths. $this->assertEquals('What is <tex mode="inline">x^2</tex>?', stack_maths::process_display_castext('What is \\(x^2\\)?')); // Test CAS text with display maths. $this->assertEquals('What is <span class="displayequation"><tex mode="display">x^2</tex></span>?', stack_maths::process_display_castext('What is \\[x^2\\]?')); // Test with replacedollars. set_config('replacedollars', '1', 'qtype_stack'); stack_utils::clear_config_cache(); $this->assertEquals('What is <tex mode="inline">x^2</tex> or ' . '<span class="displayequation"><tex mode="display">x^2</tex></span>?', stack_maths::process_display_castext('What is $x^2$ or $$x^2$$?')); stack_utils::clear_config_cache(); }
public function test_stack_docs_render_markdown() { $this->resetAfterTest(); filter_set_global_state('mathjaxloader', TEXTFILTER_DISABLED); $this->assertEquals("<p>Test</p>\n", stack_docs_render_markdown('Test', '.../doc/content')); $this->assertEquals('<p><a href=".../doc/content/readme.txt">Readme</a></p>' . "\n", stack_docs_render_markdown('[Readme](%CONTENT/readme.txt)', '.../doc/content')); $this->assertEquals("<p>Literal %CONTENT</p>\n", stack_docs_render_markdown('Literal \\%CONTENT', '.../doc/content')); $this->assertEquals("<p><code>\\(x^2\\)</code> gives \\(x^2\\).</p>\n", stack_docs_render_markdown('`\\(x^2\\)` gives \\(x^2\\).', '.../doc/content')); }
public function test_maths_output_mathsjax() { filter_set_global_state('mathjaxloader', TEXTFILTER_DISABLED); // MathJax output is the default. $this->assertEquals('Your answer needs to be a single fraction of the form \\( {a}\\over{b} \\). ', stack_string('ATSingleFrac_part')); $this->assertEquals("<p><code>\\(x^2\\)</code> gives \\(x^2\\).</p>\n", stack_docs_render_markdown('`\\(x^2\\)` gives \\(x^2\\).', '')); $this->assertEquals('What is \\(x^2\\)?', stack_maths::process_display_castext('What is \\(x^2\\)?')); $this->resetAfterTest(); set_config('replacedollars', '1', 'qtype_stack'); stack_utils::clear_config_cache(); $this->assertEquals('What is \\(x^2\\) or \\[x^2\\]?', stack_maths::process_display_castext('What is $x^2$ or $$x^2$$?')); stack_utils::clear_config_cache(); }
public function test_tex_rendering() { $this->resetAfterTest(); set_config('mathsdisplay', 'tex', 'qtype_stack'); stack_utils::clear_config_cache(); filter_set_global_state('mathjaxloader', TEXTFILTER_DISABLED); // Test language string. // The <span class="MathJax_Preview"> bit is something that got added in // Moodle 2.8, so match it optionally. $this->assertRegExp('~^Your answer needs to be a single fraction of the form ' . '(<span class="MathJax_Preview">)?<a .*alt=" \\{a\\}\\\\over\\{b\\} ".*</(a|script)> \\. ~', stack_string('ATSingleFrac_part')); // Test docs - make sure maths inside <code> is not rendered. $this->assertRegExp('~^<p><code>\\\\\\(x\\^2\\\\\\)</code> gives (<span class="MathJax_Preview">)?<a .*alt="x\\^2".*</(a|script)> \\.</p>\\n$~', stack_docs_render_markdown('<code>\\(x^2\\)</code> gives \\(x^2\\).', '')); // Test docs - make sure maths inside <textarea> is not rendered. $this->assertRegExp('~^<p>\\n' . 'Differentiate \\\\\\\\\\[x\\^2 \\+ y\\^2\\\\\\\\\\] with respect to \\\\\\\\\\(x\\\\\\\\\\).</p>\\n$~', stack_docs_render_markdown('<textarea readonly="readonly" rows="3" cols="50">' . "\n" . 'Differentiate \\[x^2 + y^2\\] with respect to \\(x\\).</textarea>', '')); // Test CAS text with inline maths. $this->assertEquals('What is \\[x^2\\]?', stack_maths::process_display_castext('What is \\(x^2\\)?')); // Test CAS text with display maths. $this->assertEquals('What is <span class="displayequation">\\[\\displaystyle x^2\\]</span>?', stack_maths::process_display_castext('What is \\[x^2\\]?')); // Test with replacedollars. set_config('replacedollars', '1', 'qtype_stack'); stack_utils::clear_config_cache(); $this->assertEquals('What is \\[x^2\\] or <span class="displayequation">\\[\\displaystyle x^2\\]</span>?', stack_maths::process_display_castext('What is $x^2$ or $$x^2$$?')); stack_utils::clear_config_cache(); }
/** * Generate a page of the documentation from the source in a file. * @param string $links menu of links to show. * @param string $file path to the file to display. * @param string $docscontent base URL for linking to images etc. * @return string HTML page body. */ function stack_docs_page($links, $file, $docscontent) { $body = ''; $body .= $links; $body .= "\n<hr/>\n"; $body .= stack_docs_render_markdown(file_get_contents($file), $docscontent); $body .= "\n<hr/>\n"; $body .= $links; return $body; }