function EntityDependencyTestCase::testDanglingTermReferenceIterator in Entity Dependency API 7
Test worse scenario with nodes, taxonomy and dangling reference to taxonomy term.
File
- ./
entity_dependency.test, line 245 - Entity Dependency tests.
Class
- EntityDependencyTestCase
- Tests the entity dependency iterator.
Code
function testDanglingTermReferenceIterator() {
// Add the 'field_tags' field.
$user = $this
->drupalCreateUser();
$term1 = $this
->createTerm();
taxonomy_term_save($term1);
$node1 = $this
->drupalCreateNode(array(
'type' => 'article',
'uid' => $user->uid,
'field_tags' => array(
LANGUAGE_NONE => array(
array(
'tid' => $term1->tid,
),
),
),
));
// Now delete the term (does not cascade to the reference in field tags).
taxonomy_term_delete($term1->tid);
// Add only the last node to the collection. What should come out of the
// iterator should be all it's dependencies, and last the node it self.
$this->entities = array(
array(
'id' => $node1->nid,
'type' => 'node',
),
);
$i = 0;
foreach ($this
->getIterator() as $entity) {
switch ($i) {
case 0:
$this
->assertCorrectEntityOrder($entity, 'user', 'uid', $user->uid);
break;
case 1:
$this
->assertCorrectEntityOrder($entity, 'node', 'nid', $node1->nid);
break;
}
$i++;
}
$this
->assertEqual($i, 2, 'Correct number of entities was iterated over.');
}