You are here

function BooleanFormatterSettingsTest::testBooleanFormatterSettings in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field/src/Tests/Boolean/BooleanFormatterSettingsTest.php \Drupal\field\Tests\Boolean\BooleanFormatterSettingsTest::testBooleanFormatterSettings()

Tests the formatter settings page for the Boolean formatter.

File

core/modules/field/src/Tests/Boolean/BooleanFormatterSettingsTest.php, line 85
Contains \Drupal\field\Tests\Boolean\BooleanFormatterSettingsTest.

Class

BooleanFormatterSettingsTest
Tests the Boolean field formatter settings.

Namespace

Drupal\field\Tests\Boolean

Code

function testBooleanFormatterSettings() {

  // List the options we expect to see on the settings form. Omit the one
  // with the Unicode check/x characters, which does not appear to work
  // well in WebTestBase.
  $options = array(
    'Yes / No',
    'True / False',
    'On / Off',
    'Enabled / Disabled',
    '1 / 0',
    'Custom',
  );

  // Define what the "default" option should look like, depending on the
  // field settings.
  $default = 'Field settings (@on / @off)';

  // For several different values of the field settings, test that the
  // options, including default, are shown correctly.
  $settings = array(
    array(
      'Yes',
      'No',
    ),
    array(
      'On',
      'Off',
    ),
    array(
      'TRUE',
      'FALSE',
    ),
  );
  foreach ($settings as $values) {

    // Set up the field settings.
    $this
      ->drupalGet('admin/structure/types/manage/' . $this->bundle . '/fields/node.' . $this->bundle . '.' . $this->fieldName);
    $this
      ->drupalPostForm(NULL, array(
      'settings[on_label]' => $values[0],
      'settings[off_label]' => $values[1],
    ), 'Save settings');

    // Open the Manage Display page and trigger the field settings form.
    $this
      ->drupalGet('admin/structure/types/manage/' . $this->bundle . '/display');
    $this
      ->drupalPostAjaxForm(NULL, array(), $this->fieldName . '_settings_edit');

    // Test that the settings options are present in the correct format.
    foreach ($options as $string) {
      $this
        ->assertText($string);
    }
    $this
      ->assertText(SafeMarkup::format($default, array(
      '@on' => $values[0],
      '@off' => $values[1],
    )));
  }
}