| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Extension\Math\MathDataUpdater; |
| 4 |
use MediaWiki\Parser\ParserOutput; |
| 5 |
use Wikibase\DataModel\Entity\NumericPropertyId; |
| 6 |
use Wikibase\DataModel\Services\Entity\PropertyDataTypeMatcher; |
| 7 |
use Wikibase\DataModel\Snak\PropertyNoValueSnak; |
| 8 |
use Wikibase\DataModel\Statement\Statement; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
class MathDataUpdaterTest extends MediaWikiIntegrationTestCase { |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
private $mathProperty; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
private $otherProperty; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
protected function setUp(): void { |
| 32 |
parent::setUp(); |
| 33 |
$this->markTestSkippedIfExtensionNotLoaded( 'WikibaseClient' ); |
| 34 |
$this->mathProperty = new NumericPropertyId( 'P' . DummyPropertyDataTypeLookup::$mathId ); |
| 35 |
$this->otherProperty = new NumericPropertyId( 'P' . ( DummyPropertyDataTypeLookup::$mathId + 1 ) ); |
| 36 |
} |
| 37 |
|
| 38 |
public function testNoMath() { |
| 39 |
$matcher = new PropertyDataTypeMatcher( new DummyPropertyDataTypeLookup() ); |
| 40 |
$updater = new MathDataUpdater( $matcher ); |
| 41 |
$statement = new Statement( new PropertyNoValueSnak( $this->otherProperty ) ); |
| 42 |
$updater->processStatement( $statement ); |
| 43 |
$parserOutput = $this->getMockBuilder( ParserOutput::class )->onlyMethods( [ |
| 44 |
'addModules', |
| 45 |
'addModuleStyles', |
| 46 |
] )->getMock(); |
| 47 |
$parserOutput->expects( $this->never() )->method( 'addModuleStyles' ); |
| 48 |
|
| 49 |
$updater->updateParserOutput( $parserOutput ); |
| 50 |
} |
| 51 |
|
| 52 |
public function testMath() { |
| 53 |
$matcher = new PropertyDataTypeMatcher( new DummyPropertyDataTypeLookup() ); |
| 54 |
$updater = new MathDataUpdater( $matcher ); |
| 55 |
$statement = new Statement( new PropertyNoValueSnak( $this->mathProperty ) ); |
| 56 |
$updater->processStatement( $statement ); |
| 57 |
$parserOutput = $this->getMockBuilder( ParserOutput::class )->onlyMethods( [ |
| 58 |
'addModules', |
| 59 |
'addModuleStyles', |
| 60 |
] )->getMock(); |
| 61 |
$parserOutput->expects( $this->once() )->method( 'addModuleStyles' ); |
| 62 |
|
| 63 |
$updater->updateParserOutput( $parserOutput ); |
| 64 |
} |
| 65 |
} |