public function setUp() { parent::setUp(); stack_utils::clear_config_cache(); self::setup_test_maxima_connection($this); $this->resetAfterTest(); }
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_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(); }