public function DynamicEntityReferenceTest::testFieldSettings in Dynamic Entity Reference 7
Tests field settings of dynamic entity reference field.
File
- ./
dynamic_entity_reference.test, line 81 - Contains tests for the module.
Class
- DynamicEntityReferenceTest
- Ensures that Dynamic Entity References field works correctly.
Code
public function testFieldSettings() {
$this
->drupalLogin($this->adminUser);
// Add a new dynamic entity reference field.
$this
->drupalGet('admin/structure/types/manage/ponies/fields');
$edit = array(
'fields[_add_new_field][label]' => 'Foobar',
'fields[_add_new_field][field_name]' => 'foobar',
'fields[_add_new_field][type]' => 'dynamic_entity_reference',
'fields[_add_new_field][widget_type]' => 'dynamic_entity_reference_default',
);
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->drupalPost(NULL, array(
'field[settings][entity_type_ids][]' => 'user',
), t('Save field settings'));
$this
->assertFieldByName('field_foobar[und][0][target_type]');
$this
->assertFieldByXPath("descendant-or-self::select[@name = 'field_foobar[und][0][target_type]']/option[@value = 'node']", 'node');
$this
->assertNoFieldByXPath("descendant-or-self::select[@name = 'field_foobar[und][0][target_type]']/option[@value = 'user']", 'user');
$this
->drupalPost(NULL, array(
'field[cardinality]' => '-1',
), t('Save settings'));
$this
->assertRaw(t('Saved %name configuration', array(
'%name' => 'Foobar',
)));
$field = field_info_field('field_foobar');
$excluded_entity_type_ids = $field['settings']['entity_type_ids'];
$this
->assertNotNull($excluded_entity_type_ids);
$this
->assertIdentical(array_keys($excluded_entity_type_ids), array(
'user',
));
// Check the include entity settings.
$this
->drupalGet('admin/structure/types/manage/ponies/fields/field_foobar');
$this
->drupalPost(NULL, array(
'field[cardinality]' => '-1',
'field[settings][exclude_entity_types]' => FALSE,
'field[settings][entity_type_ids][]' => 'user',
), t('Save settings'));
$this
->drupalGet('admin/structure/types/manage/ponies/fields/field_foobar');
$this
->assertFieldByName('field_foobar[und][0][target_type]');
$this
->assertFieldByXPath("descendant-or-self::select[@name = 'field_foobar[und][0][target_type]']/option[@value = 'user']", 'user');
$this
->assertNoFieldByXPath("descendant-or-self::select[@name = 'field_foobar[und][0][target_type]']/option[@value = 'node']", 'node');
$this
->drupalPost(NULL, array(), t('Save settings'));
$this
->assertRaw(t('Saved %name configuration', array(
'%name' => 'Foobar',
)));
$field = field_info_field('field_foobar');
$excluded_entity_type_ids = $field['settings']['entity_type_ids'];
$this
->assertNotNull($excluded_entity_type_ids);
$this
->assertIdentical(array_keys($excluded_entity_type_ids), array(
'user',
));
}