r77539 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77538‎ | r77539 | r77540 >
Date:21:16, 1 December 2010
Author:mah
Status:deferred
Tags:
Comment:
* w/s fixup explosion for tests (aka “my OCD takes over”)
* “svn diff -x-w” shows no changes
Modified paths:
  • /trunk/phase3/maintenance/tests/parserTests.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/GlobalTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/IPTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/ParserOptionsTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/SeleniumConfigurationTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/SiteConfigurationTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/TitlePermissionTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/UploadFromUrlTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/XmlTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/api/ApiSetup.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/api/ApiTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/api/ApiUploadTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/api/ApiWatchTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/api/RandomImageGenerator.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/api/generateRandomImages.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/db/DatabaseSqliteTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/search/SearchDbTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/search/SearchEngineTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/Selenium.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/SeleniumConfig.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/SeleniumServerManager.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/SeleniumTestSuite.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestSuite.php
@@ -11,7 +11,7 @@
1212 const RESULT_ERROR = 3;
1313
1414 public abstract function addTests();
15 -
 15+
1616 public function setUp() {
1717 // Hack because because PHPUnit version 3.0.6 which is on prototype does not
1818 // run setUp as part of TestSuite::run
@@ -39,7 +39,7 @@
4040 public function loadPage( $title, $action ) {
4141 $this->selenium->loadPage( $title, $action );
4242 }
43 -
 43+
4444 protected function setLoginBeforeTests( $loginBeforeTests = true ) {
4545 $this->loginBeforeTests = $loginBeforeTests;
4646 }
Index: trunk/phase3/maintenance/tests/selenium/Selenium.php
@@ -41,7 +41,7 @@
4242 self::$_instance = $this;
4343 } else {
4444 throw new MWException( "Already have one Selenium instance." );
45 - }
 45+ }
4646 }
4747
4848 public function start() {
@@ -62,7 +62,7 @@
6363 public function login() {
6464 if ( strlen( $this->user ) == 0 ) {
6565 return;
66 - }
 66+ }
6767 $this->open( self::$url . '/index.php?title=Special:Userlogin' );
6868 $this->type( 'wpName1', $this->user );
6969 $this->type( 'wpPassword1', $this->pass );
@@ -133,7 +133,7 @@
134134 public function setVerbose( $verbose ) {
135135 $this->verbose = $verbose;
136136 }
137 -
 137+
138138 public function setAvailableBrowsers( $availableBrowsers ) {
139139 $this->browsers = $availableBrowsers;
140140 }
@@ -141,15 +141,15 @@
142142 public function setJUnitLogfile( $junitlogfile ) {
143143 $this->junitlogfile = $junitlogfile;
144144 }
145 -
 145+
146146 public function getJUnitLogfile( ) {
147147 return $this->junitlogfile;
148 - }
149 -
 148+ }
 149+
150150 public function setRunAgainstGrid( $runagainstgrid ) {
151151 $this->runagainstgrid = $runagainstgrid;
152152 }
153 -
 153+
154154 public function setBrowser( $b ) {
155155 if ($this->runagainstgrid) {
156156 $this->browser = $b;
@@ -161,7 +161,7 @@
162162
163163 $this->browser = $this->browsers[$b];
164164 }
165 -
 165+
166166 public function getAvailableBrowsers() {
167167 return $this->browsers;
168168 }
Index: trunk/phase3/maintenance/tests/selenium/SeleniumServerManager.php
@@ -34,8 +34,8 @@
3535 private $SeleniumServerExecPath;
3636
3737 public function __construct( $startServer,
38 - $serverPort,
39 - $serverExecPath ) {
 38+ $serverPort,
 39+ $serverExecPath ) {
4040 $this->OS = (string) PHP_OS;
4141 if ( isset( $startServer ) )
4242 $this->SeleniumStartServer = $startServer;
@@ -172,11 +172,11 @@
173173
174174 $commandSuffix = ' > /dev/null 2>&1'. ' & echo $!';
175175 $portText = ' -port ' . $this->SeleniumServerPort;
176 - $command = "java -jar " .
 176+ $command = "java -jar " .
177177 escapeshellarg($this->SeleniumServerExecPath) .
178178 $portText . $commandSuffix;
179 - exec($command ,$op);
180 - $pid = (int)$op[0];
 179+ exec($command ,$op);
 180+ $pid = (int)$op[0];
181181 if ( $pid != "" )
182182 $this->SeleniumServerPid = $pid;
183183 else {
@@ -190,8 +190,8 @@
191191
192192 wfSuppressWarnings();
193193 for ( $cnt = 1;
194 - $cnt <= $this->SeleniumServerStartTimeout;
195 - $cnt++ ) {
 194+ $cnt <= $this->SeleniumServerStartTimeout;
 195+ $cnt++ ) {
196196 $fp = fsockopen ( 'localhost',
197197 $this->SeleniumServerPort,
198198 $errno, $errstr, 0 );
@@ -212,19 +212,19 @@
213213 else return 'running';
214214
215215 }
216 - // No Server execution path defined.
 216+ // No Server execution path defined.
217217 return 'failed';
218218 }
219219
220220 private function startServerOnWindows() {
221 - // Unimplemented.
 221+ // Unimplemented.
222222 return 'failed';
223223 }
224224
225225 private function stopServerOnUnix() {
226226
227227 if ( !empty( $this->SeleniumServerPid ) &&
228 - $this->SeleniumServerPid != 'NaN' ) {
 228+ $this->SeleniumServerPid != 'NaN' ) {
229229 exec( "kill -9 " . $this->SeleniumServerPid );
230230 return 'stopped';
231231 }
@@ -232,7 +232,7 @@
233233 }
234234
235235 private function stopServerOnWindows() {
236 - // Unimplemented.
 236+ // Unimplemented.
237237 return 'failed';
238238
239239 }
Index: trunk/phase3/maintenance/tests/selenium/SeleniumConfig.php
@@ -4,16 +4,16 @@
55 }
66
77 class SeleniumConfig {
8 -
 8+
99 /*
1010 * Retreives the Selenium configuration values from an ini file.
1111 * See sample config file in selenium_settings.ini.sample
12 - *
 12+ *
1313 */
1414
15 - public static function getSeleniumSettings ( &$seleniumSettings,
16 - &$seleniumBrowsers,
17 - &$seleniumTestSuites,
 15+ public static function getSeleniumSettings ( &$seleniumSettings,
 16+ &$seleniumBrowsers,
 17+ &$seleniumTestSuites,
1818 $seleniumConfigFile = null ) {
1919 if ( strlen( $seleniumConfigFile ) == 0 ) {
2020 global $wgSeleniumConfigFile;
@@ -23,7 +23,7 @@
2424 if ( strlen( $seleniumConfigFile ) == 0 || !file_exists( $seleniumConfigFile ) ) {
2525 throw new MWException( "Unable to read local Selenium Settings from " . $seleniumConfigFile . "\n" );
2626 }
27 -
 27+
2828 if ( !defined( 'PHP_VERSION_ID' ) ||
2929 ( PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3 ) ) {
3030 $configArray = self::parse_5_2_ini_file( $seleniumConfigFile );
@@ -38,7 +38,7 @@
3939 wfSuppressWarnings();
4040 //we may need to change how this is set. But for now leave it in the ini file
4141 $seleniumBrowsers = $configArray['SeleniumSettings']['browsers'];
42 -
 42+
4343 $seleniumSettings['host'] = $configArray['SeleniumSettings']['host'];
4444 $seleniumSettings['port'] = $configArray['SeleniumSettings']['port'];
4545 $seleniumSettings['wikiUrl'] = $configArray['SeleniumSettings']['wikiUrl'];
@@ -58,7 +58,7 @@
5959 $seleniumTestSuites = $configArray['SeleniumTests']['testSuite'];
6060 wfRestoreWarnings();
6161 }
62 - return true;
 62+ return true;
6363 }
6464
6565 private static function parse_5_2_ini_file ( $ConfigFile ) {
Index: trunk/phase3/maintenance/tests/parserTests.php
@@ -30,7 +30,7 @@
3131 require_once( dirname( __FILE__ ) . '/../commandLine.inc' );
3232
3333 if ( isset( $options['help'] ) ) {
34 - echo <<<ENDS
 34+ echo <<<ENDS
3535 MediaWiki $wgVersion parser test suite
3636 Usage: php parserTests.php [options...]
3737
@@ -39,7 +39,7 @@
4040 --quiet Suppress notification of passed tests (shows only failed tests)
4141 --show-output Show expected and actual output
4242 --color[=yes|no] Override terminal detection and force color output on or off
43 - use wgCommandLineDarkBg = true; if your term is dark
 43+ use wgCommandLineDarkBg = true; if your term is dark
4444 --regex Only run tests whose descriptions which match given regex
4545 --file=<testfile> Run test cases from a custom file instead of parserTests.txt
4646 --record Record tests in database
@@ -54,7 +54,7 @@
5555 --upload Upload test results to remote wiki (per \$wgParserTestRemote)
5656
5757 ENDS;
58 - exit( 0 );
 58+ exit( 0 );
5959 }
6060
6161 # Cases of weird db corruption were encountered when running tests on earlyish
Index: trunk/phase3/maintenance/tests/phpunit/includes/TitlePermissionTest.php
@@ -273,7 +273,7 @@
274274 '' => array( array( ), array( ), array( ), true ) );
275275 global $wgUser;
276276 $wgUser = self::$user;
277 - foreach ( array( "edit", "protect", "" ) as $action ) {
 277+ foreach ( array( "edit", "protect", "" ) as $action ) {
278278 $this->setUserPerm( null );
279279 $this->assertEquals( $check[$action][0],
280280 self::$title->getUserPermissionsErrors( $action, self::$user, true ) );
Index: trunk/phase3/maintenance/tests/phpunit/includes/UploadFromUrlTest.php
@@ -19,7 +19,7 @@
2020 ini_set( 'log_errors', 1 );
2121 ini_set( 'error_reporting', 1 );
2222 ini_set( 'display_errors', 1 );
23 -
 23+
2424 if ( wfLocalFile( 'UploadFromUrlTest.png' )->exists() ) {
2525 $this->deleteFile( 'UploadFromUrlTest.png' );
2626 }
@@ -28,7 +28,7 @@
2929 protected function doApiRequest( $params, $unused = null ) {
3030 $sessionId = session_id();
3131 session_write_close();
32 -
 32+
3333 $req = new FauxRequest( $params, true, $_SESSION );
3434 $module = new ApiMain( $req, true );
3535 $module->execute();
@@ -77,7 +77,7 @@
7878 * @depends testLogin
7979 * @depends testClearQueue
8080 */
81 - public function testSetupUrlDownload( $data ) {
 81+ public function testSetupUrlDownload( $data ) {
8282 $token = self::$user->editToken();
8383 $exception = false;
8484
@@ -142,7 +142,7 @@
143143 ), $data );
144144
145145 $this->assertEquals( $data[0]['upload']['result'], 'Queued', 'Queued upload' );
146 -
 146+
147147 $job = Job::pop();
148148 $this->assertThat( $job, $this->isInstanceOf( 'UploadFromUrlJob' ), 'Queued upload inserted' );
149149 }
@@ -160,7 +160,7 @@
161161 $this->assertEquals( $data[0]['upload']['result'], 'Success' );
162162 $this->assertEquals( $data[0]['upload']['filename'], 'UploadFromUrlTest.png' );
163163 $this->assertTrue( wfLocalFile( $data[0]['upload']['filename'] )->exists() );
164 -
 164+
165165 $this->deleteFile( 'UploadFromUrlTest.png' );
166166
167167 return $data;
@@ -177,11 +177,11 @@
178178
179179
180180 $data = $this->doAsyncUpload( $token );
181 -
 181+
182182 $this->assertEquals( $data[0]['upload']['result'], 'Warning' );
183183 $this->assertTrue( isset( $data[0]['upload']['sessionkey'] ) );
184 -
185 - $data = $this->doApiRequest( array(
 184+
 185+ $data = $this->doApiRequest( array(
186186 'action' => 'upload',
187187 'sessionkey' => $data[0]['upload']['sessionkey'],
188188 'filename' => 'UploadFromUrlTest.png',
@@ -191,7 +191,7 @@
192192 $this->assertEquals( $data[0]['upload']['result'], 'Success' );
193193 $this->assertEquals( $data[0]['upload']['filename'], 'UploadFromUrlTest.png' );
194194 $this->assertTrue( wfLocalFile( $data[0]['upload']['filename'] )->exists() );
195 -
 195+
196196 $this->deleteFile( 'UploadFromUrlTest.png' );
197197
198198 return $data;
@@ -224,18 +224,18 @@
225225
226226 return $data;
227227 }
228 -
 228+
229229 public function testLeaveMessage() {
230230 $token = self::$user->editToken();
231 -
 231+
232232 $talk = self::$user->getTalkPage();
233233 if ( $talk->exists() ) {
234234 $a = new Article( $talk );
235235 $a->doDeleteArticle( '' );
236236 }
237 -
 237+
238238 $this->assertFalse( (bool)$talk->getArticleId( Title::GAID_FOR_UPDATE ), 'User talk does not exist' );
239 -
 239+
240240 $data = $this->doApiRequest( array(
241241 'action' => 'upload',
242242 'filename' => 'UploadFromUrlTest.png',
@@ -245,19 +245,19 @@
246246 'leavemessage' => 1,
247247 'ignorewarnings' => 1,
248248 ) );
249 -
 249+
250250 $job = Job::pop();
251251 $this->assertEquals( 'UploadFromUrlJob', get_class( $job ) );
252252 $job->run();
253 -
254 - $this->assertTrue( wfLocalFile( 'UploadFromUrlTest.png' )->exists() );
 253+
 254+ $this->assertTrue( wfLocalFile( 'UploadFromUrlTest.png' )->exists() );
255255 $this->assertTrue( (bool)$talk->getArticleId( Title::GAID_FOR_UPDATE ), 'User talk exists' );
256 -
 256+
257257 $this->deleteFile( 'UploadFromUrlTest.png' );
258 -
 258+
259259 $talkRev = Revision::newFromTitle( $talk );
260260 $talkSize = $talkRev->getSize();
261 -
 261+
262262 $exception = false;
263263 try {
264264 $data = $this->doApiRequest( array(
@@ -273,27 +273,27 @@
274274 $this->assertEquals( 'Using leavemessage without ignorewarnings is not supported', $e->getMessage() );
275275 }
276276 $this->assertTrue( $exception );
277 -
 277+
278278 $job = Job::pop();
279279 $this->assertFalse( $job );
280 -
 280+
281281 return;
282282
283283 /**
284284 // Broken until using leavemessage with ignorewarnings is supported
285285 $job->run();
286 -
 286+
287287 $this->assertFalse( wfLocalFile( 'UploadFromUrlTest.png' )->exists() );
288 -
 288+
289289 $talkRev = Revision::newFromTitle( $talk );
290290 $this->assertTrue( $talkRev->getSize() > $talkSize, 'New message left' );
291291 */
292292 }
293 -
 293+
294294 /**
295 - * Helper function to perform an async upload, execute the job and fetch
 295+ * Helper function to perform an async upload, execute the job and fetch
296296 * the status
297 - *
 297+ *
298298 * @return array The result of action=upload&statuskey=key
299299 */
300300 private function doAsyncUpload( $token, $ignoreWarnings = false, $leaveMessage = false ) {
@@ -310,28 +310,28 @@
311311 if ( $leaveMessage ) {
312312 $params['leavemessage'] = 1;
313313 }
314 -
 314+
315315 $data = $this->doApiRequest( $params );
316316 $this->assertEquals( $data[0]['upload']['result'], 'Queued' );
317317 $this->assertTrue( isset( $data[0]['upload']['statuskey'] ) );
318318 $statusKey = $data[0]['upload']['statuskey'];
319 -
 319+
320320 $job = Job::pop();
321321 $this->assertEquals( 'UploadFromUrlJob', get_class( $job ) );
322 -
323 - $status = $job->run();
 322+
 323+ $status = $job->run();
324324 $this->assertTrue( $status );
325 -
326 - $data = $this->doApiRequest( array(
 325+
 326+ $data = $this->doApiRequest( array(
327327 'action' => 'upload',
328328 'statuskey' => $statusKey,
329329 'token' => $token,
330330 ) );
331 -
 331+
332332 return $data;
333333 }
334 -
335334
 335+
336336 /**
337337 *
338338 */
Index: trunk/phase3/maintenance/tests/phpunit/includes/SiteConfigurationTest.php
@@ -287,7 +287,7 @@
288288 'get(): parameter replacement on an non-existing wiki'
289289 );
290290 }
291 -
 291+
292292 function testGetAll() {
293293 $this->mConf->siteParamsCallback = 'getSiteParams';
294294
Index: trunk/phase3/maintenance/tests/phpunit/includes/db/DatabaseSqliteTest.php
@@ -65,7 +65,7 @@
6666 $this->replaceVars( "ALTER TABLE foo\nADD COLUMN foo_bar int(10) unsigned DEFAULT 42" )
6767 );
6868 }
69 -
 69+
7070 public function testTableName() {
7171 // @todo Moar!
7272 $db = new DatabaseSqliteStandalone( ':memory:' );
Index: trunk/phase3/maintenance/tests/phpunit/includes/XmlTest.php
@@ -115,7 +115,7 @@
116116 );
117117 $this->assertEquals(
118118 '<label for="id" class="nice">name</label>',
119 - Xml::label( 'name', 'id', array(
 119+ Xml::label( 'name', 'id', array(
120120 'generated' => true,
121121 'class' => 'nice',
122122 'anotherattr' => 'value',
Index: trunk/phase3/maintenance/tests/phpunit/includes/GlobalTest.php
@@ -8,7 +8,7 @@
99 unlink( $wgReadOnlyFile );
1010 $wgContLang = $wgLang = Language::factory( 'en' );
1111 }
12 -
 12+
1313 function tearDown() {
1414 global $wgReadOnlyFile;
1515 if ( file_exists( $wgReadOnlyFile ) ) {
@@ -16,7 +16,7 @@
1717 }
1818 $wgReadOnlyFile = $this->originals['wgReadOnlyFile'];
1919 }
20 -
 20+
2121 function testRandom() {
2222 # This could hypothetically fail, but it shouldn't ;)
2323 $this->assertFalse(
@@ -32,25 +32,25 @@
3333 function testReadOnlyEmpty() {
3434 global $wgReadOnly;
3535 $wgReadOnly = null;
36 -
 36+
3737 $this->assertFalse( wfReadOnly() );
3838 $this->assertFalse( wfReadOnly() );
3939 }
4040
4141 function testReadOnlySet() {
4242 global $wgReadOnly, $wgReadOnlyFile;
43 -
 43+
4444 $f = fopen( $wgReadOnlyFile, "wt" );
4545 fwrite( $f, 'Message' );
4646 fclose( $f );
4747 $wgReadOnly = null;
48 -
 48+
4949 $this->assertTrue( wfReadOnly() );
5050 $this->assertTrue( wfReadOnly() );
5151
5252 unlink( $wgReadOnlyFile );
5353 $wgReadOnly = null;
54 -
 54+
5555 $this->assertFalse( wfReadOnly() );
5656 $this->assertFalse( wfReadOnly() );
5757 }
@@ -195,53 +195,53 @@
196196 '20010115T123456Z',
197197 wfTimestamp( TS_ISO_8601_BASIC, '2001-01-15 12:34:56' ),
198198 'TS_DB to TS_ISO_8601_BASIC' );
199 -
 199+
200200 # rfc2822 section 3.3
201 -
 201+
202202 $this->assertEquals(
203203 'Mon, 15 Jan 2001 12:34:56 GMT',
204204 wfTimestamp( TS_RFC2822, '20010115123456' ),
205205 'TS_MW to TS_RFC2822' );
206 -
 206+
207207 $this->assertEquals(
208208 '20010115123456',
209209 wfTimestamp( TS_MW, 'Mon, 15 Jan 2001 12:34:56 GMT' ),
210210 'TS_RFC2822 to TS_MW' );
211 -
 211+
212212 $this->assertEquals(
213213 '20010115123456',
214214 wfTimestamp( TS_MW, ' Mon, 15 Jan 2001 12:34:56 GMT' ),
215215 'TS_RFC2822 with leading space to TS_MW' );
216 -
 216+
217217 $this->assertEquals(
218218 '20010115123456',
219219 wfTimestamp( TS_MW, '15 Jan 2001 12:34:56 GMT' ),
220220 'TS_RFC2822 without optional day-of-week to TS_MW' );
221 -
 221+
222222 # FWS = ([*WSP CRLF] 1*WSP) / obs-FWS ; Folding white space
223 - # obs-FWS = 1*WSP *(CRLF 1*WSP) ; Section 4.2
 223+ # obs-FWS = 1*WSP *(CRLF 1*WSP) ; Section 4.2
224224 $this->assertEquals(
225225 '20010115123456',
226226 wfTimestamp( TS_MW, 'Mon, 15 Jan 2001 12:34:56 GMT' ),
227227 'TS_RFC2822 to TS_MW' );
228 -
 228+
229229 # WSP = SP / HTAB ; rfc2234
230230 $this->assertEquals(
231231 '20010115123456',
232232 wfTimestamp( TS_MW, "Mon, 15 Jan\x092001 12:34:56 GMT" ),
233233 'TS_RFC2822 with HTAB to TS_MW' );
234 -
 234+
235235 $this->assertEquals(
236236 '20010115123456',
237237 wfTimestamp( TS_MW, "Mon, 15 Jan\x09 \x09 2001 12:34:56 GMT" ),
238238 'TS_RFC2822 with HTAB and SP to TS_MW' );
239 -
 239+
240240 $this->assertEquals(
241241 '19941106084937',
242242 wfTimestamp( TS_MW, "Sun, 6 Nov 94 08:49:37 GMT" ),
243243 'TS_RFC2822 with obsolete year to TS_MW' );
244244 }
245 -
 245+
246246 /**
247247 * This test checks wfTimestamp() with values outside.
248248 * It needs PHP 64 bits or PHP > 5.1.
@@ -310,8 +310,8 @@
311311 wfTimestamp( TS_RFC2822, '-62135596800'),
312312 'Year 1');
313313
314 - /* It is not clear if we should generate a year 0 or not
315 - * We are completely off RFC2822 requirement of year being
 314+ /* It is not clear if we should generate a year 0 or not
 315+ * We are completely off RFC2822 requirement of year being
316316 * 1900 or later.
317317 */
318318 $this->assertEquals( 'Wed, 18 Oct 0000 00:00:00 GMT',
@@ -320,32 +320,32 @@
321321 }
322322
323323 function testHttpDate() {
324 - # The Resource Loader uses wfTimestamp() to convert timestamps
 324+ # The Resource Loader uses wfTimestamp() to convert timestamps
325325 # from If-Modified-Since header.
326326 # Thus it must be able to parse all rfc2616 date formats
327327 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
328 -
 328+
329329 $this->assertEquals(
330330 '19941106084937',
331331 wfTimestamp( TS_MW, 'Sun, 06 Nov 1994 08:49:37 GMT' ),
332332 'RFC 822 date' );
333 -
 333+
334334 $this->assertEquals(
335335 '19941106084937',
336336 wfTimestamp( TS_MW, 'Sunday, 06-Nov-94 08:49:37 GMT' ),
337337 'RFC 850 date' );
338 -
 338+
339339 $this->assertEquals(
340340 '19941106084937',
341341 wfTimestamp( TS_MW, 'Sun Nov 6 08:49:37 1994' ),
342342 "ANSI C's asctime() format" );
343 -
 343+
344344 // See http://www.squid-cache.org/mail-archive/squid-users/200307/0122.html and r77171
345345 $this->assertEquals(
346346 '20101122141242',
347347 wfTimestamp( TS_MW, 'Mon, 22 Nov 2010 14:12:42 GMT; length=52626' ),
348348 "Netscape extension to HTTP/1.0" );
349 -
 349+
350350 }
351351
352352 function testBasename() {
Index: trunk/phase3/maintenance/tests/phpunit/includes/IPTest.php
@@ -1,10 +1,10 @@
22 <?php
3 -/*
 3+/*
44 * Tests for IP validity functions. Ported from /t/inc/IP.t by avar.
55 */
66
77 class IPTest extends PHPUnit_Framework_TestCase {
8 - // not sure it should be tested with boolean false. hashar 20100924
 8+ // not sure it should be tested with boolean false. hashar 20100924
99 public function testisIPAddress() {
1010 $this->assertFalse( IP::isIPAddress( false ), 'Boolean false is not an IP' );
1111 $this->assertFalse( IP::isIPAddress( true ), 'Boolean true is not an IP' );
@@ -24,7 +24,7 @@
2525 $this->assertTrue( IP::isIPAddress( '74.24.52.13/20', 'IPv4 range' ) );
2626 $this->assertTrue( IP::isIPAddress( 'fc:100:a:d:1:e:ac:0/24' ), 'IPv6 range' );
2727 $this->assertTrue( IP::isIPAddress( 'fc::100:a:d:1:e:ac/96' ), 'IPv6 range with "::"' );
28 -
 28+
2929 $validIPs = array( 'fc:100::', 'fc:100:a:d:1:e:ac::', 'fc::100', '::fc:100:a:d:1:e:ac',
3030 '::fc', 'fc::100:a:d:1:e:ac', 'fc:100:a:d:1:e:ac:0', '124.24.52.13', '1.24.52.13' );
3131 foreach ( $validIPs as $ip ) {
@@ -114,7 +114,7 @@
115115
116116 // tests isValid()
117117 public function testInvalidIPs() {
118 - // Out of range...
 118+ // Out of range...
119119 foreach ( range( 256, 999 ) as $i ) {
120120 $a = sprintf( "%03d", $i );
121121 $b = sprintf( "%02d", $i );
@@ -267,7 +267,7 @@
268268 * representing the network mask and the bit mask.
269269 */
270270 function testCIDRParsing() {
271 - $this->assertFalseCIDR( '192.0.2.0' , "missing mask" );
 271+ $this->assertFalseCIDR( '192.0.2.0' , "missing mask" );
272272 $this->assertFalseCIDR( '192.0.2.0/', "missing bitmask" );
273273
274274 // Verify if statement
@@ -283,7 +283,7 @@
284284 $this->assertEquals( array( 0, 0 ), IP::parseCIDR('255.255.255.255/0') );
285285
286286 // FIXME : add more tests.
287 -
 287+
288288 # This part test network shifting
289289 $this->assertNet( '192.0.0.0' , '192.0.0.2/24' );
290290 $this->assertNet( '192.168.5.0', '192.168.5.13/24');
@@ -293,6 +293,6 @@
294294 $this->assertNet( '10.0.0.4' , '10.0.0.4/30' );
295295 $this->assertNet( '172.17.32.0', '172.17.35.48/21' );
296296 $this->assertNet( '10.128.0.0' , '10.135.0.0/9' );
297 - $this->assertNet( '134.0.0.0' , '134.0.5.1/8' );
 297+ $this->assertNet( '134.0.0.0' , '134.0.5.1/8' );
298298 }
299299 }
Index: trunk/phase3/maintenance/tests/phpunit/includes/ParserOptionsTest.php
@@ -4,33 +4,33 @@
55
66 private $popts;
77 private $pcache;
8 -
 8+
99 function setUp() {
1010 ParserTest::setUp(); //reuse setup from parser tests
1111 global $wgContLang, $wgUser;
1212 $wgContLang = new StubContLang;
1313 $this->popts = new ParserOptions( $wgUser );
14 - $this->pcache = ParserCache::singleton();
 14+ $this->pcache = ParserCache::singleton();
1515 }
16 -
 16+
1717 function tearDown() {
1818 parent::tearDown();
1919 }
20 -
 20+
2121 /**
2222 * ParserOptions::optionsHash was not giving consistent results when $wgUseDynamicDates was set
2323 * @group Database
2424 */
25 - function testGetParserCacheKeyWithDynamicDates() {
 25+ function testGetParserCacheKeyWithDynamicDates() {
2626 global $wgUseDynamicDates;
2727 $wgUseDynamicDates = true;
28 -
 28+
2929 $title = Title::newFromText( "Some test article" );
30 - $article = new Article( $title );
31 -
 30+ $article = new Article( $title );
 31+
3232 $pcacheKeyBefore = $this->pcache->getKey( $article, $this->popts );
3333 $this->assertNotNull( $this->popts->getDateFormat() );
34 - $pcacheKeyAfter = $this->pcache->getKey( $article, $this->popts );
35 - $this->assertEquals( $pcacheKeyBefore, $pcacheKeyAfter );
 34+ $pcacheKeyAfter = $this->pcache->getKey( $article, $this->popts );
 35+ $this->assertEquals( $pcacheKeyBefore, $pcacheKeyAfter );
3636 }
3737 }
Index: trunk/phase3/maintenance/tests/phpunit/includes/SeleniumConfigurationTest.php
@@ -4,14 +4,14 @@
55
66 /*
77 * The file where the test temporarity stores the selenium config.
8 - * This should be cleaned up as part of teardown.
 8+ * This should be cleaned up as part of teardown.
99 */
1010 private $tempFileName;
11 -
 11+
1212 /*
1313 * String containing the a sample selenium settings
1414 */
15 - private $testConfig0 =
 15+ private $testConfig0 =
1616 '
1717 [SeleniumSettings]
1818 browsers[firefox] = "*firefox"
@@ -30,7 +30,7 @@
3131
3232 [SeleniumTests]
3333 testSuite[SimpleSeleniumTestSuite] = "maintenance/tests/selenium/SimpleSeleniumTestSuite.php"
34 -testSuite[TestSuiteName] = "testSuitePath"
 34+testSuite[TestSuiteName] = "testSuitePath"
3535 ';
3636 /*
3737 * Array of expected browsers from $testConfig0
@@ -60,14 +60,14 @@
6161 */
6262 private $testSuites0 = array(
6363 'SimpleSeleniumTestSuite' => 'maintenance/tests/selenium/SimpleSeleniumTestSuite.php',
64 - 'TestSuiteName' => 'testSuitePath'
 64+ 'TestSuiteName' => 'testSuitePath'
6565 );
66 -
67 -
 66+
 67+
6868 /*
6969 * Another sample selenium settings file contents
7070 */
71 - private $testConfig1 =
 71+ private $testConfig1 =
7272 '
7373 [SeleniumSettings]
7474 host = "localhost"
@@ -96,15 +96,15 @@
9797 /*
9898 * Expected test suites from $testConfig1
9999 */
100 - private $testSuites1 = null;
101 -
102 -
 100+ private $testSuites1 = null;
 101+
 102+
103103 public function setUp() {
104104 if ( !defined( 'SELENIUMTEST' ) ) {
105105 define( 'SELENIUMTEST', true );
106106 }
107107 }
108 -
 108+
109109 /*
110110 * Clean up the temporary file used to store the selenium settings.
111111 */
@@ -115,90 +115,90 @@
116116 }
117117 parent::tearDown();
118118 }
119 -
 119+
120120 /**
121 - * @expectedException MWException
122 - * @group SeleniumFramework
123 - */
124 - public function testErrorOnIncorrectConfigFile() {
 121+ * @expectedException MWException
 122+ * @group SeleniumFramework
 123+ */
 124+ public function testErrorOnIncorrectConfigFile() {
125125 $seleniumSettings;
126126 $seleniumBrowsers;
127127 $seleniumTestSuites;
128128
129 - SeleniumConfig::getSeleniumSettings($seleniumSettings,
130 - $seleniumBrowsers,
 129+ SeleniumConfig::getSeleniumSettings($seleniumSettings,
 130+ $seleniumBrowsers,
131131 $seleniumTestSuites,
132132 "Some_fake_settings_file.ini" );
133133
134134 }
135 -
 135+
136136 /**
137 - * @expectedException MWException
138 - * @group SeleniumFramework
139 - */
140 - public function testErrorOnMissingConfigFile() {
 137+ * @expectedException MWException
 138+ * @group SeleniumFramework
 139+ */
 140+ public function testErrorOnMissingConfigFile() {
141141 $seleniumSettings;
142142 $seleniumBrowsers;
143143 $seleniumTestSuites;
144144 global $wgSeleniumConfigFile;
145145 $wgSeleniumConfigFile = '';
146 - SeleniumConfig::getSeleniumSettings($seleniumSettings,
147 - $seleniumBrowsers,
 146+ SeleniumConfig::getSeleniumSettings($seleniumSettings,
 147+ $seleniumBrowsers,
148148 $seleniumTestSuites);
149149 }
150 -
 150+
151151 /**
152 - * @group SeleniumFramework
153 - */
154 - public function testUsesGlobalVarForConfigFile() {
 152+ * @group SeleniumFramework
 153+ */
 154+ public function testUsesGlobalVarForConfigFile() {
155155 $seleniumSettings;
156156 $seleniumBrowsers;
157157 $seleniumTestSuites;
158158 global $wgSeleniumConfigFile;
159159 $this->writeToTempFile( $this->testConfig0 );
160160 $wgSeleniumConfigFile = $this->tempFileName;
161 - SeleniumConfig::getSeleniumSettings($seleniumSettings,
162 - $seleniumBrowsers,
 161+ SeleniumConfig::getSeleniumSettings($seleniumSettings,
 162+ $seleniumBrowsers,
163163 $seleniumTestSuites);
164164 $this->assertEquals($seleniumSettings, $this->testSettings0 ,
165165 'The selenium settings should have been read from the file defined in $wgSeleniumConfigFile'
166166 );
167 - $this->assertEquals($seleniumBrowsers, $this->testBrowsers0,
 167+ $this->assertEquals($seleniumBrowsers, $this->testBrowsers0,
168168 'The available browsers should have been read from the file defined in $wgSeleniumConfigFile'
169169 );
170 - $this->assertEquals($seleniumTestSuites, $this->testSuites0,
 170+ $this->assertEquals($seleniumTestSuites, $this->testSuites0,
171171 'The test suites should have been read from the file defined in $wgSeleniumConfigFile'
172 - );
 172+ );
173173 }
174 -
 174+
175175 /**
176 - * @group SeleniumFramework
177 - * @dataProvider sampleConfigs
178 - */
179 - public function testgetSeleniumSettings($sampleConfig, $expectedSettings, $expectedBrowsers, $expectedSuites ) {
 176+ * @group SeleniumFramework
 177+ * @dataProvider sampleConfigs
 178+ */
 179+ public function testgetSeleniumSettings($sampleConfig, $expectedSettings, $expectedBrowsers, $expectedSuites ) {
180180 $this->writeToTempFile( $sampleConfig );
181181 $seleniumSettings;
182182 $seleniumBrowsers;
183183 $seleniumTestSuites;
184184
185 - SeleniumConfig::getSeleniumSettings($seleniumSettings,
186 - $seleniumBrowsers,
 185+ SeleniumConfig::getSeleniumSettings($seleniumSettings,
 186+ $seleniumBrowsers,
187187 $seleniumTestSuites,
188188 $this->tempFileName );
189 -
190 - $this->assertEquals($seleniumSettings, $expectedSettings,
 189+
 190+ $this->assertEquals($seleniumSettings, $expectedSettings,
191191 "The selenium settings for the following test configuration was not retrieved correctly" . $sampleConfig
192192 );
193 - $this->assertEquals($seleniumBrowsers, $expectedBrowsers,
 193+ $this->assertEquals($seleniumBrowsers, $expectedBrowsers,
194194 "The available browsers for the following test configuration was not retrieved correctly" . $sampleConfig
195195 );
196 - $this->assertEquals($seleniumTestSuites, $expectedSuites,
 196+ $this->assertEquals($seleniumTestSuites, $expectedSuites,
197197 "The test suites for the following test configuration was not retrieved correctly" . $sampleConfig
198198 );
199 -
200 -
 199+
 200+
201201 }
202 -
 202+
203203 /*
204204 * create a temp file and write text to it.
205205 * @param $testToWrite the text to write to the temp file
@@ -209,11 +209,11 @@
210210 fwrite($tempFile , $textToWrite);
211211 fclose($tempFile);
212212 }
213 -
 213+
214214 /*
215215 * Returns an array containing:
216216 * The contents of the selenium cingiguration ini file
217 - * The expected selenium configuration array that getSeleniumSettings should return
 217+ * The expected selenium configuration array that getSeleniumSettings should return
218218 * The expected available browsers array that getSeleniumSettings should return
219219 * The expected test suites arrya that getSeleniumSettings should return
220220 */
@@ -223,6 +223,6 @@
224224 array($this->testConfig1, $this->testSettings1, $this->testBrowsers1, $this->testSuites1 )
225225 );
226226 }
227 -
228227
 228+
229229 }
Index: trunk/phase3/maintenance/tests/phpunit/includes/search/SearchDbTest.php
@@ -14,7 +14,7 @@
1515 $this->db = wfGetDB( DB_MASTER );
1616 if ( !$this->db ) {
1717 $this->markTestIncomplete( "Can't find a database to test with." );
18 - }
 18+ }
1919
2020 parent::setup();
2121
Index: trunk/phase3/maintenance/tests/phpunit/includes/search/SearchEngineTest.php
@@ -33,26 +33,26 @@
3434 }
3535
3636 function insertSearchData() {
37 - if ( $this->pageExists( 'Not_Main_Page' ) ) {
 37+ if ( $this->pageExists( 'Not_Main_Page' ) ) {
3838 return;
39 - }
40 - $this->insertPage( "Not_Main_Page", "This is not a main page", 0 );
41 - $this->insertPage( 'Talk:Not_Main_Page', 'This is not a talk page to the main page, see [[smithee]]', 1 );
42 - $this->insertPage( 'Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]', 0 );
43 - $this->insertPage( 'Talk:Smithee', 'This article sucks.', 1 );
44 - $this->insertPage( 'Unrelated_page', 'Nothing in this page is about the S word.', 0 );
45 - $this->insertPage( 'Another_page', 'This page also is unrelated.', 0 );
46 - $this->insertPage( 'Help:Help', 'Help me!', 4 );
47 - $this->insertPage( 'Thppt', 'Blah blah', 0 );
48 - $this->insertPage( 'Alan_Smithee', 'yum', 0 );
49 - $this->insertPage( 'Pages', 'are\'food', 0 );
50 - $this->insertPage( 'HalfOneUp', 'AZ', 0 );
51 - $this->insertPage( 'FullOneUp', 'AZ', 0 );
52 - $this->insertPage( 'HalfTwoLow', 'az', 0 );
53 - $this->insertPage( 'FullTwoLow', 'az', 0 );
54 - $this->insertPage( 'HalfNumbers', '1234567890', 0 );
55 - $this->insertPage( 'FullNumbers', '1234567890', 0 );
56 - $this->insertPage( 'DomainName', 'example.com', 0 );
 39+ }
 40+ $this->insertPage( "Not_Main_Page", "This is not a main page", 0 );
 41+ $this->insertPage( 'Talk:Not_Main_Page', 'This is not a talk page to the main page, see [[smithee]]', 1 );
 42+ $this->insertPage( 'Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]', 0 );
 43+ $this->insertPage( 'Talk:Smithee', 'This article sucks.', 1 );
 44+ $this->insertPage( 'Unrelated_page', 'Nothing in this page is about the S word.', 0 );
 45+ $this->insertPage( 'Another_page', 'This page also is unrelated.', 0 );
 46+ $this->insertPage( 'Help:Help', 'Help me!', 4 );
 47+ $this->insertPage( 'Thppt', 'Blah blah', 0 );
 48+ $this->insertPage( 'Alan_Smithee', 'yum', 0 );
 49+ $this->insertPage( 'Pages', 'are\'food', 0 );
 50+ $this->insertPage( 'HalfOneUp', 'AZ', 0 );
 51+ $this->insertPage( 'FullOneUp', 'AZ', 0 );
 52+ $this->insertPage( 'HalfTwoLow', 'az', 0 );
 53+ $this->insertPage( 'FullTwoLow', 'az', 0 );
 54+ $this->insertPage( 'HalfNumbers', '1234567890', 0 );
 55+ $this->insertPage( 'FullNumbers', '1234567890', 0 );
 56+ $this->insertPage( 'DomainName', 'example.com', 0 );
5757 }
5858
5959 function removeSearchData() {
@@ -62,7 +62,7 @@
6363 $article = new Article( $title, $id );
6464 $article->doDeleteArticle( "Search Test" );
6565 }*/
66 - }
 66+ }
6767
6868 function fetchIds( $results ) {
6969 $this->assertTrue( is_object( $results ) );
@@ -81,82 +81,82 @@
8282
8383 // Modified version of WikiRevision::importOldRevision()
8484 function insertPage( $pageName, $text, $ns ) {
85 - $dbw = $this->db;
86 - $title = Title::newFromText( $pageName );
 85+ $dbw = $this->db;
 86+ $title = Title::newFromText( $pageName );
8787
88 - $userId = 0;
89 - $userText = 'WikiSysop';
90 - $comment = 'Search Test';
 88+ $userId = 0;
 89+ $userText = 'WikiSysop';
 90+ $comment = 'Search Test';
9191
92 - // avoid memory leak...?
93 - $linkCache = LinkCache::singleton();
94 - $linkCache->clear();
 92+ // avoid memory leak...?
 93+ $linkCache = LinkCache::singleton();
 94+ $linkCache->clear();
9595
96 - $article = new Article( $title );
97 - $pageId = $article->getId();
98 - $created = false;
99 - if ( $pageId == 0 ) {
100 - # must create the page...
101 - $pageId = $article->insertOn( $dbw );
102 - $created = true;
103 - }
 96+ $article = new Article( $title );
 97+ $pageId = $article->getId();
 98+ $created = false;
 99+ if ( $pageId == 0 ) {
 100+ # must create the page...
 101+ $pageId = $article->insertOn( $dbw );
 102+ $created = true;
 103+ }
104104
105 - # FIXME: Use original rev_id optionally (better for backups)
106 - # Insert the row
107 - $revision = new Revision( array(
108 - 'page' => $pageId,
109 - 'text' => $text,
110 - 'comment' => $comment,
111 - 'user' => $userId,
112 - 'user_text' => $userText,
113 - 'timestamp' => 0,
114 - 'minor_edit' => false,
 105+ # FIXME: Use original rev_id optionally (better for backups)
 106+ # Insert the row
 107+ $revision = new Revision( array(
 108+ 'page' => $pageId,
 109+ 'text' => $text,
 110+ 'comment' => $comment,
 111+ 'user' => $userId,
 112+ 'user_text' => $userText,
 113+ 'timestamp' => 0,
 114+ 'minor_edit' => false,
115115 ) );
116 - $revId = $revision->insertOn( $dbw );
117 - $changed = $article->updateIfNewerOn( $dbw, $revision );
 116+ $revId = $revision->insertOn( $dbw );
 117+ $changed = $article->updateIfNewerOn( $dbw, $revision );
118118
119 - $GLOBALS['wgTitle'] = $title;
120 - if ( $created ) {
121 - Article::onArticleCreate( $title );
122 - $article->createUpdates( $revision );
123 - } elseif ( $changed ) {
124 - Article::onArticleEdit( $title );
125 - $article->editUpdates(
126 - $text, $comment, false, 0, $revId );
127 - }
 119+ $GLOBALS['wgTitle'] = $title;
 120+ if ( $created ) {
 121+ Article::onArticleCreate( $title );
 122+ $article->createUpdates( $revision );
 123+ } elseif ( $changed ) {
 124+ Article::onArticleEdit( $title );
 125+ $article->editUpdates(
 126+ $text, $comment, false, 0, $revId );
 127+ }
128128
129 - $su = new SearchUpdate( $article->getId(), $pageName, $text );
130 - $su->doUpdate();
 129+ $su = new SearchUpdate( $article->getId(), $pageName, $text );
 130+ $su->doUpdate();
131131
132 - $this->pageList[] = array( $title, $article->getId() );
 132+ $this->pageList[] = array( $title, $article->getId() );
133133
134 - return true;
135 - }
 134+ return true;
 135+ }
136136
137137 function testFullWidth() {
138 - $this->assertEquals(
139 - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
140 - $this->fetchIds( $this->search->searchText( 'AZ' ) ),
141 - "Search for normalized from Half-width Upper" );
142 - $this->assertEquals(
143 - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
144 - $this->fetchIds( $this->search->searchText( 'az' ) ),
145 - "Search for normalized from Half-width Lower" );
146 - $this->assertEquals(
147 - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
148 - $this->fetchIds( $this->search->searchText( 'AZ' ) ),
149 - "Search for normalized from Full-width Upper" );
150 - $this->assertEquals(
151 - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
152 - $this->fetchIds( $this->search->searchText( 'az' ) ),
153 - "Search for normalized from Full-width Lower" );
 138+ $this->assertEquals(
 139+ array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
 140+ $this->fetchIds( $this->search->searchText( 'AZ' ) ),
 141+ "Search for normalized from Half-width Upper" );
 142+ $this->assertEquals(
 143+ array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
 144+ $this->fetchIds( $this->search->searchText( 'az' ) ),
 145+ "Search for normalized from Half-width Lower" );
 146+ $this->assertEquals(
 147+ array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
 148+ $this->fetchIds( $this->search->searchText( 'AZ' ) ),
 149+ "Search for normalized from Full-width Upper" );
 150+ $this->assertEquals(
 151+ array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ),
 152+ $this->fetchIds( $this->search->searchText( 'az' ) ),
 153+ "Search for normalized from Full-width Lower" );
154154 }
155155
156156 function testTextSearch() {
157157 $this->assertEquals(
158 - array( 'Smithee' ),
159 - $this->fetchIds( $this->search->searchText( 'smithee' ) ),
160 - "Plain search failed" );
 158+ array( 'Smithee' ),
 159+ $this->fetchIds( $this->search->searchText( 'smithee' ) ),
 160+ "Plain search failed" );
161161 }
162162
163163 function testTextPowerSearch() {
Index: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiTest.php
@@ -98,7 +98,7 @@
9999 "lgpassword" => "bad",
100100 )
101101 );
102 -
 102+
103103 $result = $ret[0];
104104
105105 $this->assertNotType( "bool", $result );
Index: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiSetup.php
@@ -36,7 +36,7 @@
3737 self::$user = new UserWrapper( 'User for MediaWiki automated tests', User::randomPassword() );
3838 self::$sysopUser = new UserWrapper( 'Sysop for MediaWiki automated tests', User::randomPassword(), 'sysop' );
3939 }
40 -
 40+
4141 $GLOBALS['wgUser'] = self::$sysopUser->user;
4242 }
4343 }
Index: trunk/phase3/maintenance/tests/phpunit/includes/api/RandomImageGenerator.php
@@ -1,21 +1,21 @@
22 <?php
33
4 -/*
 4+/*
55 * RandomImageGenerator -- does what it says on the tin.
66 * Requires Imagick, the ImageMagick library for PHP, or the command line equivalent (usually 'convert').
77 *
88 * Because MediaWiki tests the uniqueness of media upload content, and filenames, it is sometimes useful to generate
99 * files that are guaranteed (or at least very likely) to be unique in both those ways.
10 - * This generates a number of filenames with random names and random content (colored circles)
 10+ * This generates a number of filenames with random names and random content (colored circles)
1111 *
12 - * It is also useful to have fresh content because our tests currently run in a "destructive" mode, and don't create a fresh new wiki for each
 12+ * It is also useful to have fresh content because our tests currently run in a "destructive" mode, and don't create a fresh new wiki for each
1313 * test run.
14 - * Consequently, if we just had a few static files we kept re-uploading, we'd get lots of warnings about matching content or filenames,
 14+ * Consequently, if we just had a few static files we kept re-uploading, we'd get lots of warnings about matching content or filenames,
1515 * and even if we deleted those files, we'd get warnings about archived files.
1616 *
1717 * This can also be used with a cronjob to generate random files all the time -- I use it to have a constant, never ending supply when I'm
1818 * testing interactively.
19 - *
 19+ *
2020 * @file
2121 * @author Neil Kandalgaonkar <neilk@wikimedia.org>
2222 */
@@ -33,7 +33,7 @@
3434 private $maxHeight = 800;
3535 private $circlesToDraw = 5;
3636 private $imageWriteMethod;
37 -
 37+
3838 public function __construct( $options ) {
3939 global $wgUseImageMagick, $wgImageMagickConvertCommand;
4040 foreach ( array( 'dictionaryFile', 'minWidth', 'minHeight', 'maxHeight', 'circlesToDraw' ) as $property ) {
@@ -62,12 +62,12 @@
6363 $this->imageWriteMethod = 'writeImageWithCommandLine';
6464 } else {
6565 throw new Exception( "RandomImageGenerator: could not find a suitable method to write images" );
66 - }
 66+ }
6767 }
6868
6969 /**
7070 * Writes random images with random filenames to disk in the directory you specify, or current working directory
71 - *
 71+ *
7272 * @param $number Integer: number of filenames to write
7373 * @param $format String: optional, must be understood by ImageMagick, such as 'jpg' or 'gif'
7474 * @param $dir String: directory, optional (will default to current working directory)
@@ -81,10 +81,10 @@
8282 return $filenames;
8383 }
8484
85 - /**
 85+ /**
8686 * Return a number of randomly-generated filenames
8787 * Each filename uses two words randomly drawn from the dictionary, like elephantine_spatula.jpg
88 - *
 88+ *
8989 * @param $number Integer: of filenames to generate
9090 * @param $extension String: optional, defaults to 'jpg'
9191 * @param $dir String: optional, defaults to current working directory
@@ -103,23 +103,23 @@
104104 $basename = preg_replace( '/\s+/', '', $basename );
105105 $filenames[] = "$dir/$basename";
106106 }
107 -
 107+
108108 return $filenames;
109 -
 109+
110110 }
111111
112112
113113 /**
114 - * Generate data representing an image of random size (within limits),
 114+ * Generate data representing an image of random size (within limits),
115115 * consisting of randomly colored and sized circles against a random background color
116116 * (This data is used in the writeImage* methods).
117 - * @return {Mixed}
 117+ * @return {Mixed}
118118 */
119 - public function getImageSpec() {
 119+ public function getImageSpec() {
120120 $spec = array();
121 -
122 - $spec['width'] = mt_rand( $this->minWidth, $this->maxWidth );
123 - $spec['height'] = mt_rand( $this->minHeight, $this->maxHeight );
 121+
 122+ $spec['width'] = mt_rand( $this->minWidth, $this->maxWidth );
 123+ $spec['height'] = mt_rand( $this->minHeight, $this->maxHeight );
124124 $spec['fill'] = $this->getRandomColor();
125125
126126 $diagonalLength = sqrt( pow( $spec['width'], 2 ) + pow( $spec['height'], 2 ) );
@@ -134,14 +134,14 @@
135135
136136 $draw = array();
137137 $draw['fill'] = $this->getRandomColor();
138 - $draw['circle'] = array(
139 - 'originX' => $originX,
140 - 'originY' => $originY,
141 - 'perimeterX' => $perimeterX,
142 - 'perimeterY' => $perimeterY
 138+ $draw['circle'] = array(
 139+ 'originX' => $originX,
 140+ 'originY' => $originY,
 141+ 'perimeterX' => $perimeterX,
 142+ 'perimeterY' => $perimeterY
143143 );
144144 $draws[] = $draw;
145 -
 145+
146146 }
147147
148148 $spec['draws'] = $draws;
@@ -156,12 +156,12 @@
157157 * @param $format: file format to write
158158 * @param $filename: filename to write to
159159 */
160 - public function writeImageWithApi( $spec, $format, $filename ) {
 160+ public function writeImageWithApi( $spec, $format, $filename ) {
161161 $image = new Imagick();
162162 $image->newImage( $spec['width'], $spec['height'], new ImagickPixel( $spec['fill'] ) );
163163
164164 foreach ( $spec['draws'] as $drawSpec ) {
165 - $draw = new ImagickDraw();
 165+ $draw = new ImagickDraw();
166166 $draw->setFillColor( $drawSpec['fill'] );
167167 $circle = $drawSpec['circle'];
168168 $draw->circle( $circle['originX'], $circle['originY'], $circle['perimeterX'], $circle['perimeterY'] );
@@ -178,9 +178,9 @@
179179 *
180180 * Sample command line:
181181 * $ convert -size 100x60 xc:rgb(90,87,45) \
182 - * -draw 'fill rgb(12,34,56) circle 41,39 44,57' \
183 - * -draw 'fill rgb(99,123,231) circle 59,39 56,57' \
184 - * -draw 'fill rgb(240,12,32) circle 50,21 50,3' filename.png
 182+ * -draw 'fill rgb(12,34,56) circle 41,39 44,57' \
 183+ * -draw 'fill rgb(99,123,231) circle 59,39 56,57' \
 184+ * -draw 'fill rgb(240,12,32) circle 50,21 50,3' filename.png
185185 *
186186 * @param $spec: spec describing background and circles to draw
187187 * @param $format: file format to write (unused by this method but kept so it has the same signature as writeImageWithApi)
@@ -210,7 +210,7 @@
211211
212212 /**
213213 * Generate a string of random colors for ImageMagick, like "rgb(12, 37, 98)"
214 - *
 214+ *
215215 * @return {String}
216216 */
217217 public function getRandomColor() {
@@ -221,13 +221,13 @@
222222 return 'rgb(' . join(', ', $components) . ')';
223223 }
224224
225 - /**
 225+ /**
226226 * Get an array of random pairs of random words, like array( array( 'foo', 'bar' ), array( 'quux', 'baz' ) );
227227 *
228228 * @param $number Integer: number of pairs
229229 * @return Array: of two-element arrays
230230 */
231 - private function getRandomWordPairs( $number ) {
 231+ private function getRandomWordPairs( $number ) {
232232 $lines = $this->getRandomLines( $number * 2 );
233233 // construct pairs of words
234234 $pairs = array();
@@ -238,16 +238,16 @@
239239 return $pairs;
240240 }
241241
242 -
 242+
243243 /**
244244 * Return N random lines from a file
245 - *
 245+ *
246246 * Will throw exception if the file could not be read or if it had fewer lines than requested.
247 - *
 247+ *
248248 * @param $number_desired Integer: number of lines desired
249249 * @return Array: of exactly n elements, drawn randomly from lines the file
250250 */
251 - private function getRandomLines( $number_desired ) {
 251+ private function getRandomLines( $number_desired ) {
252252 $filepath = $this->dictionaryFile;
253253
254254 // initialize array of lines
@@ -257,7 +257,7 @@
258258 }
259259
260260 /*
261 - * This algorithm obtains N random lines from a file in one single pass. It does this by replacing elements of
 261+ * This algorithm obtains N random lines from a file in one single pass. It does this by replacing elements of
262262 * a fixed-size array of lines, less and less frequently as it reads the file.
263263 */
264264 $fh = fopen( $filepath, "r" );
@@ -266,12 +266,12 @@
267267 }
268268 $line_number = 0;
269269 $max_index = $number_desired - 1;
270 - while( !feof( $fh ) ) {
 270+ while( !feof( $fh ) ) {
271271 $line = fgets( $fh );
272272 if ( $line !== false ) {
273 - $line_number++;
274 - $line = trim( $line );
275 - if ( mt_rand( 0, $line_number ) <= $max_index ) {
 273+ $line_number++;
 274+ $line = trim( $line );
 275+ if ( mt_rand( 0, $line_number ) <= $max_index ) {
276276 $lines[ mt_rand( 0, $max_index ) ] = $line;
277277 }
278278 }
@@ -280,7 +280,7 @@
281281 if ( $line_number < $number_desired ) {
282282 throw new Exception( "not enough lines in $filepath" );
283283 }
284 -
 284+
285285 return $lines;
286286 }
287287
Index: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiUploadTest.php
@@ -6,14 +6,14 @@
77 */
88
99 /**
10 - * n.b. Ensure that you can write to the images/ directory as the
 10+ * n.b. Ensure that you can write to the images/ directory as the
1111 * user that will run tests.
1212 */
1313
1414 // Note for reviewers: this intentionally duplicates functionality already in "ApiSetup" and so on.
1515 // This framework works better IMO and has less strangeness (such as test cases inheriting from "ApiSetup"...)
1616 // (and in the case of the other Upload tests, this flat out just actually works... )
17 -
 17+
1818 // TODO: refactor into several files
1919 // TODO: port the other Upload tests, and other API tests to this framework
2020
@@ -29,14 +29,14 @@
3030 public $user;
3131
3232 function __construct( $username, $realname = 'Real Name', $email = 'sample@sample.com', $groups = array() ) {
33 - $this->username = $username;
34 - $this->realname = $realname;
 33+ $this->username = $username;
 34+ $this->realname = $realname;
3535 $this->email = $email;
3636 $this->groups = $groups;
3737
38 - // don't allow user to hardcode or select passwords -- people sometimes run tests
 38+ // don't allow user to hardcode or select passwords -- people sometimes run tests
3939 // on live wikis. Sometimes we create sysop users in these tests. A sysop user with
40 - // a known password would be a Bad Thing.
 40+ // a known password would be a Bad Thing.
4141 $this->password = User::randomPassword();
4242
4343 $this->user = User::newFromName( $this->username );
@@ -48,17 +48,17 @@
4949 // In core MediaWiki, there is no functionality to delete users, so this is the best we can do.
5050 if ( !$this->user->getID() ) {
5151 // create the user
52 - $this->user = User::createNew(
 52+ $this->user = User::createNew(
5353 $this->username, array(
5454 "email" => $this->email,
5555 "real_name" => $this->realname
56 - )
 56+ )
5757 );
5858 if ( !$this->user ) {
5959 throw new Exception( "error creating user" );
6060 }
6161 }
62 -
 62+
6363 // update the user to use the new random password and other details
6464 $this->user->setPassword( $this->password );
6565 $this->user->setEmail( $this->email );
@@ -73,7 +73,7 @@
7474 }
7575 }
7676 $this->user->saveSettings();
77 -
 77+
7878 }
7979
8080 }
@@ -90,17 +90,17 @@
9191 $wgRequest = new FauxRequest( array() );
9292
9393 self::$users = array(
94 - 'sysop' => new ApiTestUser(
95 - 'Apitestsysop',
96 - 'Api Test Sysop',
97 - 'api_test_sysop@sample.com',
98 - array( 'sysop' )
 94+ 'sysop' => new ApiTestUser(
 95+ 'Apitestsysop',
 96+ 'Api Test Sysop',
 97+ 'api_test_sysop@sample.com',
 98+ array( 'sysop' )
9999 ),
100 - 'uploader' => new ApiTestUser(
 100+ 'uploader' => new ApiTestUser(
101101 'Apitestuser',
102102 'Api Test User',
103103 'api_test_user@sample.com',
104 - array()
 104+ array()
105105 )
106106 );
107107
@@ -145,7 +145,7 @@
146146 */
147147 class ApiUploadTest extends ApiTestCase {
148148 /**
149 - * Fixture -- run before every test
 149+ * Fixture -- run before every test
150150 */
151151 public function setUp() {
152152 global $wgEnableUploads, $wgEnableAPI;
@@ -158,12 +158,12 @@
159159 ini_set( 'log_errors', 1 );
160160 ini_set( 'error_reporting', 1 );
161161 ini_set( 'display_errors', 1 );
162 -
 162+
163163 $this->clearFakeUploads();
164164 }
165165
166166 /**
167 - * Fixture -- run after every test
 167+ * Fixture -- run after every test
168168 * Clean up temporary files etc.
169169 */
170170 function tearDown() {
@@ -177,10 +177,10 @@
178178 function testLogin() {
179179 $user = self::$users['uploader'];
180180
181 - $params = array(
182 - 'action' => 'login',
183 - 'lgname' => $user->username,
184 - 'lgpassword' => $user->password
 181+ $params = array(
 182+ 'action' => 'login',
 183+ 'lgname' => $user->username,
 184+ 'lgpassword' => $user->password
185185 );
186186 list( $result, , ) = $this->doApiRequest( $params );
187187 $this->assertArrayHasKey( "login", $result );
@@ -192,8 +192,8 @@
193193 'action' => 'login',
194194 'lgtoken' => $token,
195195 'lgname' => $user->username,
196 - 'lgpassword' => $user->password
197 - );
 196+ 'lgpassword' => $user->password
 197+ );
198198 list( $result, , $session ) = $this->doApiRequest( $params );
199199 $this->assertArrayHasKey( "login", $result );
200200 $this->assertArrayHasKey( "result", $result['login'] );
@@ -207,7 +207,7 @@
208208 /**
209209 * @depends testLogin
210210 */
211 - public function testUploadRequiresToken( $session ) {
 211+ public function testUploadRequiresToken( $session ) {
212212 $exception = false;
213213 try {
214214 $this->doApiRequest( array(
@@ -222,8 +222,8 @@
223223
224224 /**
225225 * @depends testLogin
226 - */
227 - public function testUploadMissingParams( $session ) {
 226+ */
 227+ public function testUploadMissingParams( $session ) {
228228 global $wgUser;
229229 $wgUser = self::$users['uploader']->user;
230230
@@ -244,7 +244,7 @@
245245 /**
246246 * @depends testLogin
247247 */
248 - public function testUpload( $session ) {
 248+ public function testUpload( $session ) {
249249 global $wgUser;
250250 $wgUser = self::$users['uploader']->user;
251251
@@ -261,7 +261,7 @@
262262 $filePaths = $randomImageGenerator->writeImages( 1, $extension, dirname( wfTempDir() ) );
263263 $filePath = $filePaths[0];
264264 $fileSize = filesize( $filePath );
265 - $fileName = basename( $filePath );
 265+ $fileName = basename( $filePath );
266266
267267 $this->deleteFileByFileName( $fileName );
268268 $this->deleteFileByContent( $filePath );
@@ -299,7 +299,7 @@
300300 /**
301301 * @depends testLogin
302302 */
303 - public function testUploadZeroLength( $session ) {
 303+ public function testUploadZeroLength( $session ) {
304304 global $wgUser;
305305 $wgUser = self::$users['uploader']->user;
306306
@@ -340,7 +340,7 @@
341341 /**
342342 * @depends testLogin
343343 */
344 - public function testUploadSameFileName( $session ) {
 344+ public function testUploadSameFileName( $session ) {
345345 global $wgUser;
346346 $wgUser = self::$users['uploader']->user;
347347
@@ -356,7 +356,7 @@
357357
358358 $filePaths = $randomImageGenerator->writeImages( 2, $extension, dirname( wfTempDir() ) );
359359 // we'll reuse this filename
360 - $fileName = basename( $filePaths[0] );
 360+ $fileName = basename( $filePaths[0] );
361361
362362 // clear any other files with the same name
363363 $this->deleteFileByFileName( $fileName );
@@ -371,7 +371,7 @@
372372 );
373373
374374 // first upload .... should succeed
375 -
 375+
376376 if (! $this->fakeUploadFile( 'file', $fileName, $mimeType, $filePaths[0] ) ) {
377377 $this->markTestIncomplete( "Couldn't upload file!\n" );
378378 }
@@ -386,7 +386,7 @@
387387 $this->assertEquals( 'Success', $result['upload']['result'] );
388388 $this->assertFalse( $exception );
389389
390 - // second upload with the same name (but different content)
 390+ // second upload with the same name (but different content)
391391
392392 if (! $this->fakeUploadFile( 'file', $fileName, $mimeType, $filePaths[1] ) ) {
393393 $this->markTestIncomplete( "Couldn't upload file!\n" );
@@ -414,7 +414,7 @@
415415 /**
416416 * @depends testLogin
417417 */
418 - public function testUploadSameContent( $session ) {
 418+ public function testUploadSameContent( $session ) {
419419 global $wgUser;
420420 $wgUser = self::$users['uploader']->user;
421421
@@ -428,7 +428,7 @@
429429 $this->markTestIncomplete( $e->getMessage() );
430430 }
431431 $filePaths = $randomImageGenerator->writeImages( 1, $extension, dirname( wfTempDir() ) );
432 - $fileNames[0] = basename( $filePaths[0] );
 432+ $fileNames[0] = basename( $filePaths[0] );
433433 $fileNames[1] = "SameContentAs" . $fileNames[0];
434434
435435 // clear any other files with the same name or content
@@ -437,7 +437,7 @@
438438 $this->deleteFileByFileName( $fileNames[1] );
439439
440440 // first upload .... should succeed
441 -
 441+
442442 $params = array(
443443 'action' => 'upload',
444444 'filename' => $fileNames[0],
@@ -445,7 +445,7 @@
446446 'comment' => 'dummy comment',
447447 'text' => "This is the page text for " . $fileNames[0],
448448 );
449 -
 449+
450450 if (! $this->fakeUploadFile( 'file', $fileNames[0], $mimeType, $filePaths[0] ) ) {
451451 $this->markTestIncomplete( "Couldn't upload file!\n" );
452452 }
@@ -461,12 +461,12 @@
462462 $this->assertFalse( $exception );
463463
464464
465 - // second upload with the same content (but different name)
 465+ // second upload with the same content (but different name)
466466
467467 if (! $this->fakeUploadFile( 'file', $fileNames[1], $mimeType, $filePaths[0] ) ) {
468468 $this->markTestIncomplete( "Couldn't upload file!\n" );
469469 }
470 -
 470+
471471 $params = array(
472472 'action' => 'upload',
473473 'filename' => $fileNames[1],
@@ -497,7 +497,7 @@
498498 /**
499499 * @depends testLogin
500500 */
501 - public function testUploadStash( $session ) {
 501+ public function testUploadStash( $session ) {
502502 global $wgUser;
503503 $wgUser = self::$users['uploader']->user;
504504
@@ -514,7 +514,7 @@
515515 $filePaths = $randomImageGenerator->writeImages( 1, $extension, dirname( wfTempDir() ) );
516516 $filePath = $filePaths[0];
517517 $fileSize = filesize( $filePath );
518 - $fileName = basename( $filePath );
 518+ $fileName = basename( $filePath );
519519
520520 $this->deleteFileByFileName( $fileName );
521521 $this->deleteFileByContent( $filePath );
@@ -545,15 +545,15 @@
546546 $this->assertEquals( $mimeType, $result['upload']['imageinfo']['mime'] );
547547 $this->assertTrue( isset( $result['upload']['sessionkey'] ) );
548548 $sessionkey = $result['upload']['sessionkey'];
549 -
550 - // it should be visible from Special:UploadStash
 549+
 550+ // it should be visible from Special:UploadStash
551551 // XXX ...but how to test this, with a fake WebRequest with the session?
552552
553553 // now we should try to release the file from stash
554554 $params = array(
555555 'action' => 'upload',
556556 'sessionkey' => $sessionkey,
557 - 'filename' => $fileName,
 557+ 'filename' => $fileName,
558558 'comment' => 'dummy comment',
559559 'text' => "This is the page text for $fileName, altered",
560560 );
@@ -581,7 +581,7 @@
582582 * @param $title Title: title to be removed
583583 */
584584 public function deleteFileByTitle( $title ) {
585 - if ( $title->exists() ) {
 585+ if ( $title->exists() ) {
586586 $file = wfFindFile( $title, array( 'ignoreRedirect' => true ) );
587587 $noOldArchive = ""; // yes this really needs to be set this way
588588 $comment = "removing for test";
@@ -593,14 +593,14 @@
594594 $article = new Article( $title );
595595 $article->doDeleteArticle( "removing for test" );
596596
597 - // see if it now doesn't exist; reload
 597+ // see if it now doesn't exist; reload
598598 $title = Title::newFromText( $fileName, NS_FILE );
599599 }
600600 return ! ( $title && $title instanceof Title && $title->exists() );
601601 }
602602
603603 /**
604 - * Helper function -- remove files and associated articles with a particular filename
 604+ * Helper function -- remove files and associated articles with a particular filename
605605 * @param $fileName String: filename to be removed
606606 */
607607 public function deleteFileByFileName( $fileName ) {
@@ -622,10 +622,10 @@
623623 return $success;
624624 }
625625
626 - /**
 626+ /**
627627 * Fake an upload by dumping the file into temp space, and adding info to $_FILES.
628628 * (This is what PHP would normally do).
629 - * @param $fieldName String: name this would have in the upload form
 629+ * @param $fieldName String: name this would have in the upload form
630630 * @param $fileName String: name to title this
631631 * @param $type String: mime type
632632 * @param $filePath String: path where to find file contents
@@ -636,7 +636,7 @@
637637 throw new Exception( "$filePath doesn't exist!" );
638638 };
639639
640 - if ( !copy( $filePath, $tmpName ) ) {
 640+ if ( !copy( $filePath, $tmpName ) ) {
641641 throw new Exception( "couldn't copy $filePath to $tmpName" );
642642 }
643643
Index: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiWatchTest.php
@@ -75,7 +75,7 @@
7676 $this->assertArrayHasKey( 'protecttoken', $data[0]['query']['pages'][$key] );
7777 }
7878
79 - return $data;
 79+ return $data;
8080 }
8181
8282 function testGetToken() {
@@ -161,7 +161,7 @@
162162 if ( !Title::newFromText( 'Main Page' )->exists() ) {
163163 $this->markTestIncomplete( "The article [[Main Page]] does not exist" );
164164 }
165 -
 165+
166166 $data = $this->doApiRequest( array(
167167 'action' => 'query',
168168 'prop' => 'revisions',
@@ -172,7 +172,7 @@
173173 $this->assertArrayHasKey( 'pages', $data[0]['query'] );
174174 $keys = array_keys( $data[0]['query']['pages'] );
175175 $key = array_pop( $keys );
176 -
 176+
177177 if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) {
178178 $this->markTestIncomplete( "Target page (Main Page) doesn't exist" );
179179 }
@@ -232,6 +232,6 @@
233233 'action' => 'query',
234234 'list' => 'watchlist' ), $data );
235235
236 - $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );
 236+ $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );
237237 }
238238 }
Index: trunk/phase3/maintenance/tests/phpunit/includes/api/generateRandomImages.php
@@ -2,7 +2,7 @@
33
44 require("RandomImageGenerator.php");
55
6 -$getOptSpec = array(
 6+$getOptSpec = array(
77 'dictionaryFile::',
88 'minWidth::',
99 'maxWidth::',

Status & tagging log