Commit graph

30 commits

Author SHA1 Message Date
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
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
Umherirrender
9cd9ab0590 tests: Do not hide deprecation in SpecialPageFatalTest
Since 9cc1cd3 a filterDeprecation() call exists to hide MediWiki
deprecations, let php deprecation show up

Depends-On: Id07a55743bdfe04022b7c96acb6c154c7fe33098
Change-Id: Ia51b00399c584671ccf5d9fb8dfed1e94e5d60f9
2022-12-16 13:04:45 +00:00
Daimona Eaytoy
1c60cafab4 Add @coversNothing to all structure tests
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
2022-10-07 03:21:54 +02:00
Kosta Harlan
ff63886b0f
phpunit: Do not access MW services in dataProviders
We cannot access MW services in a data provider, as MW will not have
bootstrapped by this point in plain PHPUnit. And we do not want to
bootstrap MW by the time a dataProvider is executing, because unit tests
should not need (nor be able to access) MW services.

Change-Id: I21a5993f91b8fbe3fa476a8244b8911cf81e1d5f
2022-05-30 23:16:06 +02:00
Lucas Werkmeister (WMDE)
1aca74e298 Revert "Add SpecialPageFatalTest to @group Database"
This reverts commit be7565e3e1.

Reason for revert: Needed for a revert of CentralAuth change I3baf207711.

Change-Id: I847086a8ea2be8931b9f3fc092467445c47644a0
2022-03-31 12:37:57 +00:00
Taavi Väänänen
be7565e3e1
Add SpecialPageFatalTest to @group Database
This causes this test case to be run with sql_mode set to
STRICT_ALL_TABLES,ONLY_FULL_GROUP_BY, instead of the default TRADITIONAL
set in DevelopmentSettings. Many database pages (such as those including
a pager) make database connections when loaded without parameters.

If this can be merged without problems it would let us un-revert
Ic2729428297162763a772e6a16549ded8de06c01 too.

Bug: T304762
Change-Id: I3bb424ddcbd7d3d6c03ad23d071a69a94b7f5749
2022-03-26 15:43:46 +02:00
Lucas Werkmeister (WMDE)
39f8110385 Revert "tests: Special page constructor are not allow to call getContext"
This reverts commit f2de49b694.

Reason for revert: breaks CI for several other extensions.

Bug: T297020
Change-Id: I20061df89f4727431be84e52e5133fe50412d338
2021-12-03 18:09:03 +00:00
Umherirrender
f2de49b694 tests: Special page constructor are not allow to call getContext
special page constructor should be cheap and
not infer global context on Special:SpecialPages

Depends-On: I6a3dd263dbe02111aea65a087ce69a5a191f63fc
Depends-On: I39dee5bd5064e319d7209e8f86da70bc5383a9bf
Depends-On: I75d3593de0233540710d69ba9a30631cb62fd262
Depends-On: Ifdc9e45d8c0dbcdf03a849a40b42f65b1cf1aa65
Change-Id: Ia3cbbf4971072c922f8cc137f81607a2d3bf61fc
2021-11-09 23:11:18 +01:00
James D. Forrester
3c946b30c4 phpunit: Drop bypass for now-fixed dberror from SpecialPageFatalTest
Now that CI is running MariaDB 10.3+, this shouldn't happen any more.

Bug: T248191
Change-Id: I71f91ddb11f23b68a1c382ac8b4bb6a87ead417a
2021-09-16 08:49:46 -07:00
libraryupgrader
5357695270 build: Updating dependencies
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
2021-07-22 03:36:05 +00:00
daniel
fed7f0b179 Remove $actor field from UsererIdentityValue
Code that needs to store an actor ID in the database to
represent a UserIdentity, or needs to construct a UserIdentity based on
an actor ID loaded from the database, should use the ActorNormalization
service.

Note: The getActorId() method is removed from the UserIdentity interface,
but all concrete classes continue to support it for now.
UsererIdentityValue::getActorId() is hard deprecated and should
be removed in 1.37. It always returns 0.
User::getActorId() is not deprecated at this point.

Bug: T274179
Depends-On: Id2b3ddf6a2a7cdf90f8936a69148d2cce6fde237
Change-Id: I9925906d11e47efaec3c1f48d5cb3f9896a982c1
2021-04-13 18:18:06 +00:00
DannyS712
653c62053e SpecialPageFatalTest: add names to test cases
Jenkins logs show that some of the cases are slow,
but its hard to tell what special page "data set #74"
corresponds to

Change-Id: I9b2a04b35c31bedd71fa575a6d7b9634f8282031
2021-03-13 02:49:49 +00:00
Lucas Werkmeister
293b061f29 SpecialPageFatalTest: tolerate failure to create page
Sometimes the special page can’t be created – for example, the list of
registered pages could have changed between the data provider and the
test function, due to extensions conditionally registering their special
pages. Skip the test in this case instead of crashing.

Bug: T275661
Change-Id: I573967ac22ed3a596b4f80b76d395ac948f802e8
2021-02-24 19:28:04 +01:00
Petr Pchelko
eb4e26bc03 Use Authority in special pages pagers
Change-Id: I01eccaab42759c186649d69c104318e05e91157a
2021-02-23 14:29:10 -07:00
daniel
0266b57963 Make ActorNormalization a proper service.
ActorNormalization needs to have separate wiring if we want to be able
to access it by name. This is needed to allow access to the service in
declarative wiring, e.g. via ObjectFactory specs.

As an aside, this changes SpecialPageFatalTest to not construct special
pages in a data provider. Accessing services in data providers should be
avoided. This change does not eliminate all such access, but reduces it
by deferring service lookups via ObjectFactory.

Change-Id: I5792cdcc0e5b0d1681f55dbe3e1f70c34a0cb775
2021-02-22 11:58:46 +01:00
Ammar Abdulhamid
308e6c66e1 Use generator in SpecialPageFatalTest
Slightly more performant and took less time to complete

Change-Id: I661057aa1850ecc736253ebb61e00f0199a04f59
2020-11-21 19:45:28 +01:00
addshore
959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
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
2020-06-30 17:02:22 +01:00
Thiemo Kreuz
5f3a92385b Fix visibility of setUp/tearDown
Change-Id: I636be48eb9f713680abac35d46091f7b49374696
2020-06-16 21:02:05 +02:00
Thiemo Kreuz
9cc1cd36c0 Fix SpecialPageFatalTest failing on unrelated deprecations
Bug: T236809
Change-Id: Ibf8175c957a51befe4c4853814502bccb5d17991
2020-05-29 08:17:38 +02:00
Timo Tijhof
fffc34a52a phpunit: Acknowledge known dberror from SpecialPageFatalTest
This is specifically for fatal errors, so it's fine that some
queries encounter (non-fatal) errors. Surpress them for now,
so that we can safely re-enable enforcement for everything else.

Bug: T248191
Change-Id: I962ee2dbb0568cc869fda6fa7312edc45ba43215
2020-05-18 22:41:31 +01:00
Amir Sarabadani
16b82d0ef0 Run SpecialPageFatalTest with lang=qqx
SpecialPageFatalTest:testSpecialPageDoesNotFatal is one of the slowest
tests (specially running Special:Version) due to the fact that it needs
to translate so many message keys.

3206ms to run SpecialPageFatalTest:testSpecialPageDoesNotFatal with data set "Version"

Running with lang=qqx would ensure that the special doesn't fatal but also avoid
unnecessary message translations

Change-Id: I8ff715ac539e93915c98f7209523df1b3ea3a7e8
2019-07-08 14:52:06 +02:00
Gergő Tisza
45d4e8d13a Exempt structure tests from @covers checks
@covers does not make any sense for structure tests, which either
do not cover any PHP lines (they test things like configuration or
messages), or cover lines which cannot be determined at the time
of writing the tests (e.g. they cover all classes implementing a
certain interface). Requiring @coversNothing to be manually added
for all of them is a waste of developer time.

tests/phpunit/suite.xml has forceCoversAnnotation=true so removing
the annotations will not change test coverage, these files will
still be skipped.

Change-Id: I27cb58e92341b9b1a76f109701f5bc843adbaa9b
2019-06-11 21:40:14 +00:00
Umherirrender
7d7820fb4a Relax SpecialPageFatalTest about deprecation notices
Deprecation notice from SpecialPageFatalTest is the most merge blocker
since merge of I8fb26380724b6b12bf08458dbff2e00b759d219b
Deprecation can occur at any time and than break many extensions to
merge, even there are still working.
Ignore deprecation as before, but keep the error and notices

Change-Id: Idcbc38b662c569fbe8e778a6b1ab815db332dc08
2019-04-19 20:18:22 +02:00
Umherirrender
4743ab9efc Do not suppress php notices in SpecialPageFatalTest
When the php notice is converted to exception,
it is also from type Exception and currently ignored.
Catch the special phpunit exception type separated and rethrow.

This changed is in a structure test and can break other exceptions.

Change-Id: I8fb26380724b6b12bf08458dbff2e00b759d219b
2019-02-19 21:20:59 +01:00
Umherirrender
d28f315d24 Add @coversNothing for left over tests and enable sniff
LessFileCompilationTest is checking less files for valid syntax
doc test is checking xml file for valid syntax
MediaWikiTest is testing a complex situation with many functions involved
SideBarTest is self checking, needs no coverage
structure tests not covers functions, there are covers global structures

Change-Id: I3ac65db561cae0be8418aa9c830e7a9f46ad11fe
2019-02-02 21:53:40 -08:00
Tim Starling
5322107191 Reset services before every test
Trying to avoid resetting services introduces a lot of complexity and
several bugs. We were doing a reset for 70% of @group Database tests
anyway.

Instead:

* Reset services at the start of MediaWikiTestCase::run().
* Capture the actual original service container instead of making a
  special shared service container.
* The test-isolated local service container can now only be initialised
  non-statically. Revert the recent conversion of overrideMwServices()
  to static.
* Store a reference to the local service container in the test case
  object. In MediaWikiTestCase, always use the original or local service
  container directly, to avoid confusion about which one is active at
  the time.
* Remove a lot of unnecessary teardown
* Always call ServiceContainer::destroy() before forceGlobalInstance()
  since the memory is not otherwise freed.

Change-Id: I4a17c1c7ec92c14e3bc471f0216473ebe19477b9
2018-09-03 16:38:58 +00:00
Aryeh Gregor
e68fdb4065 Mass conversion to SpecialPageFactory service
Change-Id: Ia6e1e819ec6cbe8bf75b820109f51d47863e31fc
2018-08-17 12:03:12 -07:00
Aryeh Gregor
d4045035b0 Make SpecialPageFactory a service
Calling SpecialPageFactory methods statically is now soft-deprecated.

SpecialPageFactory::resetList() is a no-op, and I changed tests
in core to use overrideMwServices() instead.

Methods that fell back to $wgUser now require a User object being passed.

Depends-On: Ie1f80315871085b9fd4763a265b588849d94414d
Change-Id: Id8a92d57743f790b7d8c377c033cef38d1bb24de
2018-08-17 11:12:23 -07:00
addshore
b50c8848e6 Introduce SpecialPageFatalTest
This test makes sure that special pages do not fatal
in their most basic form (anon user viewing the page).

Depends-On: I3a9f5b315eb114cb12ea4071f8da9079f797fcf6
Change-Id: Ic675e92d8dd8f11fa67914d2ce1dc00a379106ca
2018-07-31 07:11:48 +00:00