You are here

function UUIDFunctionalityTestCase::testChangedSettingNodeUUID in Universally Unique IDentifier 6

Verify uuid behavior with changed settings. All settings are forced to disabled, then a node is created (with no UUID). Then settings are enabled, and the node is resaved, which should trigger UUIDs being created.

File

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

Class

UUIDFunctionalityTestCase
Test basic uuid resolver functionality.

Code

function testChangedSettingNodeUUID() {

  // 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',
  );
  $object1 = $this
    ->drupalCreateNode($options);
  $object2 = $this
    ->drupalCreateNode($options);

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

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

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

  // Now programmatically set UUIDs and test with object2
  $new_uuid = uuid_uuid();
  $revision_uuid = uuid_uuid();
  $object2->uuid = $new_uuid;
  $object2->revision_uuid = $revision_uuid;
  node_save($object2);
  $loaded_node = node_load($object2->nid, NULL, TRUE);
  $this
    ->assertEqual($object2->uuid, $new_uuid, t("Node uuid can be set programmatically with changed settings."), t("Node UUID"));
  $this
    ->assertEqual($object2->uuid, $loaded_node->uuid, t("Node uuid with changed settings is being returned correctly."), t("Node UUID"));
  $this
    ->assertEqual($object2->revision_uuid, $revision_uuid, t("Node revision uuid can be set programmatically with changed settings."), t("Node Revision UUID"));
  $this
    ->assertEqual($object2->revision_uuid, $loaded_node->revision_uuid, t("Node revision uuid with changed settings is being returned correctly."), t("Node Revision UUID"));

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