You are here

RelationshipJoinTestBase.php in Zircon Profile 8.0

Same filename and directory in other branches
  1. 8 core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php

File

core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php
View source
<?php

/**
 * @file
 * Contains \Drupal\views\Tests\Plugin\RelationshipJoinTestBase.
 */
namespace Drupal\views\Tests\Plugin;

use Drupal\views\Views;

/**
 * Provides a base class for a testing a relationship.
 *
 * @see \Drupal\views\Tests\Handler\JoinTest
 * @see \Drupal\views\Tests\Plugin\RelationshipTest
 */
abstract class RelationshipJoinTestBase extends PluginKernelTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array(
    'system',
    'user',
    'field',
  );

  /**
   * @var \Drupal\user\Entity\User
   */
  protected $rootUser;

  /**
   * {@inheritdoc}
   */
  protected function setUpFixtures() {
    $this
      ->installEntitySchema('user');
    $this
      ->installConfig(array(
      'user',
    ));
    parent::setUpFixtures();

    // Create a record for uid 1.
    $this->rootUser = entity_create('user', array(
      'name' => $this
        ->randomMachineName(),
    ));
    $this->rootUser
      ->save();
    Views::viewsData()
      ->clear();
  }

  /**
   * Overrides \Drupal\views\Tests\ViewTestBase::schemaDefinition().
   *
   * Adds a uid column to test the relationships.
   */
  protected function schemaDefinition() {
    $schema = parent::schemaDefinition();
    $schema['views_test_data']['fields']['uid'] = array(
      'description' => "The {users_field_data}.uid of the author of the beatle entry.",
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    );
    return $schema;
  }

  /**
   * Overrides \Drupal\views\Tests\ViewTestBase::viewsData().
   *
   * Adds a relationship for the uid column.
   */
  protected function viewsData() {
    $data = parent::viewsData();
    $data['views_test_data']['uid'] = array(
      'title' => t('UID'),
      'help' => t('The test data UID'),
      'relationship' => array(
        'id' => 'standard',
        'base' => 'users_field_data',
        'base field' => 'uid',
      ),
    );
    return $data;
  }

}

Classes

Namesort descending Description
RelationshipJoinTestBase Provides a base class for a testing a relationship.