Debian Codegraph @

extensions/Math/tests/phpunit/MathNativeMMLTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Extension\Math\MathNativeMML;
4 use Wikimedia\Rdbms\IDatabase;
5 use Wikimedia\Rdbms\LBFactory;
6
7 /**
8 * Test the native MathML output format.
9 *
10 * @covers \MediaWiki\Extension\Math\MathNativeMML
11 *
12 * @group Math
13 *
14 * @license GPL-2.0-or-later
15 */
16 class MathNativeMMLTest extends MediaWikiIntegrationTestCase {
17
18 protected function setUp(): void {
19 parent::setUp();
20 $db = $this->createMock( IDatabase::class );
21 $db->method( 'selectRow' )->willReturn( false );
22 $lbFactory = $this->createMock( LBFactory::class );
23 $lbFactory->method( 'getReplicaDatabase' )->willReturn( $db );
24 $this->setService( 'DBLoadBalancerFactory', $lbFactory );
25 $this->overrideConfigValue( 'MathValidModes', [ 'native' ] );
26 $this->clearHooks();
27 }
28
29 public function testSin() {
30 $mml = new MathNativeMML( '\sin' );
31 $this->assertSame( 'tex', $mml->getInputType() );
32 $this->assertTrue( $mml->checkTeX() );
33 $this->assertTrue( $mml->render() );
34 $this->assertStringContainsString( 'sin', $mml->getMathml() );
35 }
36
37 public function testNoLink() {
38 $this->overrideConfigValue( 'MathEnableFormulaLinks', false );
39 $mml = new MathNativeMML( '\sin', [ 'qid' => 'Q1' ] );
40 $this->assertTrue( $mml->render() );
41 $this->assertStringNotContainsString( 'href', $mml->getMathml() );
42 }
43
44 public function testLink() {
45 $this->overrideConfigValue( 'MathEnableFormulaLinks', true );
46 $mml = new MathNativeMML( '\sin', [ 'qid' => 'Q1' ] );
47 $this->assertTrue( $mml->render() );
48 $this->assertStringContainsString( 'href', $mml->getMathml() );
49 }
50
51 public function testId() {
52 $mml = new MathNativeMML( '\sin', [ 'id' => 'unique-id' ] );
53 $this->assertTrue( $mml->render() );
54 $this->assertStringContainsString( 'unique-id', $mml->getMathml() );
55 }
56
57 public function testBlock() {
58 $mml = new MathNativeMML( '\sin', [ 'display' => 'block' ] );
59 $this->assertTrue( $mml->render() );
60 $this->assertStringContainsString( 'block', $mml->getMathml() );
61 }
62 }