MediaWiki  1.23.0
MagicVariableTest.php
Go to the documentation of this file.
1 <?php
19  private $testParser = null;
20 
28  private $expectedAsInteger = array(
29  'revisionday',
30  'revisionmonth1',
31  );
32 
34  protected function setUp() {
35  parent::setUp();
36 
37  $contLang = Language::factory( 'en' );
38  $this->setMwGlobals( array(
39  'wgLanguageCode' => 'en',
40  'wgContLang' => $contLang,
41  ) );
42 
43  $this->testParser = new Parser();
44  $this->testParser->Options( ParserOptions::newFromUserAndLang( new User, $contLang ) );
45 
46  # initialize parser output
47  $this->testParser->clearState();
48 
49  # Needs a title to do magic word stuff
50  $title = Title::newFromText( 'Tests' );
51  $title->mRedirect = false; # Else it needs a db connection just to check if it's a redirect (when deciding the page language)
52 
53  $this->testParser->setTitle( $title );
54  }
55 
60  private static function createProviderUpTo( $num ) {
61  $ret = array();
62  for ( $i = 1; $i <= $num; $i++ ) {
63  $ret[] = array( $i );
64  }
65 
66  return $ret;
67  }
68 
72  public static function provideMonths() {
73  return self::createProviderUpTo( 12 );
74  }
75 
79  public static function provideDays() {
80  return self::createProviderUpTo( 31 );
81  }
82 
83  ############### TESTS #############################################
84  # @todo FIXME:
85  # - those got copy pasted, we can probably make them cleaner
86  # - tests are lacking useful messages
87 
88  # day
89 
91  public function testCurrentdayIsUnPadded( $day ) {
92  $this->assertUnPadded( 'currentday', $day );
93  }
94 
96  public function testCurrentdaytwoIsZeroPadded( $day ) {
97  $this->assertZeroPadded( 'currentday2', $day );
98  }
99 
101  public function testLocaldayIsUnPadded( $day ) {
102  $this->assertUnPadded( 'localday', $day );
103  }
104 
106  public function testLocaldaytwoIsZeroPadded( $day ) {
107  $this->assertZeroPadded( 'localday2', $day );
108  }
109 
110  # month
111 
113  public function testCurrentmonthIsZeroPadded( $month ) {
114  $this->assertZeroPadded( 'currentmonth', $month );
115  }
116 
118  public function testCurrentmonthoneIsUnPadded( $month ) {
119  $this->assertUnPadded( 'currentmonth1', $month );
120  }
121 
123  public function testLocalmonthIsZeroPadded( $month ) {
124  $this->assertZeroPadded( 'localmonth', $month );
125  }
126 
128  public function testLocalmonthoneIsUnPadded( $month ) {
129  $this->assertUnPadded( 'localmonth1', $month );
130  }
131 
132  # revision day
133 
135  public function testRevisiondayIsUnPadded( $day ) {
136  $this->assertUnPadded( 'revisionday', $day );
137  }
138 
140  public function testRevisiondaytwoIsZeroPadded( $day ) {
141  $this->assertZeroPadded( 'revisionday2', $day );
142  }
143 
144  # revision month
145 
147  public function testRevisionmonthIsZeroPadded( $month ) {
148  $this->assertZeroPadded( 'revisionmonth', $month );
149  }
150 
152  public function testRevisionmonthoneIsUnPadded( $month ) {
153  $this->assertUnPadded( 'revisionmonth1', $month );
154  }
155 
162  public function testServernameFromDifferentProtocols( $server ) {
163  $this->setMwGlobals( 'wgServer', $server );
164 
165  $this->assertMagic( 'localhost', 'servername' );
166  }
167 
168  public static function provideDataServernameFromDifferentProtocols() {
169  return array(
170  array( 'http://localhost/' ),
171  array( 'https://localhost/' ),
172  array( '//localhost/' ), # bug 31176
173  );
174  }
175 
176  ############### HELPERS ############################################
177 
179  public function assertZeroPadded( $magic, $value ) {
180  $this->assertMagicPadding( $magic, $value, '%02d' );
181  }
182 
184  public function assertUnPadded( $magic, $value ) {
185  $this->assertMagicPadding( $magic, $value, '%d' );
186  }
187 
194  private function assertMagicPadding( $magic, $value, $format ) {
195  # Initialize parser timestamp as year 2010 at 12h34 56s.
196  # month and day are given by the caller ($value). Month < 12!
197  if ( $value > 12 ) {
198  $month = $value % 12;
199  } else {
200  $month = $value;
201  }
202 
203  $this->setParserTS(
204  sprintf( '2010%02d%02d123456', $month, $value )
205  );
206 
207  # please keep the following commented line of code. It helps debugging.
208  //print "\nDEBUG (value $value):" . sprintf( '2010%02d%02d123456', $value, $value ) . "\n";
209 
210  # format expectation and test it
211  $expected = sprintf( $format, $value );
212  $this->assertMagic( $expected, $magic );
213  }
214 
216  private function setParserTS( $ts ) {
217  $this->testParser->Options()->setTimestamp( $ts );
218  $this->testParser->mRevisionTimestamp = $ts;
219  }
220 
224  private function assertMagic( $expected, $magic ) {
225  if ( in_array( $magic, $this->expectedAsInteger ) ) {
226  $expected = (int)$expected;
227  }
228 
229  # Generate a message for the assertion
230  $msg = sprintf( "Magic %s should be <%s:%s>",
231  $magic,
232  $expected,
233  gettype( $expected )
234  );
235 
236  $this->assertSame(
237  $expected,
238  $this->testParser->getVariableValue( $magic ),
239  $msg
240  );
241  }
242 }
check
in this case you re responsible for computing and outputting the entire conflict i the difference between revisions and your text headers and sections and Diff overridable Default is either copyrightwarning or copyrightwarning2 overridable Default is editpage tos summary such as anonymity and the real check
Definition: hooks.txt:1038
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
MagicVariableTest\assertZeroPadded
assertZeroPadded( $magic, $value)
assertion helper expecting a magic output which is zero padded
Definition: MagicVariableTest.php:178
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
MagicVariableTest\setParserTS
setParserTS( $ts)
helper to set the parser timestamp and revision timestamp
Definition: MagicVariableTest.php:215
MagicVariableTest\$testParser
Parser $testParser
Definition: MagicVariableTest.php:18
MagicVariableTest\$expectedAsInteger
$expectedAsInteger
An array of magicword returned as type integer by the parser They are usually returned as a string fo...
Definition: MagicVariableTest.php:27
ParserOptions\newFromUserAndLang
static newFromUserAndLang(User $user, Language $lang)
Get a ParserOptions object from a given user and language.
Definition: ParserOptions.php:386
MagicVariableTest\assertMagic
assertMagic( $expected, $magic)
Assertion helper to test a magic variable output.
Definition: MagicVariableTest.php:223
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
MagicVariableTest\setUp
setUp()
setup a basic parser object
Definition: MagicVariableTest.php:33
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
$value
$value
Definition: styleTest.css.php:45
MagicVariableTest
Definition: MagicVariableTest.php:15
MagicVariableTest\assertMagicPadding
assertMagicPadding( $magic, $value, $format)
Main assertion helper for magic variables padding.
Definition: MagicVariableTest.php:193
it
=Architecture==Two class hierarchies are used to provide the functionality associated with the different content models:*Content interface(and AbstractContent base class) define functionality that acts on the concrete content of a page, and *ContentHandler base class provides functionality specific to a content model, but not acting on concrete content. The most important function of ContentHandler is to act as a factory for the appropriate implementation of Content. These Content objects are to be used by MediaWiki everywhere, instead of passing page content around as text. All manipulation and analysis of page content must be done via the appropriate methods of the Content object. For each content model, a subclass of ContentHandler has to be registered with $wgContentHandlers. The ContentHandler object for a given content model can be obtained using ContentHandler::getForModelID($id). Also Title, WikiPage and Revision now have getContentHandler() methods for convenience. ContentHandler objects are singletons that provide functionality specific to the content type, but not directly acting on the content of some page. ContentHandler::makeEmptyContent() and ContentHandler::unserializeContent() can be used to create a Content object of the appropriate type. However, it is recommended to instead use WikiPage::getContent() resp. Revision::getContent() to get a page 's content as a Content object. These two methods should be the ONLY way in which page content is accessed. Another important function of ContentHandler objects is to define custom action handlers for a content model, see ContentHandler::getActionOverrides(). This is similar to what WikiPage::getActionOverrides() was already doing.==Serialization==With the ContentHandler facility, page content no longer has to be text based. Objects implementing the Content interface are used to represent and handle the content internally. For storage and data exchange, each content model supports at least one serialization format via ContentHandler::serializeContent($content). The list of supported formats for a given content model can be accessed using ContentHandler::getSupportedFormats(). Content serialization formats are identified using MIME type like strings. The following formats are built in:*text/x-wiki - wikitext *text/javascript - for js pages *text/css - for css pages *text/plain - for future use, e.g. with plain text messages. *text/html - for future use, e.g. with plain html messages. *application/vnd.php.serialized - for future use with the api and for extensions *application/json - for future use with the api, and for use by extensions *application/xml - for future use with the api, and for use by extensions In PHP, use the corresponding CONTENT_FORMAT_XXX constant. Note that when using the API to access page content, especially action=edit, action=parse and action=query &prop=revisions, the model and format of the content should always be handled explicitly. Without that information, interpretation of the provided content is not reliable. The same applies to XML dumps generated via maintenance/dumpBackup.php or Special:Export. Also note that the API will provide encapsulated, serialized content - so if the API was called with format=json, and contentformat is also json(or rather, application/json), the page content is represented as a string containing an escaped json structure. Extensions that use JSON to serialize some types of page content may provide specialized API modules that allow access to that content in a more natural form.==Compatibility==The ContentHandler facility is introduced in a way that should allow all existing code to keep functioning at least for pages that contain wikitext or other text based content. However, a number of functions and hooks have been deprecated in favor of new versions that are aware of the page 's content model, and will now generate warnings when used. Most importantly, the following functions have been deprecated:*Revisions::getText() and Revisions::getRawText() is deprecated in favor Revisions::getContent() *WikiPage::getText() is deprecated in favor WikiPage::getContent() Also, the old Article::getContent()(which returns text) is superceded by Article::getContentObject(). However, both methods should be avoided since they do not provide clean access to the page 's actual content. For instance, they may return a system message for non-existing pages. Use WikiPage::getContent() instead. Code that relies on a textual representation of the page content should eventually be rewritten. However, ContentHandler::getContentText() provides a stop-gap that can be used to get text for a page. Its behavior is controlled by $wgContentHandlerTextFallback it
Definition: contenthandler.txt:107
connection
you have access to all of the normal MediaWiki so you can get a DB connection
Definition: maintenance.txt:52
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:184
MagicVariableTest\assertUnPadded
assertUnPadded( $magic, $value)
assertion helper expecting a magic output which is unpadded
Definition: MagicVariableTest.php:183
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59