diff options
author | Gergő Tisza <tgr.huwiki@gmail.com> | 2022-08-17 17:35:37 -0700 |
---|---|---|
committer | Kosta Harlan <kharlan@wikimedia.org> | 2022-08-31 11:51:18 +0000 |
commit | 0024c7195477d4ca427aa42b360949942653c6b9 (patch) | |
tree | d673c7cc0248ec24b1ab03aa8fea23f06826a2ba /tests/phpunit/includes/api/query/ApiQueryUserInfoTest.php | |
parent | 04bdfa50f0fddb429d2d7171a4c6d4f947793254 (diff) | |
download | mediawikicore-0024c7195477d4ca427aa42b360949942653c6b9.tar.gz mediawikicore-0024c7195477d4ca427aa42b360949942653c6b9.zip |
Add cancreateaccount property to userinfo API
Add a new action=query&meta=userinfo&uiprop=cancreateaccount
API property that checks whether the current user is allowed to
create accounts. This replaces the functionality removed from
list=users&usprop=cancreate in Ie94d61640301192b287275311f345,
and makes more sense - list=users is supposed to be about the
username (and re-called every time the username in the
registration form is changed), while meta=userinfo is about the
current user. It's also more accurate: it checks for all things
integrated with the permission system.
Change-Id: I0006500245a7c2bc3be0310ce9860b5771637a29
Diffstat (limited to 'tests/phpunit/includes/api/query/ApiQueryUserInfoTest.php')
-rw-r--r-- | tests/phpunit/includes/api/query/ApiQueryUserInfoTest.php | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/phpunit/includes/api/query/ApiQueryUserInfoTest.php b/tests/phpunit/includes/api/query/ApiQueryUserInfoTest.php index abbac8224488..d528aed53a2d 100644 --- a/tests/phpunit/includes/api/query/ApiQueryUserInfoTest.php +++ b/tests/phpunit/includes/api/query/ApiQueryUserInfoTest.php @@ -49,4 +49,37 @@ class ApiQueryUserInfoTest extends ApiTestCase { $queryTimestamp = $apiResult[0]['query']['userinfo']['latestcontrib']; $this->assertSame( $revisionTimestamp, $queryTimestamp ); } + + public function testCanCreateAccount() { + $params = [ + 'action' => 'query', + 'meta' => 'userinfo', + 'uiprop' => 'cancreateaccount', + ]; + $user = $this->getTestUser()->getUser(); + $apiResult = $this->doApiRequest( $params, null, false, $user ); + $this->assertArrayHasKey( 'query', $apiResult[0] ); + $this->assertArrayHasKey( 'userinfo', $apiResult[0]['query'] ); + $this->assertArrayHasKey( 'cancreateaccount', $apiResult[0]['query']['userinfo'] ); + $this->assertTrue( $apiResult[0]['query']['userinfo']['cancreateaccount'] ); + $this->assertArrayNotHasKey( 'cancreateaccounterror', $apiResult[0]['query']['userinfo'] ); + + $user = $this->getMutableTestUser()->getUser(); + $status = $this->getServiceContainer()->getBlockUserFactory()->newBlockUser( + $user, + $this->getTestSysop()->getUser(), + 'infinity', + '', + [ 'isCreateAccountBlocked' => true ] + )->placeBlock(); + if ( !$status->isGood() ) { + $this->fail( $status->getWikiText( false, false, 'en' ) ); + } + $apiResult = $this->doApiRequest( $params, null, false, $user ); + $this->assertArrayHasKey( 'query', $apiResult[0] ); + $this->assertArrayHasKey( 'userinfo', $apiResult[0]['query'] ); + $this->assertArrayHasKey( 'cancreateaccount', $apiResult[0]['query']['userinfo'] ); + $this->assertFalse( $apiResult[0]['query']['userinfo']['cancreateaccount'] ); + $this->assertArrayHasKey( 'cancreateaccounterror', $apiResult[0]['query']['userinfo'] ); + } } |