2014-03-07 18:29:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class ResourceLoaderStartupModuleTest extends ResourceLoaderTestCase {
|
|
|
|
|
|
|
|
|
|
public static function provideGetModuleRegistrations() {
|
|
|
|
|
return array(
|
|
|
|
|
array( array(
|
|
|
|
|
'msg' => 'Empty registry',
|
|
|
|
|
'modules' => array(),
|
|
|
|
|
'out' => '
|
|
|
|
|
mw.loader.addSource( {
|
2014-08-25 08:02:48 +00:00
|
|
|
"local": "/w/load.php"
|
2014-03-07 18:29:23 +00:00
|
|
|
} );mw.loader.register( [] );'
|
|
|
|
|
) ),
|
|
|
|
|
array( array(
|
|
|
|
|
'msg' => 'Basic registry',
|
|
|
|
|
'modules' => array(
|
|
|
|
|
'test.blank' => new ResourceLoaderTestModule(),
|
|
|
|
|
),
|
|
|
|
|
'out' => '
|
|
|
|
|
mw.loader.addSource( {
|
2014-08-25 08:02:48 +00:00
|
|
|
"local": "/w/load.php"
|
2014-03-07 18:29:23 +00:00
|
|
|
} );mw.loader.register( [
|
|
|
|
|
[
|
|
|
|
|
"test.blank",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400
|
2014-03-07 18:29:23 +00:00
|
|
|
]
|
|
|
|
|
] );',
|
|
|
|
|
) ),
|
|
|
|
|
array( array(
|
|
|
|
|
'msg' => 'Group signature',
|
|
|
|
|
'modules' => array(
|
|
|
|
|
'test.blank' => new ResourceLoaderTestModule(),
|
|
|
|
|
'test.group.foo' => new ResourceLoaderTestModule( array( 'group' => 'x-foo' ) ),
|
|
|
|
|
'test.group.bar' => new ResourceLoaderTestModule( array( 'group' => 'x-bar' ) ),
|
|
|
|
|
),
|
|
|
|
|
'out' => '
|
|
|
|
|
mw.loader.addSource( {
|
2014-08-25 08:02:48 +00:00
|
|
|
"local": "/w/load.php"
|
2014-03-07 18:29:23 +00:00
|
|
|
} );mw.loader.register( [
|
|
|
|
|
[
|
|
|
|
|
"test.blank",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400
|
2014-03-07 18:29:23 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"test.group.foo",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400,
|
2014-03-07 18:29:23 +00:00
|
|
|
[],
|
|
|
|
|
"x-foo"
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"test.group.bar",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400,
|
2014-03-07 18:29:23 +00:00
|
|
|
[],
|
|
|
|
|
"x-bar"
|
|
|
|
|
]
|
|
|
|
|
] );'
|
|
|
|
|
) ),
|
|
|
|
|
array( array(
|
|
|
|
|
'msg' => 'Different target (non-test should not be registered)',
|
|
|
|
|
'modules' => array(
|
|
|
|
|
'test.blank' => new ResourceLoaderTestModule(),
|
|
|
|
|
'test.target.foo' => new ResourceLoaderTestModule( array( 'targets' => array( 'x-foo' ) ) ),
|
|
|
|
|
),
|
|
|
|
|
'out' => '
|
|
|
|
|
mw.loader.addSource( {
|
2014-08-25 08:02:48 +00:00
|
|
|
"local": "/w/load.php"
|
2014-03-07 18:29:23 +00:00
|
|
|
} );mw.loader.register( [
|
|
|
|
|
[
|
|
|
|
|
"test.blank",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400
|
2014-03-07 18:29:23 +00:00
|
|
|
]
|
|
|
|
|
] );'
|
|
|
|
|
) ),
|
|
|
|
|
array( array(
|
|
|
|
|
'msg' => 'Foreign source',
|
|
|
|
|
'sources' => array(
|
|
|
|
|
'example' => array(
|
|
|
|
|
'loadScript' => 'http://example.org/w/load.php',
|
|
|
|
|
'apiScript' => 'http://example.org/w/api.php',
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
'modules' => array(
|
|
|
|
|
'test.blank' => new ResourceLoaderTestModule( array( 'source' => 'example' ) ),
|
|
|
|
|
),
|
|
|
|
|
'out' => '
|
|
|
|
|
mw.loader.addSource( {
|
2014-08-25 08:02:48 +00:00
|
|
|
"local": "/w/load.php",
|
|
|
|
|
"example": "http://example.org/w/load.php"
|
2014-03-07 18:29:23 +00:00
|
|
|
} );mw.loader.register( [
|
|
|
|
|
[
|
|
|
|
|
"test.blank",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400,
|
2014-03-07 18:29:23 +00:00
|
|
|
[],
|
|
|
|
|
null,
|
|
|
|
|
"example"
|
|
|
|
|
]
|
|
|
|
|
] );'
|
2014-04-30 21:06:51 +00:00
|
|
|
) ),
|
|
|
|
|
array( array(
|
|
|
|
|
'msg' => 'Conditional dependency function',
|
|
|
|
|
'modules' => array(
|
|
|
|
|
'test.x.core' => new ResourceLoaderTestModule(),
|
|
|
|
|
'test.x.polyfill' => new ResourceLoaderTestModule( array(
|
|
|
|
|
'skipFunction' => 'return true;'
|
|
|
|
|
) ),
|
|
|
|
|
'test.y.polyfill' => new ResourceLoaderTestModule( array(
|
|
|
|
|
'skipFunction' =>
|
|
|
|
|
'return !!(' .
|
|
|
|
|
' window.JSON &&' .
|
|
|
|
|
' JSON.parse &&' .
|
|
|
|
|
' JSON.stringify' .
|
|
|
|
|
');'
|
|
|
|
|
) ),
|
|
|
|
|
'test.z.foo' => new ResourceLoaderTestModule( array(
|
|
|
|
|
'dependencies' => array(
|
|
|
|
|
'test.x.core',
|
2014-10-25 00:18:24 +00:00
|
|
|
'test.x.polyfill',
|
|
|
|
|
'test.y.polyfill',
|
2014-04-30 21:06:51 +00:00
|
|
|
),
|
|
|
|
|
) ),
|
|
|
|
|
),
|
|
|
|
|
'out' => '
|
|
|
|
|
mw.loader.addSource( {
|
2014-08-25 08:02:48 +00:00
|
|
|
"local": "/w/load.php"
|
2014-04-30 21:06:51 +00:00
|
|
|
} );mw.loader.register( [
|
|
|
|
|
[
|
|
|
|
|
"test.x.core",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400
|
2014-04-30 21:06:51 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"test.x.polyfill",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400,
|
2014-04-30 21:06:51 +00:00
|
|
|
[],
|
|
|
|
|
null,
|
2014-12-09 00:29:19 +00:00
|
|
|
null,
|
2014-04-30 21:06:51 +00:00
|
|
|
"return true;"
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"test.y.polyfill",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400,
|
2014-04-30 21:06:51 +00:00
|
|
|
[],
|
|
|
|
|
null,
|
2014-12-09 00:29:19 +00:00
|
|
|
null,
|
2014-04-30 21:06:51 +00:00
|
|
|
"return !!( window.JSON \u0026\u0026 JSON.parse \u0026\u0026 JSON.stringify);"
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"test.z.foo",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400,
|
2014-04-30 21:06:51 +00:00
|
|
|
[
|
2014-10-25 00:18:24 +00:00
|
|
|
0,
|
|
|
|
|
1,
|
|
|
|
|
2
|
2014-04-30 21:06:51 +00:00
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
] );',
|
2014-03-07 18:29:23 +00:00
|
|
|
) ),
|
|
|
|
|
array( array(
|
|
|
|
|
// This may seem like an edge case, but a plain MediaWiki core install
|
|
|
|
|
// with a few extensions installed is likely far more complex than this
|
|
|
|
|
// even, not to mention an install like Wikipedia.
|
|
|
|
|
// TODO: Make this even more realistic.
|
|
|
|
|
'msg' => 'Advanced (everything combined)',
|
|
|
|
|
'sources' => array(
|
|
|
|
|
'example' => array(
|
|
|
|
|
'loadScript' => 'http://example.org/w/load.php',
|
|
|
|
|
'apiScript' => 'http://example.org/w/api.php',
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
'modules' => array(
|
|
|
|
|
'test.blank' => new ResourceLoaderTestModule(),
|
|
|
|
|
'test.x.core' => new ResourceLoaderTestModule(),
|
|
|
|
|
'test.x.util' => new ResourceLoaderTestModule( array(
|
|
|
|
|
'dependencies' => array(
|
|
|
|
|
'test.x.core',
|
|
|
|
|
),
|
|
|
|
|
) ),
|
|
|
|
|
'test.x.foo' => new ResourceLoaderTestModule( array(
|
|
|
|
|
'dependencies' => array(
|
|
|
|
|
'test.x.core',
|
|
|
|
|
),
|
|
|
|
|
) ),
|
|
|
|
|
'test.x.bar' => new ResourceLoaderTestModule( array(
|
|
|
|
|
'dependencies' => array(
|
|
|
|
|
'test.x.core',
|
|
|
|
|
'test.x.util',
|
|
|
|
|
),
|
|
|
|
|
) ),
|
|
|
|
|
'test.x.quux' => new ResourceLoaderTestModule( array(
|
|
|
|
|
'dependencies' => array(
|
|
|
|
|
'test.x.foo',
|
|
|
|
|
'test.x.bar',
|
|
|
|
|
'test.x.util',
|
2013-07-07 22:51:15 +00:00
|
|
|
'test.x.unknown',
|
2014-03-07 18:29:23 +00:00
|
|
|
),
|
|
|
|
|
) ),
|
|
|
|
|
'test.group.foo.1' => new ResourceLoaderTestModule( array(
|
|
|
|
|
'group' => 'x-foo',
|
|
|
|
|
) ),
|
|
|
|
|
'test.group.foo.2' => new ResourceLoaderTestModule( array(
|
|
|
|
|
'group' => 'x-foo',
|
|
|
|
|
) ),
|
|
|
|
|
'test.group.bar.1' => new ResourceLoaderTestModule( array(
|
|
|
|
|
'group' => 'x-bar',
|
|
|
|
|
) ),
|
|
|
|
|
'test.group.bar.2' => new ResourceLoaderTestModule( array(
|
|
|
|
|
'group' => 'x-bar',
|
|
|
|
|
'source' => 'example',
|
|
|
|
|
) ),
|
|
|
|
|
'test.target.foo' => new ResourceLoaderTestModule( array(
|
|
|
|
|
'targets' => array( 'x-foo' ),
|
|
|
|
|
) ),
|
|
|
|
|
'test.target.bar' => new ResourceLoaderTestModule( array(
|
|
|
|
|
'source' => 'example',
|
|
|
|
|
'targets' => array( 'x-foo' ),
|
|
|
|
|
) ),
|
|
|
|
|
),
|
|
|
|
|
'out' => '
|
|
|
|
|
mw.loader.addSource( {
|
2014-08-25 08:02:48 +00:00
|
|
|
"local": "/w/load.php",
|
|
|
|
|
"example": "http://example.org/w/load.php"
|
2014-03-07 18:29:23 +00:00
|
|
|
} );mw.loader.register( [
|
|
|
|
|
[
|
|
|
|
|
"test.blank",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400
|
2014-03-07 18:29:23 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"test.x.core",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400
|
2014-03-07 18:29:23 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"test.x.util",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400,
|
2014-03-07 18:29:23 +00:00
|
|
|
[
|
2014-10-25 00:18:24 +00:00
|
|
|
1
|
2014-03-07 18:29:23 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"test.x.foo",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400,
|
2014-03-07 18:29:23 +00:00
|
|
|
[
|
2014-10-25 00:18:24 +00:00
|
|
|
1
|
2014-03-07 18:29:23 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"test.x.bar",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400,
|
2014-03-07 18:29:23 +00:00
|
|
|
[
|
2014-10-25 00:18:24 +00:00
|
|
|
2
|
2014-03-07 18:29:23 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"test.x.quux",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400,
|
2014-03-07 18:29:23 +00:00
|
|
|
[
|
2014-10-25 00:18:24 +00:00
|
|
|
3,
|
|
|
|
|
4,
|
2013-07-07 22:51:15 +00:00
|
|
|
"test.x.unknown"
|
2014-03-07 18:29:23 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"test.group.foo.1",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400,
|
2014-03-07 18:29:23 +00:00
|
|
|
[],
|
|
|
|
|
"x-foo"
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"test.group.foo.2",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400,
|
2014-03-07 18:29:23 +00:00
|
|
|
[],
|
|
|
|
|
"x-foo"
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"test.group.bar.1",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400,
|
2014-03-07 18:29:23 +00:00
|
|
|
[],
|
|
|
|
|
"x-bar"
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"test.group.bar.2",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400,
|
2014-03-07 18:29:23 +00:00
|
|
|
[],
|
|
|
|
|
"x-bar",
|
|
|
|
|
"example"
|
|
|
|
|
]
|
|
|
|
|
] );'
|
|
|
|
|
) ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetModuleRegistrations
|
2014-11-22 17:54:47 +00:00
|
|
|
* @covers ResourceLoaderStartupModule::compileUnresolvedDependencies
|
2014-03-07 18:29:23 +00:00
|
|
|
* @covers ResourceLoaderStartUpModule::getModuleRegistrations
|
2013-07-07 22:51:15 +00:00
|
|
|
* @covers ResourceLoader::makeLoaderSourcesScript
|
|
|
|
|
* @covers ResourceLoader::makeLoaderRegisterScript
|
2014-03-07 18:29:23 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetModuleRegistrations( $case ) {
|
|
|
|
|
if ( isset( $case['sources'] ) ) {
|
|
|
|
|
$this->setMwGlobals( 'wgResourceLoaderSources', $case['sources'] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$context = self::getResourceLoaderContext();
|
|
|
|
|
$rl = $context->getResourceLoader();
|
|
|
|
|
|
|
|
|
|
$rl->register( $case['modules'] );
|
|
|
|
|
|
2014-08-07 10:25:56 +00:00
|
|
|
$module = new ResourceLoaderStartUpModule();
|
2014-03-07 18:29:23 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
ltrim( $case['out'], "\n" ),
|
2014-08-07 10:25:56 +00:00
|
|
|
$module->getModuleRegistrations( $context ),
|
2014-03-07 18:29:23 +00:00
|
|
|
$case['msg']
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-30 21:06:51 +00:00
|
|
|
public static function provideRegistrations() {
|
|
|
|
|
return array(
|
|
|
|
|
array( array(
|
|
|
|
|
'test.blank' => new ResourceLoaderTestModule(),
|
|
|
|
|
'test.min' => new ResourceLoaderTestModule( array(
|
|
|
|
|
'skipFunction' =>
|
|
|
|
|
'return !!(' .
|
|
|
|
|
' window.JSON &&' .
|
|
|
|
|
' JSON.parse &&' .
|
|
|
|
|
' JSON.stringify' .
|
|
|
|
|
');',
|
|
|
|
|
'dependencies' => array(
|
|
|
|
|
'test.blank',
|
|
|
|
|
),
|
|
|
|
|
) ),
|
|
|
|
|
) )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideRegistrations
|
|
|
|
|
*/
|
|
|
|
|
public function testRegistrationsMinified( $modules ) {
|
|
|
|
|
$this->setMwGlobals( 'wgResourceLoaderDebug', false );
|
|
|
|
|
|
|
|
|
|
$context = self::getResourceLoaderContext();
|
|
|
|
|
$rl = $context->getResourceLoader();
|
|
|
|
|
$rl->register( $modules );
|
2014-08-07 10:25:56 +00:00
|
|
|
$module = new ResourceLoaderStartUpModule();
|
2014-04-30 21:06:51 +00:00
|
|
|
$this->assertEquals(
|
2014-08-25 08:02:48 +00:00
|
|
|
'mw.loader.addSource({"local":"/w/load.php"});'
|
2014-04-30 21:06:51 +00:00
|
|
|
. 'mw.loader.register(['
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
. '["test.blank",1388534400],'
|
2014-12-09 00:29:19 +00:00
|
|
|
. '["test.min",1388534400,[0],null,null,'
|
2014-04-30 21:06:51 +00:00
|
|
|
. '"return!!(window.JSON\u0026\u0026JSON.parse\u0026\u0026JSON.stringify);"'
|
|
|
|
|
. ']]);',
|
2014-08-07 10:25:56 +00:00
|
|
|
$module->getModuleRegistrations( $context ),
|
2014-04-30 21:06:51 +00:00
|
|
|
'Minified output'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideRegistrations
|
|
|
|
|
*/
|
|
|
|
|
public function testRegistrationsUnminified( $modules ) {
|
|
|
|
|
$context = self::getResourceLoaderContext();
|
|
|
|
|
$rl = $context->getResourceLoader();
|
|
|
|
|
$rl->register( $modules );
|
2014-08-07 10:25:56 +00:00
|
|
|
$module = new ResourceLoaderStartUpModule();
|
2014-04-30 21:06:51 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'mw.loader.addSource( {
|
2014-08-25 08:02:48 +00:00
|
|
|
"local": "/w/load.php"
|
2014-04-30 21:06:51 +00:00
|
|
|
} );mw.loader.register( [
|
|
|
|
|
[
|
|
|
|
|
"test.blank",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400
|
2014-04-30 21:06:51 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"test.min",
|
resourceloader: Make timestamp handling more consistent
* Use time() instead of:
- wfTimestamp()
- wfTimestamp( TS_UNIX )
- wfTimestamp( TS_UNIX, 0 )
- wfTimestamp( TS_UNIX, time() )
- intval( wfTimestamp( TS_UNIX, time() ) )
* Consistently use 1 as default instead of 0. Previously the
unwritten convention was that anything "final" max()'ed with 1,
and any internal method would use 0, but this wasn't applied
consistently made it fragile. There doesn't seem to be any
value in returning 0 only to have it maxed up to 1 (because if
the 0 would ever make it out alive, we'd be in trouble).
* wfTimestamp returns a string for TS_UNIX. In PHP this doesn't
matter much. In fact, max() takes number-like integers so
transparently, it even preserves it:
> max( 1, 3, '2' );
< 3
> max( 1, '3', 2 );
< "3"
Just cast it in one place at the very end (StartupModule)
instead of doing intval( wfTimestamp() ).
* Fix weird documentation claiming getModifiedTime can return
an array, or mixed.
* Remove 'version > 1 ? version : 1' logic in
ResourceLoader::makeLoaderRegisterScript. The client doesn't
have "0 means now" behaviour so this isn't needed. And the method
was only doing it for variadic argument calls.
Removal of quotes around timestamps reduced the size of the startup
module from 26.8KB to 25.9KB before gzip. After gzip the size was
and still is 5.7KB, though. (From 5456 bytes to 5415 bytes.)
Change-Id: If92ca3e7511e78fa779f2f2701e2ab24db78c8a8
2014-12-05 20:28:54 +00:00
|
|
|
1388534400,
|
2014-04-30 21:06:51 +00:00
|
|
|
[
|
2014-10-25 00:18:24 +00:00
|
|
|
0
|
2014-04-30 21:06:51 +00:00
|
|
|
],
|
|
|
|
|
null,
|
2014-12-09 00:29:19 +00:00
|
|
|
null,
|
2014-04-30 21:06:51 +00:00
|
|
|
"return !!( window.JSON \u0026\u0026 JSON.parse \u0026\u0026 JSON.stringify);"
|
|
|
|
|
]
|
|
|
|
|
] );',
|
2014-08-07 10:25:56 +00:00
|
|
|
$module->getModuleRegistrations( $context ),
|
2014-04-30 21:06:51 +00:00
|
|
|
'Unminified output'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-07 18:29:23 +00:00
|
|
|
}
|