Added "maxPartitionsTry" option to JobQueueFederated
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / ParserMethodsTest.php
1 <?php
2
3 class ParserMethodsTest extends MediaWikiLangTestCase {
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
16 /**
17 * @dataProvider providePreSaveTransform
18 */
19 public function testPreSaveTransform( $text, $expected ) {
20 global $wgParser;
21
22 $title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) );
23 $user = new User();
24 $user->setName( "127.0.0.1" );
25 $popts = ParserOptions::newFromUser( $user );
26 $text = $wgParser->preSaveTransform( $text, $title, $user, $popts );
27
28 $this->assertEquals( $expected, $text );
29 }
30
31 public function testCallParserFunction() {
32 global $wgParser;
33
34 // Normal parses test passing PPNodes. Test passing an array.
35 $title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) );
36 $wgParser->startExternalParse( $title, new ParserOptions(), Parser::OT_HTML );
37 $frame = $wgParser->getPreprocessor()->newFrame();
38 $ret = $wgParser->callParserFunction( $frame, '#tag',
39 array( 'pre', 'foo', 'style' => 'margin-left: 1.6em' )
40 );
41 $ret['text'] = $wgParser->mStripState->unstripBoth( $ret['text'] );
42 $this->assertSame( array(
43 'found' => true,
44 'text' => '<pre style="margin-left: 1.6em">foo</pre>',
45 ), $ret, 'callParserFunction works for {{#tag:pre|foo|style=margin-left: 1.6em}}' );
46 }
47
48 public function testGetSections() {
49 global $wgParser;
50
51 $title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) );
52 $out = $wgParser->parse( "==foo==\n<h2>bar</h2>\n==baz==\n", $title, new ParserOptions() );
53 $this->assertSame( array(
54 array(
55 'toclevel' => 1,
56 'level' => '2',
57 'line' => 'foo',
58 'number' => '1',
59 'index' => '1',
60 'fromtitle' => $title->getPrefixedDBkey(),
61 'byteoffset' => 0,
62 'anchor' => 'foo',
63 ),
64 array(
65 'toclevel' => 1,
66 'level' => '2',
67 'line' => 'bar',
68 'number' => '2',
69 'index' => '',
70 'fromtitle' => false,
71 'byteoffset' => null,
72 'anchor' => 'bar',
73 ),
74 array(
75 'toclevel' => 1,
76 'level' => '2',
77 'line' => 'baz',
78 'number' => '3',
79 'index' => '2',
80 'fromtitle' => $title->getPrefixedDBkey(),
81 'byteoffset' => 21,
82 'anchor' => 'baz',
83 ),
84 ), $out->getSections(), 'getSections() with proper value when <h2> is used' );
85 }
86 // TODO: Add tests for cleanSig() / cleanSigInSig(), getSection(), replaceSection(), getPreloadText()
87 }