d643264fd048ec6abeec5b810616e0fe78e1e0d2
6 class TagHookTest
extends MediaWikiTestCase
{
7 public static function provideValidNames() {
8 return array( array( 'foo' ), array( 'foo-bar' ), array( 'foo_bar' ), array( 'FOO-BAR' ), array( 'foo bar' ) );
11 public static function provideBadNames() {
12 return array( array( "foo<bar" ), array( "foo>bar" ), array( "foo\nbar" ), array( "foo\rbar" ) );
15 protected function setUp() {
18 $this->setMwGlobals( 'wgAlwaysUseTidy', false );
22 * @dataProvider provideValidNames
25 function testTagHooks( $tag ) {
26 global $wgParserConf, $wgContLang;
27 $parser = new Parser( $wgParserConf );
29 $parser->setHook( $tag, array( $this, 'tagCallback' ) );
30 $parserOutput = $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title
::newFromText( 'Test' ), ParserOptions
::newFromUserAndLang( new User
, $wgContLang ) );
31 $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() );
33 $parser->mPreprocessor
= null; # Break the Parser <-> Preprocessor cycle
37 * @dataProvider provideBadNames
38 * @expectedException MWException
40 function testBadTagHooks( $tag ) {
41 global $wgParserConf, $wgContLang;
42 $parser = new Parser( $wgParserConf );
44 $parser->setHook( $tag, array( $this, 'tagCallback' ) );
45 $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title
::newFromText( 'Test' ), ParserOptions
::newFromUserAndLang( new User
, $wgContLang ) );
46 $this->fail( 'Exception not thrown.' );
50 * @dataProvider provideValidNames
53 function testFunctionTagHooks( $tag ) {
54 global $wgParserConf, $wgContLang;
55 $parser = new Parser( $wgParserConf );
57 $parser->setFunctionTagHook( $tag, array( $this, 'functionTagCallback' ), 0 );
58 $parserOutput = $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title
::newFromText( 'Test' ), ParserOptions
::newFromUserAndLang( new User
, $wgContLang ) );
59 $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() );
61 $parser->mPreprocessor
= null; # Break the Parser <-> Preprocessor cycle
65 * @dataProvider provideBadNames
66 * @expectedException MWException
68 function testBadFunctionTagHooks( $tag ) {
69 global $wgParserConf, $wgContLang;
70 $parser = new Parser( $wgParserConf );
72 $parser->setFunctionTagHook( $tag, array( $this, 'functionTagCallback' ), SFH_OBJECT_ARGS
);
73 $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title
::newFromText( 'Test' ), ParserOptions
::newFromUserAndLang( new User
, $wgContLang ) );
74 $this->fail( 'Exception not thrown.' );
77 function tagCallback( $text, $params, $parser ) {
78 return str_rot13( $text );
81 function functionTagCallback( &$parser, $frame, $code, $attribs ) {
82 return str_rot13( $code );