* upgrade patches for oracle 1.17->1.19
[mediawiki.git] / tests / phpunit / includes / parser / TagHooks.php
blob713ce846ded1ce2eed42a0ac2425d285f3a202cc
1 <?php
3 /**
4 * @group Parser
5 */
6 class TagHookTest extends MediaWikiTestCase {
8 public static function provideValidNames() {
9 return array( array( 'foo' ), array( 'foo-bar' ), array( 'foo_bar' ), array( 'FOO-BAR' ), array( 'foo bar' ) );
12 public static function provideBadNames() {
13 return array( array( "foo<bar" ), array( "foo>bar" ), array( "foo\nbar" ), array( "foo\rbar" ) );
16 /**
17 * @dataProvider provideValidNames
19 function testTagHooks( $tag ) {
20 global $wgParserConf;
21 $parser = new Parser( $wgParserConf );
23 $parser->setHook( $tag, array( $this, 'tagCallback' ) );
24 $parserOutput = $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), new ParserOptions );
25 $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() );
27 $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
30 /**
31 * @dataProvider provideBadNames
32 * @expectedException MWException
34 function testBadTagHooks( $tag ) {
35 global $wgParserConf;
36 $parser = new Parser( $wgParserConf );
38 $parser->setHook( $tag, array( $this, 'tagCallback' ) );
39 $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), new ParserOptions );
40 $this->fail('Exception not thrown.');
43 /**
44 * @dataProvider provideValidNames
46 function testFunctionTagHooks( $tag ) {
47 global $wgParserConf;
48 $parser = new Parser( $wgParserConf );
50 $parser->setFunctionTagHook( $tag, array( $this, 'functionTagCallback' ), 0 );
51 $parserOutput = $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), new ParserOptions );
52 $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() );
54 $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
57 /**
58 * @dataProvider provideBadNames
59 * @expectedException MWException
61 function testBadFunctionTagHooks( $tag ) {
62 global $wgParserConf;
63 $parser = new Parser( $wgParserConf );
65 $parser->setFunctionTagHook( $tag, array( $this, 'functionTagCallback' ), SFH_OBJECT_ARGS );
66 $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), new ParserOptions );
67 $this->fail('Exception not thrown.');
70 function tagCallback( $text, $params, $parser ) {
71 return str_rot13( $text );
74 function functionTagCallback( &$parser, $frame, $code, $attribs ) {
75 return str_rot13( $code );