2016-02-09 19:53:51 +00:00
|
|
|
<?php
|
2018-03-10 12:17:05 +00:00
|
|
|
|
|
|
|
use DataValues\StringValue;
|
|
|
|
use Wikibase\DataModel\Entity\PropertyId;
|
|
|
|
use Wikibase\DataModel\Snak\PropertyValueSnak;
|
|
|
|
use Wikimedia\Purtle\NTriplesRdfWriter;
|
|
|
|
|
2016-02-09 19:53:51 +00:00
|
|
|
/**
|
|
|
|
* Test the MathML RDF formatter
|
|
|
|
*
|
|
|
|
* @group Math
|
2019-11-26 09:59:54 +00:00
|
|
|
* @covers \MathMLRdfBuilder
|
2016-02-09 19:53:51 +00:00
|
|
|
* @author Moritz Schubotz (physikerwelt)
|
|
|
|
*/
|
|
|
|
class MathMLRdfBuilderTest extends MediaWikiTestCase {
|
|
|
|
const ACME_PREFIX_URL = 'http://acme/';
|
|
|
|
const ACME_REF = 'testing';
|
|
|
|
protected static $hasRestbase;
|
|
|
|
|
2019-11-02 00:18:33 +00:00
|
|
|
public static function setUpBeforeClass() : void {
|
2016-02-09 19:53:51 +00:00
|
|
|
$rbi = new MathRestbaseInterface();
|
|
|
|
self::$hasRestbase = $rbi->checkBackend( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up the fixture, for example, opens a network connection.
|
|
|
|
* This method is called before a test is executed.
|
|
|
|
*/
|
2019-10-11 17:45:11 +00:00
|
|
|
protected function setUp() : void {
|
2016-02-09 19:53:51 +00:00
|
|
|
parent::setUp();
|
|
|
|
if ( !self::$hasRestbase ) {
|
|
|
|
$this->markTestSkipped( "Can not connect to Restbase Math interface." );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $test
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function makeCase( $test ) {
|
|
|
|
$builder = new MathMLRdfBuilder();
|
|
|
|
$writer = new NTriplesRdfWriter();
|
|
|
|
$writer->prefix( 'www', "http://www/" );
|
|
|
|
$writer->prefix( 'acme', self::ACME_PREFIX_URL );
|
|
|
|
|
|
|
|
$writer->start();
|
|
|
|
$writer->about( 'www', 'Q1' );
|
|
|
|
|
|
|
|
$snak = new PropertyValueSnak( new PropertyId( 'P1' ), new StringValue( $test ) );
|
|
|
|
$builder->addValue( $writer, 'acme', self::ACME_REF, 'DUMMY', $snak );
|
|
|
|
|
|
|
|
return trim( $writer->drain() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testValidInput() {
|
|
|
|
$triples = $this->makeCase( 'a^2' );
|
|
|
|
$this->assertContains( self::ACME_PREFIX_URL . self::ACME_REF . '> "<math', $triples );
|
|
|
|
$this->assertContains( '<mi>a</mi>\n', $triples );
|
|
|
|
$this->assertContains( '<mn>2</mn>\n', $triples );
|
|
|
|
$this->assertContains( 'a^{2}', $triples );
|
|
|
|
$this->assertContains( '^^<http://www.w3.org/1998/Math/MathML> .', $triples );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvalidInput() {
|
|
|
|
$triples = $this->makeCase( '\notExists' );
|
|
|
|
$this->assertContains( '<math', $triples );
|
|
|
|
$this->assertContains( 'unknown function', $triples );
|
|
|
|
$this->assertContains( 'notExists', $triples );
|
|
|
|
$this->assertContains( '^^<http://www.w3.org/1998/Math/MathML> .', $triples );
|
|
|
|
}
|
|
|
|
}
|