From 37ef4c4ad40962f3e2db409b068311072f4be28a Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Fri, 27 Mar 2015 22:22:51 -0700 Subject: [PATCH] Simplify TitleTest::testWgWhitelistReadRegexp() * Use setMwGlobals instead of doing it manually * Give user no rights to avoid a database query Change-Id: I3ab20972314e39bb81bc97c89fce7a4c0d331fe6 --- tests/phpunit/includes/TitleTest.php | 39 ++++++++-------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index 01c2578946..d55f958baf 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -325,36 +325,19 @@ class TitleTest extends MediaWikiTestCase { $whitelistRegexp = array( $whitelistRegexp ); } + $this->setMwGlobals( array( + // So User::isEveryoneAllowed( 'read' ) === false + 'wgGroupPermissions' => array( '*' => array( 'read' => false ) ), + 'wgWhitelistRead' => array( 'some random non sense title' ), + 'wgWhitelistReadRegexp' => $whitelistRegexp, + ) ); + $title = Title::newFromDBkey( $source ); - global $wgGroupPermissions; - $oldPermissions = $wgGroupPermissions; - // Disallow all so we can ensure our regex works - $wgGroupPermissions = array(); - $wgGroupPermissions['*']['read'] = false; - - global $wgWhitelistRead; - $oldWhitelist = $wgWhitelistRead; - // Undo any LocalSettings explicite whitelists so they won't cause a - // failing test to succeed. Set it to some random non sense just - // to make sure we properly test Title::checkReadPermissions() - $wgWhitelistRead = array( 'some random non sense title' ); - - global $wgWhitelistReadRegexp; - $oldWhitelistRegexp = $wgWhitelistReadRegexp; - $wgWhitelistReadRegexp = $whitelistRegexp; - - // Just use $wgUser which in test is a user object for '127.0.0.1' - global $wgUser; - // Invalidate user rights cache to take in account $wgGroupPermissions - // change above. - $wgUser->clearInstanceCache(); - $errors = $title->userCan( $action, $wgUser ); - - // Restore globals - $wgGroupPermissions = $oldPermissions; - $wgWhitelistRead = $oldWhitelist; - $wgWhitelistReadRegexp = $oldWhitelistRegexp; + // New anonymous user with no rights + $user = new User; + $user->mRights = array(); + $errors = $title->userCan( $action, $user ); if ( is_bool( $expected ) ) { # Forge the assertion message depending on the assertion expectation -- 2.20.1