public function HandlerTest::testRelationshipUI

Tests the relationship ui for field/filter/argument/relationship.

File

drupal/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerTest.php, line 241
Definition of Drupal\views\Tests\Handler\HandlerTest.

Class

HandlerTest
Tests abstract handlers of views.

Namespace

Drupal\views\Tests\Handler

Code

public function testRelationshipUI() {
  $views_admin = $this
    ->drupalCreateUser(array(
    'administer views',
  ));
  $this
    ->drupalLogin($views_admin);

  // Make sure the link to the field options exists.
  $handler_options_path = 'admin/structure/views/nojs/config-item/test_handler_relationships/default/field/title';
  $view_edit_path = 'admin/structure/views/view/test_handler_relationships/edit';
  $this
    ->drupalGet($view_edit_path);
  $this
    ->assertLinkByHref($handler_options_path);

  // The test view has a relationship to node_revision so the field should
  // show a relationship selection.
  $this
    ->drupalGet($handler_options_path);
  $relationship_name = 'options[relationship]';
  $this
    ->assertFieldByName($relationship_name);

  // Check for available options.
  $xpath = $this
    ->constructFieldXpath('name', $relationship_name);
  $fields = $this
    ->xpath($xpath);
  $options = array();
  foreach ($fields as $field) {
    $items = $this
      ->getAllOptions($field);
    foreach ($items as $item) {
      $options[] = $item
        ->attributes()->value;
    }
  }
  $expected_options = array(
    'none',
    'nid',
  );
  $this
    ->assertEqual($options, $expected_options);

  // Remove the relationship and take sure no relationship option appears.
  $this
    ->drupalPost('admin/structure/views/nojs/config-item/test_handler_relationships/default/relationship/nid', array(), t('Remove'));
  $this
    ->drupalGet($handler_options_path);
  $this
    ->assertNoFieldByName($relationship_name, 'Make sure that no relationship option is available');
}