Debian Codegraph @

extensions/Math/tests/phpunit/MathCacheTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Extension\Math\MathMathML;
4 use MediaWiki\Extension\Math\MathRenderer;
5
6 /**
7 * Test the database access and core functionality of MathRenderer.
8 *
9 * @covers \MediaWiki\Extension\Math\MathRenderer
10 *
11 * @group Math
12 *
13 * @license GPL-2.0-or-later
14 */
15 class MathCacheTest extends MediaWikiIntegrationTestCase {
16 /**
17 * @var MathRenderer
18 */
19 private $renderer;
20 private const SOME_TEX = "a+b";
21 private const SOME_MATHML = "iℏ∂_tΨ=H^Ψ<mrow><\ci>";
22
23 protected function setUp(): void {
24 parent::setUp();
25 $this->renderer = new MathMathML( self::SOME_TEX );
26 }
27
28 /**
29 * Checks the tex and hash functions
30 * @covers \MediaWiki\Extension\Math\MathRenderer::getInputHash
31 */
32 public function testInputHash() {
33 $this->assertEquals( 'beb7506b16f7c36aa0f9c8c9ef41b40b', $this->renderer->getInputHash() );
34 }
35
36 /**
37 * Helper function to set the current state of the sample renderer instance to the test values
38 */
39 public function setValues() {
40 // set some values
41 $this->renderer->setTex( self::SOME_TEX );
42 $this->renderer->setMathml( self::SOME_MATHML );
43 }
44
45 /**
46 * Checks database access. Writes an entry and reads it back.
47 * @covers \MediaWiki\Extension\Math\MathRenderer::writeToCache
48 * @covers \MediaWiki\Extension\Math\MathRenderer::readFromCache
49 */
50 public function testDBBasics() {
51 $this->setValues();
52 $this->renderer->writeToCache();
53 $renderer2 = new MathMathML( self::SOME_TEX, [ 'display' => '' ] );
54 $this->assertTrue( $renderer2->readFromCache(), 'Reading from database failed' );
55 // comparing the class object does now work due to null values etc.
56 $this->assertEquals(
57 $this->renderer->getTex(), $renderer2->getTex(), "test if tex is the same"
58 );
59 $this->assertEquals(
60 $this->renderer->getMathml(), $renderer2->getMathml(), "Check MathML encoding"
61 );
62 $this->assertEquals(
63 $this->renderer->getHtmlOutput(), $renderer2->getHtmlOutput(), 'test if HTML is the same'
64 );
65 }
66
67 /**
68 * This test checks if no additional write operation
69 * is performed, if the entry already existed in the database.
70 */
71 public function testNoWrite() {
72 $this->setValues();
73 $inputHash = $this->renderer->getInputHash();
74 $this->assertTrue( $this->renderer->isChanged() );
75 $this->assertTrue( $this->renderer->writeCache(), "Write new entry" );
76 $this->assertTrue( $this->renderer->readFromCache(), "Read entry from database" );
77 $this->assertFalse( $this->renderer->isChanged() );
78 }
79 }