Move ResultWrapper subclasses to Rdbms
[mediawiki.git] / tests / phpunit / includes / parser / TagHooksTest.php
blob12936ee21d10248063e33ea5804655c5d490c751
1 <?php
3 /**
4 * @group Database
5 * @group Parser
7 * @covers Parser
8 * @covers StripState
10 * @covers Preprocessor_DOM
11 * @covers PPDStack
12 * @covers PPDStackElement
13 * @covers PPDPart
14 * @covers PPFrame_DOM
15 * @covers PPTemplateFrame_DOM
16 * @covers PPCustomFrame_DOM
17 * @covers PPNode_DOM
19 * @covers Preprocessor_Hash
20 * @covers PPDStack_Hash
21 * @covers PPDStackElement_Hash
22 * @covers PPDPart_Hash
23 * @covers PPFrame_Hash
24 * @covers PPTemplateFrame_Hash
25 * @covers PPCustomFrame_Hash
26 * @covers PPNode_Hash_Tree
27 * @covers PPNode_Hash_Text
28 * @covers PPNode_Hash_Array
29 * @covers PPNode_Hash_Attr
31 class TagHookTest extends MediaWikiTestCase {
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 /**
47 * @dataProvider provideValidNames
49 public function testTagHooks( $tag ) {
50 global $wgParserConf, $wgContLang;
51 $parser = new Parser( $wgParserConf );
53 $parser->setHook( $tag, [ $this, 'tagCallback' ] );
54 $parserOutput = $parser->parse(
55 "Foo<$tag>Bar</$tag>Baz",
56 Title::newFromText( 'Test' ),
57 ParserOptions::newFromUserAndLang( new User, $wgContLang )
59 $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() );
61 $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
64 /**
65 * @dataProvider provideBadNames
66 * @expectedException MWException
68 public function testBadTagHooks( $tag ) {
69 global $wgParserConf, $wgContLang;
70 $parser = new Parser( $wgParserConf );
72 $parser->setHook( $tag, [ $this, 'tagCallback' ] );
73 $parser->parse(
74 "Foo<$tag>Bar</$tag>Baz",
75 Title::newFromText( 'Test' ),
76 ParserOptions::newFromUserAndLang( new User, $wgContLang )
78 $this->fail( 'Exception not thrown.' );
81 /**
82 * @dataProvider provideValidNames
84 public function testFunctionTagHooks( $tag ) {
85 global $wgParserConf, $wgContLang;
86 $parser = new Parser( $wgParserConf );
88 $parser->setFunctionTagHook( $tag, [ $this, 'functionTagCallback' ], 0 );
89 $parserOutput = $parser->parse(
90 "Foo<$tag>Bar</$tag>Baz",
91 Title::newFromText( 'Test' ),
92 ParserOptions::newFromUserAndLang( new User, $wgContLang )
94 $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() );
96 $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
99 /**
100 * @dataProvider provideBadNames
101 * @expectedException MWException
103 public function testBadFunctionTagHooks( $tag ) {
104 global $wgParserConf, $wgContLang;
105 $parser = new Parser( $wgParserConf );
107 $parser->setFunctionTagHook(
108 $tag,
109 [ $this, 'functionTagCallback' ],
110 Parser::SFH_OBJECT_ARGS
112 $parser->parse(
113 "Foo<$tag>Bar</$tag>Baz",
114 Title::newFromText( 'Test' ),
115 ParserOptions::newFromUserAndLang( new User, $wgContLang )
117 $this->fail( 'Exception not thrown.' );
120 function tagCallback( $text, $params, $parser ) {
121 return str_rot13( $text );
124 function functionTagCallback( &$parser, $frame, $code, $attribs ) {
125 return str_rot13( $code );