2013-02-16 22:55:39 +00:00
|
|
|
<?php
|
2016-02-12 16:57:37 +00:00
|
|
|
|
2021-08-11 18:15:35 +00:00
|
|
|
use MediaWiki\Extension\Math\MathConfig;
|
2021-04-07 22:22:05 +00:00
|
|
|
use MediaWiki\Extension\Math\MathSource;
|
|
|
|
|
2013-02-16 22:55:39 +00:00
|
|
|
/**
|
|
|
|
* Test the TeX source output format.
|
2016-02-12 16:57:37 +00:00
|
|
|
*
|
2021-04-07 22:22:05 +00:00
|
|
|
* @covers \MediaWiki\Extension\Math\MathSource
|
2016-02-12 16:57:37 +00:00
|
|
|
*
|
2018-04-13 14:06:39 +00:00
|
|
|
* @license GPL-2.0-or-later
|
2013-02-16 22:55:39 +00:00
|
|
|
*/
|
2021-10-11 22:51:10 +00:00
|
|
|
class MathSourceTest extends MediaWikiIntegrationTestCase {
|
2013-02-16 22:55:39 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-08 14:25:11 +00:00
|
|
|
* Checks the basic functionality
|
2013-02-16 22:55:39 +00:00
|
|
|
* i.e. if the span element is generated right.
|
|
|
|
*/
|
2014-02-09 19:02:15 +00:00
|
|
|
public function testBasics() {
|
2022-06-21 09:23:05 +00:00
|
|
|
$renderer = $this->getServiceContainer()
|
|
|
|
->get( 'Math.RendererFactory' )
|
|
|
|
->getRenderer( 'a+b', [], MathConfig::MODE_SOURCE );
|
|
|
|
$renderer->render();
|
|
|
|
$real = $renderer->getHtmlOutput();
|
2014-03-11 15:53:03 +00:00
|
|
|
$this->assertEquals(
|
2014-03-17 06:14:02 +00:00
|
|
|
'<span class="mwe-math-fallback-source-inline tex" dir="ltr">$ a+b $</span>',
|
2014-03-11 15:53:03 +00:00
|
|
|
$real,
|
|
|
|
"Rendering of a+b in plain Text mode"
|
|
|
|
);
|
2013-02-16 22:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if newlines are converted to spaces correctly.
|
|
|
|
*/
|
2014-02-09 19:02:15 +00:00
|
|
|
public function testNewLines() {
|
2022-06-21 09:23:05 +00:00
|
|
|
$renderer = $this->getServiceContainer()
|
|
|
|
->get( 'Math.RendererFactory' )
|
|
|
|
->getRenderer( "a\n b", [], MathConfig::MODE_SOURCE );
|
|
|
|
$renderer->render();
|
|
|
|
$real = $renderer->getHtmlOutput();
|
2014-03-11 15:53:03 +00:00
|
|
|
$this->assertSame(
|
2014-03-17 06:14:02 +00:00
|
|
|
'<span class="mwe-math-fallback-source-inline tex" dir="ltr">$ a b $</span>',
|
2014-03-11 15:53:03 +00:00
|
|
|
$real,
|
|
|
|
"converting newlines to spaces"
|
|
|
|
);
|
2013-02-16 22:55:39 +00:00
|
|
|
}
|
|
|
|
|
2018-06-08 14:25:11 +00:00
|
|
|
public function testConstructor() {
|
|
|
|
$renderer = new MathSource( 'a' );
|
|
|
|
|
2021-08-11 18:15:35 +00:00
|
|
|
$this->assertEquals( MathConfig::MODE_SOURCE, $renderer->getMode() );
|
2018-06-08 14:25:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRender() {
|
|
|
|
$renderer = new MathSource( 'a+b' );
|
|
|
|
|
|
|
|
$this->assertTrue( $renderer->render() );
|
|
|
|
$this->assertFalse( $renderer->isChanged() );
|
|
|
|
}
|
2015-01-10 01:55:54 +00:00
|
|
|
}
|