Commit graph

343 commits

Author SHA1 Message Date
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
Timo Tijhof
c7e29903ac ResourceLoader: Remove ResourcesTest::testCommentedLocalFileReferences
* Unrelated to the ResourcesTest structure test as it isn't testing
  any of core's resources.

* Moved to the libs/Minify repo in change Ia9018a966a5325d.

Change-Id: If87035777633635fe4ad0f01790e7084f56f65a0
2023-10-20 19:47:50 -07:00
jenkins-bot
23e070865d Merge "Structure tests: Alter resources test to also check skinStyles" 2023-10-19 13:52:22 +00:00
Jon Robson
2dc2af1d28 Structure tests: Alter resources test to also check skinStyles
Bug: T348676
Change-Id: I804bda05901e38dc2b0ba12ec954aafcfed3fcbc
2023-10-19 13:09:59 +00:00
Ammarpad
88c21717e9 ApiStructureTest: Improve error message
Make message to actually communicate errors instead of
confirming success, this will reduce confusion like in T348934

Change-Id: I0b9cd5aed26be539db429a79c486217a69f74cdb
2023-10-17 09:53:37 -04:00
DannyS712
8b66151b73 Update references to config-vars.php
Moved to docs/ rather than includes/, update references and remove
from phan exclusion list

Follow-up: I32c034d05bf2354cdaa5f02d19031421cbae78a1
Change-Id: I8d71c29c8cbfa413db47066f00d71783259f0916
2023-09-23 03:37:44 +00:00
Amir Sarabadani
abbb4281cb tests: Migrate more cases to SQB
Bug: T344971
Change-Id: Ia69d82d6a6e623b9032240dc910fb47ff5887661
2023-09-21 18:30:37 +00:00
James D. Forrester
c1599c91b3 Namespace Config-related classes under \MediaWiki\Config
Bug: T166010
Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
2023-09-21 05:41:58 +00:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Amir Sarabadani
5bd33d46ef Reorg: Move WebRequest to includes\Request
This has been approved as part of RFC T166010

Bug: T321882
Change-Id: I6bbdbbe6ea48cc1f50bc568bb8780fc7c5361a6f
2023-09-11 21:44:34 +01:00
jenkins-bot
f415979f2c Merge "Make all limits function as user rights." 2023-09-11 12:34:48 +00:00
daniel
9143649f48 Make all limits function as user rights.
In order to check all existing rate limits through Authority, the limit
keys must function as user rights. However, we do not want them to be
"normal" permissions, since they cannot sensibly be revoked, and they
should not clutter the user interface.

To solve this, we introduce the concept of "implicit rights", which are
always granted, but limitable.

Change-Id: I0ea6f29130da1d68d022d47d9221fe878bc9beae
2023-09-11 12:03:57 +00:00
Daimona Eaytoy
f83e611efa Make MediaWikiIntegrationTestCase::addCoreDBData a noop
The method should never be called directly, so make it throw an exception.
Nonetheless, mark it as deprecated and detect overrides in the
constructor, so that anyone who tries to override this method will see a
warning.

Fix the few tests that were relying on the existence of the test page.

Bug: T342428
Depends-On: Ic64ded5e2c0b59e7c888ece9566076058a125be4
Change-Id: I308617427309815062d54c14f3438cab31b08a73
2023-09-05 00:36:36 +00:00
Umherirrender
d7f959e528 tests: Use namespaced Wikimedia\Rdbms\IDatabase
Bug: T344536
Change-Id: I29c80fe2ac3effd5e9df4402c598dc33c1b23d5e
2023-08-20 15:18:57 +02:00
Daimona Eaytoy
c6bd1e842c Do not use UTSysop directly in tests
If the test expects the user to exist, it should use getTestSysop to
guarantee the account creation. Otherwise, use mocks or different
usernames to clarify that the username is not relevant to the test.

Change-Id: I87a27f01e1874af410e5d43e2e7fc3b10bb14eb8
2023-08-16 00:35:25 +00:00
Tim Starling
f2a5946375 ResourceLoader: wrap module definitions in functions
This is an intermediate step towards the linked bug, to help untangle
the performance impacts.

Bug: T343407
Change-Id: I086f173f811fb44683f4a67bf6bc415d7e27f593
2023-08-11 00:36:52 +00:00
Daimona Eaytoy
59b93e9e4f Avoid DB access in non-database tests
Mock the needed dependencies to avoid database access when possible, and
add the test to the Database group otherwise.

Bug: T155147
Change-Id: Ic5c39ab35ab4d993721713285180f072497a5a40
2023-08-06 22:57:48 +00:00
Daimona Eaytoy
1cb036c392 Avoid DB access in more non-Database tests
Bug: T155147
Change-Id: Iae2512c66c32b209ea8579beecb3de94a744da14
2023-08-06 16:07:27 +00:00
Daimona Eaytoy
485e47ff10 tests: Avoid database usage when possible
We would like to remove DB access in non-database PHPUnit tests. As a
first step, avoid database usage in tested code when possible. In
particular:
- In NameTableStoreFactory, avoid domain ID normalization if the
  provided ID is already false.
- In SpecialDoubleRedirects, do not acquire a DB connection until it's
  needed (which is just one place).
- Use editPage() in TitleDefTest instead of a DIY implementation, and
  add `@group Database` accordingly.
- Avoid parsing titles in ContentHandler tests that don't need to parse
  titles. Among the many dependencies of parsing titles is the interwiki
  lookup, which requires DB access.
- Also remove test cases that used the "Gadget" namespace; it doesn't
  exist in core, so these pages were actually in the mainspace.
- Mock the database in CategoriesRdfTest. The only two methods that use
  the database were already being mocked.
- Add `@group Database` to test classes that are intentionally using the
  Database, mainly via getTestUser().

Bug: T155147
Change-Id: I9385fe14cfeb6b7b7378cc322d510034c4ee0711
2023-07-31 00:46:13 +00:00
Daimona Eaytoy
2a0de02aab phpunit: Avoid TestUser in non-database tests
TestUser creates the user and therefore needs the database. Avoid using
it in non-database tests.

Add ApiQueryBlockInfoTraitTest to the Database group because it needs
the database.

Add DeleteUserEmailTest to the Database group because since 3bedffa8
the default user is not created any more in non-database tests

Change-Id: Iff438964dde47a47a2fa4a314d55010bd8c7fee5
2023-07-29 14:26:50 +00:00
daniel
420f222266 Make Shell::makeScriptCommand use run.php
This makes makeScriptCommand wrap all callers in run.php

Change-Id: If041beb6d4b6b3555e0c200a3d5088a94c198349
2023-07-25 01:35:59 +00:00
jenkins-bot
daa4bdf97c Merge "Fix DB usage in non-database tests" 2023-07-24 04:14:31 +00:00
Daimona Eaytoy
f00ca670bc Fix DB usage in non-database tests
Some non-database tests are currently accessing the database. Fixing
them means either avoiding the DB access if it's possible and makes
sense for the test, or adding the `Database` group otherwise. In
particular:

- Replace global/static functions with services in a couple places to
  make testing easier.
- RevisionRendererTest needs to be in the Database group due to heavy
  global state usage (including DB) by Parser
- ActionFactoryIntegrationTest and SpecialPageFatalTest should be in
  the database group because they test many different classes, and some
  of which may use the database in the tested methods.
- SpecialUserLogoutTest must be in the database group because of User.
- Some pager tests are using wfGetDB directly.

Change-Id: I96eb2acf9a2cbfd17e81225db2773d5e8e30260b
2023-07-21 13:52:47 +02:00
Daimona Eaytoy
5494d15efb Add ResourcesTest to the Database group
This tests needs the database in various places:
SqlModuleDependencyStore, wfGetDB() for WikiModule::preloadTitleInfo,
and other things in WikiModule. Some of these might be avoided; for
instance, it could use KeyValueDependencyStore. Others can't really be
avoided as the relevant classes call wfGetDB (or equivalent methods in
MediaWikiServices) directly.

Given the importance of this test, I'd rather have it continue using the
database, so add it to the Database group.

Change-Id: I564a826e97967897a3538d74cdef6f3dbdd570f1
2023-07-19 19:40:47 +02:00
Daimona Eaytoy
b04576b3be phpunit: Sync phpunit.xml.dist with tests/phpunit/suite.xml
Since the latter is going to be removed, make sure that the former has
everything we need. In particular:
- Add failOnRisky=true from suite.xml
- Reorder config options and add comment about stderr from suite.xml
- Remove non-existent tests/phpunit/skins and
  tests/phpunit/documentation from the test suites. These cause an error
  when trying to run all the suites with `composer phpunit`.
- Leave the other suites as they are. Compared to suite.xml,
  phpunit.xml.dist has separate suites for core, extensions, and skins
  unit tests.
- Leave includeUncoveredFiles to false. The rationale in
  I3d19627fa36f6cc6666c29fdb638272fdaa30630 seems convincing. CI already
  sets it to true: https://w.wiki/72qE
- Leave slowThreshold to 100 as per
  Ia6ed404d4d4cc8a7b4b8a48b232f644f400f8103. I believe that change
  simply missed suite.xml. The same rationale that led to the threshold
  being increased for unit tests is valid a fortiori for integration
  tests, which are generally slower.

Rename SuiteDirectoryTest and make it check phpunit.xml.dist too.

Bug: T227900
Change-Id: Ib4b47b337870dffc61dd44817a21d11809075d5b
2023-07-14 20:59:42 +00:00
Daimona Eaytoy
5cc78474e1 tests: Avoid DB queries in ApiStructureTest::provideParameters
Some of the methods called in the data provider, like getAllowedParams,
may make read queries. This should be avoided in data providers (see
e.g. T312849). Instantiate the module in the test method instead, and
process all parameters there. This does mean that a failure with a
single parameter will make the test end without testing the remaining
parameters, but there isn't much we can do about it.

Bug: T341731
Change-Id: I7eeed0da5da61e90c6fbfa0411a2b3b416395167
2023-07-12 23:18:41 +02:00
Umherirrender
792981fea5 tests: Use Title::makeTitle instead of Title::newFromText
Avoid parsing known titles in tests to improve performance

Change-Id: Iddefe62c3d85281642f17e60cbc27aff47b85a67
2023-06-19 21:54:57 +02:00
Michael Große
be7b1537a6 Reenable "RedundantTargets" test
Depends-On: Ic8d1b6871efb45b34325c412de737f3a5f75c0e6
Depends-On: I0f53fbda59f6d2e3088aa3f59a0ba795194240a0
Change-Id: I0af85955adbb224827bf52e8d4c49d0aca0caba4
2023-06-09 10:40:28 +02:00
Michael Große
202afecee6 Skip targets test to merge mutually blocking fixes
Needed-By: I0f53fbda59f6d2e3088aa3f59a0ba795194240a0
Needed-By: Ic8d1b6871efb45b34325c412de737f3a5f75c0e6
Change-Id: I92c297f0d170db17dfce03ed0d26614ac2182c87
2023-06-09 10:38:46 +02:00
Jon Robson
c1f8e81356 Tests: Error for any new module that introduces bad targets
Going forward we do not want to use the targets system in the way
we traditionally used it. While updating existing usages will take
time it seems like it might be a good idea to prevent additional usages
being added. This list would gradually be updated as we update those
components.

Bug: T127268
Depends-On: Ibd7270abc5f223bc4f4814c896e7ef4d02d21386
Change-Id: I2e226c174be88caeb505738645cfa0582e39a197
2023-06-08 20:05:30 +00:00
jenkins-bot
6f9ac8889b Merge "Replace substr with cleaner string methods" 2023-06-06 14:15:27 +00:00