You are here

public function EntityReferenceFieldTestCase::testShowLinksSetting in Entity reference 7

Tests the "Show links" setting for the field formatter "Rendered entity".

File

tests/entityreference.field.test, line 77

Class

EntityReferenceFieldTestCase
Tests for the Entity Reference field.

Code

public function testShowLinksSetting() {

  // Create an entity reference field.
  $this
    ->createEntityReferenceField('test');

  // Set formatter to "Rendered entity".
  $this
    ->drupalPost('admin/structure/types/manage/' . $this->contentType . '/display', array(
    'fields[field_test][type]' => 'entityreference_entity_view',
  ), t('Save'));

  // Set view mode option to "teaser" and enable the "Show links" option.
  $this
    ->drupalPostAJAX(NULL, array(), 'field_test_formatter_settings_edit');
  $edit = array(
    'fields[field_test][settings_edit_form][settings][view_mode]' => 'teaser',
    'fields[field_test][settings_edit_form][settings][links]' => 1,
  );
  $this
    ->drupalPostAJAX(NULL, $edit, 'field_test_formatter_settings_update');
  $this
    ->drupalPost(NULL, array(), t('Save'));

  // Assert that the formatter says that links will be shown.
  $this
    ->assertText('Display links');
  $this
    ->assertNoText('Do not display links');

  // Create two nodes. The second node will reference the first one.
  $node1 = $this
    ->drupalCreateNode(array(
    'type' => $this->contentType,
  ));
  $node2 = $this
    ->drupalCreateNode(array(
    'type' => $this->contentType,
    'field_test' => array(
      LANGUAGE_NONE => array(
        0 => array(
          'target_id' => $node1->nid,
        ),
      ),
    ),
  ));

  // Assert that a read more link is shown on node 2.
  $this
    ->drupalGet('node/2');
  $this
    ->assertText('Read more');

  // Now turn off the "Show links" setting.
  $this
    ->drupalGet('admin/structure/types/manage/' . $this->contentType . '/display');
  $this
    ->drupalPostAJAX(NULL, array(), 'field_test_formatter_settings_edit');
  $edit = array(
    'fields[field_test][settings_edit_form][settings][links]' => FALSE,
  );
  $this
    ->drupalPostAJAX(NULL, $edit, 'field_test_formatter_settings_update');
  $this
    ->drupalPost(NULL, array(), t('Save'));

  // Assert that the formatter says that no links will be shown.
  $this
    ->assertText('Do not display links');

  // And assert that the read more link is no longer displayed on node 2.
  $this
    ->drupalGet('node/2');
  $this
    ->assertNoText('Read more');
}