This changeset implements T89432 and related tickets and is based on exploration
done at the Prague Hackathon. The goal is to identify tests in MediaWiki core
that can be run without having to install & configure MediaWiki and its dependencies,
and provide a way to execute these tests via the standard phpunit entry point,
allowing for faster development and integration with existing tooling like IDEs.
The initial set of tests that met these criteria were identified using the work Amir did in
I88822667693d9e00ac3d4639c87bc24e5083e5e8. These tests were then moved into a new subdirectory
under phpunit/ and organized into a separate test suite. The environment for this suite
is set up via a PHPUnit bootstrap file without a custom entry point.
You can execute these tests by running:
$ vendor/bin/phpunit -d memory_limit=512M -c tests/phpunit/unit-tests.xml
Bug: T89432
Bug: T87781
Bug: T84948
Change-Id: Iad01033a0548afd4d2a6f2c1ef6fcc9debf72c0d
This introduces XML schema validation into the unit tests for
the backup dump scripts. This is intended to ensure that the
output keeps conforming to the schema when updating XmlDumpWriter
and friends to support newer schema versions.
Bug: T174031
Change-Id: Iafa8cb8ba5b3684a08172e92974edaf0482f19b7
Created class RevisionStoreCacheRecord to avoid returning stale
cached revision visibility and actor data when changes were
made after the cache was populated for that revision.
Bug: T216159
Change-Id: Iabed80e06a08ff0793dfe64db881cbcd535cb13f
Update the default implementation of FormSpecialPage::checkExecutePermissions()
so that a Special page is only blocked if the user has a sitewide block.
This change allows the user to continue performing critical functions (like
resetting their password) even if they are partially blocked.
Bug: T209097
Change-Id: I5190297b7b235b6ebbdfa522323ce9bbd46b6729
When a unit test fails it is possible, perhaps even likely in some
cases, that some code that was run logged useful information about
how that failure came to be.
Help people out, tell them what happened!
Change-Id: I30bbc31799a65024868678d052fec9aafacc1aff
Remex is pure PHP so there is no reason to use an external tidy any
more. Configuration variables and implementation classes were
deprecated in 1.32 or earlier. We've kept only $wgTidyConfig
which can be used for experimental features or debugging Remex.
Bug: T198214
Change-Id: I99d48f858d97b6e1d1e6cd76a42c960cc2c61f9f
Partial blocks logic will be used in multiple places. This
classes will group block restriction functionality to avoid
code duplication
Bug: T202036
Change-Id: I675316dddf272fd0d6172ecad3882160752bf780
During development a lot of classes were placed in MediaWiki\Storage\.
The precedent set would mean that every class relating to something
stored in a database table, plus all related value classes and such,
would go into that namespace.
Let's put them into MediaWiki\Revision\ instead. Then future classes
related to the 'page' table can go into MediaWiki\Page\, future classes
related to the 'user' table can go into MediaWiki\User\, and so on.
Note I didn't move DerivedPageDataUpdater, PageUpdateException,
PageUpdater, or RevisionSlotsUpdate in this patch. If these are kept
long-term, they probably belong in MediaWiki\Page\ or MediaWiki\Edit\
instead.
Bug: T204158
Change-Id: I16bea8927566a3c73c07e4f4afb3537e05aa04a5
Otherwise I get errors every time I try to run PHPUnit on includes/ or
includes/parser, because it tries to run ParserIntegrationTest.php and
fails. Apparently the <exclude> in suite.xml doesn't work if PHPUnit is
invoked on a directory.
Bug: T201278
Change-Id: I7d09576bee2705d8516152e8fa671da8dac40233
* 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
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
NOTE: this changes the numeric values of the MIGRATION_XXX constants!
Order is preserved.
Bug: T197619
Change-Id: I16db7dd5799ab98c1cb12e7cd1e0b2da83b366fc
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
Various code using the search engine shouldn't need to implement it's
own methods, such as over-fetching, to determine if there are more
results available. This should be knowledge internal to search that is
exposed by a boolean.
Change-Id: Ica094428700637dfdedb723b03f6aeadfe12b9f4
The funky iteration here was at best annoying. Switch
it over to an iterator based approach with appropriate
BC code to simulate the old iteration style.
Depends-On: I19a8d6621a130811871dec9335038797627d9448
Change-Id: I9fccda15dd58a0dc35771d3b5cd7a6e8b02514a0
This introduces traits for testing different schema variations.
These are not very useful in this patch, but make it much easier
to add tests for MCR schema migration in subsequent patches.
The code in this patch was previously part of If259b1e1c49ceaa4.
Change-Id: I239572f75bebbc9c731a3e3860c4eff179dc15e4
This makes sure that length and hash are calculated if not known.
This patch also adds missing unit tests for RevisionArchiveRecord,
and consolidates unit tests for the different RevisionRecord
subclasses using a trait.
Bug: T192189
Change-Id: I5e1d17ba96e61e068b6aa5ac9c45ac0f657905a6
Hamcrest has its own assertThat() function, which is used in PHPUnit
tests. However, in PHPUnit 6, tests that don't have any assertions are
marked as risky.
To work around that, add a HamcrestPHPUnitIntegration trait that
provides a $this->assertThatHamcrest() - it wraps around Hamcrest's
assertThat(), and increments PHPUnit's assertion counter, so using it
ensures that the test is not risky.
Change-Id: Ia4a4ec226f64ebe90d1091ffd27420a356ca76ff
PHPUnit 6 removed some functions that were heavily used in version 4. To
be able to support both versions for a short time, we'll use a trait to
fill in the missing methods until we drop PHPUnit 4 support.
This trait is included in MediaWikiTestCase so most tests will be able
to benefit from it by default. Otherwise, anything that calls
setExpectedException() or getMock() will need to use it.
Change-Id: I707129e471e960e034e2aa994a467b9dc0239b69
Add it to the autoloader for the tests, and remove the unneeded use
statements which cause test failures.
Change-Id: I7092525eae440c6969fc84e8979572957733cf03
Bugs fixed:
* The major one was that appendtext and prependtext seemingly didn't
work at all on empty pages in the MediaWiki namespace, because
$this->getTitle() was being used in place of $titleObj.
* Negative undo/undoafter were not rejected in a correct fashion.
* If a logged-in user who was not allowed to upload images tried to
create an image redirect, the error message used a nonexistent key.
I also replaced assertEquals with assertSame.
I also removed a bit of clearly dead code. This includes a "break"
following dieStatus(). If we actually want this break so that nobody
adds a case after the default and then removes the dieStatus() so the
switch incorrectly falls through, it could be re-added with
@codeCoverageIgnore.
I put the fixes in the same commit as the test changes because I like to
keep fixes together with the tests for those fixes.
All code now shows up as covered locally, except for one line that seems
to be a PHPUnit bug.
Change-Id: I9375bc5f40268fd681a2d447c66a03f40b23390a
Clean up use of @codingStandardsIgnore
- @codingStandardsIgnoreFile -> phpcs:ignoreFile
- @codingStandardsIgnoreLine -> phpcs:ignore
- @codingStandardsIgnoreStart -> phpcs:disable
- @codingStandardsIgnoreEnd -> phpcs:enable
For phpcs:disable always the necessary sniffs are provided.
Some start/end pairs are changed to line ignore
Change-Id: I92ef235849bcc349c69e53504e664a155dd162c8
PHPUnit only verifies that @covers tags are correct when actually
running coverage - but that's too slow to do on every commit. And if
even a single tag is incorrect, the entire coverage job will fail. It
also has some different requirements compared to normal tags, like all
namespaced classes must use their absolute name. All of those things
combined make it easy for developers to accidentally break the coverage
job.
There are some external tools that also do this, but those tools are
incompatible with our unusual PHPUnit setup (the phpunit.php wrapper
script).
The MediaWikiCoversValidator trait just calls the same method that
PHPUnit does to validate @covers tags. It is implemented as a trait so
that test cases that implement PHPUnit_Framework_TestCase directly can
still use this.
Bug: T171899
Change-Id: I1d564bcae2bfbedb004c440b90db6341148ed4ba
core used to have a test case that ran various Revision tests
with and without ContentHandlerUseDB set, however it did not
run due to the class / file having a bad name.
This patch reintroduces the running on Revision tests for both
ContentHandlerUseDB settings.
The global has to be set in setup / before the page used for
testing is created, else this page will be created with the
wrong values in the DB for use in the tests.
Change-Id: Ied1023e22eeac413fa86ea6946aa31619fd66319
And allow extensions to add their own media handlers.
I'm not too happy with the introduction of another global,
but didn't like the alternatives either:
* Add some hook to MockMediaHandlerFactory that would allow
extensions to add their own stuff in.
* Use another hook (like ParserTestTables or ParserTestGlobals)
and then override the service with a new instance - seemed
too hacky
The good thing about this is that it lets us kill off a class.
I'm other to other suggestions in case I missed something.
Bug: T169258
Depends-On: I5875621c58597426ad5242bf3d07714555c439b5
Change-Id: I1c2e903fb235395a8de8e0f7bf65ce07739d2930
This already worked as expected for any module that uses the new
enableModuleContentVersion model, but for the majority of file modules
this is not yet the case for performance reasons. As such, make
sure lessVars are included in our manual tracking.
Include it conditionally to avoid changing the array for other modules,
which would needlessly invalidate their cache.
Bug: T171809
Change-Id: Ib250068e0ecfc29a09ca33c23bef901ee0482bf2
If your extension depended on this, replace \TestingAccessWrapper
with \Wikimedia\TestingAccessWrapper.
Bug: T163434
Change-Id: Ice1e8aae258b4c6ae7ab1b2a4815fe682335cc3a
Generate old RC, Related changes (it was already displayed and working
on 'Related changes' before this change), and Watchlist/etc. and data
for new UI from back-end.
This moves everything used for defining the old (unstructured) and new
(structured) filters into unified objects, ChangesListFilter and
ChangesListFilterGroup (and sub-classes).
This includes the query logic (see below) and logic for adding
CSS attribution classes.
This is a breaking change (for subclasses of ChangesListSpecialpage)
due to the signature (and name) change of buildMainQueryConds and
doMainQuery. An alternative that I don't think is a breaking change
would be to put the filter->DB logic in runMainQueryHook, but then it's
doing more than just running a hook.
This is because it used to only build $conds here, but it's clear from
filterOnUserExperienceLevel filters need more than this. I added all
the DB parameters from the hook, but this could be debated.
I have an checked and fixed the WMF-deployed extensions affected by
this.
Other than that, there should be full back-compat (including legacy
filters not using the new system).
* add hidepatrolled/hideunpatrolled to new UI.
* Move userExpLevel from RC to ChangesListSpecialPage. Although for
now the structured UI only displays on RC anyway, when it displays on
watchlist, it seems we'll want userExpLevel there.
Change this to make 'all' exclude unregistered users.
* Don't have front-end convert none-selected to 'all' on string_options.
* Needs the hideanons/hideliu special redirect to be done before this
is merged (T151873)
Bug: T152754
Bug: T152797
Change-Id: Iec2d82f6a830403d1c948a280efa58992e0cdee7