2013-04-07 00:01:56 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Test the database access and core functionallity of MathRenderer.
|
|
|
|
*
|
|
|
|
* @group Math
|
|
|
|
*/
|
|
|
|
class MathRendererTest extends MediaWikiTestCase {
|
|
|
|
/**
|
|
|
|
* Checks the tex and hash functions
|
|
|
|
* @covers MathRenderer::getTex()
|
|
|
|
* @covers MathRenderer::__construct()
|
|
|
|
*/
|
|
|
|
public function testBasics() {
|
2013-04-25 17:07:25 +00:00
|
|
|
$renderer = $this->getMockForAbstractClass( 'MathRenderer'
|
|
|
|
, array ( MathDatabaseTest::SOME_TEX ) );
|
2013-04-07 00:01:56 +00:00
|
|
|
// check if the TeX input was corretly passed to the class
|
2013-04-25 17:07:25 +00:00
|
|
|
$this->assertEquals( MathDatabaseTest::SOME_TEX, $renderer->getTex()
|
|
|
|
, "test getTex" );
|
|
|
|
$this->assertEquals( $renderer->isChanged(), false
|
2014-02-09 19:02:15 +00:00
|
|
|
, "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() {
|
|
|
|
$renderer = $this->getMockBuilder( 'MathRenderer' )
|
2014-05-27 04:46:53 +00:00
|
|
|
->setMethods( array( 'writeToDatabase' , 'render', 'getMathTableName' ) )
|
2013-04-07 00:01:56 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$renderer->expects( $this->never() )
|
2013-04-24 06:01:53 +00:00
|
|
|
->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() {
|
|
|
|
$renderer = $this->getMockBuilder( 'MathRenderer' )
|
2014-05-27 04:46:53 +00:00
|
|
|
->setMethods( array( 'writeToDatabase' , 'render', 'getMathTableName' ) )
|
2013-04-07 00:01:56 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$renderer->expects( $this->never() )
|
2013-04-24 06:01:53 +00:00
|
|
|
->method( 'writeToDatabase' );
|
2013-04-07 00:01:56 +00:00
|
|
|
$renderer->writeCache();
|
|
|
|
}
|
2013-04-25 17:07:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test behavior $change when the rendered hash was changed
|
|
|
|
* @covers MathRenderer::setHash()
|
|
|
|
*/
|
|
|
|
public function testChangeHash() {
|
|
|
|
$renderer = $this->getMockBuilder( 'MathRenderer' )
|
2014-05-27 04:46:53 +00:00
|
|
|
->setMethods( array( 'render', 'getMathTableName' ) )
|
2013-04-25 17:07:25 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2014-03-11 15:53:03 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
$renderer->isChanged(),
|
|
|
|
false,
|
|
|
|
"test if changed is initially false"
|
|
|
|
);
|
2014-02-09 19:02:15 +00:00
|
|
|
$renderer->setHash( '0000' );
|
2014-03-11 15:53:03 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
$renderer->isChanged(),
|
|
|
|
true,
|
|
|
|
"assumes that changing a hash sets changed to true" );
|
2013-04-25 17:07:25 +00:00
|
|
|
}
|
2013-05-14 21:49:06 +00:00
|
|
|
|
2014-02-09 19:02:15 +00:00
|
|
|
public function testSetPurge() {
|
2013-05-14 21:49:06 +00:00
|
|
|
$renderer = $this->getMockBuilder( 'MathRenderer' )
|
2014-05-27 04:46:53 +00:00
|
|
|
->setMethods( array( 'render', 'getMathTableName' ) )
|
2013-05-14 21:49:06 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$renderer->setPurge();
|
|
|
|
$this->assertEquals( $renderer->isPurge(), true, "Test purge." );
|
|
|
|
|
|
|
|
}
|
2013-04-07 00:01:56 +00:00
|
|
|
}
|