public function testGetHash()
 {
     $context = self::getResourceLoaderContext();
     $derived = new DerivativeResourceLoaderContext($context);
     $derived->setLanguage('nl');
     // Assert that subclass is able to clear parent class "hash" member
     $this->assertEquals($derived->getHash(), 'nl|fallback|||scripts|||||');
 }
 /**
  * Get a string identifying the current version of this module in a given context.
  *
  * Whenever anything happens that changes the module's response (e.g. scripts, styles, and
  * messages) this value must change. This value is used to store module responses in cache.
  * (Both client-side and server-side.)
  *
  * It is not recommended to override this directly. Use getDefinitionSummary() instead.
  * If overridden, one must call the parent getVersionHash(), append data and re-hash.
  *
  * This method should be quick because it is frequently run by ResourceLoaderStartUpModule to
  * propagate changes to the client and effectively invalidate cache.
  *
  * For backward-compatibility, the following optional data providers are automatically included:
  *
  * - getModifiedTime()
  * - getModifiedHash()
  *
  * @since 1.26
  * @param ResourceLoaderContext $context
  * @return string Hash (should use ResourceLoader::makeHash)
  */
 public function getVersionHash(ResourceLoaderContext $context)
 {
     // The startup module produces a manifest with versions representing the entire module.
     // Typically, the request for the startup module itself has only=scripts. That must apply
     // only to the startup module content, and not to the module version computed here.
     $context = new DerivativeResourceLoaderContext($context);
     $context->setModules(array());
     // Version hash must cover all resources, regardless of startup request itself.
     $context->setOnly(null);
     // Compute version hash based on content, not debug urls.
     $context->setDebug(false);
     // Cache this somewhat expensive operation. Especially because some classes
     // (e.g. startup module) iterate more than once over all modules to get versions.
     $contextHash = $context->getHash();
     if (!array_key_exists($contextHash, $this->versionHash)) {
         if ($this->enableModuleContentVersion()) {
             // Detect changes directly
             $str = json_encode($this->getModuleContent($context));
         } else {
             // Infer changes based on definition and other metrics
             $summary = $this->getDefinitionSummary($context);
             if (!isset($summary['_cacheEpoch'])) {
                 throw new LogicException('getDefinitionSummary must call parent method');
             }
             $str = json_encode($summary);
             $mtime = $this->getModifiedTime($context);
             if ($mtime !== null) {
                 // Support: MediaWiki 1.25 and earlier
                 $str .= strval($mtime);
             }
             $mhash = $this->getModifiedHash($context);
             if ($mhash !== null) {
                 // Support: MediaWiki 1.25 and earlier
                 $str .= strval($mhash);
             }
         }
         $this->versionHash[$contextHash] = ResourceLoader::makeHash($str);
     }
     return $this->versionHash[$contextHash];
 }