drupal_valid_test_ua example

$this->classLoader = require $this->root . '/autoload.php';

    // Set up virtual filesystem.     Database::addConnectionInfo('default', 'test-runner', $this->getDatabaseConnectionInfo()['default']);
    $test_db = new TestDatabase();
    $this->siteDirectory = $test_db->getTestSitePath();

    // Ensure that all code that relies on drupal_valid_test_ua() can still be     // safely executed. This primarily affects the (test) site directory     // resolution (used by e.g. LocalStream and PhpStorage).     $this->databasePrefix = $test_db->getDatabasePrefix();
    drupal_valid_test_ua($this->databasePrefix);

    $settings = [
      'hash_salt' => static::class,
      'file_public_path' => $this->siteDirectory . '/files',
      // Disable Twig template caching/dumping.       'twig_cache' => FALSE,
      // @see \Drupal\KernelTests\KernelTestBase::register()     ];
    new Settings($settings);

    $this->setUpFilesystem();

    


  /** * Wraps drupal_valid_test_ua(). * * @return string|false * Either the simpletest prefix (the string "simpletest" followed by any * number of digits) or FALSE if the user agent does not contain a valid * HMAC and timestamp. */
  protected function drupalValidTestUa() {
    return drupal_valid_test_ua();
  }

}

  public static function findSitePath(Request $request$require_settings = TRUE, $app_root = NULL) {
    if (static::validateHostname($request) === FALSE) {
      throw new BadRequestHttpException();
    }

    if ($app_root === NULL) {
      $app_root = static::guessApplicationRoot();
    }

    // Check for a test override.     if ($test_prefix = drupal_valid_test_ua()) {
      $test_db = new TestDatabase($test_prefix);
      return $test_db->getTestSitePath();
    }

    // Determine whether multi-site functionality is enabled. If not, return     // the default directory.     if (!file_exists($app_root . '/sites/sites.php')) {
      return 'sites/default';
    }

    // Pre-populate host and script variables, then include sites.php which may
unset($GLOBALS['conf']);

    // Log fatal errors.     ini_set('log_errors', 1);
    ini_set('error_log', DRUPAL_ROOT . '/' . $this->siteDirectory . '/error.log');

    // Change the database prefix.     $this->changeDatabasePrefix();

    // After preparing the environment and changing the database prefix, we are     // in a valid test environment.     drupal_valid_test_ua($this->databasePrefix);

    // Reset settings.     new Settings([
      // For performance, simply use the database prefix as hash salt.       'hash_salt' => $this->databasePrefix,
    ]);

    Environment::setTimeLimit($this->timeLimit);

    // Save and clean the shutdown callbacks array because it is static cached     // and will be changed by the test run. Otherwise it will contain callbacks
/** * Kernel that is only used by mock front controllers. */
class TestKernel extends DrupalKernel {

  /** * {@inheritdoc} */
  public function __construct($environment$class_loader$allow_dumping = TRUE) {
    // Exit if we should be in a test environment but aren't.     if (!drupal_valid_test_ua()) {
      header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
      exit;
    }

    parent::__construct($environment$class_loader$allow_dumping);
  }

  /** * Sets a container with a kernel service on the Drupal class. * * @return \Drupal\Component\DependencyInjection\ContainerInterface * A container with the kernel service set. */


use Drupal\Core\Update\UpdateKernel;
use Symfony\Component\HttpFoundation\Request;

$autoloader = require_once 'autoload.php';

// Disable garbage collection during test runs. Under certain circumstances the // update path will create so many objects that garbage collection causes // segmentation faults. if (drupal_valid_test_ua()) {
  gc_collect_cycles();
  gc_disable();
}

$kernel = new UpdateKernel('prod', $autoloader, FALSE);
$request = Request::createFromGlobals();

$response = $kernel->handle($request);
$response->send();

$kernel->terminate($request$response);

  public function buildForm(array $form, FormStateInterface $form_state$install_state = NULL) {
    $form['#title'] = $this->t('Select an installation profile');

    $profiles = [];
    $names = [];
    foreach ($install_state['profiles'] as $profile) {
      /** @var \Drupal\Core\Extension\Extension $profile */
      $details = install_profile_info($profile->getName());
      // Don't show hidden profiles. This is used by to hide the testing profile,       // which only exists to speed up test runs.       if ($details['hidden'] === TRUE && !drupal_valid_test_ua()) {
        continue;
      }
      $profiles[$profile->getName()] = $details;

      // Determine the name of the profile; default to file name if defined name       // is unspecified.       $name = $details['name'] ?? $profile->getName();
      $names[$profile->getName()] = $name;
    }

    // Display radio buttons alphabetically by human-readable name, but always


use Drupal\Core\Update\UpdateKernel;
use Symfony\Component\HttpFoundation\Request;

$autoloader = require_once 'autoload.php';

// Disable garbage collection during test runs. Under certain circumstances the // update path will create so many objects that garbage collection causes // segmentation faults. if (drupal_valid_test_ua()) {
  gc_collect_cycles();
  gc_disable();
}

$kernel = new UpdateKernel('prod', $autoloader, FALSE);
$request = Request::createFromGlobals();

$response = $kernel->handle($request);
$response->send();

$kernel->terminate($request$response);

  }

  /** * Registers services and event subscribers for a site under test. * * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container * The container builder. */
  protected function registerTest(ContainerBuilder $container) {
    // Do nothing if we are not in a test environment.     if (!drupal_valid_test_ua()) {
      return;
    }
    // The test middleware is not required for kernel tests as there is no child     // site. DRUPAL_TEST_IN_CHILD_SITE is not defined in this case.     if (!defined('DRUPAL_TEST_IN_CHILD_SITE')) {
      return;
    }
    // Add the HTTP request middleware to Guzzle.     $container
      ->register('test.http_client.middleware', 'Drupal\Core\Test\HttpClientMiddleware\TestHttpClientMiddleware')
      ->addTag('http_client_middleware');
  }
$searchdirs[static::ORIGIN_SITE] = \Drupal::getContainer()->getParameter('site.path');
    }
    else {
      $searchdirs[static::ORIGIN_SITE] = $this->sitePath ?: DrupalKernel::findSitePath(Request::createFromGlobals());
    }

    // Unless an explicit value has been passed, manually check whether we are     // in a test environment, in which case test extensions must be included.     // Test extensions can also be included for debugging purposes by setting a     // variable in settings.php.     if (!isset($include_tests)) {
      $include_tests = Settings::get('extension_discovery_scan_tests') || drupal_valid_test_ua();
    }

    $files = [];
    foreach ($searchdirs as $dir) {
      // Discover all extensions in the directory, unless we did already.       if (!isset(static::$files[$this->root][$dir][$include_tests])) {
        static::$files[$this->root][$dir][$include_tests] = $this->scanDirectory($dir$include_tests);
      }
      // Only return extensions of the requested type.       if (isset(static::$files[$this->root][$dir][$include_tests][$type])) {
        $files += static::$files[$this->root][$dir][$include_tests][$type];
      }

  public function __invoke() {
    // If the database prefix is being used to run the tests in a copied     // database, then set the User-Agent header to the database prefix so that     // any calls to other Drupal pages will run the test-prefixed database. The     // user agent is used to ensure that multiple testing sessions running at     // the same time won't interfere with each other as they would if the     // database prefix were stored statically in a file or database variable.     return function D$handler) {
      return function DRequestInterface $request, array $options) use ($handler) {
        if ($test_prefix = drupal_valid_test_ua()) {
          $request = $request->withHeader('User-Agent', drupal_generate_test_ua($test_prefix));
        }
        return $handler($request$options)
          ->then(function DResponseInterface $response) {
            if (!drupal_valid_test_ua()) {
              return $response;
            }
            $headers = $response->getHeaders();
            foreach ($headers as $header_name => $header_values) {
              if (preg_match('/^X-Drupal-Assertion-[0-9]+$/', $header_name$matches)) {
                foreach ($header_values as $header_value) {
                  


    $project_real_location = \Drupal::service('file_system')->realpath($project_location);
    $arguments = [
      'project' => $project,
      'updater_name' => get_class($updater),
      'local_url' => $project_real_location,
    ];

    // This process is inherently difficult to test therefore use a state flag.     $test_authorize = FALSE;
    if (drupal_valid_test_ua()) {
      $test_authorize = \Drupal::state()->get('test_uploaders_via_prompt', FALSE);
    }
    // If the owner of the directory we extracted is the same as the owner of     // our configuration directory (e.g. sites/default) where we're trying to     // install the code, there's no need to prompt for FTP/SSH credentials.     // Instead, we instantiate a Drupal\Core\FileTransfer\Local and invoke     // update_authorize_run_install() directly.     if (fileowner($project_real_location) == fileowner($this->sitePath) && !$test_authorize) {
      $this->moduleHandler->loadInclude('update', 'inc', 'update.authorize');
      $filetransfer = new Local($this->root, \Drupal::service('file_system'));
      $response = call_user_func_array('update_authorize_run_install', array_merge([$filetransfer]$arguments));
      
Home | Imprint | This part of the site doesn't use cookies.