You are here

protected function NameWidgetTest::assertFieldSettings in Name Field 8

Asserts that the field settings appear in the correct order.

Parameters

array $settings: The field settings, as form post array.

1 call to NameWidgetTest::assertFieldSettings()
NameWidgetTest::testFieldEntry in tests/src/Functional/NameWidgetTest.php
The most basic test.

File

tests/src/Functional/NameWidgetTest.php, line 182

Class

NameWidgetTest
Various tests on creating a name widget on a node.

Namespace

Drupal\Tests\name\Functional

Code

protected function assertFieldSettings(array $settings) {
  $xpath = '//div[@id="edit-field-name-test-wrapper"]/div/div';
  $elements = $this
    ->xpath($xpath);
  $this
    ->assertNotEmpty($elements, 'No components found.');
  $content = '';
  foreach ($elements as $element) {
    $content .= str_replace([
      "\n",
      "\r",
    ], " ", $element
      ->getHtml());
  }
  $this
    ->verbose(Html::escape($content));
  $this
    ->verbose($settings["settings[component_layout]"]);
  switch ($settings["settings[component_layout]"]) {
    case 'asian':
      $regexp = '/name-family-wrapper.*name-middle-wrapper.*name-given-wrapper.*name-title-wrapper.*name-credentials-wrapper.*/';
      if (strpos($content, 'name-generational-wrapper')) {
        $this
          ->assertTrue(FALSE, "Generational field is not rendered with asian layout.");
      }
      break;
    case 'eastern':
      $regexp = '/name-title-wrapper.*name-family-wrapper.*name-given-wrapper.*name-middle-wrapper.*name-generational-wrapper.*name-credentials-wrapper.*/';
      break;
    case 'german':
      $regexp = '/name-title-wrapper.*name-credentials-wrapper.*name-given-wrapper.*name-middle-wrapper.*name-family-wrapper.*/';
      if (strpos($content, 'name-generational-wrapper')) {
        $this
          ->assertTrue(FALSE, "Generational field is not rendered with german layout.");
      }
      break;
    case 'default':
    default:
      $regexp = '/name-title-wrapper.*name-given-wrapper.*name-middle-wrapper.*name-family-wrapper.*name-generational-wrapper.*name-credentials-wrapper.*/';
      break;
  }
  $this
    ->assertTrue((bool) preg_match($regexp, $content), 'Generational field wrapper classes appear to be in the correct order.');

  // @todo: Tests for settings[credentials_inline] setting.
}