uuid.test 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. <?php
  2. /**
  3. * @file
  4. * Test suite for UUID module.
  5. */
  6. /**
  7. * Base class with some helper methods.
  8. */
  9. class UUIDTestCase extends DrupalWebTestCase {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. function setUp() {
  14. parent::setUp(func_get_args());
  15. }
  16. /**
  17. * Helper function that asserts a UUID.
  18. */
  19. function assertUUID($uuid, $message = NULL) {
  20. $this->assertTrue(uuid_is_valid($uuid), $message);
  21. }
  22. }
  23. /**
  24. * Tests the UUID API functions.
  25. */
  26. class UUIDAPITestCase extends UUIDTestCase {
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public static function getInfo() {
  31. return array(
  32. 'name' => 'UUID API',
  33. 'description' => 'Tests the UUID API functions.',
  34. 'group' => 'UUID',
  35. );
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. function setUp() {
  41. parent::setUp('uuid');
  42. }
  43. /**
  44. * Tests uuid function calls.
  45. */
  46. function testAPIFunctions() {
  47. // This is a valid UUID, we know that.
  48. $valid_uuid = '0ab26e6b-f074-4e44-9da6-1205fa0e9761';
  49. // Test the uuid_is_valid() function.
  50. $this->assertUUID($valid_uuid, 'UUID validation works.');
  51. // The default generator is 'php'.
  52. $uuid = uuid_generate();
  53. $this->assertUUID($uuid, 'PHP generator works.');
  54. // Test the 'mysql' generator.
  55. variable_set('uuid_generator', 'mysql');
  56. drupal_static_reset('uuid_generate');
  57. $uuid = uuid_generate();
  58. $this->assertUUID($uuid, 'MySQL generator works.');
  59. }
  60. }
  61. /**
  62. * Tests the Entity API functions.
  63. */
  64. class UUIDEntityTestCase extends UUIDTestCase {
  65. /**
  66. * {@inheritdoc}
  67. */
  68. public static function getInfo() {
  69. return array(
  70. 'name' => 'Entity API functions',
  71. 'description' => 'Tests the Entity API functions.',
  72. 'group' => 'UUID',
  73. );
  74. }
  75. /**
  76. * {@inheritdoc}
  77. */
  78. function setUp() {
  79. parent::setUp('uuid');
  80. }
  81. /**
  82. * Tests Entity API's UUID functions.
  83. */
  84. function testEntityAPIFunctions() {
  85. // Create some entities that we will work with.
  86. $user = $this->drupalCreateUser();
  87. $node = $this->drupalCreateNode(array('title' => 'original title', 'uid' => $user->uid));
  88. // Test entity_get_id_by_uuid().
  89. $nids = entity_get_id_by_uuid('node', array($node->uuid), FALSE);
  90. $this->assertTrue(in_array($node->nid, $nids), 'Lookup of entity ID works.');
  91. $vids = entity_get_id_by_uuid('node', array($node->vuuid), TRUE);
  92. $this->assertTrue(in_array($node->vid, $vids), 'Lookup of entity revision ID works.');
  93. // Test entity_get_uuid_by_id().
  94. $uuids = entity_get_uuid_by_id('node', array($node->nid), FALSE);
  95. $this->assertTrue(in_array($node->uuid, $uuids), 'Lookup of entity UUID works.');
  96. $vuuids = entity_get_uuid_by_id('node', array($node->vid), TRUE);
  97. $this->assertTrue(in_array($node->vuuid, $vuuids), 'Lookup of entity revision UUID works.');
  98. }
  99. }
  100. /**
  101. * Tests the User implementation.
  102. */
  103. class UUIDUserTestCase extends UUIDTestCase {
  104. /**
  105. * {@inheritdoc}
  106. */
  107. public static function getInfo() {
  108. return array(
  109. 'name' => 'User implementation',
  110. 'description' => 'Tests the User implementation.',
  111. 'group' => 'UUID',
  112. );
  113. }
  114. /**
  115. * {@inheritdoc}
  116. */
  117. function setUp() {
  118. // Some tests depends on the optional Entity API module.
  119. if (module_exists('entity')) {
  120. parent::setUp('uuid', 'entity');
  121. }
  122. else {
  123. parent::setUp('uuid');
  124. }
  125. }
  126. /**
  127. * Test CRUD on users with UUID functions.
  128. */
  129. function testUserCRUD() {
  130. $user = $this->drupalCreateUser();
  131. $this->assertUUID($user->uuid, 'User UUID was generated.');
  132. // Test updating user.
  133. $user_test = clone $user;
  134. user_save($user_test, array('name' => 'new name'));
  135. $user_test = user_load($user->uid, TRUE);
  136. $this->assertEqual($user_test->uuid, $user->uuid, 'User UUID was intact after update.');
  137. // Test entity_uuid_load().
  138. $users = entity_uuid_load('user', array($user->uuid), array(), TRUE);
  139. $user_test = reset($users);
  140. $this->assertEqual($user_test->uid, $user->uid, 'User was correctly loaded with UUID.');
  141. // The following tests depends on the optional Entity API module.
  142. if (module_exists('entity')) {
  143. // Test entity_uuid_save() for users.
  144. $user_test = clone $user;
  145. $user_test->uid = rand();
  146. $user_test->name = 'new name';
  147. entity_uuid_save('user', $user_test);
  148. $user_test = user_load($user->uid, TRUE);
  149. $this->assertEqual($user_test->name, 'new name', 'Saving user with UUID mapped to correct user.');
  150. $this->assertEqual($user_test->uuid, $user->uuid, 'User UUID was intact after saving with UUID.');
  151. // Test entity_uuid_delete() for users.
  152. entity_uuid_delete('user', $user->uuid);
  153. $user_test = user_load($user->uid);
  154. $this->assertFalse($user_test, 'Deleting user with UUID worked.');
  155. }
  156. }
  157. }
  158. /**
  159. * Tests the Node implementation.
  160. */
  161. class UUIDNodeTestCase extends UUIDTestCase {
  162. /**
  163. * {@inheritdoc}
  164. */
  165. public static function getInfo() {
  166. return array(
  167. 'name' => 'Node implementation',
  168. 'description' => 'Tests the Node implementation.',
  169. 'group' => 'UUID',
  170. );
  171. }
  172. /**
  173. * {@inheritdoc}
  174. */
  175. function setUp() {
  176. // Some tests depends on the optional Entity API module.
  177. if (module_exists('entity')) {
  178. parent::setUp('uuid', 'entity');
  179. }
  180. else {
  181. parent::setUp('uuid');
  182. }
  183. }
  184. /**
  185. * Tests CRUD on nodes with UUID functions.
  186. *
  187. * @todo
  188. * Break out into multiple test methods to loosen coupling between tests.
  189. */
  190. function testNodeCRUD() {
  191. // Create some entities that we will work with.
  192. $user = $this->drupalCreateUser();
  193. $node = $this->drupalCreateNode(array('title' => 'original title', 'uid' => $user->uid));
  194. $this->assertUUID($node->uuid, 'Node UUID was generated.');
  195. $this->assertUUID($node->vuuid, 'Node revision UUID was generated.');
  196. // Test node update, without creating new revision.
  197. $node_test = clone $node;
  198. $node_test->title = 'original title';
  199. $node_test->revision = FALSE;
  200. node_save($node_test);
  201. $node_test = node_load($node->nid, FALSE, TRUE);
  202. $this->assertEqual($node_test->uuid, $node->uuid, 'Node UUID was intact after update, when not creating new revision.');
  203. $this->assertEqual($node_test->vuuid, $node->vuuid, 'Node revision UUID was intact after updating, when not creating new revision.');
  204. // Save the original revision IDs that we will test with later.
  205. $vid_old = $node_test->vid;
  206. $vuuid_old = $node_test->vuuid;
  207. $uuid_old = $node_test->uuid;
  208. // Test node update, with new revision.
  209. $node_test = clone $node;
  210. $node_test->title = 'newer title';
  211. $node_test->revision = TRUE;
  212. node_save($node_test);
  213. $node_test = node_load($node->nid, FALSE, TRUE);
  214. $this->assertEqual($node_test->uuid, $node->uuid, 'Node UUID was intact after updating, when creating new revision.');
  215. $this->assertNotEqual($node_test->vuuid, $node->vuuid, 'A new node revision UUID was generated, when creating new revision.');
  216. $this->assertUUID($node_test->vuuid, 'The new node revision UUID was valid.');
  217. // Test entity_uuid_load().
  218. // Save some variables that we will test against.
  219. $nid_test = $node_test->nid;
  220. $vid_test = $node_test->vid;
  221. $uid_test = $user->uuid;
  222. $uuid_test = $node_test->uuid;
  223. $vuuid_test = $node_test->vuuid;
  224. $nodes = entity_uuid_load('node', array($node->uuid), array(), TRUE);
  225. $node_test = reset($nodes);
  226. $this->assertEqual($node_test->nid, $nid_test, 'Node ID was correct when loading with UUID.');
  227. $this->assertEqual($node_test->vid, $vid_test, 'Node revision ID was correct when loading with UUID.');
  228. $this->assertEqual($node_test->uid, $uid_test, "Node author ID was transformed to UUID when loaded with UUID.");
  229. $this->assertEqual($node_test->uuid, $uuid_test, 'Node UUID was correct when loading with UUID.');
  230. $this->assertEqual($node_test->vuuid, $vuuid_test, 'Node revision UUID was correct when loading with UUID.');
  231. // Test entity_uuid_load() with conditions.
  232. // Load the previous revision UUID that we saved earlier.
  233. $nodes = entity_uuid_load('node', array($uuid_test), array('vuuid' => $vuuid_old));
  234. $node_test = reset($nodes);
  235. $this->assertTrue((($node_test->uuid == $uuid_test) && ($node_test->nid && $node->nid)), 'The correct entity was loaded when loading a universal entity with a revision UUID condition.');
  236. $this->assertEqual($node_test->vuuid, $vuuid_old, 'Correct revision UUID was loaded when loading a universal entity with a revision UUID condition.');
  237. $this->assertEqual($node_test->vid, $vid_old, 'Correct revision ID was loaded when loading a universal entity with a revision UUID condition.');
  238. $this->assertEqual($node_test->title, 'original title', 'Correct title was loaded when loading a universal entity with a revision UUID condition.');
  239. // The following tests depends on the optional Entity API module.
  240. if (module_exists('entity')) {
  241. // Reload the node again because we have created new revisions above.
  242. $node = node_load($node->nid, FALSE, TRUE);
  243. // Test entity_uuid_save() for nodes.
  244. $nodes = entity_uuid_load('node', array($node->uuid), array(), TRUE);
  245. $node_test = reset($nodes);
  246. $node_test->nid = rand();
  247. $node_test->vid = rand();
  248. $node_test->title = 'new title';
  249. $node_test->revision = FALSE;
  250. entity_uuid_save('node', $node_test);
  251. $node_test = node_load($node->nid, FALSE, TRUE);
  252. $this->assertEqual($node_test->title, 'new title', 'Saving node with UUID mapped to correct node, when not creating new revision.');
  253. $this->assertEqual($node_test->uuid, $node->uuid, 'Node UUID was intact after saving with UUID, when not creating new revision.');
  254. $this->assertEqual($node_test->vuuid, $node->vuuid, 'Node revison UUID was intact after saving with UUID, when not creating new revision.');
  255. $this->assertEqual($node_test->uid, $node->uid, "Node property 'uid' was intact after saving with UUID, when not creating new revision.");
  256. // Test the same thing again, but now triggering a new revision.
  257. $nodes = entity_uuid_load('node', array($node->uuid), array(), TRUE);
  258. $node_test = reset($nodes);
  259. $node_test->nid = rand();
  260. $node_test->vid = rand();
  261. $node_test->title = 'newer title';
  262. $node_test->revision = TRUE;
  263. entity_uuid_save('node', $node_test);
  264. $node_test = node_load($node->nid, FALSE, TRUE);
  265. $this->assertEqual($node_test->title, 'newer title', 'Saving node with UUID mapped to correct node, when creating new revision.');
  266. $this->assertEqual($node_test->uuid, $node->uuid, 'Node UUID was intact after saving with UUID, when creating new revision.');
  267. $this->assertNotEqual($node_test->vuuid, $node->vuuid, 'A new node revison UUID was generated after saving with UUID, when creating new revision.');
  268. $this->assertUUID($node_test->vuuid, 'New node revision UUID was valid.');
  269. $this->assertEqual($node_test->uid, $node->uid, "Node property 'uid' was intact after saving with UUID, when creating new revision.");
  270. // Test the same thing again, but now triggering a new revision from a
  271. // remote environment.
  272. // TODO: Move this test to the uuid_services module.
  273. $nodes = entity_uuid_load('node', array($node->uuid), array(), TRUE);
  274. $node_test = reset($nodes);
  275. // Store the current local revision ID to test with later.
  276. $vid_old1 = $node_test->vid;
  277. $vuuid_old1 = $node_test->vuuid;
  278. // Simulate this node coming from a remote environment by generating
  279. // IDs that won't match. Only the UUID match at this point.
  280. $node_test->uuid_services = TRUE;
  281. $nid_remote = rand();
  282. $vid_remote = rand();
  283. $vuuid_test = uuid_generate();
  284. $node_test->nid = $nid_test;
  285. $node_test->vid = $vid_test;
  286. $node_test->vuuid = $vuuid_test;
  287. $node_test->revision = TRUE;
  288. entity_uuid_save('node', $node_test);
  289. $node_test = node_load($node->nid, FALSE, TRUE);
  290. $this->assertNotEqual($node_test->vid, $vid_old1, 'A new revision was created, when trying to create new revision with new revision UUID from remote site');
  291. $this->assertEqual($node_test->vuuid, $vuuid_test, 'The revison UUID was preserved after saving with UUID, when trying to create new revision with new revision UUID from remote site.');
  292. // Test the same thing again from a remote environment, but now with the
  293. // same vuuid as once previosuly. This should not trigger a new revision.
  294. // This covers the case of "dupe deployments" where a client might push a
  295. // node several times.
  296. // TODO: Move this test to the uuid_services module.
  297. $nodes = entity_uuid_load('node', array($node->uuid), array(), TRUE);
  298. $node_test = reset($nodes);
  299. // Store the current local revision ID to test with later.
  300. $vid_old2 = $node_test->vid;
  301. // Simulate this node coming from a remote environment by generating
  302. // IDs that won't match.
  303. $node_test->uuid_services = TRUE;
  304. $node_test->nid = $nid_test;
  305. $node_test->vid = $vid_test;
  306. $node_test->vuuid = $vuuid_test;
  307. $node_test->revision = TRUE;
  308. entity_uuid_save('node', $node_test);
  309. $node_test = node_load($node->nid, FALSE, TRUE);
  310. $this->assertEqual($node_test->vid, $vid_old2, 'A new revision was not created, when trying to create new revision with existing revision UUID from remote site.');
  311. $this->assertEqual($node_test->vuuid, $vuuid_test, 'The revison UUID was preserved after saving with UUID, when trying to create new revision with existing revision UUID from remote site.');
  312. // Test the same this again, but now with an old revision.
  313. $nodes = entity_uuid_load('node', array($uuid_old), array('vuuid' => $vuuid_old), TRUE);
  314. $node_test = reset($nodes);
  315. // Simulate this node coming from a remote environment by generating
  316. // IDs that won't match.
  317. $node_test->uuid_services = TRUE;
  318. $node_test->nid = rand();
  319. $node_test->vid = rand();
  320. $node_test->revision = TRUE;
  321. $node_test->title = 'newest title';
  322. entity_uuid_save('node', $node_test);
  323. $node_test = node_load($node->nid, $vid_old, TRUE);
  324. $this->assertEqual($node_test->title, 'newest title', 'The revision was updated, when updating old revision with existing revision UUID from remote site.');
  325. $this->assertEqual($node_test->vuuid, $vuuid_old, 'The revison UUID was preserved after saving with UUID, when updating old revision with existing revision UUID from remote site.');
  326. // Setting the node options variable should also trigger a new revision.
  327. $nodes = entity_uuid_load('node', array($node->uuid), array(), TRUE);
  328. $node_test = reset($nodes);
  329. variable_set('node_options_' . $node_test->type, array('revision'));
  330. entity_uuid_save('node', $node_test);
  331. $this->assertNotEqual($node_test->vuuid, $node->vuuid, 'A new node revison ID was generated after saving with UUID, when relying on the node options variable.');
  332. // Test entity_uuid_delete() for nodes.
  333. entity_uuid_delete('node', $node->uuid);
  334. $node_test = node_load($node->nid);
  335. $this->assertFalse($node_test, 'Deleting node with UUID worked.');
  336. }
  337. }
  338. }
  339. /**
  340. * Tests the Comment implementation.
  341. *
  342. * @todo
  343. * Contribute patch to CommentHelperCase::setUp() to make it extendable.
  344. */
  345. class UUIDCommentTestCase extends CommentHelperCase {
  346. /**
  347. * {@inheritdoc}
  348. */
  349. public static function getInfo() {
  350. return array(
  351. 'name' => 'Comment implementation',
  352. 'description' => 'Tests the Comment implementation.',
  353. 'group' => 'UUID',
  354. );
  355. }
  356. /**
  357. * Helper function that asserts a UUID.
  358. *
  359. * We have duplicated this function from UUIDTestCase since we have to extend
  360. * CommentHelperCase instead.
  361. */
  362. function assertUUID($uuid, $message = NULL) {
  363. $this->assertTrue(uuid_is_valid($uuid), $message);
  364. }
  365. /**
  366. * Test CRUD on comments with UUID functions.
  367. */
  368. function testCommentCRUD() {
  369. // This is sub optimal, but due to how CommentHelperCase::setUp() is
  370. // constructed we are enforced to do this. So unfortunately this test
  371. // depends on 'entity' module for now.
  372. module_enable(array('uuid', 'entity'), TRUE);
  373. $user = $this->drupalCreateUser();
  374. $this->drupalLogin($user);
  375. $node = $this->drupalCreateNode();
  376. $return = $this->postComment($node, 'Lorem ipsum');
  377. $comment = comment_load($return->id);
  378. $this->assertUUID($comment->uuid, 'Comment UUID was generated.');
  379. // Test updating comment.
  380. $comment_test = clone $comment;
  381. $comment_test->subject = 'new subject';
  382. comment_save($comment_test);
  383. $comment_test = comment_load($comment->cid);
  384. $this->assertEqual($comment_test->uuid, $comment->uuid, 'Comment UUID was intact after update.');
  385. // Test entity_uuid_load().
  386. $comments = entity_uuid_load('comment', array($comment->uuid), array(), TRUE);
  387. $comment_test = reset($comments);
  388. $this->assertEqual($comment_test->cid, $return->id, 'Comment was correctly loaded with UUID.');
  389. $this->assertEqual($comment_test->uid, $user->uuid, "Comment property 'uid' was transformed to UUID when loaded with UUID.");
  390. $this->assertEqual($comment_test->nid, $node->uuid, "Comment property 'nid' was transformed to UUID when loaded with UUID.");
  391. // The following tests depends on the optional Entity API module.
  392. if (module_exists('entity')) {
  393. // Test entity_uuid_save() for comments.
  394. $comments = entity_uuid_load('comment', array($comment->uuid), array(), TRUE);
  395. $comment_test = reset($comments);
  396. $comment_test->cid = rand();
  397. $comment_test->subject = 'newer subject';
  398. entity_uuid_save('comment', $comment_test);
  399. $comment_test = comment_load($comment->cid);
  400. $this->assertEqual($comment_test->subject, 'newer subject', 'Saving comment with UUID mapped to correct comment.');
  401. $this->assertEqual($comment_test->uuid, $comment->uuid, 'Comment UUID was intact after saving with UUID.');
  402. $this->assertEqual($comment_test->uid, $user->uid, "Comment property 'uid' was after saving with UUID.");
  403. $this->assertEqual($comment_test->nid, $node->nid, "Comment property 'nid' was after saving with UUID.");
  404. // Test entity_uuid_delete() for comments.
  405. entity_uuid_delete('comment', $comment->uuid);
  406. $comment_test = comment_load($comment->cid);
  407. $this->assertFalse($comment_test, 'Deleting comment with UUID worked.');
  408. }
  409. }
  410. }
  411. /**
  412. * Tests the Taxonomy implementation.
  413. */
  414. class UUIDTaxonomyTestCase extends TaxonomyWebTestCase {
  415. /**
  416. * {@inheritdoc}
  417. */
  418. public static function getInfo() {
  419. return array(
  420. 'name' => 'Taxonomy implementation',
  421. 'description' => 'Tests the Taxonomy implementation.',
  422. 'group' => 'UUID',
  423. );
  424. }
  425. /**
  426. * {@inheritdoc}
  427. *
  428. * A lot of code here is taken from TaxonomyTermTestCase::setUp().
  429. */
  430. function setUp() {
  431. // Some tests depends on the optional Entity API module.
  432. if (module_exists('entity')) {
  433. parent::setUp('taxonomy', 'uuid', 'entity');
  434. }
  435. else {
  436. parent::setUp('taxonomy', 'uuid');
  437. }
  438. }
  439. /**
  440. * Helper function that asserts a UUID.
  441. *
  442. * We have duplicated this function from UUIDTestCase since we have to extend
  443. * TaxonomyWebTestCase instead.
  444. */
  445. function assertUUID($uuid, $message = NULL) {
  446. $this->assertTrue(uuid_is_valid($uuid), $message);
  447. }
  448. /**
  449. * Test CRUD on comments with UUID functions.
  450. */
  451. function testTaxonomyCRUD() {
  452. $user = $this->drupalCreateUser(array('administer taxonomy', 'administer nodes', 'bypass node access'));
  453. $this->drupalLogin($user);
  454. // Create a term by tagging a node. We'll use this node later too.
  455. $vocabulary = new stdClass;
  456. $vocabulary->vid = 1;
  457. $term = $this->createTerm($vocabulary);
  458. $this->assertUUID($term->uuid, 'Term UUID was generated.');
  459. // Test updating term.
  460. $term_test = clone $term;
  461. $term_test->name = 'new name';
  462. taxonomy_term_save($term_test);
  463. $term_test = taxonomy_term_load($term->tid);
  464. $this->assertEqual($term_test->uuid, $term->uuid, 'Term UUID was intact after update.');
  465. // Test entity_uuid_load().
  466. $terms = entity_uuid_load('taxonomy_term', array($term->uuid), array(), TRUE);
  467. $term_test = reset($terms);
  468. $this->assertEqual($term_test->tid, $term->tid, 'Term was correctly loaded with UUID.');
  469. // The following tests depends on the Entity API module.
  470. if (module_exists('entity')) {
  471. // Test entity_uuid_save() for terms.
  472. $terms = entity_uuid_load('taxonomy_term', array($term->uuid), array(), TRUE);
  473. $term_test = reset($terms);
  474. $term_test->tid = rand();
  475. $term_test->name = 'newer name';
  476. entity_uuid_save('taxonomy_term', $term_test);
  477. $term_test = taxonomy_term_load($term->tid);
  478. $this->assertEqual($term_test->name, 'newer name', 'Saving term with UUID mapped to correct term.');
  479. $this->assertEqual($term_test->uuid, $term->uuid, 'Term UUID was intact after saving with UUID.');
  480. // Test entity_uuid_delete() for nodes.
  481. entity_uuid_delete('taxonomy_term', $term->uuid);
  482. $term_test = taxonomy_term_load($term->tid);
  483. $this->assertFalse($term_test, 'Deleting term with UUID worked.');
  484. }
  485. }
  486. }
  487. /**
  488. * Tests for the UUID synchronization.
  489. */
  490. class UUIDSyncTestCase extends UUIDTestCase {
  491. /**
  492. * {@inheritdoc}
  493. */
  494. public static function getInfo() {
  495. return array(
  496. 'name' => 'UUID sync',
  497. 'description' => 'Tests the UUID synchronization.',
  498. 'group' => 'UUID',
  499. );
  500. }
  501. /**
  502. * Helper function that asserts that a database table column exists.
  503. *
  504. * @todo
  505. * There are something weird around this assertion.
  506. */
  507. function assertTableColumn($table, $column, $message) {
  508. $this->assertTrue(db_field_exists($table, $column), $message);
  509. }
  510. /**
  511. * Tests creating UUIDs for entities that don't have them.
  512. */
  513. function testSync() {
  514. // These entities will not have UUID from the start, since the UUID module
  515. // isn't installed yet.
  516. $user = $this->drupalCreateUser();
  517. $node = $this->drupalCreateNode();
  518. $this->assertTrue(!isset($node->uuid), "Node has no UUID before installation of UUID module.");
  519. $this->assertTrue(!isset($node->vuuid), "Node has no revision UUID before installation of UUID module.");
  520. $this->assertTrue(!isset($user->uuid), "User has no UUID before installation of UUID module.");
  521. // Now enable the UUID module.
  522. module_enable(array('uuid'), TRUE);
  523. drupal_flush_all_caches();
  524. drupal_static_reset();
  525. // Check that the UUID column was generated for {node}.
  526. $this->assertTableColumn('node', 'uuid', 'UUID column was generated for the node table.');
  527. $this->assertTableColumn('node_revision', 'vuuid', 'Revision UUID column was generated for the node_revision table.');
  528. $this->assertTableColumn('users', 'uuid', 'UUID column was generated for the user table.');
  529. // Login with a user and click the sync button.
  530. $web_user = $this->drupalCreateUser(array('administer uuid'));
  531. $this->drupalLogin($web_user);
  532. $this->drupalPost('admin/config/system/uuid', array(), t('Create missing UUIDs'));
  533. // Test if UUID was generated for nodes.
  534. $node_test = node_load($node->nid, FALSE, TRUE);
  535. $this->assertUUID($node_test->uuid, 'Node UUID was generated when clicking the sync button.');
  536. $this->assertUUID($node_test->vuuid, 'Node revision UUID was generated when clicking the sync button.');
  537. // Test if UUID was generated for users.
  538. $user_test = user_load($user->uid, TRUE);
  539. $this->assertUUID($user_test->uuid, 'User UUID was generated when clicking the sync button.');
  540. }
  541. }