| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Extension\Math\MathLaTeXML; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class MathLaTeXMLCacheTest extends MediaWikiIntegrationTestCase { |
| 13 |
|
| 14 |
public $renderer; |
| 15 |
private const SOME_TEX = "a+b"; |
| 16 |
private const SOME_MATHML = "iℏ∂_tΨ=H^Ψ<mrow><\ci>"; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
protected static function getMethod( $name ) { |
| 24 |
$class = new ReflectionClass( MathLaTeXML::class ); |
| 25 |
$method = $class->getMethod( $name ); |
| 26 |
return $method; |
| 27 |
} |
| 28 |
|
| 29 |
protected function setUp(): void { |
| 30 |
parent::setUp(); |
| 31 |
$this->renderer = new MathLaTeXML( self::SOME_TEX ); |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public function testInputHash() { |
| 39 |
$this->assertIsString( $this->renderer->getInputHash() ); |
| 40 |
$this->assertStringMatchesFormat( '%x', $this->renderer->getInputHash() ); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public function setValues() { |
| 47 |
|
| 48 |
$this->renderer->setTex( self::SOME_TEX ); |
| 49 |
$this->renderer->setMathml( self::SOME_MATHML ); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public function testTableName() { |
| 56 |
$fnGetMathTableName = self::getMethod( 'getMathTableName' ); |
| 57 |
$obj = new MathLaTeXML(); |
| 58 |
$tableName = $fnGetMathTableName->invokeArgs( $obj, [] ); |
| 59 |
$this->assertEquals( "mathlatexml", $tableName, "Wrong latexml table name" ); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public function testDBBasics() { |
| 68 |
$this->setValues(); |
| 69 |
$this->renderer->writeToCache(); |
| 70 |
|
| 71 |
$renderer2 = $this->renderer = new MathLaTeXML( self::SOME_TEX ); |
| 72 |
$renderer2->readFromCache(); |
| 73 |
|
| 74 |
$this->assertEquals( |
| 75 |
$this->renderer->getTex(), $renderer2->getTex(), "test if tex is the same" |
| 76 |
); |
| 77 |
$this->assertEquals( |
| 78 |
$this->renderer->getMathml(), $renderer2->getMathml(), "Check MathML encoding" |
| 79 |
); |
| 80 |
} |
| 81 |
} |