mediawiki-extensions-Math/tests/phpunit/MathDataUpdaterTest.php
Petr Pchelko 551340ee11 Skip wikibase tests if wikibase is not loaded
When running tests locally I don't want to install wikibase
if I'm not working on wikibase-math integration. It's
annoying that some of the tests fail in this schenario.

Depends-On: Id996abdb353547b95d795494ba961b9a215ef2ef
Change-Id: I836c7a3bab5393b7482e985d9148226373ae0a58
2021-08-13 18:43:42 +00:00

66 lines
2.1 KiB
PHP

<?php
use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\DataModel\Services\Entity\PropertyDataTypeMatcher;
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
use Wikibase\DataModel\Statement\Statement;
/**
* Test the MathDataUpdater for Wikidata
*
* @covers \MediaWiki\Extension\Math\MathDataUpdater
*
* @license GPL-2.0-or-later
*/
class MathDataUpdaterTest extends MediaWikiTestCase {
/**
* @var PropertyId
*/
private $mathProperty;
/**
* @var PropertyId
*/
private $otherProperty;
/**
* @inheritDoc
*/
protected function setUp(): void {
parent::setUp();
$this->markTestSkippedIfExtensionNotLoaded( 'WikibaseClient' );
$this->mathProperty = new PropertyId( 'P' . DummyPropertyDataTypeLookup::$mathId );
$this->otherProperty = new PropertyId( 'P' . ( DummyPropertyDataTypeLookup::$mathId + 1 ) );
}
public function testNoMath() {
$matcher = new PropertyDataTypeMatcher( new DummyPropertyDataTypeLookup() );
$updater = new MathDataUpdater( $matcher );
$statement = new Statement( new PropertyNoValueSnak( $this->otherProperty ) );
$updater->processStatement( $statement );
$parserOutput = $this->getMockBuilder( ParserOutput::class )->onlyMethods( [
'addModules',
'addModuleStyles',
] )->getMock();
$parserOutput->expects( $this->never() )->method( 'addModules' );
$parserOutput->expects( $this->never() )->method( 'addModuleStyles' );
/** @var ParserOutput $parserOutput */
$updater->updateParserOutput( $parserOutput );
}
public function testMath() {
$matcher = new PropertyDataTypeMatcher( new DummyPropertyDataTypeLookup() );
$updater = new MathDataUpdater( $matcher );
$statement = new Statement( new PropertyNoValueSnak( $this->mathProperty ) );
$updater->processStatement( $statement );
$parserOutput = $this->getMockBuilder( ParserOutput::class )->onlyMethods( [
'addModules',
'addModuleStyles',
] )->getMock();
$parserOutput->expects( $this->once() )->method( 'addModules' );
$parserOutput->expects( $this->once() )->method( 'addModuleStyles' );
/** @var ParserOutput $parserOutput */
$updater->updateParserOutput( $parserOutput );
}
}