You are here

public function DoubleFieldFormattersTestCase::testFormmaters in Double Field 7.2

Test formatters.

File

tests/double_field_formatters.test, line 31
Tests for Double field formatters.

Class

DoubleFieldFormattersTestCase
Test case for Double field formatters.

Code

public function testFormmaters() {
  $this
    ->drupalGet("admin/structure/types/manage/{$this->type_name}/display");
  $formatters = DoubleFieldFormatter::getAllFormatterTypes();

  // Check whether double field formatters are accessible.
  foreach ($formatters as $formatter_type => $label) {
    $found = $this
      ->xpath("//select[@name='fields[{$this->field_name}][type]']/option[@value='{$formatter_type}' and text()='{$label}']");
    $this
      ->assertTrue($found, '«' . $label . '» formatter was found');
  }
  $this
    ->assertTrue(count($formatters) == count($this
    ->xpath("//select[@name='fields[{$this->field_name}][type]']/option[@value != 'hidden']")), 'All double field formatters were found');

  // Iterate through all supported formatter types.
  foreach ($formatters as $formatter_type => $label) {
    $this
      ->drupalGet("admin/structure/types/manage/{$this->type_name}/display");
    $formatter = new DoubleFieldFormatter($formatter_type);

    // Change the formatter and verify that it is selected.
    $edit = array(
      "fields[{$this->field_name}][type]" => $formatter
        ->getType(),
      'refresh_rows' => $this->field_name,
    );
    $this
      ->drupalPostAJAX(NULL, $edit, array(
      'op' => t('Refresh'),
    ));
    $this
      ->assertFieldByName("fields[{$this->field_name}][type]", $formatter
      ->getType(), t('The expected formatter is selected.'));
    $this
      ->drupalPostAJAX(NULL, array(), $this->field_name . '_formatter_settings_edit');
    $input = $formatter
      ->getSettingsFormInput($this->field_name);
    $this
      ->drupalPostAJAX(NULL, $input, array(
      $this->field_name . '_formatter_settings_update' => t('Update'),
    ));
    $this
      ->drupalPostAJAX(NULL, array(), $this->field_name . '_formatter_settings_edit');
    $this
      ->verbose("Ending URL: {$this->url}<hr/>" . $this
      ->drupalGetContent());
    $validators = $formatter
      ->getSettingsFormValidators($this->field_name);
    $this
      ->validate($validators, "«{$label}» formatter settings form is valid.");
    $this
      ->drupalPost(NULL, array(), t('Save'));
    $this
      ->assertRaw('Your settings have been saved.');
    $this
      ->assertRaw($formatter
      ->getSummary(), "«{$label}» formatter summary is valid.");
    $this
      ->drupalGet('node/' . $this->node->nid);
    $items = field_get_items('node', $this->node, $this->field_name);
    $validators = $formatter
      ->getFormatterValidators($this->field_name, $items);
    $this
      ->validate($validators, "«{$label}» formatter is valid");
  }
}