Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/289373

Change subject: foo
......................................................................

foo

Change-Id: I0ef8dd29ee2fd22ebe71636332993ca895f0560a
---
M tests/phpunit/MediaWikiTestCase.php
1 file changed, 33 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/73/289373/1

diff --git a/tests/phpunit/MediaWikiTestCase.php 
b/tests/phpunit/MediaWikiTestCase.php
index 3b08157..dedd087 100644
--- a/tests/phpunit/MediaWikiTestCase.php
+++ b/tests/phpunit/MediaWikiTestCase.php
@@ -127,6 +127,16 @@
                self::prepareServices( new GlobalVarConfig() );
        }
 
+       public static function getTestSysop( $mutable = false ) {
+               return self::getTestUser( $mutable, [ 'sysop', 'bureaucrat' ] );
+       }
+
+       public static function getTestUser( $mutable = false, $groups = [] ) {
+               return $mutable
+                       ? TestUserRegistry::getMutableTestUser( __CLASS__, 
$groups )
+                       : TestUserRegistry::getImmutableTestUser( $groups );
+       }
+
        /**
         * Prepare service configuration for unit testing.
         *
@@ -880,7 +890,7 @@
        protected function insertPage( $pageName, $text = 'Sample page for unit 
test.' ) {
                $title = Title::newFromText( $pageName, 0 );
 
-               $user = User::newFromName( 'UTSysop' );
+               $user = $this->getTestSysop()->getUser();
                $comment = __METHOD__ . ': Sample page for unit test.';
 
                // Avoid memory leak...?
@@ -931,36 +941,33 @@
 
                        # Insert 0 user to prevent FK violations
                        # Anonymous user
-                       $this->db->insert( 'user', [
-                               'user_id' => 0,
-                               'user_name' => 'Anonymous' ], __METHOD__, [ 
'IGNORE' ] );
+                       if ( !$this->db->selectField( 'user', '1', [ 'user_id' 
=> 0 ] ) ) {
+                               $this->db->insert( 'user', [
+                                       'user_id' => 0,
+                                       'user_name' => 'Anonymous' ], 
__METHOD__, [ 'IGNORE' ] );
+                       }
 
                        # Insert 0 page to prevent FK violations
                        # Blank page
-                       $this->db->insert( 'page', [
-                               'page_id' => 0,
-                               'page_namespace' => 0,
-                               'page_title' => ' ',
-                               'page_restrictions' => null,
-                               'page_is_redirect' => 0,
-                               'page_is_new' => 0,
-                               'page_random' => 0,
-                               'page_touched' => $this->db->timestamp(),
-                               'page_latest' => 0,
-                               'page_len' => 0 ], __METHOD__, [ 'IGNORE' ] );
+                       if ( !$this->db->selectField( 'page', '1', [ 'page_id' 
=> 0 ] ) ) {
+                               $this->db->insert( 'page', [
+                                       'page_id' => 0,
+                                       'page_namespace' => 0,
+                                       'page_title' => ' ',
+                                       'page_restrictions' => null,
+                                       'page_is_redirect' => 0,
+                                       'page_is_new' => 0,
+                                       'page_random' => 0,
+                                       'page_touched' => 
$this->db->timestamp(),
+                                       'page_latest' => 0,
+                                       'page_len' => 0 ], __METHOD__, [ 
'IGNORE' ] );
+                       }
                }
 
                User::resetIdByNameCache();
 
                // Make sysop user
-               $user = User::newFromName( 'UTSysop' );
-
-               if ( $user->idForName() == 0 ) {
-                       $user->addToDatabase();
-                       TestUser::setPasswordForUser( $user, 'UTSysopPassword' 
);
-                       $user->addGroup( 'sysop' );
-                       $user->addGroup( 'bureaucrat' );
-               }
+               $user = TestUserRegistry::getImmutableTestUser( [ 'sysop', 
'bureaucrat' ] )->getUser();
 
                // Make 1 page with 1 revision
                $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
@@ -1184,6 +1191,8 @@
                                TestingAccessWrapper::newFromClass( 'User' )
                                        ->getInProcessCache()
                                        ->clear();
+
+                               TestUserRegistry::clear();
                        }
 
                        $truncate = in_array( $db->getType(), [ 'oracle', 
'mysql' ] );
@@ -1548,7 +1557,7 @@
         * @return int The ID of the wikitext Namespace
         * @since 1.21
         */
-       protected function getDefaultWikitextNS() {
+       protected static function getDefaultWikitextNS() {
                global $wgNamespaceContentModels;
 
                static $wikitextNS = null; // this is not going to change

-- 
To view, visit https://gerrit.wikimedia.org/r/289373
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0ef8dd29ee2fd22ebe71636332993ca895f0560a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to