You are here

class MockDrupalSystem in X Autoload 7.5

Hierarchy

Expanded class hierarchy of MockDrupalSystem

2 files declare their use of MockDrupalSystem
DrupalComponentContainer.php in tests/src/VirtualDrupal/DrupalComponentContainer.php
DrupalEnvironment.php in tests/src/VirtualDrupal/DrupalEnvironment.php

File

tests/src/Mock/MockDrupalSystem.php, line 9

Namespace

Drupal\xautoload\Tests\Mock
View source
class MockDrupalSystem implements DrupalSystemInterface {

  /**
   * @var DrupalComponentContainer
   */
  private $components;

  /**
   * @var array
   */
  private $variables = array();

  /**
   * @param DrupalComponentContainer $components
   */
  function __construct(DrupalComponentContainer $components) {
    $this->components = $components;
  }

  /**
   * {@inheritdoc}
   */
  function variableSet($name, $value) {
    $this->variables[$name] = $value;
  }

  /**
   * {@inheritdoc}
   */
  function variableGet($name, $default = NULL) {
    return isset($this->variables[$name]) ? $this->variables[$name] : $default;
  }

  /**
   * {@inheritdoc}
   */
  function drupalGetFilename($type, $name) {
    return $this->components->DrupalGetFilename
      ->drupalGetFilename($type, $name);
  }

  /**
   * {@inheritdoc}
   */
  function drupalGetPath($type, $name) {
    return $this->components->DrupalGetFilename
      ->drupalGetPath($type, $name);
  }

  /**
   * {@inheritdoc}
   */
  function getExtensionTypes($extension_names) {

    // Simply assume that everything is a module.
    return array_fill_keys($extension_names, 'module');
  }

  /**
   * {@inheritdoc}
   */
  function getActiveExtensions() {
    return $this->components->SystemTable
      ->getActiveExtensions();
  }

  /**
   * Replicates module_list()
   *
   * @param bool $refresh
   * @param bool $bootstrap_refresh
   * @param bool $sort
   *
   * @return string[]
   */
  function moduleList($refresh = FALSE, $bootstrap_refresh = FALSE, $sort = FALSE) {
    return $this->components->ModuleList
      ->moduleList($refresh, $bootstrap_refresh, $sort);
  }

  /**
   * @see module_invoke()
   *
   * @param string $module
   * @param string $hook
   *
   * @return mixed
   *
   * @throws \Exception
   */
  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.");
    }
  }

  /**
   * @param string $hook
   */
  function moduleInvokeAll($hook) {
    $args = func_get_args();
    call_user_func_array(array(
      $this->components->HookSystem,
      'moduleInvokeAll',
    ), $args);
  }

  /**
   * @param string $hook
   *
   * @throws \Exception
   * @return array
   */
  function moduleImplements($hook) {
    return $this->components->HookSystem
      ->moduleImplements($hook);
  }

  /**
   * @param string $hook
   * @param mixed $data
   */
  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]);
  }

  /**
   * Replicates module_load_include()
   *
   * @param string $type
   * @param string $module
   * @param string|null $name
   *
   * @return bool|string
   */
  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;
  }

  /**
   * Resets the module_implements() cache.
   */
  public function resetModuleImplementsCache() {
    $this->components->HookSystem
      ->moduleImplementsReset();
  }

  /**
   * @see libraries_info()
   *
   * @return mixed
   */
  function getLibrariesInfo() {
    $this->components->LibrariesInfo
      ->resetLibrariesInfo();
    return $this->components->LibrariesInfo
      ->getLibrariesInfo();
  }

  /**
   * @see libraries_get_path()
   *
   * @param string $name
   *   Name of the library.
   *
   * @return string|false
   */
  function librariesGetPath($name) {
    return $this->components->LibrariesInfo
      ->librariesGetPath($name);
  }

  /**
   * Called from xautoload_install() to set the module weight.
   *
   * @param int $weight
   *   New module weight for xautoload.
   */
  public function installSetModuleWeight($weight) {
    $this->components->SystemTable
      ->moduleSetWeight('xautoload', $weight);
    $this->components->SystemListReset
      ->systemListReset();
  }

  /**
   * @param string $cid
   * @param string $bin
   *
   * @return object|false
   *   The cache or FALSE on failure.
   *
   * @see cache_get()
   */
  public function cacheGet($cid, $bin = 'cache') {
    return $this->components->Cache
      ->cacheGet($cid, $bin);
  }

  /**
   * @param string $cid
   * @param mixed $data
   * @param string $bin
   *
   * @return mixed
   *
   * @see cache_set()
   */
  public function cacheSet($cid, $data, $bin = 'cache') {
    $this->components->Cache
      ->cacheSet($cid, $data, $bin);
  }

  /**
   * @param string|null $cid
   * @param string|null $bin
   *
   * @see cache_clear_all()
   */
  public function cacheClearAll($cid = NULL, $bin = NULL) {
    $this->components->Cache
      ->cacheClearAll($cid, $bin);
  }

  /**
   * @param string $key
   */
  public function drupalStaticReset($key) {
    $this->components->DrupalStatic
      ->resetKey($key);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MockDrupalSystem::$components private property
MockDrupalSystem::$variables private property
MockDrupalSystem::cacheClearAll public function Overrides DrupalSystemInterface::cacheClearAll
MockDrupalSystem::cacheGet public function Overrides DrupalSystemInterface::cacheGet
MockDrupalSystem::cacheSet public function Overrides DrupalSystemInterface::cacheSet
MockDrupalSystem::drupalAlter function
MockDrupalSystem::drupalGetFilename function Replacement of drupal_get_filename(), but returning an absolute file path. Overrides DrupalSystemInterface::drupalGetFilename
MockDrupalSystem::drupalGetPath function Replacement of drupal_get_path(), but returning an absolute directory path. Overrides DrupalSystemInterface::drupalGetPath
MockDrupalSystem::drupalStaticReset public function Overrides DrupalSystemInterface::drupalStaticReset
MockDrupalSystem::getActiveExtensions function Gets active extensions directly from the system table. Overrides DrupalSystemInterface::getActiveExtensions
MockDrupalSystem::getExtensionTypes function Overrides DrupalSystemInterface::getExtensionTypes
MockDrupalSystem::getLibrariesInfo function Overrides DrupalSystemInterface::getLibrariesInfo
MockDrupalSystem::installSetModuleWeight public function Called from xautoload_install() to set the module weight. Overrides DrupalSystemInterface::installSetModuleWeight
MockDrupalSystem::librariesGetPath function Overrides DrupalSystemInterface::librariesGetPath
MockDrupalSystem::moduleImplements function Overrides DrupalSystemInterface::moduleImplements
MockDrupalSystem::moduleInvoke function
MockDrupalSystem::moduleInvokeAll function
MockDrupalSystem::moduleList function Replicates module_list() Overrides DrupalSystemInterface::moduleList
MockDrupalSystem::moduleLoadInclude function Replicates module_load_include()
MockDrupalSystem::resetModuleImplementsCache public function Resets the module_implements() cache.
MockDrupalSystem::variableGet function Replacement of variable_get(). Overrides DrupalSystemInterface::variableGet
MockDrupalSystem::variableSet function Wrapper for variable_set() Overrides DrupalSystemInterface::variableSet
MockDrupalSystem::__construct function