You are here

function LinkTokenTest::testUserTokenLinkCreate in Link 6.2

Same name and namespace in other branches
  1. 7 tests/LinkTokenTest.test \LinkTokenTest::testUserTokenLinkCreate()

Creates a link field with a required title enabled for user-entered tokens. Creates a node with a token in the link title and checks the value.

File

tests/link.token.test, line 46
Contains simpletests making sure token integration works.

Class

LinkTokenTest
Testing that tokens can be used in link titles

Code

function testUserTokenLinkCreate() {
  $account = $this
    ->drupalCreateUser(array(
    'administer content types',
    'access content',
    'create page content',
  ));
  $this
    ->drupalLogin($account);

  // create field
  $name = strtolower($this
    ->randomName());
  $edit = array(
    '_add_new_field[label]' => $name,
    '_add_new_field[field_name]' => $name,
    '_add_new_field[type]' => 'link',
    '_add_new_field[widget_type]' => 'link',
  );
  $this
    ->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
  $this
    ->drupalPost(NULL, array(
    'title' => 'required',
    'enable_tokens' => TRUE,
  ), t('Save field settings'));

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

  // create page form
  $this
    ->drupalGet('node/add/page');
  $field_name = 'field_' . $name;
  $this
    ->assertField($field_name . '[0][title]', 'Title found');
  $this
    ->assertField($field_name . '[0][url]', 'URL found');
  $input = array(
    'href' => 'http://example.com/' . $this
      ->randomName(),
    'label' => $this
      ->randomName(),
  );
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('node/add/page');
  $edit = array(
    'title' => $input['label'],
    $field_name . '[0][title]' => $input['label'] . " [type]",
    $field_name . '[0][url]' => $input['href'],
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $url = $this
    ->getUrl();

  // change to anonymous user
  $this
    ->drupalLogout();
  $this
    ->drupalGet($url);
  $this
    ->assertRaw(l($input['label'] . ' page', $input['href']));
}