initMink example

    \Drupal::service('file_system')->prepareDirectory($this->tempFilesDirectory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);

    // Set the container. parent::rebuildAll() would normally do this, but this     // not safe to do here, because the database has not been updated yet.     $this->container = \Drupal::getContainer();

    $this->replaceUser1();

    require_once $this->root . '/core/includes/update.inc';

    // Setup Mink.     $this->initMink();

    // Set up the browser test output file.     $this->initBrowserOutputFile();
  }

  /** * {@inheritdoc} */
  public function installDrupal() {
    $this->initUserSession();
    $this->prepareSettings();
    

  protected function setUp(): void {
    parent::setUp();
    static::checkMethodCommandRequirements($this->getName());
    $this->phpFinder = new PhpExecutableFinder();
    // Set up the workspace directory.     // @todo Glean working directory from env vars, etc.     $fs = new SymfonyFilesystem();
    $this->workspaceDir = $fs->tempnam(DrupalFilesystem::getOsTemporaryDirectory(), '/build_workspace_' . md5($this->getName() . microtime(TRUE)));
    $fs->remove($this->workspaceDir);
    $fs->mkdir($this->workspaceDir);
    $this->initMink();
  }

  /** * {@inheritdoc} */
  protected function tearDown(): void {
    parent::tearDown();

    $this->stopServer();
    foreach ($this->portLocks as $lock) {
      $lock->release();
    }
// Allow tests to compare MarkupInterface objects via assertEquals().     $this->registerComparator(new MarkupInterfaceComparator());

    $this->setupBaseUrl();

    // Install Drupal test site.     $this->prepareEnvironment();
    $this->installDrupal();

    // Setup Mink.     $this->initMink();

    // Set up the browser test output file.     $this->initBrowserOutputFile();

    // Ensure that the test is not marked as risky because of no assertions. In     // PHPUnit 6 tests that only make assertions using $this->assertSession()     // can be marked as risky.     $this->addToAssertionCount(1);
  }

  /** * {@inheritdoc} */
$handler_stack = HandlerStack::create();
    $test_http_client_middleware = new TestHttpClientMiddleware();
    $handler_stack->push($test_http_client_middleware(), 'test.http_client.middleware');
    $this->container
      ->set('http_handler_stack', $handler_stack);

    $this->container
      ->setParameter('app.root', DRUPAL_ROOT);
    \Drupal::setContainer($this->container);

    // Setup Mink.     $this->initMink();

    // Set up the browser test output file.     $this->initBrowserOutputFile();

    $this->visitInstaller();

    // Select language.     $this->setUpLanguage();

    // Select profile.     $this->setUpProfile();

    
/** * {@inheritdoc} */
  protected function initMink() {
    if (!is_a($this->minkDefaultDriverClass, DrupalSelenium2Driver::class, TRUE)) {
      throw new \UnexpectedValueException(sprintf("%s has to be an instance of %s", $this->minkDefaultDriverClass, DrupalSelenium2Driver::class));
    }
    $this->minkDefaultDriverArgs = ['chrome', NULL, 'http://localhost:4444'];

    try {
      return parent::initMink();
    }
    catch (DriverException $e) {
      if ($this->minkDefaultDriverClass === DrupalSelenium2Driver::class) {
        $this->markTestSkipped("The test wasn't able to connect to your webdriver instance. For more information read core/tests/README.md.\n\nThe original message while starting Mink: {$e->getMessage()}");
      }
      else {
        throw $e;
      }
    }
    catch (\Exception $e) {
      $this->markTestSkipped('An unexpected error occurred while starting Mink: ' . $e->getMessage());
    }
Home | Imprint | This part of the site doesn't use cookies.