Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / parser / TagHooksTest.php
blob251da471c4ae5e337887807ef9da1ce5f7a19a40
1 <?php
3 /**
4 * @group Parser
5 */
6 class TagHookTest extends MediaWikiTestCase {
7 public static function provideValidNames() {
8 return array(
9 array( 'foo' ),
10 array( 'foo-bar' ),
11 array( 'foo_bar' ),
12 array( 'FOO-BAR' ),
13 array( 'foo bar' )
17 public static function provideBadNames() {
18 return array( array( "foo<bar" ), array( "foo>bar" ), array( "foo\nbar" ), array( "foo\rbar" ) );
21 protected function setUp() {
22 parent::setUp();
24 $this->setMwGlobals( 'wgAlwaysUseTidy', false );
27 /**
28 * @dataProvider provideValidNames
29 * @covers Parser::setHook
31 public function testTagHooks( $tag ) {
32 global $wgParserConf, $wgContLang;
33 $parser = new Parser( $wgParserConf );
35 $parser->setHook( $tag, array( $this, 'tagCallback' ) );
36 $parserOutput = $parser->parse(
37 "Foo<$tag>Bar</$tag>Baz",
38 Title::newFromText( 'Test' ),
39 ParserOptions::newFromUserAndLang( new User, $wgContLang )
41 $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() );
43 $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
46 /**
47 * @dataProvider provideBadNames
48 * @expectedException MWException
49 * @covers Parser::setHook
51 public function testBadTagHooks( $tag ) {
52 global $wgParserConf, $wgContLang;
53 $parser = new Parser( $wgParserConf );
55 $parser->setHook( $tag, array( $this, 'tagCallback' ) );
56 $parser->parse(
57 "Foo<$tag>Bar</$tag>Baz",
58 Title::newFromText( 'Test' ),
59 ParserOptions::newFromUserAndLang( new User, $wgContLang )
61 $this->fail( 'Exception not thrown.' );
64 /**
65 * @dataProvider provideValidNames
66 * @covers Parser::setFunctionTagHook
68 public function testFunctionTagHooks( $tag ) {
69 global $wgParserConf, $wgContLang;
70 $parser = new Parser( $wgParserConf );
72 $parser->setFunctionTagHook( $tag, array( $this, 'functionTagCallback' ), 0 );
73 $parserOutput = $parser->parse(
74 "Foo<$tag>Bar</$tag>Baz",
75 Title::newFromText( 'Test' ),
76 ParserOptions::newFromUserAndLang( new User, $wgContLang )
78 $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() );
80 $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
83 /**
84 * @dataProvider provideBadNames
85 * @expectedException MWException
86 * @covers Parser::setFunctionTagHook
88 public function testBadFunctionTagHooks( $tag ) {
89 global $wgParserConf, $wgContLang;
90 $parser = new Parser( $wgParserConf );
92 $parser->setFunctionTagHook( $tag, array( $this, 'functionTagCallback' ), Parser::SFH_OBJECT_ARGS );
93 $parser->parse(
94 "Foo<$tag>Bar</$tag>Baz",
95 Title::newFromText( 'Test' ),
96 ParserOptions::newFromUserAndLang( new User, $wgContLang )
98 $this->fail( 'Exception not thrown.' );
101 function tagCallback( $text, $params, $parser ) {
102 return str_rot13( $text );
105 function functionTagCallback( &$parser, $frame, $code, $attribs ) {
106 return str_rot13( $code );