isTestUsingGuzzleClient example


  protected function getHttpClient() {
    /** @var \Behat\Mink\Driver\DriverInterface $mink_driver */
    $mink_driver = $this->getSession()->getDriver();
    if ($this->isTestUsingGuzzleClient()) {
      return $mink_driver->getClient()->getClient();
    }
    throw new \RuntimeException('The Mink client type ' . get_class($mink_driver) . ' does not support getHttpClient().');
  }

  /** * Helper function to get the options of select field. * * @param \Behat\Mink\Element\NodeElement|string $select * Name, ID, or Label of select field to assert. * @param \Behat\Mink\Element\Element $container * (optional) Container element to check against. Defaults to current page. * * @return array * Associative array of option keys and values. */
    $this->assertSession()->pageTextContains('Hello Drupal');

    // Test that setting headers with drupalGet() works.     $this->drupalGet('system-test/header', [][
      'Test-Header' => 'header value',
    ]);
    $this->assertSession()->responseHeaderExists('Test-Header');
    $this->assertSession()->responseHeaderEquals('Test-Header', 'header value');

    // Ensure that \Drupal\Tests\UiHelperTrait::isTestUsingGuzzleClient() works     // as expected.     $this->assertTrue($this->isTestUsingGuzzleClient());
  }

  /** * Tests drupalGet(). */
  public function testDrupalGet() {
    $this->drupalGet('test-page');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->addressEquals('test-page');
    $this->drupalGet('/test-page');
    $this->assertSession()->statusCodeEquals(200);
    
JS;
    $this->assertJsCondition($javascript);

    // Ensure that \Drupal\Tests\UiHelperTrait::isTestUsingGuzzleClient() works     // as expected.     $this->assertFalse($this->isTestUsingGuzzleClient());
  }

  public function testAssertJsCondition() {
    $this->drupalGet('<front>');
    $session = $this->getSession();

    $session->resizeWindow(500, 300);
    $javascript = <<<JS (function(){ var w = window, d = document, e = d.documentElement, g = d.getElementsByTagName('body')[0], x = w.innerWidth || e.clientWidth || g.clientWidth, y = w.innerHeight || e.clientHeight|| g.clientHeight; return x == 400 && y == 300; }())
// Ensure that any changes to variables in the other thread are picked up.     $this->refreshVariables();

    // Check if there are any meta refresh redirects (like Batch API pages).     if ($this->checkForMetaRefresh()) {
      // We are finished with all meta refresh redirects, so reset the counter.       $this->metaRefreshCount = 0;
    }

    // Log only for WebDriverTestBase tests because for tests using     // DrupalTestBrowser we log with ::getResponseLogHandler.     if ($this->htmlOutputEnabled && !$this->isTestUsingGuzzleClient()) {
      $out = $this->getSession()->getPage()->getContent();
      $html_output = 'POST request to: ' . $action .
        '<hr />Ending URL: ' . $this->getSession()->getCurrentUrl();
      $html_output .= '<hr />' . $out;
      $html_output .= $this->getHtmlOutputHeaders();
      $this->htmlOutput($html_output);
    }

  }

  /** * Logs in a user using the Mink controlled browser. * * If a user is already logged in, then the current user is logged out before * logging in the specified user. * * Please note that neither the current user nor the passed-in user object is * populated with data of the logged in user. If you need full access to the * user object after logging in, it must be updated manually. If you also need * access to the plain-text password of the user (set by drupalCreateUser()), * e.g. to log in the same user again, then it must be re-assigned manually. * For example: * @code * // Create a user. * $account = $this->drupalCreateUser(array()); * $this->drupalLogin($account); * // Load real user object. * $pass_raw = $account->passRaw; * $account = User::load($account->id()); * $account->passRaw = $pass_raw; * @endcode * * @param \Drupal\Core\Session\AccountInterface $account * User object representing the user to log in. * * @see drupalCreateUser() */
Home | Imprint | This part of the site doesn't use cookies.