Make tests more portable. Prepping for initial CI use.
authorMark A. Hershberger <mah@users.mediawiki.org>
Wed, 26 May 2010 04:32:17 +0000 (04:32 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Wed, 26 May 2010 04:32:17 +0000 (04:32 +0000)
* Use wfTempDir for writing files to avoid permission errors
* Skip search engine tests on non-mysql DBs.
* Make title tests more portable

maintenance/tests/CdbTest.php
maintenance/tests/SearchEngineTest.php
maintenance/tests/TitlePermissionTest.php
maintenance/tests/UploadFromUrlTest.php
maintenance/tests/UploadFromUrlTestSuite.php
maintenance/tests/bootstrap.php

index dbe8268..8b7afd5 100644 (file)
@@ -13,8 +13,13 @@ class CdbTest extends PHPUnit_Framework_TestCase {
        }
 
        public function testCdb() {
-               $w1 = new CdbWriter_PHP( 'php.cdb' );
-               $w2 = new CdbWriter_DBA( 'dba.cdb' );
+               $dir = wfTempDir();
+               if ( !is_writable( $dir ) ) {
+                       $this->markTestSkipped( "Temp dir isn't writable" );
+               }
+
+               $w1 = new CdbWriter_PHP( "$dir/php.cdb" );
+               $w2 = new CdbWriter_DBA( "$dir/dba.cdb" );
 
                $data = array();
                for ( $i = 0; $i < 1000; $i++ ) {
@@ -32,13 +37,13 @@ class CdbTest extends PHPUnit_Framework_TestCase {
                $w2->close();
 
                $this->assertEquals(
-                       md5_file( 'dba.cdb' ),
-                       md5_file( 'php.cdb' ),
+                       md5_file( "$dir/dba.cdb" ),
+                       md5_file( "$dir/php.cdb" ),
                        'same hash'
                );
 
-               $r1 = new CdbReader_PHP( 'php.cdb' );
-               $r2 = new CdbReader_DBA( 'dba.cdb' );
+               $r1 = new CdbReader_PHP( "$dir/php.cdb" );
+               $r2 = new CdbReader_DBA( "$dir/dba.cdb" );
 
                foreach ( $data as $key => $value ) {
                        if ( $key === '' ) {
@@ -56,8 +61,8 @@ class CdbTest extends PHPUnit_Framework_TestCase {
                        $this->cdbAssert( "DBA error", $key, $v2, $value );
                }
 
-               unlink( 'dba.cdb' );
-               unlink( 'php.cdb' );
+               unlink( "$dir/dba.cdb" );
+               unlink( "$dir/php.cdb" );
        }
 
        private function randomString() {
index a8341e3..49a4633 100644 (file)
@@ -45,6 +45,7 @@ class SearchEngineTest extends MediaWiki_Setup {
        }
 
        function fetchIds( $results ) {
+               if ( $this->db->getType() !== 'mysql' ) $this->markTestSkipped( "MySQL only" );
                $matches = array();
                while ( $row = $results->next() ) {
                        $matches[] = $row->getTitle()->getPrefixedText();
@@ -130,8 +131,8 @@ class SearchEngineTest extends MediaWiki_Setup {
                 "Search for normalized from Full-width Lower" );
        }
 
-        function testTextSearch() {
-            $this->assertEquals(
+       function testTextSearch() {
+               $this->assertEquals(
                 array( 'Smithee' ),
                 $this->fetchIds( $this->search->searchText( 'smithee' ) ),
                 "Plain search failed" );
index 2b9131c..6420266 100644 (file)
@@ -66,6 +66,9 @@ class TitlePermissionTest extends PhpUnit_Framework_TestCase {
        }
 
        function testQuickPermissions() {
+               global $wgContLang;
+               $prefix = $wgContLang->getNsText( NS_PROJECT );
+
                $this->setUser( 'anon' );
                $this->setTitle( NS_TALK );
                $this->setUserPerm( "createtalk" );
@@ -251,10 +254,10 @@ class TitlePermissionTest extends PhpUnit_Framework_TestCase {
                $this->assertEquals( array( ), $res );
 
                $this->setUser( 'anon' );
-               $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[Mw:Users|Users]]", 2 ) ),
+               $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
                                                                                 array( array( 'badaccess-group0' ) ),
                                                                                 array( ), true ),
-                                               'protect' => array( array( array( 'badaccess-groups', "[[Mw:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
+                                               'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
                                                                                        array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
                                                                                        array( array( 'protect-cantedit' ) ), false ),
                                                '' => array( array( ), array( ), array( ), true ) );
@@ -316,14 +319,15 @@ class TitlePermissionTest extends PhpUnit_Framework_TestCase {
        function testPermissionHooks() { }
        function testSpecialsAndNSPermissions() {
                $this->setUser( self::$userName );
-               global $wgUser;
+               global $wgUser, $wgContLang;
                $wgUser = self::$user;
+               $prefix = $wgContLang->getNsText( NS_PROJECT );
 
                $this->setTitle( NS_SPECIAL );
 
                $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
                                                         self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
-               $this->assertEquals( array( array( 'badaccess-groups', '*, [[Mw:Administrators|Administrators]]', 2 ) ),
+               $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Administrators|Administrators]]", 2 ) ),
                                                         self::$title->getUserPermissionsErrors( 'createaccount', self::$user ) );
                $this->assertEquals( array( array( 'badaccess-group0' ) ),
                                                         self::$title->getUserPermissionsErrors( 'execute', self::$user ) );
@@ -421,7 +425,10 @@ class TitlePermissionTest extends PhpUnit_Framework_TestCase {
        }
 
        function testPageRestrictions() {
-               global $wgUser;
+               global $wgUser, $wgContLang;
+
+               $prefix = $wgContLang->getNsText( NS_PROJECT );
+
                $wgUser = self::$user;
                $this->setTitle( NS_MAIN );
                self::$title->mRestrictionsLoaded = true;
@@ -455,7 +462,7 @@ class TitlePermissionTest extends PhpUnit_Framework_TestCase {
                                                                        array( 'protectedpagetext', 'protect' ) ),
                                                         self::$title->getUserPermissionsErrors( 'bogus',
                                                                                                                                         self::$user ) );
-               $this->assertEquals( array( array( 'badaccess-groups', '*, [[Mw:Users|Users]]', 2 ),
+               $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
                                                                        array( 'protectedpagetext', 'bogus' ),
                                                                        array( 'protectedpagetext', 'protect' ),
                                                                        array( 'protectedpagetext', 'protect' ) ),
index 8d2e0ca..9294fa9 100644 (file)
@@ -18,14 +18,6 @@ class UploadFromUrlTest extends ApiSetup {
                $wgEnableUploads = true;
                $wgAllowCopyUploads = true;
                parent::setup();
-               $wgLocalFileRepo = array(
-                       'class' => 'LocalRepo',
-                       'name' => 'local',
-                       'directory' => 'test-repo',
-                       'url' => 'http://example.com/images',
-                       'hashLevels' => 2,
-                       'transformVia404' => false,
-               );
 
                ini_set( 'log_errors', 1 );
                ini_set( 'error_reporting', 1 );
@@ -174,6 +166,7 @@ class UploadFromUrlTest extends ApiSetup {
                $this->assertEquals( 'UploadFromUrlJob', get_class( $job ) );
 
                $status = $job->run();
+
                $this->assertTrue( $status->isOk() );
 
                return $data;
index 80bbbd6..314be76 100644 (file)
@@ -30,7 +30,7 @@ class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite
                $wgLocalFileRepo = array(
                        'class' => 'LocalRepo',
                        'name' => 'local',
-                       'directory' => 'test-repo',
+                       'directory' => wfTempDir().'/test-repo',
                        'url' => 'http://example.com/images',
                        'hashLevels' => 2,
                        'transformVia404' => false,
index 52f7a41..3783191 100644 (file)
@@ -14,6 +14,10 @@ define( 'MW_PHPUNIT_TEST', true );
 require_once( "$IP/maintenance/commandLine.inc" );
 $wgLocaltimezone = 'UTC';
 
+/* Tests were failing with sqlite */
+global $wgCaches;
+$wgCaches[CACHE_DB] = false;
+
 if ( !version_compare( PHPUnit_Runner_Version::id(), "3.4.1", ">" ) ) {
   echo <<<EOF
 ************************************************************