public function RelationViewsTest::testDirectionalRelations in Relation 8.2
Same name and namespace in other branches
- 8 src/Tests/RelationViewsTest.php \Drupal\relation\Tests\RelationViewsTest::testDirectionalRelations()
Tests views with directional relations to source, to target and to both.
File
- src/
Tests/ RelationViewsTest.php, line 162
Class
- RelationViewsTest
- Relation Views test
Namespace
Drupal\relation\TestsCode
public function testDirectionalRelations() {
/*
foreach (array(FALSE, TRUE) as $required) {
for ($delta = -1; $delta < 2; $delta++) {
$view = new view();
$handler = $view->new_display('default');
$handler->display->display_options['relationships']['relation_directional_node']['id'] = 'relation_directional_node';
$handler->display->display_options['relationships']['relation_directional_node']['table'] = 'node';
$handler->display->display_options['relationships']['relation_directional_node']['field'] = 'relation_directional_node';
$handler->display->display_options['relationships']['relation_directional_node']['required'] = $required;
$handler->display->display_options['relationships']['relation_directional_node']['delta'] = $delta;
$handler->display->display_options['fields']['nid_source']['id'] = 'nid';
$handler->display->display_options['fields']['nid_source']['table'] = 'node';
$handler->display->display_options['fields']['nid_source']['field'] = 'nid';
$handler->display->display_options['fields']['nid_target']['id'] = 'nid';
$handler->display->display_options['fields']['nid_target']['table'] = 'node';
$handler->display->display_options['fields']['nid_target']['field'] = 'nid';
$handler->display->display_options['fields']['nid_target']['relationship'] = 'relation_directional_node';
$handler->display->display_options['arguments']['nid']['id'] = 'nid';
$handler->display->display_options['arguments']['nid']['table'] = 'node';
$handler->display->display_options['arguments']['nid']['field'] = 'nid';
// First test: node that has relations. The results should be the same
// for required and non-required relations.
$view->set_arguments(array($this->node3->nid));
$view->execute();
switch ($delta) {
case -1:
// Directional, both ways.
$this->assertEqual(count($view->result), 2);
$targetmatches = array($this->node1->nid => TRUE, $this->node4->nid => TRUE);
foreach ($view->result as $result) {
$this->assertEqual($result->nid, $this->node3->nid);
unset($targetmatches[$result->node_node_nid]);
}
$this->assertFalse($targetmatches);
break;
case 0:
// Source. This finds the 3->4 relation.
$this->assertEqual(count($view->result), 1);
$this->assertEqual($view->result[0]->nid, $this->node3->nid);
$this->assertEqual($view->result[0]->node_node_nid, $this->node4->nid);
break;
case 1:
// Target. This finds the 1->3 relation.
$this->assertEqual(count($view->result), 1);
$this->assertEqual($view->result[0]->nid, $this->node3->nid);
$this->assertEqual($view->result[0]->node_node_nid, $this->node1->nid);
break;
}
// Second test: node that has no relations. The results should be that
// no results are found for the required relation, and 6 / NULL
// for the optional relation.
$view = $view->clone_view();
$view->set_arguments(array($this->node6->nid));
$view->execute();
if ($required) {
$this->assertEqual(count($view->result), 0);
}
else {
$this->assertEqual(count($view->result), 1);
$result = array_pop($view->result);
$this->assertEqual($result->nid, $this->node6->nid);
$this->assertEqual($result->node_node_nid, NULL);
}
}
}
*/
}