/**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     // Generate and store a random set of credentials.
     // Make them as close to the production values as possible
     // Something like AAAA-1234
     $this->id = $this->randomMachineName(10);
     // Most of the keys and salts have a 32char lenght
     $this->key = $this->randomMachineName(32);
     $this->salt = $this->randomMachineName(32);
     // Include Solarium autoloader.
     $dirs = drupal_phpunit_contrib_extension_directory_roots();
     $extensions = [];
     foreach ($dirs as $path) {
         $extensions += drupal_phpunit_find_extension_directories($path);
     }
     require_once $extensions['search_api_solr'] . '/vendor/autoload.php';
     unset($extensions);
     $this->searchSubscriber = new SearchSubscriber();
     $this->derivedKey = CryptConnector::createDerivedKey($this->salt, $this->id, $this->key);
 }
示例#2
0
function drupal_phpunit_register_extension_dirs(Composer\Autoload\ClassLoader $loader, $dirs)
{
    foreach ($dirs as $extension => $dir) {
        if (is_dir($dir . '/src')) {
            // Register the PSR-4 directory for module-provided classes.
            $loader->addPsr4('Drupal\\' . $extension . '\\', $dir . '/src');
        }
        if (is_dir($dir . '/tests/src')) {
            // Register the PSR-4 directory for PHPUnit test classes.
            $loader->addPsr4('Drupal\\' . $extension . '\\Tests\\', $dir . '/tests/src');
        }
    }
}
// Start with classes in known locations.
$loader = (require __DIR__ . '/../vendor/autoload.php');
$loader->add('Drupal\\Tests', __DIR__);
// Scan for arbitrary extension namespaces from core and contrib.
$extension_roots = array_merge(array(__DIR__ . '/../modules', __DIR__ . '/../profiles'), drupal_phpunit_contrib_extension_directory_roots());
$dirs = array_map('drupal_phpunit_find_extension_directories', $extension_roots);
$dirs = array_reduce($dirs, 'array_merge', array());
drupal_phpunit_register_extension_dirs($loader, $dirs);
// Look into removing these later.
define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']);
define('DRUPAL_ROOT', realpath(__DIR__ . '/../../'));
// Set sane locale settings, to ensure consistent string, dates, times and
// numbers handling.
// @see \Drupal\Core\DrupalKernel::bootEnvironment()
setlocale(LC_ALL, 'C');
// Set the default timezone. While this doesn't cause any tests to fail, PHP
// complains if 'date.timezone' is not set in php.ini.
date_default_timezone_set('UTC');
/**
 * Populate class loader with additional namespaces for tests.
 *
 * We run this in a function to avoid setting the class loader to a global
 * that can change. This change can cause unpredictable false positives for
 * phpunit's global state change watcher. The class loader can be retrieved from
 * composer at any time by requiring autoload.php.
 */
function drupal_phpunit_populate_class_loader()
{
    /** @var \Composer\Autoload\ClassLoader $loader */
    $loader = (require __DIR__ . '/../../autoload.php');
    // Start with classes in known locations.
    $loader->add('Drupal\\Tests', __DIR__);
    $loader->add('Drupal\\KernelTests', __DIR__);
    $loader->add('Drupal\\FunctionalTests', __DIR__);
    $loader->add('Drupal\\FunctionalJavascriptTests', __DIR__);
    if (!isset($GLOBALS['namespaces'])) {
        // Scan for arbitrary extension namespaces from core and contrib.
        $extension_roots = drupal_phpunit_contrib_extension_directory_roots();
        $dirs = array_map('drupal_phpunit_find_extension_directories', $extension_roots);
        $dirs = array_reduce($dirs, 'array_merge', array());
        $GLOBALS['namespaces'] = drupal_phpunit_get_extension_namespaces($dirs);
    }
    foreach ($GLOBALS['namespaces'] as $prefix => $paths) {
        $loader->addPsr4($prefix, $paths);
    }
    return $loader;
}
示例#4
0
 /**
  * Finds extensions in a Drupal installation.
  *
  * An extension is defined as a directory with an *.info.yml file in it.
  *
  * @param string $root
  *   Path to the root of the Drupal installation.
  *
  * @return string[]
  *   Associative array of extension paths, with extension name as keys.
  */
 protected function findExtensionDirectories($root)
 {
     $extension_roots = \drupal_phpunit_contrib_extension_directory_roots($root);
     $extension_directories = array_map('drupal_phpunit_find_extension_directories', $extension_roots);
     return array_reduce($extension_directories, 'array_merge', array());
 }
示例#5
0
            $namespaces['Drupal\\' . $extension . '\\'][] = $dir . '/src';
        }
        if (is_dir($dir . '/tests/src')) {
            // Register the PSR-4 directory for PHPUnit test classes.
            $namespaces['Drupal\\Tests\\' . $extension . '\\'][] = $dir . '/tests/src';
        }
    }
    return $namespaces;
}
// Start with classes in known locations.
$loader = (require __DIR__ . '/../../autoload.php');
$loader->add('Drupal\\Tests', __DIR__);
$loader->add('Drupal\\KernelTests', __DIR__);
if (!isset($GLOBALS['namespaces'])) {
    // Scan for arbitrary extension namespaces from core and contrib.
    $extension_roots = drupal_phpunit_contrib_extension_directory_roots();
    $dirs = array_map('drupal_phpunit_find_extension_directories', $extension_roots);
    $dirs = array_reduce($dirs, 'array_merge', array());
    $GLOBALS['namespaces'] = drupal_phpunit_get_extension_namespaces($dirs);
}
foreach ($GLOBALS['namespaces'] as $prefix => $paths) {
    $loader->addPsr4($prefix, $paths);
}
// Set sane locale settings, to ensure consistent string, dates, times and
// numbers handling.
// @see \Drupal\Core\DrupalKernel::bootEnvironment()
setlocale(LC_ALL, 'C');
// Set the default timezone. While this doesn't cause any tests to fail, PHP
// complains if 'date.timezone' is not set in php.ini. The Australia/Sydney
// timezone is chosen so all tests are run using an edge case scenario (UTC+10
// and DST). This choice is made to prevent timezone related regressions and