aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/integration/includes/user
Commit message (Collapse)AuthorAgeFilesLines
* Namespace all remaining files in includes/exceptionJames D. Forrester2025-03-251-1/+1
| | | | | | | | | In MediaWiki/Exception, to follow PSR-4 per plural vs. singular (this can be changed later if people really care). Also, move the couple of exceptions in here that were already namespaced in the MW-top-level into the new space. Bug: T353458 Change-Id: I12ed850ae99effb699a6d7ada173f54e72f0570e
* Fix expensive computations before cache hit and add additional caching to ↵Dylan F2025-03-161-1/+2
| | | | | | | | | | | DefaultOptionsLookup * Moved getCacheKey to UserOptionsLookup * Added caching to DefaultOptionsLookup after conditional options * Move expensive getDefaultOptions to after cache miss Bug: T386883 Change-Id: I307e1d30e84396b56d919993aef4d411ecae8ea1
* user: Allow gender to be a global preferenceTim Starling2025-03-063-1/+33
| | | | | | | | | | | | | | | | | | | | | | | | GenderCache gets the "gender" user preference directly out of the core database. Thus it does not respect global preferences. So: * Add UserOptionsLookup::getOptionBatchForUserNames(), which gets a single user preference for a set of named users. * Add UserOptionsStore::fetchBatchForUserNames() as a backend. This is a new interface method so is a breaking change. * Have GenderCache call the new interface. The no-database case in ServiceWiring is apparently no longer reachable from the installer due to my previous patch which split MediaWikiTitleCodec. Performance generally degrades from one query to three. For change lists and user page namespace redirects, it shouldn't be a problem, but for the {{GENDER}} parser function there may be a user-visible performance degradation. Bug: T386584 Depends-On: Id02489a597f96cd1cd6db08e16b3624542fdf1f7 Change-Id: I9646b5422afce356e9a1dceeb09d8d4e286dc65e
* user: Add UserOptionsManager::GLOBAL_CREATETim Starling2025-02-242-28/+100
| | | | | | | | | Provide an interface allowing extensions to add global preferences. Add test for all the $global values. Bug: T386592 Change-Id: Id982656e228efaa97068b90f5137a0495c86fae5
* user: Implement batch user registration lookupsMáté Szabó2025-02-192-31/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Why: - The TSP team would like to change the way expired temporary account user links are displayed, which requires an efficient way to fetch their registration timestamps. - On WMF wikis, which use CentralAuth, this requires fetching the first (i.e. global) registration timestamp of the account, rather than the naïve approach of using the registration timestamp from the local user table. - MediaWiki provides the UserRegistrationLookup facade to transparently fetch the earliest registration timestamp for a single user, but offers no batch interface to do the same. - Since user links are often rendered in large pagers, a batch interface is needed. What: - Add IUserRegistrationProvider::fetchRegistrationBatch(), which takes an iterable of UserIdentities and returns a map of their registration timestamps (or null if not available), keyed by user ID. Although this interface is marked as stable to implement, its sole non-core implementor according to codesearch is CentralAuth. - Add UserRegistrationLookup::getFirstRegistrationBatch(), which delegates to fetchRegistrationBatch() on configured registration providers and returns the earliest registration timestamp for each user in the batch. - To avoid potential interface incompatibility in WMF production, this depends on CentralAuth implementing the new IUserRegistrationProvider method first. Bug: T358469 Depends-On: Ibe28163e962161567d486607e36d999a36a1e604 Change-Id: I1f6af2693a8f0c5c854b8a6b04edd1eb21934007
* build: Updating mediawiki/mediawiki-codesniffer to 46.0.0libraryupgrader2025-01-312-3/+3
| | | | Change-Id: I0f8a8cac36015bba52aea3ee2affd92f83d3574a
* Remove 2-line PHPDocs that just repeat the types from the codethiemowmde2025-01-171-2/+0
| | | | | | | | | | | | | | | | Same as Ia294bf4 did for 1-line comments. This patch removes slightly more complex 2-line PHPDoc comments that don't add any new information to the code, but literally repeat what the code already says. They say "don't document the code, code the documentation", and we are doing this more and more. We just tend to forget to remove the obsolete comments. Note I'm also removing a line of text in a few cases when it's very short and literally says the same as the method name. Again, such comments add zero new information. Change-Id: I01535404bab458c6c47e48e5456403b7a64198ed
* Merge "UserSelectQueryBuilder: Do not consider unregistered actors to be named"jenkins-bot2025-01-021-5/+10
|\
| * UserSelectQueryBuilder: Do not consider unregistered actors to be namedMartin Urbanec2025-01-021-5/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | Prior to this patch, UserSelectQueryBuilder::named was implemented as an equivalent of `!User::isTemp()`. Unfortunately, that is not fully correct. An IP address is a non-temporary actor, but it is not a named actor. Actors must be BOTH non-temporary AND registered to be considered named. This patch fixes the bug. Bug: T382889 Change-Id: Ie24ccaa0c446150f61772ecfbebe186757fdf26e
* | TempAccounts: Set fake timestamps for TempUserCreatorTestxtex2025-01-011-7/+10
|/ | | | | | | | This has been failing integration tests since 20250101 because all 2024 become 2025. Bug: T382848 Change-Id: I5aa71bb7644cfb42140d8eaba9f408e762b2937c
* Merge "Use ++ and -- rather than += 1 and -= 1"jenkins-bot2024-10-231-1/+1
|\
| * Use ++ and -- rather than += 1 and -= 1Reedy2024-10-171-1/+1
| | | | | | | | Change-Id: I27b9a19ab952ede1267921bd042af0fe1c89e228
* | tests: Use namespaced classesUmherirrender2024-10-211-0/+1
|/ | | | | | | | Changes to the use statements and some additions are done automatically via script This also updates @covers tag for the namespaced classes Change-Id: I859ba6d05018c99710b744e2becab432410d3bca
* Stop using heavy Language object when not neededAmir Sarabadani2024-10-161-2/+1
| | | | | | | Two easy cases, way more can be done. Bug: T376565 Change-Id: I3b875c4b6b2c2bdf7171a712898d50e26d86c807
* UserSelectQueryBuilder: temp() should not select non-temp usersGergő Tisza2024-10-072-20/+37
| | | | | | | | | | | | | | | When temp users are not configured, temp() was a no-op; it should be the empty condition instead. Didn't cause any problems (the only caller is expireTemporaryAccounts.php and that does check the isKnown() flag first) but would be an easy mistake to make in the future. Corresponding CentralAuth patch: I107222c77d8f6dc4caee0db4f706108a2581b4bd Bug: T372702 Change-Id: I904bbb97b028702ecfe98c97e3f821ba6038e27a
* Add namespace to IDBAccessObject and DBAccessObjectUtilsJames D. Forrester2024-09-273-1/+3
| | | | | Bug: T353458 Change-Id: I23cf7991f8792d4d000d1780463d8ce76dc0aee0
* UserOptionsManager: Allow global prefs for users without local accountsBartosz Dziewoński2024-09-102-6/+47
| | | | | Bug: T371340 Change-Id: I5eba0fa558ad7f111988c17cfcee260c5a272baf
* Add MediaWiki\Registration namespace to registration classesEbrahim Byagowi2024-08-101-1/+1
| | | | | Bug: T353458 Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
* Use MainConfigNames constants in tests where possiblethiemowmde2024-07-101-7/+9
| | | | | | | I believe this makes the code less brittle, and also makes it a bit more obvious what these strings are meant to represent. Change-Id: Ia39b5c80af4b495931d0a68fd091b783645dd709
* Merge "Create an autocreate log when a temporary account is created on edit"jenkins-bot2024-07-041-0/+63
|\
| * Create an autocreate log when a temporary account is created on editDreamy Jazz2024-07-041-0/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Why: * When a temporary account is created on edit, no log entry is visible on Special:Log to indicate that the temporary account exists. * No log is specifically set through the call to AuthManager ::autoCreateUser having the $log parameter set always to false. This was set in e8dbf5f80c029c4be52f1afd4ef91c59cfcd1185 which was the commit that created the code to create temporary accounts. * No specific reason was provided to not create a log and in T357498 there is a request to add this log. What: * Remove the `false` argument for $log to AuthManager ::autoCreateUser in TempUserCreator::attemptAutoCreate. * Update the integration tests to verify that an autocreate log is added when a temporary user is successfully created. Bug: T357498 Change-Id: Icf6be65a91437aa32684769c2858262a06ad0416
* | ActorStoreTest: Update tests to pass with temp accountsKosta Harlan2024-06-271-1/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Why: - Existing tests don't pass with temp accounts enabled What: - Disable temp accounts if a user in a test case represents an IP editor - Disable temp accounts entirely for some test cases that check only IP edits - Update some tests to use a named user identity value, as they don't check for IP editing behavior Bug: T365669 Change-Id: I6db9a4ed700abaf89314c67369164cf4c49ec847
* | Replace db with getDb for TestsWandji692024-06-232-51/+51
|/ | | | | Bug: T316841 Change-Id: I29e535e8ee9b5641a4546d53b98cd5060d39681d
* [temp accounts] Set expiration to 90 daysKosta Harlan2024-06-201-1/+1
| | | | | | | | | | | | | | Why: - We are unlikely to see good faith editing patterns with temp accounts that would require a full year What: - Set the default expiry for temp accounts to 90 days Bug: T359653 Change-Id: Iae9dd0f73aceecfc9935b2b6019b035b1057eeb3
* Merge "TempUserTestTrait: Use an array for config overrides when disabling"jenkins-bot2024-06-142-21/+30
|\
| * TempUserTestTrait: Use an array for config overrides when disablingKosta Harlan2024-06-132-21/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Why: - Consistency with the enableAutoCreateTempUser method - Allows for overriding config properties (e.g. 'known') What: - Use an array as the parameter for `disableAutoCreateTempUser` instead of a string Change-Id: I1a495cc83effcf92364fa489f779c5f4bf2d29b9
* | user: Introduce UserOptionsStoreTim Starling2024-06-121-1/+2
|/ | | | | | | | | | | | | | | | | | | | | | | Refactoring: * Break out the database access part of UserOptionsManager to a separate class hierarchy implementing interface UserOptionsStore. It's basically a key/key/string-value store, very simple. The complex parts of user options storage remain in UserOptionsManager. * Bundle the UserOptionsManager caches into a per-user cache object. I was adding a couple more and it was getting tedious. Start integrating GlobalPreferences with UserOptionsManager: * Have an array of stores. There's always a local store, and extensions can add stores via an attribute. * Add $global parameter to UserOptionsManager::setOption(), allowing this method to update or override global options. * Rename loadOptionsFromDb to loadOptionsFromStore. * Move the local override feature from GlobalPreferences to core. Bug: T323076 Change-Id: Ib3623b723557c819bc0ffdf21a4ffcb070eb298b
* user: Move "reset kinds" concept to PreferencesFactoryTim Starling2024-06-111-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix the dependency loop between PreferencesFactory and UserOptionsManager by moving the concept of "reset kinds" or "option kinds" to PreferencesFactory. Note that this is a half-baked feature from 2013 (I5f9ba5b0dfe7c2ea) that is not really used for anything. Apparently only the "all" and "unused" kinds are used. The strong dependencies on PreferencesFactory internal details show that this feature belongs in PreferencesFactory. But UserOptionsManager can reset "all" preferences without help from PreferencesFactory, so add a helper for that. The rationale for putting it in UserOptionsManager was that eventually all preference definition information should move to UserOptionsManager (T250822). I don't agree with that. UserOptionsManager is the key/value store which backs PreferencesFactory. I need to refactor it further for T323076 and it will help to have these concepts be separate. Hard-deprecate UserOptionsManager methods resetOptions, listOptionKinds and getOptionKinds. Add convenience methods to replace calls to resetOptions(). I couldn't understand the logic in resetOptions(). Why was it copying old values instead of just omitting them? Why was it assigning null but only for "all"? setOption() had a documented method for resetting an option to the default, so I just used that. Bug: T323076 Depends-On: I1ed0a1a9f6492fb50254104fa4bc9f2130218323 Change-Id: I900fd4a48c96d91491eae54824e7bf02a004843d
* Remove all @package commentsthiemowmde2024-05-102-2/+0
| | | | | | | | | | | | I don't think these do anything with the documentation generators we currently use. Especially not in tests. How are tests part of a "package" when the code is not? Note how most of these are simply identical to the namespace. They are most probably auto-generated by some IDEs but don't actually mean anything. Change-Id: I771b5f2041a8e3b077865c79cbebddbe028543d1
* tests: Use IDatabase for mocking instead of DBConnRefUmherirrender2024-05-021-5/+5
| | | | | | DBConnRef is internal, use of IDatabase interface is more common Change-Id: Id7649d0723a936cebc7e5a40bf826e38220acee5
* Stop using LoadBalancer::getConnectionRef() so it can be hard-deprecatedAmir Sarabadani2024-04-301-1/+1
| | | | | Bug: T326274 Change-Id: I90493d7cd4c21fdc022bcc19765fc04d986a9c8f
* TempAccounts: Make Throttler and WebRequest requiredKosta Harlan2024-04-231-2/+3
| | | | | | | | | | | | | | | | Why: - In real world usages, both the Throttler and request objects are required. We can override these objects in tests easily enough and simplify the application code in the process. What: - Make Throttler and WebRequest objects required in `TempUserCreator::create()` Depends-On: I13cb0dbeaa78e3ad5c7250c7565ee97099d97867 Change-Id: I5eaa68b8212570b3324a0fdec452189c6b56f810
* TempAccounts: Rate limit acquisition of temp account namesKosta Harlan2024-04-233-16/+47
| | | | | | | | | | | | | | | | | | | Why: - We don't want to allow unlimited acquisition of temp account names. These should be rate limited in similar way to how we limit the creation of temp accounts What: - Provide a TempAccountNameAcquisitionThrottle, and use it in the acquireName() method - Set a default that is 10 times the limit of TempAccountNameCreationThrottle Depends-On: If660aad1d0f04f366414084aff3f88484a19d416 Bug: T343101 Change-Id: I99d5973498a89ac227847de5837c0a8e895c28fb
* Fix some line indentUmherirrender2024-04-202-9/+9
| | | | Change-Id: I8f82724197d20f9289d80e138d80310f1eab29f2
* Merge "tests: Migrate to IDatabase::newInsertQueryBuilder"jenkins-bot2024-04-141-6/+7
|\
| * tests: Migrate to IDatabase::newInsertQueryBuilderUmherirrender2024-04-141-6/+7
| | | | | | | | | | | | | | | | | | Changed some inserts to use multi-row insert for small performance benefit where possible and not already used. InsertQueryBuilder does not return a value, deprecated since 1.33 Bug: T353219 Change-Id: I2380ebc8ec8db178dd790247aefbdd798b6d62ff
* | tests: Migrate to IDatabase::newUpdateQueryBuilderUmherirrender2024-04-141-6/+6
|/ | | | | Bug: T353219 Change-Id: Icecc444e6b4d6d2e9f4b13cda2931b10bb753318
* Update wgAutoCreateTempUser config defaultsDreamy Jazz2024-04-035-84/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Merge "TempUserConfig: Deduplicate code generating match conditions"jenkins-bot2024-03-071-0/+36
|\
| * TempUserConfig: Deduplicate code generating match conditionsBartosz Dziewoński2024-03-061-0/+36
| | | | | | | | | | | | | | The idea is similar to the one behind TempUser\Pattern::toLikeValue(), which has been effectively deprecated by allowing multiple patterns. Change-Id: Iddb284bff21355deb8ceaa6925d3c2aea34d727e
* | TempUserCreator: Use separate rate limit for temp account creationsKosta Harlan2024-03-061-0/+19
|/ | | | | | | | | | | | | | | | | | | | | Why: - The pathway to creating a regular account is different from that of a temporary account. It makes sense to rate limiting creation of these two types of accounts at different rates. What: - Add a TempAccountCreationThrottle config with a restrictive default that matches the existing production configuration of AccountCreationThrottle (6 creations per day) - Update resetAuthenticationThrottle.php to support resetting the temp account creation throttle - For now, not adding an equivalent hook for account creation throttle's ExemptFromAccountCreationThrottle Bug: T357777 Change-Id: Ibf36ac96f717107bace6f0a3326f79ed129a1dfe
* tests: Add replacement for assertions deprecated in PHPUnit 9.6Daimona Eaytoy2024-02-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | expectWarning() and friends have been deprecated in PHPUnit 9.6, and removed in PHPUnit 10. Unfortunately, there is no simple replacement because PHPUnit no longer converts them to exceptions in the first place. In fact, Sebastian Bergmann explicitly stated that he does not consider the use case of > a library developer to verify a code block warns its consumer when > certain action is performed worth supporting. So, add an ad-hoc replacement for all the deprecated methods. This is quite ugly, but it's simple enough given the low number of usages. On the bright side, this new method does not halt the test when the warning is triggered. This seems to align with the developers' expectation, seen in a few existing tests, that any code following the notice will be executed. Bug: T342110 Change-Id: I214abfed4280834840c115777ed78eb0a5570da9
* Merge "Remove IDBAccessObject from being implemented in many classes"jenkins-bot2024-02-213-5/+5
|\
| * Remove IDBAccessObject from being implemented in many classesAmir Sarabadani2024-02-193-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | This is inconsistent with the access pattern of other constants in MediaWiki. it's also confusing (e.g. it's unclear to a newcomer why UserFactory is implementing IDBAccessObject) and it's prone to clashes (e.g. BagOStuff class has a clashing constant). It has been already announced: https://w.wiki/9DAX Bug: T354194 Change-Id: Ic2357634b8385d65b55db2b557191419b06c40e0
* | Add createaccount permission in TempUserTestTraitLucas Werkmeister2024-02-201-0/+1
|/ | | | | | | | | To use temporary accounts, anonymous users must be able to create accounts. Without this, I sometimes get test failures in Wikibase, particularly in EditEntityTest (though I’m not 100% sure why). Bug: T356149 Change-Id: I7c164a81687fad5bab4a2f1f732baf543d826140
* tests: Fix @covers and @coversDefaultClass to have leading \Reedy2024-02-163-35/+35
| | | | Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
* test: Convert LocalizedNumericSerialMappingTest to a unit testDoğu Abaris2024-02-091-19/+0
| | | | | | | | | | | | This commit refactors the LocalizedNumericSerialMappingTest to make use of mocks for Language and LanguageFactory. Introduced a data provider for comprehensive testing of getSerialIdForIndex with various scenarios. Added testConstruct to verify constructor functionality and LanguageFactory integration. This refactor changes the base test class from MediaWikiIntegrationTestCase to MediaWikiUnitTestCase, shifting focus to unit testing. Change-Id: I00d80d0a1d6d0bb8f7fc5c6e7c6fa4732ef04abb
* Always allow local IP actors to be created when importingThalia2024-01-292-0/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Why: * Following T345578, the ActorStore throws an error on attempting to create an actor whose name is their IP address if temporary accounts are enabled. * For the specific case of importing old revisions, we need to be able to create new actors whose name is their IP address, while still generally disallowing it. What: * Add $allowCreateIpActors flag to ActorStore, and check for it during actor name validation. * Set the flag from ActorStoreFactory::getActorStore depending on whether temporary users are enabled. * Add ActorStoreFactory::getActorStoreForImport, which sets flag to true. * Add RevisionStoreFactory::getRevisionStoreForImport, which uses getActorStoreForImport. Use this from classes handling imports, so that IP actors can always be created. * Add $forImport flag on ActorMigration, since RevisionStore uses an actor store obtained via ActorMigration. Bug: T354207 Change-Id: I0715bd0d23089fd8156e579913e6e823089809be
* tests: Use namespaced class names in @covers annotationsUmherirrender2024-01-271-1/+1
| | | | | | Assist from 8c9cb701e56226cac43fee2fa24b0d0e586f1733 Change-Id: I47897c499028d9e24c00ad0bc6ba7fd8002d9bc1
* Change more uses of getDBLoadBalancerFactory() to getConnectionProvider()Bartosz Dziewoński2024-01-231-1/+1
| | | | | | | | | | | Some less trivial cases. Also update variable names. This doesn't really change anything, but I hope it helps promote getConnectionProvider() as the common way to do this. Follow-up to 8604c384f624273f46b653ec252ffaed30e6ff89. Change-Id: I6657d783375fac5c7fa856b884ff1fb09285e94c