2013-04-07 00:01:56 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2014-05-28 19:31:41 +00:00
|
|
|
* Test the database access and core functionality of MathRenderer.
|
2013-04-07 00:01:56 +00:00
|
|
|
*
|
|
|
|
* @group Math
|
|
|
|
*/
|
|
|
|
class MathRendererTest extends MediaWikiTestCase {
|
2014-05-28 19:31:41 +00:00
|
|
|
const SOME_TEX = "a+b";
|
2014-09-06 01:59:13 +00:00
|
|
|
const TEXVCCHECK_INPUT = '\forall \epsilon \exist \delta';
|
|
|
|
const TEXVCCHECK_OUTPUT = '\forall \epsilon \exists \delta '; // be aware of the s at exists
|
2013-04-07 00:01:56 +00:00
|
|
|
/**
|
|
|
|
* Checks the tex and hash functions
|
|
|
|
* @covers MathRenderer::getTex()
|
|
|
|
* @covers MathRenderer::__construct()
|
|
|
|
*/
|
|
|
|
public function testBasics() {
|
2014-09-06 01:59:13 +00:00
|
|
|
$renderer = $this->getMockForAbstractClass( 'MathRenderer', array( self::SOME_TEX ) );
|
2013-04-07 00:01:56 +00:00
|
|
|
// check if the TeX input was corretly passed to the class
|
2014-09-06 01:59:13 +00:00
|
|
|
$this->assertEquals( self::SOME_TEX, $renderer->getTex(), "test getTex" );
|
|
|
|
$this->assertEquals( $renderer->isChanged(), false, "test if changed is initially false" );
|
2013-04-07 00:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-04-25 17:07:25 +00:00
|
|
|
* Test behavior of writeCache() when nothing was changed
|
2013-04-07 00:01:56 +00:00
|
|
|
* @covers MathRenderer::writeCache()
|
|
|
|
*/
|
|
|
|
public function testWriteCacheSkip() {
|
2014-09-06 01:59:13 +00:00
|
|
|
$renderer =
|
|
|
|
$this->getMockBuilder( 'MathRenderer' )->setMethods( array(
|
|
|
|
'writeToDatabase',
|
|
|
|
'render',
|
|
|
|
'getMathTableName',
|
|
|
|
'getHtmlOutput'
|
|
|
|
) )->disableOriginalConstructor()->getMock();
|
|
|
|
$renderer->expects( $this->never() )->method( 'writeToDatabase' );
|
2013-04-07 00:01:56 +00:00
|
|
|
$renderer->writeCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test behavior of writeCache() when values were changed.
|
|
|
|
* @covers MathRenderer::writeCache()
|
|
|
|
*/
|
|
|
|
public function testWriteCache() {
|
2014-09-06 01:59:13 +00:00
|
|
|
$renderer =
|
|
|
|
$this->getMockBuilder( 'MathRenderer' )->setMethods( array(
|
|
|
|
'writeToDatabase',
|
|
|
|
'render',
|
|
|
|
'getMathTableName',
|
|
|
|
'getHtmlOutput'
|
|
|
|
) )->disableOriginalConstructor()->getMock();
|
|
|
|
$renderer->expects( $this->never() )->method( 'writeToDatabase' );
|
2013-04-07 00:01:56 +00:00
|
|
|
$renderer->writeCache();
|
|
|
|
}
|
2013-04-25 17:07:25 +00:00
|
|
|
|
2014-02-09 19:02:15 +00:00
|
|
|
public function testSetPurge() {
|
2014-09-06 01:59:13 +00:00
|
|
|
$renderer =
|
|
|
|
$this->getMockBuilder( 'MathRenderer' )->setMethods( array(
|
|
|
|
'render',
|
|
|
|
'getMathTableName',
|
|
|
|
'getHtmlOutput'
|
|
|
|
) )->disableOriginalConstructor()->getMock();
|
2013-05-14 21:49:06 +00:00
|
|
|
$renderer->setPurge();
|
|
|
|
$this->assertEquals( $renderer->isPurge(), true, "Test purge." );
|
|
|
|
|
|
|
|
}
|
2014-09-06 01:59:13 +00:00
|
|
|
|
|
|
|
public function testCheckingAlways() {
|
2015-07-22 22:10:46 +00:00
|
|
|
$this->setMwGlobals( "wgMathDisableTexFilter", 'always' );
|
2014-09-06 01:59:13 +00:00
|
|
|
$renderer =
|
|
|
|
$this->getMockBuilder( 'MathRenderer' )->setMethods( array(
|
|
|
|
'render',
|
|
|
|
'getMathTableName',
|
|
|
|
'getHtmlOutput',
|
|
|
|
'readFromDatabase',
|
|
|
|
'setTex'
|
|
|
|
) )->setConstructorArgs( array( self::TEXVCCHECK_INPUT ) )->getMock();
|
|
|
|
$renderer->expects( $this->never() )->method( 'readFromDatabase' );
|
|
|
|
$renderer->expects( $this->once() )->method( 'setTex' )->with( self::TEXVCCHECK_OUTPUT );
|
|
|
|
|
|
|
|
$this->assertEquals( $renderer->checkTex(), true );
|
|
|
|
// now setTex sould not be called again
|
|
|
|
$this->assertEquals( $renderer->checkTex(), true );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCheckingNever() {
|
2015-07-22 22:10:46 +00:00
|
|
|
$this->setMwGlobals( "wgMathDisableTexFilter", 'never' );
|
2014-09-06 01:59:13 +00:00
|
|
|
$renderer =
|
|
|
|
$this->getMockBuilder( 'MathRenderer' )->setMethods( array(
|
|
|
|
'render',
|
|
|
|
'getMathTableName',
|
|
|
|
'getHtmlOutput',
|
|
|
|
'readFromDatabase',
|
|
|
|
'setTex'
|
|
|
|
) )->setConstructorArgs( array( self::TEXVCCHECK_INPUT ) )->getMock();
|
|
|
|
$renderer->expects( $this->never() )->method( 'readFromDatabase' );
|
|
|
|
$renderer->expects( $this->never() )->method( 'setTex' );
|
|
|
|
|
|
|
|
$this->assertEquals( $renderer->checkTex(), true );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCheckingNewUnknown() {
|
2015-07-22 22:10:46 +00:00
|
|
|
$this->setMwGlobals( "wgMathDisableTexFilter", 'new' );
|
2014-09-06 01:59:13 +00:00
|
|
|
$renderer =
|
|
|
|
$this->getMockBuilder( 'MathRenderer' )->setMethods( array(
|
|
|
|
'render',
|
|
|
|
'getMathTableName',
|
|
|
|
'getHtmlOutput',
|
|
|
|
'readFromDatabase',
|
|
|
|
'setTex'
|
|
|
|
) )->setConstructorArgs( array( self::TEXVCCHECK_INPUT ) )->getMock();
|
|
|
|
$renderer->expects( $this->once() )->method( 'readFromDatabase' )
|
|
|
|
->will( $this->returnValue( false ) );
|
|
|
|
$renderer->expects( $this->once() )->method( 'setTex' )->with( self::TEXVCCHECK_OUTPUT );
|
|
|
|
|
|
|
|
$this->assertEquals( $renderer->checkTex(), true );
|
|
|
|
// now setTex sould not be called again
|
|
|
|
$this->assertEquals( $renderer->checkTex(), true );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCheckingNewKnown() {
|
2015-07-22 22:10:46 +00:00
|
|
|
$this->setMwGlobals( "wgMathDisableTexFilter", 'new' );
|
2014-09-06 01:59:13 +00:00
|
|
|
$renderer =
|
|
|
|
$this->getMockBuilder( 'MathRenderer' )->setMethods( array(
|
|
|
|
'render',
|
|
|
|
'getMathTableName',
|
|
|
|
'getHtmlOutput',
|
|
|
|
'readFromDatabase',
|
|
|
|
'setTex'
|
|
|
|
) )->setConstructorArgs( array( self::TEXVCCHECK_INPUT ) )->getMock();
|
|
|
|
$renderer->expects( $this->exactly( 2 ) )->method( 'readFromDatabase' )
|
|
|
|
->will( $this->returnValue( true ) );
|
|
|
|
$renderer->expects( $this->never() )->method( 'setTex' );
|
|
|
|
|
|
|
|
$this->assertEquals( $renderer->checkTex(), true );
|
|
|
|
// we don't mark a object as checked even though we rely on the database cache
|
|
|
|
// so readFromDatabase will be called again
|
|
|
|
$this->assertEquals( $renderer->checkTex(), true );
|
|
|
|
}
|
2015-01-10 01:55:54 +00:00
|
|
|
}
|