mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-24 07:34:22 +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\Entity\PropertyId;
|
||||||
use Wikibase\DataModel\Services\Entity\PropertyDataTypeMatcher;
|
use Wikibase\DataModel\Services\Entity\PropertyDataTypeMatcher;
|
||||||
use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup;
|
use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup;
|
||||||
|
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
|
||||||
|
use Wikibase\DataModel\Statement\Statement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the MathDataUpdater for Wikidata
|
* Test the MathDataUpdater for Wikidata
|
||||||
|
@ -34,13 +36,7 @@ class MathDataUpdaterTest extends MediaWikiTestCase {
|
||||||
public function testNoMath() {
|
public function testNoMath() {
|
||||||
$matcher = new PropertyDataTypeMatcher( new DummyPropertyDataTypeLookup() );
|
$matcher = new PropertyDataTypeMatcher( new DummyPropertyDataTypeLookup() );
|
||||||
$updater = new MathDataUpdater( $matcher );
|
$updater = new MathDataUpdater( $matcher );
|
||||||
$statement =
|
$statement = new Statement( new PropertyNoValueSnak( $this->otherProperty ) );
|
||||||
$this->getMockBuilder( Wikibase\DataModel\Statement\Statement::class )
|
|
||||||
->setMethods( [ 'getPropertyId' ] )
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$statement->method( 'getPropertyId' )->willReturn( $this->otherProperty );
|
|
||||||
/** @var Wikibase\DataModel\Statement\Statement $statement */
|
|
||||||
$updater->processStatement( $statement );
|
$updater->processStatement( $statement );
|
||||||
$parserOutput = $this->getMockBuilder( ParserOutput::class )->setMethods( [
|
$parserOutput = $this->getMockBuilder( ParserOutput::class )->setMethods( [
|
||||||
'addModules',
|
'addModules',
|
||||||
|
@ -55,13 +51,7 @@ class MathDataUpdaterTest extends MediaWikiTestCase {
|
||||||
public function testMath() {
|
public function testMath() {
|
||||||
$matcher = new PropertyDataTypeMatcher( new DummyPropertyDataTypeLookup() );
|
$matcher = new PropertyDataTypeMatcher( new DummyPropertyDataTypeLookup() );
|
||||||
$updater = new MathDataUpdater( $matcher );
|
$updater = new MathDataUpdater( $matcher );
|
||||||
$statement =
|
$statement = new Statement( new PropertyNoValueSnak( $this->mathProperty ) );
|
||||||
$this->getMockBuilder( Wikibase\DataModel\Statement\Statement::class )
|
|
||||||
->setMethods( [ 'getPropertyId' ] )
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$statement->method( 'getPropertyId' )->willReturn( $this->mathProperty );
|
|
||||||
/** @var Wikibase\DataModel\Statement\Statement $statement */
|
|
||||||
$updater->processStatement( $statement );
|
$updater->processStatement( $statement );
|
||||||
$parserOutput = $this->getMockBuilder( ParserOutput::class )->setMethods( [
|
$parserOutput = $this->getMockBuilder( ParserOutput::class )->setMethods( [
|
||||||
'addModules',
|
'addModules',
|
||||||
|
|
|
@ -8,30 +8,13 @@
|
||||||
* @license GPL-2.0-or-later
|
* @license GPL-2.0-or-later
|
||||||
*/
|
*/
|
||||||
class MathInputCheckTest extends MediaWikiTestCase {
|
class MathInputCheckTest extends MediaWikiTestCase {
|
||||||
/**
|
|
||||||
* @covers \MathInputCheck::isValid
|
|
||||||
*/
|
|
||||||
public function testIsValid() {
|
|
||||||
$InputCheck = $this->getMockBuilder( MathInputCheck::class )->getMock();
|
|
||||||
$this->assertEquals( $InputCheck->IsValid(), false );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public function testAbstractClass() {
|
||||||
* @covers \MathInputCheck::getError
|
$InputCheck = $this->getMockForAbstractClass( MathInputCheck::class );
|
||||||
* @todo Implement testGetError().
|
/** @var MathInputCheck $InputCheck */
|
||||||
*/
|
$this->assertFalse( $InputCheck->IsValid() );
|
||||||
public function testGetError() {
|
|
||||||
$InputCheck = $this->getMockBuilder( MathInputCheck::class )->getMock();
|
|
||||||
$this->assertNull( $InputCheck->getError() );
|
$this->assertNull( $InputCheck->getError() );
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \MathInputCheck::getValidTex
|
|
||||||
*/
|
|
||||||
public function testGetValidTex() {
|
|
||||||
$InputCheck = $this->getMockBuilder( MathInputCheck::class )
|
|
||||||
->setConstructorArgs( [ 'some tex input' ] )
|
|
||||||
->getMock();
|
|
||||||
$this->assertNull( $InputCheck->getValidTex() );
|
$this->assertNull( $InputCheck->getValidTex() );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,6 @@ class MathMathMLTest extends MediaWikiTestCase {
|
||||||
$url = 'http://example.com/timeout';
|
$url = 'http://example.com/timeout';
|
||||||
$renderer = $this->getMockBuilder( MathMathML::class )
|
$renderer = $this->getMockBuilder( MathMathML::class )
|
||||||
->setMethods( [ 'getPostData' ] )
|
->setMethods( [ 'getPostData' ] )
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
->getMock();
|
||||||
$renderer->expects( $this->once() )->method( 'getPostData' );
|
$renderer->expects( $this->once() )->method( 'getPostData' );
|
||||||
|
|
||||||
|
@ -149,7 +148,6 @@ class MathMathMLTest extends MediaWikiTestCase {
|
||||||
self::setMockValues( false, true, true );
|
self::setMockValues( false, true, true );
|
||||||
$renderer = $this->getMockBuilder( MathMathML::class )
|
$renderer = $this->getMockBuilder( MathMathML::class )
|
||||||
->setMethods( [ 'getPostData', 'pickHost' ] )
|
->setMethods( [ 'getPostData', 'pickHost' ] )
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
->getMock();
|
||||||
$renderer->expects( $this->once() )->method( 'pickHost' );
|
$renderer->expects( $this->once() )->method( 'pickHost' );
|
||||||
|
|
||||||
|
@ -237,10 +235,7 @@ class MathMathMLTest extends MediaWikiTestCase {
|
||||||
$rbi->method( 'getSuccess' )->willReturn( true );
|
$rbi->method( 'getSuccess' )->willReturn( true );
|
||||||
$renderer->setRestbaseInterface( $rbi );
|
$renderer->setRestbaseInterface( $rbi );
|
||||||
$renderer->render();
|
$renderer->render();
|
||||||
$parser = $this->getMockBuilder( Parser::class )
|
$parser = $this->createMock( Parser::class );
|
||||||
->setMethods( [ 'addTrackingCategory' ] )
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$parser->method( 'addTrackingCategory' )->willReturn( true );
|
$parser->method( 'addTrackingCategory' )->willReturn( true );
|
||||||
$parser->expects( $this->once() )
|
$parser->expects( $this->once() )
|
||||||
->method( 'addTrackingCategory' )
|
->method( 'addTrackingCategory' )
|
||||||
|
|
|
@ -39,9 +39,10 @@ class MathRendererTest extends MediaWikiTestCase {
|
||||||
*/
|
*/
|
||||||
public function testBasics() {
|
public function testBasics() {
|
||||||
$renderer = $this->getMockForAbstractClass( MathRenderer::class, [ self::SOME_TEX ] );
|
$renderer = $this->getMockForAbstractClass( MathRenderer::class, [ self::SOME_TEX ] );
|
||||||
|
/** @var MathRenderer $renderer */
|
||||||
// check if the TeX input was corretly passed to the class
|
// check if the TeX input was corretly passed to the class
|
||||||
$this->assertEquals( self::SOME_TEX, $renderer->getTex(), "test getTex" );
|
$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',
|
'render',
|
||||||
'getMathTableName',
|
'getMathTableName',
|
||||||
'getHtmlOutput'
|
'getHtmlOutput'
|
||||||
] )->disableOriginalConstructor()->getMock();
|
] )->getMock();
|
||||||
$renderer->expects( $this->never() )->method( 'writeToDatabase' );
|
$renderer->expects( $this->never() )->method( 'writeToDatabase' );
|
||||||
|
/** @var MathRenderer $renderer */
|
||||||
$renderer->writeCache();
|
$renderer->writeCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,8 +73,9 @@ class MathRendererTest extends MediaWikiTestCase {
|
||||||
'render',
|
'render',
|
||||||
'getMathTableName',
|
'getMathTableName',
|
||||||
'getHtmlOutput'
|
'getHtmlOutput'
|
||||||
] )->disableOriginalConstructor()->getMock();
|
] )->getMock();
|
||||||
$renderer->expects( $this->never() )->method( 'writeToDatabase' );
|
$renderer->expects( $this->never() )->method( 'writeToDatabase' );
|
||||||
|
/** @var MathRenderer $renderer */
|
||||||
$renderer->writeCache();
|
$renderer->writeCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,9 +85,10 @@ class MathRendererTest extends MediaWikiTestCase {
|
||||||
'render',
|
'render',
|
||||||
'getMathTableName',
|
'getMathTableName',
|
||||||
'getHtmlOutput'
|
'getHtmlOutput'
|
||||||
] )->disableOriginalConstructor()->getMock();
|
] )->getMock();
|
||||||
|
/** @var MathRenderer $renderer */
|
||||||
$renderer->setPurge();
|
$renderer->setPurge();
|
||||||
$this->assertEquals( $renderer->isPurge(), true, "Test purge." );
|
$this->assertTrue( $renderer->isPurge(), "Test purge." );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDisableCheckingAlways() {
|
public function testDisableCheckingAlways() {
|
||||||
|
@ -100,9 +104,10 @@ class MathRendererTest extends MediaWikiTestCase {
|
||||||
$renderer->expects( $this->never() )->method( 'readFromDatabase' );
|
$renderer->expects( $this->never() )->method( 'readFromDatabase' );
|
||||||
$renderer->expects( $this->once() )->method( 'setTex' )->with( self::TEXVCCHECK_OUTPUT );
|
$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
|
// now setTex sould not be called again
|
||||||
$this->assertEquals( $renderer->checkTeX(), true );
|
$this->assertTrue( $renderer->checkTeX() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDisableCheckingNever() {
|
public function testDisableCheckingNever() {
|
||||||
|
@ -118,7 +123,8 @@ class MathRendererTest extends MediaWikiTestCase {
|
||||||
$renderer->expects( $this->never() )->method( 'readFromDatabase' );
|
$renderer->expects( $this->never() )->method( 'readFromDatabase' );
|
||||||
$renderer->expects( $this->never() )->method( 'setTex' );
|
$renderer->expects( $this->never() )->method( 'setTex' );
|
||||||
|
|
||||||
$this->assertEquals( $renderer->checkTeX(), true );
|
/** @var MathRenderer $renderer */
|
||||||
|
$this->assertTrue( $renderer->checkTeX() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCheckingNewUnknown() {
|
public function testCheckingNewUnknown() {
|
||||||
|
@ -135,9 +141,10 @@ class MathRendererTest extends MediaWikiTestCase {
|
||||||
->will( $this->returnValue( false ) );
|
->will( $this->returnValue( false ) );
|
||||||
$renderer->expects( $this->once() )->method( 'setTex' )->with( self::TEXVCCHECK_OUTPUT );
|
$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
|
// now setTex sould not be called again
|
||||||
$this->assertEquals( $renderer->checkTeX(), true );
|
$this->assertTrue( $renderer->checkTeX() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCheckingNewKnown() {
|
public function testCheckingNewKnown() {
|
||||||
|
@ -154,9 +161,10 @@ class MathRendererTest extends MediaWikiTestCase {
|
||||||
->will( $this->returnValue( true ) );
|
->will( $this->returnValue( true ) );
|
||||||
$renderer->expects( $this->never() )->method( 'setTex' );
|
$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
|
// we don't mark a object as checked even though we rely on the database cache
|
||||||
// so readFromDatabase will be called again
|
// so readFromDatabase will be called again
|
||||||
$this->assertEquals( $renderer->checkTeX(), true );
|
$this->assertTrue( $renderer->checkTeX() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue