X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FTitlePermissionTest.php;h=dd84b7eb01c9d3fc9c7866f8be68ba7f708999c1;hb=775bcac17220296e5d10d10178139a5884a4c7f2;hp=7dfb7357f5c31486be4b7d00ae7c5f09eb355235;hpb=0ded00ab4c6dc1ad4e961412d357080a0a5a056d;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/TitlePermissionTest.php b/tests/phpunit/includes/TitlePermissionTest.php index 7dfb7357f5..dd84b7eb01 100644 --- a/tests/phpunit/includes/TitlePermissionTest.php +++ b/tests/phpunit/includes/TitlePermissionTest.php @@ -1,5 +1,7 @@ user = $this->userUser; } + $this->overrideMwServices(); } protected function setUserPerm( $perm ) { @@ -96,11 +99,15 @@ class TitlePermissionTest extends MediaWikiLangTestCase { /** * @todo This test method should be split up into separate test methods and * data providers + * + * This test is failing per T201776. + * + * @group Broken * @covers Title::checkQuickPermissions */ public function testQuickPermissions() { - global $wgContLang; - $prefix = $wgContLang->getFormattedNsText( NS_PROJECT ); + $prefix = MediaWikiServices::getInstance()->getContentLanguage()-> + getFormattedNsText( NS_PROJECT ); $this->setUser( 'anon' ); $this->setTitle( NS_TALK ); @@ -453,14 +460,38 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->runConfigEditPermissions( [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ], + [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ], [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ], [ [ 'badaccess-group0' ] ], + [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ], [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ], [ [ 'badaccess-group0' ] ] ); } + /** + * @todo This test method should be split up into separate test methods and + * data providers + * @covers Title::checkUserConfigPermissions + */ + public function testJsonConfigEditPermissions() { + $this->setUser( $this->userName ); + + $this->setTitle( NS_USER, $this->userName . '/test.json' ); + $this->runConfigEditPermissions( + [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ], + + [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ], + [ [ 'badaccess-group0' ] ], + [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ], + + [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ], + [ [ 'badaccess-group0' ] ], + [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ] + ); + } + /** * @todo This test method should be split up into separate test methods and * data providers @@ -475,8 +506,10 @@ class TitlePermissionTest extends MediaWikiLangTestCase { [ [ 'badaccess-group0' ] ], [ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ], + [ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ], [ [ 'badaccess-group0' ] ], + [ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ], [ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ] ); } @@ -493,14 +526,38 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->runConfigEditPermissions( [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ], + [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ], [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ], [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ], + [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ], [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ], [ [ 'badaccess-group0' ] ] ); } + /** + * @todo This test method should be split up into separate test methods and + * data providers + * @covers Title::checkUserConfigPermissions + */ + public function testOtherJsonConfigEditPermissions() { + $this->setUser( $this->userName ); + + $this->setTitle( NS_USER, $this->altUserName . '/test.json' ); + $this->runConfigEditPermissions( + [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ], + + [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ], + [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ], + [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ], + + [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ], + [ [ 'badaccess-group0' ] ], + [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ] + ); + } + /** * @todo This test method should be split up into separate test methods and * data providers @@ -513,10 +570,12 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->runConfigEditPermissions( [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ], + [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ], [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ], [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ], [ [ 'badaccess-group0' ] ], + [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ], [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ] ); } @@ -533,9 +592,11 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->runConfigEditPermissions( [ [ 'badaccess-group0' ] ], + [ [ 'badaccess-group0' ] ], [ [ 'badaccess-group0' ] ], [ [ 'badaccess-group0' ] ], + [ [ 'badaccess-group0' ] ], [ [ 'badaccess-group0' ] ], [ [ 'badaccess-group0' ] ] ); @@ -544,8 +605,10 @@ class TitlePermissionTest extends MediaWikiLangTestCase { protected function runConfigEditPermissions( $resultNone, $resultMyCss, + $resultMyJson, $resultMyJs, $resultUserCss, + $resultUserJson, $resultUserJs ) { $this->setUserPerm( '' ); @@ -556,6 +619,10 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user ); $this->assertEquals( $resultMyCss, $result ); + $this->setUserPerm( 'editmyuserjson' ); + $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user ); + $this->assertEquals( $resultMyJson, $result ); + $this->setUserPerm( 'editmyuserjs' ); $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user ); $this->assertEquals( $resultMyJs, $result ); @@ -564,11 +631,15 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user ); $this->assertEquals( $resultUserCss, $result ); + $this->setUserPerm( 'edituserjson' ); + $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user ); + $this->assertEquals( $resultUserJson, $result ); + $this->setUserPerm( 'edituserjs' ); $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user ); $this->assertEquals( $resultUserJs, $result ); - $this->setUserPerm( [ 'edituserjs', 'editusercss' ] ); + $this->setUserPerm( [ 'edituserjs', 'edituserjson', 'editusercss' ] ); $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user ); $this->assertEquals( [ [ 'badaccess-group0' ] ], $result ); } @@ -576,12 +647,15 @@ class TitlePermissionTest extends MediaWikiLangTestCase { /** * @todo This test method should be split up into separate test methods and * data providers + * + * This test is failing per T201776. + * + * @group Broken * @covers Title::checkPageRestrictions */ public function testPageRestrictions() { - global $wgContLang; - - $prefix = $wgContLang->getFormattedNsText( NS_PROJECT ); + $prefix = MediaWikiServices::getInstance()->getContentLanguage()-> + getFormattedNsText( NS_PROJECT ); $this->setTitle( NS_MAIN ); $this->title->mRestrictionsLoaded = true; @@ -778,18 +852,23 @@ class TitlePermissionTest extends MediaWikiLangTestCase { * @covers Title::checkUserBlock */ public function testUserBlock() { - global $wgEmailConfirmToEdit, $wgEmailAuthentication; - $wgEmailConfirmToEdit = true; - $wgEmailAuthentication = true; + $this->setMwGlobals( [ + 'wgEmailConfirmToEdit' => true, + 'wgEmailAuthentication' => true, + ] ); $this->setUserPerm( [ "createpage", "move" ] ); $this->setTitle( NS_HELP, "test page" ); - # $short - $this->assertEquals( [ [ 'confirmedittext' ] ], + # $wgEmailConfirmToEdit only applies to 'edit' action + $this->assertEquals( [], $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); - $wgEmailConfirmToEdit = false; - $this->assertEquals( true, $this->title->userCan( 'move-target', $this->user ) ); + $this->assertContains( [ 'confirmedittext' ], + $this->title->getUserPermissionsErrors( 'edit', $this->user ) ); + + $this->setMwGlobals( 'wgEmailConfirmToEdit', false ); + $this->assertNotContains( [ 'confirmedittext' ], + $this->title->getUserPermissionsErrors( 'edit', $this->user ) ); # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount' $this->assertEquals( [],