Commit graph

156 commits

Author SHA1 Message Date
Alexander Vorwerk
bf56204a44 Remove the MediaWikiTestCase class alias
Bug: T293043
Depends-On: I53852a255ceeab8083d0f5354949929df6c55b96
Change-Id: I477c0dfcb7bbb53a9972ce6b48acb470118c1ace
2021-12-05 13:50:40 +00:00
jenkins-bot
683495458e Merge "MediaWikiIntegrationTestCase::getExistingTestPage: Don't assume NS0 is wikitext" 2021-09-16 20:34:55 +00:00
DannyS712
a2b20b63d7 Emit deprecation warnings reading from $wgUser
With this patch deprecation warnings will be emitted
if $wgUser is accessed or written into. The only pattern
of usage still allowed is

$oldUser = $wgUser;
$wgUser = $newUser;
// Do something
$wgUser = $oldUser;

Once there is no deprecation warnings, we know that nothing
legitimately depends on $wgUser being set, so we can safely
remove the code that's still allowed as well.

Bug: T267861
Change-Id: Ia1c42b3a32acd0e2bb9b0e93f1dc3c82640dcb22
2021-09-15 20:17:04 -07:00
James D. Forrester
f4eef180a0 MediaWikiIntegrationTestCase::getExistingTestPage: Don't assume NS0 is wikitext
Found in the WikiLambda extension following the landing of 2b24f6d20.

Change-Id: I19aa4c9833e3659325977beac7d790045da73df1
2021-09-13 09:48:55 -07:00
James D. Forrester
eeaec4ce6b ExternalStoreDB: Rename getMaster to getPrimary
Bug: T282894
Change-Id: I6d6361a0b84f7130a27df6a6c75a983c73e5dd95
2021-09-03 13:44:04 -07:00
Tim Starling
0fc428c803 Make IResultWrapper extend Countable
Provide ResultWrapper::count() as an alias for numRows(), and implement
Countable, so that you can do count($res).

Change-Id: Id9909f7143dae623b318b2fb24205c3e58a7d178
2021-08-30 14:19:45 +10:00
Fomafix
c7ebc1ec44 Fix various typos in documentation
Bug: T201491
Change-Id: I144c120cc88bda723c8608ed7fb0ccb709f295f1
2021-08-23 09:03:44 +00:00
Petr Pchelko
dc321179c9 Utility in MWIntegrationTest to skip is extension not loaded
For testing extensions that optionally depend on other
extensions this is rather useful.

Change-Id: Id996abdb353547b95d795494ba961b9a215ef2ef
2021-08-13 18:39:31 +00:00
Petr Pchelko
39c6c5e34c Tests: reset ParserOptions static cache with MW services
ParserOptions store the result of ParserOptionsRegister
hook execution in a static cache. If we register a lazy
option, which depends on user options and use OptionsLookup,
tests break because a lookup from a destroyed service container
ends up being reused between tests.

The reset was added to resetLegacyGlobals because 1) it's
called at all the right times 2) this static cache is legacy,
when we have a factory service for ParserOptions, this will
not be needed anymore.

Change-Id: I9e820045443be1df2c89e1ed4b56f0d55662c486
2021-08-10 09:11:19 -07:00
Petr Pchelko
0484ac9e7a Remove deprecated Language::$mLangObjCache
Removing this deprecated cache allows LanguageFactory
to start using MapCacheLRU instead of implementing
LRU semantics manually.

Change-Id: I8093067fb6f51110351b8592fcbcfa7559d942ee
2021-07-26 06:28:18 -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
James D. Forrester
719cf161f2 More master -> primary documentation and internal var renaming
Bug: T254646
Change-Id: I63cc8895033714bdfbf09aee933a8f0a43b387f3
2021-07-15 11:20:20 +01:00
DannyS712
b0ab985420 Fix some @stable for ... annotations to use @stable to ...
Bug: T257789
Change-Id: I3ba94a9d6b739cd57cd57afe5d397963127160a8
2021-07-08 02:54:59 +00:00
DannyS712
b45ddb2ab3 Use WikiPage::doUserEditContent() instead of ::doEditContent()
Results in passing a user where previously the fallback
to $wgUser was being used, mostly in tests.

Bug: T255507
Change-Id: Iabe24315b23c0ad1272353186425e71974528d23
2021-06-28 00:11:30 -07:00
Alexander Vorwerk
e77ebc1854 Remove AuthManager::$instance and ::resetCache()
AuthManager has been converted to a service in 1.35.
AuthManager::$instance is only used in AuthManager::resetCache(),
where it is set to null.

This patch also removes AuthManager::resetCache() because with
removing AuthManager::$instance AuthManager::resetCache() has no
longer any effect.

Change-Id: I8b27f9a2d0d3f7acec6b93f64f9c256084990026
2021-06-20 14:55:10 +02:00
daniel
ddc3f55a5a phpunit: Remove the PHPUNIT_REUSE_DB / --reuse-db option
This option has been dysfunctional since at least MW 1.32: with
the option set, no tables would be cloned, and all tests trying to
access the database would fail.

Apparently the option was originally introduced to improve speed
when testing against a Oracle database backend in
5933586266.

Since nobody complained about the option being broken,
and we no longer support Oracle, it should just be removed.

Bug: T283146
Change-Id: I7d7f10b2c863ab92279c7817893086ad50e6ac4d
2021-05-19 12:19:59 -07:00
DannyS712
2ed29c04fc Remove MediaWikiIntegrationTestCase::formatErrorLevel, private and unused
Use was removed in I7dc3fe90385c8066b89a5e06c55f5455edfbb4ca
when the logic that was using it was moved to MediaWikiTestCaseTrait

Change-Id: I3be7fdb0ad3e76d0f0bff713c21cb9216b77ee20
2021-05-12 21:04:43 +00:00
Petr Pchelko
7136d671d2 Replace User::idFromName with ActorStore
Depends-On: I87fdac02a88aba52a2174949f8736a9a36d3edf7
Depends-On: I812c49009665515778cd354d6c62a17ee24f3625
Change-Id: I5369e9714a3ec653c19ad81f02402e4aa1b22553
2021-05-11 07:44:38 -07:00
jenkins-bot
b2480a7efe Merge "Add a JobQueueGroupFactory service" 2021-05-10 18:59:51 +00:00
Ammarpad
d90bff177f IntegrationTestCase: Fix incomplete error message
Change-Id: Id5bee445b67cf5339b0e3d7bb4376fb114312a06
2021-05-10 15:34:55 +01:00
mainframe98
ae55be3000 Add a JobQueueGroupFactory service
This replaces JobQueueGroup::singleton and ::destroySingletons.
A JobQueueGroup service has been added to serve as convenience
getter.

Bug: T277648
Change-Id: Ic8709119773ab788a07531193dc65d418536eda2
2021-05-07 06:50:29 +00:00
Tim Starling
9a6dcfb4e5 Run tests with ONLY_FULL_GROUP_BY
Have MySQL emulate PostgreSQL's standards-compliant GROUP BY
nitpicking, so that MySQL developers can tell whether queries would fail
on PostgreSQL.

Bug: T281329
Change-Id: Ia9e6c6ad3286dd37f7efb55045e8556d85791c37
2021-05-07 00:48:31 +00:00
jenkins-bot
5127fe1b43 Merge "Add MediaWikiIntegrationTestCase::runJobs() and use it" 2021-05-05 03:15:17 +00:00
Tim Starling
0e05879d7e Add MediaWikiIntegrationTestCase::runJobs() and use it
JobRunner catches all exceptions and hides them in the status array,
meaning that it is not obvious when a job fails during a test case.
So, introduce MediaWikiIntegrationTestCase::runJobs(), which runs jobs
and asserts various things about the returned status array.

Depends-On: I4f4790c5d16a0767790eeff202e0be8fcdaeda93
Depends-On: I118f9e3f8950fd82d7b02baed6705b29fd6ab7d5
Change-Id: I63603aa158f77df4b40add096cb248f3b24979f4
2021-05-05 02:51:30 +00:00
Umherirrender
e69f56fc9b build: Remove unneeded phpcs:ignore on false positives
False positives are resolved with the current release

Change-Id: I21986ec808edb341bf56abae8ee4e34e1559bc49
2021-04-29 23:50:07 +02:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
jenkins-bot
bfb21cb176 Merge "Give WikiAwareEntityTrait it's own unit tests." 2021-04-29 12:18:37 +00:00
Petr Pchelko
ccd4b6d98b Give WikiAwareEntityTrait it's own unit tests.
Change-Id: I7f3b9e58a3d0ff4aeb1315c16d3cf91b79530095
2021-04-27 20:31:14 -07:00
jenkins-bot
ee0ebef91c Merge "Use @before/@after in MediaWikiIntegrationTestCase/MediaWikiUnitTestCase" 2021-04-28 02:36:05 +00:00
Timo Tijhof
e9051b2b99 rdbms: Move setLBFactoryTriggers from doMaintenance to service wiring
This logic is not needed to run on every PHP process and was making
it difficult to run offline maintenance scripts without additional
complexity based on Maintenance::getDbType and DB_NONE.

Instead of skipping this only for DB_NONE, and establishing a pattern
that may spread to other ad-hoc places throughout the codebase, instead
remove this entirely from the eager set up code for all PHP processes
and move it to the service wiring and dependency injection.

That way, it naturally doesn't happen until and unless the DB service
is actually called upon. Scripts and entry point that need to disable
the DB service, can continue to use
MediaWikiServices::disableStorageBackend.

== Impact on SiteStatsUpdate ==

With wgCommandLineMode no longer being read at run-time from a global,
but in service wiring, this means SiteStatsUpdateTest can't change
the behaviour between CLI-like and Web-like, unless it e.g. resets
the 'DBLoadBalancerFactory' service first. Unfortunately, while most
any reset is supported, a reset of the 'DBLoadBalancerFactory' would
be unsupported as that would lose the temporary db clone context and
such, bringing us to either the developer's live db, or a broken set
up altogether. If there is a strong need for toggling oppertunistic
updates off and on at run-time, this could be supported in the
DeferredUpdates class perhaps, but we already have numerous methods
there (incl db begin/commit being a good proxy already), which this
test already used, so for now I've just removed the extra assertion
for this as it wasn't essential to that test.

Bug: T228895
Bug: T238436
Change-Id: Icf29bc484c155f52b6d8f61e5902233a15ba0c6d
2021-04-27 23:35:20 +01:00
Umherirrender
a120f1dc87 Use @before/@after in MediaWikiIntegrationTestCase/MediaWikiUnitTestCase
Set functions to final.
This avoids that the function is overwritten without parent call

Follows-up I9d4771c28160356ff58.

Change-Id: I40cde489a892b06284692ecbbef14e650afe7c9e
2021-04-27 22:21:59 +02:00
jenkins-bot
5752dcbe0b Merge "Reset fake timestamps for unit tests too" 2021-04-14 21:45:02 +00:00
DannyS712
438b3924b4 Reset fake timestamps for unit tests too
Discovered in another patch that while integration
tests automatically reset fake timestamps afterwards,
unit tests don't. Add a shared method to MediaWikiTestCaseTrait
to reset for both integration tests and unit tests

Do the same for TypeDefTestCase

Change-Id: I677aec4e60894053fc554f2e13b069fb599858f2
2021-04-14 21:01:33 +00:00
jenkins-bot
9c74a067c3 Merge "Factor out rollback logic from WikiPage" 2021-04-14 20:22:27 +00:00
Petr Pchelko
46db19ecdf Factor out rollback logic from WikiPage
Change-Id: I95da91875fcf2f53143c315560e35ccd5ffbf4b3
2021-04-14 11:49:07 -07:00
DannyS712
ede7dc8b68 Convert DiffHistoryBlobTest to pure unit test
No integration needed, though it did rely on
checkPHPExtension which was only available in
MediaWikiIntegrationTestCase, moved to
MediaWikiTestCaseTrait

Also put under /includes/historyblob/ to match covered class

Change-Id: I0bfe3e44bd45535c18f5ee2534430330586a1c4c
2021-04-14 02:09:51 +00:00
James D. Forrester
bdddfb92ba Drop wgContLang, deprecated in 1.32
Bug: T245940
Depends-On: Ib7fe7318100c0aadc3aa759416bf787913a9b788
Change-Id: I75c3b6715abd5eaf3619337cab8b1844e9a8349a
2021-03-08 13:27:28 -06:00
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
Reedy
729f20afc8 Tests: Mark more closures as static
Bug: T274036
Change-Id: I911d3041cebe417d162934223b46ea295c6d20e3
2021-02-07 13:26:56 +01:00
Cindy Cicalese
21699acebd Allow expectDeprecation() in multiple tests in the same test suite
Without this, expectDeprecation() will not work if the same
deprecation is emitted in more than one test in the same test suite.

Change-Id: I850a072cc61437d1ab33af082ee99534bc6deee6
2021-02-02 08:32:26 -06:00
Umherirrender
7691dbeca9 Add missing @param and @return to documentation in tests
Change-Id: Ic663e81cca0bf007804a70772250914a85f1fef4
2021-01-22 19:57:25 +01:00
C. Scott Ananian
665eae14ac ParserTestRunner: share more code w/ MediaWikiIntegrationTestCase
Refactor the database setup code to share more code between
ParserTestRunner and MediaWikiIntegrationTestCase.  Made
`::setupAllTestDBs` static so it can be reused from
ParserTestRunner.

Made ParserTestRunner::addArticle more like
MediaWikiIntegrationTestCase::addCoreDBData().  Some additional
refactoring work could be done here in the future to share more code.

After the refactoring the ParserTestTables hook is no longer necessary
and so has been (soft) deprecated.  MediaWikiIntegrationTestCase
clones all database tables, so ParserTestRunner no longer needs to ask
extensions for a list of specific tables it should clone.  Cleaning up
the handful of extensions which define this hook will be left to a
future patch set.

Change-Id: I5124789fac333a664b73b4b4a1e801ecc0a618ca
2021-01-07 23:31:12 -05:00
C. Scott Ananian
6328600cdd MediaWikiIntegrationTestCase: use static:: for ::getTestSysop()/::getTestUser()
Also fix two places where we were using `$this->` in a corner case.

Using `static::` lets subclasses override these method definitions,
at least in theory.

Change-Id: I76a6d10ce463a5bc79e14051a31f469668924494
2020-12-24 09:52:54 -05:00
Daimona Eaytoy
6f7132cbcf Remove MediaWikiIntegrationTestCase::assertType
Deprecated since 1.35, not compatible with PHPUnit 8. This could've
happened earlier, but here we go.

Unused in known repos (except for the sniff looking for this usage):
https://codesearch.wmcloud.org/search/?q=assertType%5C(&i=nope&files=php&repos=

Bug: T192167
Change-Id: I479cf71d0941c35096d21686077b4d1cbc4f898d
2020-12-18 19:23:14 +00:00
jenkins-bot
02342b9065 Merge "Don't access $wgRequest from User" 2020-12-16 05:06:16 +00:00
Tim Starling
6b2a52181f Don't access $wgRequest from User
Some User methods fail if they are called before $wgRequest is
set. But according to the Setup.php comment, it is only set for b/c.
The global request object can be lazy-initialised at any time.

This is sufficient to avoid T263911 (loss/obfuscation of the $wgServer
error message).

In tests, try to keep $wgRequest and RequestContext::$request in sync.
Introduce MediaWikiIntegrationTestCase::setRequest() which sets both at
once, and use that instead of setMwGlobals() or direct assignment.

BlockManagerTest was accidentally exploiting the fact that the global
context request and $wgRequest were separate objects. Making them the
same causes session cookies to appear in the response, breaking the
cookie counts. Use a new response for the test.

Bug: T263911
Bug: T245940
Change-Id: I2be99f7251a837bc6b62be0b152038157dec10f2
2020-12-16 12:21:00 +11:00
jenkins-bot
f49e8f4f56 Merge "Clean up temp files correctly after unit tests" 2020-12-12 10:33:19 +00:00
Umherirrender
2579ca623a build: Updating mediawiki/mediawiki-codesniffer to 34.0.0
Change-Id: I2fb18ddd4c144655a665792901e59f88bcd906dc
2020-12-07 14:55:24 +01:00
Umherirrender
98de078a4c Improve callable docs
Change-Id: I4cc9b2dbe285ad935a1dfd08effa673a39167483
2020-11-13 22:55:10 +01:00
Umherirrender
21536f9af0 Clean up temp files correctly after unit tests
Change-Id: Iba4e45d8c41d678d4ec2de442c105e03cf8d87e1
2020-10-31 01:07:52 +01:00