Commit graph

226 commits

Author SHA1 Message Date
jenkins-bot
f3b5f09e4c Merge "Make use of the ?? and ??= operators where it makes sense" 2022-12-16 01:06:50 +00:00
daniel
c6ca5baa16 phpunit: improve isolation by calling User::clearInstanceCache
User objects may hold references to service objects. They need to be
reset when services are reset between and during tests.

Change-Id: I7fe767977f1fe01d508fddf7a92ade3ec8ba2662
2022-12-04 15:21:30 +01:00
daniel
166b569444 Make use of the new PageUpdateStatus
PageUpdateStatus provides clean access the the newly created
RevisionRecord.

Depends-On: Ia08c586198082ea47e8313d0d41835f9830fb29e
Change-Id: Id6963842321c4eaa3d7d029ad0b769f73433c103
2022-11-30 17:56:58 +00:00
thiemowmde
0af1a51345 Make use of the ?? and ??= operators where it makes sense
?? is an older PHP 7.0 feature.
??= was added in PHP 7.4, which we can finally use.

Change-Id: I85921f1db9670987e173e905e8206bdf46659457
2022-11-10 18:31:18 +01:00
jenkins-bot
fcf1254593 Merge "PHPUnit: introduce clearHooks() method." 2022-11-04 14:11:49 +00:00
daniel
8e0ae53482 PHPUnit: introduce clearHooks() method.
Since the introduction of the new hooks stystem, it is not possible to
clear all hooks by setting $wgHooks. This would only clear old-style
hooks. This is becoming increasingly problematic as the new hooks system
is adopted by more and more extensions.

Introduce a method that allows tests to reset many or all hooks.
This isn't needed much in core, but extension tests need it.

Change-Id: Ica3eb88fe23fe822d2aadb96ff5d15f80dce0d7b
2022-11-03 13:40:42 +01:00
Amir Sarabadani
bbe704b5c1 Reorg: Move some of request related classes to MediaWiki/Request
Redoing I5ea70120d74 but without moving WebRequest that caused issues
with phan-taint-plugin.

Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequestUpload

Bug: T321882
Change-Id: I832b133aaf61ee9f6190b0227d2f3de99bd1717b
2022-10-28 10:15:31 +00:00
Zabe
f6b9381d7f Revert "Reorg: Move some of request related classes to MediaWiki/Request"
This reverts commit 2bdc0b2b72.

Reason for revert: T166010#8349431

Bug: T166010
Change-Id: Idcd3025647aec99532f5d69b9c1718c531761283
2022-10-27 13:14:16 +00:00
Amir Sarabadani
2bdc0b2b72 Reorg: Move some of request related classes to MediaWiki/Request
Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequest
 - WebRequestUpload

Bug: T166010
Change-Id: I5ea70120d745f2876ae31d039f3f8a51e49e9ad8
2022-10-26 16:49:10 +02:00
Tim Starling
43a93d9782 Use the null coalescing assignment operator
Available since PHP 7.4.

Automated search, manual replacement.

Change-Id: Ibb163141526e799bff08cfeb4037b52144bb39fa
2022-10-21 13:26:49 +11:00
Aaron Schulz
c1e1512698 rdbms: improve LoadBalancer connection pool reuse (ii)
Make DBConnRef enforce the DB domain selected during its lifetime
and allow more nested and successive use of the same connection handle
via DBConnRef. This can avoid extra connections in some cases where
getConnection()/getConnectionRef() is used.

Also:
* Reduce the number of connection pools arrays from six to two
* Merge getLocalConnection()/getForeignConnection() into one method
* Expand various related code comments

Since LoadBalancer::getReadOnlyReason() no longer user the local domain
but rather DOMAIN_ANY, it should not result in "USE" errors if the local
domain does not have a database on the server.

This version of the patch removes the unused reuseConnectionInternal()
method (the method was previously added back to the patch by mistake).

Bug: T226595
Change-Id: I62502f4de4f86a54f25be1699c4d1a1c1baee60b
2022-10-18 17:23:44 -07:00
jenkins-bot
8d808457a1 Merge "Revert "rdbms: improve LoadBalancer connection pool reuse"" 2022-09-29 13:10:18 +00:00
Ladsgroup
4edae94817 Revert "rdbms: improve LoadBalancer connection pool reuse"
This reverts commit 76be4dca81.

Reason for revert: Caused T318904

Bug: T318904
Change-Id: I92f23205b4d62f69c0f27af40f972f104d1a7a7c
2022-09-29 12:12:14 +00:00
Umherirrender
89b2d11a0d tests: Use Title::makeTitle instead of Title::newFromText
Avoid parsing known titles in tests to improve performance

Change-Id: Ie240eb42479d19714e64cc4606e26073fadc2e13
2022-09-23 21:53:11 +02:00
Aaron Schulz
76be4dca81 rdbms: improve LoadBalancer connection pool reuse
Make DBConnRef enforce the DB domain selected during its lifetime
and allow more nested and successive use of the same connection handle
via DBConnRef. This can avoid extra connections in some cases where
getConnection()/getConnectionRef() is used.

Also:
* Reduce the number of connection pools arrays from six to two
* Merge getLocalConnection()/getForeignConnection() into one method
* Expand various related code comments

Bug: T226595
Depends-On: If808cbab429d41e1f2289683533e4a781a4bdf5e
Change-Id: I540b08920997c57cad6445ddb09d8e663eaf4714
2022-09-23 10:53:58 +10:00
Kosta Harlan
9748113b1f MediaWikiIntegrationTestCase: Add redirect table to list of tables to truncate
Change-Id: I5e40e6adfe51e2c86c30dff05916c1c2adcfbbf5
2022-09-20 11:19:02 +00:00
jenkins-bot
aafa2e0b04 Merge "tests: Replace deprecated WikiPage::factory" 2022-09-09 16:25:08 +00:00
Aaron Schulz
7a1bb4011d unittests: add MediaWikiIntegrationTestCase::getDb()
When tests use code that uses getConnection() to foreign domains, it changes the
DB domain of the "db" member field, which can break assertions. Use of this new
method can avoid that problem by using DBConnRef.

Bug: T316841
Change-Id: Ia0f3cf49c79affb7189801852ac7e9ec67933a3c
2022-09-06 23:24:38 +00:00
Umherirrender
6555923b08 tests: Replace deprecated WikiPage::factory
Bug: T297688
Change-Id: Ic84d491c5603f3590e26cb56a305508b2b0ca109
2022-09-02 19:34:02 +00:00
daniel
79746fbd35 ParsoidOutputAccess: support target language.
When parsing content for page creation, we need to be able to pass the
page language explicitly. This patch allows the language to be looped
through from ParsoidHTMLHelper via ParsoidOutputAccess into Parsoid
itself.

Change-Id: I1bbf9c2180de2d91679edbc9d73adfe44075dde3
2022-09-02 14:00:40 +00:00
jenkins-bot
c17df8ff78 Merge "tests/api: Add TestUser::getAuthority and use it" 2022-08-19 16:35:47 +00:00
jenkins-bot
706d479075 Merge "tests/api: Use MediaWikiIntegrationTestCase::editPage for edits" 2022-08-19 16:35:40 +00:00
jenkins-bot
425303861f Merge "rdbms: add getDomainChangeException() call to DBConnRef::tablePrefix()" 2022-08-10 04:14:28 +00:00
Umherirrender
ef0623ec06 tests/api: Add TestUser::getAuthority and use it
Change-Id: Icfb66f9927c8e67582010a208538b0b5e0ba353f
2022-08-06 23:15:27 +02:00
Umherirrender
6a8f3b4c55 tests/api: Use MediaWikiIntegrationTestCase::editPage for edits
Also improve MediaWikiIntegrationTestCase::editPage by accepting
LinkTarget objects and use services instead of static functions

Change-Id: I3d036b0837f212d3500159c1d3a3daa4e706882c
2022-08-06 22:21:51 +02:00
Aaron Schulz
3e49c2029e rdbms: add getDomainChangeException() call to DBConnRef::tablePrefix()
This matches the DB domain logic enforcement in the other class methods.

Cleanup several type hints in related code.

Change-Id: I6668852ccebe16349b38b5a793543bd3ec0a35b8
2022-08-03 21:41:09 +00:00
TheSandDoctor
da38639658 Remove deprecated $wgParser
$wgParser, deprecated in 1.32, has been removed.

Bug: T160811
Change-Id: Iaf09d3e158e1fee8c0f541695b6d9b4233033c81
2022-08-03 14:40:16 +02:00
Umherirrender
dee77e59a1 tests: Remove resetServiceForTesting after overrideConfigValues
overrideConfigValues is documented to reset services as well

Change-Id: Ie13a699f6cd912b912d34adb97704bab3cbdff2d
2022-07-27 23:08:27 +02:00
jenkins-bot
1874b90587 Merge "test: installMockMwServices should apply overrides per default." 2022-07-18 20:38:34 +00:00
daniel
7945b5301b test: installMockMwServices should apply overrides per default.
MediaWikiIntegrationTestCase::installMockMwServices() was changed in
I1922d9b903dcafb83691c2d96790f72747eeef9c to no longer apply default
overrides. This was left to overrideMwServices().

This caused parser tests to run without the necessary config overrides,
since it calls installMockMwServices(), but cannot make use of
overrideMwServices().

This changes installMockMwServices() so it will apply the default
overrides when called with no parameters.

Bug: T312709
Change-Id: I898927717ce961d98617a7fcd9c7fa8e19bec412
2022-07-17 17:34:01 +02:00
mainframe98
00eab3cef3 tests: ensure LocalServerObjectCache is reset before redefining
If an extension uses this service somewhere, redefining before
resetting it breaks the tests.

Follows-up: Ia60cb0bc18b235f23d9778da8241f65accfc0d35
Change-Id: Ie930f2bbab3d31831751caa1ca342fd9a023b19b
2022-07-16 12:29:58 +02:00
Umherirrender
bbaa4c25d9 tests: Use MainConfigNames constants on overrideConfigValue
Change-Id: Ieeefb88daf55a976883f6e20ef6881c89a7f7630
2022-07-12 19:34:54 +02:00
Derick Alangi
f00cd03580 tests: Make use of overrideConfig(Value|Values) where needed
As we slowly move away from using globals, overrideConfigValue()
and overrideConfigValues() were introduced as a way to override
test configs between tests.

Under the hood, it just calls setMwGlobals() which resets services,
so take note.

Part 1: Directories covered are: languages/, maintenance/, tests/,
structure/ and includes/Permissions/.

Depends-On: I618b16c6d99c94eb2e7edcf05e888a65f7156754
Change-Id: If56f7d10d79f3a9824a52091a2b544d8653dd7b6
2022-07-11 21:15:26 +01:00
daniel
c6c62e2c8f PHPUnit: enable main object cache in tests
This sets MainCacheType to 'hash', so the main cache is functional
within test cases. Between tests we are already calling ObjectCache::clear,
so the cache will not leak data into other test cases.

It turned out that the way we have been overriding configuration
settings in MediaWikiIntegrationTestCase is insufficient, since the
overrides would only apply in the main Config object, not in global
variables. This means they could not be overwritten with setMwGlobals.
So this patch also changes how we apply config overrides for test setup.

Config overrides that happen during tests work as before.

Depends-On: Ic36e92b73f22fd64e2d0b680d8e900f598158460
Change-Id: Ia60cb0bc18b235f23d9778da8241f65accfc0d35
2022-07-07 16:26:03 +10:00
daniel
bf092744c9 PHPUnit: introduce setMainCache
The main object cache is disabled during testing. Some integration tests
need it though. This provides a clean way to enable it, to replace the hacks
that were used so far.

Note that we may want to enable the main cache during testing soon. When
that happens, this method is still useful to disable the cache in certain
tests, and to set a specific cache instance.

Change-Id: I04ae1bf1b6b2c8f6310acd2edf89459d01a9c870
2022-07-07 16:25:59 +10:00
jenkins-bot
0f75ef7180 Merge "Use HashConfig to override config variables in phpunit tests" 2022-07-07 05:13:52 +00:00
daniel
ac7138d45b Use HashConfig to override config variables in phpunit tests
This implements config overrides with a HashConfig that is layered on
top of the base config, so we can move away from global variables.

Global variables are still updated using setMwGlobals, for compatibility
with code that is still reading configuration from global variables.

This fixes an issue with the default overrides not being applied to
global variables.

Change-Id: I1922d9b903dcafb83691c2d96790f72747eeef9c
2022-07-07 14:54:06 +10:00
Umherirrender
6629932569 tests: Remove unneeded Title::newFromLinkTarget calls
Use the page identity from RevisionRecord instead

Change-Id: I80550f41645b55278b085968295ed016c212934c
2022-07-05 23:57:30 +02:00
jenkins-bot
bf5806d4ff Merge "tests: Move assertHTMLEquals to the test case trait" 2022-06-24 01:51:57 +00:00
daniel
033060bbaa PHPUnit: introduce overrideConfigValues.
overrideConfigValues() is introduced as a replacement for
setMwGlobals(). Since we are moving away from reading configuration
from global variables, test cases should not use global variables to set
configuration.

Bug: T294739
Change-Id: I9d41045bd13932bd853f53e00322233fc4f1321c
2022-06-21 13:29:29 +02:00
mainframe98
3fd374e974 tests: Move assertHTMLEquals to the test case trait
This allows accessing it in both integration and unit tests.

Bug: T310514
Change-Id: I5c97364cbdc81fe67f156cffb04b252af7ccf6ff
2022-06-13 15:32:57 +00:00
Lucas Werkmeister (WMDE)
acae1c5107 Revert "phpunit: Default to vendor/bin/phpunit, remove suites.xml"
This caused unexpected problems with no obvious fixes. Needs more work.

This reverts commit 7238dff532.

Bug: T310255
Bug: T90875
Change-Id: I3758cbb6d0029b20ec1b0f67dbf2f422031c50ae
2022-06-09 14:15:54 +00:00
Kosta Harlan
7238dff532 phpunit: Default to vendor/bin/phpunit, remove suites.xml
* switch to phpunit.xml.dist instead of suites.xml
* switch composer.json to vendor/bin/phpunit
  * tests/phpunit/phpunit.php is retained but will be removed after CI
    jobs and other references on
    codesearch (https://codesearch.wmcloud.org/search/?q=tests%2Fphpunit%2Fphpunit.php&i=nope&files=&excludeFiles=&repos=)
    are removed
* add a default bootstrap.integration.php; unit tests in
  composer.json use the non-MW bootstrap file (bootstrap.php)
  * Migrate the phpunit.php logic into tests/phpunit/BootstrapIntegrationWrapper.php

Depends-On: I19d560bdcdb2ee914ab055e094841f2b5db8be55
Depends-On: Ib23209fc3b095e3c012ed84ce5c11f8b2d27b898
Co-authored-by: Daimona Eaytoy <daimona.wiki@gmail.com>
Bug: T227900
Bug: T90875
Change-Id: I82045c207738d152d5b0006f353637cfaa40bb66
2022-06-08 18:31:16 +00:00
Amir Sarabadani
24115a8f4c Start clean up of revision_actor_temp table
It is being dropped in production

Bug: T215466
Change-Id: I66b2cb8653252e720c897351065978119f040ba7
2022-05-23 15:37:42 +00:00
daniel
237bbf089f Turn DefaultSettings.php into a deprecated stub
DefaultSettings.php has been replaced by MainConfigSchema.
Loading DefaultSettings.php is deprecated.

Code that needs to have access to configuration defaults should use the
ConfigSchema service object.

Bug: T300129
Change-Id: I7b2c0ca95a78990be1cdb9dd9ace92f6dcf1af15
2022-05-17 16:50:56 +02:00
Amir Sarabadani
a294e715a4 rdbms: Replace getConnection with getLazyConnectionRef
This would simplify the code for its users a lot.

Bug: T255493
Depends-On: I6ab4440a13f4682dd3a6e9cfc6c629222fbeab8a
Change-Id: I6e7544763bde56fc1e19de0358b71ba984a978ca
2022-05-12 07:43:03 +02:00
jenkins-bot
654ccb3a4c Merge "Setup.php: clarify the use of $IP." 2022-05-04 18:10:39 +00:00
daniel
bedd996fe6 Setup.php: clarify the use of $IP.
The global variable $IP has been replaced by the MW_INSTALL_PATH
constant. Clarify the continued use of $IP on Setup.php.

Change-Id: I157abfd9049fb8382da53005a084ab86f47e8d8a
2022-05-03 11:53:05 +02:00
Aryeh Gregor
79fc95d39c Use MainConfigNames instead of string literals, #5
This should be the last of the usages in core, although I'm sure a few
are hiding somehow.

Change-Id: I7bf0b24bf23d3efb4c56a891830bbfe67945e899
2022-04-27 18:46:29 +03:00
Daimona Eaytoy
0a6ec1031a Move wfRequireOnceInGlobalScope to TestSetup
TestSetup seems a nice place for this function. This way, it can also be
reused in the other boostrap file whilst we migrate the entrypoint.
Also, replace the check in MediaWikiIntegrationTestCase with another
constant; this also makes it easier to understand when exactly that code
should run.

Bug: T90875
Change-Id: I7858d982378ab4b6f11c4e9bf955d83d1acbc85d
2022-04-25 12:52:58 +00:00