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" ) );
17 * @dataProvider provideValidNames
19 function testTagHooks( $tag ) {
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
31 * @dataProvider provideBadNames
32 * @expectedException MWException
34 function testBadTagHooks( $tag ) {
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.');
44 * @dataProvider provideValidNames
46 function testFunctionTagHooks( $tag ) {
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
58 * @dataProvider provideBadNames
59 * @expectedException MWException
61 function testBadFunctionTagHooks( $tag ) {
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 );