2018-07-05 10:43:55 +00:00
|
|
|
<?php
|
|
|
|
|
2021-10-01 01:16:45 +00:00
|
|
|
use MediaWiki\Extension\Math\MathDataUpdater;
|
2021-09-17 08:33:48 +00:00
|
|
|
use Wikibase\DataModel\Entity\NumericPropertyId;
|
2018-07-05 10:43:55 +00:00
|
|
|
use Wikibase\DataModel\Services\Entity\PropertyDataTypeMatcher;
|
2019-11-26 11:01:30 +00:00
|
|
|
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
|
|
|
|
use Wikibase\DataModel\Statement\Statement;
|
2018-07-05 10:43:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the MathDataUpdater for Wikidata
|
|
|
|
*
|
2021-04-07 22:22:05 +00:00
|
|
|
* @covers \MediaWiki\Extension\Math\MathDataUpdater
|
2020-01-14 07:43:50 +00:00
|
|
|
*
|
2018-07-05 10:43:55 +00:00
|
|
|
* @license GPL-2.0-or-later
|
|
|
|
*/
|
2021-10-11 22:51:10 +00:00
|
|
|
class MathDataUpdaterTest extends MediaWikiIntegrationTestCase {
|
2018-07-05 10:43:55 +00:00
|
|
|
|
|
|
|
/**
|
2021-09-17 08:33:48 +00:00
|
|
|
* @var NumericPropertyId
|
2018-07-05 10:43:55 +00:00
|
|
|
*/
|
|
|
|
private $mathProperty;
|
|
|
|
/**
|
2021-09-17 08:33:48 +00:00
|
|
|
* @var NumericPropertyId
|
2018-07-05 10:43:55 +00:00
|
|
|
*/
|
|
|
|
private $otherProperty;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2021-07-22 11:56:28 +00:00
|
|
|
protected function setUp(): void {
|
2018-07-05 10:43:55 +00:00
|
|
|
parent::setUp();
|
2021-08-12 12:54:49 +00:00
|
|
|
$this->markTestSkippedIfExtensionNotLoaded( 'WikibaseClient' );
|
2021-09-17 08:33:48 +00:00
|
|
|
$this->mathProperty = new NumericPropertyId( 'P' . DummyPropertyDataTypeLookup::$mathId );
|
|
|
|
$this->otherProperty = new NumericPropertyId( 'P' . ( DummyPropertyDataTypeLookup::$mathId + 1 ) );
|
2018-07-05 10:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoMath() {
|
|
|
|
$matcher = new PropertyDataTypeMatcher( new DummyPropertyDataTypeLookup() );
|
|
|
|
$updater = new MathDataUpdater( $matcher );
|
2019-11-26 11:01:30 +00:00
|
|
|
$statement = new Statement( new PropertyNoValueSnak( $this->otherProperty ) );
|
2018-07-05 10:43:55 +00:00
|
|
|
$updater->processStatement( $statement );
|
2021-05-04 08:06:42 +00:00
|
|
|
$parserOutput = $this->getMockBuilder( ParserOutput::class )->onlyMethods( [
|
2018-07-05 10:43:55 +00:00
|
|
|
'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 );
|
2019-11-26 11:01:30 +00:00
|
|
|
$statement = new Statement( new PropertyNoValueSnak( $this->mathProperty ) );
|
2018-07-05 10:43:55 +00:00
|
|
|
$updater->processStatement( $statement );
|
2021-05-04 08:06:42 +00:00
|
|
|
$parserOutput = $this->getMockBuilder( ParserOutput::class )->onlyMethods( [
|
2018-07-05 10:43:55 +00:00
|
|
|
'addModules',
|
|
|
|
'addModuleStyles',
|
|
|
|
] )->getMock();
|
|
|
|
$parserOutput->expects( $this->once() )->method( 'addModules' );
|
|
|
|
$parserOutput->expects( $this->once() )->method( 'addModuleStyles' );
|
|
|
|
/** @var ParserOutput $parserOutput */
|
|
|
|
$updater->updateParserOutput( $parserOutput );
|
|
|
|
}
|
|
|
|
}
|