1 node.test NodeEntityViewModeAlterTest::testNodeViewModeChangeHiddenField()

Tests fields that were previously hidden when the display mode is changed.

File

core/modules/node/tests/node.test, line 3706
Tests for node.module.

Class

NodeEntityViewModeAlterTest
Tests changing display modes for nodes.

Code

function testNodeViewModeChangeHiddenField() {
  // Hide the tags field on the default display
  $instance = field_info_instance('node', 'field_tags', 'post');
  $instance['display']['default']['type'] = 'hidden';
  field_update_instance($instance);

  $web_user = $this->backdropCreateUser(array('create post content', 'edit own post content'));
  $this->backdropLogin($web_user);

  // Create a node.
  $edit = array();
  $langcode = LANGUAGE_NONE;
  $edit["title"] = $this->randomName(8);
  $edit["body[$langcode][0][value]"] = 'Data that should appear only in the body for the node.';
  $edit["body[$langcode][0][summary]"] = 'Extra data that should appear only in the teaser for the node.';
  $edit["field_tags[$langcode]"] = 'Extra tag';
  $this->backdropPost('node/add/post', $edit, t('Save'));

  $node = $this->backdropGetNodeByTitle($edit["title"]);

  // Set the flag to alter the display mode and view the node.
  state_set('node_test_change_view_mode', 'teaser');
  $this->backdropGet('node/' . $node->nid);

  // Check that teaser mode is viewed.
  $this->assertText('Extra data that should appear only in the teaser for the node.', 'Teaser text present');
  // Make sure body text is not present.
  $this->assertNoText('Data that should appear only in the body for the node.', 'Body text not present');
  // Make sure tags are present.
  $this->assertText('Extra tag', 'Taxonomy term present');

  // Test that the correct build mode has been set.
  $build = node_view($node);
  $this->assertEqual($build['#view_mode'], 'teaser', 'The display mode has correctly been set to teaser.');
}