Created
December 12, 2012 08:26
-
-
Save RoySegall/4266083 to your computer and use it in GitHub Desktop.
Allow deleting group-content when group is deleted
http://drupal.org/node/1862702
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Testing for deleting group-content when group is deleted. | |
*/ | |
class OgDeleteGroupContentTestCase extends DrupalWebTestCase { | |
public $groupType; | |
public $nodeType; | |
public static function getInfo() { | |
return array( | |
'name' => 'OG delete content', | |
'description' => 'When deleting a grop, we need to check if the group content is deleted.', | |
'group' => 'Organic groups', | |
); | |
} | |
function setUp() { | |
parent::setUp('og_test', 'advancedqueue'); | |
// Create a group content type. | |
$group = $this->drupalCreateContentType(); | |
og_create_field(OG_GROUP_FIELD, 'node', $group->type); | |
$this->groupType = $group->type; | |
// Create group audience content type. | |
$type = $this->drupalCreateContentType(); | |
$this->nodeType = $type->type; | |
// Add OG audience field to the audience content type. | |
$og_field = og_fields_info(OG_AUDIENCE_FIELD); | |
$og_field['field']['settings']['target_type'] = 'node'; | |
og_create_field(OG_AUDIENCE_FIELD, 'node', $type->type, $og_field); | |
// Set the setting for delete a group content when deleting group. | |
variable_set('og_orphans_delete', TRUE); | |
variable_set('og_use_queue', TRUE); | |
} | |
function testDeleteGroup() { | |
// Creating a group. | |
$group = (object) array( | |
'type' => $this->groupType, | |
'title' => $this->randomName(), | |
); | |
$GroupWrapper = entity_metadata_wrapper('node', $group); | |
$GroupWrapper->save(); | |
// Create the group content. | |
$node = (object) array( | |
'type' => $this->nodeType, | |
'title' => $this->randomName(), | |
); | |
$wrapper = entity_metadata_wrapper('node', $node); | |
$wrapper->{OG_AUDIENCE_FIELD}->set(array($GroupWrapper->getIdentifier())); | |
$wrapper->save(); | |
// Delete the group. | |
$GroupWrapper->delete(); | |
// Active the queue. | |
$queue = DrupalQueue::get('og_membership_orphans'); | |
$item = $queue->claimItem(); | |
og_membership_orphans_worker($item); | |
// Verify the orphan node deleted. | |
$this->assert(!node_load($wrapper->getIdentifier()), t("The orphan node deleted")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment