From: Mark A. Hershberger Date: Wed, 1 Dec 2010 21:16:47 +0000 (+0000) Subject: * w/s fixup explosion for tests (aka “my OCD takes over”) X-Git-Tag: 1.31.0-rc.0~33657 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=f05219ce369532ee7561001cbc2330743c4487a7;p=lhc%2Fweb%2Fwiklou.git * w/s fixup explosion for tests (aka “my OCD takes over”) * “svn diff -x-w” shows no changes --- diff --git a/maintenance/tests/parserTests.php b/maintenance/tests/parserTests.php index 7895aaa13e..886d92c8d6 100644 --- a/maintenance/tests/parserTests.php +++ b/maintenance/tests/parserTests.php @@ -30,7 +30,7 @@ $optionsWithArgs = array( 'regex', 'seed', 'setversion' ); require_once( dirname( __FILE__ ) . '/../commandLine.inc' ); if ( isset( $options['help'] ) ) { - echo << Run test cases from a custom file instead of parserTests.txt --record Record tests in database @@ -54,7 +54,7 @@ Options: --upload Upload test results to remote wiki (per \$wgParserTestRemote) ENDS; - exit( 0 ); + exit( 0 ); } # Cases of weird db corruption were encountered when running tests on earlyish diff --git a/maintenance/tests/phpunit/includes/GlobalTest.php b/maintenance/tests/phpunit/includes/GlobalTest.php index 43eb28bf4c..c4bfe7033f 100644 --- a/maintenance/tests/phpunit/includes/GlobalTest.php +++ b/maintenance/tests/phpunit/includes/GlobalTest.php @@ -8,7 +8,7 @@ class GlobalTest extends PHPUnit_Framework_TestCase { unlink( $wgReadOnlyFile ); $wgContLang = $wgLang = Language::factory( 'en' ); } - + function tearDown() { global $wgReadOnlyFile; if ( file_exists( $wgReadOnlyFile ) ) { @@ -16,7 +16,7 @@ class GlobalTest extends PHPUnit_Framework_TestCase { } $wgReadOnlyFile = $this->originals['wgReadOnlyFile']; } - + function testRandom() { # This could hypothetically fail, but it shouldn't ;) $this->assertFalse( @@ -32,25 +32,25 @@ class GlobalTest extends PHPUnit_Framework_TestCase { function testReadOnlyEmpty() { global $wgReadOnly; $wgReadOnly = null; - + $this->assertFalse( wfReadOnly() ); $this->assertFalse( wfReadOnly() ); } function testReadOnlySet() { global $wgReadOnly, $wgReadOnlyFile; - + $f = fopen( $wgReadOnlyFile, "wt" ); fwrite( $f, 'Message' ); fclose( $f ); $wgReadOnly = null; - + $this->assertTrue( wfReadOnly() ); $this->assertTrue( wfReadOnly() ); unlink( $wgReadOnlyFile ); $wgReadOnly = null; - + $this->assertFalse( wfReadOnly() ); $this->assertFalse( wfReadOnly() ); } @@ -195,53 +195,53 @@ class GlobalTest extends PHPUnit_Framework_TestCase { '20010115T123456Z', wfTimestamp( TS_ISO_8601_BASIC, '2001-01-15 12:34:56' ), 'TS_DB to TS_ISO_8601_BASIC' ); - + # rfc2822 section 3.3 - + $this->assertEquals( 'Mon, 15 Jan 2001 12:34:56 GMT', wfTimestamp( TS_RFC2822, '20010115123456' ), 'TS_MW to TS_RFC2822' ); - + $this->assertEquals( '20010115123456', wfTimestamp( TS_MW, 'Mon, 15 Jan 2001 12:34:56 GMT' ), 'TS_RFC2822 to TS_MW' ); - + $this->assertEquals( '20010115123456', wfTimestamp( TS_MW, ' Mon, 15 Jan 2001 12:34:56 GMT' ), 'TS_RFC2822 with leading space to TS_MW' ); - + $this->assertEquals( '20010115123456', wfTimestamp( TS_MW, '15 Jan 2001 12:34:56 GMT' ), 'TS_RFC2822 without optional day-of-week to TS_MW' ); - + # FWS = ([*WSP CRLF] 1*WSP) / obs-FWS ; Folding white space - # obs-FWS = 1*WSP *(CRLF 1*WSP) ; Section 4.2 + # obs-FWS = 1*WSP *(CRLF 1*WSP) ; Section 4.2 $this->assertEquals( '20010115123456', wfTimestamp( TS_MW, 'Mon, 15 Jan 2001 12:34:56 GMT' ), 'TS_RFC2822 to TS_MW' ); - + # WSP = SP / HTAB ; rfc2234 $this->assertEquals( '20010115123456', wfTimestamp( TS_MW, "Mon, 15 Jan\x092001 12:34:56 GMT" ), 'TS_RFC2822 with HTAB to TS_MW' ); - + $this->assertEquals( '20010115123456', wfTimestamp( TS_MW, "Mon, 15 Jan\x09 \x09 2001 12:34:56 GMT" ), 'TS_RFC2822 with HTAB and SP to TS_MW' ); - + $this->assertEquals( '19941106084937', wfTimestamp( TS_MW, "Sun, 6 Nov 94 08:49:37 GMT" ), 'TS_RFC2822 with obsolete year to TS_MW' ); } - + /** * This test checks wfTimestamp() with values outside. * It needs PHP 64 bits or PHP > 5.1. @@ -310,8 +310,8 @@ class GlobalTest extends PHPUnit_Framework_TestCase { wfTimestamp( TS_RFC2822, '-62135596800'), 'Year 1'); - /* It is not clear if we should generate a year 0 or not - * We are completely off RFC2822 requirement of year being + /* It is not clear if we should generate a year 0 or not + * We are completely off RFC2822 requirement of year being * 1900 or later. */ $this->assertEquals( 'Wed, 18 Oct 0000 00:00:00 GMT', @@ -320,32 +320,32 @@ class GlobalTest extends PHPUnit_Framework_TestCase { } function testHttpDate() { - # The Resource Loader uses wfTimestamp() to convert timestamps + # The Resource Loader uses wfTimestamp() to convert timestamps # from If-Modified-Since header. # Thus it must be able to parse all rfc2616 date formats # http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1 - + $this->assertEquals( '19941106084937', wfTimestamp( TS_MW, 'Sun, 06 Nov 1994 08:49:37 GMT' ), 'RFC 822 date' ); - + $this->assertEquals( '19941106084937', wfTimestamp( TS_MW, 'Sunday, 06-Nov-94 08:49:37 GMT' ), 'RFC 850 date' ); - + $this->assertEquals( '19941106084937', wfTimestamp( TS_MW, 'Sun Nov 6 08:49:37 1994' ), "ANSI C's asctime() format" ); - + // See http://www.squid-cache.org/mail-archive/squid-users/200307/0122.html and r77171 $this->assertEquals( '20101122141242', wfTimestamp( TS_MW, 'Mon, 22 Nov 2010 14:12:42 GMT; length=52626' ), "Netscape extension to HTTP/1.0" ); - + } function testBasename() { diff --git a/maintenance/tests/phpunit/includes/IPTest.php b/maintenance/tests/phpunit/includes/IPTest.php index ff05ae285c..ee092997bd 100644 --- a/maintenance/tests/phpunit/includes/IPTest.php +++ b/maintenance/tests/phpunit/includes/IPTest.php @@ -1,10 +1,10 @@ assertFalse( IP::isIPAddress( false ), 'Boolean false is not an IP' ); $this->assertFalse( IP::isIPAddress( true ), 'Boolean true is not an IP' ); @@ -24,7 +24,7 @@ class IPTest extends PHPUnit_Framework_TestCase { $this->assertTrue( IP::isIPAddress( '74.24.52.13/20', 'IPv4 range' ) ); $this->assertTrue( IP::isIPAddress( 'fc:100:a:d:1:e:ac:0/24' ), 'IPv6 range' ); $this->assertTrue( IP::isIPAddress( 'fc::100:a:d:1:e:ac/96' ), 'IPv6 range with "::"' ); - + $validIPs = array( 'fc:100::', 'fc:100:a:d:1:e:ac::', 'fc::100', '::fc:100:a:d:1:e:ac', '::fc', 'fc::100:a:d:1:e:ac', 'fc:100:a:d:1:e:ac:0', '124.24.52.13', '1.24.52.13' ); foreach ( $validIPs as $ip ) { @@ -114,7 +114,7 @@ class IPTest extends PHPUnit_Framework_TestCase { // tests isValid() public function testInvalidIPs() { - // Out of range... + // Out of range... foreach ( range( 256, 999 ) as $i ) { $a = sprintf( "%03d", $i ); $b = sprintf( "%02d", $i ); @@ -267,7 +267,7 @@ class IPTest extends PHPUnit_Framework_TestCase { * representing the network mask and the bit mask. */ function testCIDRParsing() { - $this->assertFalseCIDR( '192.0.2.0' , "missing mask" ); + $this->assertFalseCIDR( '192.0.2.0' , "missing mask" ); $this->assertFalseCIDR( '192.0.2.0/', "missing bitmask" ); // Verify if statement @@ -283,7 +283,7 @@ class IPTest extends PHPUnit_Framework_TestCase { $this->assertEquals( array( 0, 0 ), IP::parseCIDR('255.255.255.255/0') ); // FIXME : add more tests. - + # This part test network shifting $this->assertNet( '192.0.0.0' , '192.0.0.2/24' ); $this->assertNet( '192.168.5.0', '192.168.5.13/24'); @@ -293,6 +293,6 @@ class IPTest extends PHPUnit_Framework_TestCase { $this->assertNet( '10.0.0.4' , '10.0.0.4/30' ); $this->assertNet( '172.17.32.0', '172.17.35.48/21' ); $this->assertNet( '10.128.0.0' , '10.135.0.0/9' ); - $this->assertNet( '134.0.0.0' , '134.0.5.1/8' ); + $this->assertNet( '134.0.0.0' , '134.0.5.1/8' ); } } diff --git a/maintenance/tests/phpunit/includes/ParserOptionsTest.php b/maintenance/tests/phpunit/includes/ParserOptionsTest.php index 2566ac352d..63d98e7c93 100644 --- a/maintenance/tests/phpunit/includes/ParserOptionsTest.php +++ b/maintenance/tests/phpunit/includes/ParserOptionsTest.php @@ -4,33 +4,33 @@ class ParserOptionsTest extends PHPUnit_Framework_TestCase { private $popts; private $pcache; - + function setUp() { ParserTest::setUp(); //reuse setup from parser tests global $wgContLang, $wgUser; $wgContLang = new StubContLang; $this->popts = new ParserOptions( $wgUser ); - $this->pcache = ParserCache::singleton(); + $this->pcache = ParserCache::singleton(); } - + function tearDown() { parent::tearDown(); } - + /** * ParserOptions::optionsHash was not giving consistent results when $wgUseDynamicDates was set * @group Database */ - function testGetParserCacheKeyWithDynamicDates() { + function testGetParserCacheKeyWithDynamicDates() { global $wgUseDynamicDates; $wgUseDynamicDates = true; - + $title = Title::newFromText( "Some test article" ); - $article = new Article( $title ); - + $article = new Article( $title ); + $pcacheKeyBefore = $this->pcache->getKey( $article, $this->popts ); $this->assertNotNull( $this->popts->getDateFormat() ); - $pcacheKeyAfter = $this->pcache->getKey( $article, $this->popts ); - $this->assertEquals( $pcacheKeyBefore, $pcacheKeyAfter ); + $pcacheKeyAfter = $this->pcache->getKey( $article, $this->popts ); + $this->assertEquals( $pcacheKeyBefore, $pcacheKeyAfter ); } } diff --git a/maintenance/tests/phpunit/includes/SeleniumConfigurationTest.php b/maintenance/tests/phpunit/includes/SeleniumConfigurationTest.php index 7841e2fb0a..16a916ed6c 100644 --- a/maintenance/tests/phpunit/includes/SeleniumConfigurationTest.php +++ b/maintenance/tests/phpunit/includes/SeleniumConfigurationTest.php @@ -4,14 +4,14 @@ class SeleniumConfigurationTest extends PHPUnit_Framework_TestCase { /* * The file where the test temporarity stores the selenium config. - * This should be cleaned up as part of teardown. + * This should be cleaned up as part of teardown. */ private $tempFileName; - + /* * String containing the a sample selenium settings */ - private $testConfig0 = + private $testConfig0 = ' [SeleniumSettings] browsers[firefox] = "*firefox" @@ -30,7 +30,7 @@ runAgainstGrid = false [SeleniumTests] testSuite[SimpleSeleniumTestSuite] = "maintenance/tests/selenium/SimpleSeleniumTestSuite.php" -testSuite[TestSuiteName] = "testSuitePath" +testSuite[TestSuiteName] = "testSuitePath" '; /* * Array of expected browsers from $testConfig0 @@ -60,14 +60,14 @@ testSuite[TestSuiteName] = "testSuitePath" */ private $testSuites0 = array( 'SimpleSeleniumTestSuite' => 'maintenance/tests/selenium/SimpleSeleniumTestSuite.php', - 'TestSuiteName' => 'testSuitePath' + 'TestSuiteName' => 'testSuitePath' ); - - + + /* * Another sample selenium settings file contents */ - private $testConfig1 = + private $testConfig1 = ' [SeleniumSettings] host = "localhost" @@ -96,15 +96,15 @@ testBrowser = "firefox" /* * Expected test suites from $testConfig1 */ - private $testSuites1 = null; - - + private $testSuites1 = null; + + public function setUp() { if ( !defined( 'SELENIUMTEST' ) ) { define( 'SELENIUMTEST', true ); } } - + /* * Clean up the temporary file used to store the selenium settings. */ @@ -115,90 +115,90 @@ testBrowser = "firefox" } parent::tearDown(); } - + /** - * @expectedException MWException - * @group SeleniumFramework - */ - public function testErrorOnIncorrectConfigFile() { + * @expectedException MWException + * @group SeleniumFramework + */ + public function testErrorOnIncorrectConfigFile() { $seleniumSettings; $seleniumBrowsers; $seleniumTestSuites; - SeleniumConfig::getSeleniumSettings($seleniumSettings, - $seleniumBrowsers, + SeleniumConfig::getSeleniumSettings($seleniumSettings, + $seleniumBrowsers, $seleniumTestSuites, "Some_fake_settings_file.ini" ); } - + /** - * @expectedException MWException - * @group SeleniumFramework - */ - public function testErrorOnMissingConfigFile() { + * @expectedException MWException + * @group SeleniumFramework + */ + public function testErrorOnMissingConfigFile() { $seleniumSettings; $seleniumBrowsers; $seleniumTestSuites; global $wgSeleniumConfigFile; $wgSeleniumConfigFile = ''; - SeleniumConfig::getSeleniumSettings($seleniumSettings, - $seleniumBrowsers, + SeleniumConfig::getSeleniumSettings($seleniumSettings, + $seleniumBrowsers, $seleniumTestSuites); } - + /** - * @group SeleniumFramework - */ - public function testUsesGlobalVarForConfigFile() { + * @group SeleniumFramework + */ + public function testUsesGlobalVarForConfigFile() { $seleniumSettings; $seleniumBrowsers; $seleniumTestSuites; global $wgSeleniumConfigFile; $this->writeToTempFile( $this->testConfig0 ); $wgSeleniumConfigFile = $this->tempFileName; - SeleniumConfig::getSeleniumSettings($seleniumSettings, - $seleniumBrowsers, + SeleniumConfig::getSeleniumSettings($seleniumSettings, + $seleniumBrowsers, $seleniumTestSuites); $this->assertEquals($seleniumSettings, $this->testSettings0 , 'The selenium settings should have been read from the file defined in $wgSeleniumConfigFile' ); - $this->assertEquals($seleniumBrowsers, $this->testBrowsers0, + $this->assertEquals($seleniumBrowsers, $this->testBrowsers0, 'The available browsers should have been read from the file defined in $wgSeleniumConfigFile' ); - $this->assertEquals($seleniumTestSuites, $this->testSuites0, + $this->assertEquals($seleniumTestSuites, $this->testSuites0, 'The test suites should have been read from the file defined in $wgSeleniumConfigFile' - ); + ); } - + /** - * @group SeleniumFramework - * @dataProvider sampleConfigs - */ - public function testgetSeleniumSettings($sampleConfig, $expectedSettings, $expectedBrowsers, $expectedSuites ) { + * @group SeleniumFramework + * @dataProvider sampleConfigs + */ + public function testgetSeleniumSettings($sampleConfig, $expectedSettings, $expectedBrowsers, $expectedSuites ) { $this->writeToTempFile( $sampleConfig ); $seleniumSettings; $seleniumBrowsers; $seleniumTestSuites; - SeleniumConfig::getSeleniumSettings($seleniumSettings, - $seleniumBrowsers, + SeleniumConfig::getSeleniumSettings($seleniumSettings, + $seleniumBrowsers, $seleniumTestSuites, $this->tempFileName ); - - $this->assertEquals($seleniumSettings, $expectedSettings, + + $this->assertEquals($seleniumSettings, $expectedSettings, "The selenium settings for the following test configuration was not retrieved correctly" . $sampleConfig ); - $this->assertEquals($seleniumBrowsers, $expectedBrowsers, + $this->assertEquals($seleniumBrowsers, $expectedBrowsers, "The available browsers for the following test configuration was not retrieved correctly" . $sampleConfig ); - $this->assertEquals($seleniumTestSuites, $expectedSuites, + $this->assertEquals($seleniumTestSuites, $expectedSuites, "The test suites for the following test configuration was not retrieved correctly" . $sampleConfig ); - - + + } - + /* * create a temp file and write text to it. * @param $testToWrite the text to write to the temp file @@ -209,11 +209,11 @@ testBrowser = "firefox" fwrite($tempFile , $textToWrite); fclose($tempFile); } - + /* * Returns an array containing: * The contents of the selenium cingiguration ini file - * The expected selenium configuration array that getSeleniumSettings should return + * The expected selenium configuration array that getSeleniumSettings should return * The expected available browsers array that getSeleniumSettings should return * The expected test suites arrya that getSeleniumSettings should return */ @@ -223,6 +223,6 @@ testBrowser = "firefox" array($this->testConfig1, $this->testSettings1, $this->testBrowsers1, $this->testSuites1 ) ); } - + } diff --git a/maintenance/tests/phpunit/includes/SiteConfigurationTest.php b/maintenance/tests/phpunit/includes/SiteConfigurationTest.php index dec5d5fa02..9bfab9ede2 100644 --- a/maintenance/tests/phpunit/includes/SiteConfigurationTest.php +++ b/maintenance/tests/phpunit/includes/SiteConfigurationTest.php @@ -287,7 +287,7 @@ class SiteConfigurationTest extends PHPUnit_Framework_TestCase { 'get(): parameter replacement on an non-existing wiki' ); } - + function testGetAll() { $this->mConf->siteParamsCallback = 'getSiteParams'; diff --git a/maintenance/tests/phpunit/includes/TitlePermissionTest.php b/maintenance/tests/phpunit/includes/TitlePermissionTest.php index 81b3f6efae..fa83b9a669 100644 --- a/maintenance/tests/phpunit/includes/TitlePermissionTest.php +++ b/maintenance/tests/phpunit/includes/TitlePermissionTest.php @@ -273,7 +273,7 @@ class TitlePermissionTest extends PHPUnit_Framework_TestCase { '' => array( array( ), array( ), array( ), true ) ); global $wgUser; $wgUser = self::$user; - foreach ( array( "edit", "protect", "" ) as $action ) { + foreach ( array( "edit", "protect", "" ) as $action ) { $this->setUserPerm( null ); $this->assertEquals( $check[$action][0], self::$title->getUserPermissionsErrors( $action, self::$user, true ) ); diff --git a/maintenance/tests/phpunit/includes/UploadFromUrlTest.php b/maintenance/tests/phpunit/includes/UploadFromUrlTest.php index 6c4a4106ee..8382299289 100644 --- a/maintenance/tests/phpunit/includes/UploadFromUrlTest.php +++ b/maintenance/tests/phpunit/includes/UploadFromUrlTest.php @@ -19,7 +19,7 @@ class UploadFromUrlTest extends ApiTestSetup { ini_set( 'log_errors', 1 ); ini_set( 'error_reporting', 1 ); ini_set( 'display_errors', 1 ); - + if ( wfLocalFile( 'UploadFromUrlTest.png' )->exists() ) { $this->deleteFile( 'UploadFromUrlTest.png' ); } @@ -28,7 +28,7 @@ class UploadFromUrlTest extends ApiTestSetup { protected function doApiRequest( $params, $unused = null ) { $sessionId = session_id(); session_write_close(); - + $req = new FauxRequest( $params, true, $_SESSION ); $module = new ApiMain( $req, true ); $module->execute(); @@ -77,7 +77,7 @@ class UploadFromUrlTest extends ApiTestSetup { * @depends testLogin * @depends testClearQueue */ - public function testSetupUrlDownload( $data ) { + public function testSetupUrlDownload( $data ) { $token = self::$user->editToken(); $exception = false; @@ -142,7 +142,7 @@ class UploadFromUrlTest extends ApiTestSetup { ), $data ); $this->assertEquals( $data[0]['upload']['result'], 'Queued', 'Queued upload' ); - + $job = Job::pop(); $this->assertThat( $job, $this->isInstanceOf( 'UploadFromUrlJob' ), 'Queued upload inserted' ); } @@ -160,7 +160,7 @@ class UploadFromUrlTest extends ApiTestSetup { $this->assertEquals( $data[0]['upload']['result'], 'Success' ); $this->assertEquals( $data[0]['upload']['filename'], 'UploadFromUrlTest.png' ); $this->assertTrue( wfLocalFile( $data[0]['upload']['filename'] )->exists() ); - + $this->deleteFile( 'UploadFromUrlTest.png' ); return $data; @@ -177,11 +177,11 @@ class UploadFromUrlTest extends ApiTestSetup { $data = $this->doAsyncUpload( $token ); - + $this->assertEquals( $data[0]['upload']['result'], 'Warning' ); $this->assertTrue( isset( $data[0]['upload']['sessionkey'] ) ); - - $data = $this->doApiRequest( array( + + $data = $this->doApiRequest( array( 'action' => 'upload', 'sessionkey' => $data[0]['upload']['sessionkey'], 'filename' => 'UploadFromUrlTest.png', @@ -191,7 +191,7 @@ class UploadFromUrlTest extends ApiTestSetup { $this->assertEquals( $data[0]['upload']['result'], 'Success' ); $this->assertEquals( $data[0]['upload']['filename'], 'UploadFromUrlTest.png' ); $this->assertTrue( wfLocalFile( $data[0]['upload']['filename'] )->exists() ); - + $this->deleteFile( 'UploadFromUrlTest.png' ); return $data; @@ -224,18 +224,18 @@ class UploadFromUrlTest extends ApiTestSetup { return $data; } - + public function testLeaveMessage() { $token = self::$user->editToken(); - + $talk = self::$user->getTalkPage(); if ( $talk->exists() ) { $a = new Article( $talk ); $a->doDeleteArticle( '' ); } - + $this->assertFalse( (bool)$talk->getArticleId( Title::GAID_FOR_UPDATE ), 'User talk does not exist' ); - + $data = $this->doApiRequest( array( 'action' => 'upload', 'filename' => 'UploadFromUrlTest.png', @@ -245,19 +245,19 @@ class UploadFromUrlTest extends ApiTestSetup { 'leavemessage' => 1, 'ignorewarnings' => 1, ) ); - + $job = Job::pop(); $this->assertEquals( 'UploadFromUrlJob', get_class( $job ) ); $job->run(); - - $this->assertTrue( wfLocalFile( 'UploadFromUrlTest.png' )->exists() ); + + $this->assertTrue( wfLocalFile( 'UploadFromUrlTest.png' )->exists() ); $this->assertTrue( (bool)$talk->getArticleId( Title::GAID_FOR_UPDATE ), 'User talk exists' ); - + $this->deleteFile( 'UploadFromUrlTest.png' ); - + $talkRev = Revision::newFromTitle( $talk ); $talkSize = $talkRev->getSize(); - + $exception = false; try { $data = $this->doApiRequest( array( @@ -273,27 +273,27 @@ class UploadFromUrlTest extends ApiTestSetup { $this->assertEquals( 'Using leavemessage without ignorewarnings is not supported', $e->getMessage() ); } $this->assertTrue( $exception ); - + $job = Job::pop(); $this->assertFalse( $job ); - + return; /** // Broken until using leavemessage with ignorewarnings is supported $job->run(); - + $this->assertFalse( wfLocalFile( 'UploadFromUrlTest.png' )->exists() ); - + $talkRev = Revision::newFromTitle( $talk ); $this->assertTrue( $talkRev->getSize() > $talkSize, 'New message left' ); */ } - + /** - * Helper function to perform an async upload, execute the job and fetch + * Helper function to perform an async upload, execute the job and fetch * the status - * + * * @return array The result of action=upload&statuskey=key */ private function doAsyncUpload( $token, $ignoreWarnings = false, $leaveMessage = false ) { @@ -310,27 +310,27 @@ class UploadFromUrlTest extends ApiTestSetup { if ( $leaveMessage ) { $params['leavemessage'] = 1; } - + $data = $this->doApiRequest( $params ); $this->assertEquals( $data[0]['upload']['result'], 'Queued' ); $this->assertTrue( isset( $data[0]['upload']['statuskey'] ) ); $statusKey = $data[0]['upload']['statuskey']; - + $job = Job::pop(); $this->assertEquals( 'UploadFromUrlJob', get_class( $job ) ); - - $status = $job->run(); + + $status = $job->run(); $this->assertTrue( $status ); - - $data = $this->doApiRequest( array( + + $data = $this->doApiRequest( array( 'action' => 'upload', 'statuskey' => $statusKey, 'token' => $token, ) ); - + return $data; } - + /** * diff --git a/maintenance/tests/phpunit/includes/XmlTest.php b/maintenance/tests/phpunit/includes/XmlTest.php index 7298f9f914..f01c0f1cc4 100644 --- a/maintenance/tests/phpunit/includes/XmlTest.php +++ b/maintenance/tests/phpunit/includes/XmlTest.php @@ -115,7 +115,7 @@ class XmlTest extends PHPUnit_Framework_TestCase { ); $this->assertEquals( '', - Xml::label( 'name', 'id', array( + Xml::label( 'name', 'id', array( 'generated' => true, 'class' => 'nice', 'anotherattr' => 'value', diff --git a/maintenance/tests/phpunit/includes/api/ApiSetup.php b/maintenance/tests/phpunit/includes/api/ApiSetup.php index cbf0b27cf4..f004f3c6be 100644 --- a/maintenance/tests/phpunit/includes/api/ApiSetup.php +++ b/maintenance/tests/phpunit/includes/api/ApiSetup.php @@ -36,7 +36,7 @@ abstract class ApiTestSetup extends PHPUnit_Framework_TestCase { self::$user = new UserWrapper( 'User for MediaWiki automated tests', User::randomPassword() ); self::$sysopUser = new UserWrapper( 'Sysop for MediaWiki automated tests', User::randomPassword(), 'sysop' ); } - + $GLOBALS['wgUser'] = self::$sysopUser->user; } } diff --git a/maintenance/tests/phpunit/includes/api/ApiTest.php b/maintenance/tests/phpunit/includes/api/ApiTest.php index d953cbd3af..5df834dbbc 100644 --- a/maintenance/tests/phpunit/includes/api/ApiTest.php +++ b/maintenance/tests/phpunit/includes/api/ApiTest.php @@ -98,7 +98,7 @@ class ApiTest extends ApiTestSetup { "lgpassword" => "bad", ) ); - + $result = $ret[0]; $this->assertNotType( "bool", $result ); diff --git a/maintenance/tests/phpunit/includes/api/ApiUploadTest.php b/maintenance/tests/phpunit/includes/api/ApiUploadTest.php index 115de86d0a..1135d5727f 100644 --- a/maintenance/tests/phpunit/includes/api/ApiUploadTest.php +++ b/maintenance/tests/phpunit/includes/api/ApiUploadTest.php @@ -6,14 +6,14 @@ */ /** - * n.b. Ensure that you can write to the images/ directory as the + * n.b. Ensure that you can write to the images/ directory as the * user that will run tests. */ // Note for reviewers: this intentionally duplicates functionality already in "ApiSetup" and so on. // This framework works better IMO and has less strangeness (such as test cases inheriting from "ApiSetup"...) // (and in the case of the other Upload tests, this flat out just actually works... ) - + // TODO: refactor into several files // TODO: port the other Upload tests, and other API tests to this framework @@ -29,14 +29,14 @@ class ApiTestUser { public $user; function __construct( $username, $realname = 'Real Name', $email = 'sample@sample.com', $groups = array() ) { - $this->username = $username; - $this->realname = $realname; + $this->username = $username; + $this->realname = $realname; $this->email = $email; $this->groups = $groups; - // don't allow user to hardcode or select passwords -- people sometimes run tests + // don't allow user to hardcode or select passwords -- people sometimes run tests // on live wikis. Sometimes we create sysop users in these tests. A sysop user with - // a known password would be a Bad Thing. + // a known password would be a Bad Thing. $this->password = User::randomPassword(); $this->user = User::newFromName( $this->username ); @@ -48,17 +48,17 @@ class ApiTestUser { // In core MediaWiki, there is no functionality to delete users, so this is the best we can do. if ( !$this->user->getID() ) { // create the user - $this->user = User::createNew( + $this->user = User::createNew( $this->username, array( "email" => $this->email, "real_name" => $this->realname - ) + ) ); if ( !$this->user ) { throw new Exception( "error creating user" ); } } - + // update the user to use the new random password and other details $this->user->setPassword( $this->password ); $this->user->setEmail( $this->email ); @@ -73,7 +73,7 @@ class ApiTestUser { } } $this->user->saveSettings(); - + } } @@ -90,17 +90,17 @@ abstract class ApiTestCase extends PHPUnit_Framework_TestCase { $wgRequest = new FauxRequest( array() ); self::$users = array( - 'sysop' => new ApiTestUser( - 'Apitestsysop', - 'Api Test Sysop', - 'api_test_sysop@sample.com', - array( 'sysop' ) + 'sysop' => new ApiTestUser( + 'Apitestsysop', + 'Api Test Sysop', + 'api_test_sysop@sample.com', + array( 'sysop' ) ), - 'uploader' => new ApiTestUser( + 'uploader' => new ApiTestUser( 'Apitestuser', 'Api Test User', 'api_test_user@sample.com', - array() + array() ) ); @@ -145,7 +145,7 @@ abstract class ApiTestCase extends PHPUnit_Framework_TestCase { */ class ApiUploadTest extends ApiTestCase { /** - * Fixture -- run before every test + * Fixture -- run before every test */ public function setUp() { global $wgEnableUploads, $wgEnableAPI; @@ -158,12 +158,12 @@ class ApiUploadTest extends ApiTestCase { ini_set( 'log_errors', 1 ); ini_set( 'error_reporting', 1 ); ini_set( 'display_errors', 1 ); - + $this->clearFakeUploads(); } /** - * Fixture -- run after every test + * Fixture -- run after every test * Clean up temporary files etc. */ function tearDown() { @@ -177,10 +177,10 @@ class ApiUploadTest extends ApiTestCase { function testLogin() { $user = self::$users['uploader']; - $params = array( - 'action' => 'login', - 'lgname' => $user->username, - 'lgpassword' => $user->password + $params = array( + 'action' => 'login', + 'lgname' => $user->username, + 'lgpassword' => $user->password ); list( $result, , ) = $this->doApiRequest( $params ); $this->assertArrayHasKey( "login", $result ); @@ -192,8 +192,8 @@ class ApiUploadTest extends ApiTestCase { 'action' => 'login', 'lgtoken' => $token, 'lgname' => $user->username, - 'lgpassword' => $user->password - ); + 'lgpassword' => $user->password + ); list( $result, , $session ) = $this->doApiRequest( $params ); $this->assertArrayHasKey( "login", $result ); $this->assertArrayHasKey( "result", $result['login'] ); @@ -207,7 +207,7 @@ class ApiUploadTest extends ApiTestCase { /** * @depends testLogin */ - public function testUploadRequiresToken( $session ) { + public function testUploadRequiresToken( $session ) { $exception = false; try { $this->doApiRequest( array( @@ -222,8 +222,8 @@ class ApiUploadTest extends ApiTestCase { /** * @depends testLogin - */ - public function testUploadMissingParams( $session ) { + */ + public function testUploadMissingParams( $session ) { global $wgUser; $wgUser = self::$users['uploader']->user; @@ -244,7 +244,7 @@ class ApiUploadTest extends ApiTestCase { /** * @depends testLogin */ - public function testUpload( $session ) { + public function testUpload( $session ) { global $wgUser; $wgUser = self::$users['uploader']->user; @@ -261,7 +261,7 @@ class ApiUploadTest extends ApiTestCase { $filePaths = $randomImageGenerator->writeImages( 1, $extension, dirname( wfTempDir() ) ); $filePath = $filePaths[0]; $fileSize = filesize( $filePath ); - $fileName = basename( $filePath ); + $fileName = basename( $filePath ); $this->deleteFileByFileName( $fileName ); $this->deleteFileByContent( $filePath ); @@ -299,7 +299,7 @@ class ApiUploadTest extends ApiTestCase { /** * @depends testLogin */ - public function testUploadZeroLength( $session ) { + public function testUploadZeroLength( $session ) { global $wgUser; $wgUser = self::$users['uploader']->user; @@ -340,7 +340,7 @@ class ApiUploadTest extends ApiTestCase { /** * @depends testLogin */ - public function testUploadSameFileName( $session ) { + public function testUploadSameFileName( $session ) { global $wgUser; $wgUser = self::$users['uploader']->user; @@ -356,7 +356,7 @@ class ApiUploadTest extends ApiTestCase { $filePaths = $randomImageGenerator->writeImages( 2, $extension, dirname( wfTempDir() ) ); // we'll reuse this filename - $fileName = basename( $filePaths[0] ); + $fileName = basename( $filePaths[0] ); // clear any other files with the same name $this->deleteFileByFileName( $fileName ); @@ -371,7 +371,7 @@ class ApiUploadTest extends ApiTestCase { ); // first upload .... should succeed - + if (! $this->fakeUploadFile( 'file', $fileName, $mimeType, $filePaths[0] ) ) { $this->markTestIncomplete( "Couldn't upload file!\n" ); } @@ -386,7 +386,7 @@ class ApiUploadTest extends ApiTestCase { $this->assertEquals( 'Success', $result['upload']['result'] ); $this->assertFalse( $exception ); - // second upload with the same name (but different content) + // second upload with the same name (but different content) if (! $this->fakeUploadFile( 'file', $fileName, $mimeType, $filePaths[1] ) ) { $this->markTestIncomplete( "Couldn't upload file!\n" ); @@ -414,7 +414,7 @@ class ApiUploadTest extends ApiTestCase { /** * @depends testLogin */ - public function testUploadSameContent( $session ) { + public function testUploadSameContent( $session ) { global $wgUser; $wgUser = self::$users['uploader']->user; @@ -428,7 +428,7 @@ class ApiUploadTest extends ApiTestCase { $this->markTestIncomplete( $e->getMessage() ); } $filePaths = $randomImageGenerator->writeImages( 1, $extension, dirname( wfTempDir() ) ); - $fileNames[0] = basename( $filePaths[0] ); + $fileNames[0] = basename( $filePaths[0] ); $fileNames[1] = "SameContentAs" . $fileNames[0]; // clear any other files with the same name or content @@ -437,7 +437,7 @@ class ApiUploadTest extends ApiTestCase { $this->deleteFileByFileName( $fileNames[1] ); // first upload .... should succeed - + $params = array( 'action' => 'upload', 'filename' => $fileNames[0], @@ -445,7 +445,7 @@ class ApiUploadTest extends ApiTestCase { 'comment' => 'dummy comment', 'text' => "This is the page text for " . $fileNames[0], ); - + if (! $this->fakeUploadFile( 'file', $fileNames[0], $mimeType, $filePaths[0] ) ) { $this->markTestIncomplete( "Couldn't upload file!\n" ); } @@ -461,12 +461,12 @@ class ApiUploadTest extends ApiTestCase { $this->assertFalse( $exception ); - // second upload with the same content (but different name) + // second upload with the same content (but different name) if (! $this->fakeUploadFile( 'file', $fileNames[1], $mimeType, $filePaths[0] ) ) { $this->markTestIncomplete( "Couldn't upload file!\n" ); } - + $params = array( 'action' => 'upload', 'filename' => $fileNames[1], @@ -497,7 +497,7 @@ class ApiUploadTest extends ApiTestCase { /** * @depends testLogin */ - public function testUploadStash( $session ) { + public function testUploadStash( $session ) { global $wgUser; $wgUser = self::$users['uploader']->user; @@ -514,7 +514,7 @@ class ApiUploadTest extends ApiTestCase { $filePaths = $randomImageGenerator->writeImages( 1, $extension, dirname( wfTempDir() ) ); $filePath = $filePaths[0]; $fileSize = filesize( $filePath ); - $fileName = basename( $filePath ); + $fileName = basename( $filePath ); $this->deleteFileByFileName( $fileName ); $this->deleteFileByContent( $filePath ); @@ -545,15 +545,15 @@ class ApiUploadTest extends ApiTestCase { $this->assertEquals( $mimeType, $result['upload']['imageinfo']['mime'] ); $this->assertTrue( isset( $result['upload']['sessionkey'] ) ); $sessionkey = $result['upload']['sessionkey']; - - // it should be visible from Special:UploadStash + + // it should be visible from Special:UploadStash // XXX ...but how to test this, with a fake WebRequest with the session? // now we should try to release the file from stash $params = array( 'action' => 'upload', 'sessionkey' => $sessionkey, - 'filename' => $fileName, + 'filename' => $fileName, 'comment' => 'dummy comment', 'text' => "This is the page text for $fileName, altered", ); @@ -581,7 +581,7 @@ class ApiUploadTest extends ApiTestCase { * @param $title Title: title to be removed */ public function deleteFileByTitle( $title ) { - if ( $title->exists() ) { + if ( $title->exists() ) { $file = wfFindFile( $title, array( 'ignoreRedirect' => true ) ); $noOldArchive = ""; // yes this really needs to be set this way $comment = "removing for test"; @@ -593,14 +593,14 @@ class ApiUploadTest extends ApiTestCase { $article = new Article( $title ); $article->doDeleteArticle( "removing for test" ); - // see if it now doesn't exist; reload + // see if it now doesn't exist; reload $title = Title::newFromText( $fileName, NS_FILE ); } return ! ( $title && $title instanceof Title && $title->exists() ); } /** - * Helper function -- remove files and associated articles with a particular filename + * Helper function -- remove files and associated articles with a particular filename * @param $fileName String: filename to be removed */ public function deleteFileByFileName( $fileName ) { @@ -622,10 +622,10 @@ class ApiUploadTest extends ApiTestCase { return $success; } - /** + /** * Fake an upload by dumping the file into temp space, and adding info to $_FILES. * (This is what PHP would normally do). - * @param $fieldName String: name this would have in the upload form + * @param $fieldName String: name this would have in the upload form * @param $fileName String: name to title this * @param $type String: mime type * @param $filePath String: path where to find file contents @@ -636,7 +636,7 @@ class ApiUploadTest extends ApiTestCase { throw new Exception( "$filePath doesn't exist!" ); }; - if ( !copy( $filePath, $tmpName ) ) { + if ( !copy( $filePath, $tmpName ) ) { throw new Exception( "couldn't copy $filePath to $tmpName" ); } diff --git a/maintenance/tests/phpunit/includes/api/ApiWatchTest.php b/maintenance/tests/phpunit/includes/api/ApiWatchTest.php index e16ea31d1e..0742a0af4e 100644 --- a/maintenance/tests/phpunit/includes/api/ApiWatchTest.php +++ b/maintenance/tests/phpunit/includes/api/ApiWatchTest.php @@ -75,7 +75,7 @@ class ApiWatchTest extends ApiTestSetup { $this->assertArrayHasKey( 'protecttoken', $data[0]['query']['pages'][$key] ); } - return $data; + return $data; } function testGetToken() { @@ -161,7 +161,7 @@ class ApiWatchTest extends ApiTestSetup { if ( !Title::newFromText( 'Main Page' )->exists() ) { $this->markTestIncomplete( "The article [[Main Page]] does not exist" ); } - + $data = $this->doApiRequest( array( 'action' => 'query', 'prop' => 'revisions', @@ -172,7 +172,7 @@ class ApiWatchTest extends ApiTestSetup { $this->assertArrayHasKey( 'pages', $data[0]['query'] ); $keys = array_keys( $data[0]['query']['pages'] ); $key = array_pop( $keys ); - + if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) { $this->markTestIncomplete( "Target page (Main Page) doesn't exist" ); } @@ -232,6 +232,6 @@ class ApiWatchTest extends ApiTestSetup { 'action' => 'query', 'list' => 'watchlist' ), $data ); - $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' ); + $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' ); } } diff --git a/maintenance/tests/phpunit/includes/api/RandomImageGenerator.php b/maintenance/tests/phpunit/includes/api/RandomImageGenerator.php index e16b6c4928..05861f93e8 100644 --- a/maintenance/tests/phpunit/includes/api/RandomImageGenerator.php +++ b/maintenance/tests/phpunit/includes/api/RandomImageGenerator.php @@ -1,21 +1,21 @@ */ @@ -33,7 +33,7 @@ class RandomImageGenerator { private $maxHeight = 800; private $circlesToDraw = 5; private $imageWriteMethod; - + public function __construct( $options ) { global $wgUseImageMagick, $wgImageMagickConvertCommand; foreach ( array( 'dictionaryFile', 'minWidth', 'minHeight', 'maxHeight', 'circlesToDraw' ) as $property ) { @@ -62,12 +62,12 @@ class RandomImageGenerator { $this->imageWriteMethod = 'writeImageWithCommandLine'; } else { throw new Exception( "RandomImageGenerator: could not find a suitable method to write images" ); - } + } } /** * Writes random images with random filenames to disk in the directory you specify, or current working directory - * + * * @param $number Integer: number of filenames to write * @param $format String: optional, must be understood by ImageMagick, such as 'jpg' or 'gif' * @param $dir String: directory, optional (will default to current working directory) @@ -81,10 +81,10 @@ class RandomImageGenerator { return $filenames; } - /** + /** * Return a number of randomly-generated filenames * Each filename uses two words randomly drawn from the dictionary, like elephantine_spatula.jpg - * + * * @param $number Integer: of filenames to generate * @param $extension String: optional, defaults to 'jpg' * @param $dir String: optional, defaults to current working directory @@ -103,23 +103,23 @@ class RandomImageGenerator { $basename = preg_replace( '/\s+/', '', $basename ); $filenames[] = "$dir/$basename"; } - + return $filenames; - + } /** - * Generate data representing an image of random size (within limits), + * Generate data representing an image of random size (within limits), * consisting of randomly colored and sized circles against a random background color * (This data is used in the writeImage* methods). - * @return {Mixed} + * @return {Mixed} */ - public function getImageSpec() { + public function getImageSpec() { $spec = array(); - - $spec['width'] = mt_rand( $this->minWidth, $this->maxWidth ); - $spec['height'] = mt_rand( $this->minHeight, $this->maxHeight ); + + $spec['width'] = mt_rand( $this->minWidth, $this->maxWidth ); + $spec['height'] = mt_rand( $this->minHeight, $this->maxHeight ); $spec['fill'] = $this->getRandomColor(); $diagonalLength = sqrt( pow( $spec['width'], 2 ) + pow( $spec['height'], 2 ) ); @@ -134,14 +134,14 @@ class RandomImageGenerator { $draw = array(); $draw['fill'] = $this->getRandomColor(); - $draw['circle'] = array( - 'originX' => $originX, - 'originY' => $originY, - 'perimeterX' => $perimeterX, - 'perimeterY' => $perimeterY + $draw['circle'] = array( + 'originX' => $originX, + 'originY' => $originY, + 'perimeterX' => $perimeterX, + 'perimeterY' => $perimeterY ); $draws[] = $draw; - + } $spec['draws'] = $draws; @@ -156,12 +156,12 @@ class RandomImageGenerator { * @param $format: file format to write * @param $filename: filename to write to */ - public function writeImageWithApi( $spec, $format, $filename ) { + public function writeImageWithApi( $spec, $format, $filename ) { $image = new Imagick(); $image->newImage( $spec['width'], $spec['height'], new ImagickPixel( $spec['fill'] ) ); foreach ( $spec['draws'] as $drawSpec ) { - $draw = new ImagickDraw(); + $draw = new ImagickDraw(); $draw->setFillColor( $drawSpec['fill'] ); $circle = $drawSpec['circle']; $draw->circle( $circle['originX'], $circle['originY'], $circle['perimeterX'], $circle['perimeterY'] ); @@ -178,9 +178,9 @@ class RandomImageGenerator { * * Sample command line: * $ convert -size 100x60 xc:rgb(90,87,45) \ - * -draw 'fill rgb(12,34,56) circle 41,39 44,57' \ - * -draw 'fill rgb(99,123,231) circle 59,39 56,57' \ - * -draw 'fill rgb(240,12,32) circle 50,21 50,3' filename.png + * -draw 'fill rgb(12,34,56) circle 41,39 44,57' \ + * -draw 'fill rgb(99,123,231) circle 59,39 56,57' \ + * -draw 'fill rgb(240,12,32) circle 50,21 50,3' filename.png * * @param $spec: spec describing background and circles to draw * @param $format: file format to write (unused by this method but kept so it has the same signature as writeImageWithApi) @@ -210,7 +210,7 @@ class RandomImageGenerator { /** * Generate a string of random colors for ImageMagick, like "rgb(12, 37, 98)" - * + * * @return {String} */ public function getRandomColor() { @@ -221,13 +221,13 @@ class RandomImageGenerator { return 'rgb(' . join(', ', $components) . ')'; } - /** + /** * Get an array of random pairs of random words, like array( array( 'foo', 'bar' ), array( 'quux', 'baz' ) ); * * @param $number Integer: number of pairs * @return Array: of two-element arrays */ - private function getRandomWordPairs( $number ) { + private function getRandomWordPairs( $number ) { $lines = $this->getRandomLines( $number * 2 ); // construct pairs of words $pairs = array(); @@ -238,16 +238,16 @@ class RandomImageGenerator { return $pairs; } - + /** * Return N random lines from a file - * + * * Will throw exception if the file could not be read or if it had fewer lines than requested. - * + * * @param $number_desired Integer: number of lines desired * @return Array: of exactly n elements, drawn randomly from lines the file */ - private function getRandomLines( $number_desired ) { + private function getRandomLines( $number_desired ) { $filepath = $this->dictionaryFile; // initialize array of lines @@ -257,7 +257,7 @@ class RandomImageGenerator { } /* - * This algorithm obtains N random lines from a file in one single pass. It does this by replacing elements of + * This algorithm obtains N random lines from a file in one single pass. It does this by replacing elements of * a fixed-size array of lines, less and less frequently as it reads the file. */ $fh = fopen( $filepath, "r" ); @@ -266,12 +266,12 @@ class RandomImageGenerator { } $line_number = 0; $max_index = $number_desired - 1; - while( !feof( $fh ) ) { + while( !feof( $fh ) ) { $line = fgets( $fh ); if ( $line !== false ) { - $line_number++; - $line = trim( $line ); - if ( mt_rand( 0, $line_number ) <= $max_index ) { + $line_number++; + $line = trim( $line ); + if ( mt_rand( 0, $line_number ) <= $max_index ) { $lines[ mt_rand( 0, $max_index ) ] = $line; } } @@ -280,7 +280,7 @@ class RandomImageGenerator { if ( $line_number < $number_desired ) { throw new Exception( "not enough lines in $filepath" ); } - + return $lines; } diff --git a/maintenance/tests/phpunit/includes/api/generateRandomImages.php b/maintenance/tests/phpunit/includes/api/generateRandomImages.php index a72d34fd1c..cab1ec7de6 100644 --- a/maintenance/tests/phpunit/includes/api/generateRandomImages.php +++ b/maintenance/tests/phpunit/includes/api/generateRandomImages.php @@ -2,7 +2,7 @@ require("RandomImageGenerator.php"); -$getOptSpec = array( +$getOptSpec = array( 'dictionaryFile::', 'minWidth::', 'maxWidth::', diff --git a/maintenance/tests/phpunit/includes/db/DatabaseSqliteTest.php b/maintenance/tests/phpunit/includes/db/DatabaseSqliteTest.php index 6c73a84f2a..4cd3daf04a 100644 --- a/maintenance/tests/phpunit/includes/db/DatabaseSqliteTest.php +++ b/maintenance/tests/phpunit/includes/db/DatabaseSqliteTest.php @@ -65,7 +65,7 @@ class DatabaseSqliteTest extends PHPUnit_Framework_TestCase { $this->replaceVars( "ALTER TABLE foo\nADD COLUMN foo_bar int(10) unsigned DEFAULT 42" ) ); } - + public function testTableName() { // @todo Moar! $db = new DatabaseSqliteStandalone( ':memory:' ); diff --git a/maintenance/tests/phpunit/includes/search/SearchDbTest.php b/maintenance/tests/phpunit/includes/search/SearchDbTest.php index 0f1fbf3d0b..daf9747fe6 100644 --- a/maintenance/tests/phpunit/includes/search/SearchDbTest.php +++ b/maintenance/tests/phpunit/includes/search/SearchDbTest.php @@ -14,7 +14,7 @@ class SearchDbTest extends SearchEngineTest { $this->db = wfGetDB( DB_MASTER ); if ( !$this->db ) { $this->markTestIncomplete( "Can't find a database to test with." ); - } + } parent::setup(); diff --git a/maintenance/tests/phpunit/includes/search/SearchEngineTest.php b/maintenance/tests/phpunit/includes/search/SearchEngineTest.php index 4b38c333ae..b97afb6728 100644 --- a/maintenance/tests/phpunit/includes/search/SearchEngineTest.php +++ b/maintenance/tests/phpunit/includes/search/SearchEngineTest.php @@ -33,26 +33,26 @@ class SearchEngineTest extends MediaWikiTestSetup { } function insertSearchData() { - if ( $this->pageExists( 'Not_Main_Page' ) ) { + if ( $this->pageExists( 'Not_Main_Page' ) ) { return; - } - $this->insertPage( "Not_Main_Page", "This is not a main page", 0 ); - $this->insertPage( 'Talk:Not_Main_Page', 'This is not a talk page to the main page, see [[smithee]]', 1 ); - $this->insertPage( 'Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]', 0 ); - $this->insertPage( 'Talk:Smithee', 'This article sucks.', 1 ); - $this->insertPage( 'Unrelated_page', 'Nothing in this page is about the S word.', 0 ); - $this->insertPage( 'Another_page', 'This page also is unrelated.', 0 ); - $this->insertPage( 'Help:Help', 'Help me!', 4 ); - $this->insertPage( 'Thppt', 'Blah blah', 0 ); - $this->insertPage( 'Alan_Smithee', 'yum', 0 ); - $this->insertPage( 'Pages', 'are\'food', 0 ); - $this->insertPage( 'HalfOneUp', 'AZ', 0 ); - $this->insertPage( 'FullOneUp', 'AZ', 0 ); - $this->insertPage( 'HalfTwoLow', 'az', 0 ); - $this->insertPage( 'FullTwoLow', 'az', 0 ); - $this->insertPage( 'HalfNumbers', '1234567890', 0 ); - $this->insertPage( 'FullNumbers', '1234567890', 0 ); - $this->insertPage( 'DomainName', 'example.com', 0 ); + } + $this->insertPage( "Not_Main_Page", "This is not a main page", 0 ); + $this->insertPage( 'Talk:Not_Main_Page', 'This is not a talk page to the main page, see [[smithee]]', 1 ); + $this->insertPage( 'Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]', 0 ); + $this->insertPage( 'Talk:Smithee', 'This article sucks.', 1 ); + $this->insertPage( 'Unrelated_page', 'Nothing in this page is about the S word.', 0 ); + $this->insertPage( 'Another_page', 'This page also is unrelated.', 0 ); + $this->insertPage( 'Help:Help', 'Help me!', 4 ); + $this->insertPage( 'Thppt', 'Blah blah', 0 ); + $this->insertPage( 'Alan_Smithee', 'yum', 0 ); + $this->insertPage( 'Pages', 'are\'food', 0 ); + $this->insertPage( 'HalfOneUp', 'AZ', 0 ); + $this->insertPage( 'FullOneUp', 'AZ', 0 ); + $this->insertPage( 'HalfTwoLow', 'az', 0 ); + $this->insertPage( 'FullTwoLow', 'az', 0 ); + $this->insertPage( 'HalfNumbers', '1234567890', 0 ); + $this->insertPage( 'FullNumbers', '1234567890', 0 ); + $this->insertPage( 'DomainName', 'example.com', 0 ); } function removeSearchData() { @@ -62,7 +62,7 @@ class SearchEngineTest extends MediaWikiTestSetup { $article = new Article( $title, $id ); $article->doDeleteArticle( "Search Test" ); }*/ - } + } function fetchIds( $results ) { $this->assertTrue( is_object( $results ) ); @@ -81,82 +81,82 @@ class SearchEngineTest extends MediaWikiTestSetup { // Modified version of WikiRevision::importOldRevision() function insertPage( $pageName, $text, $ns ) { - $dbw = $this->db; - $title = Title::newFromText( $pageName ); - - $userId = 0; - $userText = 'WikiSysop'; - $comment = 'Search Test'; - - // avoid memory leak...? - $linkCache = LinkCache::singleton(); - $linkCache->clear(); - - $article = new Article( $title ); - $pageId = $article->getId(); - $created = false; - if ( $pageId == 0 ) { - # must create the page... - $pageId = $article->insertOn( $dbw ); - $created = true; - } - - # FIXME: Use original rev_id optionally (better for backups) - # Insert the row - $revision = new Revision( array( - 'page' => $pageId, - 'text' => $text, - 'comment' => $comment, - 'user' => $userId, - 'user_text' => $userText, - 'timestamp' => 0, - 'minor_edit' => false, + $dbw = $this->db; + $title = Title::newFromText( $pageName ); + + $userId = 0; + $userText = 'WikiSysop'; + $comment = 'Search Test'; + + // avoid memory leak...? + $linkCache = LinkCache::singleton(); + $linkCache->clear(); + + $article = new Article( $title ); + $pageId = $article->getId(); + $created = false; + if ( $pageId == 0 ) { + # must create the page... + $pageId = $article->insertOn( $dbw ); + $created = true; + } + + # FIXME: Use original rev_id optionally (better for backups) + # Insert the row + $revision = new Revision( array( + 'page' => $pageId, + 'text' => $text, + 'comment' => $comment, + 'user' => $userId, + 'user_text' => $userText, + 'timestamp' => 0, + 'minor_edit' => false, ) ); - $revId = $revision->insertOn( $dbw ); - $changed = $article->updateIfNewerOn( $dbw, $revision ); + $revId = $revision->insertOn( $dbw ); + $changed = $article->updateIfNewerOn( $dbw, $revision ); - $GLOBALS['wgTitle'] = $title; - if ( $created ) { - Article::onArticleCreate( $title ); - $article->createUpdates( $revision ); - } elseif ( $changed ) { - Article::onArticleEdit( $title ); - $article->editUpdates( - $text, $comment, false, 0, $revId ); - } + $GLOBALS['wgTitle'] = $title; + if ( $created ) { + Article::onArticleCreate( $title ); + $article->createUpdates( $revision ); + } elseif ( $changed ) { + Article::onArticleEdit( $title ); + $article->editUpdates( + $text, $comment, false, 0, $revId ); + } - $su = new SearchUpdate( $article->getId(), $pageName, $text ); - $su->doUpdate(); + $su = new SearchUpdate( $article->getId(), $pageName, $text ); + $su->doUpdate(); - $this->pageList[] = array( $title, $article->getId() ); + $this->pageList[] = array( $title, $article->getId() ); - return true; - } + return true; + } function testFullWidth() { - $this->assertEquals( - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), - $this->fetchIds( $this->search->searchText( 'AZ' ) ), - "Search for normalized from Half-width Upper" ); - $this->assertEquals( - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), - $this->fetchIds( $this->search->searchText( 'az' ) ), - "Search for normalized from Half-width Lower" ); - $this->assertEquals( - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), - $this->fetchIds( $this->search->searchText( 'AZ' ) ), - "Search for normalized from Full-width Upper" ); - $this->assertEquals( - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), - $this->fetchIds( $this->search->searchText( 'az' ) ), - "Search for normalized from Full-width Lower" ); + $this->assertEquals( + array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), + $this->fetchIds( $this->search->searchText( 'AZ' ) ), + "Search for normalized from Half-width Upper" ); + $this->assertEquals( + array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), + $this->fetchIds( $this->search->searchText( 'az' ) ), + "Search for normalized from Half-width Lower" ); + $this->assertEquals( + array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), + $this->fetchIds( $this->search->searchText( 'AZ' ) ), + "Search for normalized from Full-width Upper" ); + $this->assertEquals( + array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), + $this->fetchIds( $this->search->searchText( 'az' ) ), + "Search for normalized from Full-width Lower" ); } function testTextSearch() { $this->assertEquals( - array( 'Smithee' ), - $this->fetchIds( $this->search->searchText( 'smithee' ) ), - "Plain search failed" ); + array( 'Smithee' ), + $this->fetchIds( $this->search->searchText( 'smithee' ) ), + "Plain search failed" ); } function testTextPowerSearch() { diff --git a/maintenance/tests/selenium/Selenium.php b/maintenance/tests/selenium/Selenium.php index 662e282e41..7eb70c114b 100644 --- a/maintenance/tests/selenium/Selenium.php +++ b/maintenance/tests/selenium/Selenium.php @@ -41,7 +41,7 @@ class Selenium { self::$_instance = $this; } else { throw new MWException( "Already have one Selenium instance." ); - } + } } public function start() { @@ -62,7 +62,7 @@ class Selenium { public function login() { if ( strlen( $this->user ) == 0 ) { return; - } + } $this->open( self::$url . '/index.php?title=Special:Userlogin' ); $this->type( 'wpName1', $this->user ); $this->type( 'wpPassword1', $this->pass ); @@ -133,7 +133,7 @@ class Selenium { public function setVerbose( $verbose ) { $this->verbose = $verbose; } - + public function setAvailableBrowsers( $availableBrowsers ) { $this->browsers = $availableBrowsers; } @@ -141,15 +141,15 @@ class Selenium { public function setJUnitLogfile( $junitlogfile ) { $this->junitlogfile = $junitlogfile; } - + public function getJUnitLogfile( ) { return $this->junitlogfile; - } - + } + public function setRunAgainstGrid( $runagainstgrid ) { $this->runagainstgrid = $runagainstgrid; } - + public function setBrowser( $b ) { if ($this->runagainstgrid) { $this->browser = $b; @@ -161,7 +161,7 @@ class Selenium { $this->browser = $this->browsers[$b]; } - + public function getAvailableBrowsers() { return $this->browsers; } diff --git a/maintenance/tests/selenium/SeleniumConfig.php b/maintenance/tests/selenium/SeleniumConfig.php index ca438a8832..ca69b1f0e0 100644 --- a/maintenance/tests/selenium/SeleniumConfig.php +++ b/maintenance/tests/selenium/SeleniumConfig.php @@ -4,16 +4,16 @@ if ( !defined( 'SELENIUMTEST' ) ) { } class SeleniumConfig { - + /* * Retreives the Selenium configuration values from an ini file. * See sample config file in selenium_settings.ini.sample - * + * */ - public static function getSeleniumSettings ( &$seleniumSettings, - &$seleniumBrowsers, - &$seleniumTestSuites, + public static function getSeleniumSettings ( &$seleniumSettings, + &$seleniumBrowsers, + &$seleniumTestSuites, $seleniumConfigFile = null ) { if ( strlen( $seleniumConfigFile ) == 0 ) { global $wgSeleniumConfigFile; @@ -23,7 +23,7 @@ class SeleniumConfig { if ( strlen( $seleniumConfigFile ) == 0 || !file_exists( $seleniumConfigFile ) ) { throw new MWException( "Unable to read local Selenium Settings from " . $seleniumConfigFile . "\n" ); } - + if ( !defined( 'PHP_VERSION_ID' ) || ( PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3 ) ) { $configArray = self::parse_5_2_ini_file( $seleniumConfigFile ); @@ -38,7 +38,7 @@ class SeleniumConfig { wfSuppressWarnings(); //we may need to change how this is set. But for now leave it in the ini file $seleniumBrowsers = $configArray['SeleniumSettings']['browsers']; - + $seleniumSettings['host'] = $configArray['SeleniumSettings']['host']; $seleniumSettings['port'] = $configArray['SeleniumSettings']['port']; $seleniumSettings['wikiUrl'] = $configArray['SeleniumSettings']['wikiUrl']; @@ -58,7 +58,7 @@ class SeleniumConfig { $seleniumTestSuites = $configArray['SeleniumTests']['testSuite']; wfRestoreWarnings(); } - return true; + return true; } private static function parse_5_2_ini_file ( $ConfigFile ) { diff --git a/maintenance/tests/selenium/SeleniumServerManager.php b/maintenance/tests/selenium/SeleniumServerManager.php index 0596ea7845..ae5ea68250 100644 --- a/maintenance/tests/selenium/SeleniumServerManager.php +++ b/maintenance/tests/selenium/SeleniumServerManager.php @@ -34,8 +34,8 @@ class SeleniumServerManager { private $SeleniumServerExecPath; public function __construct( $startServer, - $serverPort, - $serverExecPath ) { + $serverPort, + $serverExecPath ) { $this->OS = (string) PHP_OS; if ( isset( $startServer ) ) $this->SeleniumStartServer = $startServer; @@ -172,11 +172,11 @@ class SeleniumServerManager { $commandSuffix = ' > /dev/null 2>&1'. ' & echo $!'; $portText = ' -port ' . $this->SeleniumServerPort; - $command = "java -jar " . + $command = "java -jar " . escapeshellarg($this->SeleniumServerExecPath) . $portText . $commandSuffix; - exec($command ,$op); - $pid = (int)$op[0]; + exec($command ,$op); + $pid = (int)$op[0]; if ( $pid != "" ) $this->SeleniumServerPid = $pid; else { @@ -190,8 +190,8 @@ class SeleniumServerManager { wfSuppressWarnings(); for ( $cnt = 1; - $cnt <= $this->SeleniumServerStartTimeout; - $cnt++ ) { + $cnt <= $this->SeleniumServerStartTimeout; + $cnt++ ) { $fp = fsockopen ( 'localhost', $this->SeleniumServerPort, $errno, $errstr, 0 ); @@ -212,19 +212,19 @@ class SeleniumServerManager { else return 'running'; } - // No Server execution path defined. + // No Server execution path defined. return 'failed'; } private function startServerOnWindows() { - // Unimplemented. + // Unimplemented. return 'failed'; } private function stopServerOnUnix() { if ( !empty( $this->SeleniumServerPid ) && - $this->SeleniumServerPid != 'NaN' ) { + $this->SeleniumServerPid != 'NaN' ) { exec( "kill -9 " . $this->SeleniumServerPid ); return 'stopped'; } @@ -232,7 +232,7 @@ class SeleniumServerManager { } private function stopServerOnWindows() { - // Unimplemented. + // Unimplemented. return 'failed'; } diff --git a/maintenance/tests/selenium/SeleniumTestSuite.php b/maintenance/tests/selenium/SeleniumTestSuite.php index b5f69e2091..ba178051fa 100644 --- a/maintenance/tests/selenium/SeleniumTestSuite.php +++ b/maintenance/tests/selenium/SeleniumTestSuite.php @@ -11,7 +11,7 @@ abstract class SeleniumTestSuite extends PHPUnit_Framework_TestSuite { const RESULT_ERROR = 3; public abstract function addTests(); - + public function setUp() { // Hack because because PHPUnit version 3.0.6 which is on prototype does not // run setUp as part of TestSuite::run @@ -39,7 +39,7 @@ abstract class SeleniumTestSuite extends PHPUnit_Framework_TestSuite { public function loadPage( $title, $action ) { $this->selenium->loadPage( $title, $action ); } - + protected function setLoginBeforeTests( $loginBeforeTests = true ) { $this->loginBeforeTests = $loginBeforeTests; }