You are here

function TokenEntityTestCase::testEntityMapping in Token 7

File

./token.test, line 678
Test integration for the token module.

Class

TokenEntityTestCase

Code

function testEntityMapping() {
  $this
    ->assertIdentical(token_get_entity_mapping('token', 'node'), 'node');
  $this
    ->assertIdentical(token_get_entity_mapping('token', 'term'), 'taxonomy_term');
  $this
    ->assertIdentical(token_get_entity_mapping('token', 'vocabulary'), 'taxonomy_vocabulary');
  $this
    ->assertIdentical(token_get_entity_mapping('token', 'invalid'), FALSE);
  $this
    ->assertIdentical(token_get_entity_mapping('token', 'invalid', TRUE), 'invalid');
  $this
    ->assertIdentical(token_get_entity_mapping('entity', 'node'), 'node');
  $this
    ->assertIdentical(token_get_entity_mapping('entity', 'taxonomy_term'), 'term');
  $this
    ->assertIdentical(token_get_entity_mapping('entity', 'taxonomy_vocabulary'), 'vocabulary');
  $this
    ->assertIdentical(token_get_entity_mapping('entity', 'invalid'), FALSE);
  $this
    ->assertIdentical(token_get_entity_mapping('entity', 'invalid', TRUE), 'invalid');

  // Test that when we send the mis-matched entity type into token_replace()
  // that we still get the tokens replaced.
  $vocabulary = taxonomy_vocabulary_machine_name_load('tags');
  $term = $this
    ->addTerm($vocabulary);
  $this
    ->assertIdentical(token_replace('[vocabulary:name]', array(
    'taxonomy_vocabulary' => $vocabulary,
  )), $vocabulary->name);
  $this
    ->assertIdentical(token_replace('[term:name][term:vocabulary:name]', array(
    'taxonomy_term' => $term,
  )), $term->name . $vocabulary->name);
}