Store original media dimensions as additional header
[lhc/web/wiklou.git] / tests / phpunit / includes / TestUser.php
index 6887ed1..86f4ae7 100644 (file)
@@ -6,25 +6,19 @@
  */
 class TestUser {
        /**
-        * @deprecated Since 1.25. Use TestUser::getUser()->getName()
-        * @private
         * @var string
         */
-       public $username;
+       private $username;
 
        /**
-        * @deprecated Since 1.25. Use TestUser::getPassword()
-        * @private
         * @var string
         */
-       public $password;
+       private $password;
 
        /**
-        * @deprecated Since 1.25. Use TestUser::getUser()
-        * @private
         * @var User
         */
-       public $user;
+       private $user;
 
        private function assertNotReal() {
                global $wgDBprefix;
@@ -36,7 +30,7 @@ class TestUser {
        }
 
        public function __construct( $username, $realname = 'Real Name',
-               $email = 'sample@example.com', $groups = array()
+               $email = 'sample@example.com', $groups = []
        ) {
                $this->assertNotReal();
 
@@ -53,10 +47,10 @@ class TestUser {
                if ( !$this->user->isLoggedIn() ) {
                        // create the user
                        $this->user = User::createNew(
-                               $this->username, array(
+                               $this->username, [
                                        "email" => $email,
                                        "real_name" => $realname
-                               )
+                               ]
                        );
 
                        if ( !$this->user ) {
@@ -78,6 +72,12 @@ class TestUser {
                        $this->user->removeGroup( $group );
                }
                if ( $change ) {
+                       // Disable CAS check before saving. The User object may have been initialized from cached
+                       // information that may be out of whack with the database during testing. If tests were
+                       // perfectly isolated, this would not happen. But if it does happen, let's just ignore the
+                       // inconsistency, and just write the data we want - during testing, we are not worried
+                       // about data loss.
+                       $this->user->mTouched = '';
                        $this->user->saveSettings();
                }
        }
@@ -129,20 +129,32 @@ class TestUser {
                        throw new MWException( "Passed User has not been added to the database yet!" );
                }
 
-               $passwordFactory = new PasswordFactory();
-               $passwordFactory->init( RequestContext::getMain()->getConfig() );
-               // A is unsalted MD5 (thus fast) ... we don't care about security here, this is test only
-               $passwordFactory->setDefaultType( 'A' );
-               $pwhash = $passwordFactory->newFromPlaintext( $password );
-               wfGetDB( DB_MASTER )->update(
+               $dbw = wfGetDB( DB_MASTER );
+               $row = $dbw->selectRow(
                        'user',
-                       array( 'user_password' => $pwhash->toString() ),
-                       array( 'user_id' => $user->getId() ),
+                       [ 'user_password' ],
+                       [ 'user_id' => $user->getId() ],
                        __METHOD__
                );
+               if ( !$row ) {
+                       throw new MWException( "Passed User has an ID but is not in the database?" );
+               }
+
+               $passwordFactory = new PasswordFactory();
+               $passwordFactory->init( RequestContext::getMain()->getConfig() );
+               if ( !$passwordFactory->newFromCiphertext( $row->user_password )->equals( $password ) ) {
+                       $passwordHash = $passwordFactory->newFromPlaintext( $password );
+                       $dbw->update(
+                               'user',
+                               [ 'user_password' => $passwordHash->toString() ],
+                               [ 'user_id' => $user->getId() ],
+                               __METHOD__
+                       );
+               }
        }
 
        /**
+        * @since 1.25
         * @return User
         */
        public function getUser() {
@@ -150,6 +162,7 @@ class TestUser {
        }
 
        /**
+        * @since 1.25
         * @return string
         */
        public function getPassword() {