jenkins-bot has submitted this change and it was merged.
Change subject: Add tests for OutputPage::makeResourceLoaderLink()
......................................................................
Add tests for OutputPage::makeResourceLoaderLink()
Change-Id: I22dc7fd1003f07ab0be61bb4645b45a9db9f2548
---
M tests/phpunit/ResourceLoaderTestCase.php
M tests/phpunit/includes/OutputPageTest.php
2 files changed, 94 insertions(+), 0 deletions(-)
Approvals:
Krinkle: Looks good to me, approved
Legoktm: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/tests/phpunit/ResourceLoaderTestCase.php
b/tests/phpunit/ResourceLoaderTestCase.php
index daf4bd9..f316f56 100644
--- a/tests/phpunit/ResourceLoaderTestCase.php
+++ b/tests/phpunit/ResourceLoaderTestCase.php
@@ -43,6 +43,8 @@
protected $dependencies = array();
protected $group = null;
protected $source = 'local';
+ protected $script = '';
+ protected $styles = '';
protected $skipFunction = null;
protected $targets = array( 'test' );
@@ -52,6 +54,14 @@
}
}
+ public function getScript( ResourceLoaderContext $context ) {
+ return $this->script;
+ }
+
+ public function getStyles( ResourceLoaderContext $context ) {
+ return array( '' => $this->styles );
+ }
+
public function getDependencies() {
return $this->dependencies;
}
diff --git a/tests/phpunit/includes/OutputPageTest.php
b/tests/phpunit/includes/OutputPageTest.php
index 385cee5..542b3d6 100644
--- a/tests/phpunit/includes/OutputPageTest.php
+++ b/tests/phpunit/includes/OutputPageTest.php
@@ -135,4 +135,88 @@
'message' => 'On request with handheld querystring and
media is screen, returns null'
) );
}
+
+ public static function provideMakeResourceLoaderLink() {
+ return array(
+ // Load module script only
+ array(
+ array( 'test.foo',
ResourceLoaderModule::TYPE_SCRIPTS ),
+ '<script
src="http://127.0.0.1:8080/w/load.php?debug=false&lang=en&modules=test.foo&only=scripts&skin=vector&*"></script>
+'
+ ),
+ // Load module styles only
+ // This also tests the order the modules are put into
the url
+ array(
+ array( array( 'test.baz', 'test.foo',
'test.bar' ), ResourceLoaderModule::TYPE_STYLES ),
+ '<link rel=stylesheet
href="http://127.0.0.1:8080/w/load.php?debug=false&lang=en&modules=test.bar%2Cbaz%2Cfoo&only=styles&skin=vector&*">
+'
+ ),
+ // Load private module (combined)
+ array(
+ array( 'test.quux',
ResourceLoaderModule::TYPE_COMBINED ),
+ '<script>if(window.mw){
+mw.loader.implement("test.quux",function($,jQuery){mw.test.baz({token:123});},{"css":[".mw-icon{transition:none}\n/*
cache key:
wiki:resourceloader:filter:minify-css:7:fd8ea20b3336b2bfb230c789d430067a
*/"]},{});
+/* cache key:
wiki:resourceloader:filter:minify-js:7:274ccee17be73cd5f4dda5dc2a819188 */
+}</script>
+'
+ ),
+ // Load module script with with ESI
+ array(
+ array( 'test.foo',
ResourceLoaderModule::TYPE_SCRIPTS, true ),
+ '<script><esi:include
src="http://127.0.0.1:8080/w/load.php?debug=false&lang=en&modules=test.foo&only=scripts&skin=vector&*"
/></script>
+'
+ ),
+ // Load module styles with with ESI
+ array(
+ array( 'test.foo',
ResourceLoaderModule::TYPE_STYLES, true ),
+ '<style><esi:include
src="http://127.0.0.1:8080/w/load.php?debug=false&lang=en&modules=test.foo&only=styles&skin=vector&*"
/></style>
+',
+ ),
+ );
+ }
+
+
+ /**
+ * @dataProvider provideMakeResourceLoaderLink
+ * @covers OutputPage::makeResourceLoaderLink
+ */
+ public function testMakeResourceLoaderLink( $args, $expectedHtml) {
+ $this->setMwGlobals( array(
+ 'wgResourceLoaderUseESI' => true,
+ 'wgLoadScript' => 'http://127.0.0.1:8080/w/load.php',
+ // Affects whether CDATA is inserted
+ 'wgWellFormedXml' => false,
+ // Cache key is based on database name, and affects
output;
+ // this test should not touch the database anyways.
+ 'wgDBname' => 'wiki',
+ 'wgDBprefix' => '',
+ ) );
+ $class = new ReflectionClass( 'OutputPage' );
+ $method = $class->getMethod( 'makeResourceLoaderLink' );
+ $method->setAccessible( true );
+ $ctx = new RequestContext();
+ $out = new OutputPage( $ctx );
+ $rl = $out->getResourceLoader();
+ $rl->register( array(
+ 'test.foo' => new ResourceLoaderTestModule(array(
+ 'script' => 'mw.test.foo( { a: true } );',
+ 'styles' => '.mw-test-foo { content: "style";
}',
+ )),
+ 'test.bar' => new ResourceLoaderTestModule(array(
+ 'script' => 'mw.test.bar( { a: true } );',
+ 'styles' => '.mw-test-bar { content: "style";
}',
+ )),
+ 'test.baz' => new ResourceLoaderTestModule(array(
+ 'script' => 'mw.test.baz( { a: true } );',
+ 'styles' => '.mw-test-baz { content: "style";
}',
+ )),
+ 'test.quux' => new ResourceLoaderTestModule(array(
+ 'script' => 'mw.test.baz( { token: 123 } );',
+ 'styles' => '/* pref-animate=off */ .mw-icon {
transition: none; }',
+ 'group' => 'private',
+ )),
+ ) );
+ $links = $method->invokeArgs( $out, $args );
+ $this->assertEquals( $expectedHtml, $links['html'] );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/142830
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I22dc7fd1003f07ab0be61bb4645b45a9db9f2548
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits