getMockBuilder( 'MathLaTeXML' ) ->setMethods( NULL ) ->disableOriginalConstructor() ->getMock(); $requestReturn = $renderer->makeRequest( $url, 'a+b', $res, $error , 'LaTeXMLHttpRequestTester' ); $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_latexml_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( 'MathLaTeXML' ) ->setMethods( NULL ) ->disableOriginalConstructor() ->getMock(); $requestReturn = $renderer->makeRequest( $url, 'a+b', $res, $error , 'LaTeXMLHttpRequestTester' ); $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 MathTexvc::makeRequest */ public function testMakeRequestTimeout() { self::setMockValues( false, true, true ); $url = 'http://example.com/timeout'; $renderer = $this->getMockBuilder( 'MathLaTeXML' ) ->setMethods( NULL ) ->disableOriginalConstructor() ->getMock(); $requestReturn = $renderer->makeRequest( $url, '$\longcommand$', $res , $error, 'LaTeXMLHttpRequestTester' ); $this->assertEquals( false, $requestReturn, "timeout call return" ); $this->assertEquals( false, $res, "timeout call return" ); $errmsg = wfMessage( 'math_latexml_timeout', $url ) ->inContentLanguage()->escaped(); $this->assertContains( $errmsg, $error, "timeout call errormessage" ); } /** * Checks the basic functionallity * i.e. if the span element is generated right. */ public function testIntegration() { global $wgLaTeXMLTimeout; $wgLaTeXMLTimeout = 20; $renderer = MathRenderer::getRenderer( "a+b", array(), MW_MATH_LATEXML ); $real = $renderer->render( true ); $expected = ' a + b a b a+b '; $this->assertEquals( $expected, $real , "Rendering of a+b in plain Text mode" ); } } /** * Helper class for testing * @author physikerwelt * @see MWHttpRequestTester * */ class LaTeXMLHttpRequestTester { public static function factory() { return new LaTeXMLHttpRequestTester(); } public static function execute() { return new LaTeXMLTestStatus(); } public static function getContent() { return MathLaTeXMLTest::$content; } } /** * Helper class for testing * @author physikerwelt * @see Status */ class LaTeXMLTestStatus { static function isGood() { return MathLaTeXMLTest::$good; } static function hasMessage( $s ) { if ( $s == 'http-timed-out' ) { return MathLaTeXMLTest::$timeout; } else { return false; } } static function getHtml() { return MathLaTeXMLTest::$html; } }