mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-09-23 10:21:31 +00:00
Add php code sniffer to composer
Add support for php code sniffer Change-Id: I7dcdd88be4f1f8219f71ab770979284761e09bae
This commit is contained in:
parent
646fc8e94b
commit
df8ad1c799
|
@ -15,4 +15,4 @@ $specialPageAliases = array();
|
|||
/** English (English) */
|
||||
$specialPageAliases['en'] = array(
|
||||
'MathShowImage' => array( 'MathShowImage' )
|
||||
);
|
||||
);
|
||||
|
|
|
@ -9,11 +9,11 @@
|
|||
use MediaWiki\Logger\LoggerFactory;
|
||||
|
||||
class MathHooks {
|
||||
const mathCacheKey = 'math=';
|
||||
const MATHCACHEKEY = 'math=';
|
||||
|
||||
public static function mathConstantToString( $value, array $defs, $prefix, $default ){
|
||||
public static function mathConstantToString( $value, array $defs, $prefix, $default ) {
|
||||
foreach ( $defs as $defKey => $defValue ) {
|
||||
if( !defined( $defKey ) ) {
|
||||
if ( !defined( $defKey ) ) {
|
||||
define( $defKey, $defValue );
|
||||
} elseif ( $defValue !== constant( $defKey ) ) {
|
||||
throw new Exception( 'Math constant "'. $defKey . '" has unexpected value "' .
|
||||
|
@ -22,7 +22,7 @@ class MathHooks {
|
|||
}
|
||||
$invDefs = array_flip( $defs );
|
||||
if ( is_int( $value ) ){
|
||||
if ( array_key_exists( $value , $invDefs ) ) {
|
||||
if ( array_key_exists( $value, $invDefs ) ) {
|
||||
$value = $invDefs[$value];
|
||||
} else {
|
||||
return $default;
|
||||
|
@ -37,7 +37,7 @@ class MathHooks {
|
|||
}
|
||||
if ( array_key_exists( $value, $defs ) ) {
|
||||
return $newValues[$value];
|
||||
} elseif (in_array( $value, $newValues) ){
|
||||
} elseif ( in_array( $value, $newValues ) ){
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ class MathHooks {
|
|||
}
|
||||
|
||||
public static function mathStyleToString( $style, $default = 'inlineDisplaystyle' ) {
|
||||
$defs = array (
|
||||
$defs = array(
|
||||
'MW_MATHSTYLE_INLINE_DISPLAYSTYLE' => 0, // default large operator inline
|
||||
'MW_MATHSTYLE_DISPLAY' => 1, // large operators centered in a new line
|
||||
'MW_MATHSTYLE_INLINE' => 2, // small operators inline
|
||||
|
@ -55,7 +55,7 @@ class MathHooks {
|
|||
}
|
||||
|
||||
public static function mathCheckToString( $style, $default = 'always' ) {
|
||||
$defs = array (
|
||||
$defs = array(
|
||||
'MW_MATH_CHECK_ALWAYS' => 0,
|
||||
'MW_MATH_CHECK_NEVER' => 1,
|
||||
'MW_MATH_CHECK_NEW' => 2,
|
||||
|
@ -71,7 +71,7 @@ class MathHooks {
|
|||
// 'MW_MATH_MATHJAX' => 6
|
||||
// 'MW_MATH_LATEXML_JAX' => 8
|
||||
|
||||
$defs = array (
|
||||
$defs = array(
|
||||
'MW_MATH_PNG' => 0,
|
||||
'MW_MATH_SOURCE' => 3,
|
||||
'MW_MATH_MATHML' => 5,
|
||||
|
@ -81,7 +81,7 @@ class MathHooks {
|
|||
}
|
||||
|
||||
public static function mathModeToHashKey( $mode, $default = 0 ) {
|
||||
$defs = array (
|
||||
$defs = array(
|
||||
'png' => 0,
|
||||
'source' => 3,
|
||||
'mathml' => 5,
|
||||
|
@ -116,19 +116,20 @@ class MathHooks {
|
|||
// Check if the key already contains the math option part
|
||||
if (
|
||||
!preg_match(
|
||||
'/(^|!)' . self::mathCacheKey . $mathOption . '(!|$)/',
|
||||
'/(^|!)' . self::MATHCACHEKEY . $mathOption . '(!|$)/',
|
||||
$confstr
|
||||
)
|
||||
) {
|
||||
// The math part of cache key starts with "math=" followed by a star or a number for the math mode
|
||||
if ( preg_match( '/(^|!)' . self::mathCacheKey . '[*\d]m?(!|$)/', $confstr ) ) {
|
||||
// The math part of cache key starts with "math="
|
||||
// followed by a star or a number for the math mode
|
||||
if ( preg_match( '/(^|!)' . self::MATHCACHEKEY . '[*\d]m?(!|$)/', $confstr ) ) {
|
||||
$confstr = preg_replace(
|
||||
'/(^|!)' . self::mathCacheKey . '[*\d]m?(!|$)/',
|
||||
'\1' . self::mathCacheKey . $mathOption . '\2',
|
||||
'/(^|!)' . self::MATHCACHEKEY . '[*\d]m?(!|$)/',
|
||||
'\1' . self::MATHCACHEKEY . $mathOption . '\2',
|
||||
$confstr
|
||||
);
|
||||
} else {
|
||||
$confstr .= '!' . self::mathCacheKey . $mathOption;
|
||||
$confstr .= '!' . self::MATHCACHEKEY . $mathOption;
|
||||
}
|
||||
|
||||
LoggerFactory::getInstance( 'Math' )->debug( "New cache key: $confstr" );
|
||||
|
@ -239,7 +240,7 @@ class MathHooks {
|
|||
// If the default option is not in the valid options the
|
||||
// user interface throws an exception (BUG 64844)
|
||||
$mode = MathHooks::mathModeToString( $wgDefaultUserOptions['math'] );
|
||||
if ( ! in_array( $mode , MathRenderer::getValidModes() ) ) {
|
||||
if ( ! in_array( $mode, MathRenderer::getValidModes() ) ) {
|
||||
LoggerFactory::getInstance( 'Math' )->error( 'Misconfiguration: '.
|
||||
"\$wgDefaultUserOptions['math'] is not in " . MathRenderer::getValidModes() . ".\n".
|
||||
"Please check your LocalSetting.php file." );
|
||||
|
@ -313,7 +314,7 @@ class MathHooks {
|
|||
throw new Exception( "Math extension does not currently support $type database for LaTeXML." );
|
||||
}
|
||||
}
|
||||
if ( in_array( 'mathml', MathRenderer::getValidModes() ) ) {
|
||||
if ( in_array( 'mathml', MathRenderer::getValidModes() ) ) {
|
||||
if ( in_array( $type, array( 'mysql', 'sqlite', 'postgres' ) ) ) {
|
||||
$sql = __DIR__ . '/db/mathoid.' . $type . '.sql';
|
||||
$updater->addExtensionTable( 'mathoid', $sql );
|
||||
|
|
2
Math.php
2
Math.php
|
@ -12,4 +12,4 @@ if ( function_exists( 'wfLoadExtension' ) ) {
|
|||
return;
|
||||
} else {
|
||||
die( 'This version of the Math extension requires MediaWiki 1.25+' );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
/**
|
||||
* MediaWiki math extension
|
||||
*
|
||||
* (c) 2002-2014 Tomasz Wegrzanowski, Brion Vibber, Moritz Schubotz, and other MediaWiki contributors
|
||||
* (c) 2002-2014 Tomasz Wegrzanowski, Brion Vibber, Moritz Schubotz,
|
||||
* and other MediaWiki contributors
|
||||
*
|
||||
* GPLv2 license; info in main package.
|
||||
*
|
||||
* @author Moritz Schubotz
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
/**
|
||||
* MediaWiki math extension
|
||||
*
|
||||
* (c) 2002-2015 Tomasz Wegrzanowski, Brion Vibber, Moritz Schubotz, and other MediaWiki contributors
|
||||
* (c) 2002-2015 Tomasz Wegrzanowski, Brion Vibber, Moritz Schubotz,
|
||||
* and other MediaWiki contributors
|
||||
* GPLv2 license; info in main package.
|
||||
*
|
||||
* @author Moritz Schubotz
|
||||
|
|
|
@ -107,7 +107,7 @@ class MathLaTeXML extends MathMathML {
|
|||
// There is an API-inconsistency between different versions of the LaTeXML daemon
|
||||
// some versions require the literal prefix other don't allow it.
|
||||
if ( ! strpos( $host, '/convert' ) ){
|
||||
$post = preg_replace( '/&tex=/' , '&tex=literal:', $post , 1);
|
||||
$post = preg_replace( '/&tex=/', '&tex=literal:', $post, 1 );
|
||||
}
|
||||
$this->lastError = '';
|
||||
$requestResult = $this->makeRequest( $host, $post, $res, $this->lastError );
|
||||
|
|
|
@ -24,7 +24,7 @@ class MathMathML extends MathRenderer {
|
|||
/**
|
||||
* @param string $inputType
|
||||
*/
|
||||
public function setInputType($inputType) {
|
||||
public function setInputType( $inputType ) {
|
||||
$this->inputType = $inputType;
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,9 @@ class MathMathML extends MathRenderer {
|
|||
* @param String $httpRequestClass class name of MWHttpRequest (needed for testing only)
|
||||
* @return boolean success
|
||||
*/
|
||||
public function makeRequest( $host, $post, &$res, &$error = '', $httpRequestClass = 'MWHttpRequest' ) {
|
||||
public function makeRequest(
|
||||
$host, $post, &$res, &$error = '', $httpRequestClass = 'MWHttpRequest'
|
||||
) {
|
||||
// TODO: Change the timeout mechanism.
|
||||
global $wgMathLaTeXMLTimeout;
|
||||
|
||||
|
@ -219,7 +221,7 @@ class MathMathML extends MathRenderer {
|
|||
if ( $this->getMathStyle() == 'inlineDisplaystyle' ) {
|
||||
// default preserve the (broken) layout as it was
|
||||
$out = 'type=inline-TeX&q=' . rawurlencode( '{\\displaystyle ' . $input . '}' );
|
||||
} elseif ($this->getMathStyle() == 'inline' ){
|
||||
} elseif ( $this->getMathStyle() == 'inline' ) {
|
||||
$out = 'type=inline-TeX&q=' . rawurlencode( $input );
|
||||
} else {
|
||||
$out = 'type=tex&q=' . rawurlencode( $input );
|
||||
|
@ -235,7 +237,9 @@ class MathMathML extends MathRenderer {
|
|||
*/
|
||||
protected function doRender() {
|
||||
if ( $this->getTex() === '' ) {
|
||||
LoggerFactory::getInstance( 'Math' )->debug( 'Rendering was requested, but no TeX string is specified.' );
|
||||
LoggerFactory::getInstance( 'Math' )->debug(
|
||||
'Rendering was requested, but no TeX string is specified.'
|
||||
);
|
||||
$this->lastError = $this->getError( 'math_empty_tex' );
|
||||
return false;
|
||||
}
|
||||
|
@ -299,12 +303,12 @@ class MathMathML extends MathRenderer {
|
|||
} else {
|
||||
$name = $xmlObject->getRootElement();
|
||||
$elementSplit = explode( ':', $name );
|
||||
if ( is_array($elementSplit) ) {
|
||||
if ( is_array( $elementSplit ) ) {
|
||||
$localName = end( $elementSplit );
|
||||
} else {
|
||||
$localName = $name;
|
||||
}
|
||||
if ( in_array( $localName , $this->getAllowedRootElements() ) ) {
|
||||
if ( in_array( $localName, $this->getAllowedRootElements() ) ) {
|
||||
$out = true;
|
||||
} else {
|
||||
LoggerFactory::getInstance( 'Math' )->error( "Got wrong root element : $name" );
|
||||
|
@ -336,14 +340,16 @@ class MathMathML extends MathRenderer {
|
|||
$style .= ' ' . $styles[1]; // merge styles
|
||||
if ( $this->getMathStyle() === 'display' ) {
|
||||
// TODO: Improve style cleaning
|
||||
$style = preg_replace( '/margin\-(left|right)\:\s*\d+(\%|in|cm|mm|em|ex|pt|pc|px)\;/', '', $style );
|
||||
$style = preg_replace(
|
||||
'/margin\-(left|right)\:\s*\d+(\%|in|cm|mm|em|ex|pt|pc|px)\;/', '', $style
|
||||
);
|
||||
}
|
||||
$style = preg_replace( '/position:\s*absolute;\s*left:\s*0px;/', '', $style );
|
||||
}
|
||||
// TODO: Figure out if there is a way to construct
|
||||
// a SVGReader from a string that represents the SVG
|
||||
// content
|
||||
if ( preg_match( "/height=\"(.*?)\"/" , $this->getSvg(), $matches ) ) {
|
||||
if ( preg_match( "/height=\"(.*?)\"/", $this->getSvg(), $matches ) ) {
|
||||
$style .= 'height: ' . $matches[1] . '; ';
|
||||
}
|
||||
if ( preg_match( "/width=\"(.*?)\"/", $this->getSvg(), $matches ) ) {
|
||||
|
@ -353,8 +359,10 @@ class MathMathML extends MathRenderer {
|
|||
|
||||
/**
|
||||
* Gets img tag for math image
|
||||
* @param boolean $noRender if true no rendering will be performed if the image is not stored in the database
|
||||
* @param boolean|string $classOverride if classOverride is false the class name will be calculated by getClassName
|
||||
* @param boolean $noRender if true no rendering will be performed
|
||||
* if the image is not stored in the database
|
||||
* @param boolean|string $classOverride if classOverride
|
||||
* is false the class name will be calculated by getClassName
|
||||
* @return string XML the image html tag
|
||||
*/
|
||||
private function getFallbackImage( $noRender = false, $classOverride = false ) {
|
||||
|
@ -364,23 +372,28 @@ class MathMathML extends MathRenderer {
|
|||
if ( $classOverride === false ) { // $class = '' suppresses class attribute
|
||||
$class = $this->getClassName( true );
|
||||
} else {
|
||||
$class = $classOverride;
|
||||
$class = $classOverride;
|
||||
}
|
||||
|
||||
// TODO: move the common styles to the global stylesheet!
|
||||
$style = 'background-image: url(\''. $url .
|
||||
'\'); background-repeat: no-repeat; background-size: 100% 100%;';
|
||||
$this->correctSvgStyle( $this->getSvg(), $style );
|
||||
if ( $class ) { $attribs['class'] = $class; }
|
||||
if ( $class ) {
|
||||
$attribs['class'] = $class;
|
||||
}
|
||||
|
||||
// Don't use an empty span, as that is going to be stripped by HTML tidy
|
||||
// when enabled (which is true in production).
|
||||
return Xml::element( 'meta', $this->getAttributes( 'span', $attribs , array( 'aria-hidden' => 'true', 'style' => $style ) ) );
|
||||
return Xml::element( 'meta', $this->getAttributes(
|
||||
'span', $attribs, array( 'aria-hidden' => 'true', 'style' => $style
|
||||
) ) );
|
||||
}
|
||||
|
||||
|
||||
protected function getMathTableName() {
|
||||
return 'mathoid';
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the default class name for a math element
|
||||
* @param boolean $fallback
|
||||
|
@ -398,11 +411,14 @@ class MathMathML extends MathRenderer {
|
|||
} else {
|
||||
$class .= 'inline';
|
||||
}
|
||||
if ( !$fallback) {
|
||||
if ( !$fallback ) {
|
||||
// @codingStandardsIgnoreStart
|
||||
$class .= ' mwe-math-mathml-a11y';
|
||||
// @codingStandardsIgnoreEnd
|
||||
}
|
||||
return $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Html output that is embedded in the page
|
||||
*/
|
||||
|
@ -420,28 +436,32 @@ class MathMathML extends MathRenderer {
|
|||
// MathML has to be wrapped into a div or span in order to be able to hide it.
|
||||
// Remove displayStyle attributes set by the MathML converter
|
||||
// (Beginning from Mathoid 0.2.5 block is the default layout.)
|
||||
$mml = preg_replace( '/(<math[^>]*)(display|mode)=["\'](inline|block)["\']/', '$1', $this->getMathml() );
|
||||
$mml = preg_replace(
|
||||
'/(<math[^>]*)(display|mode)=["\'](inline|block)["\']/', '$1', $this->getMathml()
|
||||
);
|
||||
if ( $this->getMathStyle() == 'display' ) {
|
||||
$mml = preg_replace( '/<math/', '<math display="block"', $mml );
|
||||
}
|
||||
$output .= Xml::tags( $element, array( 'class' => $this->getClassName(), 'style' => 'display: none;' ), $mml );
|
||||
$output .= $this->getFallbackImage( );
|
||||
$output .= Xml::tags( $element, array(
|
||||
'class' => $this->getClassName(), 'style' => 'display: none;'
|
||||
), $mml );
|
||||
$output .= $this->getFallbackImage();
|
||||
$output .= HTML::closeElement( $element );
|
||||
return $output;
|
||||
}
|
||||
|
||||
protected function dbOutArray() {
|
||||
$out = parent::dbOutArray();
|
||||
if ($this->getMathTableName() == 'mathoid' ) {
|
||||
if ( $this->getMathTableName() == 'mathoid' ) {
|
||||
$out['math_input'] = $out['math_inputtex'];
|
||||
unset($out['math_inputtex']);
|
||||
unset( $out['math_inputtex'] );
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
protected function dbInArray() {
|
||||
$out = parent::dbInArray();
|
||||
if ($this->getMathTableName() == 'mathoid' ) {
|
||||
if ( $this->getMathTableName() == 'mathoid' ) {
|
||||
$out = array_diff( $out, array( 'math_inputtex' ) );
|
||||
$out[] = 'math_input';
|
||||
}
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
/**
|
||||
* MediaWiki math extension
|
||||
*
|
||||
* (c) 2002-2012 Tomasz Wegrzanowski, Brion Vibber, Moritz Schubotz, and other MediaWiki contributors
|
||||
* (c) 2002-2012 Tomasz Wegrzanowski, Brion Vibber, Moritz Schubotz,
|
||||
* and other MediaWiki contributors
|
||||
* GPLv2 license; info in main package.
|
||||
*
|
||||
* @file
|
||||
|
@ -187,7 +188,9 @@ abstract class MathRenderer {
|
|||
* Returns an internationalized HTML error string
|
||||
*
|
||||
* @param string $msg message key for specific error
|
||||
* @internal param \Varargs $parameters (optional) zero or more message parameters for specific error
|
||||
* @internal param \Varargs $parameters (optional) zero
|
||||
* or more message parameters for specific error
|
||||
*
|
||||
* @return string HTML error string
|
||||
*/
|
||||
public function getError( $msg /*, ... */ ) {
|
||||
|
@ -291,7 +294,8 @@ abstract class MathRenderer {
|
|||
if ( ! empty( $rpage->math_mathml ) ) {
|
||||
$this->mathml = utf8_decode( $rpage->math_mathml );
|
||||
}
|
||||
if ( ! empty( $rpage->math_inputtex ) ) { // in the current database the field is probably not set.
|
||||
if ( ! empty( $rpage->math_inputtex ) ) {
|
||||
// in the current database the field is probably not set.
|
||||
$this->userInputTex = $rpage->math_inputtex;
|
||||
}
|
||||
if ( ! empty( $rpage->math_tex ) ) {
|
||||
|
@ -308,7 +312,8 @@ abstract class MathRenderer {
|
|||
*
|
||||
* WARNING: Use writeCache() instead of this method to be sure that all
|
||||
* renderer specific (such as squid caching) are taken into account.
|
||||
* This function stores the values that are currently present in the class to the database even if they are empty.
|
||||
* This function stores the values that are currently present in the class
|
||||
* to the database even if they are empty.
|
||||
*
|
||||
* This function can be seen as protected function.
|
||||
* @param DatabaseBase $dbw
|
||||
|
@ -494,7 +499,7 @@ abstract class MathRenderer {
|
|||
* Checks if there is an explicit user request to rerender the math-tag.
|
||||
* @return boolean
|
||||
*/
|
||||
function isPurge( ) {
|
||||
function isPurge() {
|
||||
if ( $this->purge ) {
|
||||
return true;
|
||||
}
|
||||
|
@ -562,8 +567,8 @@ abstract class MathRenderer {
|
|||
// equation was already checked or checking is disabled
|
||||
return true;
|
||||
} else {
|
||||
if( self::getDisableTexFilter() == 'new' && $this->mode != 'source' ){
|
||||
if( $this->readFromDatabase() ){
|
||||
if ( self::getDisableTexFilter() == 'new' && $this->mode != 'source' ){
|
||||
if ( $this->readFromDatabase() ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -635,20 +640,20 @@ abstract class MathRenderer {
|
|||
return trim( $this->svg );
|
||||
}
|
||||
|
||||
protected abstract function getMathTableName();
|
||||
abstract protected function getMathTableName();
|
||||
|
||||
public function getModeStr() {
|
||||
$names = MathHooks::getMathNames();
|
||||
return $names[ $this->getMode() ];
|
||||
}
|
||||
|
||||
public static function getValidModes(){
|
||||
public static function getValidModes() {
|
||||
global $wgMathValidModes;
|
||||
return array_map( "MathHooks::mathModeToString", $wgMathValidModes );
|
||||
}
|
||||
|
||||
|
||||
public static function getDisableTexFilter(){
|
||||
public static function getDisableTexFilter() {
|
||||
global $wgMathDisableTexFilter;
|
||||
return MathHooks::mathCheckToString( $wgMathDisableTexFilter );
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ class MathSource extends MathRenderer {
|
|||
}
|
||||
|
||||
protected function getMathTableName() {
|
||||
throw new Exception ( 'in math source mode no database caching should happen');
|
||||
throw new Exception( 'in math source mode no database caching should happen' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
/**
|
||||
* MediaWiki math extension
|
||||
*
|
||||
* (c) 2002-2012 Tomasz Wegrzanowski, Brion Vibber, Moritz Schubotz, and other MediaWiki contributors
|
||||
* (c) 2002-2012 Tomasz Wegrzanowski, Brion Vibber, Moritz Schubotz,
|
||||
* and other MediaWiki contributors
|
||||
* GPLv2 license; info in main package.
|
||||
*
|
||||
* Contains the driver function for the texvc program
|
||||
|
@ -29,7 +30,7 @@ class MathTexvc extends MathRenderer {
|
|||
const LIBERAL = 0;
|
||||
const MW_TEXVC_SUCCESS = -1;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Gets an array that matches the variables of the class to the database columns
|
||||
* @return array
|
||||
*/
|
||||
|
@ -397,7 +398,9 @@ class MathTexvc extends MathRenderer {
|
|||
Hooks::run( 'ParserAfterParse', array( &$parser, &$text, &$stripState ) );
|
||||
}
|
||||
$backend = $this->getBackend();
|
||||
return $backend->getFileContents( array( 'src' => $this->getHashPath() . "/" . $this->getHash() . '.png' ) );
|
||||
return $backend->getFileContents(
|
||||
array( 'src' => $this->getHashPath() . "/" . $this->getHash() . '.png' )
|
||||
);
|
||||
}
|
||||
|
||||
public function isInDatabase() {
|
||||
|
|
|
@ -34,7 +34,9 @@ class SpecialMathShowImage extends SpecialPage {
|
|||
$request->response()->header( "Content-type: image/svg+xml; charset=utf-8" );
|
||||
}
|
||||
if ( $success && !( $this->noRender ) ) {
|
||||
$request->response()->header( 'Cache-Control: public, s-maxage=604800, max-age=3600' ); // 1 week (server) 1 hour (client)
|
||||
$request->response()->header(
|
||||
'Cache-Control: public, s-maxage=604800, max-age=3600'
|
||||
); // 1 week (server) 1 hour (client)
|
||||
$request->response()->header( 'Vary: User-Agent' );
|
||||
}
|
||||
}
|
||||
|
@ -79,16 +81,20 @@ class SpecialMathShowImage extends SpecialPage {
|
|||
// and render the conventional way
|
||||
$mmlRenderer = MathMathML::newFromMd5( $hash );
|
||||
$mmlRenderer->readFromDatabase();
|
||||
$this->renderer = MathRenderer::getRenderer( $mmlRenderer->getUserInputTex(), array(), 'png' );
|
||||
$this->renderer = MathRenderer::getRenderer(
|
||||
$mmlRenderer->getUserInputTex(), array(), 'png'
|
||||
);
|
||||
$this->renderer->setMathStyle( $mmlRenderer->getMathStyle() );
|
||||
}
|
||||
$success = $this->renderer->render();
|
||||
}
|
||||
} elseif ( $asciimath === '' ) {
|
||||
$this->renderer = MathRenderer::getRenderer( $tex , array(), $this->mode );
|
||||
$this->renderer = MathRenderer::getRenderer( $tex, array(), $this->mode );
|
||||
$success = $this->renderer->render();
|
||||
} else {
|
||||
$this->renderer = MathRenderer::getRenderer( $asciimath , array( 'type' => 'ascii' ), $this->mode );
|
||||
$this->renderer = MathRenderer::getRenderer(
|
||||
$asciimath, array( 'type' => 'ascii' ), $this->mode
|
||||
);
|
||||
$success = $this->renderer->render();
|
||||
}
|
||||
if ( $success ) {
|
||||
|
@ -120,11 +126,12 @@ class SpecialMathShowImage extends SpecialPage {
|
|||
*/
|
||||
private function printSvgError( $msg ) {
|
||||
global $wgDebugComments;
|
||||
$result = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 4"
|
||||
preserveAspectRatio="xMidYMid meet" >' .
|
||||
// @codingStandardsIgnoreStart
|
||||
$result = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 4" preserveAspectRatio="xMidYMid meet" >' .
|
||||
'<text text-anchor="start" fill="red" y="2">' . htmlspecialchars( $msg ) . '</text></svg>';
|
||||
// @codingStandardsIgnoreEnd
|
||||
if ( $wgDebugComments ) {
|
||||
$result .= '<!--'. var_export($this->renderer, true) .'-->';
|
||||
$result .= '<!--'. var_export( $this->renderer, true ) .'-->';
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
|
||||
/**
|
||||
* MediaWiki math extension
|
||||
*
|
||||
* (c) 2002-2015 Tomasz Wegrzanowski, Brion Vibber, Moritz Schubotz, and other MediaWiki contributors
|
||||
* (c) 2002-2015 Tomasz Wegrzanowski, Brion Vibber, Moritz Schubotz,
|
||||
* and other MediaWiki contributors
|
||||
* GPLv2 license; info in main package.
|
||||
*
|
||||
* @author Moritz Schubotz
|
||||
|
@ -34,7 +37,7 @@ class SpecialMathStatus extends SpecialPage {
|
|||
|
||||
foreach ( $enabledMathModes as $modeNr => $modeName ){
|
||||
$out->addWikiText( "=== $modeName ===" );
|
||||
switch( $modeNr ){
|
||||
switch ( $modeNr ) {
|
||||
case 'mathml':
|
||||
$this->runMathMLTest( $modeName );
|
||||
break;
|
||||
|
@ -62,8 +65,10 @@ class SpecialMathStatus extends SpecialPage {
|
|||
public function testSpecialCaseText() {
|
||||
$renderer = MathRenderer::getRenderer( 'x^2+\text{a sample Text}', array(), 'mathml' );
|
||||
$expected = 'a sample Text</mtext>';
|
||||
$this->assertTrue( $renderer->render(), 'Rendering the input "x^2+\text{a sample Text}"' );
|
||||
$this->assertContains( $expected, $renderer->getHtmlOutput(), 'Comparing to the reference rendering' );
|
||||
$this->assertTrue( $renderer->render(), 'Rendering the input "x^2+\text{a sample Text}"' );
|
||||
$this->assertContains(
|
||||
$expected, $renderer->getHtmlOutput(), 'Comparing to the reference rendering'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,6 +76,7 @@ class SpecialMathStatus extends SpecialPage {
|
|||
* i.e. if the span element is generated right.
|
||||
*/
|
||||
public function testMathMLIntegration() {
|
||||
// @codingStandardsIgnoreStart
|
||||
$svgRef = '<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg xmlns:xlink="http://www.w3.org/1999/xlink" style="vertical-align: -0.333ex; " width="5.167ex" height="1.833ex" viewBox="0 -717.9 2195.4 823.9" xmlns="http://www.w3.org/2000/svg" role="math" aria-labelledby="MathJax-SVG-1-Title MathJax-SVG-1-Desc">
|
||||
|
@ -87,22 +93,28 @@ class SpecialMathStatus extends SpecialPage {
|
|||
<use xlink:href="#E1-MJMATHI-62" x="1761" y="0"></use>
|
||||
</g>
|
||||
</svg>';
|
||||
// @codingStandardsIgnoreEnd
|
||||
$renderer = MathRenderer::getRenderer( "a+b", array(), 'mathml' );
|
||||
$this->assertTrue( $renderer->render( true ), "Rendering of a+b in plain MathML mode" );
|
||||
$real = str_replace( "\n", '', $renderer->getHtmlOutput() );
|
||||
$expected = '<mo>+</mo>';
|
||||
$this->assertContains( $expected, $real, "Checking the presence of '+' in the MathML output" );
|
||||
$this->assertEquals( $svgRef, $renderer->getSvg(), "Comparing the generated SVG with the reference" );
|
||||
$this->assertEquals(
|
||||
$svgRef, $renderer->getSvg(), "Comparing the generated SVG with the reference"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the experimental option to 'render' MathML input
|
||||
*/
|
||||
public function testPmmlInput() {
|
||||
// sample from 'Navajo Coal Combustion and Respiratory Health Near Shiprock, New Mexico' in ''Journal of Environmental and Public Health'' , vol. 2010p.
|
||||
// authors Joseph E. Bunnell; Linda V. Garcia; Jill M. Furst; Harry Lerch; Ricardo A. Olea; Stephen E. Suitt; Allan Kolker
|
||||
// sample from 'Navajo Coal Combustion and Respiratory Health Near Shiprock,
|
||||
// New Mexico' in ''Journal of Environmental and Public Health'' , vol. 2010p.
|
||||
// authors Joseph E. Bunnell; Linda V. Garcia; Jill M. Furst;
|
||||
// Harry Lerch; Ricardo A. Olea; Stephen E. Suitt; Allan Kolker
|
||||
// @codingStandardsIgnoreStart
|
||||
$inputSample = '<msub> <mrow> <mi> P</mi> </mrow> <mrow> <mi> i</mi> <mi> j</mi> </mrow> </msub> <mo> =</mo> <mfrac> <mrow> <mn> 100</mn> <msub> <mrow> <mi> d</mi> </mrow> <mrow> <mi> i</mi> <mi> j</mi> </mrow> </msub> </mrow> <mrow> <mn> 6.75</mn> <msub> <mrow> <mi> r</mi> </mrow> <mrow> <mi> j</mi> </mrow> </msub> </mrow> </mfrac> <mo> ,</mo> </math>';
|
||||
$attribs = array( 'type' => 'pmml' );
|
||||
// @codingStandardsIgnoreEnd
|
||||
$renderer = new MathMathML( $inputSample, $attribs );
|
||||
$this->assertEquals( 'pmml', $renderer->getInputType(), 'Checking if MathML input is supported' );
|
||||
$this->assertTrue( $renderer->render(), 'Rendering Presentation MathML sample' );
|
||||
|
@ -118,10 +130,12 @@ class SpecialMathStatus extends SpecialPage {
|
|||
public function testLaTeXMLIntegration() {
|
||||
$renderer = MathRenderer::getRenderer( "a+b", array(), 'latexml' );
|
||||
$this->assertTrue( $renderer->render( true ), "Rendering of a+b in LaTeXML mode" );
|
||||
// @codingStandardsIgnoreStart
|
||||
$expected = '<math xmlns="http://www.w3.org/1998/Math/MathML" id="p1.1.m1.1" class="ltx_Math" alttext="{\displaystyle a+b}" ><semantics id="p1.1.m1.1a"><mrow id="p1.1.m1.1.4" xref="p1.1.m1.1.4.cmml"><mi id="p1.1.m1.1.1" xref="p1.1.m1.1.1.cmml">a</mi><mo id="p1.1.m1.1.2" xref="p1.1.m1.1.2.cmml">+</mo><mi id="p1.1.m1.1.3" xref="p1.1.m1.1.3.cmml">b</mi></mrow><annotation-xml encoding="MathML-Content" id="p1.1.m1.1b"><apply id="p1.1.m1.1.4.cmml" xref="p1.1.m1.1.4"><plus id="p1.1.m1.1.2.cmml" xref="p1.1.m1.1.2"/><ci id="p1.1.m1.1.1.cmml" xref="p1.1.m1.1.1">a</ci><ci id="p1.1.m1.1.3.cmml" xref="p1.1.m1.1.3">b</ci></apply></annotation-xml><annotation encoding="application/x-tex" id="p1.1.m1.1c">{\displaystyle a+b}</annotation></semantics></math>';
|
||||
// @codingStandardsIgnoreEnd
|
||||
$real = preg_replace( "/\n\\s*/", '', $renderer->getHtmlOutput() );
|
||||
$this->assertContains( $expected, $real
|
||||
, "Comparing the output to the MathML reference rendering" .
|
||||
$this->assertContains( $expected, $real,
|
||||
"Comparing the output to the MathML reference rendering" .
|
||||
$renderer->getLastError() );
|
||||
}
|
||||
|
||||
|
@ -134,7 +148,7 @@ class SpecialMathStatus extends SpecialPage {
|
|||
global $wgMathDefaultLaTeXMLSetting;
|
||||
$tex = '';
|
||||
$testMax = ceil( $wgMathDefaultLaTeXMLSetting[ 'linelength' ] / 2 );
|
||||
for( $i = 0; $i < $testMax; $i++ ) {
|
||||
for ( $i = 0; $i < $testMax; $i++ ) {
|
||||
$tex .= "$i+";
|
||||
}
|
||||
$tex .= $testMax;
|
||||
|
@ -142,17 +156,16 @@ class SpecialMathStatus extends SpecialPage {
|
|||
$this->assertTrue( $renderer->render( true ), "Rendering of linebreak test in LaTeXML mode" );
|
||||
$expected = 'mtr';
|
||||
$real = preg_replace( "/\n\\s*/", '', $renderer->getHtmlOutput() );
|
||||
$this->assertContains( $expected, $real
|
||||
, "Checking for linebreak" .
|
||||
$this->assertContains( $expected, $real, "Checking for linebreak" .
|
||||
$renderer->getLastError() );
|
||||
}
|
||||
|
||||
private function assertTrue( $expression, $message = '' ) {
|
||||
if ( $expression ){
|
||||
$this->getOutput()->addWikiMsgArray( 'math-test-success' , $message );
|
||||
$this->getOutput()->addWikiMsgArray( 'math-test-success', $message );
|
||||
return true;
|
||||
} else {
|
||||
$this->getOutput()->addWikiMsgArray( 'math-test-fail' , $message );
|
||||
$this->getOutput()->addWikiMsgArray( 'math-test-fail', $message );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
{
|
||||
"require-dev": {
|
||||
"jakub-onderka/php-parallel-lint": "0.9.*"
|
||||
"jakub-onderka/php-parallel-lint": "0.9.*",
|
||||
"mediawiki/mediawiki-codesniffer": "0.3.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": [
|
||||
"parallel-lint . --exclude vendor"
|
||||
"parallel-lint . --exclude vendor",
|
||||
"phpcs -p"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,12 +25,13 @@ class MathGenerateTests extends Maintenance
|
|||
{
|
||||
const REFERENCE_PAGE = 'mediawikiwiki:Extension:Math/CoverageTest';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->mDescription = 'Rebuilds the MathCoverage tests';
|
||||
$this->addArg( 'page', "The page used for the testset generation.", false );
|
||||
$this->addOption( 'offset', "If set the first n equations on the page are skipped", false, true, "o" );
|
||||
$this->addOption(
|
||||
'offset', "If set the first n equations on the page are skipped", false, true, "o"
|
||||
);
|
||||
$this->addOption( 'length', "If set the only n equations were processed", false, true, "l" );
|
||||
$this->addOption( 'user', "User with rights to view the page", false, true, "u" );
|
||||
|
||||
|
@ -59,8 +60,7 @@ class MathGenerateTests extends Maintenance
|
|||
return $math;
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
public function execute() {
|
||||
global $wgUser;
|
||||
$parserTests = array();
|
||||
$page = $this->getArg( 0, self::REFERENCE_PAGE );
|
||||
|
@ -85,7 +85,9 @@ class MathGenerateTests extends Maintenance
|
|||
echo '.';
|
||||
}
|
||||
echo "Generated $i tests\n";
|
||||
file_put_contents( __DIR__ . '/../tests/ParserTest.json', json_encode( $parserTests, JSON_PRETTY_PRINT ) );
|
||||
file_put_contents(
|
||||
__DIR__ . '/../tests/ParserTest.json', json_encode( $parserTests, JSON_PRETTY_PRINT )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
7
phpcs.xml
Normal file
7
phpcs.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0"?>
|
||||
<ruleset>
|
||||
<rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
|
||||
<file>.</file>
|
||||
<arg name="extensions" value="php"/>
|
||||
<exclude-pattern>vendor</exclude-pattern>
|
||||
</ruleset>
|
|
@ -6,11 +6,14 @@
|
|||
* 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:
|
||||
*
|
||||
* 1. copy the source from https://www.mediawiki.org/wiki/Extension:Math/CoverageTest to a new page e.g.
|
||||
* 1. copy the source from https://www.mediawiki.org/wiki/Extension:Math/CoverageTest
|
||||
* to a new page e.g.
|
||||
* MathTest at your local vagrant instance
|
||||
* 2. run <code>php MathGenerateTests.php MathTest</code> in the maitenance folder of the Math extension.
|
||||
* 2. run <code>php MathGenerateTests.php MathTest</code>
|
||||
* in the maitenance folder of the Math extension.
|
||||
* 3. Test local e.g. via
|
||||
* <code>sudo php /vagrant/mediawiki/tests/phpunit/phpunit.php /vagrant/mediawiki/extensions/Math/tests/MathCoverageTest.php</code>
|
||||
* <code>sudo php /vagrant/mediawiki/tests/phpunit/phpunit.php
|
||||
* /vagrant/mediawiki/extensions/Math/tests/MathCoverageTest.php</code>
|
||||
* (If you don't use sudo you might have problems with the permissions set at vagrant.)
|
||||
*
|
||||
* @group Extensions
|
||||
|
@ -58,13 +61,13 @@ class MathCoverageTest extends MediaWikiTestCase {
|
|||
self::$texvcPath );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loops over all test cases provided by the provider function.
|
||||
* Compares each the rendering result of each input with the expected output.
|
||||
* @dataProvider provideCoverage
|
||||
*/
|
||||
public function testCoverage( $input, $output )
|
||||
{
|
||||
public function testCoverage( $input, $output ) {
|
||||
// TODO: Make rendering mode configurable
|
||||
// TODO: Provide test-ids
|
||||
// TODO: Link to the wikipage that contains the reference rendering
|
||||
|
@ -77,7 +80,8 @@ class MathCoverageTest extends MediaWikiTestCase {
|
|||
|
||||
/**
|
||||
* Gets the test-data from the file ParserTest.json
|
||||
* @return array($input, $output) where $input is the test input string and $output is the rendered html5-output string
|
||||
* @return array($input, $output) where $input is the test input string
|
||||
* and $output is the rendered html5-output string
|
||||
*/
|
||||
public function provideCoverage() {
|
||||
return json_decode( file_get_contents( __DIR__ . '/ParserTest.json' ) );
|
||||
|
|
|
@ -67,12 +67,17 @@ class MathDatabaseTest extends MediaWikiTestCase {
|
|||
$renderer2 = new MathTexvc( self::SOME_TEX );
|
||||
$this->assertTrue( $renderer2->readFromDatabase(), 'Reading from database failed' );
|
||||
// comparing the class object does now work due to null values etc.
|
||||
$this->assertEquals( $this->renderer->getTex(), $renderer2->getTex(), "test if tex is the same" );
|
||||
$this->assertEquals( $this->renderer->getMathml(), $renderer2->getMathml(), "Check MathML encoding" );
|
||||
$this->assertEquals( $this->renderer->getHtml(), $renderer2->getHtml(), 'test if HTML is the same' );
|
||||
$this->assertEquals(
|
||||
$this->renderer->getTex(), $renderer2->getTex(), "test if tex is the same"
|
||||
);
|
||||
$this->assertEquals(
|
||||
$this->renderer->getMathml(), $renderer2->getMathml(), "Check MathML encoding"
|
||||
);
|
||||
$this->assertEquals(
|
||||
$this->renderer->getHtml(), $renderer2->getHtml(), 'test if HTML is the same'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks the creation of the math table.
|
||||
* @covers MathHooks::onLoadExtensionSchemaUpdates
|
||||
|
@ -87,7 +92,7 @@ class MathDatabaseTest extends MediaWikiTestCase {
|
|||
$this->renderer->writeToDatabase();
|
||||
$res = $this->db->select( "math", "*" );
|
||||
$row = $res->fetchRow();
|
||||
$this->assertEquals( 10, sizeof( $row ) );
|
||||
$this->assertEquals( 10, count( $row ) );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -91,8 +91,10 @@ class MathInputCheckTexvcTest extends MediaWikiTestCase {
|
|||
$this->BadObject->isValid();
|
||||
$this->GoodObject->isValid();
|
||||
$this->assertNull( $this->GoodObject->getError() );
|
||||
$expectedMessage = wfMessage( 'math_unknown_function', '\newcommand' )->inContentLanguage()->escaped();
|
||||
$this->assertContains( $expectedMessage , $this->BadObject->getError() );
|
||||
$expectedMessage = wfMessage(
|
||||
'math_unknown_function', '\newcommand'
|
||||
)->inContentLanguage()->escaped();
|
||||
$this->assertContains( $expectedMessage, $this->BadObject->getError() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,7 +139,7 @@ class MathInputCheckTexvcTest extends MediaWikiTestCase {
|
|||
*/
|
||||
public function testConvertTexvcError() {
|
||||
$texvc = $this->getMockBuilder( 'MathInputCheckTexvc' )
|
||||
->setMethods( NULL )
|
||||
->setMethods( null )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
|
@ -145,23 +147,41 @@ class MathInputCheckTexvcTest extends MediaWikiTestCase {
|
|||
|
||||
$actualLexing = $texvc->convertTexvcError( 'E' );
|
||||
$expectedLexing = wfMessage( 'math_lexing_error', '' )->inContentLanguage()->escaped();
|
||||
$this->assertContains( $mathFailure, $actualLexing, 'Lexing error contains general math failure message' );
|
||||
$this->assertContains( $expectedLexing, $actualLexing, 'Lexing error contains detailed error for lexing' );
|
||||
$this->assertContains(
|
||||
$mathFailure, $actualLexing, 'Lexing error contains general math failure message'
|
||||
);
|
||||
$this->assertContains(
|
||||
$expectedLexing, $actualLexing, 'Lexing error contains detailed error for lexing'
|
||||
);
|
||||
|
||||
$actualSyntax = $texvc->convertTexvcError( 'S' );
|
||||
$expectedSyntax = wfMessage( 'math_syntax_error', '' )->inContentLanguage()->escaped();
|
||||
$this->assertContains( $mathFailure, $actualSyntax, 'Syntax error contains general math failure message' );
|
||||
$this->assertContains( $expectedSyntax, $actualSyntax, 'Syntax error contains detailed error for syntax' );
|
||||
$this->assertContains(
|
||||
$mathFailure, $actualSyntax, 'Syntax error contains general math failure message'
|
||||
);
|
||||
$this->assertContains(
|
||||
$expectedSyntax, $actualSyntax, 'Syntax error contains detailed error for syntax'
|
||||
);
|
||||
|
||||
$unknownFunction = 'figureEightIntegral';
|
||||
$actualUnknownFunction = $texvc->convertTexvcError( "F$unknownFunction" );
|
||||
$expectedUnknownFunction = wfMessage( 'math_unknown_function', $unknownFunction )->inContentLanguage()->escaped();
|
||||
$this->assertContains( $mathFailure, $actualUnknownFunction, 'Unknown function error contains general math failure message' );
|
||||
$this->assertContains( $expectedUnknownFunction, $actualUnknownFunction, 'Unknown function error contains detailed error for unknown function' );
|
||||
$expectedUnknownFunction = wfMessage(
|
||||
'math_unknown_function', $unknownFunction
|
||||
)->inContentLanguage()->escaped();
|
||||
$this->assertContains( $mathFailure, $actualUnknownFunction,
|
||||
'Unknown function error contains general math failure message'
|
||||
);
|
||||
$this->assertContains( $expectedUnknownFunction, $actualUnknownFunction,
|
||||
'Unknown function error contains detailed error for unknown function'
|
||||
);
|
||||
|
||||
$actualUnknownError = $texvc->convertTexvcError( 'Q' );
|
||||
$expectedUnknownError = wfMessage( 'math_unknown_error', '' )->inContentLanguage()->escaped();
|
||||
$this->assertContains( $mathFailure, $actualUnknownError, 'Unknown error contains general math failure message' );
|
||||
$this->assertContains( $expectedUnknownError, $actualUnknownError, 'Unknown error contains detailed error for unknownError' );
|
||||
$this->assertContains(
|
||||
$mathFailure, $actualUnknownError, 'Unknown error contains general math failure message'
|
||||
);
|
||||
$this->assertContains( $expectedUnknownError, $actualUnknownError,
|
||||
'Unknown error contains detailed error for unknownError'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,14 +19,13 @@ class MathLaTeXMLDatabaseTest extends MediaWikiTestCase {
|
|||
* @param $name
|
||||
* @return ReflectionMethod
|
||||
*/
|
||||
protected static function getMethod($name) {
|
||||
$class = new ReflectionClass('MathLaTeXML');
|
||||
$method = $class->getMethod($name);
|
||||
$method->setAccessible(true);
|
||||
protected static function getMethod( $name ) {
|
||||
$class = new ReflectionClass( 'MathLaTeXML' );
|
||||
$method = $class->getMethod( $name );
|
||||
$method->setAccessible( true );
|
||||
return $method;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* creates a new database connection and a new math renderer
|
||||
* TODO: Check if there is a way to get database access without creating
|
||||
|
@ -43,7 +42,8 @@ class MathLaTeXMLDatabaseTest extends MediaWikiTestCase {
|
|||
// Create a new instance of MathSource
|
||||
$this->renderer = new MathLaTeXML( self::SOME_TEX );
|
||||
self::setupTestDB( $this->db, "mathtest" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the tex and hash functions
|
||||
* @covers MathRenderer::getInputHash()
|
||||
|
@ -86,7 +86,7 @@ class MathLaTeXMLDatabaseTest extends MediaWikiTestCase {
|
|||
$this->renderer->writeToDatabase();
|
||||
$res = $this->db->select( "mathlatexml", "*" );
|
||||
$row = $res->fetchRow();
|
||||
$this->assertEquals( 12, sizeof( $row ) );
|
||||
$this->assertEquals( 12, count( $row ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,9 +102,11 @@ class MathLaTeXMLDatabaseTest extends MediaWikiTestCase {
|
|||
$renderer2 = $this->renderer = new MathLaTeXML( self::SOME_TEX );
|
||||
$renderer2->readFromDatabase();
|
||||
// comparing the class object does now work due to null values etc.
|
||||
$this->assertEquals( $this->renderer->getTex(), $renderer2->getTex(), "test if tex is the same" );
|
||||
$this->assertEquals( $this->renderer->getMathml(), $renderer2->getMathml(), "Check MathML encoding" );
|
||||
$this->assertEquals(
|
||||
$this->renderer->getTex(), $renderer2->getTex(), "test if tex is the same"
|
||||
);
|
||||
$this->assertEquals(
|
||||
$this->renderer->getMathml(), $renderer2->getMathml(), "Check MathML encoding"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ class MathLaTeXMLTest extends MediaWikiTestCase {
|
|||
*/
|
||||
public function testSerializeSettings() {
|
||||
$renderer = $this->getMockBuilder( 'MathLaTeXML' )
|
||||
->setMethods( NULL )
|
||||
->setMethods( null )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$sampleSettings = array(
|
||||
|
|
|
@ -35,18 +35,18 @@ class MathMathMLTest extends MediaWikiTestCase {
|
|||
$url = 'http://example.com/invalid';
|
||||
|
||||
$renderer = $this->getMockBuilder( 'MathMathML' )
|
||||
->setMethods( NULL )
|
||||
->setMethods( null )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$requestReturn = $renderer->makeRequest( $url, 'a+b', $res, $error
|
||||
, 'MathMLHttpRequestTester' );
|
||||
$this->assertEquals( false, $requestReturn
|
||||
, "requestReturn is false if HTTP::post returns false." );
|
||||
$this->assertEquals( false, $res
|
||||
, "res is false if HTTP:post returns false." );
|
||||
$requestReturn = $renderer->makeRequest( $url, 'a+b', $res, $error,
|
||||
'MathMLHttpRequestTester' );
|
||||
$this->assertEquals( false, $requestReturn,
|
||||
"requestReturn is false if HTTP::post returns false." );
|
||||
$this->assertEquals( false, $res,
|
||||
"res is false if HTTP:post returns false." );
|
||||
$errmsg = wfMessage( 'math_invalidresponse', '', $url, '' )->inContentLanguage()->escaped();
|
||||
$this->assertContains( $errmsg, $error
|
||||
, "return an error if HTTP::post returns false" );
|
||||
$this->assertContains( $errmsg, $error,
|
||||
"return an error if HTTP::post returns false" );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,11 +58,11 @@ class MathMathMLTest extends MediaWikiTestCase {
|
|||
self::setMockValues( true, true, false );
|
||||
$url = 'http://example.com/valid';
|
||||
$renderer = $this->getMockBuilder( 'MathMathML' )
|
||||
->setMethods( NULL )
|
||||
->setMethods( null )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$requestReturn = $renderer->makeRequest( $url, 'a+b', $res, $error
|
||||
, 'MathMLHttpRequestTester' );
|
||||
$requestReturn = $renderer->makeRequest( $url, 'a+b', $res, $error,
|
||||
'MathMLHttpRequestTester' );
|
||||
$this->assertEquals( true, $requestReturn, "successful call return" );
|
||||
$this->isTrue( $res, "successfull call" );
|
||||
$this->assertEquals( $error, '', "successfull call errormessage" );
|
||||
|
@ -77,31 +77,33 @@ class MathMathMLTest extends MediaWikiTestCase {
|
|||
self::setMockValues( false, true, true );
|
||||
$url = 'http://example.com/timeout';
|
||||
$renderer = $this->getMockBuilder( 'MathMathML' )
|
||||
->setMethods( NULL )
|
||||
->setMethods( null )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$requestReturn = $renderer->makeRequest( $url, '$\longcommand$', $res
|
||||
, $error, 'MathMLHttpRequestTester' );
|
||||
$requestReturn = $renderer->makeRequest(
|
||||
$url, '$\longcommand$', $res, $error, 'MathMLHttpRequestTester'
|
||||
);
|
||||
$this->assertEquals( false, $requestReturn, "timeout call return" );
|
||||
$this->assertEquals( false, $res, "timeout call return" );
|
||||
$errmsg = wfMessage( 'math_timeout', '', $url )->inContentLanguage()->escaped();
|
||||
$this->assertContains( $errmsg, $error, "timeout call errormessage" );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if a String is a valid MathML element
|
||||
* @covers MathMathML::isValidXML
|
||||
*/
|
||||
public function testisValidXML() {
|
||||
$renderer = $this->getMockBuilder( 'MathMathML' )
|
||||
->setMethods( NULL )
|
||||
->setMethods( null )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$validSample = '<math>content</math>';
|
||||
$invalidSample = '<notmath />';
|
||||
$this->assertTrue( $renderer->isValidMathML( $validSample ), 'test if math expression is valid mathml sample' );
|
||||
$this->assertFalse( $renderer->isValidMathML( $invalidSample ), 'test if math expression is invalid mathml sample' );
|
||||
$this->assertTrue( $renderer->isValidMathML( $validSample ),
|
||||
'test if math expression is valid mathml sample' );
|
||||
$this->assertFalse( $renderer->isValidMathML( $invalidSample ),
|
||||
'test if math expression is invalid mathml sample' );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ class MathTexvcTest extends MediaWikiTestCase {
|
|||
*/
|
||||
public function testConvertTexvcError() {
|
||||
$texvc = $this->getMockBuilder( 'MathTexvc' )
|
||||
->setMethods( NULL )
|
||||
->setMethods( null )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
|
@ -130,25 +130,44 @@ class MathTexvcTest extends MediaWikiTestCase {
|
|||
|
||||
$actualLexing = $texvc->convertTexvcError( 'E' );
|
||||
$expectedLexing = wfMessage( 'math_lexing_error', '' )->inContentLanguage()->escaped();
|
||||
$this->assertContains( $mathFailure, $actualLexing, 'Lexing error contains general math failure message' );
|
||||
$this->assertContains( $expectedLexing, $actualLexing, 'Lexing error contains detailed error for lexing' );
|
||||
$this->assertContains(
|
||||
$mathFailure, $actualLexing, 'Lexing error contains general math failure message'
|
||||
);
|
||||
$this->assertContains(
|
||||
$expectedLexing, $actualLexing, 'Lexing error contains detailed error for lexing'
|
||||
);
|
||||
|
||||
$actualSyntax = $texvc->convertTexvcError( 'S' );
|
||||
$expectedSyntax = wfMessage( 'math_syntax_error', '' )->inContentLanguage()->escaped();
|
||||
$this->assertContains( $mathFailure, $actualSyntax, 'Syntax error contains general math failure message' );
|
||||
$this->assertContains( $expectedSyntax, $actualSyntax, 'Syntax error contains detailed error for syntax' );
|
||||
$this->assertContains(
|
||||
$mathFailure, $actualSyntax, 'Syntax error contains general math failure message'
|
||||
);
|
||||
$this->assertContains(
|
||||
$expectedSyntax, $actualSyntax, 'Syntax error contains detailed error for syntax'
|
||||
);
|
||||
|
||||
$unknownFunction = 'figureEightIntegral';
|
||||
$actualUnknownFunction = $texvc->convertTexvcError( "F$unknownFunction" );
|
||||
$expectedUnknownFunction = wfMessage( 'math_unknown_function', $unknownFunction )->inContentLanguage()->escaped();
|
||||
$this->assertContains( $mathFailure, $actualUnknownFunction, 'Unknown function error contains general math failure message' );
|
||||
$this->assertContains( $expectedUnknownFunction, $actualUnknownFunction, 'Unknown function error contains detailed error for unknown function' );
|
||||
$expectedUnknownFunction = wfMessage(
|
||||
'math_unknown_function', $unknownFunction
|
||||
)->inContentLanguage()->escaped();
|
||||
$this->assertContains( $mathFailure, $actualUnknownFunction,
|
||||
'Unknown function error contains general math failure message'
|
||||
);
|
||||
$this->assertContains( $expectedUnknownFunction, $actualUnknownFunction,
|
||||
'Unknown function error contains detailed error for unknown function'
|
||||
);
|
||||
|
||||
$actualUnknownError = $texvc->convertTexvcError( 'Q' );
|
||||
$expectedUnknownError = wfMessage( 'math_unknown_error', '' )->inContentLanguage()->escaped();
|
||||
$this->assertContains( $mathFailure, $actualUnknownError, 'Unknown error contains general math failure message' );
|
||||
$this->assertContains( $expectedUnknownError, $actualUnknownError, 'Unknown error contains detailed error for unknownError' );
|
||||
$this->assertContains(
|
||||
$mathFailure, $actualUnknownError, 'Unknown error contains general math failure message'
|
||||
);
|
||||
$this->assertContains( $expectedUnknownError, $actualUnknownError,
|
||||
'Unknown error contains detailed error for unknownError'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test behavior $change when the rendered hash was changed
|
||||
* @covers MathRenderer::setHash()
|
||||
|
|
|
@ -81,12 +81,13 @@ class MathUtilsTest extends MediaWikiTestCase {
|
|||
|
||||
public function testMathModeToHash() {
|
||||
$default = 0;
|
||||
$testCases = array (
|
||||
$testCases = array(
|
||||
'png' => 0,
|
||||
'source' => 3,
|
||||
'mathml' => 5,
|
||||
'latexml'=> 7,
|
||||
'invalid'=> $default);
|
||||
'invalid'=> $default
|
||||
);
|
||||
|
||||
foreach ( $testCases as $input => $expected ){
|
||||
$real = MathHooks::mathModeToHashKey( $input, $default );
|
||||
|
@ -99,4 +100,4 @@ class MathUtilsTest extends MediaWikiTestCase {
|
|||
$this->assertEquals( 'PNG images', $real['png'] );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue