Index: trunk/phase3/tests/phpunit/includes/parser/TagHooks.php |
— | — | @@ -0,0 +1,77 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * @group Parser |
| 6 | + */ |
| 7 | +class TagHookTest extends MediaWikiTestCase { |
| 8 | + |
| 9 | + public static function provideValidNames() { |
| 10 | + return array( array( 'foo' ), array( 'foo-bar' ), array( 'foo_bar' ), array( 'FOO-BAR' ) ); |
| 11 | + } |
| 12 | + |
| 13 | + public static function provideBadNames() { |
| 14 | + return array( array( "foo<bar" ), array( "foo>bar" ), array( "foo bar" ), array( "foo\nbar" ), array( "foo\rbar" ) ); |
| 15 | + } |
| 16 | + |
| 17 | + /** |
| 18 | + * @dataProvider provideValidNames |
| 19 | + */ |
| 20 | + function testTagHooks( $tag ) { |
| 21 | + global $wgParserConf; |
| 22 | + $parser = new Parser( $wgParserConf ); |
| 23 | + |
| 24 | + $parser->setHook( $tag, array( $this, 'tagCallback' ) ); |
| 25 | + $parserOutput = $parser->parse( "Foo<$tag>Bar</$tag>Baz", new Title( 'Test' ), new ParserOptions ); |
| 26 | + $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() ); |
| 27 | + |
| 28 | + $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * @dataProvider provideBadNames |
| 33 | + * @expectedException MWException |
| 34 | + */ |
| 35 | + function testBadTagHooks( $tag ) { |
| 36 | + global $wgParserConf; |
| 37 | + $parser = new Parser( $wgParserConf ); |
| 38 | + |
| 39 | + $parser->setHook( $tag, array( $this, 'tagCallback' ) ); |
| 40 | + $parser->parse( "Foo<$tag>Bar</$tag>Baz", new Title( 'Test' ), new ParserOptions ); |
| 41 | + $this->fail('Exception not thrown.'); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @dataProvider provideValidNames |
| 46 | + */ |
| 47 | + function testFunctionTagHooks( $tag ) { |
| 48 | + global $wgParserConf; |
| 49 | + $parser = new Parser( $wgParserConf ); |
| 50 | + |
| 51 | + $parser->setFunctionTagHook( $tag, array( $this, 'functionTagCallback' ), 0 ); |
| 52 | + $parserOutput = $parser->parse( "Foo<$tag>Bar</$tag>Baz", new Title( 'Test' ), new ParserOptions ); |
| 53 | + $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() ); |
| 54 | + |
| 55 | + $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @dataProvider provideBadNames |
| 60 | + * @expectedException MWException |
| 61 | + */ |
| 62 | + function testBadFunctionTagHooks( $tag ) { |
| 63 | + global $wgParserConf; |
| 64 | + $parser = new Parser( $wgParserConf ); |
| 65 | + |
| 66 | + $parser->setFunctionTagHook( $tag, array( $this, 'functionTagCallback' ), SFH_OBJECT_ARGS ); |
| 67 | + $parser->parse( "Foo<$tag>Bar</$tag>Baz", new Title( 'Test' ), new ParserOptions ); |
| 68 | + $this->fail('Exception not thrown.'); |
| 69 | + } |
| 70 | + |
| 71 | + function tagCallback( $text, $params, $parser ) { |
| 72 | + return str_rot13( $text ); |
| 73 | + } |
| 74 | + |
| 75 | + function functionTagCallback( &$parser, $frame, $code, $attribs ) { |
| 76 | + return str_rot13( $code ); |
| 77 | + } |
| 78 | +} |
Property changes on: trunk/phase3/tests/phpunit/includes/parser/TagHooks.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 79 | + native |