mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-23 23:25:02 +00:00
Always call original constructors in tests, and more cleanups
* Get rid of a few more MockBuilders and mocks that aren't needed. * Make sure the original constructor is always called. This is highly relevant for I263a711. * Fix mixed order in assertions. In PHP, the expected value comes first. * Add some missing inline @var type hints. Change-Id: Ia15d62af56dfdb61bc2514aa994ce3d4ecd6e077
This commit is contained in:
parent
a10719db44
commit
852eba3c9e
|
@ -3,6 +3,8 @@
|
|||
use Wikibase\DataModel\Entity\PropertyId;
|
||||
use Wikibase\DataModel\Services\Entity\PropertyDataTypeMatcher;
|
||||
use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup;
|
||||
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
|
||||
use Wikibase\DataModel\Statement\Statement;
|
||||
|
||||
/**
|
||||
* Test the MathDataUpdater for Wikidata
|
||||
|
@ -34,13 +36,7 @@ class MathDataUpdaterTest extends MediaWikiTestCase {
|
|||
public function testNoMath() {
|
||||
$matcher = new PropertyDataTypeMatcher( new DummyPropertyDataTypeLookup() );
|
||||
$updater = new MathDataUpdater( $matcher );
|
||||
$statement =
|
||||
$this->getMockBuilder( Wikibase\DataModel\Statement\Statement::class )
|
||||
->setMethods( [ 'getPropertyId' ] )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$statement->method( 'getPropertyId' )->willReturn( $this->otherProperty );
|
||||
/** @var Wikibase\DataModel\Statement\Statement $statement */
|
||||
$statement = new Statement( new PropertyNoValueSnak( $this->otherProperty ) );
|
||||
$updater->processStatement( $statement );
|
||||
$parserOutput = $this->getMockBuilder( ParserOutput::class )->setMethods( [
|
||||
'addModules',
|
||||
|
@ -55,13 +51,7 @@ class MathDataUpdaterTest extends MediaWikiTestCase {
|
|||
public function testMath() {
|
||||
$matcher = new PropertyDataTypeMatcher( new DummyPropertyDataTypeLookup() );
|
||||
$updater = new MathDataUpdater( $matcher );
|
||||
$statement =
|
||||
$this->getMockBuilder( Wikibase\DataModel\Statement\Statement::class )
|
||||
->setMethods( [ 'getPropertyId' ] )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$statement->method( 'getPropertyId' )->willReturn( $this->mathProperty );
|
||||
/** @var Wikibase\DataModel\Statement\Statement $statement */
|
||||
$statement = new Statement( new PropertyNoValueSnak( $this->mathProperty ) );
|
||||
$updater->processStatement( $statement );
|
||||
$parserOutput = $this->getMockBuilder( ParserOutput::class )->setMethods( [
|
||||
'addModules',
|
||||
|
|
|
@ -8,30 +8,13 @@
|
|||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class MathInputCheckTest extends MediaWikiTestCase {
|
||||
/**
|
||||
* @covers \MathInputCheck::isValid
|
||||
*/
|
||||
public function testIsValid() {
|
||||
$InputCheck = $this->getMockBuilder( MathInputCheck::class )->getMock();
|
||||
$this->assertEquals( $InputCheck->IsValid(), false );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \MathInputCheck::getError
|
||||
* @todo Implement testGetError().
|
||||
*/
|
||||
public function testGetError() {
|
||||
$InputCheck = $this->getMockBuilder( MathInputCheck::class )->getMock();
|
||||
public function testAbstractClass() {
|
||||
$InputCheck = $this->getMockForAbstractClass( MathInputCheck::class );
|
||||
/** @var MathInputCheck $InputCheck */
|
||||
$this->assertFalse( $InputCheck->IsValid() );
|
||||
$this->assertNull( $InputCheck->getError() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \MathInputCheck::getValidTex
|
||||
*/
|
||||
public function testGetValidTex() {
|
||||
$InputCheck = $this->getMockBuilder( MathInputCheck::class )
|
||||
->setConstructorArgs( [ 'some tex input' ] )
|
||||
->getMock();
|
||||
$this->assertNull( $InputCheck->getValidTex() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -132,7 +132,6 @@ class MathMathMLTest extends MediaWikiTestCase {
|
|||
$url = 'http://example.com/timeout';
|
||||
$renderer = $this->getMockBuilder( MathMathML::class )
|
||||
->setMethods( [ 'getPostData' ] )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$renderer->expects( $this->once() )->method( 'getPostData' );
|
||||
|
||||
|
@ -149,7 +148,6 @@ class MathMathMLTest extends MediaWikiTestCase {
|
|||
self::setMockValues( false, true, true );
|
||||
$renderer = $this->getMockBuilder( MathMathML::class )
|
||||
->setMethods( [ 'getPostData', 'pickHost' ] )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$renderer->expects( $this->once() )->method( 'pickHost' );
|
||||
|
||||
|
@ -237,10 +235,7 @@ class MathMathMLTest extends MediaWikiTestCase {
|
|||
$rbi->method( 'getSuccess' )->willReturn( true );
|
||||
$renderer->setRestbaseInterface( $rbi );
|
||||
$renderer->render();
|
||||
$parser = $this->getMockBuilder( Parser::class )
|
||||
->setMethods( [ 'addTrackingCategory' ] )
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$parser = $this->createMock( Parser::class );
|
||||
$parser->method( 'addTrackingCategory' )->willReturn( true );
|
||||
$parser->expects( $this->once() )
|
||||
->method( 'addTrackingCategory' )
|
||||
|
|
|
@ -39,9 +39,10 @@ class MathRendererTest extends MediaWikiTestCase {
|
|||
*/
|
||||
public function testBasics() {
|
||||
$renderer = $this->getMockForAbstractClass( MathRenderer::class, [ self::SOME_TEX ] );
|
||||
/** @var MathRenderer $renderer */
|
||||
// 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" );
|
||||
$this->assertFalse( $renderer->isChanged(), "test if changed is initially false" );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,8 +56,9 @@ class MathRendererTest extends MediaWikiTestCase {
|
|||
'render',
|
||||
'getMathTableName',
|
||||
'getHtmlOutput'
|
||||
] )->disableOriginalConstructor()->getMock();
|
||||
] )->getMock();
|
||||
$renderer->expects( $this->never() )->method( 'writeToDatabase' );
|
||||
/** @var MathRenderer $renderer */
|
||||
$renderer->writeCache();
|
||||
}
|
||||
|
||||
|
@ -71,8 +73,9 @@ class MathRendererTest extends MediaWikiTestCase {
|
|||
'render',
|
||||
'getMathTableName',
|
||||
'getHtmlOutput'
|
||||
] )->disableOriginalConstructor()->getMock();
|
||||
] )->getMock();
|
||||
$renderer->expects( $this->never() )->method( 'writeToDatabase' );
|
||||
/** @var MathRenderer $renderer */
|
||||
$renderer->writeCache();
|
||||
}
|
||||
|
||||
|
@ -82,9 +85,10 @@ class MathRendererTest extends MediaWikiTestCase {
|
|||
'render',
|
||||
'getMathTableName',
|
||||
'getHtmlOutput'
|
||||
] )->disableOriginalConstructor()->getMock();
|
||||
] )->getMock();
|
||||
/** @var MathRenderer $renderer */
|
||||
$renderer->setPurge();
|
||||
$this->assertEquals( $renderer->isPurge(), true, "Test purge." );
|
||||
$this->assertTrue( $renderer->isPurge(), "Test purge." );
|
||||
}
|
||||
|
||||
public function testDisableCheckingAlways() {
|
||||
|
@ -100,9 +104,10 @@ class MathRendererTest extends MediaWikiTestCase {
|
|||
$renderer->expects( $this->never() )->method( 'readFromDatabase' );
|
||||
$renderer->expects( $this->once() )->method( 'setTex' )->with( self::TEXVCCHECK_OUTPUT );
|
||||
|
||||
$this->assertEquals( $renderer->checkTeX(), true );
|
||||
/** @var MathRenderer $renderer */
|
||||
$this->assertTrue( $renderer->checkTeX() );
|
||||
// now setTex sould not be called again
|
||||
$this->assertEquals( $renderer->checkTeX(), true );
|
||||
$this->assertTrue( $renderer->checkTeX() );
|
||||
}
|
||||
|
||||
public function testDisableCheckingNever() {
|
||||
|
@ -118,7 +123,8 @@ class MathRendererTest extends MediaWikiTestCase {
|
|||
$renderer->expects( $this->never() )->method( 'readFromDatabase' );
|
||||
$renderer->expects( $this->never() )->method( 'setTex' );
|
||||
|
||||
$this->assertEquals( $renderer->checkTeX(), true );
|
||||
/** @var MathRenderer $renderer */
|
||||
$this->assertTrue( $renderer->checkTeX() );
|
||||
}
|
||||
|
||||
public function testCheckingNewUnknown() {
|
||||
|
@ -135,9 +141,10 @@ class MathRendererTest extends MediaWikiTestCase {
|
|||
->will( $this->returnValue( false ) );
|
||||
$renderer->expects( $this->once() )->method( 'setTex' )->with( self::TEXVCCHECK_OUTPUT );
|
||||
|
||||
$this->assertEquals( $renderer->checkTeX(), true );
|
||||
/** @var MathRenderer $renderer */
|
||||
$this->assertTrue( $renderer->checkTeX() );
|
||||
// now setTex sould not be called again
|
||||
$this->assertEquals( $renderer->checkTeX(), true );
|
||||
$this->assertTrue( $renderer->checkTeX() );
|
||||
}
|
||||
|
||||
public function testCheckingNewKnown() {
|
||||
|
@ -154,9 +161,10 @@ class MathRendererTest extends MediaWikiTestCase {
|
|||
->will( $this->returnValue( true ) );
|
||||
$renderer->expects( $this->never() )->method( 'setTex' );
|
||||
|
||||
$this->assertEquals( $renderer->checkTeX(), true );
|
||||
/** @var MathRenderer $renderer */
|
||||
$this->assertTrue( $renderer->checkTeX() );
|
||||
// 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 );
|
||||
$this->assertTrue( $renderer->checkTeX() );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue