require_once( dirname( __FILE__ ) . '/../commandLine.inc' );
if ( isset( $options['help'] ) ) {
- echo <<<ENDS
+ echo <<<ENDS
MediaWiki $wgVersion parser test suite
Usage: php parserTests.php [options...]
--quiet Suppress notification of passed tests (shows only failed tests)
--show-output Show expected and actual output
--color[=yes|no] Override terminal detection and force color output on or off
- use wgCommandLineDarkBg = true; if your term is dark
+ use wgCommandLineDarkBg = true; if your term is dark
--regex Only run tests whose descriptions which match given regex
--file=<testfile> Run test cases from a custom file instead of parserTests.txt
--record Record tests in database
--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
unlink( $wgReadOnlyFile );
$wgContLang = $wgLang = Language::factory( 'en' );
}
-
+
function tearDown() {
global $wgReadOnlyFile;
if ( file_exists( $wgReadOnlyFile ) ) {
}
$wgReadOnlyFile = $this->originals['wgReadOnlyFile'];
}
-
+
function testRandom() {
# This could hypothetically fail, but it shouldn't ;)
$this->assertFalse(
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() );
}
'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.
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',
}
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() {
<?php
-/*
+/*
* Tests for IP validity functions. Ported from /t/inc/IP.t by avar.
*/
class IPTest extends PHPUnit_Framework_TestCase {
- // not sure it should be tested with boolean false. hashar 20100924
+ // not sure it should be tested with boolean false. hashar 20100924
public function testisIPAddress() {
$this->assertFalse( IP::isIPAddress( false ), 'Boolean false is not an IP' );
$this->assertFalse( IP::isIPAddress( true ), 'Boolean true is not an IP' );
$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 ) {
// 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 );
* 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
$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');
$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' );
}
}
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 );
}
}
/*
* 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"
[SeleniumTests]
testSuite[SimpleSeleniumTestSuite] = "maintenance/tests/selenium/SimpleSeleniumTestSuite.php"
-testSuite[TestSuiteName] = "testSuitePath"
+testSuite[TestSuiteName] = "testSuitePath"
';
/*
* Array of expected browsers from $testConfig0
*/
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"
/*
* 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.
*/
}
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
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
*/
array($this->testConfig1, $this->testSettings1, $this->testBrowsers1, $this->testSuites1 )
);
}
-
+
}
'get(): parameter replacement on an non-existing wiki'
);
}
-
+
function testGetAll() {
$this->mConf->siteParamsCallback = 'getSiteParams';
'' => 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 ) );
ini_set( 'log_errors', 1 );
ini_set( 'error_reporting', 1 );
ini_set( 'display_errors', 1 );
-
+
if ( wfLocalFile( 'UploadFromUrlTest.png' )->exists() ) {
$this->deleteFile( 'UploadFromUrlTest.png' );
}
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();
* @depends testLogin
* @depends testClearQueue
*/
- public function testSetupUrlDownload( $data ) {
+ public function testSetupUrlDownload( $data ) {
$token = self::$user->editToken();
$exception = false;
), $data );
$this->assertEquals( $data[0]['upload']['result'], 'Queued', 'Queued upload' );
-
+
$job = Job::pop();
$this->assertThat( $job, $this->isInstanceOf( 'UploadFromUrlJob' ), 'Queued upload inserted' );
}
$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;
$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',
$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;
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',
'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(
$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 ) {
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;
}
-
+
/**
*
);
$this->assertEquals(
'<label for="id" class="nice">name</label>',
- Xml::label( 'name', 'id', array(
+ Xml::label( 'name', 'id', array(
'generated' => true,
'class' => 'nice',
'anotherattr' => 'value',
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;
}
}
"lgpassword" => "bad",
)
);
-
+
$result = $ret[0];
$this->assertNotType( "bool", $result );
*/
/**
- * 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
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 );
// 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 );
}
}
$this->user->saveSettings();
-
+
}
}
$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()
)
);
*/
class ApiUploadTest extends ApiTestCase {
/**
- * Fixture -- run before every test
+ * Fixture -- run before every test
*/
public function setUp() {
global $wgEnableUploads, $wgEnableAPI;
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() {
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 );
'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'] );
/**
* @depends testLogin
*/
- public function testUploadRequiresToken( $session ) {
+ public function testUploadRequiresToken( $session ) {
$exception = false;
try {
$this->doApiRequest( array(
/**
* @depends testLogin
- */
- public function testUploadMissingParams( $session ) {
+ */
+ public function testUploadMissingParams( $session ) {
global $wgUser;
$wgUser = self::$users['uploader']->user;
/**
* @depends testLogin
*/
- public function testUpload( $session ) {
+ public function testUpload( $session ) {
global $wgUser;
$wgUser = self::$users['uploader']->user;
$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 );
/**
* @depends testLogin
*/
- public function testUploadZeroLength( $session ) {
+ public function testUploadZeroLength( $session ) {
global $wgUser;
$wgUser = self::$users['uploader']->user;
/**
* @depends testLogin
*/
- public function testUploadSameFileName( $session ) {
+ public function testUploadSameFileName( $session ) {
global $wgUser;
$wgUser = self::$users['uploader']->user;
$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 );
);
// first upload .... should succeed
-
+
if (! $this->fakeUploadFile( 'file', $fileName, $mimeType, $filePaths[0] ) ) {
$this->markTestIncomplete( "Couldn't upload file!\n" );
}
$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" );
/**
* @depends testLogin
*/
- public function testUploadSameContent( $session ) {
+ public function testUploadSameContent( $session ) {
global $wgUser;
$wgUser = self::$users['uploader']->user;
$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
$this->deleteFileByFileName( $fileNames[1] );
// first upload .... should succeed
-
+
$params = array(
'action' => 'upload',
'filename' => $fileNames[0],
'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" );
}
$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],
/**
* @depends testLogin
*/
- public function testUploadStash( $session ) {
+ public function testUploadStash( $session ) {
global $wgUser;
$wgUser = self::$users['uploader']->user;
$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 );
$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",
);
* @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";
$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 ) {
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
throw new Exception( "$filePath doesn't exist!" );
};
- if ( !copy( $filePath, $tmpName ) ) {
+ if ( !copy( $filePath, $tmpName ) ) {
throw new Exception( "couldn't copy $filePath to $tmpName" );
}
$this->assertArrayHasKey( 'protecttoken', $data[0]['query']['pages'][$key] );
}
- return $data;
+ return $data;
}
function testGetToken() {
if ( !Title::newFromText( 'Main Page' )->exists() ) {
$this->markTestIncomplete( "The article [[Main Page]] does not exist" );
}
-
+
$data = $this->doApiRequest( array(
'action' => 'query',
'prop' => 'revisions',
$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" );
}
'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' );
}
}
<?php
-/*
+/*
* RandomImageGenerator -- does what it says on the tin.
* Requires Imagick, the ImageMagick library for PHP, or the command line equivalent (usually 'convert').
*
* Because MediaWiki tests the uniqueness of media upload content, and filenames, it is sometimes useful to generate
* files that are guaranteed (or at least very likely) to be unique in both those ways.
- * This generates a number of filenames with random names and random content (colored circles)
+ * This generates a number of filenames with random names and random content (colored circles)
*
- * 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
+ * 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
* test run.
- * Consequently, if we just had a few static files we kept re-uploading, we'd get lots of warnings about matching content or filenames,
+ * Consequently, if we just had a few static files we kept re-uploading, we'd get lots of warnings about matching content or filenames,
* and even if we deleted those files, we'd get warnings about archived files.
*
* 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
* testing interactively.
- *
+ *
* @file
* @author Neil Kandalgaonkar <neilk@wikimedia.org>
*/
private $maxHeight = 800;
private $circlesToDraw = 5;
private $imageWriteMethod;
-
+
public function __construct( $options ) {
global $wgUseImageMagick, $wgImageMagickConvertCommand;
foreach ( array( 'dictionaryFile', 'minWidth', 'minHeight', 'maxHeight', 'circlesToDraw' ) as $property ) {
$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)
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
$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 ) );
$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;
* @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'] );
*
* 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)
/**
* Generate a string of random colors for ImageMagick, like "rgb(12, 37, 98)"
- *
+ *
* @return {String}
*/
public function getRandomColor() {
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();
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
}
/*
- * 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" );
}
$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;
}
}
if ( $line_number < $number_desired ) {
throw new Exception( "not enough lines in $filepath" );
}
-
+
return $lines;
}
require("RandomImageGenerator.php");
-$getOptSpec = array(
+$getOptSpec = array(
'dictionaryFile::',
'minWidth::',
'maxWidth::',
$this->replaceVars( "ALTER TABLE foo\nADD COLUMN foo_bar int(10) unsigned DEFAULT 42" )
);
}
-
+
public function testTableName() {
// @todo Moar!
$db = new DatabaseSqliteStandalone( ':memory:' );
$this->db = wfGetDB( DB_MASTER );
if ( !$this->db ) {
$this->markTestIncomplete( "Can't find a database to test with." );
- }
+ }
parent::setup();
}
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() {
$article = new Article( $title, $id );
$article->doDeleteArticle( "Search Test" );
}*/
- }
+ }
function fetchIds( $results ) {
$this->assertTrue( is_object( $results ) );
// 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() {
self::$_instance = $this;
} else {
throw new MWException( "Already have one Selenium instance." );
- }
+ }
}
public function start() {
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 );
public function setVerbose( $verbose ) {
$this->verbose = $verbose;
}
-
+
public function setAvailableBrowsers( $availableBrowsers ) {
$this->browsers = $availableBrowsers;
}
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;
$this->browser = $this->browsers[$b];
}
-
+
public function getAvailableBrowsers() {
return $this->browsers;
}
}
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;
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 );
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'];
$seleniumTestSuites = $configArray['SeleniumTests']['testSuite'];
wfRestoreWarnings();
}
- return true;
+ return true;
}
private static function parse_5_2_ini_file ( $ConfigFile ) {
private $SeleniumServerExecPath;
public function __construct( $startServer,
- $serverPort,
- $serverExecPath ) {
+ $serverPort,
+ $serverExecPath ) {
$this->OS = (string) PHP_OS;
if ( isset( $startServer ) )
$this->SeleniumStartServer = $startServer;
$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 {
wfSuppressWarnings();
for ( $cnt = 1;
- $cnt <= $this->SeleniumServerStartTimeout;
- $cnt++ ) {
+ $cnt <= $this->SeleniumServerStartTimeout;
+ $cnt++ ) {
$fp = fsockopen ( 'localhost',
$this->SeleniumServerPort,
$errno, $errstr, 0 );
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';
}
}
private function stopServerOnWindows() {
- // Unimplemented.
+ // Unimplemented.
return 'failed';
}
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
public function loadPage( $title, $action ) {
$this->selenium->loadPage( $title, $action );
}
-
+
protected function setLoginBeforeTests( $loginBeforeTests = true ) {
$this->loginBeforeTests = $loginBeforeTests;
}