1 entityreference.field.test | public EntityReferenceFieldTestCase::testShowLinksSetting() |
Tests the "Show links" setting for the field formatter "Rendered entity".
File
- core/
modules/ entityreference/ tests/ entityreference.field.test, line 72
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->backdropPost('admin/structure/types/manage/' . $this->contentType . '/display/default', array(
'fields[field_test][type]' => 'entityreference_entity_view',
), t('Save'));
// Set view mode option to "teaser" and enable the "Show links" option.
$this->backdropPostAJAX(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->backdropPostAJAX(NULL, $edit, 'field_test_formatter_settings_update');
$this->backdropPost(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->backdropCreateNode(array(
'type' => $this->contentType,
));
$node2 = $this->backdropCreateNode(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->backdropGet('node/' . $node2->nid);
$this->assertText('Read more');
// Now turn off the "Show links" setting.
$this->backdropGet('admin/structure/types/manage/' . $this->contentType . '/display/default');
$this->backdropPostAJAX(NULL, array(), 'field_test_formatter_settings_edit');
$edit = array(
'fields[field_test][settings_edit_form][settings][links]' => FALSE,
);
$this->backdropPostAJAX(NULL, $edit, 'field_test_formatter_settings_update');
$this->backdropPost(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->backdropGet('node/' . $node2->nid);
$this->assertNoText('Read more');
}