wiki.techinc.nl/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php
Kunal Mehta 8968d8787f 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
2014-08-30 00:24:37 +00:00

67 lines
1.6 KiB
PHP

<?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,
),
);
}
}