View source
<?php
namespace Drupal\xautoload\Tests\Mock;
use Drupal\xautoload\DrupalSystem\DrupalSystemInterface;
use Drupal\xautoload\Tests\VirtualDrupal\DrupalComponentContainer;
use Drupal\xautoload\Tests\VirtualDrupal\PureFunctions;
class MockDrupalSystem implements DrupalSystemInterface {
private $components;
private $variables = array();
function __construct(DrupalComponentContainer $components) {
$this->components = $components;
}
function variableSet($name, $value) {
$this->variables[$name] = $value;
}
function variableGet($name, $default = NULL) {
return isset($this->variables[$name]) ? $this->variables[$name] : $default;
}
function drupalGetFilename($type, $name) {
return $this->components->DrupalGetFilename
->drupalGetFilename($type, $name);
}
function drupalGetPath($type, $name) {
return $this->components->DrupalGetFilename
->drupalGetPath($type, $name);
}
function getExtensionTypes($extension_names) {
return array_fill_keys($extension_names, 'module');
}
function getActiveExtensions() {
return $this->components->SystemTable
->getActiveExtensions();
}
function moduleList($refresh = FALSE, $bootstrap_refresh = FALSE, $sort = FALSE) {
return $this->components->ModuleList
->moduleList($refresh, $bootstrap_refresh, $sort);
}
function moduleInvoke($module, $hook) {
$args = func_get_args();
switch (count($args)) {
case 2:
return PureFunctions::moduleInvoke($module, $hook);
case 3:
return PureFunctions::moduleInvoke($module, $hook, $args[2]);
case 4:
return PureFunctions::moduleInvoke($module, $hook, $args[2], $args[3]);
default:
throw new \Exception("More arguments than expected.");
}
}
function moduleInvokeAll($hook) {
$args = func_get_args();
call_user_func_array(array(
$this->components->HookSystem,
'moduleInvokeAll',
), $args);
}
function moduleImplements($hook) {
return $this->components->HookSystem
->moduleImplements($hook);
}
function drupalAlter($hook, &$data) {
$args = func_get_args();
assert($hook === array_shift($args));
assert($data === array_shift($args));
while (count($args) < 3) {
$args[] = NULL;
}
$this->components->HookSystem
->drupalAlter($hook, $data, $args[0], $args[1], $args[2]);
}
function moduleLoadInclude($type, $module, $name = NULL) {
if (!isset($name)) {
$name = $module;
}
$file = $this
->drupalGetPath('module', $module) . "/{$name}.{$type}";
if (is_file($file)) {
require_once $file;
return $file;
}
return FALSE;
}
public function resetModuleImplementsCache() {
$this->components->HookSystem
->moduleImplementsReset();
}
function getLibrariesInfo() {
$this->components->LibrariesInfo
->resetLibrariesInfo();
return $this->components->LibrariesInfo
->getLibrariesInfo();
}
function librariesGetPath($name) {
return $this->components->LibrariesInfo
->librariesGetPath($name);
}
public function installSetModuleWeight($weight) {
$this->components->SystemTable
->moduleSetWeight('xautoload', $weight);
$this->components->SystemListReset
->systemListReset();
}
public function cacheGet($cid, $bin = 'cache') {
return $this->components->Cache
->cacheGet($cid, $bin);
}
public function cacheSet($cid, $data, $bin = 'cache') {
$this->components->Cache
->cacheSet($cid, $data, $bin);
}
public function cacheClearAll($cid = NULL, $bin = NULL) {
$this->components->Cache
->cacheClearAll($cid, $bin);
}
public function drupalStaticReset($key) {
$this->components->DrupalStatic
->resetKey($key);
}
}