public function OgVocabUnbindFromContentType::testUnbindContentType in OG Vocabulary 7
When a vocabulary is related to a bundle and it's term are reference to the group content, un-bind it from the bundle the terms should not be reference any more to the node.
File
- ./
og_vocab.test, line 537 - Test organic groups vocabulary module.
Class
Code
public function testUnbindContentType() {
$groups_contents = array(
$this->first_group_content,
$this->second_group_content,
);
// Create a dummy vocabulary.
$vocabulary = new stdClass();
$vocabulary->name = "Vocabulary " . $this->group->nid;
$vocabulary->machine_name = "vocabulary_" . $this->group->nid;
taxonomy_vocabulary_save($vocabulary);
// Relate vocabulary to group.
og_vocab_relation_save($vocabulary->vid, 'node', $this->group->nid);
// Create the vocabulary.
foreach ($groups_contents as $groups_content) {
// Create OG vocabulary entity.
$og_vocab = og_vocab_create_og_vocab($vocabulary->vid, 'node', $groups_content->type);
$og_vocab
->save();
// Create terms in the vocabulary.
$terms = array();
for ($i = 1; $i < 3; ++$i) {
$term = new stdClass();
$term->name = "Vocab {$vocabulary->vid} term {$i}";
$term->vid = $vocabulary->vid;
taxonomy_term_save($term);
$terms[] = $term->tid;
}
// Reference between the taxonomy terms and the nodes.
$wrapper = entity_metadata_wrapper('node', $groups_content);
$wrapper->{OG_VOCAB_FIELD}
->set($terms);
$wrapper
->save();
}
// Verify the terms are attached to the nodes.
foreach ($groups_contents as $groups_content) {
$node = node_load($groups_content->nid);
$this
->assertTrue(!empty($node->{OG_VOCAB_FIELD}), format_string('Terms are attached to the node @title.', array(
'@title' => $groups_content->title,
)));
}
// Delete the last vocabulary.
$og_vocab
->delete();
// Execute manually the queue worker.
$queue = DrupalQueue::get('og_vocab');
$item = $queue
->claimItem();
og_vocab_remove_referenced_items_queue_worker($item->data);
// Verify the terms are attached to the nodes.
$node = node_load($this->first_group_content->nid);
$this
->assertTrue(!empty($node->{OG_VOCAB_FIELD}), format_string('Terms are attached to the node @title.', array(
'@title' => $this->first_group_content->title,
)));
$node = node_load($this->second_group_content->nid);
$this
->assertTrue(empty($node->{OG_VOCAB_FIELD}), format_string('There are no terms attached to the node @title.', array(
'@title' => $this->second_group_content->title,
)));
}