You are here

class DrupalBootHookTest in X Autoload 7.5

Tests modules that use hook_xautoload() and hook_libraries_info()

@runTestsInSeparateProcesses @preserveGlobalState disabled

Hierarchy

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

Expanded class hierarchy of DrupalBootHookTest

See also

HookTestExampleModules

File

tests/src/DrupalBootTest/DrupalBootHookTest.php, line 25

Namespace

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

  /**
   * @return array[]
   */
  public function providerModuleEnable() {
    $hookXautoloadEarly = FALSE;
    $hookXautoloadLate = TRUE;
    $initialModuleVariations = array(
      array(
        'system' => TRUE,
      ),
    );
    foreach (array(
      'xautoload' => array(
        FALSE,
        TRUE,
      ),
      'libraries' => array(
        FALSE,
        TRUE,
      ),
      'testmod' => array(
        FALSE,
        NULL,
      ),
    ) as $module => $states) {
      $initialModuleVariations = $this
        ->providerArrayKeyVariations($initialModuleVariations, $module, $states);
    }
    $variations = array();
    foreach ($initialModuleVariations as $initialModuleVariation) {
      $expectedCalls = array();
      if ($hookXautoloadEarly) {
        $expectedCalls[] = array(
          'function' => 'testmod_xautoload',
          'args' => array(
            '(xautoload_InjectedAPI_hookXautoload)',
            dirname(dirname(__DIR__)) . '/fixtures/.modules/testmod',
          ),
        );
      }
      if (NULL === $initialModuleVariation['testmod']) {
        $expectedCalls[] = array(
          'function' => 'testmod_schema',
          'args' => array(),
        );
        $expectedCalls[] = array(
          'function' => 'testmod_install',
          'args' => array(),
        );
        $expectedCalls[] = array(
          'function' => 'testmod_watchdog',
          'args' => array(),
        );
      }
      $expectedCalls[] = array(
        'function' => 'testmod_enable',
        'args' => array(),
      );
      $expectedCalls[] = array(
        'function' => 'testmod_watchdog',
        'args' => array(),
      );
      if ($hookXautoloadLate) {
        $expectedCalls[] = array(
          'function' => 'testmod_xautoload',
          'args' => array(
            '(xautoload_InjectedAPI_hookXautoload)',
            dirname(dirname(__DIR__)) . '/fixtures/.modules/testmod',
          ),
        );
      }
      $expectedCalls[] = array(
        'function' => 'testmod_modules_enabled',
        'args' => array(
          '(array)',
        ),
      );
      $expectedCalls[] = array(
        'function' => 'testmod_libraries_info',
        'args' => array(),
      );
      $expectedCalls[] = array(
        'function' => '_testmod_libraries_testlib_xautoload',
        'args' => array(
          '(xautoload_InjectedAPI_hookXautoload)',
          dirname(dirname(__DIR__)) . '/fixtures/.libraries/testlib',
        ),
      );
      $variations[] = array(
        $initialModuleVariation,
        $expectedCalls,
      );
    }
    return $variations;
  }
  function initOnce() {
    if (isset($this->exampleDrupal)) {
      return;
    }
    $this->exampleModules = new HookTestExampleModules();
    $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(
      array(
        'function' => 'testmod_xautoload',
        'args' => array(
          '(xautoload_InjectedAPI_hookXautoload)',
          dirname(dirname(__DIR__)) . '/fixtures/.modules/testmod',
        ),
      ),
      array(
        'function' => 'testmod_init',
        'args' => array(),
      ),
      array(
        'function' => 'testmod_libraries_info',
        'args' => array(),
      ),
      array(
        'function' => '_testmod_libraries_testlib_xautoload',
        'args' => array(
          '(xautoload_InjectedAPI_hookXautoload)',
          dirname(dirname(__DIR__)) . '/fixtures/.libraries/testlib',
        ),
      ),
    );
    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.
DrupalBootHookTest::getExpectedCallsForNormalRequest protected function Overrides AbstractDrupalBootTest::getExpectedCallsForNormalRequest
DrupalBootHookTest::initOnce function
DrupalBootHookTest::prepare protected function setUp() does not help us because of the process sharing problem. So we use this instead. Overrides AbstractDrupalBootTest::prepare
DrupalBootHookTest::providerModuleEnable public function Overrides AbstractDrupalBootTest::providerModuleEnable