diff options
author | Kunal Mehta <legoktm@gmail.com> | 2014-08-28 23:31:44 -0700 |
---|---|---|
committer | Ori.livneh <ori@wikimedia.org> | 2014-08-30 00:24:37 +0000 |
commit | 8968d8787fee47739649ccb2e32e883cdd2b0f4d (patch) | |
tree | 3ae6c4f69ac594b41d66620f5c373145d20e9947 /tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php | |
parent | 08e50bcecd32e6646b2a07a356517feb733aad78 (diff) | |
download | mediawikicore-8968d8787fee47739649ccb2e32e883cdd2b0f4d.tar.gz mediawikicore-8968d8787fee47739649ccb2e32e883cdd2b0f4d.zip |
Check page_len in ResourceLoaderWikiModule::isKnownEmpty() for 'user' modules
In most cases, we just check whether the pages exist before saying
the module is not empty to avoid generating cached HTML without
the appropriate <script> or <link> tags.
However, for modules in the 'user' group, normal users cannot
delete their personal JavaScript/CSS pages, causing needless
extra requests, even though we know the pages are empty.
ResourceLoader::isKnownEmpty() now checks the page_len field
for modules in the 'user' group to check that there is
some actual content.
Bug: 68488
Change-Id: I0570f62887fd4642fd60367ae0b51d7dc19488ca
Diffstat (limited to 'tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php')
-rw-r--r-- | tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php new file mode 100644 index 000000000000..50f88c825f3a --- /dev/null +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php @@ -0,0 +1,67 @@ +<?php + +class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase { + + /** + * @covers ResourceLoaderWikiModule::isKnownEmpty + * @dataProvider provideIsKnownEmpty + */ + public function testIsKnownEmpty( $titleInfo, $group, $expected ) { + $module = $this->getMockBuilder( 'ResourceLoaderWikiModuleTestModule' ) + ->setMethods( array( 'getTitleInfo', 'getGroup' ) ) + ->getMock(); + $module->expects( $this->any() ) + ->method( 'getTitleInfo' ) + ->will( $this->returnValue( $titleInfo ) ); + $module->expects( $this->any() ) + ->method( 'getGroup' ) + ->will( $this->returnValue( $group ) ); + $context = $this->getMockBuilder( 'ResourceLoaderContext' ) + ->disableOriginalConstructor() + ->getMock(); + $this->assertEquals( $expected, $module->isKnownEmpty( $context ) ); + } + + public function provideIsKnownEmpty() { + return array( + // No valid pages + array( array(), 'test1', true ), + // 'site' module with a non-empty page + array( + array( + 'MediaWiki:Common.js' => array( + 'timestamp' => 123456789, + 'length' => 1234 + ) + ), 'site', false, + ), + // 'site' module with an empty page + array( + array( + 'MediaWiki:Monobook.js' => array( + 'timestamp' => 987654321, + 'length' => 0, + ), + ), 'site', false, + ), + // 'user' module with a non-empty page + array( + array( + 'User:FooBar/common.js' => array( + 'timestamp' => 246813579, + 'length' => 25, + ), + ), 'user', false, + ), + // 'user' module with an empty page + array( + array( + 'User:FooBar/monobook.js' => array( + 'timestamp' => 1357924680, + 'length' => 0, + ), + ), 'user', true, + ), + ); + } +} |