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…' ) );
}
}
|