| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Extension\Math\MathMathML; |
| 4 |
use MediaWiki\Extension\Math\MathRenderer; |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class MathCacheTest extends MediaWikiIntegrationTestCase { |
| 16 |
|
| 17 |
|
| 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 |
|
| 30 |
|
| 31 |
|
| 32 |
public function testInputHash() { |
| 33 |
$this->assertEquals( 'beb7506b16f7c36aa0f9c8c9ef41b40b', $this->renderer->getInputHash() ); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public function setValues() { |
| 40 |
|
| 41 |
$this->renderer->setTex( self::SOME_TEX ); |
| 42 |
$this->renderer->setMathml( self::SOME_MATHML ); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 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 |
|
| 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 |
|
| 69 |
|
| 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 |
} |