Commit graph

37 commits

Author SHA1 Message Date
Aryeh Gregor
043d88f680 Make LocalisationCache a service
This removes Language::$dataCache without deprecation, because 1) I
don't know of a way to properly simulate it in the new paradigm, and 2)
I found no direct access to the member outside of the Language and
LanguageTest classes.

An earlier version of this patch (e4468a1d6b) had to be reverted
because of a massive slowdown on test runs. Based on some local testing,
this should fix the problem. Running all tests in languages is slowed
down by only around 20% instead of a factor of five, and memory usage is
actually reduced greatly (~350 MB -> ~200 MB). The slowdown is still not
great, but I assume it's par for the course for converting things to
services and is acceptable. If not, I can try to optimize further.

Bug: T231220
Bug: T231198
Bug: T231200
Bug: T201405
Change-Id: Ieadbd820379a006d8ad2d2e4a1e96241e172ec5a
2019-10-07 13:18:47 -07:00
Max Semenik
fb06e4cd85 Update tests to use PHPUnit 6 class names
Bug: T192167
Change-Id: I42b0c8908b4968b95b08f861a40af18dc79fa0a1
2019-10-06 01:01:28 -07:00
Max Semenik
dc3fba4619 tests: Nuke everything HHVM-related
Change-Id: Ieccce5ebba25132b2433fc13a575b65a5bd538f2
2019-10-05 12:51:07 -07:00
daniel
387bd38287 MWTestCase: include table prefix in domain for temp table only mode.
This patch allows PageUpdaterTest and DerivedPageDataUpdaterTest to
function properly. Without this patch, the fail when run by themselves.

See phab ticket for analysis.

Bug: T234031
Change-Id: I0804b503bc8b860343a5141c0bfb25fe6855c87d
2019-09-27 13:10:22 +02:00
jenkins-bot
a99171228d Merge "Refactor MediaWikiIntegrationTestCase::resetDB() for readability" 2019-09-20 12:05:18 +00:00
Thiemo Kreuz
3709096126 Refactor MediaWikiIntegrationTestCase::resetDB() for readability
This was inspired by I1b2a6eb. As far as I can tell this patch does not
change anything in terms of behavior. My main motivation was to get rid
of the (possibly confusing) duplications, and turn them into a loop.

The special case where TestUserRegistry::clear() is executed appears like
it might not do the exact same as before, but I'm pretty sure it does.
Before, the special case was executed whenever any of the user tables was
present in the $tablesUsed array originally passed to the method. The
same still happens.

Additional changes:
* Strict type hints in the method signature.

Change-Id: I7f292095c0dac99b9cc0b0aa5ce10703f24f8bba
2019-09-19 15:39:55 +00:00
David Causse
b3b95c3927 Add assertFileContains to MediaWikiTestCaseTrait
Used by CirrusSearch unit tests.

Change-Id: I1b67a9cddfca7fa06fb0b916981d1efde0764018
2019-09-17 17:24:33 +02:00
Adam Wight
1c5d140761 Reset all logging tables together
For example, leftover cruft in `log_search` will cause spurious
associated_rev links between unrelated revisions and log entries.

Bug: T227849
Change-Id: Ie344522229e4142f2c61a267b4d693051b813236
2019-09-13 13:03:07 +02:00
Lucas Werkmeister
74fbb2c5c4 Improve MediaWikiIntegrationTestCase::resetDB()
Test the intersection of $tablesUsed with each set of tables
separately and only update it afterwards.  Without this fix, overlaps
between the table groups would cause additional groups to be pulled in
unnecessarily.

Change-Id: I1b2a6eb47e061dee8a27fb4779809b4684c05104
2019-09-13 13:01:41 +02:00
Adam Wight
4d02bdf897 Rollback change_tag table for tests
When a change tag row is written during a test, it links to content IDs which
may be reused in future tests.  To maintain test isolation, we should include
this table in the rollback for any tests that touch pages.

Bug: T227849
Change-Id: I98fe17e209f6c685ad87e52886a3526f35645d1e
2019-09-05 16:07:06 +02:00
jenkins-bot
a9fb2b3b06 Merge "FileJournal tests" 2019-09-03 11:22:00 +00:00
Aryeh Gregor
5bbcaef231 FileJournal tests
100% unit test coverage for FileJournal and NullFileJournal. 100%
integration test coverage for DBFileJournal. Unit tests for
DBFileJournal once it supports injection.

I removed FileJournal and NullFileJournal from the list of classes that
FileBackendTest tests. It doesn't actually test them, it just happens to
run code from them without checking its correctness at all.

Depends-On: Ic22075bb5e81b7c2c4c1b8647547aa55306a10a7
Change-Id: I46d10ab7b87c23937aa04d7ec1922abfcf3bd611
2019-09-03 10:12:41 +00:00
jenkins-bot
72fa557f45 Merge "Correctly format null error reporting level" 2019-09-02 16:54:48 +00:00
jenkins-bot
97905cc790 Merge "Revert "Reset $wgContLang consistently for tests"" 2019-09-02 11:28:10 +00:00
Ladsgroup
ab0dfd181a Revert "Reset $wgContLang consistently for tests"
This reverts commit 09407afd74.
Reason for revert: It broke Wikibase on master.

Bug: T231799
Change-Id: Ie347abb24183ce3000af4d653ce2343ec7a63290
2019-09-02 11:03:18 +00:00
jenkins-bot
7dd780846c Merge "phpunit: Add more info to LocalSettings.php error in MediaWikiIntegrationTestCase" 2019-09-02 08:55:51 +00:00
Aryeh Gregor
09407afd74 Reset $wgContLang consistently for tests
We already reset $wgParser to a stub in a number of places where it
might have changed. Let's give $wgContLang the same treatment so we can
avoid special-case code.

This deprecates setContentLang(), which is no longer needed. The magic
of $wgContLang is now handled by setMwGlobals() and setService().

This is a follow-up to e4f69ee, which fixed one case of this problem.

Change-Id: I90925ef8b2a7478cce90d474db1b8b4539e45c15
2019-09-01 23:09:26 +00:00
Timo Tijhof
eccceb8f1d phpunit: Add more info to LocalSettings.php error in MediaWikiIntegrationTestCase
Change-Id: I3df68aab40f4b0bb1d5134330347d77ed3399f02
2019-09-01 21:29:02 +00:00
Lucas Werkmeister
e4f69ee33e Also set $wgContLang in MWITC::setContentLang()
This assignment got lost in change Ie7a89f6ed7 (commit 47464abb4f) – the
resetServices() now implicit in setMwGlobals() resets the
ContentLanguage service, but does not update the $wgContLang global.
setService( 'ContentLanguage' ) does update it, but that method is
deliberately not used in this branch of setContentLang(), for reasons
that I assume are still relevant even though the comment explaining them
was removed – see change I8c60e37c17 (commit c70c2e4714).

Bug: T231630
Change-Id: I0170cc6bf40a5524523c45e8ffff8f72adc2fc47
2019-08-30 14:35:49 +02:00
Aryeh Gregor
4802a26be1 Correctly format null error reporting level
Previously you could sometimes get the mysterious error "PHP
error_reporting setting was left dirty: was 0x0 before test, 0x0 after
test!"

Change-Id: I425a694f9c2c71d917012ab9fb1780b5c2133ff4
2019-08-30 11:22:02 +03:00
Aryeh Gregor
47464abb4f Call resetServices() when setting globals in tests
Now that resetServices() will preserve (but reset) customized services,
it should be reasonably safe to call it every time globals are changed,
and much more effective than relying on tests to call it every time
themselves.

Depends-On: Iab8ea3a61bbc6803805d855ef23c071067646f71
Depends-On: I00e35ecea6a27468674b2a6e7d9d9eb6518e3bd5
Change-Id: Ie7a89f6ed7d52a0bc01672019ff92e7ee105a1f3
2019-08-29 14:26:13 +03:00
Amir Sarabadani
308e6427ae Revert "Make LocalisationCache a service"
This reverts commits:
 - 76a940350d
 - b78b8804d0
 - 2e52f48c2e
 - e4468a1d6b

Bug: T231200
Bug: T231198
Change-Id: I1a7e46a979ae5c9c8130dd3927f6663a216ba753
2019-08-26 18:28:26 +02:00
jenkins-bot
358348d9bf Merge "rdbms: add setTempTablesOnlyMode() to suppress CONN_TRX_AUTOCOMMIT during tests" 2019-08-25 15:02:48 +00:00
Aryeh Gregor
e4468a1d6b Make LocalisationCache a service
This removes Language::$dataCache without deprecation, because 1) I
don't know of a way to properly simulate it in the new paradigm, and 2)
I found no direct access to the member outside of the Language and
LanguageTest classes.

Change-Id: Iaa86c48e7434f081a53f5bae8723c37c5a34f503
2019-08-22 14:25:18 +03:00
Aryeh Gregor
5e2199c5b0 BadFileLookup to replace wfIsBadImage
I think this probably shouldn't be directly in the MediaWiki namespace,
but I don't know where is a better place to put it.

In order to avoid gratuitous use of TitleFormatter, I changed the cache
format -- the old implementation used getPrefixedDBkey() and I switched
to an ns/dbkey pair. I also changed the cache keys to use SHA1 instead
of MD5, by Daniel's request.

The previous implementation cached the parsed blacklist for one minute
without invalidation, so it could return slightly stale results, but it
didn't retrieve the bad image list message on a cache hit. The new
implementation unconditionally retrieves the bad image list message, but
uses a hash of it in the cache key and caches for one day. The new
behavior happens to be more cleanly implementable in a service.

Bug: T200882
Bug: T139216
Change-Id: I69fed1b1f3cfc1aa149e0739780e67f6de01609d
2019-08-21 20:45:37 +03:00
Aaron Schulz
0b8a4daaa4 rdbms: add setTempTablesOnlyMode() to suppress CONN_TRX_AUTOCOMMIT during tests
Bug: T202116
Change-Id: Ib3e80eb04580b2d5a75ede8fb5546409c09a751a
2019-08-19 18:47:21 -04:00
Aryeh Gregor
8a8f23ddc6 Add a bunch of MovePage tests
The expected values in many cases are silly, because our code is
currently silly and could use some refactoring. These are marked with
@todo. In one case the return value is even wrong (moving to an invalid
non-empty name is considered valid).

Change-Id: I9649a4de12bbcd6263c85de37d7b9365d9c0aeb4
2019-08-19 20:26:02 +03:00
DannyS712
6dd07c38bf Fix doc for MediaWikiIntegrationTestCase::getTestSysop
Bug: T230670
Change-Id: Icd57ef2f6268d362a0912931911c46f93165d4ff
2019-08-18 11:53:49 +00:00
jenkins-bot
3d1c78c5f8 Merge "More clean up of oracle/mssql" 2019-08-14 19:25:12 +00:00
Amir Sarabadani
807d793ab9 More clean up of oracle/mssql
Bug: T230418
Change-Id: I1ff01548e55f01f9419668e31d5aa7dd03d23258
2019-08-14 17:04:50 +02:00
Aryeh Gregor
3458e332da Clear test user registry between tests
Otherwise User members will wind up retaining stale references to
services. The more things move to services, the more state we need to
reset between tests to avoid subtle and confusing test failures!

TestUsers can't be created if the DB prefix is not either unittest_ or
ut_, which caused failures in RCFeedIntegrationTest.php with this change
now that it was trying to create a new TestUser. Fix is to set the
prefix to one of those two instead of empty.

Change-Id: I41f87e1acffe94361748ef4ab69c290de587e6be
2019-08-14 10:27:21 +03:00
Kosta Harlan
36c6b6d536 Tests: Assert that integration tests are not in unit test directory
Bug: T87781
Change-Id: If82efb1829095a6cf76435921f1328801508a70a
2019-07-10 13:41:44 -04:00
Kosta Harlan
822efb467d Assert that LocalSettings file exists
This time, use $IP to get correct path to LocalSettings so that tests can be run
from outside MediaWiki root.

Change-Id: I0dd3dd281cff67b0d8acdc09b97328c44eca2bb6
Follows-Up: Ia36d22217f94e019bb5945705243bd0daace72e0
Bug: T226977
2019-07-02 11:57:00 -04:00
Amir Sarabadani
6568edb9e2 Drop the check for existences of LocalSettings.php in MediaWikiIntegrationTestCase
This is not needed and we should let testers run integration tests without
the need to define LocalSettings.php

This reverts small part of Ie717b0ecf4fcfd089d46248f14853c80b7ef4a76

Bug: T226977
Change-Id: Ia36d22217f94e019bb5945705243bd0daace72e0
2019-07-01 17:15:35 +02:00
Máté Szabó
344481f60d Move trivially compatible tests to the unit tests suite
This changeset resumes work on T89432 and related tickets
by porting an initial set of tests to the new unit test suite
separated out in I69b92db3e70093570e05cc0a64c7780a278b321a.
The tests were only ported if they worked immediately without
requiring any changes other than changing the test case class
to MediaWikiUnitTestCase and moving the test to the new suite.
If a test failed for any reason (even trivial misconfiguration),
it was NOT ported.

With this change, the unit tests suite now consits of a total
of 455 tests. As before, you can run these tests via the following
command:
$ composer phpunit:unit

Bug: T84948
Bug: T89432
Bug: T87781
Change-Id: Ibb8175981092d7f41864e641cc3c118af70a5c76
2019-06-30 15:23:53 +02:00
Vedmaka
dd6b94024c Re-apply: Factors out permissions check from User into PermissionManager service
Was reverted by I549810a4cd2e424cc4a438887d2f24614a24cc00 due to
T224607.

Original change by  Vedmaka Wakalaka was
Ia0d840b772ea5f20c9594ce151cc57adc270e48b.

Original commit message:

The following methods should are factored out of the User class into PermissionManager,
leaving only deprecated stubs:

- User::isAllowed -> PermissionManager::userHasRight
- User::getRights -> PermissionManager::getUserPermissions
- User::groupHasPermission -> PermissionManager::groupHasPermission
- User::getGroupPermissions -> PermissionManager::getGroupPermissions
 -User::getGroupsWithPermission -> PermissionManager::getGroupsWithPermission
- User::groupHasPermission -> PermissionManager::groupHasPermission
- User::isEveryoneAllowed -> PermissionManager::isEveryoneAllowed
- User::getAllRights -> PermissionManager::getAllPermissions

Depends-On: I7909e9bd6bbfbd708c0a00b861a9b22a38c6665d

Bug: T218558
Bug: T223294
Change-Id: I8899240378f636ea70f447616710516c0a3c5c31
2019-06-28 13:19:38 -07:00
Kosta Harlan
214750d8d2 Define unit and integration test suites
Following discussion in Ibb8175981092d7f41864e641cc3c118af70a5c76, this patch
proposes to further reduce the scope of what unit tests may access, by removing
the loading of DefaultSettings and GlobalFunctions.php. This also has the
implied effect of disabling the storage backend, as well as the global service
locator.

MediaWikiTestCase is renamed to MediaWikiIntegrationTestCase so it's scope and
purpose is more clear. Whether we still need to keep `@group Database`
annotation around is debatable, as it's unclear to me what the performance costs
are of implying database access for all tests which extend IntegrationTestCase.
As far as I can tell, `@group Database` is primarily used in CI to run faster
tests before slower ones, and with the new UnitTestCase the annotation seems
redundant.

To run all testsuites, use `composer phpunit`. Other composer scripts:

- `composer phpunit:unit` to run unit tests
- `composer phpunit:integration` to run integration tests
- `composer phpunit:coverage` to generate code coverage reports from unit
   tests (requires XDebug).

Note that you can pass arguments to composer scripts with `--`, e.g. `composer
phpunit:integration --exclude-group Dump`.

Other changes:

- Rename bootstrap.php to bootstrap.maintenance.php so it's clear it's part of
  the legacy PHPUnit-as-maintenance-class setup
- Create new bootstrap.php which loads the minimal configuration necessary for
  the tests, and do additional setup in the run() method of the unit/integration
	test case classes
- Move the unit-tests.xml file to phpunit.xml.dist in preparation for this being
  the default test configuration

For a follow-up patch:

- Find unit/integration tests for extensions/skins
- Migrate other test suites from suite.xml
- Support running all tests via vendor/bin/phpunit

Bug: T84948
Bug: T89432
Bug: T87781
Change-Id: Ie717b0ecf4fcfd089d46248f14853c80b7ef4a76
2019-06-28 12:18:18 -04:00
Renamed from tests/phpunit/MediaWikiTestCase.php (Browse further)