You are here

function OgDeleteOrphansTestCase::testDeleteGroup in Organic groups 7.2

Testing two things: When deleting a group, the node of the group will be deleted. Associated node with the deleted group and another group won't be deleted.

File

./og.test, line 2029

Class

OgDeleteOrphansTestCase
Testing for deleting orphans group content.

Code

function testDeleteGroup() {

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

  // Create two nodes.
  $first_node = $this
    ->drupalCreateNode(array(
    'type' => $this->node_type,
  ));
  og_group('node', $first_group, array(
    'entity_type' => 'node',
    'entity' => $first_node,
  ));
  og_group('node', $second_group, array(
    'entity_type' => 'node',
    'entity' => $first_node,
  ));
  $second_node = $this
    ->drupalCreateNode(array(
    'type' => $this->node_type,
  ));
  og_group('node', $first_group, array(
    'entity_type' => 'node',
    'entity' => $second_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 nodes we used during the test.
  $first_node = node_load($first_node->nid);
  $second_node = node_load($second_node->nid);

  // Verify the none orphan node wasn't deleted.
  $this
    ->assertTrue($first_node, "The second node is realted to another group and deleted.");

  // Verify the orphan node deleted.
  $this
    ->assertFalse($second_node, "The orphan node deleted.");
}