Commit graph

34 commits

Author SHA1 Message Date
Bartosz Dziewoński
0c0d50ce81 Fix specifying messages with params as arrays in API documentation
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
2024-08-21 13:26:02 +00:00
theprotonade
12a4c08ad8 Deprecate ApiBase::makeMessage
Replace usages of ApiBase::makeMessage
with ApiBase::msg and deprecate the former
method

Bug: T370240
Change-Id: I9e6e775dad7f3e3cfd78351f87f4732677d90971
2024-08-16 12:09:33 -04:00
Umherirrender
f27c2433bb tests: Use namespaced classes (2)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: I4ff4d0c10820dc2a3b8419b4115fadf81a76f7a2
2024-06-13 23:21:02 +02:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Ammarpad
88c21717e9 ApiStructureTest: Improve error message
Make message to actually communicate errors instead of
confirming success, this will reduce confusion like in T348934

Change-Id: I0b9cd5aed26be539db429a79c486217a69f74cdb
2023-10-17 09:53:37 -04:00
Daimona Eaytoy
485e47ff10 tests: Avoid database usage when possible
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
2023-07-31 00:46:13 +00:00
Daimona Eaytoy
5cc78474e1 tests: Avoid DB queries in ApiStructureTest::provideParameters
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
2023-07-12 23:18:41 +02:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
Daimona Eaytoy
1c60cafab4 Add @coversNothing to all structure tests
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
2022-10-07 03:21:54 +02:00
Umherirrender
6dcb1ebe76 tests: Change multiple calls from overrideConfigValue to overrideConfigValues
Also change loops to multi-value function

Change-Id: I2301cc246b7f8ca3028d44d70756a5e1ba04e82d
2022-08-17 12:08:50 +00:00
Derick Alangi
f00cd03580 tests: Make use of overrideConfig(Value|Values) where needed
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
2022-07-11 21:15:26 +01:00
Umherirrender
de47d93928 Get the MainConfig from MediaWikiServices instead of RequestContext
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
2022-05-24 21:54:21 +00:00
Aryeh Gregor
79fc95d39c Use MainConfigNames instead of string literals, #5
This should be the last of the usages in core, although I'm sure a few
are hiding somehow.

Change-Id: I7bf0b24bf23d3efb4c56a891830bbfe67945e899
2022-04-27 18:46:29 +03:00
Reedy
6e29611642 Remove or replace usages of "sanity"
Still some more to go...

Bug: T254646
Change-Id: Ia117f01e443c35b4765f3275cab4f2707e1be96f
2021-11-21 16:42:31 +00: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
Thiemo Kreuz
2f66b3754f tests: Remove @param docs from test code that just repeat the signature
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
2021-01-21 03:41:23 +00:00
addshore
959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
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
2020-06-30 17:02:22 +01:00
jenkins-bot
9b2199bcf1 Merge "ApiDisabled: Correctly fall back to api-help-no-extended-description" 2020-02-12 00:11:14 +00:00
Brad Jorsch
d4c2f0d899 Move some validation logic from ApiStructureTest to ParamValidator
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
2020-02-04 20:29:35 +00:00
Brad Jorsch
edc3272816 ApiDisabled: Correctly fall back to api-help-no-extended-description
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
2020-01-13 09:24:11 -05:00
Daimona Eaytoy
f5529400cc Stop using assertContains with string haystack
This was done automatically by replacing every assertContains with
string *needle*. Then verifying the results.

Bug: T192167
Change-Id: Id8cbbf3b01e948f80046714183cc299f86be21fd
2019-12-15 00:22:44 +00:00
Daimona Eaytoy
e501bb3b50 Manual fix of the remaining assertInternalType & Co.
Bug: T192167
Change-Id: I3b8176745f49b1d4bfe6f36978b7879d546f68a9
2019-12-15 00:20:10 +00:00
Daimona Eaytoy
6365eaab8d Autofix 94 PHPUnit 8 compat issues
Done automatically using the master version of MW codesniffer and
running composer fix.

Bug: T192167
Change-Id: If6b40f515fde32ab5eff074a90e821c30c791827
2019-12-13 15:29:10 +01:00
Gergő Tisza
45d4e8d13a Exempt structure tests from @covers checks
@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
2019-06-11 21:40:14 +00:00
Aryeh Gregor
2e1ac38485 Mass conversion to NamespaceInfo
Change-Id: I2fef157ceec772f304c0923a1cd8c0eef2e82a0f
2019-05-07 22:44:56 +02:00
Reedy
c13fee87d4 Collapse some nested if statements
Change-Id: I9a97325d738d09370d29d35d5254bc0dadc57ff4
2019-04-04 19:02:22 +00:00
Umherirrender
d28f315d24 Add @coversNothing for left over tests and enable sniff
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
2019-02-02 21:53:40 -08: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
Brad Jorsch
78d1b8ebba API: Introduce "templated parameters"
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
2018-05-16 16:19:31 -04:00
Aryeh Gregor
4fe5d0dbaa Add more checks to ApiStructureTest.php
Depends-On: Ideca8903e4b529b7471ba81aa7dd3b01039ed2f9
Depends-On: I39b96ad0334a17fd50501e92b26f1d47ee4ccbba
Depends-On: Ied07ccfd7ff6db9d399eac3c8aab63993b91c1f4
Change-Id: I4a2505cfc8e86e73e46d40acffbf3cd8803458e2
2018-04-08 15:58:06 +03:00
James D. Forrester
9acd5508cf Drop the 'CategorizedRecentChanges' feature
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
2018-02-15 10:45:10 -08:00
Umherirrender
45da581551 Use ::class to resolve class names in tests
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c
2018-01-26 22:49:13 +01:00
Gergő Tisza
17d001b73a Add string length limits
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
2017-11-21 10:24:11 +00:00
Gergő Tisza
5e76403387 Make API multivalue limits configurable
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)