You are here

function LinkTokenTest::testStaticTokenLinkCreate2 in Link 6.2

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

Creates a link field with a static title and an admin-entered token. Creates a node with a link and checks the title value.

Basically, I want to make sure the [title-raw] token works, because it's a token that changes from node to node, where [type]'s always going to be the same.

File

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

Class

LinkTokenTest
Testing that tokens can be used in link titles

Code

function testStaticTokenLinkCreate2() {
  $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' => 'value',
    'title_value' => $name . ' [title-raw]',
    'enable_tokens' => FALSE,
  ), 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][url]', 'URL found');
  $input = array(
    'href' => 'http://example.com/' . $this
      ->randomName(),
  );
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('node/add/page');
  $edit = array(
    'title' => $name,
    $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($name . ' ' . $name, $input['href']));
}