File: MagicWordTest.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (49 lines) | stat: -rw-r--r-- 1,622 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php

namespace MediaWiki\Tests\Parser;

use MediaWiki\Language\Language;
use MediaWiki\Parser\MagicWord;
use MediaWikiUnitTestCase;

/**
 * @covers \MediaWiki\Parser\MagicWord
 */
class MagicWordTest extends MediaWikiUnitTestCase {

	public function testAllFeatures() {
		$lang = $this->createNoOpMock( Language::class );
		$mw = new MagicWord( 'ID', [ 'SYN', 'SYN2' ], false, $lang );

		$this->assertSame( [ 'SYN', 'SYN2' ], $mw->getSynonyms() );
		$this->assertSame( 'SYN', $mw->getSynonym( 0 ) );
		$this->assertFalse( $mw->isCaseSensitive() );

		$this->assertSame( '/SYN2|SYN/iu', $mw->getRegex() );
		$this->assertSame( 'iu', $mw->getRegexCase() );
		$this->assertSame( '/^(?:SYN2|SYN)/iu', $mw->getRegexStart() );
		$this->assertSame( '/^(?:SYN2|SYN)$/iu', $mw->getRegexStartToEnd() );
		$this->assertSame( 'SYN2|SYN', $mw->getBaseRegex() );

		$this->assertFalse( $mw->match( 'ID' ), 'identifier is not automatically valid syntax' );
		$this->assertTrue( $mw->match( '…SYN…' ) );
		$this->assertFalse( $mw->matchStartToEnd( 'ID' ) );
		$this->assertFalse( $mw->matchStartToEnd( 'SYN…' ) );
		$this->assertTrue( $mw->matchStartToEnd( 'SYN' ) );

		$text = 'ID';
		$this->assertFalse( $mw->matchAndRemove( $text ) );
		$text = '…SYN…';
		$this->assertTrue( $mw->matchAndRemove( $text ) );
		$this->assertSame( '……', $text );

		$text = '…SYN';
		$this->assertFalse( $mw->matchStartAndRemove( $text ) );
		$text = 'SYN…';
		$this->assertTrue( $mw->matchStartAndRemove( $text ) );
		$this->assertSame( '…', $text );

		$this->assertSame( '…NEW…', $mw->replace( 'NEW', '…SYN…' ) );
	}

}