You are here

protected function LengthIndicatorTest::assertActiveElement in Length Indicator 8

Tests the field length indicator for a specific field.

Parameters

string $field_name: The field to test.

string $class_modifier: The class modifier that you expect the active indicator to have.

string $value: (optional) Set the field to this value before testing the indicator.

1 call to LengthIndicatorTest::assertActiveElement()
LengthIndicatorTest::testLengthIndicator in tests/src/FunctionalJavascript/LengthIndicatorTest.php
Tests the length indicator.

File

tests/src/FunctionalJavascript/LengthIndicatorTest.php, line 153

Class

LengthIndicatorTest
Tests the UI for entity displays.

Namespace

Drupal\Tests\length_indicator\FunctionalJavascript

Code

protected function assertActiveElement($field_name, $class_modifier, $value = NULL) {
  if (!is_null($value)) {
    $this
      ->getSession()
      ->getPage()
      ->fillField($field_name . '[0][value]', $value);
  }
  $active_elements = $this
    ->xpath('//*[@id="edit-' . str_replace('_', '-', $field_name) . '-wrapper"]/div[2]/span[contains(@class, "is-active")]');
  $this
    ->assertCount(1, $active_elements);
  $this
    ->assertContains("length-indicator__indicator--{$class_modifier}", $active_elements[0]
    ->getAttribute('class'), "{$field_name} field's active indicator has class modifier '{$class_modifier}'");
}