Commit graph

104 commits

Author SHA1 Message Date
Alangi Derick
8221a7a4f2 Remove array_unique() on expected classes in checkAutoLoadConf()
Sometimes classes can be loaded via autoload (PSR-4) and class_aliasing
and due to this calling array_unique() on expected classes will remove
one of these classes due to them sharing the same file (and array_unique()
works on array values).

Also allow for ::class suffixed classes to be namespaced (ie look for \
in the regexes)

Cleanup some of the regexes, remove redunant code (don't need multi cased
letters when we have /i), simplify them

Bug: T206728
Change-Id: I235274d579b1bfd12a448448ddf020546c9aa89b
2018-11-30 00:22:06 +00:00
Brad Jorsch
ca3789a271 AutoloadGenerator: Filter PSR4-compliant classes instead of ignoring directories
Per discussion in T166010, we're going to handle class aliases (e.g. for
BC) by including the class_alias() call in the same file as the target
class. When the target class is a PSR4-compliant class, we still need to
pick up that alias for inclusion in autoload.php.

Thus, instead of excluding whole directories, we need to process the
files and filter out only those found classes that are PSR4 compliant.

Bug: T204983
Change-Id: I1c516998df368531c90ea54acc5be8be96e1db6c
2018-09-20 15:15:27 -04:00
Umherirrender
480b653720 StructureTest::testUnitTestFileNamesEndWithTest() should not shell out
Bug: T169005
Change-Id: I17b35f31c3989ca0b9056252866a45434c31a105
2018-09-18 20:34:28 +02:00
jenkins-bot
df76e044f5 Merge "Pass delimiter to preg_quote" 2018-09-10 23:55:19 +00: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
jenkins-bot
5354c219cd Merge "test: Assert that API generators have unique prefixes" 2018-08-18 01:04:31 +00:00
jenkins-bot
fd08137ebf Merge "Turn ApiPrefixUniquenessTest into a structure test" 2018-08-18 00:55:18 +00:00
Antoine Musso
821fbb27c4 test: Assert that API generators have unique prefixes
Signed-off-by: Brad Jorsch <bjorsch@wikimedia.org>
Change-Id: I30758f2ac95fd8ae361ef8079abdfb0a82d92e34
2018-08-17 17:31:22 -07:00
Kunal Mehta
72b4099727 Turn ApiPrefixUniquenessTest into a structure test
This way it gets run during extension test runs as well.

Temporarily add a hack allowing 'wbeu' duplicates until T196962 is fixed.

Change-Id: Ic89a22a2ff4525585de9e290a1d47d22cfaaac5e
2018-08-17 14:19:41 -07:00
Aryeh Gregor
e68fdb4065 Mass conversion to SpecialPageFactory service
Change-Id: Ia6e1e819ec6cbe8bf75b820109f51d47863e31fc
2018-08-17 12:03:12 -07: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
addshore
b50c8848e6 Introduce SpecialPageFatalTest
This test makes sure that special pages do not fatal
in their most basic form (anon user viewing the page).

Depends-On: I3a9f5b315eb114cb12ea4071f8da9079f797fcf6
Change-Id: Ic675e92d8dd8f11fa67914d2ce1dc00a379106ca
2018-07-31 07:11:48 +00:00
Kunal Mehta
13b817d408 Check for right-* messages as a structure test
Structure tests run for extensions as well, which this test should. All
user rights should have right-* messages for display in the interface.

Bug: T143156
Change-Id: I23b8eb66bc68121b2ae17e73e705acd3e6f2d053
2018-07-26 14:14:54 -07:00
Timo Tijhof
b7b84d55d4 resourceloader: Embed 'mediawiki' directly in startup response
Embed the essential files to define mw.loader directly as part of
the startup module.

* This means the internal 'mediawiki' module no longer exists.
  This is safe to remove because:
  1) While registered server-side for loading from startup.js, a PHPUnit
     structure test disallowed being specified as a dependency.
  2) Anything that attempted to load it client-side failed because the
     module was marked in the registry as 'raw', thereby excluding it
     from the data sent to the client-side. As such, it was seen as an
     unknown module that the client refused to fetch from the server.

* Deprecate getStartupModules() and getLegacyModules().
  These are no longer needed. There are no known callers anywhere in
  Wikimedia Git or elsewhere indexed by Codesearch, but easy enough
  to leave as no-op for one release.

* Remove ResourceLoaderRawFileModule class.
  No longer needed. Was created as a hack specifically for the 'mediawiki'
  module so that it would not leak global variables in debug mode.
  It has no usage anywhere in Wikimedia Git, nor elsewhere in Codesearch.
  Remove without deprecation given this was meant to be a 'private' class.

* Introduce (private) getBaseModules(). Previously, this list only existed
  locally in getStartupModulesUrl() by merging getStartupModules() and
  getLegacyModules(). This value was factored out into its own method.

* Make getStartupModulesUrl() private and rename to getBaseModulesUrl().
  It is only used internally to export the 'baseModulesUri' value.
  Its name was already confusing before, but it would've been even more
  confusing now given it doesn't even call getStartupModules() any more.

Bug: T192623
Change-Id: I14ba282d7b65e99ca54b7c2f77ba6e1adaddd11c
2018-06-27 17:06:35 +00:00
Hashar
afb2269cb9 Revert "Use pathinfo() in AutoLoaderStructureTest::testPSR4Completeness"
This reverts commit 634c2ec2af.

Reason for revert: that strips the PSR4 directories from the class.

Example:
$dir BlueSpiceFoundation/src/"
$file BlueSpiceFoundation/src/ConfigDefinition/IntSetting.php

$abbrFileName: IntSetting
$expectedClassName: BlueSpice\IntSetting

$abbrFileName should be relative to $dir and not just the filename.

Bug: T198077
Change-Id: Ie934e309fee0392439b4e26d86249f0650e5ea67
2018-06-25 12:38:07 +00:00
Antoine Musso
634c2ec2af Use pathinfo() in AutoLoaderStructureTest::testPSR4Completeness
When setting AutoloadNamespaces to './' in extension.json, the test
AutoLoaderStructureTest::testPSR4Completeness would fail. The directory
path is not made canonical while the file is, which causes the substr()
call being used to strip too many characters. For example:

  $dir : /mediawiki/extensions/Wikidata.org/./
  $file: /mediawiki/extensions/Wikidata.org/Hooks.php

$abbrFileName = substr( substr( $file, strlen( $dir ) ), 0, -4 );
>>> oks

Use pathinfo() to parse the filename. Yields 'Hooks' as expected.

Bug: T198077
Change-Id: Ia8a11d87788b32ddb426a16a61b410b05ff5f15e
2018-06-25 11:47:52 +00:00
Kunal Mehta
4acb7ed51c Add @coversNothing to tests that don't cover specific PHP classes
Change-Id: Idbd364561bc28547e9fac20d7a80b9a44edf14a9
2018-06-12 13:27:40 -07:00
Kunal Mehta
b5e6da43e4 Don't autoload classes in AutoloadStructureTest
Autoloading classes is a 100% accurate way to ensure the autoloader
worked, but there are cases where if optional dependencies aren't
installed, then autoloading the class will fail. We can re-implement the
logic behind the PSR-4 autoloader, and ensure that classes will be
autoloadable by turning the filename into a class name, and making sure
that class name is the one we found in the file.

Bug: T195823
Change-Id: I5df378180e567c257386482383ef73812592f989
2018-05-29 11:09:57 -07:00
Kunal Mehta
e7ae019fc0 AutoLoaderStructureTest: Allow PSR-4 directories to have files with 0 classes
Files like ServiceWiring.php can be safely located in a PSR-4 autoloaded
directory, because they have no classes.

Change-Id: I359b305df9071d6bc5afe4b5f29e762041f4aaef
2018-05-26 16:51:56 -07:00
Kunal Mehta
e298f548f6 Split AutoloaderTest into a structure and class test
AutoloaderTest covers the AutoLoader class, and AutoLoaderStructureTest
covers the structure part of the test.

Change-Id: Ic4e7bfd670e1c3413631bda31260cc1cc825b1a2
2018-05-26 16:16:02 -07:00
Kunal Mehta
0e6f6b592d Add structure test to ensure PSR-4 autoloader covers everything
This ensures that there aren't any classes inside a PSR-4 autoloaded
directory that aren't being autoloaded properly.

Change-Id: I200a8535c2f47a6bf3287a7fe1182151493372f4
2018-05-24 18:57:42 -07: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
Lucas Werkmeister
4a1e59b63d Accept non-fully qualified TestCase in StructureTest
This makes StructureTest also recognize test classes which look like

    use PHPUnit\Framework\TestCase;

    class FooTest extends TestCase {

instead of

    class FooTest extends \PHPUnit\Framework\TestCase {

This form is preferred, for instance, in Wikibase code.

Bug: T188276
Change-Id: I5bef035df33d317893ad3ba195ecb75f3b09a62f
2018-02-26 18:06:27 +01:00
Umherirrender
63d96c15fd build: Updating mediawiki/mediawiki-codesniffer to 16.0.0
Change-Id: I59b59f79bbf3ce4feff3b3a20c1c31bc16370531
2018-02-17 13:29:13 +01: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
Reedy
39f0f919c5 Update suppressWarning()/restoreWarning() calls
Bug: T182273
Change-Id: I9e1b628fe5949ca54258424c2e45b2fb6d491d0f
2018-02-10 08:50:12 +00: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
Kunal Mehta
75160bdd3b Use MediaWikiCoversValidator for tests that don't use MediaWikiTestCase
Change-Id: I8c4de7e9c72c9969088666007b54c6fd23f6cc13
2018-01-01 08:28:02 +00:00
mainframe98
70e92cdad5 Fix additional usage of incorrect case
Courtesy of the PhpStorm inspection Case mismatch in method call or
class usage.

Bug: T166759
Change-Id: I27c53658b99048fa0dd8f9d6ef1398620386e1cc
2017-12-15 11:58:11 +01:00
Kunal Mehta
036f5b47ef Enable using PSR-4 autoloader for MediaWiki core and extensions
This adds support for a PSR-4 (<http://www.php-fig.org/psr/psr-4/>)
autoloader, so instead of needing to manually list each class, just the
namespace prefix is needed.

Extensions can set a "AutoloadNamespaces" property in extension.json to
register PSR-4 compatible namespaces to be autoloaded.

The implementation is based off of the example implementation
(<http://www.php-fig.org/psr/psr-4/examples/>) with some modifications
for performance, notably cutting down on function calls, and only trying
to look up classes that are namespaced.

The generateLocalAutoload.php script will ignore any directory that is
registered as a PSR-4 namespace.

Bug: T99865
Bug: T173799
Change-Id: Id095dde37cbb40aa424fb628bd3c94e684ca2f65
2017-12-12 00:20:11 +00: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
Timo Tijhof
d4a17a10a5 phpunit: Include all raw modules in detection of illegal dependencies
* Use getStartupModules() instead of hardcoding these two module names.
* Also collect any other module that is registered with raw=>true.

Change-Id: I5f75cc8f99b90f58d76b7e87f068f50f9f608ed0
2017-10-03 18:13:20 +01: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
Timo Tijhof
ddb7575e4e rdbms: Refactor DatabaseTest
* Move DatabaseTest and DatabaseSQLTest to libs,
  and remove MediaWikiTestCase dependency.

* Refactor DatabaseTest to be a test of the Database abstract class,
  not of whatever current DB backend is configured by LocalSettings.

  - Remove most switches/conditionals and other tests for specific
    database backends. Move those to individual test classes for
    those backends instead.
  - Some tests appear to have been integration tests for the PHP driver
    and/or the db backend itself. Moved to a new DatabaseIntegrationTest.
  - Now that only the abstract Database is invoked, the test runs a bit
    faster (no real connections/queries).

* Add missing @covers tags, and remove or fix broken ones
  (follows-up 26e52f0c49).

Change-Id: I9dc4a558e701d00e95789e7eb8e02926783b65ad
2017-07-20 18:23:37 -07:00
Brad Jorsch
45093c330f API: Split description messages into summary + additional text
To fix T123930, it would be very handy to have the summary for each
module without any of the additional explanatory text.

Bug: T166411
Change-Id: I778bab2b87971875aed4c804341ad59c1c6e021f
2017-06-15 13:46:55 -04:00
Gergő Tisza
525bfbc8df Switch to librarized version of TestingAccessWrapper
Replaces \TestingAccessWrapper (defined in core) with
\Wikimedia\TestingAccessWrapper (defined in the composer package
wikimedia/testing-access-wrapper).

See https://gerrit.wikimedia.org/r/#/q/topic:librarize-testing-access-wrapper
for downstream patches.

The core version of the class is kept around for a while to avoid
circular dependency problems.

Bug: T163434
Change-Id: I52cc257e593da3d6c3b01a909e554a950225aec8
2017-04-20 14:15:57 +00:00
Timo Tijhof
516f2700e0 AutoloadGenerator: Add support for class_alias()
Blob, Field, DatabaseBase are now auto-detected.

Change-Id: Ib8fae2ec3fbb3f5e4aca7965f81631c5f0485ea1
2017-02-22 21:22:41 +00:00
Stanislav Malyshev
85fd9d4fb4 Check that empty content is valid only on handlers that allow direct editing.
Bug: T157626
Change-Id: I843f25172b70111f8219eec9a853ac3138c6aff3
2017-02-15 15:15:41 -08:00
Thiemo Mättig
3e83a50213 Remove unused imports from test classes
Validating this should be as simple as it can be: if the tests run,
this change should be fine. :-)

Change-Id: I8e4a3dfc83fdc9b8c8d7f5bbd067e088ebd2133d
2017-01-10 11:49:58 +01:00
Thiemo Mättig
00c3f09566 Remove empty lines from PHP and JavaScript comment blocks
This is a pure documentation change. It mostly removes empty lines from
comments (and entirely empty comments), as well as adds a few missing
documentation blocks and fixes a minor mistake. I hope it's ok to have
this in one patch. I can split it, please tell me.

Change-Id: I9668338602ac77b903ab6b02ff56bd52743c37c4
2016-12-09 09:01:06 +00:00
Kunal Mehta
da68c0ae82 registration: Refactor validation logic to avoid duplication
Previously, logic to validate extension.json files was in two places:
validateRegistrationFile.php maintenance script, and the
ExtensionJsonValidationTest.php structure test. This caused duplication
as validation became more complex (e.g. usage of spdx-licenses library).

A generic ExtensionJsonValidator class now handles most of the
validation work, while the maintenance script and test case just wrap
around it for their output formats.

Change-Id: I47062a4ae19c58ee1b1f2bb4877913259bf19c8b
2016-11-30 23:04:27 -08:00
Brad Jorsch
af1dfeead5 Validate getExamplesMessages() query strings
Assert that they don't begin with 'api.php?'.

Change-Id: Idf5e8e08863a379a37a427a11936e5f9ce567396
Depends-On: I8a82eecefbb0ba327d8e8bc24ec535bcf40e6429
Depends-On: I476aad09655a2822381a2c61690b4b0ad423151e
2016-11-10 10:17:04 -05:00
Leszek Manicki
d5a12f954b Remove not used variables in ResourcesTest
Change-Id: I45f531e66545175c689b8f6a62a5c3ed62ea5a9a
2016-11-05 20:28:32 +00:00
Sam Wilson
66e215baee Remove spaces after cast operators
This fixes the outstanding mis-spaced cast operators to bring them
into line with the coding standards on mediawiki.org (and with the
more common usage within this codebase).

Bug: T149545
Change-Id: Ib7bcf95bbee83d20c05f6d621ce7b4e1fb58a347
2016-10-31 13:57:39 +00:00
Kunal Mehta
f6644c07cb registration: Improve license-name validation
Our hardcoded enum list in the extension.json schema for license-name
values was incomplete and did not cover the full SPDX license identifier
specification, which includes things like "AND" for specifying multiple
licenses.

Composer already has solid code in a library to do this validation, so
let's use it! This updates both the validateRegistrationFile.php and
ExtensionJsonValidationTest.php to use the composer/spdx-licenses
library (a new development dependency) to ensure the license-name field
is a valid SPDX identifier.

Also fix a silly typo in the validateRegistrationFile script which
prevented it from running, and use ::class so it will be easier to
detect typos like that in the future.

Bug: T146862
Change-Id: Ibb8973ed7950ae81c90558f9630f73746b2aff2c
2016-09-28 20:50:48 +00:00
Kunal Mehta
f86d2a63e4 Add structure test for ContentHandler::makeEmptyContent()
This adds a structure test that verifies all registered ContentHandlers
will return a valid content object (as determined by
Content::isValid()), when makeEmptyContent() is called. Additionally, if
the handler extends TextContentHandler, it will verify it is an instance
of TextContentHandler::getContentClass().

This is a structure test so it is run for content handlers created by
extensions as well.

Change-Id: Idd67d824f2f7cc1819b1d8b186be058e63c4513d
2016-09-10 01:55:18 -07:00
jenkins-bot
2a26e0de27 Merge "Upgrade justinrainbow/json-schema to ~3.0" 2016-08-23 21:33:56 +00:00
Florian Schmidt
0cef9623c5 Upgrade justinrainbow/json-schema to ~3.0
The release between 1.6.1 and 3.0.0 has a huge amount of code
maintenance changes, as well as internal optimization and some
"visible" changes (as well as the one mentioned in the linked
task).

However, it's a version jump over 2 major versions, which is,
by it's definition a major change ;). Nonetheless, the (for us)
important api has changed marginally: Instead of using the
JsonSchema\Uri\UriRetriever class to retrieve the schema, we now use
the $ref keyword to reference the json schema file (which also is
an internal optimization). In this way, we let the json-schema library
decide, how to resolve a ref (and the schema) instead of relying
on the UriRetriever api to be public and stable.

The versions also include various bug fixes (which, as far as I know,
doesn't apply to us).

I tested this change with various combinations of valid and invalid
extension.json schemas (version 2 as well as version 3). Given that
there were no major changes to the schema interpretation itself, and
the good test coverage of the library, there shouldn't be a high risk
because of this change.

The full list of changes can be found at:
https://github.com/justinrainbow/json-schema/compare/1.6.1...3.0.0

as well as the changelogs of the single versions:
https://github.com/justinrainbow/json-schema/releases

Bug: T141281
Depends-On: I5687286da9f7fa2bb2b84699fa43ab3c2547fe03
Change-Id: Ie37e2ebc48684783abf8d99d2f775ee6a5988da7
2016-08-23 21:22:21 +00:00