MediaWiki  1.23.2
ParserMethodsTest.php
Go to the documentation of this file.
1 <?php
2 
4 
5  public static function providePreSaveTransform() {
6  return array(
7  array( 'hello this is ~~~',
8  "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
9  ),
10  array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
11  'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
12  ),
13  );
14  }
15 
20  public function testPreSaveTransform( $text, $expected ) {
22 
23  $title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) );
24  $user = new User();
25  $user->setName( "127.0.0.1" );
27  $text = $wgParser->preSaveTransform( $text, $title, $user, $popts );
28 
29  $this->assertEquals( $expected, $text );
30  }
31 
35  public function testCallParserFunction() {
37 
38  // Normal parses test passing PPNodes. Test passing an array.
39  $title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) );
40  $wgParser->startExternalParse( $title, new ParserOptions(), Parser::OT_HTML );
41  $frame = $wgParser->getPreprocessor()->newFrame();
42  $ret = $wgParser->callParserFunction( $frame, '#tag',
43  array( 'pre', 'foo', 'style' => 'margin-left: 1.6em' )
44  );
45  $ret['text'] = $wgParser->mStripState->unstripBoth( $ret['text'] );
46  $this->assertSame( array(
47  'found' => true,
48  'text' => '<pre style="margin-left: 1.6em">foo</pre>',
49  ), $ret, 'callParserFunction works for {{#tag:pre|foo|style=margin-left: 1.6em}}' );
50  }
51 
56  public function testGetSections() {
58 
59  $title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) );
60  $out = $wgParser->parse( "==foo==\n<h2>bar</h2>\n==baz==\n", $title, new ParserOptions() );
61  $this->assertSame( array(
62  array(
63  'toclevel' => 1,
64  'level' => '2',
65  'line' => 'foo',
66  'number' => '1',
67  'index' => '1',
68  'fromtitle' => $title->getPrefixedDBkey(),
69  'byteoffset' => 0,
70  'anchor' => 'foo',
71  ),
72  array(
73  'toclevel' => 1,
74  'level' => '2',
75  'line' => 'bar',
76  'number' => '2',
77  'index' => '',
78  'fromtitle' => false,
79  'byteoffset' => null,
80  'anchor' => 'bar',
81  ),
82  array(
83  'toclevel' => 1,
84  'level' => '2',
85  'line' => 'baz',
86  'number' => '3',
87  'index' => '2',
88  'fromtitle' => $title->getPrefixedDBkey(),
89  'byteoffset' => 21,
90  'anchor' => 'baz',
91  ),
92  ), $out->getSections(), 'getSections() with proper value when <h2> is used' );
93  }
94  //@Todo Add tests for cleanSig() / cleanSigInSig(), getSection(), replaceSection(), getPreloadText()
95 }
ParserOptions
Set options of the Parser.
Definition: ParserOptions.php:31
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
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
$ret
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 & $ret
Definition: hooks.txt:1530
ParserMethodsTest\providePreSaveTransform
static providePreSaveTransform()
Definition: ParserMethodsTest.php:5
$out
$out
Definition: UtfNormalGenerate.php:167
ParserMethodsTest
Definition: ParserMethodsTest.php:3
ParserMethodsTest\testPreSaveTransform
testPreSaveTransform( $text, $expected)
@dataProvider providePreSaveTransform @covers Parser::preSaveTransform
Definition: ParserMethodsTest.php:20
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ParserMethodsTest\testCallParserFunction
testCallParserFunction()
@covers Parser::callParserFunction
Definition: ParserMethodsTest.php:35
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:6
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
OT_HTML
const OT_HTML
Definition: Defines.php:230
$wgParser
$wgParser
Definition: Setup.php:567
User
User
Definition: All_system_messages.txt:425
ParserMethodsTest\testGetSections
testGetSections()
@covers Parser::parse @covers ParserOutput::getSections
Definition: ParserMethodsTest.php:56
ParserOptions\newFromUser
static newFromUser( $user)
Get a ParserOptions object from a given user.
Definition: ParserOptions.php:375