Commit graph

373 commits

Author SHA1 Message Date
C. Scott Ananian
ed94cc0b64 structure tests: allow PHP 8.1 syntax and autoload enums
Change-Id: I0069df20fbc7ee46c7dc177e5bf352434b8abf32
(cherry picked from commit 12c9e516a2a42d399f5d51f6ba1b162ba68f4894)
2025-06-18 10:55:15 +01:00
Reedy
82d3f6ac64 composer.json: Updated nikic/php-parser from ^4.10.2 to ^5.3.1
Bug: T379508
Change-Id: Ia693d5e3424d925172cd2e4b7cb501a031822f3b
(cherry picked from commit beed3ed1741db223e9e48c159214059d9c7eb439)
2025-06-18 10:54:38 +01:00
Brent Laabs
5565af9c96 Add DumpableObjectsTest to the database test group
Bug: T374494
Change-Id: I4a33d3ff43e2e31c77377fb9880a31b25ab39268
(cherry picked from commit 4a730b2e63663b9f5c5cca5b8cb97501836d49d2)
2024-11-08 14:37:40 +00:00
Umherirrender
839613ff77 tests: Use namespaced classes
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
2024-10-21 18:53:02 +02:00
jenkins-bot
6ac66f9e3f Merge "tests: Validate Resources.php against ResourceModules schema" 2024-10-14 11:14:48 +00:00
Umherirrender
e10ca69c78 tests: Mock IContextSource in RestStructureTest
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
2024-10-11 23:16:53 +00:00
Bartosz Dziewoński
09b768cb48 tests: Validate Resources.php against ResourceModules schema
Change-Id: I189f5d48e92fa77d15116b2acbcb783f02b522c1
2024-10-07 21:10:52 +00:00
James D. Forrester
30458987e2 tests: Consistently use class_alias comments like elsewhere
Found via `[^*][^\\]\nclass_alias`.

Change-Id: I9732f75226445f48fb131c432b209d0fd3eba1ba
2024-09-25 09:48:46 -04:00
daniel
84fe1b9ccd REST: Introduce discovery endpoint
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
2024-09-20 17:02:59 +00:00
daniel
d7ed4b14bb REST: validate JSON in tests
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
2024-09-20 15:42:32 +00:00
Bartosz Dziewoński
0c0d50ce81 Fix specifying messages with params as arrays in API documentation
Follow-up to 12a4c08ad8.
I didn't review it carefully enough to notice that when these
functions return arrays, they contain a message key and parameters,
not a key and fallback keys (while other API documentation message
code uses fallback keys).

Instead of `$this->msg( $msg )`, this code must be written as
`is_array( $msg ) ? $this->msg( ...$msg ) : $this->msg( $msg )`
or `$this->msg( Message::newFromSpecifier( $msg ) )`, both of which
are ugly, but the latter looks a bit better to me.

Bonus changes:
* Add documentation to prevent a repeat of this mistake in the future
* Remove some unreachable dieDebug() calls (the Message class already
  throws for bad inputs)

It seems that we don't have any definitions using such arrays
in the core API classes. There are only a few uses in extensions,
e.g. AbuseFilter's 'apihelp-query+abuselog-param-filter' message,
which is passed the wrong parameter without this change.

Bug: T372988
Change-Id: I44c1c3c7d0c069e500c85a58c27e9b675b0b68ee
2024-08-21 13:26:02 +00:00
jenkins-bot
3ddf03c3f8 Merge "Deprecate ApiBase::makeMessage" 2024-08-16 18:17:01 +00:00
theprotonade
12a4c08ad8 Deprecate ApiBase::makeMessage
Replace usages of ApiBase::makeMessage
with ApiBase::msg and deprecate the former
method

Bug: T370240
Change-Id: I9e6e775dad7f3e3cfd78351f87f4732677d90971
2024-08-16 12:09:33 -04:00
Eric Gardner
38066e5317 tests: Add a test for Codex i18n messages
Adds a new "structure" PHPUnit test, "CodexMessageDefinitionTest.php".
This test exists to ensure that every message in the Codex message keys
file (produced by the library during build and updated for each Codex
release) is defined in the en.json and qqq.json message files for Codex
in MediaWiki.

Bug: T371330
Change-Id: I01f0888d13122d587bef17043eec46c32e8f534e
2024-08-12 15:30:11 -07:00
Ebrahim Byagowi
697e19e461 Add MediaWiki\Registration namespace to registration classes
Bug: T353458
Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
2024-08-10 10:08:22 +00:00
Fomafix
f90af6c157 Use MediaWikiIntegrationTestCase::getConfVar in tests
Change-Id: I3a99f24da3d572281b49a8a8b92e006fde3eaa41
2024-08-06 12:52:34 +00:00
Wendy Quarshie
b5c9e740ed getParamSettings prohibited from using array type
Bug: T368133
Change-Id: I2af5880fdf4d6fb3f8047e24e3a3d69a08a433f7
2024-07-25 10:09:02 +00:00
Wendy Quarshie
53b9268e57 add structure test that checks if param schemas are valid
Bug: T368133
Change-Id: Ib0e881d13b4709bc31831e1bc7d88ad6041589a1
2024-07-23 00:25:55 +00:00
thiemowmde
26e54d49ab Merge @dataProviders in AbstractSchemaValidationTest
The two test functions are identical. They can as well use a single
@dataProvider to do the same as before. No coverage is lost.

Change-Id: I865b75f8e14e016ad4aa7ffdcf9e4023387b40bb
2024-07-19 10:18:29 +00:00
jenkins-bot
aef29a83c3 Merge "param-settings: Remove backward compatibility code from default" 2024-07-10 17:32:21 +00:00
Atieno
2b31f4c46f param-settings: Remove backward compatibility code from default
We no longer have to check for 'body' PARAM_SOURCE from within getParamSettings

Bug: T367394
Change-Id: I16075fde2db6ea47f61d1d2df1e07a4ef46b537b
2024-07-10 19:55:08 +03:00
Ebrahim Byagowi
fab78547ad Add namespace to the root classes of ObjectCache
And deprecated aliases for the the no namespaced classes.

ReplicatedBagOStuff that already is deprecated isn't moved.

Bug: T353458
Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
2024-07-10 00:14:54 +03:30
jenkins-bot
286f49b678 Merge "Add Special:RestSandbox for exploring REST API" 2024-06-14 01:19:30 +00:00
Umherirrender
f27c2433bb tests: Use namespaced classes (2)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: I4ff4d0c10820dc2a3b8419b4115fadf81a76f7a2
2024-06-13 23:21:02 +02:00
daniel
c01b7c7b4b Add Special:RestSandbox for exploring REST API
Special:RestSandbox presents a Swagger-UI interface for exploring REST APIs. The available APIs can be configured using RestSandboxSpecs.

For now, the default is to support no APIs, so the feature is disabled in production. In the future, it would make sense to expose the wiki's own REST API per default. The corresponding entry in $wgRestSandboxSpecs in LocalSettings.php would look like this:

	'mw' => [
		'url' => $wgScriptPath . '/rest.php/',
		'name' => 'MediaWiki REST API',
	]

Note that the spec URL may still change.

To also explore the endpoints exposed through RESTbase, we might add:

	'wmf-restbase' => [
		'url' => $wgServer . '/api/rest_v1/',
		'name' => 'Wikimedia RESTbase API',
	]

Similarly, we could expose a spec for endpoints on api.wikimedia.org, which could then be explored using the new special page.

NOTE: This adds a dependency on the swagger-ui npm library. See T325558 for the security review.

Bug: T362006
Change-Id: I1dd5ed82680a28f9c15136b446a2de0398525061
2024-06-13 21:40:36 +02:00
Wendy Quarshie
e7fd78aed1 Migrate MediaWiki.rest_api to statslib
Bug: T359364
Change-Id: I3646140ee8e16800c43f37958fc4b6ff00edcad6
2024-06-11 18:13:21 +00:00
Ebrahim Byagowi
16197f7d76 Add namespace and deprecation alias to TextContentHandler
This patch introduces a namespace declaration for the
MediaWiki\Content to TextContentHandler and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I2c72dacf28ee72fb70b15acdd81d0eb717ea949a
2024-05-20 05:34:31 +03:30
Func
4e6158a6fb Use constants provided by MainConfigNames for config names
Change-Id: I2f29ea8227da64b79b70fcce3decb6e34ea8da5b
2024-05-18 01:26:46 +08:00
daniel
91a1741787 Introduce Modules into the REST framework
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
2024-05-08 16:12:30 +02:00
daniel
97eae33cf5 REST: introduce getBodyParamSettings
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
2024-05-07 17:35:36 +00:00
Bartosz Dziewoński
eae0341415 ResourcesTest: Test 'packageFiles' existence too
Also, reset logo settings to avoid failures caused by them.

Change-Id: I666141ff776d52e578f0cad4e00d3ec14e444b42
2024-04-16 17:58:03 +00:00
Wendy Quarshie
47f28ecd2d rest: use new body validation in creation and update handler
Bug: T358850
Change-Id: Idce281198604e0983f35776e03d607b7a280cc7e
2024-04-03 13:17:20 +00:00
jenkins-bot
9a24b39080 Merge "handler: Declare known sources in Validator" 2024-03-28 14:28:53 +00:00
Atieno
36c16d9c96 handler: Declare known sources in Validator
Bug: T358558
Change-Id: I0536e0d659b53c8f85bf7685beffbb5c5d027998
2024-03-28 16:42:59 +03:00
Derick Alangi
d372626b97
objectcache: Introduce ObjectCacheFactory MW service
ObjectCache is already doing a lot of factory pattern logic like
creating instances of the various BagOStuff, this should really be
the responsibility of the factory servicet.

This patch introduces a proper factory (ObjectCacheFactory) to handle
the responsibility of creating various instances of BagOStuff. Since
`newFromParams()` is a static function that gets passed in configuration
of $wgObjectCaches, that can stay that way (to keep supporting how we do
this in prod today).

Technical Breaking Change: `ObjectCache::makeLocalServerCache()` now has
a parameter and requires it but there are no callers of this method outside
MW core hence it is safe to change (and this patch update all callers) to
work correctly. Cache prefix is gotten from global state because sometimes
at this stage, the services container is not available.

Bug: T358346
Change-Id: I3179a387486377c6a575d173f39f82870c49c321
2024-03-19 12:38:39 +03:00
jenkins-bot
5d8b59b3ea Merge "ResourceLoader: Add module property skipStructureTest" 2024-03-13 22:09:01 +00:00
daniel
ae9d8e6054 Rest: Turn Rest\EntryPoint into a MediaWikiEntryPoint subclass
The idea is for all entry points to use the MediaWikiEntryPoint
base class, to improve consistency and testability.

Bug: T354216
Change-Id: I3678afe32c7c1a313d2dcb1808286c25ecd167eb
2024-03-12 14:37:18 +01:00
Tim Starling
c45ca5c0e3 ResourceLoader: Add module property skipStructureTest
Allow extensions with very special modules that can't be called in a
testing environment to skip ResourcesTest::testRespond().

Needed by If1186797fd047d4f for ext.wikisource.OCR.

Change-Id: Id02915d9633c2d8209d2ff2e60f6748095ec10fe
2024-03-11 17:01:16 +00:00
Matěj Suchánek
45390a52eb Clean up tests
Replace strpos with str_contains, str_starts_with, etc.
Fix spelling of "cannot" and other typos.

Change-Id: Ie52900b323f46d1978a9dd9ea3b17619b8942160
2024-02-12 09:25:25 +01:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Bartosz Dziewoński
e4c7272976 Change uses of getDBLoadBalancerFactory() to getConnectionProvider()
Update cases where one of the IConnectionProvider methods is called
immediately.

This doesn't really change anything, but I hope it helps promote
getConnectionProvider() as the common way to do this.

Follow-up to 8604c384f6.

Change-Id: Id0e7d02bab0c570343c2b1f03c70b44ee39db112
2024-01-22 22:27:45 +01:00
Alexander Vorwerk
cd6ac532ce tests: Replace usages of wfGetDB
Change-Id: I4f57ef084da8f0404e7bc2b4c466b7512e89670f
2024-01-18 00:12:59 +00:00
Daimona Eaytoy
605d12b9b3 Update tests for PHPUnit 9.6 (part 1)
- Avoid defining abstract test classes (ending in "Test")
- Avoid withConsecutive()
- Avoid getMockClass()

Bug: T342110
Change-Id: I131e0d85bd14e75aaebd6f212b2e64a45d4c73a2
2024-01-16 23:36:15 +01:00
James D. Forrester
273cc042ae ResourceLoader: Drop targets system, deprecated in 1.41
Bug: T340802
Depends-On: Ie936afed7042d5a4713b027c30d7487565a35eaf
Change-Id: Icad30d62301be5d7390ebdf34e818519e3fe56c4
2024-01-12 16:42:38 -05:00
Tim Starling
c55379d5b8 Deprecate and stop using Database::listViews()
Follow up Id9ab64fc8b09d9 which made listTables() consistently exclude
views.

Hard deprecate Database::listViews() which was only used for view
filtering of listTables(), conditional on database type.

Add an integration test for the new listTables() behaviour.

Change-Id: I3402a227f92b35192c6385c6aeab461de43b9f58
2023-12-14 14:35:36 +11:00
Umherirrender
388b0374fa tests: Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statements and changes to docs done manually

Change-Id: Ib326ae1e5c8409a98398c721e8b8ce42c73bd012
2023-12-11 15:59:55 +01:00
Tim Starling
c5d182eb01 rdbms: Map PostgreSQL boolean values to MySQL-compatible forms
Also fix callers that were checking for t/f.

In CASE and COALESCE expressions, using 't' and 'f' did actually work,
because those literals have an unknown type and the other argument is
boolean, so PG coerces them to boolean. But it seems safer and clearer
to use the strongly typed literals TRUE and FALSE.

Bug: T352229
Change-Id: Ia01b76d3d6d2e048feac8e3118d9faff63a9ac56
2023-11-29 13:31:42 +11:00
jenkins-bot
800f1b19f4 Merge "Remove deprecated methods from Content interface" 2023-11-28 15:52:14 +00:00
James D. Forrester
4ed5ca48b1 Follow-up 71ff05267: Stop writing to tablesUsed in tests, now unnecessary
Bug: T342301
Change-Id: I5ea01f7ee103570165261bde0965c5b65e04c369
2023-11-21 09:02:48 -05:00
daniel
eb881d9b59 Remove deprecated methods from Content interface
Several methods on the Content interface had been deprecated in 1.35 and
1.36 in favor of corresponding methods on the ContentHandler base class,
to allow implementations of these methods to use proper dependency
injection. This patch removes backwards compatibility support for
subclasses that were overriding these methods.

Change-Id: I8e474a1cc4dec760a7f6db25e4b313392f3723b1
2023-11-21 12:40:11 +01:00