You are here

public function RelationViewsTest::testForwardDirectionalDifferentEntityRelations in Relation 8

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

Tests views with forward directional relations.

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

File

src/Tests/RelationViewsTest.php, line 372

Class

RelationViewsTest
Relation Views test

Namespace

Drupal\relation\Tests

Code

public function testForwardDirectionalDifferentEntityRelations() {

  /*
  for ($r_index = -1; $r_index < 2; $r_index++) {
    $view = new view();
    $view->base_table = 'users';
    $handler = $view->new_display('default');
    $handler->display->display_options['relationships']['relation_directional_entitydifferent_node']['id'] = 'relation_directional_entitydifferent_node';
    $handler->display->display_options['relationships']['relation_directional_entitydifferent_node']['table'] = 'users';
    $handler->display->display_options['relationships']['relation_directional_entitydifferent_node']['field'] = 'relation_directional_entitydifferent_node';
    $handler->display->display_options['relationships']['relation_directional_entitydifferent_node']['required'] = 1;
    $handler->display->display_options['relationships']['relation_directional_entitydifferent_node']['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';
    $handler->display->display_options['fields']['nid']['relationship'] = 'relation_directional_entitydifferent_node';
    $handler->display->display_options['arguments']['uid']['id'] = 'uid';
    $handler->display->display_options['arguments']['uid']['table'] = 'users';
    $handler->display->display_options['arguments']['uid']['field'] = 'uid';
    $view->set_arguments(array($this->user1->uid));
    $view->execute();

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

      case 0:
        // Source. 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->node_users_nid]);
        }
        $this->assertFalse($matches);
        break;

      case 1:
        // Target. This finds no relations.
        $this->assertEqual(count($view->result), 0);
        $matches = array();
        foreach ($view->result as $result) {
          unset($matches[$result->node_users_nid]);
        }
        $this->assertFalse($matches);
        break;
    }
  }
  */
}