You are here

function UUIDFunctionalityTestCase::testEnabledNodeUUID in Universally Unique IDentifier 6

Verify uuid behavior for nodes.

File

./uuid.test, line 354
Functionality tests for UUID module.

Class

UUIDFunctionalityTestCase
Test basic uuid resolver functionality.

Code

function testEnabledNodeUUID() {

  // Set module settings.
  $settings = array(
    'uuid_automatic_for_nodes[page]' => TRUE,
  );
  $this
    ->uuidSettingsSet($settings);

  // Create a user.
  $account = $this
    ->drupalCreateUser(array(
    'create page content',
  ));

  // Create a node with that user.
  $options = array(
    'uid' => $account->uid,
    'type' => 'page',
  );
  $object = $this
    ->drupalCreateNode($options);

  // Verify fields are attached to the node.
  $this
    ->assertIsUUID($object->uuid, t("Node has uuid field attached with enabled settings."), t("Node UUID"));
  $this
    ->assertIsUUID($object->revision_uuid, t("Node has revision uuid field attached with enabled settings."), t("Node revision UUID"));

  // Show current node only in verbose mode.
  $this
    ->verbose(print_r($object, 1));

  // Test saving without a new revision
  $uuid = $object->uuid;
  $revision_uuid = $object->revision_uuid;
  $object->revision = FALSE;
  node_save($object);
  $loaded_object = node_load($object->nid, NULL, TRUE);
  $this
    ->assertEqual($object->uuid, $uuid, t("Node uuid is preserved after update with revisioning off."), t("Node UUID"));
  $this
    ->assertEqual($loaded_object->uuid, $uuid, t("Node uuid loads correctly after update with revisioning off."), t("Node UUID"));
  $this
    ->assertEqual($object->revision_uuid, $revision_uuid, t("Node revision uuid is preserved after update with revisioning off."), t("Node Revision UUID"));
  $this
    ->assertEqual($loaded_object->revision_uuid, $revision_uuid, t("Node revision uuid loads correctly after update with revisioning off."), t("Node Revision UUID"));

  // make a copy of this node.
  $node = clone $object;

  // Create a new revision for this node.
  $object->revision = 1;
  node_save($object);
  $loaded_node = node_load($object->nid, NULL, TRUE);

  // Verify fields are attached to the node.
  $this
    ->assertIsUUID($object->uuid, t("Node has uuid field attached with enabled settings."), t("Node UUID"));
  $this
    ->assertIsUUID($object->revision_uuid, t("Node has revision uuid field attached with enabled settings."), t("Node revision UUID"));

  // A new revision uuid must be created.
  $this
    ->assertEqual($object->uuid, $node->uuid, t("Node uuid is being updated successfully."), t("Node UUID"));
  $this
    ->assertNotEqual($object->revision_uuid, $node->revision_uuid, t("Node revision uuid is being updated successfully."), t("Node revision UUID"));

  // Verify altered object reflects what's really in the database
  $this
    ->assertEqual($object->uuid, $loaded_node->uuid, t("Node uuid is being returned correctly."), t("Node UUID"));
  $this
    ->assertEqual($object->revision_uuid, $loaded_node->revision_uuid, t("Node revision uuid is being returned correctly."), t("Node revision UUID"));

  // Replace the UUID
  $new_uuid = uuid_uuid();
  $revision_uuid = uuid_uuid();
  $object->uuid = $new_uuid;
  $object->revision_uuid = $revision_uuid;
  node_save($object);
  $loaded_node = node_load($object->nid, NULL, TRUE);
  $this
    ->assertEqual($object->uuid, $new_uuid, t("Node uuid is being changed correctly."), t("Node UUID"));
  $this
    ->assertEqual($object->uuid, $loaded_node->uuid, t("Node uuid is being returned correctly."), t("Node UUID"));
  $this
    ->assertEqual($object->revision_uuid, $revision_uuid, t("Node revision uuid is being changed correctly."), t("Node Revision UUID"));
  $this
    ->assertEqual($object->revision_uuid, $loaded_node->revision_uuid, t("Node revision uuid is being returned correctly."), t("Node Revision UUID"));

  // Show current node only in verbose mode.
  $this
    ->verbose(print_r($node, 1));
}