r66906 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66905‎ | r66906 | r66907 >
Date:04:32, 26 May 2010
Author:mah
Status:ok
Tags:
Comment:
Make tests more portable. Prepping for initial CI use.

* Use wfTempDir for writing files to avoid permission errors
* Skip search engine tests on non-mysql DBs.
* Make title tests more portable
Modified paths:
  • /trunk/phase3/maintenance/tests/CdbTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/SearchEngineTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/TitlePermissionTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/UploadFromUrlTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/UploadFromUrlTestSuite.php (modified) (history)
  • /trunk/phase3/maintenance/tests/bootstrap.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/SearchEngineTest.php
@@ -45,6 +45,7 @@
4646 }
4747
4848 function fetchIds( $results ) {
 49+ if ( $this->db->getType() !== 'mysql' ) $this->markTestSkipped( "MySQL only" );
4950 $matches = array();
5051 while ( $row = $results->next() ) {
5152 $matches[] = $row->getTitle()->getPrefixedText();
@@ -130,8 +131,8 @@
131132 "Search for normalized from Full-width Lower" );
132133 }
133134
134 - function testTextSearch() {
135 - $this->assertEquals(
 135+ function testTextSearch() {
 136+ $this->assertEquals(
136137 array( 'Smithee' ),
137138 $this->fetchIds( $this->search->searchText( 'smithee' ) ),
138139 "Plain search failed" );
Index: trunk/phase3/maintenance/tests/UploadFromUrlTestSuite.php
@@ -30,7 +30,7 @@
3131 $wgLocalFileRepo = array(
3232 'class' => 'LocalRepo',
3333 'name' => 'local',
34 - 'directory' => 'test-repo',
 34+ 'directory' => wfTempDir().'/test-repo',
3535 'url' => 'http://example.com/images',
3636 'hashLevels' => 2,
3737 'transformVia404' => false,
Index: trunk/phase3/maintenance/tests/bootstrap.php
@@ -14,6 +14,10 @@
1515 require_once( "$IP/maintenance/commandLine.inc" );
1616 $wgLocaltimezone = 'UTC';
1717
 18+/* Tests were failing with sqlite */
 19+global $wgCaches;
 20+$wgCaches[CACHE_DB] = false;
 21+
1822 if ( !version_compare( PHPUnit_Runner_Version::id(), "3.4.1", ">" ) ) {
1923 echo <<<EOF
2024 ************************************************************
Index: trunk/phase3/maintenance/tests/TitlePermissionTest.php
@@ -66,6 +66,9 @@
6767 }
6868
6969 function testQuickPermissions() {
 70+ global $wgContLang;
 71+ $prefix = $wgContLang->getNsText( NS_PROJECT );
 72+
7073 $this->setUser( 'anon' );
7174 $this->setTitle( NS_TALK );
7275 $this->setUserPerm( "createtalk" );
@@ -251,10 +254,10 @@
252255 $this->assertEquals( array( ), $res );
253256
254257 $this->setUser( 'anon' );
255 - $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[Mw:Users|Users]]", 2 ) ),
 258+ $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
256259 array( array( 'badaccess-group0' ) ),
257260 array( ), true ),
258 - 'protect' => array( array( array( 'badaccess-groups', "[[Mw:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
 261+ 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
259262 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
260263 array( array( 'protect-cantedit' ) ), false ),
261264 '' => array( array( ), array( ), array( ), true ) );
@@ -316,14 +319,15 @@
317320 function testPermissionHooks() { }
318321 function testSpecialsAndNSPermissions() {
319322 $this->setUser( self::$userName );
320 - global $wgUser;
 323+ global $wgUser, $wgContLang;
321324 $wgUser = self::$user;
 325+ $prefix = $wgContLang->getNsText( NS_PROJECT );
322326
323327 $this->setTitle( NS_SPECIAL );
324328
325329 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
326330 self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
327 - $this->assertEquals( array( array( 'badaccess-groups', '*, [[Mw:Administrators|Administrators]]', 2 ) ),
 331+ $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Administrators|Administrators]]", 2 ) ),
328332 self::$title->getUserPermissionsErrors( 'createaccount', self::$user ) );
329333 $this->assertEquals( array( array( 'badaccess-group0' ) ),
330334 self::$title->getUserPermissionsErrors( 'execute', self::$user ) );
@@ -421,7 +425,10 @@
422426 }
423427
424428 function testPageRestrictions() {
425 - global $wgUser;
 429+ global $wgUser, $wgContLang;
 430+
 431+ $prefix = $wgContLang->getNsText( NS_PROJECT );
 432+
426433 $wgUser = self::$user;
427434 $this->setTitle( NS_MAIN );
428435 self::$title->mRestrictionsLoaded = true;
@@ -455,7 +462,7 @@
456463 array( 'protectedpagetext', 'protect' ) ),
457464 self::$title->getUserPermissionsErrors( 'bogus',
458465 self::$user ) );
459 - $this->assertEquals( array( array( 'badaccess-groups', '*, [[Mw:Users|Users]]', 2 ),
 466+ $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
460467 array( 'protectedpagetext', 'bogus' ),
461468 array( 'protectedpagetext', 'protect' ),
462469 array( 'protectedpagetext', 'protect' ) ),
Index: trunk/phase3/maintenance/tests/UploadFromUrlTest.php
@@ -18,14 +18,6 @@
1919 $wgEnableUploads = true;
2020 $wgAllowCopyUploads = true;
2121 parent::setup();
22 - $wgLocalFileRepo = array(
23 - 'class' => 'LocalRepo',
24 - 'name' => 'local',
25 - 'directory' => 'test-repo',
26 - 'url' => 'http://example.com/images',
27 - 'hashLevels' => 2,
28 - 'transformVia404' => false,
29 - );
3022
3123 ini_set( 'log_errors', 1 );
3224 ini_set( 'error_reporting', 1 );
@@ -174,6 +166,7 @@
175167 $this->assertEquals( 'UploadFromUrlJob', get_class( $job ) );
176168
177169 $status = $job->run();
 170+
178171 $this->assertTrue( $status->isOk() );
179172
180173 return $data;
Index: trunk/phase3/maintenance/tests/CdbTest.php
@@ -13,9 +13,14 @@
1414 }
1515
1616 public function testCdb() {
17 - $w1 = new CdbWriter_PHP( 'php.cdb' );
18 - $w2 = new CdbWriter_DBA( 'dba.cdb' );
 17+ $dir = wfTempDir();
 18+ if ( !is_writable( $dir ) ) {
 19+ $this->markTestSkipped( "Temp dir isn't writable" );
 20+ }
1921
 22+ $w1 = new CdbWriter_PHP( "$dir/php.cdb" );
 23+ $w2 = new CdbWriter_DBA( "$dir/dba.cdb" );
 24+
2025 $data = array();
2126 for ( $i = 0; $i < 1000; $i++ ) {
2227 $key = $this->randomString();
@@ -32,13 +37,13 @@
3338 $w2->close();
3439
3540 $this->assertEquals(
36 - md5_file( 'dba.cdb' ),
37 - md5_file( 'php.cdb' ),
 41+ md5_file( "$dir/dba.cdb" ),
 42+ md5_file( "$dir/php.cdb" ),
3843 'same hash'
3944 );
4045
41 - $r1 = new CdbReader_PHP( 'php.cdb' );
42 - $r2 = new CdbReader_DBA( 'dba.cdb' );
 46+ $r1 = new CdbReader_PHP( "$dir/php.cdb" );
 47+ $r2 = new CdbReader_DBA( "$dir/dba.cdb" );
4348
4449 foreach ( $data as $key => $value ) {
4550 if ( $key === '' ) {
@@ -56,8 +61,8 @@
5762 $this->cdbAssert( "DBA error", $key, $v2, $value );
5863 }
5964
60 - unlink( 'dba.cdb' );
61 - unlink( 'php.cdb' );
 65+ unlink( "$dir/dba.cdb" );
 66+ unlink( "$dir/php.cdb" );
6267 }
6368
6469 private function randomString() {

Status & tagging log