You are here

public function EditPageTest::testIndicators in Require on Publish 8

Ensure there is an indicator for the 'Required on Publish' fields.

File

tests/src/FunctionalJavascript/EditPageTest.php, line 124

Class

EditPageTest
Tests Require on Publish functionality on the entity edit page.

Namespace

Drupal\Tests\require_on_publish\FunctionalJavascript

Code

public function testIndicators() {
  $this
    ->drupalLogin($this->account);
  $this
    ->drupalGet('node/add/article');
  $page = $this
    ->getSession()
    ->getPage();
  $entity_form = \Drupal::entityTypeManager()
    ->getStorage('entity_form_display')
    ->load('node.article.default');
  $node_base_field_definitions = $this->container
    ->get('entity_field.manager')
    ->getBaseFieldDefinitions('node');
  foreach ($entity_form
    ->getComponents() as $field_name => $component) {
    if (in_array($field_name, array_keys($node_base_field_definitions))) {
      continue;
    }
    $field_id = sprintf("edit-%s-wrapper", str_replace('_', '-', $field_name));
    $field_id = str_replace('--', '-', $field_id);
    $field = $page
      ->find('css', "#{$field_id}");
    if ($field && $field
      ->isVisible()) {
      $html = $field
        ->getOuterHtml();
      $indicator_exists = strpos($html, 'form-required-on-publish') !== FALSE;
      $message = sprintf('(%s:%s): %s', $field_name, $field_id, $html);
      $this
        ->assertTrue($indicator_exists, $message);
    }
  }
}