2014-10-09 13:49:26 +00:00
|
|
|
<?php
|
2016-02-12 16:57:37 +00:00
|
|
|
|
2021-04-07 22:22:05 +00:00
|
|
|
use MediaWiki\Extension\Math\MathLaTeXML;
|
|
|
|
|
2014-10-09 13:49:26 +00:00
|
|
|
/**
|
2021-04-07 22:22:05 +00:00
|
|
|
* @covers \MediaWiki\Extension\Math\MathLaTeXML
|
2016-02-12 16:57:37 +00:00
|
|
|
*
|
|
|
|
* @group Math
|
|
|
|
*
|
2018-04-13 14:06:39 +00:00
|
|
|
* @license GPL-2.0-or-later
|
2016-02-12 16:57:37 +00:00
|
|
|
*/
|
2023-11-19 19:23:09 +00:00
|
|
|
class MathLaTeXMLCacheTest extends MediaWikiIntegrationTestCase {
|
2024-08-25 12:22:07 +00:00
|
|
|
/** @var MathLaTeXML */
|
2014-10-09 13:49:26 +00:00
|
|
|
public $renderer;
|
2020-05-30 01:13:31 +00:00
|
|
|
private const SOME_TEX = "a+b";
|
|
|
|
private const SOME_MATHML = "iℏ∂_tΨ=H^Ψ<mrow><\ci>";
|
2014-10-09 13:49:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to test protected/private Methods
|
2018-06-20 09:10:23 +00:00
|
|
|
* @param string $name
|
2014-10-09 13:49:26 +00:00
|
|
|
* @return ReflectionMethod
|
|
|
|
*/
|
2015-09-21 16:14:01 +00:00
|
|
|
protected static function getMethod( $name ) {
|
2018-06-06 10:13:04 +00:00
|
|
|
$class = new ReflectionClass( MathLaTeXML::class );
|
2015-09-21 16:14:01 +00:00
|
|
|
$method = $class->getMethod( $name );
|
|
|
|
$method->setAccessible( true );
|
2014-10-09 13:49:26 +00:00
|
|
|
return $method;
|
|
|
|
}
|
|
|
|
|
2021-07-22 11:56:28 +00:00
|
|
|
protected function setUp(): void {
|
2014-10-09 13:49:26 +00:00
|
|
|
parent::setUp();
|
|
|
|
$this->renderer = new MathLaTeXML( self::SOME_TEX );
|
2015-09-21 16:14:01 +00:00
|
|
|
}
|
|
|
|
|
2014-10-09 13:49:26 +00:00
|
|
|
/**
|
|
|
|
* Checks the tex and hash functions
|
2021-04-07 22:22:05 +00:00
|
|
|
* @covers \MediaWiki\Extension\Math\MathRenderer::getInputHash
|
2014-10-09 13:49:26 +00:00
|
|
|
*/
|
|
|
|
public function testInputHash() {
|
2023-11-19 19:23:09 +00:00
|
|
|
$this->assertIsString( $this->renderer->getInputHash() );
|
|
|
|
$this->assertStringMatchesFormat( '%x', $this->renderer->getInputHash() );
|
2014-10-09 13:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to set the current state of the sample renderer instance to the test values
|
|
|
|
*/
|
|
|
|
public function setValues() {
|
|
|
|
// set some values
|
|
|
|
$this->renderer->setTex( self::SOME_TEX );
|
|
|
|
$this->renderer->setMathml( self::SOME_MATHML );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-04-07 22:22:05 +00:00
|
|
|
* @covers \MediaWiki\Extension\Math\MathLaTeXML::getMathTableName
|
2014-10-09 13:49:26 +00:00
|
|
|
*/
|
|
|
|
public function testTableName() {
|
|
|
|
$fnGetMathTableName = self::getMethod( 'getMathTableName' );
|
|
|
|
$obj = new MathLaTeXML();
|
2016-04-12 20:53:25 +00:00
|
|
|
$tableName = $fnGetMathTableName->invokeArgs( $obj, [] );
|
2021-01-29 17:01:16 +00:00
|
|
|
$this->assertEquals( "mathlatexml", $tableName, "Wrong latexml table name" );
|
2014-10-09 13:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks database access. Writes an entry and reads it back.
|
2023-11-19 19:23:09 +00:00
|
|
|
* @covers \MediaWiki\Extension\Math\MathRenderer::writeToCache
|
|
|
|
* @covers \MediaWiki\Extension\Math\MathRenderer::readFromCache
|
2014-10-09 13:49:26 +00:00
|
|
|
*/
|
|
|
|
public function testDBBasics() {
|
|
|
|
$this->setValues();
|
2023-11-19 19:23:09 +00:00
|
|
|
$this->renderer->writeToCache();
|
2014-10-09 13:49:26 +00:00
|
|
|
|
|
|
|
$renderer2 = $this->renderer = new MathLaTeXML( self::SOME_TEX );
|
2023-11-19 19:23:09 +00:00
|
|
|
$renderer2->readFromCache();
|
2014-10-09 13:49:26 +00:00
|
|
|
// comparing the class object does now work due to null values etc.
|
2015-09-21 16:14:01 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
$this->renderer->getTex(), $renderer2->getTex(), "test if tex is the same"
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
$this->renderer->getMathml(), $renderer2->getMathml(), "Check MathML encoding"
|
|
|
|
);
|
2014-10-09 13:49:26 +00:00
|
|
|
}
|
|
|
|
}
|