You are here

public function EmptyFieldsViewModesWebTestCase::testEmptyFieldsOutput in Empty fields 7.2

Tests that the module actually works.

File

tests/empty_fields.test, line 39
Tests for the empty fields module.

Class

EmptyFieldsViewModesWebTestCase
Helper test class with some added functions for testing.

Code

public function testEmptyFieldsOutput() {
  $edit = array(
    'status' => 1,
    'promote' => 1,
    'title' => $this
      ->randomName(8),
  );
  $this
    ->drupalPost("node/add/page", $edit, t('Save'));
  $node = $this
    ->drupalGetNodeByTitle($edit['title']);

  // Checks full and teaser display modes via default.
  $edit = array(
    'view_modes_custom[teaser]' => FALSE,
  );
  $this
    ->drupalPost('admin/structure/types/manage/page/display', $edit, t('Save'));
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText($node->title);
  $this
    ->drupalGet('node');
  $this
    ->assertText($node->title);

  // Enable the default setting to use empty text settings.
  $instance_info = field_info_instance('node', 'body', 'page');
  $instance_info['display']['default']['settings']['empty_fields_handler'] = 'EmptyFieldText';
  $instance_info['display']['default']['settings']['empty_fields_emptyfieldtext_empty_text'] = 'foo bar';
  $instance_info['display']['default']['settings']['empty_fields_empty_class'] = 'fb-class';
  field_update_instance($instance_info);

  // Checks full and teaser display modes.
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText($node->title);
  $this
    ->assertText('foo bar');
  $this
    ->drupalGet('admin/structure/types/manage/page/display');
  $this
    ->drupalGet('admin/structure/types/manage/page/display/teaser');
  $this
    ->drupalGet('node');
  $this
    ->assertText($node->title);
  $this
    ->assertText('foo bar');

  // Enable and configure the teaser display.
  $edit = array(
    'view_modes_custom[full]' => 'full',
    'view_modes_custom[teaser]' => 'teaser',
  );
  $this
    ->drupalPost('admin/structure/types/manage/page/display', $edit, t('Save'));
  $instance_info = field_info_instance('node', 'body', 'page');
  $instance_info['display']['teaser']['settings']['empty_fields_handler'] = 'EmptyFieldText';
  $instance_info['display']['teaser']['settings']['empty_fields_emptyfieldtext_empty_text'] = 'bar foo';
  $instance_info['display']['teaser']['settings']['empty_fields_empty_class'] = 'bf-class';
  field_update_instance($instance_info);
  $instance_info = field_info_instance('node', 'body', 'page');
  $instance_info['display']['full']['settings']['empty_fields_handler'] = '';
  field_update_instance($instance_info);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText($node->title);
  $this
    ->assertNoText('foo bar');
  $this
    ->assertNoText('bar foo');
  $this
    ->drupalGet('admin/structure/types/manage/page/display');
  $this
    ->drupalGet('admin/structure/types/manage/page/display/teaser');
  $this
    ->drupalGet('node');
  $this
    ->assertText($node->title);
  $this
    ->assertText('bar foo');
}