Debian Codegraph @

tests/phpunit/unit/includes/parser/MagicWordTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Parser;
4
5 use MediaWiki\Language\Language;
6 use MediaWiki\Parser\MagicWord;
7 use MediaWikiUnitTestCase;
8
9 /**
10 * @covers \MediaWiki\Parser\MagicWord
11 */
12 class MagicWordTest extends MediaWikiUnitTestCase {
13
14 public function testAllFeatures() {
15 $lang = $this->createNoOpMock( Language::class );
16 $mw = new MagicWord( 'ID', [ 'SYN', 'SYN2' ], false, $lang );
17
18 $this->assertSame( [ 'SYN', 'SYN2' ], $mw->getSynonyms() );
19 $this->assertSame( 'SYN', $mw->getSynonym( 0 ) );
20 $this->assertFalse( $mw->isCaseSensitive() );
21
22 $this->assertSame( '/SYN2|SYN/iu', $mw->getRegex() );
23 $this->assertSame( 'iu', $mw->getRegexCase() );
24 $this->assertSame( '/^(?:SYN2|SYN)/iu', $mw->getRegexStart() );
25 $this->assertSame( '/^(?:SYN2|SYN)$/iu', $mw->getRegexStartToEnd() );
26 $this->assertSame( 'SYN2|SYN', $mw->getBaseRegex() );
27
28 $this->assertFalse( $mw->match( 'ID' ), 'identifier is not automatically valid syntax' );
29 $this->assertTrue( $mw->match( '…SYN…' ) );
30 $this->assertFalse( $mw->matchStartToEnd( 'ID' ) );
31 $this->assertFalse( $mw->matchStartToEnd( 'SYN…' ) );
32 $this->assertTrue( $mw->matchStartToEnd( 'SYN' ) );
33
34 $text = 'ID';
35 $this->assertFalse( $mw->matchAndRemove( $text ) );
36 $text = '…SYN…';
37 $this->assertTrue( $mw->matchAndRemove( $text ) );
38 $this->assertSame( '……', $text );
39
40 $text = '…SYN';
41 $this->assertFalse( $mw->matchStartAndRemove( $text ) );
42 $text = 'SYN…';
43 $this->assertTrue( $mw->matchStartAndRemove( $text ) );
44 $this->assertSame( '…', $text );
45
46 $this->assertSame( '…NEW…', $mw->replace( 'NEW', '…SYN…' ) );
47 }
48
49 }