function RelationViewsTestCase::testRelationsToRelationBase in Relation 7
Tests views from endpoints to Relation base
File
- tests/
relation.views.test, line 490 - Tests for Views support in the Relation module.
Class
- RelationViewsTestCase
- Functional test of Relation's integration with Views.
Code
function testRelationsToRelationBase() {
for ($r_index = -1; $r_index < 2; $r_index++) {
$view = new view();
$view->base_table = 'node';
$handler = $view
->new_display('default');
$handler->display->display_options['relationships']['relation_base_right_directional_entitydifferent']['id'] = 'relation_base_right_directional_entitydifferent';
$handler->display->display_options['relationships']['relation_base_right_directional_entitydifferent']['table'] = 'node';
$handler->display->display_options['relationships']['relation_base_right_directional_entitydifferent']['field'] = 'relation_base_right_directional_entitydifferent';
$handler->display->display_options['relationships']['relation_base_right_directional_entitydifferent']['required'] = TRUE;
$handler->display->display_options['relationships']['relation_base_right_directional_entitydifferent']['r_index'] = $r_index;
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'node';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
$view
->execute();
switch ($r_index) {
case -1:
// Both ways, should find u1->p3 and u1->p4 relations
$this
->assertEqual(count($view->result), 2);
$matches = array(
$this->node3->nid => TRUE,
$this->node4->nid => TRUE,
);
foreach ($view->result as $result) {
unset($matches[$result->nid]);
}
$this
->assertFalse($matches);
break;
case 0:
// Source. This finds no relations.
$this
->assertEqual(count($view->result), 0);
break;
case 1:
// Target. This finds the u1->p3 and u1->p4 relation.
$this
->assertEqual(count($view->result), 2);
$matches = array(
$this->node3->nid => TRUE,
$this->node4->nid => TRUE,
);
foreach ($view->result as $result) {
unset($matches[$result->nid]);
}
$this
->assertFalse($matches);
break;
}
}
}