You are here

public function BrowserTestBaseTest::testFieldAssertsForOptions in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testFieldAssertsForOptions()

Tests legacy field asserts for options field type.

File

core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php, line 451

Class

BrowserTestBaseTest
Tests BrowserTestBase functionality.

Namespace

Drupal\FunctionalTests

Code

public function testFieldAssertsForOptions() {
  $this
    ->drupalGet('test-field-xpath');

  // Option field type.
  $this
    ->assertOptionByText('options', 'one');
  try {
    $this
      ->assertOptionByText('options', 'four');
    $this
      ->fail('The select option "four" was found.');
  } catch (ExpectationException $e) {

    // Expected exception; just continue testing.
  }
  $this
    ->assertOption('options', 1);
  try {
    $this
      ->assertOption('options', 4);
    $this
      ->fail('The select option "4" was found.');
  } catch (ExpectationException $e) {

    // Expected exception; just continue testing.
  }
  $this
    ->assertNoOption('options', 'non-existing');
  try {
    $this
      ->assertNoOption('options', 'one');
    $this
      ->fail('The select option "one" was not found.');
  } catch (ExpectationException $e) {

    // Expected exception; just continue testing.
  }
  $this
    ->assertOptionSelected('options', 2);
  try {
    $this
      ->assertOptionSelected('options', 4);
    $this
      ->fail('The select option "4" was selected.');
  } catch (ExpectationException $e) {

    // Expected exception; just continue testing.
  }
  try {
    $this
      ->assertOptionSelected('options', 1);
    $this
      ->fail('The select option "1" was selected.');
  } catch (ExpectationFailedException $e) {

    // Expected exception; just continue testing.
  }
}