View source
<?php
class EntityReferenceFieldTestCase extends DrupalWebTestCase {
protected $contentType;
public static function getInfo() {
return array(
'name' => 'Entity Reference field',
'description' => 'Tests for the entity reference field formatters and widgets.',
'group' => 'Entity Reference',
);
}
public function setUp() {
parent::setUp(array(
'field_ui',
'entity',
'ctools',
'entityreference',
));
$this->admin_user = $this
->drupalCreateUser(array(
'access content',
'administer content types',
'administer nodes',
'bypass node access',
'administer filters',
'administer fields',
));
$this
->drupalLogin($this->admin_user);
$this->contentType = strtolower($this
->randomName(8));
$this
->drupalCreateContentType(array(
'name' => $this->contentType,
'type' => $this->contentType,
));
}
protected function createEntityReferenceField($field_name, $label = 'Test label') {
$bundle_path = 'admin/structure/types/manage/' . $this->contentType;
$this
->drupalPost($bundle_path . '/fields', array(
'fields[_add_new_field][label]' => $label,
'fields[_add_new_field][field_name]' => $field_name,
'fields[_add_new_field][type]' => 'entityreference',
'fields[_add_new_field][widget_type]' => 'entityreference_autocomplete',
), t('Save'));
$this
->drupalPost(NULL, array(), t('Save field settings'));
$this
->drupalPost(NULL, array(), t('Save settings'));
}
public function testShowLinksSetting() {
$this
->createEntityReferenceField('test');
$this
->drupalPost('admin/structure/types/manage/' . $this->contentType . '/display', array(
'fields[field_test][type]' => 'entityreference_entity_view',
), t('Save'));
$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'));
$this
->assertText('Display links');
$this
->assertNoText('Do not display links');
$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,
),
),
),
));
$this
->drupalGet('node/2');
$this
->assertText('Read more');
$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'));
$this
->assertText('Do not display links');
$this
->drupalGet('node/2');
$this
->assertNoText('Read more');
}
}