~ubuntu-branches/ubuntu/trusty/mediawiki/trusty

« back to all changes in this revision

Viewing changes to tests/phpunit/includes/parser/TagHooksTest.php

  • Committer: Package Import Robot
  • Author(s): Thorsten Glaser
  • Date: 2014-03-28 09:56:29 UTC
  • mfrom: (1.3.14)
  • Revision ID: package-import@ubuntu.com-20140328095629-1526y9tchdd507id
Tags: 1:1.19.14+dfsg-1
* New upstream security fix release (Closes: #742857):
  - (bug 62497) SECURITY: Add CSRF token on Special:ChangePassword
  - (bug 62467) Set a title for the context during import on the cli
* Use upstream-provided signing key bundle

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * @group Parser
 
5
 */
 
6
class TagHookTest extends MediaWikiTestCase {
 
7
        
 
8
        public static function provideValidNames() {
 
9
                return array( array( 'foo' ), array( 'foo-bar' ), array( 'foo_bar' ), array( 'FOO-BAR' ), array( 'foo bar' ) );
 
10
        }
 
11
 
 
12
        public static function provideBadNames() {
 
13
                return array( array( "foo<bar" ), array( "foo>bar" ), array( "foo\nbar" ),  array( "foo\rbar" ) );
 
14
        }
 
15
                
 
16
        /**
 
17
         * @dataProvider provideValidNames
 
18
         */
 
19
        function testTagHooks( $tag ) {
 
20
                global $wgParserConf;
 
21
                $parser = new Parser( $wgParserConf );
 
22
                
 
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() );
 
26
                
 
27
                $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
 
28
        }
 
29
        
 
30
        /**
 
31
         * @dataProvider provideBadNames
 
32
         * @expectedException MWException
 
33
         */
 
34
        function testBadTagHooks( $tag ) {
 
35
                global $wgParserConf;
 
36
                $parser = new Parser( $wgParserConf );
 
37
                
 
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.');
 
41
        }
 
42
        
 
43
        /**
 
44
         * @dataProvider provideValidNames
 
45
         */
 
46
        function testFunctionTagHooks( $tag ) {
 
47
                global $wgParserConf;
 
48
                $parser = new Parser( $wgParserConf );
 
49
                
 
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() );
 
53
                
 
54
                $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
 
55
        }
 
56
        
 
57
        /**
 
58
         * @dataProvider provideBadNames
 
59
         * @expectedException MWException
 
60
         */
 
61
        function testBadFunctionTagHooks( $tag ) {
 
62
                global $wgParserConf;
 
63
                $parser = new Parser( $wgParserConf );
 
64
                
 
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.');
 
68
        }
 
69
        
 
70
        function tagCallback( $text, $params, $parser ) {
 
71
                return str_rot13( $text );
 
72
        }
 
73
        
 
74
        function functionTagCallback( &$parser, $frame, $code, $attribs ) {
 
75
                return str_rot13( $code );
 
76
        }
 
77
}