You are here

class DrupalBootTest in X Autoload 7.5

@runTestsInSeparateProcesses @preserveGlobalState disabled

Hierarchy

  • class \Drupal\xautoload\Tests\DrupalBootTest\AbstractDrupalBootTest extends \Drupal\xautoload\Tests\DrupalBootTest\PHPUnit_Framework_TestCase

Expanded class hierarchy of DrupalBootTest

File

tests/src/DrupalBootTest/DrupalBootTest.php, line 20

Namespace

Drupal\xautoload\Tests\DrupalBootTest
View source
class DrupalBootTest extends AbstractDrupalBootTest {

  /**
   * @param bool $install
   *
   * @return array[]
   *   Variations of modules being either
   *   - enabled (TRUE),
   *   - installed but disabled (FALSE), or
   *   - not installed (NULL).
   *   Structure: array(..., array(
   *     'system' => TRUE,
   *     'xautoload' => FALSE,
   *     'libraries' => NULL), ...)
   */
  private function initialModulesVariations($install) {
    $variations = array();
    $state = $install ? NULL : FALSE;
    $variation = array(
      'system' => TRUE,
    );
    $variation += array_fill_keys(array_keys($this->exampleModules
      ->getExampleClasses()), $state);
    $variations[] = $variation;
    foreach (array(
      'xautoload',
    ) as $module) {
      $variations = $this
        ->providerArrayKeyVariations($variations, $module, array(
        TRUE,
        FALSE,
        NULL,
      ));
    }
    return $variations;
  }

  /**
   * @return array[]
   */
  public function providerModuleEnable() {
    $this
      ->initOnce();
    $variations = array();
    foreach (array(
      TRUE,
      FALSE,
    ) as $install) {
      $expectedCalls = array();
      $enabledModulesSoFar = array();
      foreach ($this->exampleModules
        ->getExampleClasses() as $module => $classes) {
        $enabledModulesSoFar[] = $module;
        if ($install) {
          $expectedCalls[] = array(
            'function' => $module . '_schema',
            'args' => array(),
          );
          $expectedCalls[] = array(
            'function' => $module . '_install',
            'args' => array(),
          );
          foreach ($enabledModulesSoFar as $module) {
            $expectedCalls[] = array(
              'function' => $module . '_watchdog',
              'args' => array(),
            );
          }
        }
        $expectedCalls[] = array(
          'function' => $module . '_enable',
          'args' => array(),
        );
        foreach ($enabledModulesSoFar as $module) {
          $expectedCalls[] = array(
            'function' => $module . '_watchdog',
            'args' => array(),
          );
        }
      }
      foreach ($this
        ->initialModulesVariations($install) as $moduleStates) {

        /*
        $enabledModules = array();
        foreach ($moduleStates as $module => $state) {
          if (TRUE !== $state) {
            $enabledModules[$module] = TRUE;
          }
        }
        foreach ($enabledModulesSoFar as $module) {
          if (isset($enabledModules[$module])) {
            unset($enabledModules[$module]);
            $enabledModules[$module] = TRUE;
          }
        }
        $enabledModules = array_keys($enabledModules);
        */
        $variationExpectedCalls = $expectedCalls;
        foreach (array_keys($this->exampleModules
          ->getExampleClasses()) as $module) {
          $variationExpectedCalls[] = array(
            'function' => $module . '_modules_enabled',
            'args' => array(
              '(array)',
            ),
          );
        }
        $variations[] = array(
          $moduleStates,
          $variationExpectedCalls,
        );
      }
    }
    return $variations;
  }
  function initOnce() {
    if (isset($this->exampleDrupal)) {
      return;
    }
    $this->exampleModules = new ExampleModules();
    $this->exampleDrupal = new DrupalEnvironment($this->exampleModules);
    $this->exampleDrupal
      ->setStaticInstance();
  }

  /**
   * setUp() does not help us because of the process sharing problem.
   * So we use this instead.
   *
   * @throws \Exception
   */
  protected function prepare() {
    $this
      ->initOnce();
    $filesystem = StreamWrapper::register('test');
    foreach ($this->exampleModules
      ->discoverModuleFilenames('module') as $name => $filename) {
      $this->exampleDrupal
        ->getSystemTable()
        ->addModuleWithFilename($name, $filename);
    }
    $this->exampleDrupal
      ->getSystemTable()
      ->moduleSetEnabled('system');
    $this->exampleDrupal
      ->initBootstrapStatus();

    # $this->exampleDrupal->getCache()->cacheSet('module_implements', $data, 'cache_bootstrap');
    xautoload()
      ->getServiceContainer()
      ->set('system', $this->exampleDrupal
      ->getMockDrupalSystem());
    $this->callLog = new CallLog();
    StaticCallLog::setCallLog($this->callLog);
  }

  /**
   * @return array[]
   */
  protected function getExpectedCallsForNormalRequest() {
    $expectedCalls = array();
    foreach ($this->exampleModules
      ->getExampleClasses() as $module => $classes) {
      $expectedCalls[] = array(
        'function' => $module . '_init',
        'args' => array(),
      );
    }
    return $expectedCalls;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AbstractDrupalBootTest::$callLog protected property
AbstractDrupalBootTest::$exampleDrupal protected property
AbstractDrupalBootTest::$exampleModules protected property
AbstractDrupalBootTest::assertClassExists public function
AbstractDrupalBootTest::assertClassIsDefined public function
AbstractDrupalBootTest::assertClassIsUndefined public function
AbstractDrupalBootTest::assertLoadClass public function
AbstractDrupalBootTest::prepareAllEnabled private function Start with all available modules enabled.
AbstractDrupalBootTest::prepareInitialModules private function
AbstractDrupalBootTest::providerArrayKeyVariations protected function Multiplies a given array of variations.
AbstractDrupalBootTest::testModuleEnable function Tests a request where modules are enabled, but xautoload is already enabled.
AbstractDrupalBootTest::testNormalRequest function Tests a simulated regular request.
AbstractDrupalBootTest::unprepare private function Runs after a test is finished.
DrupalBootTest::getExpectedCallsForNormalRequest protected function Overrides AbstractDrupalBootTest::getExpectedCallsForNormalRequest
DrupalBootTest::initialModulesVariations private function
DrupalBootTest::initOnce function
DrupalBootTest::prepare protected function setUp() does not help us because of the process sharing problem. So we use this instead. Overrides AbstractDrupalBootTest::prepare
DrupalBootTest::providerModuleEnable public function Overrides AbstractDrupalBootTest::providerModuleEnable