jenkins-bot has submitted this change and it was merged. Change subject: Refactor applyPermission out of the Test ......................................................................
Refactor applyPermission out of the Test Change-Id: Icb881141144fb940d7d1dc2857fdfad6e8638733 --- M repo/Wikibase.classes.php M repo/tests/phpunit/includes/EditEntityTest.php A repo/tests/phpunit/includes/PermissionsHelper.php M repo/tests/phpunit/includes/api/PermissionsTest.php M repo/tests/phpunit/includes/content/EntityContentTest.php 5 files changed, 63 insertions(+), 33 deletions(-) Approvals: Tobias Gritschacher: Looks good to me, approved jenkins-bot: Verified diff --git a/repo/Wikibase.classes.php b/repo/Wikibase.classes.php index 272a82a..ed31986 100644 --- a/repo/Wikibase.classes.php +++ b/repo/Wikibase.classes.php @@ -174,6 +174,7 @@ 'Wikibase\Test\Api\LangAttributeTestCase' => 'tests/phpunit/includes/api/LangAttributeTestCase.php', 'Wikibase\Test\Api\LangAttributeTestHelper' => 'tests/phpunit/includes/api/LangAttributeTestHelper.php', 'Wikibase\Test\Api\EntityTestHelper' => 'tests/phpunit/includes/api/EntityTestHelper.php', + 'Wikibase\Test\PermissionsHelper' => 'tests/phpunit/includes/PermissionsHelper.php', 'Wikibase\Test\EntityContentTest' => 'tests/phpunit/includes/content/EntityContentTest.php', 'Wikibase\Test\EntityHandlerTest' => 'tests/phpunit/includes/content/EntityHandlerTest.php', 'Wikibase\Test\RdfBuilderTest' => 'tests/phpunit/includes/rdf/RdfBuilderTest.php', diff --git a/repo/tests/phpunit/includes/EditEntityTest.php b/repo/tests/phpunit/includes/EditEntityTest.php index bb7c603..d08fbbe 100644 --- a/repo/tests/phpunit/includes/EditEntityTest.php +++ b/repo/tests/phpunit/includes/EditEntityTest.php @@ -7,7 +7,6 @@ use \Wikibase\ItemContent; use \Wikibase\Item; use \Status; -use Wikibase\Test\Api\PermissionsTest; /** * Test EditEntity. @@ -430,7 +429,7 @@ } if ( $permissions !== null ) { - PermissionsTest::applyPermissions( array( + PermissionsHelper::applyPermissions( array( '*' => $permissions, 'user' => $permissions, $group => $permissions, diff --git a/repo/tests/phpunit/includes/PermissionsHelper.php b/repo/tests/phpunit/includes/PermissionsHelper.php new file mode 100644 index 0000000..b6ac1de --- /dev/null +++ b/repo/tests/phpunit/includes/PermissionsHelper.php @@ -0,0 +1,58 @@ +<?php + +namespace Wikibase\Test; + +/** + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @since 0.4 + * + * @licence GNU GPL v2+ + * @author Daniel Kinzler + * @author Adam Shorland + */ +class PermissionsHelper { + + /** + * Utility function for applying a set of permissions to $wgGroupPermissions. + * Automatically resets the rights cache for $wgUser. + * No measures are taken to restore the original permissions later, this is up to the caller. + * + * @param $permissions + */ + public static function applyPermissions( $permissions ) { + global $wgGroupPermissions; + global $wgUser; + + if ( !$permissions ) { + return; + } + + foreach ( $permissions as $group => $rights ) { + if ( !empty( $wgGroupPermissions[ $group ] ) ) { + $wgGroupPermissions[ $group ] = array_merge( $wgGroupPermissions[ $group ], $rights ); + } else { + $wgGroupPermissions[ $group ] = $rights; + } + } + + // reset rights cache + $wgUser->addGroup( "dummy" ); + $wgUser->removeGroup( "dummy" ); + } + +} diff --git a/repo/tests/phpunit/includes/api/PermissionsTest.php b/repo/tests/phpunit/includes/api/PermissionsTest.php index ff36a0c..b8588e5 100644 --- a/repo/tests/phpunit/includes/api/PermissionsTest.php +++ b/repo/tests/phpunit/includes/api/PermissionsTest.php @@ -3,6 +3,7 @@ namespace Wikibase\Test\Api; use ApiTestCase; use Wikibase\Settings; +use Wikibase\Test\PermissionsHelper; /** * Tests for permission handling in the Wikibase API. @@ -88,38 +89,10 @@ parent::tearDown(); } - /** - * Utility function for applying a set of permissions to $wgGroupPermissions. - * Automatically resets the rights cache for $wgUser. - * No measures are taken to restore the original permissions later, this is up to the caller. - * - * @param $permissions - */ - public static function applyPermissions( $permissions ) { - global $wgGroupPermissions; - global $wgUser; - - if ( !$permissions ) { - return; - } - - foreach ( $permissions as $group => $rights ) { - if ( !empty( $wgGroupPermissions[ $group ] ) ) { - $wgGroupPermissions[ $group ] = array_merge( $wgGroupPermissions[ $group ], $rights ); - } else { - $wgGroupPermissions[ $group ] = $rights; - } - } - - // reset rights cache - $wgUser->addGroup( "dummy" ); - $wgUser->removeGroup( "dummy" ); - } - function doPermissionsTest( $action, $params, $permissions = array(), $expectedError = null, array $restore = array() ) { global $wgUser; - self::applyPermissions( $permissions ); + PermissionsHelper::applyPermissions( $permissions ); try { if ( !Settings::get( 'apiInDebug' ) || Settings::get( 'apiDebugWithTokens', false ) ) { diff --git a/repo/tests/phpunit/includes/content/EntityContentTest.php b/repo/tests/phpunit/includes/content/EntityContentTest.php index e2e2a84..79bf924 100644 --- a/repo/tests/phpunit/includes/content/EntityContentTest.php +++ b/repo/tests/phpunit/includes/content/EntityContentTest.php @@ -2,7 +2,6 @@ namespace Wikibase\Test; use Wikibase\EntityContent; -use Wikibase\Test\Api\PermissionsTest; /** * @covers Wikibase\EntityContent @@ -275,7 +274,7 @@ } if ( $permissions !== null ) { - PermissionsTest::applyPermissions( array( + PermissionsHelper::applyPermissions( array( '*' => $permissions, 'user' => $permissions, $group => $permissions, -- To view, visit https://gerrit.wikimedia.org/r/79046 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Icb881141144fb940d7d1dc2857fdfad6e8638733 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com> Gerrit-Reviewer: Tobias Gritschacher <tobias.gritschac...@wikimedia.de> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits