You are here

public function BrowserTestBaseTest::testFieldAssertsForOptions in Drupal 9

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

Tests legacy field asserts for options field type.

@group legacy

File

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

Class

BrowserTestBaseTest
Tests BrowserTestBase functionality.

Namespace

Drupal\FunctionalTests

Code

public function testFieldAssertsForOptions() {
  $this
    ->expectDeprecation('AssertLegacyTrait::assertOptionByText() is deprecated in drupal:8.4.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionExists() instead. See https://www.drupal.org/node/3129738');
  $this
    ->expectDeprecation('AssertLegacyTrait::assertOption() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionExists() instead. See https://www.drupal.org/node/3129738');
  $this
    ->expectDeprecation('AssertLegacyTrait::assertNoOption() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->optionNotExists() instead. See https://www.drupal.org/node/3129738');
  $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
    ->assertTrue($this
    ->assertSession()
    ->optionExists('options', 2)
    ->isSelected());
  try {
    $this
      ->assertTrue($this
      ->assertSession()
      ->optionExists('options', 4)
      ->isSelected());
    $this
      ->fail('The select option "4" was selected.');
  } catch (ExpectationException $e) {

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

    // Expected exception; just continue testing.
  }
}