aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/api/query/ApiQueryRecentChangesIntegrationTest.php
diff options
context:
space:
mode:
authorSTran <stran@wikimedia.org>2024-07-24 07:29:21 -0700
committerDreamy Jazz <wpgbrown@wikimedia.org>2024-07-29 11:00:22 +0100
commit311774c033ead2a2742bb7db8a69af109e8ab5d7 (patch)
tree880680acfc461e909f68ee67a3d6e0ef1a1efe44 /tests/phpunit/includes/api/query/ApiQueryRecentChangesIntegrationTest.php
parent07653be341eb6d3b8c4eef5c605c0a5d0c13084f (diff)
downloadmediawikicore-311774c033ead2a2742bb7db8a69af109e8ab5d7.tar.gz
mediawikicore-311774c033ead2a2742bb7db8a69af109e8ab5d7.zip
Filter temporary accounts as anonymous in ApiQueryRecentChanges
Edits from temporary accounts are considered anonymous edits. ApiQueryRecentChanges doesn't correctly reflect this and needs to be updated to correctly return temporary account edits as anonymous (and similarly, not to return them when requesting !anon) - Update the anon|!anon query to accomodate temporary accounts Bug: T370803 Change-Id: Ica5225422ea53d2aa3a84b86d9c2f14832a34ed4
Diffstat (limited to 'tests/phpunit/includes/api/query/ApiQueryRecentChangesIntegrationTest.php')
-rw-r--r--tests/phpunit/includes/api/query/ApiQueryRecentChangesIntegrationTest.php48
1 files changed, 40 insertions, 8 deletions
diff --git a/tests/phpunit/includes/api/query/ApiQueryRecentChangesIntegrationTest.php b/tests/phpunit/includes/api/query/ApiQueryRecentChangesIntegrationTest.php
index 1c0a0a510652..9c0db2244a8e 100644
--- a/tests/phpunit/includes/api/query/ApiQueryRecentChangesIntegrationTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryRecentChangesIntegrationTest.php
@@ -5,10 +5,10 @@ namespace MediaWiki\Tests\Api\Query;
use MediaWiki\Linker\LinkTarget;
use MediaWiki\Permissions\Authority;
use MediaWiki\Tests\Api\ApiTestCase;
+use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait;
use MediaWiki\Tests\User\TempUser\TempUserTestTrait;
use MediaWiki\Title\TitleValue;
use MediaWiki\User\User;
-use MediaWiki\User\UserIdentityValue;
use MediaWiki\Watchlist\WatchedItemQueryService;
use RecentChange;
@@ -20,6 +20,7 @@ use RecentChange;
* @covers \ApiQueryRecentChanges
*/
class ApiQueryRecentChangesIntegrationTest extends ApiTestCase {
+ use MockAuthorityTrait;
use TempUserTestTrait;
private function getLoggedInTestUser() {
@@ -74,9 +75,7 @@ class ApiQueryRecentChangesIntegrationTest extends ApiTestCase {
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromLinkTarget( $target );
$page->doUserEditContent(
$page->getContentHandler()->unserializeContent( __CLASS__ ),
- $this->getServiceContainer()
- ->getUserFactory()
- ->newFromUserIdentity( new UserIdentityValue( 123456, '~2024-1' ) ),
+ $this->mockTempUltimateAuthority(),
$summary
);
}
@@ -302,10 +301,26 @@ class ApiQueryRecentChangesIntegrationTest extends ApiTestCase {
$tempEditTarget = new TitleValue( NS_MAIN, 'Baz' );
$this->doPageEdit( $this->getLoggedInTestUser(), $userEditTarget, 'Create the page' );
$this->doAnonPageEdit( $anonEditTarget, 'Create the page' );
- $this->doTempPageEdit( $tempEditTarget, 'Create the page' );
- $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'user' ] );
+ // Test that querying for anonymous edits works even if temporary accounts are disabled
+ $this->disableAutoCreateTempUser();
+ $result = $this->doListRecentChangesRequest( [
+ 'rcprop' => 'user',
+ 'rcshow' => WatchedItemQueryService::FILTER_NOT_ANON,
+ ] );
+ $this->assertEquals(
+ [
+ [
+ 'type' => 'new',
+ 'user' => $this->getLoggedInTestUser()->getName(),
+ ],
+ ],
+ $this->getItemsFromRecentChangesResult( $result )
+ );
+ // Test that temporary accounts are treated as anonymous
+ $this->doTempPageEdit( $tempEditTarget, 'Create the page' );
+ $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'user' ] );
$this->assertEquals(
[
[
@@ -503,6 +518,9 @@ class ApiQueryRecentChangesIntegrationTest extends ApiTestCase {
$target = new TitleValue( NS_MAIN, 'Thing' );
$this->doAnonPageEdit( $target, 'Create the page' );
+ $tempEditTarget = new TitleValue( NS_MAIN, 'Baz' );
+ $this->doTempPageEdit( $tempEditTarget, 'Create the page' );
+
$resultAnon = $this->doListRecentChangesRequest( [
'rcprop' => 'user',
'rcshow' => WatchedItemQueryService::FILTER_ANON
@@ -513,8 +531,22 @@ class ApiQueryRecentChangesIntegrationTest extends ApiTestCase {
] );
$items = $this->getItemsFromRecentChangesResult( $resultAnon );
- $this->assertCount( 1, $items );
- $this->assertSame( true, $items[0]['anon'], 'anon' );
+ $this->assertCount( 2, $items );
+ $this->assertEquals(
+ [
+ [
+ 'type' => 'new',
+ 'temp' => true,
+ 'user' => '~2024-1',
+ ],
+ [
+ 'type' => 'new',
+ 'anon' => true,
+ 'user' => '127.0.0.1',
+ ],
+ ],
+ $items
+ );
$this->assertSame( [], $this->getItemsFromRecentChangesResult( $resultNotAnon ) );
}