Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / parser / TagHooksTest.php
blob333c2cde772cbfb9e44f67a6579af312dc640a63
1 <?php
3 namespace MediaWiki\Tests\Parser;
5 use InvalidArgumentException;
6 use MediaWiki\Parser\ParserOptions;
7 use MediaWiki\Title\Title;
8 use MediaWiki\User\User;
9 use MediaWikiIntegrationTestCase;
11 /**
12 * @group Database
13 * @group Parser
15 * @covers \MediaWiki\Parser\Parser
16 * @covers \MediaWiki\Parser\BlockLevelPass
17 * @covers \MediaWiki\Parser\StripState
19 * @covers \MediaWiki\Parser\Preprocessor_Hash
20 * @covers \MediaWiki\Parser\PPDStack_Hash
21 * @covers \MediaWiki\Parser\PPDStackElement_Hash
22 * @covers \MediaWiki\Parser\PPDPart_Hash
23 * @covers \MediaWiki\Parser\PPFrame_Hash
24 * @covers \MediaWiki\Parser\PPTemplateFrame_Hash
25 * @covers \MediaWiki\Parser\PPCustomFrame_Hash
26 * @covers \MediaWiki\Parser\PPNode_Hash_Tree
27 * @covers \MediaWiki\Parser\PPNode_Hash_Text
28 * @covers \MediaWiki\Parser\PPNode_Hash_Array
29 * @covers \MediaWiki\Parser\PPNode_Hash_Attr
31 class TagHooksTest extends MediaWikiIntegrationTestCase {
32 public static function provideValidNames() {
33 return [
34 [ 'foo' ],
35 [ 'foo-bar' ],
36 [ 'foo_bar' ],
37 [ 'FOO-BAR' ],
38 [ 'foo bar' ]
42 public static function provideBadNames() {
43 return [ [ "foo<bar" ], [ "foo>bar" ], [ "foo\nbar" ], [ "foo\rbar" ] ];
46 private function getParserOptions() {
47 $popt = ParserOptions::newFromUserAndLang( new User,
48 $this->getServiceContainer()->getContentLanguage() );
49 return $popt;
52 /**
53 * @dataProvider provideValidNames
55 public function testTagHooks( $tag ) {
56 $parser = $this->getServiceContainer()->getParserFactory()->create();
58 $parser->setHook( $tag, [ $this, 'tagCallback' ] );
59 $parserOutput = $parser->parse(
60 "Foo<$tag>Bar</$tag>Baz",
61 Title::makeTitle( NS_MAIN, 'Test' ),
62 $this->getParserOptions()
64 $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getRawText() );
67 /**
68 * @dataProvider provideBadNames
70 public function testBadTagHooks( $tag ) {
71 $parser = $this->getServiceContainer()->getParserFactory()->create();
73 $this->expectException( InvalidArgumentException::class );
74 $parser->setHook( $tag, [ $this, 'tagCallback' ] );
77 public function tagCallback( $text, $params, $parser ) {
78 return str_rot13( $text );