You are here

public function LinkFieldCrudTest::testCrudTitleOnlyTitleNoLink in Link 7

CRUD Title Only Title No Link.

Testing that if you have the title but no url, the title is not sanitized twice.

File

tests/LinkFieldCrudTest.test, line 257
Testing that users can not input bad URLs or labels.

Class

LinkFieldCrudTest
Testing that users can not input bad URLs or labels.

Code

public function testCrudTitleOnlyTitleNoLink() {
  $this->web_user = $this
    ->drupalCreateUser(array(
    'administer content types',
    'administer fields',
    'access content',
    'create page content',
  ));
  $this
    ->drupalLogin($this->web_user);

  // Create field.
  $name = strtolower($this
    ->randomName());
  $field_name = 'field_' . $name;
  $edit = array(
    'fields[_add_new_field][label]' => $name,
    'fields[_add_new_field][field_name]' => $name,
    'fields[_add_new_field][type]' => 'link_field',
    'fields[_add_new_field][widget_type]' => 'link_field',
  );
  $this
    ->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
  $this
    ->drupalPost(NULL, array(), t('Save field settings'));
  $this
    ->drupalPost(NULL, array(
    'instance[settings][url]' => 1,
  ), t('Save settings'));

  // Is field created?
  $this
    ->assertRaw(t('Saved %label configuration', array(
    '%label' => $name,
  )), 'Field added');

  // Create page form.
  $this
    ->drupalGet('node/add/page');
  $this
    ->assertField($field_name . '[und][0][url]', 'URL found');
  $input = array(
    'title' => 'This & That',
    'href' => '',
  );
  $edit = array(
    'title' => $name,
    $field_name . '[und][0][title]' => $input['title'],
    $field_name . '[und][0][url]' => $input['href'],
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $url = $this
    ->getUrl();

  // Change to anonymous user.
  $this
    ->drupalLogout();
  $this
    ->drupalGet($url);
  $this
    ->assertRaw('This & That');
}