public function EmptyFieldsViewModesWebTestCase::testEmptyFieldsWithMultipleViewModes in Empty fields 7.2
Test multiple view modes work.
File
- tests/
empty_fields.test, line 112 - Tests for the empty fields module.
Class
- EmptyFieldsViewModesWebTestCase
- Helper test class with some added functions for testing.
Code
public function testEmptyFieldsWithMultipleViewModes() {
$edit = array(
'status' => 1,
'promote' => 1,
'title' => $this
->randomName(8),
);
$this
->drupalPost("node/add/page", $edit, t('Save'));
$node = $this
->drupalGetNodeByTitle($edit['title']);
$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']['default']['settings']['empty_fields_handler'] = 'EmptyFieldText';
$instance_info['display']['default']['settings']['empty_fields_emptyfieldtext_empty_text'] = 'foo bar 1';
$instance_info['display']['default']['settings']['empty_fields_empty_class'] = 'fb-class-1';
$instance_info['display']['full']['settings']['empty_fields_handler'] = 'EmptyFieldText';
$instance_info['display']['full']['settings']['empty_fields_emptyfieldtext_empty_text'] = 'foo bar 2';
$instance_info['display']['full']['settings']['empty_fields_empty_class'] = 'fb-class-2';
$instance_info['display']['teaser']['settings']['empty_fields_handler'] = 'EmptyFieldText';
$instance_info['display']['teaser']['settings']['empty_fields_emptyfieldtext_empty_text'] = 'foo bar 3';
$instance_info['display']['teaser']['settings']['empty_fields_empty_class'] = 'fb-class-3';
field_update_instance($instance_info);
$output = '';
$langcode = field_language('node', $node, 'body');
field_attach_prepare_view('node', array(
$node->nid => $node,
), 'default', $langcode);
entity_prepare_view('node', array(
$node->nid => $node,
), $langcode);
$build = field_attach_view('node', $node, 'default', $langcode);
$output .= drupal_render($build);
unset($node->_field_view_prepared);
field_attach_prepare_view('node', array(
$node->nid => $node,
), 'full', $langcode);
entity_prepare_view('node', array(
$node->nid => $node,
), $langcode);
$build = field_attach_view('node', $node, 'full', $langcode);
$output .= drupal_render($build);
unset($node->_field_view_prepared);
field_attach_prepare_view('node', array(
$node->nid => $node,
), 'teaser', $langcode);
entity_prepare_view('node', array(
$node->nid => $node,
), $langcode);
$build = field_attach_view('node', $node, 'teaser', $langcode);
$output .= drupal_render($build);
$this
->verbose($output);
$this
->assertTrue(strpos($output, 'foo bar 1'));
$this
->assertTrue(strpos($output, 'foo bar 2'));
$this
->assertTrue(strpos($output, 'foo bar 3'));
}