function RelationAPITestCase::testRelationTypes in Relation 7
Tests relation types.
File
- tests/
relation.test, line 346 - Tests for Relation module.
Class
- RelationAPITestCase
- Tests Relation API.
Code
function testRelationTypes() {
// Symmetric.
$related = relation_get_related_entity('node', $this->node1->nid);
$this
->assertEqual($this->node4->nid, $related->nid);
// Confirm this works once the related entity has been cached.
$related = relation_get_related_entity('node', $this->node1->nid);
$this
->assertEqual($this->node4->nid, $related->nid);
// Directional.
// From Parent to Grandparent.
$related = relation_get_related_entity('node', $this->node3->nid, $this->relation_types['directional']['relation_type'], 1);
$this
->assertEqual($this->node1->nid, $related->nid);
// From Parent to Child.
$related = relation_get_related_entity('node', $this->node3->nid, $this->relation_types['directional']['relation_type'], 0);
$this
->assertEqual($this->node4->nid, $related->nid);
// Delete all relations related to node 4, then confirm that these can
// no longer be found as related entities.
$relations = relation_query('node', $this->node4->nid)
->execute();
foreach ($relations as $relation) {
relation_delete($relation->rid);
}
$this
->assertFalse(relation_get_related_entity('node', $this->node4->nid), 'The entity was not loaded after the relation was deleted.');
}