You are here

function UUIDFunctionalityTestCase::testDisabledNodeUUID in Universally Unique IDentifier 6

Verify uuid behavior for nodes.

File

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

Class

UUIDFunctionalityTestCase
Test basic uuid resolver functionality.

Code

function testDisabledNodeUUID() {

  // Set module settings.
  $settings = array(
    'uuid_automatic_for_nodes[page]' => FALSE,
  );
  $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 not attached to the node.
  $this
    ->assertTrue(empty($object->uuid), t("Node has no uuid field attached with disabled settings."), t("Node UUID"));
  $this
    ->assertTrue(empty($object->revision_uuid), t("Node has no revision_uuid field attached with disabled settings."), t("Node revision UUID"));

  // Create a new revision for this node.
  $object->revision = 1;
  node_save($object);

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

  // Test Programmatically setting UUIDs.
  $new_uuid = uuid_uuid();
  $revision_uuid = uuid_uuid();
  $options = array(
    'uid' => $account->uid,
    'type' => 'page',
    'uuid' => $new_uuid,
    'revision_uuid' => $revision_uuid,
  );
  $object = $this
    ->drupalCreateNode($options);
  $loaded_node = node_load($object->nid, NULL, TRUE);
  $this
    ->assertEqual($object->uuid, $new_uuid, t("Node uuid can be set programmatically with disabled settings."), 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 can be set programmatically with disabled settings."), 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"));
}