MediaWiki  1.23.15
TagHooksTest.php
Go to the documentation of this file.
1 <?php
2 
7  public static function provideValidNames() {
8  return array( array( 'foo' ), array( 'foo-bar' ), array( 'foo_bar' ), array( 'FOO-BAR' ), array( 'foo bar' ) );
9  }
10 
11  public static function provideBadNames() {
12  return array( array( "foo<bar" ), array( "foo>bar" ), array( "foo\nbar" ), array( "foo\rbar" ) );
13  }
14 
15  protected function setUp() {
16  parent::setUp();
17 
18  $this->setMwGlobals( 'wgAlwaysUseTidy', false );
19  }
20 
25  public function testTagHooks( $tag ) {
26  global $wgParserConf, $wgContLang;
27  $parser = new Parser( $wgParserConf );
28 
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() );
32 
33  $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
34  }
35 
41  public function testBadTagHooks( $tag ) {
42  global $wgParserConf, $wgContLang;
43  $parser = new Parser( $wgParserConf );
44 
45  $parser->setHook( $tag, array( $this, 'tagCallback' ) );
46  $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), ParserOptions::newFromUserAndLang( new User, $wgContLang ) );
47  $this->fail( 'Exception not thrown.' );
48  }
49 
54  public function testFunctionTagHooks( $tag ) {
55  global $wgParserConf, $wgContLang;
56  $parser = new Parser( $wgParserConf );
57 
58  $parser->setFunctionTagHook( $tag, array( $this, 'functionTagCallback' ), 0 );
59  $parserOutput = $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), ParserOptions::newFromUserAndLang( new User, $wgContLang ) );
60  $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() );
61 
62  $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
63  }
64 
70  public function testBadFunctionTagHooks( $tag ) {
71  global $wgParserConf, $wgContLang;
72  $parser = new Parser( $wgParserConf );
73 
74  $parser->setFunctionTagHook( $tag, array( $this, 'functionTagCallback' ), SFH_OBJECT_ARGS );
75  $parser->parse( "Foo<$tag>Bar</$tag>Baz", Title::newFromText( 'Test' ), ParserOptions::newFromUserAndLang( new User, $wgContLang ) );
76  $this->fail( 'Exception not thrown.' );
77  }
78 
79  function tagCallback( $text, $params, $parser ) {
80  return str_rot13( $text );
81  }
82 
83  function functionTagCallback( &$parser, $frame, $code, $attribs ) {
84  return str_rot13( $code );
85  }
86 }
TagHookTest\testBadFunctionTagHooks
testBadFunctionTagHooks( $tag)
@dataProvider provideBadNames @expectedException MWException @covers Parser::setFunctionTagHook
Definition: TagHooksTest.php:70
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
TagHookTest
@group Parser
Definition: TagHooksTest.php:6
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Preprocessor
Definition: Preprocessor.php:27
SFH_OBJECT_ARGS
const SFH_OBJECT_ARGS
Definition: Defines.php:241
$params
$params
Definition: styleTest.css.php:40
fail
as a message key or array as accepted by ApiBase::dieUsageMsg after processing request parameters Return false to let the request fail
Definition: hooks.txt:375
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
TagHookTest\testBadTagHooks
testBadTagHooks( $tag)
@dataProvider provideBadNames @expectedException MWException @covers Parser::setHook
Definition: TagHooksTest.php:41
TagHookTest\setUp
setUp()
Definition: TagHooksTest.php:15
TagHookTest\provideValidNames
static provideValidNames()
Definition: TagHooksTest.php:7
ParserOptions\newFromUserAndLang
static newFromUserAndLang(User $user, Language $lang)
Get a ParserOptions object from a given user and language.
Definition: ParserOptions.php:386
TagHookTest\testTagHooks
testTagHooks( $tag)
@dataProvider provideValidNames @covers Parser::setHook
Definition: TagHooksTest.php:25
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
$parser
do that in ParserLimitReportFormat instead $parser
Definition: hooks.txt:1961
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
TagHookTest\tagCallback
tagCallback( $text, $params, $parser)
Definition: TagHooksTest.php:79
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
TagHookTest\testFunctionTagHooks
testFunctionTagHooks( $tag)
@dataProvider provideValidNames @covers Parser::setFunctionTagHook
Definition: TagHooksTest.php:54
TagHookTest\provideBadNames
static provideBadNames()
Definition: TagHooksTest.php:11
TagHookTest\functionTagCallback
functionTagCallback(&$parser, $frame, $code, $attribs)
Definition: TagHooksTest.php:83
$attribs
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition: hooks.txt:1530
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59