aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/api/ApiOptionsTest.php
Commit message (Collapse)AuthorAgeFilesLines
* Use explicit nullable type on parameter argumentsUmherirrender2024-10-161-1/+1
| | | | | | | | | | | Implicitly marking parameter $... as nullable is deprecated in php8.4, the explicit nullable type must be used instead Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a Break one long line in SpecialPage.php Bug: T376276 Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
* Add namespace to includes/api classesJames D. Forrester2024-09-251-4/+4
| | | | | Bug: T353458 Change-Id: I3ea6b08c5018ba03ba45c5766e1f46e12f6b8597
* tests/api: Add missing documentation to class propertiesUmherirrender2024-09-101-0/+1
| | | | | | | | | | Add doc-typehints to class properties found by the PropertyDocumentation sniff to improve the documentation. Once the sniff is enabled it avoids that new code is missing type declarations. This is focused on documentation and does not change code. Change-Id: I48014b6464f3e7e2b7f083e67f517af0b1a9367e
* tests: Use const for some static data in test filesUmherirrender2024-09-011-5/+5
| | | | Change-Id: Id7ccd48e3bf626095e2d3929831b5d87ed0be948
* user: Add "global" parameter to ApiOptionsTim Starling2024-06-131-1/+1
| | | | | | | | | Add a "global" parameter to ApiOptions which allows it to update or override global preferences. Bug: T323076 Depends-On: I686c0091768ed330683fff89201fae4f93b8a1c4 Change-Id: Ieb2d0c0d0da5c51b2a47ed8a967a47b4e7ad4577
* user: Move "reset kinds" concept to PreferencesFactoryTim Starling2024-06-111-22/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* tests: Namespace api testsReedy2024-02-181-0/+7
| | | | | Bug: T357823 Change-Id: I0d7cc2c9b166d5e5b913c1305f7cee017fe377af
* tests: Fix @covers and @coversDefaultClass to have leading \Reedy2024-02-161-1/+1
| | | | Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
* Namespace includes/contextJames D. Forrester2024-02-081-0/+3
| | | | | Bug: T353458 Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
* Update tests for PHPUnit 9.6 (part 2)Daimona Eaytoy2024-01-171-10/+21
| | | | | | | - Avoid withConsecutive() Bug: T342110 Change-Id: Iedda49765cbceeb10ccd72d0248f3cda9241da1e
* Move user options related classes into its own namespaceMartin Urbanec2023-11-291-1/+1
| | | | | | | | | | | | | There are a couple of user options related classes already, and the T321527 work on dynamic defaults is going to add even more. Let's move them into a separate namespace to make core a bit more organized. Old name is kept as an alias for compatibility purposes. Bug: T321527 Bug: T352284 Change-Id: I9822eb1553870b876d0b8a927e4e86c27d83bd52
* Namespace User under \MediaWiki\UserJames D. Forrester2023-09-191-0/+1
| | | | | Bug: T166010 Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
* Replace substr with cleaner string methodsMatěj Suchánek2023-05-201-1/+1
| | | | | | | | | | Use str_starts_with, str_ends_with or string offset where appropriate. This fixes a bug in MimeAnalyzer where the "UTF-16LE" header could not be identified because of wrong constant. This is the exact type of bug that the new functions can avoid. Change-Id: I9f30881e7e895f011db29cf5dcbe43bc4f341062
* API tests: Assert error codes, not error messagesBartosz Dziewoński2023-04-261-7/+7
| | | | | | | | | | | | | | | Error messages are not guaranteed to be stable, and these tests prevent us from improving them. Error codes are supposed to be stable, so we should be asserting that they do not change (especially since many of them are dynamically generated by the dodgy code in ApiMessageTrait). Introduce helpers assertApiErrorCode() and expectApiErrorCode() to be used instead of the usual PHPUnit assertions/expectations for this case. Change-Id: I752f82f29bf5f9405ea117ebf9e5cf70335464ad
* Merge "Make ApiOptions unavailable to temporary users"jenkins-bot2023-03-281-51/+103
|\
| * Make ApiOptions unavailable to temporary userscsimiyu2023-03-281-51/+103
| | | | | | | | | | Bug: T332414 Change-Id: I7646f8a80309b739e647558a971725b9e59f3b06
* | tests: Make some PHPUnit data providers staticTim Starling2023-03-241-1/+1
|/ | | | | | | | | | | | | Just methods where adding "static" to the declaration was enough, I didn't do anything with providers that used $this. Initially by search and replace. There were many mistakes which I found mostly by running the PHPStorm inspection which searches for $this usage in a static method. Later I used the PHPStorm "make static" action which avoids the more obvious mistakes. Bug: T332865 Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
* Reorg: Namespace the Title classJames D. Forrester2023-03-021-0/+1
| | | | | | | | | | | | | | | | | | | This is moderately messy. Process was principally: * xargs rg --files-with-matches '^use Title;' | grep 'php$' | \ xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1' * rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \ xargs rg --files-with-matches 'Title\b' | \ xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1' * composer fix Then manual fix-ups for a few files that don't have any use statements. Bug: T166010 Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
* ApiOptions: Give warning if the value is too longFunc2023-01-201-0/+13
| | | | | | | | | | | | I was thinking add validations to HTMLApiField and other field types if any, but then I found one field type that hard to implement proper length validation, which is used for the `email-blacklist` preference. The API will not save options that exceed the limit after this patch, as if the validation is done by respective html fields. Bug: T326696 Change-Id: Ib6b04db33bc6a806a49a16a1797c191faf5fb59d
* Reorg: Move some of request related classes to MediaWiki/RequestAmir Sarabadani2022-10-281-0/+1
| | | | | | | | | | | | | | | Redoing I5ea70120d74 but without moving WebRequest that caused issues with phan-taint-plugin. Moving: - DerivativeRequest - FauxRequest - FauxRequestUpload - PathRouter - WebRequestUpload Bug: T321882 Change-Id: I832b133aaf61ee9f6190b0227d2f3de99bd1717b
* Revert "Reorg: Move some of request related classes to MediaWiki/Request"Zabe2022-10-271-1/+0
| | | | | | | | | This reverts commit 2bdc0b2b7209441a42a784157633a8a01b321922. Reason for revert: T166010#8349431 Bug: T166010 Change-Id: Idcd3025647aec99532f5d69b9c1718c531761283
* Reorg: Move some of request related classes to MediaWiki/RequestAmir Sarabadani2022-10-261-0/+1
| | | | | | | | | | | | | Moving: - DerivativeRequest - FauxRequest - FauxRequestUpload - PathRouter - WebRequest - WebRequestUpload Bug: T166010 Change-Id: I5ea70120d745f2876ae31d039f3f8a51e49e9ad8
* tests: Use Title::makeTitle instead of Title::newFromTextUmherirrender2022-09-231-1/+1
| | | | | | Avoid parsing known titles in tests to improve performance Change-Id: Ie240eb42479d19714e64cc4606e26073fadc2e13
* Replace trivial usa of mock builder with createMock() shortcutThiemo Kreuz2022-07-151-3/+1
| | | | | | | | | | | createMock() does the same, but is much easier to read. A small difference is that some of the replacements made in this patch didn't use disableOriginalConstructor() before. In case this was relevant we should see the respective test fail. If not we can save some CPU cycles and skip these constructors. Change-Id: Ib98fb06e0fe753b7a53cb087a47e1159515a8ad5
* Hard deprecate User group methodsvladshapik2021-07-231-3/+0
| | | | | | | | | | | | | | | | 1) The following methods were hard deprecated: - User::addAutopromoteOnceGroups - User::getEffectiveGroups - User::getAutomaticGroups - User::getFormerGroups 2) User ::getGroups, ::getGroupMemberships, ::addGroup, ::removeGroup were replaced in the production code, but they were not hard deprecated because of conflict with UserRightsProxy class. Bug: T275148 Change-Id: Ia69598316f5dc5dd9511f6112b5b13e1aa07575a
* build: Updating dependencieslibraryupgrader2021-07-221-1/+1
| | | | | | | | | | | | | | composer: * mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0 The following sniffs now pass and were enabled: * Generic.ControlStructures.InlineControlStructure * MediaWiki.PHPUnit.AssertCount.NotUsed npm: * svgo: 2.3.0 → 2.3.1 * https://npmjs.com/advisories/1754 (CVE-2021-33587) Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
* api: Replace deprecated User::getOptionKinds/resetOptions in ApiOptionsUmherirrender2021-07-021-26/+33
| | | | | Bug: T277600 Change-Id: I66320d906f735fa3edadfa29a14d6699d159d400
* api: Inject PreferencesFactory into ApiOptionsUmherirrender2021-07-021-18/+12
| | | | Change-Id: I6242f5018075e1500d87c8375c971b383aba41f6
* api: Change User::isAnon to User::isRegisteredUmherirrender2021-06-291-3/+15
| | | | | | User::isRegistered is also usable with UserIdentity Change-Id: I49ee864e9b080d324b11eb8cbbcc9aa5f6ca0470
* Hard deprecate User::listOptionKinds()ZabeMath2021-06-221-1/+15
| | | | | | | deprecated since 1.35 and unused. Bug: T274211 Change-Id: I139ef1de149c94148ad07c62a8c024e4cb0ee053
* Allow passing mock Authority in API integration testsPetr Pchelko2021-06-071-2/+5
| | | | | | | | | | | This is a demo, a lot of tests could be rewritten as a followup to pass proper Authority when executing tests instead of writing globals. Much cleaner imho. An improvement idea is to allow overriding 'default permissions' when creating a mock Authority. Change-Id: I38570024e0d5a67a8e1c52f7456c458090ec2b6e
* Hard deprecate User ::isIP, ::getOptionsvladshapik2021-04-261-6/+7
| | | | | Bug: T275602 Change-Id: Id4be13751ca0a900e51214c1855a4624077a5a62
* Merge "Remove unnecessary ->equalTo() from tests"jenkins-bot2021-04-231-4/+4
|\
| * Remove unnecessary ->equalTo() from testsThiemo Kreuz2021-04-231-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | This is the default anyway when using ->with(). The test code becomes so much more readable without this, I would like to argue. Let it just say "with these values". Because of the way I split my changes into multiple patches there are a few other changes in this patch I could not split, e.g. removing unnecessary ->any(). This is the default anyway and doesn't make the test more specific. Change-Id: I34990799fa9258ba8dc64c7e78ec43f7903b7681
* | Remove meaningless ->expects( $this->any() ) from all testsThiemo Kreuz2021-04-231-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is not entirely meaningless. It might be an indicator that the number of calls to a method is intentionally unlimited. This is similar to e.g. an @inheritDoc PHPDoc comment that marks a method as being "intentionally undocumented". However, what's the meaning of being "intentionally unconstrained"? Let's just not have any constraint then. I feel all these ->expects( $this->any() ) bloat the test code so much that it's never worth it. Change-Id: I9925e7706bd03e1666f6eb0b284cb42b0dd3be23
* | Replace PHPUnit ->returnValue() with ->willReturn() shortcutThiemo Kreuz2021-04-221-5/+3
|/ | | | | | | | | | | | It's the same and makes the test code much more readable, I would like to argue. Because of the was I split all the changes I made into smaller patches this patch contains some other changes in the same lines where I could not split them off. E.g. removal of ->any(), which is the default anyway and doesn't do anything. Change-Id: Ib297b989d4aec33b31a4e33fe9d5032865b39be0
* Avoid using User ::getDefaultOption, ::getDefaultOptionsPeter Ovchyn2021-03-161-2/+0
| | | | | | | This patch hard-deprecates the methods above Bug: T276035 Change-Id: Ic36b0702f7547acce0d162d6e0b54bbd4ecf4d81
* Use Authority and GroupPermissionLookup in Action APICindy Cicalese2021-02-231-1/+5
| | | | | | | | | | | | | | | | | | | Replaces calls directly to PermissionManager with calls to the Authority object available from Context or the GroupPermissionLookup service. This patch does not address use of PermissionManager for blocks. Deprecations: - ApiBase::checkUserRightsAny deprecated passing optional User parameter - ApiBase::checkTitleUserPermissions deprecated passing LinkTarget as first parameter, takes PageIdentity instead Bug: T271462 Bug: T271854 Change-Id: I5d7cac1c28a37e074750c46cda03283980a07fca
* Pass linkable user name in Special:Preferences "Account data" help textThalia2021-02-161-1/+1
| | | | | | | | | | | | | | For the optional message in the "Account data" section, introduced in d4357d621fa6fa09bb6fb09c57ee21331f92f260. Passes the user name escaped with underscores, so that links can be built correctly in the message translation. This means we have to expand yet further the list of User methods called in ApiOptionsTest, but so be it. Bug: T272412 Change-Id: Ia1c135144763db9e92f1b555f009229bd1a9d3c8
* Remove incomplete @param from test functionUmherirrender2021-02-011-3/+0
| | | | | | the @dataProvider should be a enough here Change-Id: I36549dcac027a68244de042d48d90d4070771be8
* tests: Add explicit return type void to setUp() and tearDown()Max Semenik2019-10-301-1/+1
| | | | | | Bug: T192167 Depends-On: I581e54278ac5da3f4e399e33f2c7ad468bae6b43 Change-Id: I3a21fb55db76bac51afdd399cf40ed0760e4f343
* Remove Language::factory and getParentLanguage useAryeh Gregor2019-10-271-1/+1
| | | | Change-Id: I11f8801ef47ec1a1f63d840116e69667e6f3ae3c
* phpcs: Enable ↵James D. Forrester2019-10-141-3/+1
| | | | | | MediaWiki.Commenting.PhpunitAnnotations.ForbiddenExpectedException* and make pass Change-Id: I63f97497714a32236268be6965c5e181dade6c58
* Update tests to use PHPUnit 6 class namesMax Semenik2019-10-061-1/+3
| | | | | Bug: T192167 Change-Id: I42b0c8908b4968b95b08f861a40af18dc79fa0a1
* Call resetServices() when setting globals in testsAryeh Gregor2019-08-291-0/+12
| | | | | | | | | | | Now that resetServices() will preserve (but reset) customized services, it should be reasonably safe to call it every time globals are changed, and much more effective than relying on tests to call it every time themselves. Depends-On: Iab8ea3a61bbc6803805d855ef23c071067646f71 Depends-On: I00e35ecea6a27468674b2a6e7d9d9eb6518e3bd5 Change-Id: Ie7a89f6ed7d52a0bc01672019ff92e7ee105a1f3
* Deprecate and replace usages of User:isAllowed{All,Any}Petr Pchelko2019-08-211-2/+1
| | | | | Bug: T220191 Change-Id: I197b8fadaa93e7b320fc19c10e3e09387fe09ad2
* ApiOptions: fix resetting some preferences to defaultMax Semenik2018-10-011-141/+118
| | | | | | | | | | For preferences like 'skin' that have a limited number of values, null is not a valid value, thus attempts to reset them fail with "Validation error for \"skin\": This value is required." Bug: T65080 Change-Id: I86554a6d30c8ab970740d8682fb2261476de0677
* Introduce preference filtersMax Semenik2018-07-171-0/+4
| | | | | | | | | | | | | This normalizes handling of transformations on the boundaries between preferences and generic form controls and removes the special case where email-blacklist is passed around as an array internally, leaking into the API. As a result of this normalization, meta=userinfo no longer returns an array of users, using the internal representation like action=options. Bug: T198935 Change-Id: Iff63da0d215585cfcf083e7f7ec8ed45d5b77301
* Use \u{00A0} instead of   or  Fomafix2018-06-241-2/+2
| | | | | | | | | | | | | Directly use the UTF-8 encoding of the 'NO-BREAK SPACE' (U+00A0) instead of the HTML/XML entities   or   or  . With the UTF-8 character the generated HTML is shorter and better to read. Also change the special value for the label in HTMLForm from   to U+00A0 but also support   for backward compability. Bug: T154300 Change-Id: I882599ac1120789bb4e524c4394870680caca4f4
* Use ::class to resolve class names in testsUmherirrender2018-01-261-1/+1
| | | | | | | This helps to find renamed or misspelled classes earlier. Phan will check the class names Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c