'; $this->assertTrue( $renderer->render() ); $this->assertContains( $expected, $renderer->getHtmlOutput(), 'Rendering the String "\text{CR}"' ); } /** * 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 = 'content'; $invalidSample = ''; $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' ); } /** * Checks the basic functionality * i.e. if the span element is generated right. */ public function testIntegration() { global $wgMathMathMLTimeout; $svgRef = ' '; $wgMathMathMLTimeout = 20; $renderer = MathRenderer::getRenderer( "a+b", array(), MW_MATH_MATHML ); $this->assertTrue( $renderer->render( true ) ); $real = str_replace( "\n", '', $renderer->getHtmlOutput() ); $expected = '+'; $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 = ' P i j = 100 d i j 6.75 r j , '; $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' ); } } /** * 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; } }