You are here

public function ClassifiedBasicTest::test1491880 in Classified Ads 6.3

Test token generation for issue #1491880.

File

tests/classified_basic.test, line 518
Basic test for known bugs in previous versions.

Class

ClassifiedBasicTest

Code

public function test1491880() {
  $this->group = __FUNCTION__;
  $this
    ->createUsers(array(
    'creator',
  ));
  $this
    ->drupalLogin($this->creatorUser);
  $types = array_keys(classified_node_info());
  $type = reset($types);

  // Get the Classified vocabulary id
  $vid = _classified_get('vid');

  // Create a term in it, do not assign a specific lifetime.
  $term_name = $this
    ->randomName(4) . " ' " . $this
    ->randomName(4);
  $term = array(
    'name' => $term_name,
    'description' => $this
      ->randomString(20),
    'vid' => $vid,
  );
  $status = taxonomy_save_term($term);
  $tid = $term['tid'];
  $this
    ->assertEqual($status, SAVED_NEW, t('Term @tid created in default vocabulary.', array(
    '@tid' => $tid,
  )), 'setup');

  // Create a node bearing that term.
  $title = $this
    ->randomName(4) . ' ' . $this
    ->randomName(4);
  module_load_include('inc', 'node', 'node.pages');
  $body = $this
    ->randomName(4) . ' ' . $this
    ->randomString(40);
  $format = FILTER_FORMAT_DEFAULT;
  $settings = array(
    'type' => $type,
    'format' => $format,
    'taxonomy' => array(
      $vid => $tid,
    ),
    'title' => $title,
    'body' => $body,
    'uid' => $this->creatorUser->uid,
  );
  $node = $this
    ->createNode($settings);

  // Make sure tokens are visible.
  $tokens = token_get_list('user');
  $tokens = reset($tokens);
  $token_names = array(
    'ads',
    'classified-ads-url',
  );
  foreach ($token_names as $token) {
    $this
      ->assertNotNull($tokens[$token], t('%token token found in user tokens.', array(
      '%token' => $token,
    )), $this->group);
  }

  // Check token replacement.
  $source = $this
    ->randomString(20);
  foreach ($token_names as $token) {
    $source .= " [{$token}] " . $this
      ->randomString(20);
  }
  $translation = token_replace_multiple($source, array(
    'user' => $this->creatorUser,
  ));
  $this
    ->assertTrue(preg_match('/' . $node->title . '/', $translation), t('Node title from token.'), $this->group);
  $url = url('user/' . $node->uid . '/classified', array(
    'absolute' => TRUE,
  ));
  $this
    ->assertTrue(preg_match("@{$url}@", $translation), t('User ads URL found from token.'), $this->group);
}