Simplify ResourceLoaderULSModule with content-based versioning

* Remove manual tracking of when a hash is first seen.
  ResourceLoader is no longer time-based, rather it is content based.
  Except where a timestamp is actually wanted as key, a hash is all
  we need. The default implementation of simply calling getScript()
  and hashing its output suffices, and isn't a performance problem
  in this case.

* Also simplify getScript() by passing an object to 'mw.config.set'.
  Instead of multiple calls for each key/value. This is a no-op
  now because there is only one key.

* Fix inaccurate class comment that was copied from an unrelated
  module in MediaWiki core.

Change-Id: I9bb82cadd9caa7e584e20dd49ce30b64218326c4
This commit is contained in:
Timo Tijhof
2016-08-22 22:26:15 -07:00
parent 694f3719a8
commit f06ac3efca
2 changed files with 9 additions and 93 deletions

View File

@@ -1,49 +0,0 @@
<?php
/**
* PHP Unit tests for ResourceLoaderULSModule class.
*
* @file
* @ingroup Extensions
*
* @author Santhosh Thottingal
*/
/**
* @covers ResourceLoaderULSModule
*/
class ResourceLoaderULSModuleMemcachedTest extends MediaWikiTestCase {
/**
* Test whether the modified time of the RL module varies
* correctly with language code.
* @covers ResourceLoaderSchemaModule::getModifiedTime
*/
public function testModifiedTime() {
$request = new WebRequest();
$module = new ResourceLoaderULSModule();
$request->setVal( 'lang', 'he' );
$context = new ResourceLoaderContext(
new ResourceLoader(), $request );
$mtimeHebrew = $module->getModifiedTime( $context );
// sleep for 1 second
sleep( 1 );
$request->setVal( 'lang', 'hi' );
$context = new ResourceLoaderContext( new ResourceLoader(), $request );
$mtimeHindi = $module->getModifiedTime( $context );
$this->assertGreaterThan( $mtimeHebrew, $mtimeHindi, 'Hindi has recent timestamp than Hebrew' );
// sleep for 1 second
sleep( 1 );
$request->setVal( 'lang', 'he' );
$context = new ResourceLoaderContext( new ResourceLoader(), $request );
$mtimeHebrewNew = $module->getModifiedTime( $context );
$this->assertEquals( $mtimeHebrewNew, $mtimeHebrew, 'Hebrew timestamp remained same' );
// sleep for 1 second
sleep( 1 );
$request->setVal( 'lang', 'hi' );
$context = new ResourceLoaderContext( new ResourceLoader(), $request );
$mtimeHindiNew = $module->getModifiedTime( $context );
$this->assertEquals( $mtimeHindi, $mtimeHindiNew, 'Hindi timestamp remained same' );
}
}