2014-06-10 16:49:20 +00:00
< ? php
2014-06-03 08:15:53 +00:00
/**
* Test the MathML output format .
*
* @ group Math
*/
class MathMathMLTest extends MediaWikiTestCase {
// State-variables for HTTP Mockup classes
public static $content = null ;
public static $good = false ;
public static $html = false ;
public static $timeout = false ;
/**
* Set the mock values for the HTTP Mockup classes
*
* @ param boolean $good
* @ param mixed $html HTML of the error message or false if no error is present .
* @ param boolean $timeout true if
*/
public static function setMockValues ( $good , $html , $timeout ) {
self :: $good = $good ;
self :: $html = $html ;
self :: $timeout = $timeout ;
}
/**
* Tests behavior of makeRequest () that communicates with the host .
* Testcase : Invalid request .
* @ covers MathTexvc :: makeRequest
*/
public function testMakeRequestInvalid () {
self :: setMockValues ( false , false , false );
$url = 'http://example.com/invalid' ;
$renderer = $this -> getMockBuilder ( 'MathMathML' )
-> 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. " );
$errmsg = wfMessage ( 'math_invalidresponse' , '' , $url , '' ) -> inContentLanguage () -> escaped ();
$this -> assertContains ( $errmsg , $error
, " return an error if HTTP::post returns false " );
}
/**
* Tests behavior of makeRequest () that communicates with the host .
* Testcase : Valid request .
* @ covers MathTexvc :: makeRequest
*/
public function testMakeRequestSuccess () {
self :: setMockValues ( true , true , false );
$url = 'http://example.com/valid' ;
$renderer = $this -> getMockBuilder ( 'MathMathML' )
-> setMethods ( NULL )
-> disableOriginalConstructor ()
-> getMock ();
$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 " );
}
/**
* Tests behavior of makeRequest () that communicates with the host .
* Testcase : Timeout .
* @ covers MathMathML :: makeRequest
*/
public function testMakeRequestTimeout () {
self :: setMockValues ( false , true , true );
$url = 'http://example.com/timeout' ;
$renderer = $this -> getMockBuilder ( 'MathMathML' )
-> setMethods ( NULL )
-> disableOriginalConstructor ()
-> getMock ();
$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 )
-> 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' );
}
2015-02-25 19:32:56 +00:00
/**
* Checks the basic functionality
* i . e . if the span element is generated right .
*/
public function testIntegration () {
global $wgMathMathMLTimeout ;
$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 " >
< defs >
< path stroke - width = " 10 " id = " E1-MJMATHI-61 " d = " M33 157Q33 258 109 349T280 441Q331 441 370 392Q386 422 416 422Q429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487Q506 153 506 144Q506 138 501 117T481 63T449 13Q436 0 417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157ZM351 328Q351 334 346 350T323 385T277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z " ></ path >
< path stroke - width = " 10 " id = " E1-MJMAIN-2B " d = " M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z " ></ path >
< path stroke - width = " 10 " id = " E1-MJMATHI-62 " d = " M73 647Q73 657 77 670T89 683Q90 683 161 688T234 694Q246 694 246 685T212 542Q204 508 195 472T180 418L176 399Q176 396 182 402Q231 442 283 442Q345 442 383 396T422 280Q422 169 343 79T173 -11Q123 -11 82 27T40 150V159Q40 180 48 217T97 414Q147 611 147 623T109 637Q104 637 101 637H96Q86 637 83 637T76 640T73 647ZM336 325V331Q336 405 275 405Q258 405 240 397T207 376T181 352T163 330L157 322L136 236Q114 150 114 114Q114 66 138 42Q154 26 178 26Q211 26 245 58Q270 81 285 114T318 219Q336 291 336 325Z " ></ path >
</ defs >
< g stroke = " black " fill = " black " stroke - width = " 0 " transform = " matrix(1 0 0 -1 0 0) " >
< use xlink : href = " #E1-MJMATHI-61 " ></ use >
< use xlink : href = " #E1-MJMAIN-2B " x = " 756 " y = " 0 " ></ use >
< use xlink : href = " #E1-MJMATHI-62 " x = " 1761 " y = " 0 " ></ use >
</ g >
</ svg > ' ;
$wgMathMathMLTimeout = 20 ;
$renderer = MathRenderer :: getRenderer ( " a+b " , array (), MW_MATH_MATHML );
$this -> assertTrue ( $renderer -> render ( true ) );
$real = str_replace ( " \n " , '' , $renderer -> getHtmlOutput () );
$expected = '<mo>+</mo>' ;
$this -> assertContains ( $expected , $real , " Rendering of a+b in plain MathML mode " );
$this -> assertEquals ( $svgRef , $renderer -> getSvg () );
}
/**
* 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
$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' );
$renderer = new MathMathML ( $inputSample , $attribs );
$this -> assertEquals ( 'pmml' , $renderer -> getInputType (), 'Input type was not set correctly' );
$this -> assertTrue ( $renderer -> render (), 'Failed to render with error:' . $renderer -> getLastError () );
$real = MathRenderer :: renderMath ( $inputSample , $attribs , MW_MATH_MATHML );
$expected = 'hash=5628b8248b79267ecac656102334d5e3&mode=5' ;
$this -> assertContains ( $expected , $real , 'Link to SVG image missing' );
}
2014-06-03 08:15:53 +00:00
}
/**
* Helper class for testing
* @ author physikerwelt
* @ see MWHttpRequestTester
*
*/
class MathMLHttpRequestTester {
public static function factory () {
return new MathMLHttpRequestTester ();
}
public static function execute () {
return new MathMLTestStatus ();
}
public static function getContent () {
return MathMathMLTest :: $content ;
}
}
/**
* Helper class for testing
* @ author physikerwelt
* @ see Status
*/
class MathMLTestStatus {
static function isGood () {
return MathMathMLTest :: $good ;
}
static function hasMessage ( $s ) {
if ( $s == 'http-timed-out' ) {
return MathMathMLTest :: $timeout ;
} else {
return false ;
}
}
static function getHtml () {
return MathMathMLTest :: $html ;
}
static function getWikiText () {
return MathMathMLTest :: $html ;
}
Merge changes from master to debug
combine commits to avoid potential problems
with gerrit and jenkins
This is a combination of 30 commits.
ve.ce.MWMathNode: Remove reference to defunct ve.bind
Bug: 73627
Change-Id: I3dd6b520a24e5cecb272de8f9a4aa0ba231bee58
Localisation updates from https://translatewiki.net.
Change-Id: I6074394864ee7c61b416ae146c94c75d48f509af
Localisation updates from https://translatewiki.net.
Change-Id: I2fa13da30e606e1dfb1e13ae64fb125bf4bfadf6
Fix Mathoid integration test
A recent change in mathoid, i.e.
I8d3cec0ee8a8c9368b7dca89e1d5e0c5683f946c
removed the margins. This causes breaking unit tests.
Change-Id: I312d6226c6f24c84254b99ee6292564a421133c3
Localisation updates from https://translatewiki.net.
Change-Id: I053b90b6a583c411270c950ab6bc0d4e94db583f
Localisation updates from https://translatewiki.net.
Change-Id: Icc6d5d961ad97e19de3c4fbdb86e5aa9315998bb
Localisation updates from https://translatewiki.net.
Change-Id: I7b8faf72ba814154896cf5039e14d23f07509440
Localisation updates from https://translatewiki.net.
Change-Id: I83ca4e6eb8eef02e98ddc6f556d113942fa436df
Localisation updates from https://translatewiki.net.
Change-Id: Icb25e8b51409754130ce22c47474f644c087124e
Localisation updates from https://translatewiki.net.
Change-Id: I6dae3f8fc6723265bf47b721148d261b11828f33
Fix for fatal caused by static call to MathRenderer::getError
MathRenderer::getError() uses $this, so it should not be called statically.
MathInputCheckTexvc should instead call its convertTexvcError method, which
constructs a MathRenderer object so it can call its getError method.
This code is pretty awful. But this way it won't throw fatal errors all the time.
Change-Id: Ic438b307a3b464651363b4cc16698c7d4320b253
Add support for display and ID attributes to VisualEditor
Change-Id: Ie65ff26c9e214f74b0217238a3def2242505d4c2
Localisation updates from https://translatewiki.net.
Change-Id: I5f978989a57affa823632061300f5de7028b2ec0
Localisation updates from https://translatewiki.net.
Change-Id: I366383149cb56c90800e06f94aaa6c8895d2381c
Localisation updates from https://translatewiki.net.
Change-Id: I204cb407cfb417961da361b4eaa84af432e2bd29
Localisation updates from https://translatewiki.net.
Change-Id: Ib3f357a76752ce2cba8642a02ec4f5373ddabe52
Localisation updates from https://translatewiki.net.
Change-Id: Iec289070ab64e2014b4c7f371926c03466258e3c
Localisation updates from https://translatewiki.net.
Change-Id: Id297a13ca02524d9db16990b6cdd282b0b52fd73
Localisation updates from https://translatewiki.net.
Change-Id: I1b86d72690b5907ef438d69cf067da6dcc1891b2
Localisation updates from https://translatewiki.net.
Change-Id: Ib4eb016b1602d94a73c5e355f0ae4a744083b0c3
Localisation updates from https://translatewiki.net.
Change-Id: I6b0398be5ec8ba5bfc71c987f80973bf2bb8afe3
Localisation updates from https://translatewiki.net.
Change-Id: Ie485a03f09f1534071d18abf64bbfa446cdee754
Localisation updates from https://translatewiki.net.
Change-Id: I2445b8fbf1b35f437d6dba99d9fe081833ab5089
Localisation updates from https://translatewiki.net.
Change-Id: If1f94c16fd20feef3403e326d58526eeb17c6a86
Localisation updates from https://translatewiki.net.
Change-Id: I74dcb97bbb16bfc6e0700ed90fcf9705f7bdecf8
Localisation updates from https://translatewiki.net.
Change-Id: I0ac3c68f796cde959629d63079d212473ad5a729
Localisation updates from https://translatewiki.net.
Change-Id: I35f1687b4f4e7030a91bdc8aba3c04bbf71f55a4
Localisation updates from https://translatewiki.net.
Change-Id: I64dfcdedea5ed345f730fe7080c8b511fe21dc49
Localisation updates from https://translatewiki.net.
Change-Id: Ib5c89c89ba2091f7784cc1c1237150ec55741fd7
MWException -> Exception
Change-Id: I18da1baeb70387b96e30811a049185a264dec26d
Update MathParser tests
In the most recent version of ubuntu14 the outputhash of the
png images for some math objects has changed.
However, the rendered images seem to look ok.
Bug: T86309
Change-Id: I52dbdefdcfa19c10f1d9d1a43369aabe8bfd92bf
Correct wrong variable name
Change-Id: Iecfa0bfa5861e077d98f7bf06af0e98cda56220b
Remove unused global
Change-Id: I8f5f77015de266f5a5b751fd7cfe424784eb3864
Update LaTeXML test
* The LaTeXML server was updated. In the new version unneccary id's
have been removed.
Change-Id: I25927912f1500ebfe6d61505c0e06ae2c24d6f6a
Update license headers
Change-Id: Ia38926b253e53a2cef5dfab623353e1dd79ad613
Make main code input area monospaced
A monospaced font is more suitable for writing LaTeX.
Change-Id: I1a6c7bbbe3618f43808be15eab1579de8b2ad59f
Whitespace fixes
Change-Id: Id22a4bfdc1b8c4074f6d7e6f21e8dbc2824d856e
Localisation updates from https://translatewiki.net.
Change-Id: I01c4bbe241c0842027b030ee912b8e481c90f625
Localisation updates from https://translatewiki.net.
Change-Id: Ie012febb53ee642520e71f18285d5b9e4133e224
Improve Math test generation
* Use the wikitext parser and not regexp to extract math
tags from the page.
* Extract the attributes from the math tags as well
In a follow up a pseudo attribute in the math tag could
be introduced to provide a bug description.
Change-Id: I0dec18d4e3f87e7b58b097b2a08c4897ceaf29ac
Remove unused XML namespace
Bug: T87142
Change-Id: I1c900584aeafbeb5848a3300904710ee312d6223
Add type hinting for newFromMd5 constructor
Bug: T87142
Change-Id: I2989ff42e48e802c1eed1877f0f2ac9316b5fd21
Remove duplicate entry from .gitignore
Change-Id: I78c7e9b630c6e96a2f125f20461ff9e720754ec4
MathRenderer, SpecialMathShowImage: Correct phpdoc
Change-Id: Ibce076dfb6bd3676e288cf2d762ebcb55606246d
MathMathML, MathTexvc: Improve PhpDoc
Change-Id: I84af65e15bdae81f69f0444afdd9ffa5fe9fc326
Minor clean up, optimisations and documentation corrections
* Handle-error-first approach for consistent function body
termination at the root with the main intend, and less indention.
* __DIR__ instead of dirname( __FILE__ )
* Single quotes.
* Correct pickHost documentation: wgMathMathMLUrl is not an array,
and is not used in this method, that's at a different level
of abstraction (via the constructor).
* White spacing.
* require_once is not a function.
Change-Id: Id4bec8415893245e2569a39ab5406a0820238ae4
Add dependency on mediawiki.toolbar
Follows-up Ibcda91bbb164b0.
ext.math.editbutton.enabler uses mw.toolbar. The toolbar interface
used to be part of mediawiki.action.edit but is now in its own module.
Bug: T86235
Change-Id: I37a0b8e84a9bd6a0de0386d5b9924bbbbbd7249c
Localisation updates from https://translatewiki.net.
Change-Id: I14cfdb2153121a9cbcd40345398dc84d3b17518f
Fix rendering issues in MathML mode
Force display:none on a hidden MathML rendering to avoid generating
focusable node highlights.
Move adding of class to setup to ensure it persists after render.
Bug: T87007
Change-Id: I5fc21afa61ccc07e9d2126846cf29ee898182a7c
Localisation updates from https://translatewiki.net.
Change-Id: I2cfa5bae2a6864548816934483cd2276e1071865
Localisation updates from https://translatewiki.net.
Change-Id: I7eb73bd36e5cd4461647bf05166fd2fd2fcbee07
Localisation updates from https://translatewiki.net.
Change-Id: I174400c5a3dad8f6bf8d03b7c738d5068682ceb3
2014-11-20 02:51:40 +00:00
}