MediaWiki REL1_32
TagHooksTest.php
Go to the documentation of this file.
1<?php
2
4
35 public static function provideValidNames() {
36 return [
37 [ 'foo' ],
38 [ 'foo-bar' ],
39 [ 'foo_bar' ],
40 [ 'FOO-BAR' ],
41 [ 'foo bar' ]
42 ];
43 }
44
45 public static function provideBadNames() {
46 return [ [ "foo<bar" ], [ "foo>bar" ], [ "foo\nbar" ], [ "foo\rbar" ] ];
47 }
48
49 private function getParserOptions() {
50 $popt = ParserOptions::newFromUserAndLang( new User,
51 MediaWikiServices::getInstance()->getContentLanguage() );
52 return $popt;
53 }
54
58 public function testTagHooks( $tag ) {
59 $parser = MediaWikiServices::getInstance()->getParserFactory()->create();
60
61 $parser->setHook( $tag, [ $this, 'tagCallback' ] );
62 $parserOutput = $parser->parse(
63 "Foo<$tag>Bar</$tag>Baz",
64 Title::newFromText( 'Test' ),
65 $this->getParserOptions()
66 );
67 $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText( [ 'unwrap' => true ] ) );
68
69 $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
70 }
71
76 public function testBadTagHooks( $tag ) {
77 $parser = MediaWikiServices::getInstance()->getParserFactory()->create();
78
79 $parser->setHook( $tag, [ $this, 'tagCallback' ] );
80 $parser->parse(
81 "Foo<$tag>Bar</$tag>Baz",
82 Title::newFromText( 'Test' ),
83 $this->getParserOptions()
84 );
85 $this->fail( 'Exception not thrown.' );
86 }
87
91 public function testFunctionTagHooks( $tag ) {
92 $parser = MediaWikiServices::getInstance()->getParserFactory()->create();
93
94 $parser->setFunctionTagHook( $tag, [ $this, 'functionTagCallback' ], 0 );
95 $parserOutput = $parser->parse(
96 "Foo<$tag>Bar</$tag>Baz",
97 Title::newFromText( 'Test' ),
98 $this->getParserOptions()
99 );
100 $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText( [ 'unwrap' => true ] ) );
101
102 $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
103 }
104
109 public function testBadFunctionTagHooks( $tag ) {
110 $parser = MediaWikiServices::getInstance()->getParserFactory()->create();
111
112 $parser->setFunctionTagHook(
113 $tag,
114 [ $this, 'functionTagCallback' ],
115 Parser::SFH_OBJECT_ARGS
116 );
117 $parser->parse(
118 "Foo<$tag>Bar</$tag>Baz",
119 Title::newFromText( 'Test' ),
120 $this->getParserOptions()
121 );
122 $this->fail( 'Exception not thrown.' );
123 }
124
125 function tagCallback( $text, $params, $parser ) {
126 return str_rot13( $text );
127 }
128
129 function functionTagCallback( &$parser, $frame, $code, $attribs ) {
130 return str_rot13( $code );
131 }
132}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
MediaWikiServices is the service locator for the application scope of MediaWiki.
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
Definition Parser.php:68
Database Parser.
testBadFunctionTagHooks( $tag)
provideBadNames MWException
tagCallback( $text, $params, $parser)
static provideValidNames()
static provideBadNames()
functionTagCallback(&$parser, $frame, $code, $attribs)
testBadTagHooks( $tag)
provideBadNames MWException
testFunctionTagHooks( $tag)
provideValidNames
testTagHooks( $tag)
provideValidNames
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:47
see documentation in includes Linker php for Linker::makeImageLink or false for current used if you return false $parser
Definition hooks.txt:1873
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition hooks.txt:895
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:2063
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
$params