You are here

function LocationCCKTest::testNodeRevisionCOW in Location 6.3

Same name and namespace in other branches
  1. 7.5 tests/location_cck.test \LocationCCKTest::testNodeRevisionCOW()
  2. 7.3 tests/location_cck.test \LocationCCKTest::testNodeRevisionCOW()
  3. 7.4 tests/location_cck.test \LocationCCKTest::testNodeRevisionCOW()

File

tests/location_cck.test, line 274

Class

LocationCCKTest

Code

function testNodeRevisionCOW() {
  $settings = array();
  $location_type = $this
    ->addLocationContentType($settings, array(
    'cck_multiple' => 10,
  ));
  $location1_name = $this
    ->randomName();
  $location2_name = $this
    ->randomName();
  $location3_name = $this
    ->randomName();
  $node = $this
    ->drupalCreateNode(array(
    'type' => $location_type,
    'field_loctest' => array(
      0 => array(
        // First
        'name' => $location1_name,
      ),
      1 => array(
        // Second
        'name' => $location2_name,
      ),
    ),
  ));

  // Reload the node.
  $node = node_load($node->nid, NULL, TRUE);
  $changes = array(
    'revision' => TRUE,
    'log' => $this
      ->randomName(20),
    'field_loctest' => array(
      0 => array(
        // Delete First
        'delete_location' => TRUE,
      ),
      2 => array(
        // Third
        'name' => $location3_name,
      ),
    ),
  );
  $this
    ->flattenPostData($changes);
  $this
    ->drupalPost('node/' . $node->nid . '/edit', $changes, 'Save');

  // Reload the node again.
  $node1 = node_load($node->nid, $node->vid, TRUE);
  $node2 = node_load($node->nid, NULL, TRUE);

  // Ensure locations are in a consistent order.
  $this
    ->reorderLocations($node, 'field_loctest');
  $this
    ->reorderLocations($node1, 'field_loctest');
  $this
    ->reorderLocations($node2, 'field_loctest');
  $this
    ->assertEqual(count($node1->field_loctest), 2, t('Ensuring second revision did not affect first revision'));
  $this
    ->pass(count($node1->field_loctest));
  $this
    ->assertEqual($node->field_loctest[0]['lid'], $node1->field_loctest[0]['lid'], t('Ensuring second revision did not affect first revision'));
  $this
    ->assertEqual($node->field_loctest[1]['lid'], $node1->field_loctest[1]['lid'], t('Ensuring second revision did not affect first revision'));
  $this
    ->assertEqual(count($node2->field_loctest), 2, t('Ensuring second revision does not have stealth locations'));

  // Delete first revision.
  db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $node1->nid, $node1->vid);
  node_invoke_nodeapi($node1, 'delete revision');
  $result = db_query('SELECT * FROM {location} WHERE lid = %d', $node1->field_loctest[0]['lid']);
  if ($row = db_fetch_object($result)) {
    $this
      ->fail(t('Ensuring location on deleted revision is garbage collected'));
  }
  else {
    $this
      ->pass(t('Ensuring location on deleted revision is garbage collected'));
  }
  $result = db_query('SELECT * FROM {location} WHERE lid = %d', $node1->field_loctest[1]['lid']);
  if ($row = db_fetch_object($result)) {
    $this
      ->pass(t('Ensuring shared location on deleted revision is NOT garbage collected'));
  }
  else {
    $this
      ->fail(t('Ensuring shared location on deleted revision is NOT garbage collected'));
  }
}