Commit graph

25 commits

Author SHA1 Message Date
Timo Tijhof
ae9c32b508 resourceloader: Add test for getVersionHash parent-definition requirement
Change-Id: I69cdfea96c1e64bd8a7495eb6e56d0aefbe37643
2018-06-26 16:24:31 +01:00
Timo Tijhof
96d25f6bcc resourceloader: Remove support for Module::getModifiedTime() and getModifiedHash()
Deprecated since 1.26. No subclasses in Wikimedia Git define these methods,
no calls to methods by this name in Wikimedia Git.

If a module subclass were to still define such a method, it is simply
not called anymore. The version hash system introduced in 1.26 will
still invalidate modules based on wgCacheEpoch.

Bug: T94074
Change-Id: I65b2a625a30f22c8a9d14a3505605546fa5bab83
2018-06-05 02:02:06 +01:00
Timo Tijhof
42d537503d resourceloader: Add @covers for covered deprecated methods
These are deprecated for extensions to implement, but still
supported and already triggered by the test cases. Previously
not mentioned because they were ignored by PHPUnit, but not anymore.

Change-Id: I594788e322bfd83be1e7847d3272d57c549f3e8b
2018-04-17 01:40:48 +01: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
Timo Tijhof
3d342d4deb resourceloader: Add support for modules sending preload headers
ResourceLoaderModule objects gain a new method getPreloadLinks() which
returns an array with the meta data required to build a Link rel=preload
header according to the current draft for W3C Preload.
<https://w3c.github.io/preload/>

Another implementation of this is already in use in OutputPage for
preloading the logo image.

This array is formatted by the ResourceLoaderModule::getHeaders method,
which is implemented as "final" at this time, thus restricting use to
the Link rel=preload header.

Headers are exposed and process-cached, like all other content
(scripts, styles, etc.), through ResourceLoaderModule::getModuleContent,
and aggregated by ResoureLoader::makeModuleResponse.

I had hoped for the getPreloadLinks to be stateless (not vary on $context).
Whether something should be preloaded and what, should not vary on the
skin or language. However, while that conceptually holds true, the exact
url for any given resource may still vary. Even the main use case for this
feature (T164299, preloading base modules request) require $context to pass
down skin and lang to the load.php url.

Add full test coverage and example documentation.

Bug: T164299
Change-Id: I2bfe0796ceaa0c82579c501f5b10e931f2175681
2017-08-03 03:57:00 +00:00
Timo Tijhof
483f13b226 resourceloader: Use "\n" instead of ";" as separator for scripts
This fixes two bugs:

* 1) When two modules are requested, and the first one ends with ";"
     inside a comment, the second module might become part of
     that comment.
* 2) A request with script=only where the requested module content
     ends in a statement without ";", but has a comment after it
     that does ends with a semicolon, then in debug=false, mw.loader.state()
     would be appended directly after the semicolon-less statement because
     the check is performed before minification.
     Previously:
     script> foo()
     script> // bar();
     states> mw.loader.state( {} );
     Became (minified separately):
     script> foo()
     states> mw.loader.state({});
     Became (concatenated)
     > foo()mw.loader.state();
     Which is invalid code.

Both of these are now fixed.

Bug: T162719
Change-Id: Ic8114c46ce232f5869400eaa40d3027003550533
2017-06-28 03:59:05 +00:00
Timo Tijhof
d3e31c7ea4 resourceloader: Add basic tests for getScript() and buildContent()
Bug: T162719
Change-Id: I37d64da77682adfef61e78033d639b623d7c9c2b
2017-06-26 22:15:17 -07:00
Fomafix
639176e01b ResourceLoaderModuleTest: Exchange expected and actual parameter
For assertEquals of PHPUnit the first parameter is $expected and the second
parameter is $actual.
https://phpunit.de/manual/current/en/appendixes.assertions.html#appendixes.assertions.assertEquals

Change-Id: Iad4b37ee74a03aa00f2dc14d3c474796b3191b51
2017-03-31 22:29:03 +02:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Timo Tijhof
9446f0cb2b resourceloader: Re-enable getVersionHash test
Shouldn't be flaky anymore as of 5d5b269e0e.

This reverts commit d151dc40ae.

Bug: T109394
Change-Id: Id94b6e71a747a5b9fe1fecd8145955fde4f39a9c
2015-12-09 20:52:58 +00:00
umherirrender
1647bb07fc Fix phpunit for wikis with $wgResourceLoaderValidateJS = false
1) ResourceLoaderModuleTest::testValidateScriptFile
Replace invalid syntax with error logging
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'var a = 'this is';
- {
-invalid'
+'mw.log.error("JavaScript parse error: Parse error: Unexpected token;
token } expected in file 'input' on line 3");'

Change-Id: I0271de4bf2d5bcc50eaf5c0e999e16e554985805
2015-12-07 17:38:28 +01:00
Timo Tijhof
d151dc40ae resourceloader: Disable flaky test ResourceLoaderModule::getVersionHash
Bug: T109394
Change-Id: I8e62d9e8326046a895588d9cc63f47e6c0d12eda
2015-10-20 02:58:12 +01:00
Timo Tijhof
047b60b96d resourceloader: Store relative instead of absolute paths in module_deps
Make paths stored in the module_deps table relative to $IP. This ensures that when
the MediaWiki install path changes and/or if the location of the extension or skins
directory changes, that ResourceLoader's internal model is still accurate.

Previously when these paths change, ResourceLoader would exhibit various bugs.

1. Unable to detect changes in the module (if the directory no longer exists).
2. Point #1 is usually preceeded by one last cache invalidation as the content hash
   of the file path changes (from a valid hash to an empty string).
3. Unnecessary cache invalidation (if both old and new directories exist). This
   happens when a file is both an entry point (in the 'scripts' or 'styles' array)
   and also a file dependency. At first they are de-duplicated by array_unique.
   But after the disk path changes, the next check will result in the old path
   being fetched from module_deps, and the new path from the live configuration.
   This causes two changes that result in needless cache invalidation:
   - The hash list contains one more item (T111481).
   - The hash list contains both the old and new version of a file.
     (or even alternate versions, e.g. when a change is backported to the old
     wmf branch; it also affects wikis on the new branch due to the stale
     file path still in the database).

It seems unusual to move a MediaWiki install, and usually we recommend third
parties to run update.php if site administrators do move their wiki. However
Wikimedia's deployment system implicitly moves the MediaWiki install continously
from e.g. "/srv/mediawiki/php-1.26wmf5" to "/srv/mediawiki/php-1.26wmf6".

This caused virtually all ResourceLoader caching layers to get invalidated every
week when another wmf-branch is deployed, thus breaking these file paths, which
changes the version hash, which then invalidates the cache.

Bug: T111481
Change-Id: I173a9820b3067c4a6598a4c8d77e239797d2659c
2015-09-30 00:25:27 +00:00
Reedy
58f0a7ee4e Wrap some long strings in tests/
Change-Id: I89d53c5051e5ee4bd8624df8ee2b25993090a7df
2015-09-26 21:01:59 +01:00
Timo Tijhof
370a7d5f39 resourceloader: Make tests less susceptible to timestamp races
getDefinitionSummary isn't the authoritive method to detect changes.
Using it as such may false cause something to appear detected or
undetected. Use getVersionHash() instead.

Thanks to Gilles for uncovering this bug.

Bug: T105476
Change-Id: Ibefc9fa8ffd9d45e29901d726801e8d4e008b66f
2015-07-10 13:59:52 +00:00
Timo Tijhof
1e4336d435 resourceloader: Add unit test for validateScriptFile()
Follows-up cd0dff5c00.

Change-Id: Ie208e58053048e932ef3f61f849148b1d88bc0be
2015-06-02 23:50:57 +01:00
Kunal Mehta
0e05ec5b31 Don't create Language objects during ResourceLoader tests
Mock calls to ResourceLoaderContext::getDirection(), which creates
Language objects to get the directionality of a language.

Change-Id: Ibe6da3013e658aa7cf596c1da2f8ca1314b7cdd3
2014-12-18 16:52:28 -08:00
Kunal Mehta
fe5170d32b Move tests into separate ResourceLoaderFileModuleTest
Change-Id: I2504867850b7e6bda2afb8c4fedbe6b8819bc15b
2014-10-22 17:16:47 +00:00
umherirrender
63dc5abc9a Fixed spacing
- Added space after reserved words: function, foreach, if
- Combined 'else if' into elseif
- Added braces to one-line statements
- Added spaces after comma, before parentheses

Change-Id: Ie5bbf680d6fbe0f0872dab2700c16b1394906a72
2014-08-27 18:31:50 +02:00
addshore
dcaa81c743 Fix phpcs errors in tests dir
Change-Id: I79fa3b8f92e958f4a0dc4fe892703f37d711ca95
2014-08-17 22:57:09 +01:00
Kunal Mehta
6a826fd6bf Register a fake skin instead of a 'vector' that will fail
Bug: 69639
Change-Id: Icd87520f7b6de337b009144420c3a430861d0833
2014-08-15 22:50:25 -07:00
Kunal Mehta
1154e1848f SkinFactory: register skins in Setup.php
This un-makes $wgValidSkinNames a legacy thing, and is
more backwards-compatible friendly.

Change-Id: I5c442f3c9e4ee7a4a3980fd02138ee756ef9fa7a
2014-08-13 13:43:09 +02:00
Bartosz Dziewoński
bfe9614992 ResourceLoaderModuleTest: Ensure 'vector' is a valid skin
Change-Id: I4c121339aec80a4c56042de7be85cf5f1748b9f0
2014-07-23 21:18:19 +00:00
Sam Smith
0bb3d2a499 Make ResourceLoaderFileModule#getAllStyleFiles include all skin styles
* Add the ResourceLoaderFileModule#getAllSkinStyleFiles method,
  which returns all of the skinStyles files for a given module
* The LessFileCompilationTest and checkLess.php script, which use
  the #getAllStyleFile method, now validate all LESS style files

Bug: 63343
Change-Id: Ib2eb5761919c648aea4ae58f8d0531799fe7982b
2014-06-17 19:38:58 +00:00
Timo Tijhof
9976cef4ed tests: Add ResourceLoaderTestCase and abstract context creation
Change-Id: Ib4b265256e60a2f2109da73dc7edba6a75587ce2
2014-03-07 20:09:59 +01:00
Renamed from tests/phpunit/includes/ResourceLoaderModuleTest.php (Browse further)