You are here

function URLFieldTestCase::_testURLFieldWithTitles in URL field 7

File

./url.test, line 96
Tests for url.module.

Class

URLFieldTestCase
Tests for URL field types.

Code

function _testURLFieldWithTitles() {

  // 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' => TRUE,
      'title_fetch' => FALSE,
    ),
    'widget' => array(
      'type' => 'url_external',
    ),
    'display' => array(
      'default' => array(
        'type' => 'url_default',
      ),
    ),
  );
  field_create_instance($this->instance);

  // Display creation form.
  $this
    ->drupalGet('test-entity/add/test-bundle');
  $langcode = LANGUAGE_NONE;
  $this
    ->assertFieldByName("{$this->field['field_name']}[{$langcode}][0][value]", '', 'URL value field is displayed');
  $this
    ->assertFieldByName("{$this->field['field_name']}[{$langcode}][0][title]", '', 'URL title field is displayed');

  // Submit a signed URL value.
  $value = 'http://www.google.com/';
  $edit = array(
    "{$this->field['field_name']}[{$langcode}][0][value]" => $value,
    "{$this->field['field_name']}[{$langcode}][0][title]" => '',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  preg_match('|test-entity/manage/(\\d+)/edit|', $this->url, $match);
  $id = $match[1];
  $this
    ->assertRaw(t('test_entity @id has been created.', array(
    '@id' => $id,
  )), 'Entity was created');
  $expected_link = l($value, $value);
  $this
    ->assertRaw($expected_link, 'Link with URL as the title is displayed.');
  $title = $this
    ->randomName();
  $edit = array(
    "{$this->field['field_name']}[{$langcode}][0][title]" => $title,
  );
  $this
    ->drupalPost("test-entity/manage/{$id}/edit", $edit, t('Save'));
  $this
    ->assertRaw(t('test_entity @id has been updated.', array(
    '@id' => $id,
  )), 'Entity was updated');
  $expected_link = l($title, $value);
  $this
    ->assertRaw($expected_link, 'Link with overridden title is displayed.');
}