Debian Codegraph @

extensions/Math/tests/phpunit/MathLaTeXMLCacheTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Extension\Math\MathLaTeXML;
4
5 /**
6 * @covers \MediaWiki\Extension\Math\MathLaTeXML
7 *
8 * @group Math
9 *
10 * @license GPL-2.0-or-later
11 */
12 class MathLaTeXMLCacheTest extends MediaWikiIntegrationTestCase {
13 /** @var MathLaTeXML */
14 public $renderer;
15 private const SOME_TEX = "a+b";
16 private const SOME_MATHML = "iℏ∂_tΨ=H^Ψ<mrow><\ci>";
17
18 /**
19 * Helper function to test protected/private Methods
20 * @param string $name
21 * @return ReflectionMethod
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 * Checks the tex and hash functions
36 * @covers \MediaWiki\Extension\Math\MathRenderer::getInputHash
37 */
38 public function testInputHash() {
39 $this->assertIsString( $this->renderer->getInputHash() );
40 $this->assertStringMatchesFormat( '%x', $this->renderer->getInputHash() );
41 }
42
43 /**
44 * Helper function to set the current state of the sample renderer instance to the test values
45 */
46 public function setValues() {
47 // set some values
48 $this->renderer->setTex( self::SOME_TEX );
49 $this->renderer->setMathml( self::SOME_MATHML );
50 }
51
52 /**
53 * @covers \MediaWiki\Extension\Math\MathLaTeXML::getMathTableName
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 * Checks database access. Writes an entry and reads it back.
64 * @covers \MediaWiki\Extension\Math\MathRenderer::writeToCache
65 * @covers \MediaWiki\Extension\Math\MathRenderer::readFromCache
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 // comparing the class object does now work due to null values etc.
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 }