Debian Codegraph @

extensions/Math/tests/phpunit/MathDataUpdaterTest.php

raw symbols SCIP
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 * Test the MathDataUpdater for Wikidata
12 *
13 * @covers \MediaWiki\Extension\Math\MathDataUpdater
14 *
15 * @license GPL-2.0-or-later
16 */
17 class MathDataUpdaterTest extends MediaWikiIntegrationTestCase {
18
19 /**
20 * @var NumericPropertyId
21 */
22 private $mathProperty;
23 /**
24 * @var NumericPropertyId
25 */
26 private $otherProperty;
27
28 /**
29 * @inheritDoc
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 /** @var ParserOutput $parserOutput */
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 /** @var ParserOutput $parserOutput */
63 $updater->updateParserOutput( $parserOutput );
64 }
65 }