visit example


  protected function initFrontPage() {
    $session = $this->getSession();
    $session->visit($this->baseUrl);
  }

  /** * Gets an instance of the default Mink driver. * * @return \Behat\Mink\Driver\DriverInterface * Instance of default Mink driver. * * @throws \InvalidArgumentException * When provided default Mink driver class can't be instantiated. */
  
'--install-profile=minimal',
      '--json',
    ];
    $this->assertNotEmpty($output_json = $this->executeCommand(implode(' ', $install_command))->getOutput());
    $this->assertCommandSuccessful();
    $connection_details = json_decode($output_json, TRUE);
    foreach (['db_prefix', 'user_agent', 'site_path'] as $key) {
      $this->assertArrayHasKey($key$connection_details);
    }

    // Visit paths with expectations.     $this->visit();
    $this->assertDrupalVisit();
  }

}

  public function formLogin($username$password$working_dir = NULL) {
    $this->visit('/user/login', $working_dir);
    $assert = $this->getMink()->assertSession();
    $assert->statusCodeEquals(200);
    $assert->fieldExists('edit-name')->setValue($username);
    $assert->fieldExists('edit-pass')->setValue($password);
    $session = $this->getMink()->getSession();
    $session->getPage()->findButton('Log in')->submit();
  }

}


        // Remove NULL character         $input = str_replace(\chr(0), '', $input);

        // Parse as HTML         if (!$parsed = $this->parser->parse($input)) {
            return '';
        }

        // Visit the DOM tree and render the sanitized nodes         return $this->domVisitors[$context]->visit($parsed)?->render() ?? '';
    }

    private function isValidUtf8(string $html): bool
    {
        // preg_match() fails silently on strings containing invalid UTF-8.         return '' === $html || preg_match('//u', $html);
    }

    private function createDomVisitorForContext(string $context): DomVisitor
    {
        $elementsConfig = [];

        

  protected function assertAggregate(string $url, bool $from_php = TRUE, string $content_type = NULL): void {
    $url = $this->getAbsoluteUrl($url);
    if (!stripos($url$this->fileAssetsPath) !== FALSE) {
      return;
    }
    $session = $this->getSession();
    $session->visit($url);
    $this->assertSession()->statusCodeEquals(200);
    $headers = $session->getResponseHeaders();
    if (isset($content_type)) {
      $this->assertStringContainsString($content_type$headers['Content-Type'][0]);
    }
    if ($from_php) {
      $this->assertStringContainsString('no-store', $headers['Cache-Control'][0]);
      $this->assertArrayHasKey('X-Generator', $headers);
    }
    else {
      $this->assertArrayNotHasKey('X-Generator', $headers);
    }
protected function drupalGetWithAlert($path, array $options = [], array $headers = []) {
    $options['absolute'] = TRUE;
    $url = $this->buildUrl($path$options);

    $session = $this->getSession();

    $this->prepareRequest();
    foreach ($headers as $header_name => $header_value) {
      $session->setRequestHeader($header_name$header_value);
    }

    $session->visit($url);

    // There are 2 alerts to accept before we can get the content of the page.     $session->getDriver()->getWebdriverSession()->accept_alert();
    $session->getDriver()->getWebdriverSession()->accept_alert();

    $out = $session->getPage()->getContent();

    // Ensure that any changes to variables in the other thread are picked up.     $this->refreshVariables();

    // Replace original page output with new output from redirected page(s).
public function testHtRouter() {
    $sqlite = (new \PDO('sqlite::memory:'))->query('select sqlite_version()')->fetch()[0];
    if (version_compare($sqlite, Tasks::SQLITE_MINIMUM_VERSION) < 0) {
      $this->markTestSkipped();
    }

    $this->copyCodebase();
    $this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction');
    $this->assertErrorOutputContains('Generating autoload files');
    $this->installQuickStart('minimal');
    $this->formLogin($this->adminUsername, $this->adminPassword);
    $this->visit('/.well-known/change-password');
    $this->assertDrupalVisit();
    $url = $this->getMink()->getSession()->getCurrentUrl();
    $this->assertEquals('http://localhost:' . $this->getPortNumber() . '/user/1/edit', $url);
  }

}

  public function visit($request_uri = '/', $working_dir = NULL) {
    if ($request_uri[0] !== '/') {
      throw new \InvalidArgumentException('URI: ' . $request_uri . ' must be relative. Example: /some/path?foo=bar');
    }
    // Try to make a server.     $this->standUpServer($working_dir);

    $request = 'http://localhost:' . $this->getPortNumber() . $request_uri;
    $this->mink->getSession()->visit($request);
    return $this->mink;
  }

  /** * Makes a local test server using PHP's internal HTTP server. * * Test authors should call visit() or assertVisit() instead. * * @param string|null $working_dir * (optional) Server docroot relative to the workspace file system. Defaults * to the workspace directory. */
protected function drupalGet($path, array $options = [], array $headers = []) {
    $options['absolute'] = TRUE;
    $url = $this->buildUrl($path$options);

    $session = $this->getSession();

    $this->prepareRequest();
    foreach ($headers as $header_name => $header_value) {
      $session->setRequestHeader($header_name$header_value);
    }

    $session->visit($url);
    $out = $session->getPage()->getContent();

    // Ensure that any changes to variables in the other thread are picked up.     $this->refreshVariables();

    // Replace original page output with new output from redirected page(s).     if ($new = $this->checkForMetaRefresh()) {
      $out = $new;
      // We are finished with all meta refresh redirects, so reset the counter.       $this->metaRefreshCount = 0;
    }

    
self::assertArrayNotHasKey('hidden', $info);
    self::assertArrayHasKey('generator', $info);
    self::assertEquals('starterkit_theme:9.4.0', $info['generator']);

    // Confirm readme is rewritten.     $readme_file = $this->getWorkspaceDirectory() . "/$theme_path_relative/README.md";
    $this->assertSame('test_custom_theme theme, generated from starterkit_theme. Additional information on generating themes can be found in the [Starterkit documentation](https://www.drupal.org/docs/core-modules-and-themes/core-themes/starterkit-theme).', file_get_contents($readme_file));

    // Ensure that the generated theme can be installed.     $this->installQuickStart('minimal');
    $this->formLogin($this->adminUsername, $this->adminPassword);
    $this->visit('/admin/appearance');
    $this->getMink()->assertSession()->pageTextContains('Test custom starterkit');
    $this->getMink()->assertSession()->pageTextContains('Custom theme generated from a starterkit theme');
    $this->getMink()->getSession()->getPage()->clickLink('Install "Test custom starterkit theme" theme');
    $this->getMink()->assertSession()->pageTextContains('The "Test custom starterkit theme" theme has been installed.');

    // Ensure that a new theme cannot be generated when the destination     // directory already exists.     $theme_path_absolute = $this->getWorkspaceDirectory() . "/$theme_path_relative";
    $this->assertFileExists($theme_path_absolute . '/test_custom_theme.theme');
    unlink($theme_path_absolute . '/test_custom_theme.theme');
    $process = $this->generateThemeFromStarterkit();
    
$style_elements = $page->findAll('xpath', '//link[@href and @rel="stylesheet"]');
    $this->assertNotEmpty($style_elements);
    $href = NULL;
    foreach ($style_elements as $element) {
      $href = $element->getAttribute('href');
      $url = $this->getAbsoluteUrl($href);
      // Not every script or style on a page is aggregated.       if (!str_contains($url$this->fileAssetsPath)) {
        continue;
      }
      $session = $this->getSession();
      $session->visit($url);
      $this->assertSession()->statusCodeEquals(200);
      $aggregate = $session = $session->getPage()->getContent();
      $this->assertStringContainsString('original-content', $aggregate);
      $this->assertStringNotContainsString('extra-stuff', $aggregate);
    }
    $file = file_get_contents('public://test.css') . '.extra-stuff{display:none;}';
    file_put_contents('public://test.css', $file);
    // Clear the library discovery and page caches again so that new URLs are     // generated.     \Drupal::service('cache.data')->deleteAll();
    \Drupal::service('cache.page')->deleteAll();
    
Home | Imprint | This part of the site doesn't use cookies.