MediaWiki REL1_33
StripStateTest.php
Go to the documentation of this file.
1<?php
2
7 public function setUp() {
8 parent::setUp();
9 $this->setContentLang( 'qqx' );
10 }
11
12 private function getMarker() {
13 static $i;
14 return Parser::MARKER_PREFIX . '-blah-' . sprintf( '%08X', $i++ ) . Parser::MARKER_SUFFIX;
15 }
16
17 private static function getWarning( $message, $max = '' ) {
18 return "<span class=\"error\">($message: $max)</span>";
19 }
20
21 public function testAddNoWiki() {
22 $ss = new StripState;
23 $marker = $this->getMarker();
24 $ss->addNoWiki( $marker, '<>' );
25 $text = "x{$marker}y";
26 $text = $ss->unstripGeneral( $text );
27 $text = str_replace( '<', '', $text );
28 $text = $ss->unstripNoWiki( $text );
29 $this->assertSame( 'x<>y', $text );
30 }
31
32 public function testAddGeneral() {
33 $ss = new StripState;
34 $marker = $this->getMarker();
35 $ss->addGeneral( $marker, '<>' );
36 $text = "x{$marker}y";
37 $text = $ss->unstripNoWiki( $text );
38 $text = str_replace( '<', '', $text );
39 $text = $ss->unstripGeneral( $text );
40 $this->assertSame( 'x<>y', $text );
41 }
42
43 public function testUnstripBoth() {
44 $ss = new StripState;
45 $mk1 = $this->getMarker();
46 $mk2 = $this->getMarker();
47 $ss->addNoWiki( $mk1, '<1>' );
48 $ss->addGeneral( $mk2, '<2>' );
49 $text = "x{$mk1}{$mk2}y";
50 $text = str_replace( '<', '', $text );
51 $text = $ss->unstripBoth( $text );
52 $this->assertSame( 'x<1><2>y', $text );
53 }
54
55 public static function provideUnstripRecursive() {
56 return [
57 [ 0, 'text' ],
58 [ 1, '=text=' ],
59 [ 2, '==text==' ],
60 [ 3, '==' . self::getWarning( 'unstrip-depth-warning', 2 ) . '==' ],
61 ];
62 }
63
65 public function testUnstripRecursive( $depth, $expected ) {
66 $ss = new StripState( null, [ 'depthLimit' => 2 ] );
67 $text = 'text';
68 for ( $i = 0; $i < $depth; $i++ ) {
69 $mk = $this->getMarker();
70 $ss->addNoWiki( $mk, "={$text}=" );
71 $text = $mk;
72 }
73 $text = $ss->unstripNoWiki( $text );
74 $this->assertSame( $expected, $text );
75 }
76
77 public function testUnstripLoop() {
78 $ss = new StripState( null, [ 'depthLimit' => 2 ] );
79 $mk = $this->getMarker();
80 $ss->addNoWiki( $mk, $mk );
81 $text = $ss->unstripNoWiki( $mk );
82 $this->assertSame( self::getWarning( 'parser-unstrip-loop-warning' ), $text );
83 }
84
85 public static function provideUnstripSize() {
86 return [
87 [ 0, 'x' ],
88 [ 1, 'xx' ],
89 [ 2, str_repeat( self::getWarning( 'unstrip-size-warning', 5 ), 2 ) ]
90 ];
91 }
92
94 public function testUnstripSize( $depth, $expected ) {
95 $ss = new StripState( null, [ 'sizeLimit' => 5 ] );
96 $text = 'x';
97 for ( $i = 0; $i < $depth; $i++ ) {
98 $mk = $this->getMarker();
99 $ss->addNoWiki( $mk, $text );
100 $text = "$mk$mk";
101 }
102 $text = $ss->unstripNoWiki( $text );
103 $this->assertSame( $expected, $text );
104 }
105
106 public function provideGetLimitReport() {
107 for ( $i = 1; $i < 4; $i++ ) {
108 yield [ $i ];
109 }
110 }
111
113 public function testGetLimitReport( $depth ) {
114 $sizeLimit = 100000;
115 $ss = new StripState( null, [ 'depthLimit' => 5, 'sizeLimit' => $sizeLimit ] );
116 $text = 'x';
117 for ( $i = 0; $i < $depth; $i++ ) {
118 $mk = $this->getMarker();
119 $ss->addNoWiki( $mk, $text );
120 $text = "$mk$mk";
121 }
122 $text = $ss->unstripNoWiki( $text );
123 $report = $ss->getLimitReport();
124 $messages = [];
125 foreach ( $report as list( $msg, $params ) ) {
126 $messages[$msg] = $params;
127 }
128 $this->assertSame( [ $depth - 1, 5 ], $messages['limitreport-unstrip-depth'] );
129 $this->assertSame(
130 [
131 strlen( $this->getMarker() ) * 2 * ( pow( 2, $depth ) - 2 ) + pow( 2, $depth ),
132 $sizeLimit
133 ],
134 $messages['limitreport-unstrip-size' ] );
135 }
136}
$messages
testUnstripRecursive( $depth, $expected)
provideUnstripRecursive
testGetLimitReport( $depth)
provideGetLimitReport
static provideUnstripRecursive()
static provideUnstripSize()
testUnstripSize( $depth, $expected)
provideUnstripSize
static getWarning( $message, $max='')
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
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