aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/api/query
diff options
context:
space:
mode:
authorDreamy Jazz <wpgbrown@wikimedia.org>2024-03-26 15:04:36 +0000
committerDreamy Jazz <dreamyjazzwikipedia@gmail.com>2024-04-03 16:25:47 +0000
commit102424bfb31825a46f8a6ba5bd21ff8f76938046 (patch)
tree56af6b516ef166ece50ab4120dc045e1fb0a28b2 /tests/phpunit/includes/api/query
parentf421c2786190dc83146daf62bafac3ab63fa62c3 (diff)
downloadmediawikicore-102424bfb31825a46f8a6ba5bd21ff8f76938046.tar.gz
mediawikicore-102424bfb31825a46f8a6ba5bd21ff8f76938046.zip
Update wgAutoCreateTempUser config defaults
Why: * The default value of wgAutoCreateTempUser has not changed since the decision to use a different prefix for temporary accounts (T332805). * The default needs to be updated to reduce the number of overrides in operations/mediawiki-config and also to make the development experience more consistent with what is happening on WMF production. What: * Update the wgAutoCreateTempUser default in the following ways: ** Set expireAfterDays as 365 ** Set notifyBeforeExpirationDays as 10 ** Set genPattern and reservedPattern to '~$1' ** Set matchPattern to null, which will mean that the genPattern is used as the value. * Update RealTempUserConfig::getPlaceholderName to add the year to the placeholder name so that if the match pattern includes the first digit of the year, then the placeholder name still is considered a valid temporary account username. * Replace modifications of the wgAutoCreateTempUser config in integration tests with a use of the TempUserTestTrait to make the code cleaner and make it easier to find tests that relies on the values in wgAutoCreateTempUser. * Update multiple tests to handle the new defaults for the config. Bug: T359335 Change-Id: Ifa5a0123cd915bdb7c87e473c51fb93321622f12
Diffstat (limited to 'tests/phpunit/includes/api/query')
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryImageInfoTest.php20
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryInfoTest.php15
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryLogEventsTest.php2
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryRecentChangesIntegrationTest.php20
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryRevisionsTest.php2
-rw-r--r--tests/phpunit/includes/api/query/ApiQuerySiteinfoTest.php40
6 files changed, 35 insertions, 64 deletions
diff --git a/tests/phpunit/includes/api/query/ApiQueryImageInfoTest.php b/tests/phpunit/includes/api/query/ApiQueryImageInfoTest.php
index 5ce33a3567dd..8dbee39cb6a1 100644
--- a/tests/phpunit/includes/api/query/ApiQueryImageInfoTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryImageInfoTest.php
@@ -4,9 +4,9 @@ namespace MediaWiki\Tests\Api\Query;
use ApiQueryImageInfo;
use File;
-use MediaWiki\MainConfigNames;
use MediaWiki\Tests\Api\ApiTestCase;
use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait;
+use MediaWiki\Tests\User\TempUser\TempUserTestTrait;
use MediaWiki\User\UserIdentityValue;
use MediaWiki\Utils\MWTimestamp;
@@ -18,6 +18,7 @@ use MediaWiki\Utils\MWTimestamp;
*/
class ApiQueryImageInfoTest extends ApiTestCase {
use MockAuthorityTrait;
+ use TempUserTestTrait;
private const IMAGE_NAME = 'Random-11m.png';
@@ -111,19 +112,10 @@ class ApiQueryImageInfoTest extends ApiTestCase {
);
// Set up temp user config
- $this->overrideConfigValue(
- MainConfigNames::AutoCreateTempUser,
- [
- 'enabled' => true,
- 'expireAfterDays' => null,
- 'actions' => [ 'edit' ],
- 'genPattern' => '*Unregistered $1',
- 'matchPattern' => '*$1',
- 'serialProvider' => [ 'type' => 'local' ],
- 'serialMapping' => [ 'type' => 'plain-numeric' ],
- ]
- );
- $this->tempUser = new UserIdentityValue( 1236764321, '*Unregistered 1' );
+ $this->enableAutoCreateTempUser();
+ $this->tempUser = $this->getServiceContainer()
+ ->getTempUserCreator()
+ ->create()->getUser();
$tempActorId = $this->getServiceContainer()
->getActorStore()
->acquireActorId( $this->tempUser, $this->db );
diff --git a/tests/phpunit/includes/api/query/ApiQueryInfoTest.php b/tests/phpunit/includes/api/query/ApiQueryInfoTest.php
index 3b5442afa4f2..080202581a50 100644
--- a/tests/phpunit/includes/api/query/ApiQueryInfoTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryInfoTest.php
@@ -6,6 +6,7 @@ use MediaWiki\Block\DatabaseBlock;
use MediaWiki\Context\RequestContext;
use MediaWiki\MainConfigNames;
use MediaWiki\Tests\Api\ApiTestCase;
+use MediaWiki\Tests\User\TempUser\TempUserTestTrait;
use MediaWiki\Title\Title;
use MediaWiki\User\User;
use Wikimedia\Timestamp\ConvertibleTimestamp;
@@ -18,6 +19,7 @@ use Wikimedia\Timestamp\ConvertibleTimestamp;
* @covers \ApiQueryInfo
*/
class ApiQueryInfoTest extends ApiTestCase {
+ use TempUserTestTrait;
protected function setUp(): void {
parent::setUp();
@@ -119,9 +121,7 @@ class ApiQueryInfoTest extends ApiTestCase {
$title = $page->getTitle();
// Disabled
- $this->overrideConfigValue( MainConfigNames::AutoCreateTempUser, [
- 'enabled' => false,
- ] );
+ $this->disableAutoCreateTempUser();
[ $data ] = $this->doApiRequest( [
'action' => 'query',
'prop' => 'info',
@@ -134,14 +134,7 @@ class ApiQueryInfoTest extends ApiTestCase {
// Enabled
$this->setGroupPermissions( '*', 'createaccount', true );
- $this->overrideConfigValue( MainConfigNames::AutoCreateTempUser, [
- 'enabled' => true,
- 'expireAfterDays' => null,
- 'actions' => [ 'edit' ],
- 'genPattern' => 'Unregistered $1',
- 'serialProvider' => [],
- 'serialMapping' => [],
- ] );
+ $this->enableAutoCreateTempUser();
[ $data ] = $this->doApiRequest( [
'action' => 'query',
'prop' => 'info',
diff --git a/tests/phpunit/includes/api/query/ApiQueryLogEventsTest.php b/tests/phpunit/includes/api/query/ApiQueryLogEventsTest.php
index f9635bb860df..75f32fddef64 100644
--- a/tests/phpunit/includes/api/query/ApiQueryLogEventsTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryLogEventsTest.php
@@ -21,7 +21,7 @@ class ApiQueryLogEventsTest extends ApiTestCase {
*/
public function testLogEventByTempUser() {
$this->enableAutoCreateTempUser();
- $tempUser = new UserIdentityValue( 1236764321, '*Unregistered 1' );
+ $tempUser = new UserIdentityValue( 1236764321, '~1' );
$title = $this->getNonexistingTestPage( 'TestPage1' )->getTitle();
$this->editPage(
$title,
diff --git a/tests/phpunit/includes/api/query/ApiQueryRecentChangesIntegrationTest.php b/tests/phpunit/includes/api/query/ApiQueryRecentChangesIntegrationTest.php
index 4269b55930bf..8a65c29a2e46 100644
--- a/tests/phpunit/includes/api/query/ApiQueryRecentChangesIntegrationTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryRecentChangesIntegrationTest.php
@@ -3,9 +3,9 @@
namespace MediaWiki\Tests\Api\Query;
use MediaWiki\Linker\LinkTarget;
-use MediaWiki\MainConfigNames;
use MediaWiki\Permissions\Authority;
use MediaWiki\Tests\Api\ApiTestCase;
+use MediaWiki\Tests\User\TempUser\TempUserTestTrait;
use MediaWiki\Title\TitleValue;
use MediaWiki\User\User;
use MediaWiki\User\UserIdentityValue;
@@ -20,6 +20,7 @@ use WatchedItemQueryService;
* @covers \ApiQueryRecentChanges
*/
class ApiQueryRecentChangesIntegrationTest extends ApiTestCase {
+ use TempUserTestTrait;
private function getLoggedInTestUser() {
return $this->getTestUser()->getUser();
@@ -68,24 +69,13 @@ class ApiQueryRecentChangesIntegrationTest extends ApiTestCase {
private function doTempPageEdit( LinkTarget $target, $summary ) {
// Set up temp user config
- $this->overrideConfigValue(
- MainConfigNames::AutoCreateTempUser,
- [
- 'enabled' => true,
- 'expireAfterDays' => null,
- 'actions' => [ 'edit' ],
- 'genPattern' => '*Unregistered $1',
- 'matchPattern' => '*$1',
- 'serialProvider' => [ 'type' => 'local' ],
- 'serialMapping' => [ 'type' => 'plain-numeric' ],
- ]
- );
+ $this->enableAutoCreateTempUser();
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromLinkTarget( $target );
$page->doUserEditContent(
$page->getContentHandler()->unserializeContent( __CLASS__ ),
$this->getServiceContainer()
->getUserFactory()
- ->newFromUserIdentity( new UserIdentityValue( 123456, '*Unregistered 1' ) ),
+ ->newFromUserIdentity( new UserIdentityValue( 123456, '~1' ) ),
$summary
);
}
@@ -320,7 +310,7 @@ class ApiQueryRecentChangesIntegrationTest extends ApiTestCase {
[
'type' => 'new',
'temp' => true,
- 'user' => '*Unregistered 1',
+ 'user' => '~1',
],
[
'type' => 'new',
diff --git a/tests/phpunit/includes/api/query/ApiQueryRevisionsTest.php b/tests/phpunit/includes/api/query/ApiQueryRevisionsTest.php
index 0d03be7b123a..ce2f4be23717 100644
--- a/tests/phpunit/includes/api/query/ApiQueryRevisionsTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryRevisionsTest.php
@@ -60,7 +60,7 @@ class ApiQueryRevisionsTest extends ApiTestCase {
*/
public function testRevisionMadeByTempUser() {
$this->enableAutoCreateTempUser();
- $tempUser = new UserIdentityValue( 1236764321, '*Unregistered 1' );
+ $tempUser = new UserIdentityValue( 1236764321, '~1' );
$title = $this->getNonexistingTestPage( 'TestPage1' )->getTitle();
$this->editPage(
diff --git a/tests/phpunit/includes/api/query/ApiQuerySiteinfoTest.php b/tests/phpunit/includes/api/query/ApiQuerySiteinfoTest.php
index 5e2ce9a4638a..a2ae1497590c 100644
--- a/tests/phpunit/includes/api/query/ApiQuerySiteinfoTest.php
+++ b/tests/phpunit/includes/api/query/ApiQuerySiteinfoTest.php
@@ -10,6 +10,7 @@ use MediaWiki\MainConfigSchema;
use MediaWiki\Message\Message;
use MediaWiki\SiteStats\SiteStats;
use MediaWiki\Tests\Api\ApiTestCase;
+use MediaWiki\Tests\User\TempUser\TempUserTestTrait;
use MediaWiki\Title\Title;
use Skin;
use Wikimedia\Composer\ComposerInstalled;
@@ -24,6 +25,8 @@ use Wikimedia\TestingAccessWrapper;
* @covers \ApiQuerySiteinfo
*/
class ApiQuerySiteinfoTest extends ApiTestCase {
+ use TempUserTestTrait;
+
private $originalRegistryLoaded = null;
protected function tearDown(): void {
@@ -375,35 +378,28 @@ class ApiQuerySiteinfoTest extends ApiTestCase {
}
public function testAutoCreateTempUser() {
- $config = $expected = [ 'enabled' => false ];
- $this->overrideConfigValue( MainConfigNames::AutoCreateTempUser, $config );
+ $this->disableAutoCreateTempUser();
$this->assertSame(
- $expected,
+ [ 'enabled' => false ],
$this->doQuery( 'autocreatetempuser' ),
'When disabled, no other properties are present'
);
- $config = [
- 'enabled' => true,
- 'expireAfterDays' => null,
- 'actions' => [ 'edit' ],
- 'genPattern' => 'Unregistered $1',
+ $this->enableAutoCreateTempUser( [
'reservedPattern' => null,
- 'serialProvider' => [ 'type' => 'local' ],
- 'serialMapping' => [ 'type' => 'plain-numeric' ],
- ];
- $expected = [
- 'enabled' => true,
- 'actions' => [ 'edit' ],
- 'genPattern' => 'Unregistered $1',
- 'matchPattern' => 'Unregistered $1',
- 'serialProvider' => [ 'type' => 'local' ],
- 'serialMapping' => [ 'type' => 'plain-numeric' ],
- ];
- $this->overrideConfigValue( MainConfigNames::AutoCreateTempUser, $config );
- $this->assertSame(
- $expected,
+ ] );
+ $this->assertArrayEquals(
+ [
+ 'enabled' => true,
+ 'actions' => [ 'edit' ],
+ 'genPattern' => '~$1',
+ 'matchPattern' => '~$1',
+ 'serialProvider' => [ 'type' => 'local', 'useYear' => true ],
+ 'serialMapping' => [ 'type' => 'plain-numeric' ],
+ ],
$this->doQuery( 'autocreatetempuser' ),
+ false,
+ true,
'When enabled, some properties are filled in or cleaned up'
);
}