Math/tests/MathRendererTest.php
physikerwelt c390f6479a Add getHtmlOutput method
Currently the method render always returns
a html string that can be a string that
represents the correct result or a rendered
error message.
This change adds a mechanism that allows
to fetch the HTML output.
In a followup commit the rendering function
is changed to return a boolean value rather
than the rendering result.
This will simplify the error handling and caching.

Change-Id: I80760493e391911c41eb69d75a93c6a34db8852e
2014-06-06 21:52:35 +02:00

61 lines
1.8 KiB
PHP

<?php
/**
* Test the database access and core functionality of MathRenderer.
*
* @group Math
*/
class MathRendererTest extends MediaWikiTestCase {
const SOME_TEX = "a+b";
/**
* Checks the tex and hash functions
* @covers MathRenderer::getTex()
* @covers MathRenderer::__construct()
*/
public function testBasics() {
$renderer = $this->getMockForAbstractClass( 'MathRenderer'
, array ( self::SOME_TEX ) );
// check if the TeX input was corretly passed to the class
$this->assertEquals( self::SOME_TEX, $renderer->getTex()
, "test getTex" );
$this->assertEquals( $renderer->isChanged(), false
, "test if changed is initially false" );
}
/**
* Test behavior of writeCache() when nothing was changed
* @covers MathRenderer::writeCache()
*/
public function testWriteCacheSkip() {
$renderer = $this->getMockBuilder( 'MathRenderer' )
->setMethods( array( 'writeToDatabase' , 'render', 'getMathTableName', 'getHtmlOutput' ) )
->disableOriginalConstructor()
->getMock();
$renderer->expects( $this->never() )
->method( 'writeToDatabase' );
$renderer->writeCache();
}
/**
* Test behavior of writeCache() when values were changed.
* @covers MathRenderer::writeCache()
*/
public function testWriteCache() {
$renderer = $this->getMockBuilder( 'MathRenderer' )
->setMethods( array( 'writeToDatabase' , 'render', 'getMathTableName', 'getHtmlOutput' ) )
->disableOriginalConstructor()
->getMock();
$renderer->expects( $this->never() )
->method( 'writeToDatabase' );
$renderer->writeCache();
}
public function testSetPurge() {
$renderer = $this->getMockBuilder( 'MathRenderer' )
->setMethods( array( 'render', 'getMathTableName', 'getHtmlOutput' ) )
->disableOriginalConstructor()
->getMock();
$renderer->setPurge();
$this->assertEquals( $renderer->isPurge(), true, "Test purge." );
}
}