Move api/ApiTestUser.php to TestUser.php and make available in MediaWikiTestCase...
authorSiebrand Mazeland <s.mazeland@xs4all.nl>
Tue, 11 Sep 2012 00:07:18 +0000 (17:07 -0700)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 13 Sep 2012 18:40:23 +0000 (18:40 +0000)
* Renamed class ApiTestUser to TestUser.

Change-Id: I1c3c659c3ba5c54a314d879132f760008983372d

tests/TestsAutoLoader.php
tests/phpunit/MediaWikiTestCase.php
tests/phpunit/includes/PreferencesTest.php
tests/phpunit/includes/TestUser.php [new file with mode: 0644]
tests/phpunit/includes/api/ApiTestCase.php
tests/phpunit/includes/api/ApiTestUser.php [deleted file]
tests/phpunit/includes/upload/UploadStashTest.php

index cb5ca36..42f5f68 100644 (file)
@@ -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",
index bfad334..5fc4feb 100644 (file)
@@ -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
         */
index 664f04a..0e12317 100644 (file)
@@ -1,25 +1,24 @@
 <?php
 
 class PreferencesTest extends MediaWikiTestCase {
-
        /** Array of User objects */
-       private $users ;
-       private $context ;
+       private $prefUsers;
+       private $context;
 
        function __construct() {
                parent::__construct();
                global $wgEnableEmail;
 
-               $this->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 (file)
index 0000000..c4d8945
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+
+/* Wraps the user object, so we can also retain full access to properties like password if we log in via the API */
+class TestUser {
+       public $username;
+       public $password;
+       public $email;
+       public $groups;
+       public $user;
+
+       function __construct( $username, $realname = 'Real Name', $email = 'sample@example.com', $groups = array() ) {
+               $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
+               // 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();
+
+       }
+}
index d6c48cb..b84292e 100644 (file)
@@ -1,10 +1,6 @@
 <?php 
 
 abstract class ApiTestCase extends MediaWikiLangTestCase {
-       /**
-        * @var Array of ApiTestUser
-        */
-       public static $users;
        protected static $apiUrl;
 
        /**
@@ -23,13 +19,13 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
                $wgRequest = new FauxRequest( array() );
 
                self::$users = array(
-                       'sysop' => 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 (file)
index 8d5f61a..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-<?php
-
-/* Wraps the user object, so we can also retain full access to properties like password if we log in via the API */
-class ApiTestUser {
-       public $username;
-       public $password;
-       public $email;
-       public $groups;
-       public $user;
-
-       function __construct( $username, $realname = 'Real Name', $email = 'sample@example.com', $groups = array() ) {
-               $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
-               // 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();
-
-       }
-
-}
index dc1c2ac..66fafaa 100644 (file)
@@ -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',