Follow-up to 12a4c08ad8.
I didn't review it carefully enough to notice that when these
functions return arrays, they contain a message key and parameters,
not a key and fallback keys (while other API documentation message
code uses fallback keys).
Instead of `$this->msg( $msg )`, this code must be written as
`is_array( $msg ) ? $this->msg( ...$msg ) : $this->msg( $msg )`
or `$this->msg( Message::newFromSpecifier( $msg ) )`, both of which
are ugly, but the latter looks a bit better to me.
Bonus changes:
* Add documentation to prevent a repeat of this mistake in the future
* Remove some unreachable dieDebug() calls (the Message class already
throws for bad inputs)
It seems that we don't have any definitions using such arrays
in the core API classes. There are only a few uses in extensions,
e.g. AbuseFilter's 'apihelp-query+abuselog-param-filter' message,
which is passed the wrong parameter without this change.
Bug: T372988
Change-Id: I44c1c3c7d0c069e500c85a58c27e9b675b0b68ee
Replace usages of ApiBase::makeMessage
with ApiBase::msg and deprecate the former
method
Bug: T370240
Change-Id: I9e6e775dad7f3e3cfd78351f87f4732677d90971
Changes to the use statements done automatically via script
Addition of missing use statement done manually
Change-Id: I4ff4d0c10820dc2a3b8419b4115fadf81a76f7a2
Make message to actually communicate errors instead of
confirming success, this will reduce confusion like in T348934
Change-Id: I0b9cd5aed26be539db429a79c486217a69f74cdb
We would like to remove DB access in non-database PHPUnit tests. As a
first step, avoid database usage in tested code when possible. In
particular:
- In NameTableStoreFactory, avoid domain ID normalization if the
provided ID is already false.
- In SpecialDoubleRedirects, do not acquire a DB connection until it's
needed (which is just one place).
- Use editPage() in TitleDefTest instead of a DIY implementation, and
add `@group Database` accordingly.
- Avoid parsing titles in ContentHandler tests that don't need to parse
titles. Among the many dependencies of parsing titles is the interwiki
lookup, which requires DB access.
- Also remove test cases that used the "Gadget" namespace; it doesn't
exist in core, so these pages were actually in the mainspace.
- Mock the database in CategoriesRdfTest. The only two methods that use
the database were already being mocked.
- Add `@group Database` to test classes that are intentionally using the
Database, mainly via getTestUser().
Bug: T155147
Change-Id: I9385fe14cfeb6b7b7378cc322d510034c4ee0711
Some of the methods called in the data provider, like getAllowedParams,
may make read queries. This should be avoided in data providers (see
e.g. T312849). Instantiate the module in the test method instead, and
process all parameters there. This does mean that a failure with a
single parameter will make the test end without testing the remaining
parameters, but there isn't much we can do about it.
Bug: T341731
Change-Id: I7eeed0da5da61e90c6fbfa0411a2b3b416395167
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
As we slowly move away from using globals, overrideConfigValue()
and overrideConfigValues() were introduced as a way to override
test configs between tests.
Under the hood, it just calls setMwGlobals() which resets services,
so take note.
Part 1: Directories covered are: languages/, maintenance/, tests/,
structure/ and includes/Permissions/.
Depends-On: I618b16c6d99c94eb2e7edcf05e888a65f7156754
Change-Id: If56f7d10d79f3a9824a52091a2b544d8653dd7b6
The getConfig of a ContextSource should only be used, if the
ContextSource is available. Getting the global context just for the
config looks harder to fix/inject as using the MainConfig from
MediaWikiServices
Change-Id: Iaf14bfc7bd68cc315672e1c256887faf87e22542
These are not only 100% identical to the actual code, but also:
* It's error-prone. Some are already wrong.
* These test…() functions are not meant to be called from
anywhere. What is the target audience for this documentation?
* There is a @dataProvider. What such @param tags actually do is
document the provider, but in an odd place. Just looking at
the provider should give the same information.
* The MediaWiki CodeSniffer allows to skip @param when there is
a @dataProvider, for the reasone listed.
Change-Id: I0f6f42f9a15776df944a0da48a50f9d5a2fb6349
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
ApiStructureTest has a lot of logic for validating Action API settings
arrays during CI. Some of that logic should be part of ParamValidator
instead.
Bug: T242887
Change-Id: I3c3d23e38456de19179ae3e5855397316b6e4c40
Depends-On: I04de72d731b94468d8a12b35df67f359382b3742
ApiBase falls back to this message when the module itself doesn't define
an extended-description message. ApiDisabled and ApiQueryDisabled should
do so as well.
Bug: T242534
Change-Id: I8f3ed17559363d9c66c5baf0ef7b0675714dc877
This was done automatically by replacing every assertContains with
string *needle*. Then verifying the results.
Bug: T192167
Change-Id: Id8cbbf3b01e948f80046714183cc299f86be21fd
Done automatically using the master version of MW codesniffer and
running composer fix.
Bug: T192167
Change-Id: If6b40f515fde32ab5eff074a90e821c30c791827
@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
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
This ensure that the regex is escaped correctly,
even when the quoted value never contains the delimiter
Change-Id: I2dc93fa0154d4506c276a30cab008bc2ac5e0687
With MCR coming up, ApiEditPage is going to need to be able to take
"text" and "contentmodel" parameters for each slot-role, and enumerating
such parameters for every possible slot would probably get rather
confusing as to what is required when, or at least long-winded in
repeating the exact same thing for every possible role.
So let's abstract it: we'll have an "editroles" parameter to specify which
slots are being edited, and ApiEditPage will just declare that
"text-{role}" and "contentmodel-{role}" parameters should exist for each
value of "editroles" in the submission.
Note this patch doesn't introduce anything that uses templated
parameters, just the functionality itself. For testing purposes you
might cherry pick I2d658e9a.
Bug: T174032
Change-Id: Ia19a1617b73067bfb1f0f16ccc57d471778b7361
It is off by default, it's very rarely used (GitHub finds four config
users setting it true), it has over time had fatals going unnoticed or
fixed for years. Let's just kill it.
Change-Id: Idac2341ed7ecf053ee84069df657e424e50b896c
Adds two new ApiBase::getAllowedParams() keys:
PARAM_MAX_BYTES and PARAM_MAX_CHARS, to set a length
limit for a (string-like) parameter.
This makes it easy to document and enforce database
field length limits (where relying on the database
would either result in unfriendly error messages or
silent truncation, depending on DB settings) and
also exposes them in structured form so API clients
can verify the length without doing roundtrips.
Change-Id: I2e784972d7e11cad79fdef887bbcde297dbd9ce0
Adds two new parameter settings, ApiBase::PARAM_ISMULTI_LIMIT1
and PARAM_ISMULTI_LIMIT2 for configuring the maximum number of values
that can be contained in a multivalue field (for unprivileged and
apihighlimits users, respectively). When present, these replace the
default 50/500.
Change-Id: Ic1b1bcc7ff556b7762c8d2375d910cc4fcb43087
2017-08-24 02:08:50 +00:00
Renamed from tests/phpunit/structure/ApiDocumentationTest.php (Browse further)