function RelationAPITestCase::testRelationSave in Relation 7
Tests saving of relations.
File
- tests/
relation.test, line 375 - Tests for Relation module.
Class
- RelationAPITestCase
- Tests Relation API.
Code
function testRelationSave() {
foreach ($this->relation_types as $value) {
$relation_type = $value['relation_type'];
$endpoints = $this->endpoints;
if (isset($value['min_arity'])) {
$endpoints = $value['min_arity'] == 1 ? $this->endpoints_unary : $this->endpoints_4;
}
if ($relation_type == 'directional_entitydifferent') {
$endpoints = $this->endpoints_entitydifferent;
}
$relation = relation_create($relation_type, $endpoints);
$rid = relation_save($relation);
$this
->assertTrue($rid, 'Relation created.');
$count = count($relation->endpoints[LANGUAGE_NONE]);
$this
->assertEqual($count, count($endpoints));
$this
->assertEqual($relation->arity, count($endpoints));
$this
->assertEqual($relation->relation_type, $relation_type);
foreach ($relation->endpoints[LANGUAGE_NONE] as $endpoint) {
$need_ids[$endpoint['entity_id']] = TRUE;
}
foreach ($relation->endpoints[LANGUAGE_NONE] as $delta => $endpoint) {
$this
->assertEqual($endpoint['entity_type'], $endpoints[$delta]['entity_type'], 'The entity type is ' . $endpoints[$delta]['entity_type'] . ': ' . $endpoint['entity_type']);
$this
->assertTrue(isset($need_ids[$endpoint['entity_id']]), 'The entity ID is correct: ' . $need_ids[$endpoint['entity_id']]);
unset($need_ids[$endpoint['entity_id']]);
}
$this
->assertFalse($need_ids, 'All ids found.');
// Confirm the rid in revision table.
$revision = db_select('relation_revision', 'v')
->fields('v', array(
'rid',
))
->condition('vid', $relation->vid)
->execute()
->fetchAllAssoc('rid');
$this
->assertTrue(array_key_exists($rid, $revision), 'Relation revision created.');
// Confirm ability to save relation multiple times in code without reload.
$rid = $relation->rid;
$vid = $relation->vid;
relation_save($relation);
$this
->assertEqual($relation->rid, $rid, 'Each revision has the same rid.');
$this
->assertNotIdentical($relation->vid, $vid, 'Each revision has a different vid.');
}
}