X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiPageSetTest.php;h=fdc9c1b2b30c7897e144b5d1d5e175f4a6d20945;hp=10bdfa735cb8b83efc13354f5bf39591430c6038;hb=91fd689add2a4067d3e306fd0a5a2d8a6ffaff1b;hpb=95cf21f8ee45faaa6c933b42bebae687a28849c4 diff --git a/tests/phpunit/includes/api/ApiPageSetTest.php b/tests/phpunit/includes/api/ApiPageSetTest.php index 10bdfa735c..fdc9c1b2b3 100644 --- a/tests/phpunit/includes/api/ApiPageSetTest.php +++ b/tests/phpunit/includes/api/ApiPageSetTest.php @@ -1,5 +1,8 @@ getName(); $userDbkey = str_replace( ' ', '_', $userName ); $request = new FauxRequest( [ - 'titles' => join( '|', [ + 'titles' => implode( '|', [ 'Special:MyContributions', 'Special:MyPage', 'Special:MyTalk/subpage', @@ -176,4 +179,44 @@ class ApiPageSetTest extends ApiTestCase { 3 => [ "$userDbkey/subpage" => -3 ], ], $pageSet->getAllTitlesByNamespace() ); } + + /** + * Test that ApiPageSet is calling GenderCache for provided user names to prefill the + * GenderCache and avoid a performance issue when loading each users' gender on it's own. + * The test is setting the "missLimit" to 0 on the GenderCache to trigger misses logic. + * When the "misses" property is no longer 0 at the end of the test, + * something was requested which is not part of the cache. Than the test is failing. + */ + public function testGenderCaching() { + // Set up the user namespace to have gender aliases to trigger the gender cache + $this->setMwGlobals( [ + 'wgExtraGenderNamespaces' => [ NS_USER => [ 'male' => 'Male', 'female' => 'Female' ] ] + ] ); + $this->overrideMwServices(); + + // User names to test with - it is not needed that the user exists in the database + // to trigger gender cache + $userNames = [ + 'Female', + 'Unknown', + 'Male', + ]; + + // Prepare the gender cache for testing - this is a fresh instance due to service override + $genderCache = TestingAccessWrapper::newFromObject( + MediaWikiServices::getInstance()->getGenderCache() + ); + $genderCache->missLimit = 0; + + // Do an api request to trigger ApiPageSet code + $this->doApiRequest( [ + 'action' => 'query', + 'titles' => 'User:' . implode( '|User:', $userNames ), + ] ); + + $this->assertEquals( 0, $genderCache->misses, + 'ApiPageSet does not prefill the gender cache correctly' ); + $this->assertEquals( $userNames, array_keys( $genderCache->cache ), + 'ApiPageSet does not prefill all users into the gender cache' ); + } }