aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/structure/RestStructureTest.php
Commit message (Collapse)AuthorAgeFilesLines
* REST: Make OpenAPI spec info strings translatablebpirkle2025-03-211-2/+6
| | | | | | | | | OpenAPI specs include an "info" section that includes strings such as "title" and "description" that are intended to be human-readable. Make all such strings translatable. Bug: T385855 Change-Id: I15285be6d196c0e7fd7e922f23058d7c09b6b31a
* 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
* REST: Make structure test for param description messagesdaniel2024-11-261-0/+11
| | | | | | | | Adds an assertion to check that the message keys used in parameter descriptions are defines. Bug: T376493 Change-Id: I789a5c2b95a5647a4e8d484c4b069d810478dd6f
* 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
* tests: Mock IContextSource in RestStructureTestUmherirrender2024-10-111-5/+16
| | | | | | | | This avoids creation of session leaking into other tests Also avoids that the session backend stores the session and consuming memory until the end of the tests Change-Id: Ib7a0a5df0f16bb25a6111a4a3f7cfadc489e7e25
* REST: Introduce discovery endpointdaniel2024-09-201-11/+50
| | | | | | | | The discovery endpoint provides basic information about accessing the wiki's APIs, as well as a directory of available modules. Bug: T365753 Change-Id: I161aa68566da91867b650e13c8aadc87cd0c428c
* REST: validate JSON in testsdaniel2024-09-201-22/+25
| | | | | | | | | | | | | | | | | | This applies JSON Schema validation in phpunit tests where appropriate: 1) In ModuleSpecHandlerTest, the generated OpenApi specs are validated against the OpenAPI 3 schema. 2) In RestStructureTest, module definition files are validated against the mwapi schema. This patch introduces a new trait to make it easy for phpunit test cases to perform validation. This patch also fixes some issues with the docs/rest/mwapi-1.0.json schema and the includes/Rest/content.v1.json module definition. Change-Id: I966cddb337c9373ed3a369496548a8d8c538ae84
* getParamSettings prohibited from using array typeWendy Quarshie2024-07-251-0/+5
| | | | | Bug: T368133 Change-Id: I2af5880fdf4d6fb3f8047e24e3a3d69a08a433f7
* add structure test that checks if param schemas are validWendy Quarshie2024-07-231-0/+36
| | | | | Bug: T368133 Change-Id: Ib0e881d13b4709bc31831e1bc7d88ad6041589a1
* Merge "param-settings: Remove backward compatibility code from default"jenkins-bot2024-07-101-20/+24
|\
| * param-settings: Remove backward compatibility code from defaultAtieno2024-07-101-20/+24
| | | | | | | | | | | | | | We no longer have to check for 'body' PARAM_SOURCE from within getParamSettings Bug: T367394 Change-Id: I16075fde2db6ea47f61d1d2df1e07a4ef46b537b
* | Add namespace to the root classes of ObjectCacheEbrahim Byagowi2024-07-101-0/+1
|/ | | | | | | | | And deprecated aliases for the the no namespaced classes. ReplicatedBagOStuff that already is deprecated isn't moved. Bug: T353458 Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
* tests: Use namespaced classes (2)Umherirrender2024-06-131-0/+1
| | | | | | | Changes to the use statements done automatically via script Addition of missing use statement done manually Change-Id: I4ff4d0c10820dc2a3b8419b4115fadf81a76f7a2
* Migrate MediaWiki.rest_api to statslibWendy Quarshie2024-06-111-2/+3
| | | | | Bug: T359364 Change-Id: I3646140ee8e16800c43f37958fc4b6ff00edcad6
* Introduce Modules into the REST frameworkdaniel2024-05-081-45/+68
| | | | | | | Modules group together endpoints by a shared prefix. The idea is that each module has its own version and can generated self-contained self-documentation. This allows clients to have clear expectations about the endpoints of each module, no matter what wiki they are accessing. So far, each wiki may be exposing a different set of endpoints, with no way to provide a spec that describes that set of endpoints in a way that would be consistent across wikis and stable over time. Bug: T362480 Change-Id: Iebcde4645d472d27eee5a30adb6eee12cc7d046b
* REST: introduce getBodyParamSettingsdaniel2024-05-071-0/+40
| | | | | | | | | | | | | | | | | Since we introduced support for the "body" PARAM_SOURCE in getParamSettings, fields in the request body can be defined in the same way that path and query parameters are defined. However, body fields are treated separately by the framework, and the value of body fields are available through getValidatedBody(), rather than getValidatedParams(). Because of that, it makes sense to have a method that returns the param settings just for the body fields. This also allows handler classes to override this method separately to specify body fields. That way, it also becomes possible to have body fields that have the same name as other parameters. Bug: T362850 Change-Id: Ia85bf7e46c949a999052d91f1b0d7d579a880108
* rest: use new body validation in creation and update handlerWendy Quarshie2024-04-031-0/+1
| | | | | Bug: T358850 Change-Id: Idce281198604e0983f35776e03d607b7a280cc7e
* handler: Declare known sources in ValidatorAtieno2024-03-281-4/+3
| | | | | Bug: T358558 Change-Id: I0536e0d659b53c8f85bf7685beffbb5c5d027998
* Rest: Turn Rest\EntryPoint into a MediaWikiEntryPoint subclassdaniel2024-03-121-4/+4
| | | | | | | | The idea is for all entry points to use the MediaWikiEntryPoint base class, to improve consistency and testability. Bug: T354216 Change-Id: I3678afe32c7c1a313d2dcb1808286c25ecd167eb
* Namespace includes/contextJames D. Forrester2024-02-081-0/+2
| | | | | Bug: T353458 Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
* Namespace Config-related classes under \MediaWiki\ConfigJames D. Forrester2023-09-211-0/+1
| | | | | Bug: T166010 Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
* Reorg: Move WebRequest to includes\RequestAmir Sarabadani2023-09-111-0/+1
| | | | | | | This has been approved as part of RFC T166010 Bug: T321882 Change-Id: I6bbdbbe6ea48cc1f50bc568bb8780fc7c5361a6f
* Avoid DB access in more non-Database testsDaimona Eaytoy2023-08-061-0/+1
| | | | | Bug: T155147 Change-Id: Iae2512c66c32b209ea8579beecb3de94a744da14
* 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
* Tests: add ObjectFactory to DummyServicesTraitDannyS7122023-01-231-2/+3
| | | | | | | | Mocks a ContainerInterface to support a specific list of services, with has() and get() working correctly, and uses that for a real ObjectFactory object. Change-Id: Ie49b5a34e0f449cc4b9f6b31d6cc1bc943d04b43
* REST: collect metrics on endpoint accessDaniel Kinzler2023-01-121-1/+8
| | | | | | | | This is a modified version of Ie282bc5b5f5df0bbd6a40c8362ba73fcbbf36c2e which was reverted in 5c7cca87763b5f40cf9a3788aca957082c3bd4e7. Bug: T321969 Change-Id: I566d54a473aa51c4cdaada21a49d63c0624aab93
* Revert "REST: collect metrics on endpoint access"Daniel Kinzler2022-12-121-8/+1
| | | | | | | | This reverts commit d32c260ed0c5f24ef7c1233501f684d612fef5a9. Reason for revert: Timo has reservations, I'll submit an updated version later. Change-Id: I71d4d61a879fda4dccfc105127446cfedde75a7b
* REST: collect metrics on endpoint accessdaniel2022-12-061-1/+8
| | | | | | | This collects metrics on how often each endpoint is hit, and with which code it responds. Change-Id: Ie282bc5b5f5df0bbd6a40c8362ba73fcbbf36c2e
* Make RestStructureTest run in IDEdaniel2022-11-221-33/+109
| | | | | | | | | | | | PHPUnit tests will fail to run in the IDE if they access the service container. Note that the structure test will not include routes registered by extensions when run without the phpunit wrapper: data providers are executed before config is loaded, so extensions do not have a chance to register. Change-Id: If9d408456686b408062204bec4b41c95f60ab775
* Add @coversNothing to all structure testsDaimona Eaytoy2022-10-071-0/+2
| | | | | | | | | | | | With PHPUnit 9, tests without @covers tags are considered risky and emit warnings. Not having @covers is bad practice anyway, so use @coversNothing instead to make the intention clear, and re-enable the phpcs rule. Also rewrite an assertion in ResourcesTest that was bothering me. Bug: T243600 Change-Id: I6dd683f93b6b2faed5f107be2ca7860602277fbc
* build: Updating dependencieslibraryupgrader2021-07-221-4/+4
| | | | | | | | | | | | | | 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
* build: Update mediawiki/mediawiki-codesniffer to 35.0.0Umherirrender2021-01-311-1/+1
| | | | Change-Id: Idb413be4b8cba8611afdc022af59810ce1a4531e
* Remove broken/outdated @param/@throws tags from @dataProvidersThiemo Kreuz2021-01-211-3/+0
| | | | | | | | | | | | | | | | My personal best practice is to not document @params when there is a @dataProvider. I mean, these test…() functions are not meant to be called from anywhere. They do not really need documentation. @param tags don't do much but duplicate what the @dataProvider does. This is error-prone, as demonstrated by the examples in this patch. This patch also removes @throws tags from tests. A test…() can never throw an exception. Otherwise the test would fail. Most of these are found by the not yet released I10559d8. Change-Id: I3782bca43f875687cd2be972144a7ab6b298454e
* tests: Remove @param docs from test code that just repeat the signatureThiemo Kreuz2021-01-211-1/+0
| | | | | | | | | | | | | | These are not only 100% identical to the actual code, but also: * It's error-prone. Some are already wrong. * These test…() functions are not meant to be called from anywhere. What is the target audience for this documentation? * There is a @dataProvider. What such @param tags actually do is document the provider, but in an odd place. Just looking at the provider should give the same information. * The MediaWiki CodeSniffer allows to skip @param when there is a @dataProvider, for the reasone listed. Change-Id: I0f6f42f9a15776df944a0da48a50f9d5a2fb6349
* Handle CORS preflight request and prevent anon users from unsafe methodsDavid Barratt2020-09-211-13/+18
| | | | | | | | | | | | | | | Creates an OPTIONS handler that handles any OPTIONS requests that are not already handled by a handler. CORS has no mechanism to ensure the user is authenticated, so the Router will reject cross-origin requests from anon users. This change allows authenticated users to make cross-origin requests if they authenticate with OAuth or if $wgRestAllowCrossOriginCookieAuth is enabled. Bug: T232176 Bug: T262712 Change-Id: I128b4bdbec4f6bea35142153c951fd7b79617106
* MediaWikiTestCase to MediaWikiIntegrationTestCaseaddshore2020-06-301-1/+1
| | | | | | | | | | | | | The name change happened some time ago, and I think its about time to start using the name name! (Done with a find and replace) My personal motivation for doing this is that I have started trying out vscode as an IDE for mediawiki development, and right now it doesn't appear to handle php aliases very well or at all. Change-Id: I412235d91ae26e4c1c6a62e0dbb7e7cf3c5ed4a6
* Update RestStructureTest to include HTTP MethodClara Andrew-Wani2020-03-241-3/+26
| | | | Change-Id: If05ba2884ba8e256c7fee45164eee1fc2d014589
* Make use of PHPUnit's assertCount feature where possibleThiemo Kreuz2020-03-021-1/+1
| | | | | | | … and avoid assertEmpty() on arrays, in favor of a much more strict assertSame( [] ). Change-Id: I20266b0b1fc38a3a87666ba1b0793cb2b37d94a9
* Add RestStructureTestBrad Jorsch2020-02-041-0/+158
This tests validity of parameter definitions for the MW REST API, like ApiStructureTest does for the Action API. Bug: T243437 Change-Id: Iac9ca951d00573be6efe00cc07478c3581c84588