You are here

public function TextformatterTestCase::testFormatterOutput in Text list formatter 7

Test the general output of the display formatter.

File

./textformatter.test, line 70
Tests for the textformatter module.

Class

TextformatterTestCase
@file Tests for the textformatter module.

Code

public function testFormatterOutput() {
  $this
    ->drupalLogin($this->admin_user);
  $field_values = array(
    LANGUAGE_NONE => array(),
  );
  for ($i = 0; $i < 10; $i++) {
    $field_values[LANGUAGE_NONE][] = array(
      'value' => $this
        ->randomName(),
    );
  }
  $node = $this
    ->drupalCreateNode(array(
    $this->field_name => $field_values,
  ));
  $this
    ->verbose('Node: ' . var_export($node, TRUE));
  $page = $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->verbose('Page: ' . $page);
  $this
    ->drupalSetContent($page);
  $this
    ->assertResponse(200);
  foreach ($field_values[LANGUAGE_NONE] as $delta => $item) {
    $this
      ->assertText($item['value'], t('Field value !delta output on node.', array(
      '!delta' => $delta,
    )));
  }
  $items = array();
  foreach ($field_values[LANGUAGE_NONE] as $item) {
    $items[] = $item['value'];
  }

  // Test the default ul list.
  $options = array(
    'type' => 'ul',
    'items' => $items,
    'attributes' => array(
      'class' => array(
        'textformatter-list',
      ),
    ),
  );
  $ul = theme('item_list', $options);
  $this
    ->assertRaw($ul, 'The expected unordered list markup was produced.');

  // Update the field settings for ol list.
  $field_instance = field_info_instance('node', $this->field_name, $node->type);
  $field_instance['display']['default']['settings']['textformatter_type'] = 'ol';
  field_update_instance($field_instance);

  // Get the node page again.
  $this
    ->drupalGet('node/' . $node->nid);

  // Test the default ol list.
  $options['type'] = 'ol';
  $ol = theme('item_list', $options);
  $this
    ->assertRaw($ol, 'The expected ordered list markup was produced.');

  // Update the field settings for comma list.
  $field_instance['display']['default']['settings']['textformatter_type'] = 'comma';
  field_update_instance($field_instance);

  // Get the node page again.
  $this
    ->drupalGet('node/' . $node->nid);

  // Test the default comma list.
  unset($options['type']);
  $comma = theme('textformatter_comma', $options);
  $this
    ->assertRaw($comma, 'The expected comma list markup was produced.');
}