Commit graph

309 commits

Author SHA1 Message Date
Kunal Mehta
a4e8bea57d tests: Add helper function for ini_set with automatic cleanup
Some tests need to change the value of an ini setting, and typically implement
cleanup handling themselves, usually imperfectly.

Provide a helper function, $this->setIniSetting(), which will take care of
teardown in the same way that $this->setMwGlobals() does.

Change-Id: I7be4198592f0aaf73a28d3c60acb307a918b1a1f
2018-10-10 22:31:37 -07:00
Aryeh Gregor
09eee138e1 Deprecate MediaWikiTestCase::stashMwGlobals
This method encourages directly editing configuration variables.  It's a
better idea to use setMwGlobals() (or other set wrappers) so that we can
be intelligent in the future, for instance resetting services after the
config change.  Plus, a lot of the callers come out cleaner this way
anyway.

Depends-On: I8a1e81acc5c42a8d7f30938a72cface0acea4a70
Depends-On: I4105dbcf9c5399fe7239478c460ec57c015a98d4
Depends-On: I1b220996acf2f66cf7b0f092b341584663df32f9
Depends-On: Ie2d1ea65c0cb334bbde1666d00781474b7ac4dab
Change-Id: I23d77398e401f4986b1d5bd1c9e11a8a40da16f8
2018-10-07 19:39:47 +03:00
jenkins-bot
69ad33b0c2 Merge "Disallow overriding services that were set" 2018-10-04 16:20:25 +00:00
Aryeh Gregor
b93b18d98a tests: Allow string to be passed to getTestUser() etc.
If there's only one group, let's not require the brackets.

Change-Id: Ib46ef1facbbbf2ba01c13b8290ebbe3a8e08cb4f
2018-10-04 15:30:47 +00:00
Aryeh Gregor
c70c2e4714 Disallow overriding services that were set
Otherwise setService() calls (including indirect, like via
setContentLang() ) will be silently overridden.  This bit me several
times already while working on tests.  If someone actually wants to do
this, they should probably split their test in two, because it evidently
has two separate phases that they're testing (with/without services
set).

Depends-On: I9acb81c0de95eb5a6bed543d757ae62523ea6041
Change-Id: I8c60e37c179320e61684cbc11281c509e525e8fb
2018-10-02 17:41:03 +03:00
C. Scott Ananian
8025629395 Ensure disabled deprecation warnings are re-enabled before next test
Tests should not interfere with each other; disabled deprecation
warnings should be disabled for a single test case only.

Bug: T191960
Change-Id: Ic9b892bc83ba6d71c1077df0d93c95dde36988bb
2018-09-25 16:30:38 +00:00
Umherirrender
4da52463e3 Ensure database is setup in MediaWikiTestCase::insertPage
Also in editPage
Add missing @group Database

Depends-On: Id81425fff0a41c651c1967698124246befcdb032
Depends-On: If97d9e6e525465ca3879003e71dd5e67fc0afdfd
Change-Id: I3bfd478769e0907913834c9639af4375223638cc
2018-09-14 22:32:23 +02:00
jenkins-bot
66351c7f1b Merge "Remove unused MediaWikiTestCase::prepareConnectionForTesting" 2018-09-13 09:40:18 +00:00
daniel
c472b7ca50 Reset services in ParserTestTopLevelSuite.
This is intended to isolate parser tests from other tests
by resetting the service locator between test runs, just like
MediaWikiTestCase does.

NOTE: this has no effect on parser tests run via parserTest.php,
it's only for tests run via PHPUnit.

Bug: T204065
Bug: T204072
Change-Id: I772b3b4a2d4d98948a249603b1cdb0933427b01c
2018-09-12 19:51:28 +02:00
addshore
46d7645db2 Remove unused MediaWikiTestCase::prepareConnectionForTesting
This method is redundant to setupDatabaseWithTestPrefix.

Change-Id: Ic6baa13c51948a3ea838fe827acea58dc740bafc
2018-09-12 13:42:01 +00:00
addshore
42312dd466 tests: Throw when tests run that "need a db" but miss Database group
Depends-On: I5cfea2dc4e56ed4639126e35c0f8aa370852f056
Depends-On: Ic472eb073290793c432812ae8b47ab2b41e74a26
Change-Id: I4cdc8130032340726c5d18d795cd2d6b6b58b307
2018-09-11 19:04:05 +00:00
jenkins-bot
df76e044f5 Merge "Pass delimiter to preg_quote" 2018-09-10 23:55:19 +00:00
jenkins-bot
7f6bd0c6fe Merge "Make assertFileContains not create files by default" 2018-09-07 07:33:47 +00:00
Stanislav Malyshev
fc202943ab Make assertFileContains not create files by default
This makes us miss test bugs like one in
https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Wikibase/+/458305

Change-Id: I2a96ed180be216aa615d8506999aa75f04c267bf
Depends-On: Ic85db75c2dba6c1c1fa6fd74dbea64f213609c0d
2018-09-05 22:21:12 +00:00
jenkins-bot
ab8648532d Merge "Make phpunit.php less hackish, and install the listener unconditionally" 2018-09-05 04:32:49 +00:00
Tim Starling
65adc37348 Make phpunit.php less hackish, and install the listener unconditionally
* Instead of rewriting $argv, add a Command subclass called
  MediaWikiPHPUnitCommand which overrides the configuration using the
  stub functions in Command which were provided for that purpose.
* Revert c804a0b5b9, which added redundant debug output to tests,
  and instead install the MediaWikiPHPUnitTestListener listener
  unconditionally. Deprecate and make non-functional the --debug-tests
  option. If you don't want tests to produce debug output, you can
  always turn the channel off.
* Because I added our listener to the listener array instead of making
  it override the printer, it's no longer necessary to derive from
  PHPUnit\TextUI\ResultPrinter. Instead we derive from BaseTestListener.
  So we don't need to call the (empty) parent methods.
* Remove the --with-phpunitclass feature since it doesn't work with this
  scheme.
* Instead of passing CLI args to MediaWikiTestCase via a public static
  variable, inject it non-statically by overriding the TestRunner and
  TestResult.
* Remove --file, which has been non-functional since my 2016 refactor.

Change-Id: Ibcaf9ca81c8dc63cce6dc6f6fb1fffee19f8804e
2018-09-04 15:30:20 +10:00
Tim Starling
0ecfe75502 Introduce NameTableStoreFactory
With a separate service for each of the NameTableStore tables, it
wasn't possible to instantiate a NameTableStore for a foreign wiki,
leading to the inelegant situation of having RevisionStoreFactory
construct a new NameTableStoreFactory every time a RevisionStore for a
foreign wiki was requested. These NameTableStore objects were not
tracked in any structured way, so there was no way to reset them for
tests.

So, introduce NameTableStoreFactory, which tracks object instances for
both local and remote table access.

This also avoids having schema details in ServiceWiring.php.

Depends-On: I5c78cfb8bf90eca935a3264592366f63517c4fad
Bug: T202641
Change-Id: Ic0f2d1d94bad9dcc047ff19a1f92db89b7e014ce
2018-09-04 15:08:38 +10:00
Tim Starling
ef88b9aa33 Don't save and restore the interwiki table
In fact it always has zero rows. Well, at least it does until
ApiQuerySiteinfoTest::testInterwikiMap() inserts two rows without using
@group Database, and then it has two rows from then on. It's meant to
have zero rows.

This saves time and memory.

Revert of f17feae3a9

Change-Id: Ibdb12ff941d2cb47143bdff176072ef9078fa0f7
2018-09-03 21:26:06 -07: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
Umherirrender
acb2e720d8 Pass delimiter to preg_quote
This ensure that the regex is escaped correctly,
even when the quoted value never contains the delimiter

Change-Id: I2dc93fa0154d4506c276a30cab008bc2ac5e0687
2018-09-01 14:52:16 +02:00
Tim Starling
c804a0b5b9 Improve logging in MediaWikiTestCase
Log test setup, start and end to the tests-phpunit log channel. This
helps when interpreting debug logs. The channel name was chosen by
analogy with the existing tests-parser log channel.

Change-Id: I2bc87564247f2f136b2244d426fa127d21663f92
2018-08-28 15:41:08 +10:00
daniel
2c7e4adcea Don't reset name tables between test runs.
Resetting the content_model and slot_role tables between test runs
requires the corresponding NameTabelStore instances to be reset
as well. We may however have many of them, buried in various services.
There is no easy way to reset them consistently.

Letting information in these tables persist between tests seems
harmless. Tests that need these tables reset can simply add them
to the tablesUsed array.

This is needed for unit tests to work with the new MCR schema.

Bug: T198561
Change-Id: I63e61e1ab74e00c20930a83d3a3f5df53092a197
2018-08-23 19:15:33 +02:00
jenkins-bot
532b15c800 Merge "Make SpecialPageFactory a service" 2018-08-17 18:53:27 +00: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
petarpetkovic
39e5d8d843 Fix spelling of word "necessary"
Bug: T201491
Change-Id: Ic983889a5702b8b8552c88ebc4d676f35e9fe61e
2018-08-16 01:35:35 +02:00
jenkins-bot
eb5fe55cd5 Merge "Fix reset interwiki table between tests" 2018-08-14 23:17:37 +00:00
Pwirth
bf28911864 Fix reset interwiki table between tests
This fixes the following SQL error, when the interwikilinks table was
marked as used:
Fatal error: Uncaught exception 'Wikimedia\Rdbms\DBQueryError' with message 'A database query error has occurred. Did you forget to run your application's database schema updater after upgrading? 
Query: INSERT  INTO `unittest_interwiki` (1,2,3) VALUES ('Array','Array','Array')
Function: MediaWikiTestCase::resetDB

iterator_to_array on the result of the select of the interwiki table
returns an array with the first entry having the key 1. For
multi insert to work, the array must start on 0.
Change-Id: I3dc1be9e2f016709f451fe6e8d7cc60862c1ffea
2018-08-14 05:08:02 +00:00
Aryeh Gregor
75d0941e7d Tests can't call resetGlobalServices()
They are supposed to call overrideMwServices() instead, per
documentation.  One test does call resetGlobalServices(), probably by
mistake.  It can be private so other tests won't make the same mistake.

Change-Id: I11ed598fcc901d0d9951724f2d210d3a7a1482d2
2018-08-09 17:53:14 +03:00
jenkins-bot
49ce67be93 Merge "Introduce ContentLanguage service to replace $wgContLang" 2018-08-02 02:52:23 +00:00
jenkins-bot
07beacf802 Merge "Automatically reset namespace caches when needed" 2018-08-02 02:26:33 +00:00
jenkins-bot
21a6c8fb40 Merge "Reset interwiki table between tests" 2018-08-02 02:14:50 +00:00
Aryeh Gregor
63d7f2ad13 Automatically reset namespace caches when needed
This avoids error-prone code written separately in every test.  In
addition to no existing tests resetting the TitleFormatter (more
services probably need to be reset as well), they mostly reset only the
namespace cache on $wgContLang, which wouldn't help for any other
language.

The parser test runner still doesn't do this, but maybe it should.

Change-Id: I44b7a1aec48f14b0950907fa14bd0df80f674296
2018-08-01 16:30:08 +03:00
Aryeh Gregor
f17feae3a9 Reset interwiki table between tests
Change-Id: I1c6d5624ffdcc7a624390336d3151e44170916e7
2018-08-01 14:13:30 +03:00
Kunal Mehta
04986dab93 Introduce MediaWikiTestCase::markTestSkippedIfDbType()
Helper to skip tests if they're being run with a specific DBMS where the
test currently fails.

The main use case for this is to temporarily disable failing postgres
and sqlite tests so we can make those test runs voting (so we don't
regress any further), and re-enable the tests once they've been fixed.

Change-Id: I1fd7ca6b2d21fed59ed387376d03489c7cbccdfe
2018-08-01 00:19:10 -07:00
Aryeh Gregor
1e079652e0 Introduce ContentLanguage service to replace $wgContLang
Bug: T200246
Depends-On: I31c2e20fc70ba3cbc124b9f462f4924a139dd9bd
Depends-On: I4aaf1c641ec6abef214eb96c0e4b42a67488ac00
Depends-On: I461cf2f441a4040bb15d6c4bb93ce6114c143845
Depends-On: I4b1cc4257348d1773fd2ccf045966261f801e7d0
Depends-On: I9790b7efdd484366dc36eb8880778aea1a559e5e
Change-Id: I193f5b9a95430b0a05573c361715e053e5411e32
2018-07-31 21:42:53 -07:00
Aryeh Gregor
05d78a6c71 Move utility methods from ApiTestCase to MediaWikiTestCase
Change-Id: I79c4e37092958c63a693194b27a9eafae70cb2f8
2018-07-29 12:47:45 +03:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
daniel
6cfdbdf60e Add support for extra database connections in unit tests.
This adds a way to take any connection to the wiki database and
allow it to be used for unit tests.

This is needed to test code that requires two independent DB
connections, to the same database or to a different wiki's database.

Change-Id: I0b84a0c4d174cbde830786028ee7568c4ea9fb5d
2018-07-04 19:07:45 +02:00
MusikAnimal
72566c80b1 Allow MediaWikiTestCase::insertPage to use given User
Sometimes you need to create pages with a non-sysop.
Example: I31aedcb9af7584fa5504916c67ca10f205ec9910

Change-Id: I9e48f7c00efbce8c2de3f5db3a74462d47ae8f64
2018-06-29 17:04:33 -04:00
jenkins-bot
84fa176c9c Merge "Avoid deprecated LinkCache::singleton()" 2018-06-14 23:48:54 +00:00
addshore
0ef66de3cf MCR RevisionStore, multi content mode..
Bug: T174024
Change-Id: Ifabf39e12ba843eb754ad0c029b7d16a311047a5
2018-06-14 17:30:33 +02:00
addshore
125bf7e44f [MCR] RevisionStore, enable insertions for new schema
Enable inserts to the new MCR db schema in single slot mode only.

TODO:
 - RELEASE NOTES

Notes:
 - When in MIGRATION_WRITE_NEW or greater, deleting and then
 restoring a page will result in different data in the revision table.
 For example, if you delete a page that has text_ids present in the
 revision table and restore it, the text_ids will be blank after.
 - When in MIGRATION_WRITE_BOTH or greater the archive table will
 start to ar_content_model entries where previously it would have been
 given NULL. This is due to the old content schema having NULL in the db
 when the default content model is used, but the new schema will always
 have a value, taken from the content_models table

Note: If259b1e1c49ce was squashed into this change.

Bug: T183488
Bug: T174024
Change-Id: Ic2221da30c8f6ac2ba42720fcd568f2d0ed70534
2018-06-14 13:36:08 +00:00
addshore
129c992ff1 Add @since tags to come MediaWikiTestCase methods
Follow up to:
 - I86e140ec981dfa4e904822b1600399c533f9e3d6 /
 e4b775acf1

Change-Id: Ib45f8ba30dfd382318dd87bc232a529c47c9a307
2018-06-14 08:46:18 +01:00
daniel
e4b775acf1 Suppress addCoreDBData() in tests overriding the revision schema.
Some unit tests for the MCR schema migration change the DB schema
in the test setup. However, addCoreDBData() will not work with the
modified schema. Since these tests don't actually need addCoreDBData()
to do anything, they can simply override it to do nothing.

Without this change, tests for Ic2221da30c and Ifabf39e12ba843
fail with $wgMultiContentRevisionSchemaMigrationStage = MIGRATION_WRITE_BOTH.

Change-Id: I86e140ec981dfa4e904822b1600399c533f9e3d6
2018-06-14 07:41:28 +00:00
Marius Hoch
291440ba49 Fix typehint-typo in MediaWikiTestCase
Change-Id: I3817d586cfaaaf38439820741e68eff044e9bf76
2018-06-12 20:20:49 +02:00
Kunal Mehta
c4e5a9dd97 Avoid deprecated LinkCache::singleton()
Change-Id: Ie0e5c4ef0fe6ec896378bb2433af0898655dd907
2018-06-10 23:55:11 -07:00
jenkins-bot
21ca5a3471 Merge "tests: Reset mwuser/pagecontent tables if necessary for postgres" 2018-06-07 14:39:15 +00:00
jenkins-bot
c3de9b16fb Merge "Reset relevant DB tables before the first test of a suite." 2018-06-07 13:46:56 +00:00
daniel
96a964631b Reset relevant DB tables before the first test of a suite.
MediaWikiTestCase truncates all the tables in the tablesUsed field
after each test. It should also do that before the first test of the
class.

Change-Id: I8c33be7b1bdd83559a9ea7803471a1f39e0eb870
2018-06-07 14:53:26 +02:00
Kunal Mehta
fda6e09a4e tests: Reset mwuser/pagecontent tables if necessary for postgres
As of 556c5cf464, postgres renames the `user` and `text` tables to
`mwuser` and `pagecontent` respectively. Have resetDB() explicitly
reset those tables when using postgres.

Bug: T195807
Change-Id: I5052dd663a4fb16389611cd2985b712fb9a15069
2018-06-06 20:31:57 -07:00