You are here

public function UUIDTaxonomyTestCase::testTaxonomyCrud in Universally Unique IDentifier 7

Test CRUD on comments with UUID functions.

File

./uuid.test, line 593
Test suite for UUID module.

Class

UUIDTaxonomyTestCase
Tests the Taxonomy implementation.

Code

public function testTaxonomyCrud() {
  $perms = array(
    'administer taxonomy',
    'administer nodes',
    'bypass node access',
  );
  $user = $this
    ->drupalCreateUser($perms);
  $this
    ->drupalLogin($user);

  // Create a term by tagging a node. We'll use this node later too.
  $vocabulary = new stdClass();
  $vocabulary->vid = 1;
  $term = $this
    ->createTerm($vocabulary);
  $this
    ->assertUuid($term->uuid, 'Term UUID was generated.');

  // Test updating term.
  $term_test = clone $term;
  $term_test->name = 'new name';
  taxonomy_term_save($term_test);
  $term_test = taxonomy_term_load($term->tid);
  $this
    ->assertEqual($term_test->uuid, $term->uuid, 'Term UUID was intact after update.');

  // Test entity_uuid_load().
  $terms = entity_uuid_load('taxonomy_term', array(
    $term->uuid,
  ), array(), TRUE);
  $term_test = reset($terms);
  $this
    ->assertEqual($term_test->tid, $term->tid, 'Term was correctly loaded with UUID.');

  // The following tests depends on the Entity API module.
  if (module_exists('entity')) {

    // Test entity_uuid_save() for terms.
    $terms = entity_uuid_load('taxonomy_term', array(
      $term->uuid,
    ), array(), TRUE);
    $term_test = reset($terms);
    $term_test->tid = rand();
    $term_test->name = 'newer name';
    entity_uuid_save('taxonomy_term', $term_test);
    $term_test = taxonomy_term_load($term->tid);
    $this
      ->assertEqual($term_test->name, 'newer name', 'Saving term with UUID mapped to correct term.');
    $this
      ->assertEqual($term_test->uuid, $term->uuid, 'Term UUID was intact after saving with UUID.');

    // Test entity_uuid_delete() for nodes.
    entity_uuid_delete('taxonomy_term', $term->uuid);
    $term_test = taxonomy_term_load($term->tid);
    $this
      ->assertFalse($term_test, 'Deleting term with UUID worked.');
  }
}