You are here

public function LinkTokenTest::testUserTokenLinkCreate in Link 7

Same name and namespace in other branches
  1. 6.2 tests/link.token.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/LinkTokenTest.test, line 38
Testing that tokens can be used in link titles.

Class

LinkTokenTest
Testing that tokens can be used in link titles.

Code

public function testUserTokenLinkCreate() {

  // Create field.
  $settings = array(
    'instance[settings][enable_tokens]' => 1,
  );
  $field_name = $this
    ->createLinkField('page', $settings);

  // Create page form.
  $this
    ->drupalGet('node/add/page');

  // $field_name = 'field_' . $name;.
  $this
    ->assertField($field_name . '[und][0][title]', 'Title found');
  $this
    ->assertField($field_name . '[und][0][url]', 'URL found');
  $input = array(
    'href' => 'http://example.com/' . $this
      ->randomName(),
    'label' => $this
      ->randomName(),
  );

  // $this->drupalLogin($this->web_user);.
  $this
    ->drupalGet('node/add/page');
  $edit = array(
    'title' => $input['label'],
    $field_name . '[und][0][title]' => $input['label'] . " [node:content-type:machine-name]",
    $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(l($input['label'] . ' page', $input['href']));
}