From: Siebrand Mazeland Date: Tue, 11 Sep 2012 00:07:18 +0000 (-0700) Subject: Move api/ApiTestUser.php to TestUser.php and make available in MediaWikiTestCase... X-Git-Tag: 1.31.0-rc.0~22388 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=59ec5a325ccd42cf02343b4c3203fc9dadbc0719;p=lhc%2Fweb%2Fwiklou.git Move api/ApiTestUser.php to TestUser.php and make available in MediaWikiTestCase class. * Renamed class ApiTestUser to TestUser. Change-Id: I1c3c659c3ba5c54a314d879132f760008983372d --- diff --git a/tests/TestsAutoLoader.php b/tests/TestsAutoLoader.php index cb5ca36f13..42f5f68af2 100644 --- a/tests/TestsAutoLoader.php +++ b/tests/TestsAutoLoader.php @@ -17,7 +17,7 @@ $wgAutoloadClasses += array( //API 'ApiFormatTestBase' => "$testFolder/phpunit/includes/api/format/ApiFormatTestBase.php", 'ApiTestCase' => "$testFolder/phpunit/includes/api/ApiTestCase.php", - 'ApiTestUser' => "$testFolder/phpunit/includes/api/ApiTestUser.php", + 'TestUser' => "$testFolder/phpunit/includes/TestUser.php", 'MockApi' => "$testFolder/phpunit/includes/api/ApiTestCase.php", 'RandomImageGenerator' => "$testFolder/phpunit/includes/api/RandomImageGenerator.php", 'UserWrapper' => "$testFolder/phpunit/includes/api/ApiTestCase.php", diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index bfad334e65..5fc4feb9d6 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -5,6 +5,11 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { public $regex = ''; public $runDisabled = false; + /** + * @var Array of TestUser + */ + public static $users; + /** * @var DatabaseBase */ diff --git a/tests/phpunit/includes/PreferencesTest.php b/tests/phpunit/includes/PreferencesTest.php index 664f04adca..0e12317791 100644 --- a/tests/phpunit/includes/PreferencesTest.php +++ b/tests/phpunit/includes/PreferencesTest.php @@ -1,25 +1,24 @@ users['noemail'] = new User; + $this->prefUsers['noemail'] = new User; - $this->users['notauth'] = new User; - $this->users['notauth'] + $this->prefUsers['notauth'] = new User; + $this->prefUsers['notauth'] ->setEmail( 'noauth@example.org' ); - $this->users['auth'] = new User; - $this->users['auth'] + $this->prefUsers['auth'] = new User; + $this->prefUsers['auth'] ->setEmail( 'noauth@example.org' ); - $this->users['auth'] + $this->prefUsers['auth'] ->setEmailAuthenticationTimestamp( 1330946623 ); $this->context = new RequestContext; @@ -63,16 +62,14 @@ class PreferencesTest extends MediaWikiTestCase { $this->assertEquals( 'mw-email-authenticated', $prefs['emailaddress']['cssclass'] ); } - /** Helper */ function prefsFor( $user_key ) { $preferences = array(); Preferences::profilePreferences( - $this->users[$user_key] + $this->prefUsers[$user_key] , $this->context , $preferences ); return $preferences; } - } diff --git a/tests/phpunit/includes/TestUser.php b/tests/phpunit/includes/TestUser.php new file mode 100644 index 0000000000..c4d8945557 --- /dev/null +++ b/tests/phpunit/includes/TestUser.php @@ -0,0 +1,58 @@ +username = $username; + $this->realname = $realname; + $this->email = $email; + $this->groups = $groups; + + // 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. + $this->password = User::randomPassword(); + + $this->user = User::newFromName( $this->username ); + $this->user->load(); + + // In an ideal world we'd have a new wiki (or mock data store) for every single test. + // But for now, we just need to create or update the user with the desired properties. + // we particularly need the new password, since we just generated it randomly. + // 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->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->setRealName( $this->realname ); + // remove all groups, replace with any groups specified + foreach ( $this->user->getGroups() as $group ) { + $this->user->removeGroup( $group ); + } + if ( count( $this->groups ) ) { + foreach ( $this->groups as $group ) { + $this->user->addGroup( $group ); + } + } + $this->user->saveSettings(); + + } +} diff --git a/tests/phpunit/includes/api/ApiTestCase.php b/tests/phpunit/includes/api/ApiTestCase.php index d6c48cbd73..b84292e3cd 100644 --- a/tests/phpunit/includes/api/ApiTestCase.php +++ b/tests/phpunit/includes/api/ApiTestCase.php @@ -1,10 +1,6 @@ new ApiTestUser( + 'sysop' => new TestUser( 'Apitestsysop', 'Api Test Sysop', 'api_test_sysop@example.com', array( 'sysop' ) ), - 'uploader' => new ApiTestUser( + 'uploader' => new TestUser( 'Apitestuser', 'Api Test User', 'api_test_user@example.com', diff --git a/tests/phpunit/includes/api/ApiTestUser.php b/tests/phpunit/includes/api/ApiTestUser.php deleted file mode 100644 index 8d5f61a75f..0000000000 --- a/tests/phpunit/includes/api/ApiTestUser.php +++ /dev/null @@ -1,59 +0,0 @@ -username = $username; - $this->realname = $realname; - $this->email = $email; - $this->groups = $groups; - - // 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. - $this->password = User::randomPassword(); - - $this->user = User::newFromName( $this->username ); - $this->user->load(); - - // In an ideal world we'd have a new wiki (or mock data store) for every single test. - // But for now, we just need to create or update the user with the desired properties. - // we particularly need the new password, since we just generated it randomly. - // 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->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->setRealName( $this->realname ); - // remove all groups, replace with any groups specified - foreach ( $this->user->getGroups() as $group ) { - $this->user->removeGroup( $group ); - } - if ( count( $this->groups ) ) { - foreach ( $this->groups as $group ) { - $this->user->addGroup( $group ); - } - } - $this->user->saveSettings(); - - } - -} diff --git a/tests/phpunit/includes/upload/UploadStashTest.php b/tests/phpunit/includes/upload/UploadStashTest.php index dc1c2ac4fc..66fafaaffe 100644 --- a/tests/phpunit/includes/upload/UploadStashTest.php +++ b/tests/phpunit/includes/upload/UploadStashTest.php @@ -16,13 +16,13 @@ class UploadStashTest extends MediaWikiTestCase { file_put_contents( $this->bug29408File, "\x00" ); self::$users = array( - 'sysop' => new ApiTestUser( + 'sysop' => new TestUser( 'Uploadstashtestsysop', 'Upload Stash Test Sysop', 'upload_stash_test_sysop@example.com', array( 'sysop' ) ), - 'uploader' => new ApiTestUser( + 'uploader' => new TestUser( 'Uploadstashtestuser', 'Upload Stash Test User', 'upload_stash_test_user@example.com',