2014-02-09 19:02:15 +00:00
|
|
|
<?php
|
2016-02-12 16:57:37 +00:00
|
|
|
|
2014-02-09 19:02:15 +00:00
|
|
|
/**
|
|
|
|
* PHPUnit tests to test the wide range of all typical use cases for formulae at Wikipedia.
|
|
|
|
* To generate the page https://www.mediawiki.org/wiki/Extension:Math/CoverageTest is used to
|
|
|
|
* generate the test data.
|
|
|
|
* The testData is generated by the maintenance script Math/maintenance/MathGenerateTests.php.
|
|
|
|
* To update the test data locally with vagrant the following procedure is recommended:
|
|
|
|
*
|
2015-09-21 16:14:01 +00:00
|
|
|
* 1. copy the source from https://www.mediawiki.org/wiki/Extension:Math/CoverageTest
|
|
|
|
* to a new page e.g.
|
2014-02-09 19:02:15 +00:00
|
|
|
* MathTest at your local vagrant instance
|
2015-09-21 16:14:01 +00:00
|
|
|
* 2. run <code>php MathGenerateTests.php MathTest</code>
|
|
|
|
* in the maitenance folder of the Math extension.
|
2014-02-09 19:02:15 +00:00
|
|
|
* 3. Test local e.g. via
|
2015-09-21 16:14:01 +00:00
|
|
|
* <code>sudo php /vagrant/mediawiki/tests/phpunit/phpunit.php
|
|
|
|
* /vagrant/mediawiki/extensions/Math/tests/MathCoverageTest.php</code>
|
2014-02-09 19:02:15 +00:00
|
|
|
* (If you don't use sudo you might have problems with the permissions set at vagrant.)
|
|
|
|
*
|
2016-02-12 16:57:37 +00:00
|
|
|
* @covers MathRenderer
|
|
|
|
*
|
2014-02-09 19:02:15 +00:00
|
|
|
* @group Extensions
|
|
|
|
* @group Math
|
2016-02-12 16:57:37 +00:00
|
|
|
*
|
2018-03-29 03:44:44 +00:00
|
|
|
* @license GNU GPL v2+
|
2014-02-09 19:02:15 +00:00
|
|
|
*/
|
|
|
|
class MathCoverageTest extends MediaWikiTestCase {
|
|
|
|
protected static $hasTexvc;
|
|
|
|
protected static $texvcPath;
|
|
|
|
|
|
|
|
public static function setUpBeforeClass() {
|
|
|
|
global $wgTexvc;
|
|
|
|
|
|
|
|
if ( is_executable( $wgTexvc ) ) {
|
|
|
|
wfDebugLog( __CLASS__, " using build in texvc from "
|
|
|
|
. "\$wgMathTexvcCheckExecutable = $wgTexvc" );
|
|
|
|
# Using build-in
|
|
|
|
self::$hasTexvc = true;
|
|
|
|
self::$texvcPath = $wgTexvc;
|
|
|
|
} else {
|
|
|
|
# Attempt to compile
|
|
|
|
wfDebugLog( __CLASS__, " compiling texvc..." );
|
|
|
|
$cmd = 'cd ' . dirname( __DIR__ ) . '/math; make --always-make 2>&1';
|
|
|
|
wfShellExec( $cmd, $retval );
|
|
|
|
if ( $retval === 0 ) {
|
|
|
|
self::$hasTexvc = true;
|
|
|
|
self::$texvcPath = dirname( __DIR__ ) . '/math/texvc';
|
|
|
|
wfDebugLog( __CLASS__, ' compiled texvc at ' . self::$texvcPath );
|
|
|
|
} else {
|
|
|
|
wfDebugLog( __CLASS__, ' ocaml not available or compilation of texvc failed' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up the fixture, for example, opens a network connection.
|
|
|
|
* This method is called before a test is executed.
|
|
|
|
*/
|
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
if ( ! self::$hasTexvc ) {
|
|
|
|
$this->markTestSkipped( "No texvc installed on server" );
|
|
|
|
} else {
|
|
|
|
$this->setMwGlobals( 'wgTexvc',
|
|
|
|
self::$texvcPath );
|
|
|
|
}
|
|
|
|
}
|
2015-09-21 16:14:01 +00:00
|
|
|
|
2014-02-09 19:02:15 +00:00
|
|
|
/**
|
|
|
|
* Loops over all test cases provided by the provider function.
|
|
|
|
* Compares each the rendering result of each input with the expected output.
|
2015-03-18 15:57:48 +00:00
|
|
|
* @dataProvider provideCoverage
|
2014-02-09 19:02:15 +00:00
|
|
|
*/
|
2015-09-21 16:14:01 +00:00
|
|
|
public function testCoverage( $input, $output ) {
|
2014-02-09 19:02:15 +00:00
|
|
|
// TODO: Make rendering mode configurable
|
|
|
|
// TODO: Provide test-ids
|
|
|
|
// TODO: Link to the wikipage that contains the reference rendering
|
2014-03-11 15:53:03 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
$this->normalize( $output ),
|
2016-04-12 20:53:25 +00:00
|
|
|
$this->normalize( MathRenderer::renderMath( $input, [], 'png' ) ),
|
2014-03-11 15:53:03 +00:00
|
|
|
"Failed to render $input"
|
|
|
|
);
|
2014-02-09 19:02:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-29 15:56:26 +00:00
|
|
|
* Gets the test-data from the file ParserTest.json
|
2017-07-10 09:40:12 +00:00
|
|
|
* @return string[] [ $input, $output ] where $input is the test input string
|
2015-09-21 16:14:01 +00:00
|
|
|
* and $output is the rendered html5-output string
|
2014-02-09 19:02:15 +00:00
|
|
|
*/
|
2015-03-18 15:57:48 +00:00
|
|
|
public function provideCoverage() {
|
2015-01-22 18:56:13 +00:00
|
|
|
return json_decode( file_get_contents( __DIR__ . '/ParserTest.json' ) );
|
2014-02-09 19:02:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function normalize( $input ) {
|
|
|
|
return preg_replace( '#src="(.*?)/(([a-f]|\d)*).png"#', 'src="\2.png"', $input );
|
|
|
|
}
|
2015-01-10 01:55:54 +00:00
|
|
|
}
|