You are here

function OptionsFieldUITest::testNodeDisplay in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/options/src/Tests/OptionsFieldUITest.php \Drupal\options\Tests\OptionsFieldUITest::testNodeDisplay()

Tests normal and key formatter display on node display.

File

core/modules/options/src/Tests/OptionsFieldUITest.php, line 315
Contains \Drupal\options\Tests\OptionsFieldUITest.

Class

OptionsFieldUITest
Tests the Options field UI functionality.

Namespace

Drupal\options\Tests

Code

function testNodeDisplay() {
  $this->fieldName = strtolower($this
    ->randomMachineName());
  $this
    ->createOptionsField('list_integer');
  $node = $this
    ->drupalCreateNode(array(
    'type' => $this->type,
  ));
  $on = $this
    ->randomMachineName();
  $off = $this
    ->randomMachineName();
  $edit = array(
    'settings[allowed_values]' => "1|{$on}\n        0|{$off}",
  );
  $this
    ->drupalPostForm($this->adminPath, $edit, t('Save field settings'));
  $this
    ->assertText(format_string('Updated field @field_name field settings.', array(
    '@field_name' => $this->fieldName,
  )), "The 'On' and 'Off' form fields work for boolean fields.");

  // Select a default value.
  $edit = array(
    $this->fieldName => '1',
  );
  $this
    ->drupalPostForm('node/' . $node
    ->id() . '/edit', $edit, t('Save and keep published'));

  // Check the node page and see if the values are correct.
  $file_formatters = array(
    'list_default',
    'list_key',
  );
  foreach ($file_formatters as $formatter) {
    $edit = array(
      "fields[{$this->fieldName}][type]" => $formatter,
    );
    $this
      ->drupalPostForm('admin/structure/types/manage/' . $this->typeName . '/display', $edit, t('Save'));
    $this
      ->drupalGet('node/' . $node
      ->id());
    if ($formatter == 'list_default') {
      $output = $on;
    }
    else {
      $output = '1';
    }
    $elements = $this
      ->xpath('//div[text()="' . $output . '"]');
    $this
      ->assertEqual(count($elements), 1, 'Correct options found.');
  }
}