You are here

function RelationViewsTestCase::testRelationsFromRelationBase in Relation 7

Tests views from Relation base to endpoint entities

File

tests/relation.views.test, line 436
Tests for Views support in the Relation module.

Class

RelationViewsTestCase
Functional test of Relation's integration with Views.

Code

function testRelationsFromRelationBase() {
  for ($r_index = -1; $r_index < 2; $r_index++) {
    $view = new view();
    $view->base_table = 'relation';
    $handler = $view
      ->new_display('default');
    $handler->display->display_options['relationships']['relation_base_directional_entitydifferent_user']['id'] = 'relation_base_directional_entitydifferent_user';
    $handler->display->display_options['relationships']['relation_base_directional_entitydifferent_user']['table'] = 'relation';
    $handler->display->display_options['relationships']['relation_base_directional_entitydifferent_user']['field'] = 'relation_base_directional_entitydifferent_user';
    $handler->display->display_options['relationships']['relation_base_directional_entitydifferent_user']['required'] = TRUE;
    $handler->display->display_options['relationships']['relation_base_directional_entitydifferent_user']['r_index'] = $r_index;
    $handler->display->display_options['fields']['rid']['id'] = 'rid';
    $handler->display->display_options['fields']['rid']['table'] = 'relation';
    $handler->display->display_options['fields']['rid']['field'] = 'rid';
    $handler->display->display_options['fields']['uid']['id'] = 'uid';
    $handler->display->display_options['fields']['uid']['table'] = 'users';
    $handler->display->display_options['fields']['uid']['field'] = 'uid';
    $handler->display->display_options['fields']['uid']['relationship'] = 'relation_base_directional_entitydifferent_user';
    $handler->display->display_options['arguments']['uid']['id'] = 'uid';
    $handler->display->display_options['arguments']['uid']['table'] = 'users';
    $handler->display->display_options['arguments']['uid']['field'] = 'uid';
    $handler->display->display_options['arguments']['uid']['relationship'] = 'relation_base_directional_entitydifferent_user';
    $view
      ->set_arguments(array(
      $this->user1->uid,
    ));
    $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->user1->uid => TRUE,
        );
        foreach ($view->result as $result) {
          unset($matches[$result->users_relation_uid]);
        }
        $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->user1->uid => TRUE,
        );
        foreach ($view->result as $result) {
          unset($matches[$result->users_relation_uid]);
        }
        $this
          ->assertFalse($matches);
        break;
      case 1:

        // Target. This finds no relations.
        $this
          ->assertEqual(count($view->result), 0);
        break;
    }
  }
}