You are here

public function RelationViewsTest::testForwardDirectionalSameEntityRelations in Relation 8.2

Same name and namespace in other branches
  1. 8 src/Tests/RelationViewsTest.php \Drupal\relation\Tests\RelationViewsTest::testForwardDirectionalSameEntityRelations()

Tests views with forward directional relations.

Tests views to source, to target and to both with the same entities types.

File

src/Tests/RelationViewsTest.php, line 242

Class

RelationViewsTest
Relation Views test

Namespace

Drupal\relation\Tests

Code

public function testForwardDirectionalSameEntityRelations() {

  /*
  for ($delta = -1; $delta < 2; $delta++) {
    $view = new view();
    $view->base_table = 'node';
    $handler = $view->new_display('default');
    $handler->display->display_options['relationships']['relation_directional_entitysame_node']['id'] = 'relation_directional_entitysame_node';
    $handler->display->display_options['relationships']['relation_directional_entitysame_node']['table'] = 'node';
    $handler->display->display_options['relationships']['relation_directional_entitysame_node']['field'] = 'relation_directional_entitysame_node';
    $handler->display->display_options['relationships']['relation_directional_entitysame_node']['required'] = 1;
    $handler->display->display_options['relationships']['relation_directional_entitysame_node']['delta'] = $delta;
    $handler->display->display_options['fields']['nid']['id'] = 'nid';
    $handler->display->display_options['fields']['nid']['table'] = 'node';
    $handler->display->display_options['fields']['nid']['field'] = 'nid';
    $handler->display->display_options['fields']['nid']['relationship'] = 'relation_directional_entitysame_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';
    $view->set_arguments(array($this->node3->nid));
    $view->execute();

    switch ($delta) {
      case -1:
        // Directional, both ways.
        $this->assertEqual(count($view->result), 3);
        $matches = array(
          $this->node4->nid => TRUE,
          $this->node4->nid => TRUE,
          $this->node5->nid => TRUE,
        );
        foreach ($view->result as $result) {
          unset($matches[$result->node_node_nid]);
        }
        $this->assertFalse($matches);
        break;

      case 0:
        // Source. This finds the p3->p4 and p3->p5 relations.
        $this->assertEqual(count($view->result), 2);
        $matches = array($this->node4->nid => TRUE, $this->node5->nid => TRUE);
        foreach ($view->result as $result) {
          unset($matches[$result->node_node_nid]);
        }
        $this->assertFalse($matches);
        break;

      case 1:
        // Target. This finds the p4->p3 relation.
        $this->assertEqual(count($view->result), 1);
        $matches = array($this->node4->nid => TRUE);
        foreach ($view->result as $result) {
          unset($matches[$result->node_node_nid]);
        }
        $this->assertFalse($matches);
        break;
    }
  }
  */
}