function URLFieldTestCase::testURLFieldAutomaticTitles in URL field 7
File
- ./
url.test, line 153 - Tests for url.module.
Class
- URLFieldTestCase
- Tests for URL field types.
Code
function testURLFieldAutomaticTitles() {
$node = $this
->drupalCreateNode(array(
'title' => 'Node "title"',
));
// Create a field with settings to validate.
$this->field = array(
'field_name' => drupal_strtolower($this
->randomName()),
'type' => 'url',
);
field_create_field($this->field);
$this->instance = array(
'field_name' => $this->field['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'settings' => array(
'title_field' => FALSE,
'title_fetch' => TRUE,
),
'widget' => array(
'type' => 'url_external',
),
'display' => array(
'default' => array(
'type' => 'url_default',
),
),
);
field_create_instance($this->instance);
// Submit an URL on the current site.
$langcode = LANGUAGE_NONE;
$value = url('node/' . $node->nid, array(
'absolute' => TRUE,
));
$edit = array(
"{$this->field['field_name']}[{$langcode}][0][value]" => $value,
);
$this
->drupalPost('test-entity/add/test-bundle', $edit, t('Save'));
preg_match('|test-entity/manage/(\\d+)/edit|', $this->url, $match);
$id = $match[1];
$entity = field_test_entity_test_load($id);
$expected_title = t('!title | !sitename', array(
'!title' => $node->title,
'!sitename' => variable_get('site_name', 'Drupal'),
));
$this
->assertEqual($entity->{$this->field['field_name']}[$langcode][0]['title'], $expected_title, 'Title fetched and decoded from URL');
}