2015-12-14 20:26:29 +00:00
|
|
|
<?php
|
2016-02-12 16:57:37 +00:00
|
|
|
|
|
|
|
use DataValues\StringValue;
|
|
|
|
use DataValues\NumberValue;
|
|
|
|
|
2015-12-14 20:26:29 +00:00
|
|
|
/**
|
|
|
|
* Test the results of MathFormatter
|
|
|
|
*
|
2016-02-12 16:57:37 +00:00
|
|
|
* @covers MathFormatter
|
|
|
|
*
|
2015-12-14 20:26:29 +00:00
|
|
|
* @group Math
|
2016-02-12 16:57:37 +00:00
|
|
|
*
|
|
|
|
* @licence GNU GPL v2+
|
2015-12-14 20:26:29 +00:00
|
|
|
*/
|
|
|
|
class MathFormatterTest extends MediaWikiTestCase {
|
2016-01-25 15:38:53 +00:00
|
|
|
|
|
|
|
const SOME_TEX = 'a^2+b^2=c^2';
|
2015-12-14 20:26:29 +00:00
|
|
|
|
|
|
|
protected static $hasRestbase;
|
|
|
|
|
|
|
|
public static function setUpBeforeClass() {
|
|
|
|
$rbi = new MathRestbaseInterface();
|
|
|
|
self::$hasRestbase = $rbi->checkBackend( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
2016-01-25 15:38:53 +00:00
|
|
|
|
2015-12-14 20:26:29 +00:00
|
|
|
if ( !self::$hasRestbase ) {
|
2016-01-25 15:38:53 +00:00
|
|
|
$this->markTestSkipped( 'Can not connect to Restbase Math interface.' );
|
2015-12-14 20:26:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks the
|
|
|
|
* @covers MathFormatter::__construct()
|
|
|
|
*/
|
|
|
|
public function testBasics() {
|
2016-01-25 15:38:53 +00:00
|
|
|
$formatter = new MathFormatter( 'text/plain' );
|
2015-12-14 20:26:29 +00:00
|
|
|
// check if the format input was corretly passed to the class
|
2016-01-25 15:38:53 +00:00
|
|
|
$this->assertSame( 'text/plain', $formatter->getFormat(), 'test getFormat' );
|
2015-12-14 20:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException ValueFormatters\Exceptions\MismatchingDataValueTypeException
|
|
|
|
*/
|
|
|
|
public function testNotStringValue() {
|
2016-01-25 15:38:53 +00:00
|
|
|
$formatter = new MathFormatter( 'text/plain' );
|
2015-12-14 20:26:29 +00:00
|
|
|
$formatter->format( new NumberValue( 0 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException ValueFormatters\Exceptions\MismatchingDataValueTypeException
|
|
|
|
*/
|
|
|
|
public function testNullValue() {
|
2016-01-25 15:38:53 +00:00
|
|
|
$formatter = new MathFormatter( 'text/plain' );
|
2015-12-14 20:26:29 +00:00
|
|
|
$formatter->format( null );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testUnknownFormat() {
|
2016-01-25 15:38:53 +00:00
|
|
|
new MathFormatter( 'unknown/unknown' );
|
2015-12-14 20:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFormatPlain() {
|
2016-01-25 15:38:53 +00:00
|
|
|
$formatter = new MathFormatter( 'text/plain' );
|
2015-12-14 20:26:29 +00:00
|
|
|
$value = new StringValue( self::SOME_TEX );
|
|
|
|
$resultFormat = $formatter->format( $value );
|
2016-01-25 15:38:53 +00:00
|
|
|
$this->assertSame( self::SOME_TEX, $resultFormat );
|
2015-12-14 20:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFormatHtml() {
|
2016-01-25 15:38:53 +00:00
|
|
|
$formatter = new MathFormatter( 'text/html' );
|
2015-12-14 20:26:29 +00:00
|
|
|
$value = new StringValue( self::SOME_TEX );
|
|
|
|
$resultFormat = $formatter->format( $value );
|
2016-01-25 15:38:53 +00:00
|
|
|
$this->assertContains( '</math>', $resultFormat, 'Result must contain math-tag' );
|
2015-12-14 20:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFormatXWiki() {
|
|
|
|
$tex = self::SOME_TEX;
|
2016-01-25 15:38:53 +00:00
|
|
|
$formatter = new MathFormatter( 'text/x-wiki' );
|
2015-12-14 20:26:29 +00:00
|
|
|
$value = new StringValue( self::SOME_TEX );
|
|
|
|
$resultFormat = $formatter->format( $value );
|
2016-01-25 15:38:53 +00:00
|
|
|
$this->assertSame( "<math>$tex</math>", $resultFormat, 'Tex wasn\'t properly wrapped' );
|
2015-12-14 20:26:29 +00:00
|
|
|
}
|
2016-01-25 15:38:53 +00:00
|
|
|
|
2015-12-14 20:26:29 +00:00
|
|
|
}
|