2018-07-05 10:43:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Wikibase\DataModel\Entity\PropertyId;
|
|
|
|
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
|
|
|
|
*
|
2019-11-26 09:59:54 +00:00
|
|
|
* @covers \MathDataUpdater
|
2018-07-05 10:43:55 +00:00
|
|
|
**
|
|
|
|
* @license GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
class MathDataUpdaterTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var PropertyId
|
|
|
|
*/
|
|
|
|
private $mathProperty;
|
|
|
|
/**
|
|
|
|
* @var PropertyId
|
|
|
|
*/
|
|
|
|
private $otherProperty;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2019-10-11 17:45:11 +00:00
|
|
|
protected function setUp() : void {
|
2018-07-05 10:43:55 +00:00
|
|
|
parent::setUp();
|
|
|
|
$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 );
|
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 );
|
|
|
|
$parserOutput = $this->getMockBuilder( ParserOutput::class )->setMethods( [
|
|
|
|
'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 );
|
|
|
|
$parserOutput = $this->getMockBuilder( ParserOutput::class )->setMethods( [
|
|
|
|
'addModules',
|
|
|
|
'addModuleStyles',
|
|
|
|
] )->getMock();
|
|
|
|
$parserOutput->expects( $this->once() )->method( 'addModules' );
|
|
|
|
$parserOutput->expects( $this->once() )->method( 'addModuleStyles' );
|
|
|
|
/** @var ParserOutput $parserOutput */
|
|
|
|
$updater->updateParserOutput( $parserOutput );
|
|
|
|
}
|
|
|
|
}
|