You are here

function OgDeleteOrphansTestCase::testMoveOrphans in Organic groups 7.2

Testing the moving of the node to another group when deleting a group.

File

./og.test, line 2063

Class

OgDeleteOrphansTestCase
Testing for deleting orphans group content.

Code

function testMoveOrphans() {

  // Creating two groups.
  $first_group = $this
    ->drupalCreateNode(array(
    'type' => $this->group_type,
    'title' => 'move',
  ));
  $second_group = $this
    ->drupalCreateNode(array(
    'type' => $this->group_type,
  ));

  // Create a group and relate it to the first group.
  $first_node = $this
    ->drupalCreateNode(array(
    'type' => $this->node_type,
  ));
  og_group('node', $first_group, array(
    'entity_type' => 'node',
    'entity' => $first_node,
  ));

  // Delete the group.
  node_delete($first_group->nid);

  // Execute manually the queue worker.
  $queue = DrupalQueue::get('og_membership_orphans');
  $item = $queue
    ->claimItem();
  og_membership_orphans_worker($item->data);

  // Load the node into a wrapper and verify we moved him to another group.
  $gids = og_get_entity_groups('node', $first_node->nid);
  $gid = reset($gids['node']);
  $this
    ->assertEqual($gid, $second_group->nid, 'The group content moved to another group.');
}