From 252f0c8ed651843c0bbd083b735411bad2dceebd Mon Sep 17 00:00:00 2001
From: webchick <webchick@24967.no-reply.drupal.org>
Date: Mon, 21 Jan 2013 16:15:48 -0800
Subject: [PATCH] Issue #1893850 by dawehner, xjm: Cleanup relationship tests
 and don't use the node module.

---
 .../views/Tests/Handler/RelationshipTest.php  | 53 +-------------
 .../Drupal/views/Tests/Plugin/JoinTest.php    | 32 +++++----
 .../Tests/Plugin/RelationshipJoinTestBase.php | 70 +++++++++++++++++++
 .../Plugin/views/join/JoinTest.php            |  2 +-
 4 files changed, 93 insertions(+), 64 deletions(-)
 create mode 100644 core/modules/views/lib/Drupal/views/Tests/Plugin/RelationshipJoinTestBase.php

diff --git a/core/modules/views/lib/Drupal/views/Tests/Handler/RelationshipTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/RelationshipTest.php
index cbab5ea4c28c..63cb46b46cf9 100644
--- a/core/modules/views/lib/Drupal/views/Tests/Handler/RelationshipTest.php
+++ b/core/modules/views/lib/Drupal/views/Tests/Handler/RelationshipTest.php
@@ -8,13 +8,14 @@
 namespace Drupal\views\Tests\Handler;
 
 use Drupal\views\Tests\ViewUnitTestBase;
+use Drupal\views\Tests\Plugin\RelationshipJoinTestBase;
 
 /**
  * Tests the base relationship handler.
  *
  * @see Drupal\views\Plugin\views\relationship\RelationshipPluginBase
  */
-class RelationshipTest extends ViewUnitTestBase {
+class RelationshipTest extends RelationshipJoinTestBase {
 
   /**
    * Views used by this test.
@@ -41,56 +42,6 @@ public static function getInfo() {
     );
   }
 
-  protected function setUp() {
-    parent::setUp();
-
-    $this->enableModules(array('field', 'user'));
-  }
-
-  /**
-   * Overrides Drupal\views\Tests\ViewTestBase::schemaDefinition().
-   *
-   * Adds a uid column to test the relationships.
-   *
-   * @return array
-   */
-  protected function schemaDefinition() {
-    $schema = parent::schemaDefinition();
-
-    $schema['views_test_data']['fields']['uid'] = array(
-      'description' => "The {users}.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.
-   *
-   * @return array
-   */
-  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',
-        'base field' => 'uid'
-      )
-    );
-
-    return $data;
-  }
-
   /**
    * Tests the query result of a view with a relationship.
    */
diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/JoinTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/JoinTest.php
index 8430a453bc2b..df011c4f936a 100644
--- a/core/modules/views/lib/Drupal/views/Tests/Plugin/JoinTest.php
+++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/JoinTest.php
@@ -13,13 +13,23 @@
 
 /**
  * Tests a generic join plugin and the join plugin base.
+ *
+ * @see \Drupal\views_test_data\Plugin\views\join\JoinTest
+ * @see \Drupal\views\Plugin\views\join\JoinPluginBase
  */
-class JoinTest extends PluginTestBase {
+class JoinTest extends RelationshipJoinTestBase {
+
+  /**
+   * Views used by this test.
+   *
+   * @var array
+   */
+  public static $testViews = array('test_view');
 
   /**
    * A plugin manager which handlers the instances of joins.
    *
-   * @var Drupal\views\Plugin\Type\ViewsPluginManager
+   * @var \Drupal\views\Plugin\ViewsPluginManager
    */
   protected $manager;
 
@@ -38,19 +48,18 @@ protected function setUp() {
     $this->manager = drupal_container()->get('plugin.manager.views.join');
   }
 
-
   /**
    * Tests an example join plugin.
    */
   public function testExamplePlugin() {
 
     // Setup a simple join and test the result sql.
-    $view = views_get_view('frontpage');
+    $view = views_get_view('test_view');
     $view->initDisplay();
     $view->initQuery();
 
     $configuration = array(
-      'left_table' => 'node',
+      'left_table' => 'views_test_data',
       'left_field' => 'uid',
       'table' => 'users',
       'field' => 'uid',
@@ -61,14 +70,13 @@ public function testExamplePlugin() {
     $rand_int = rand(0, 1000);
     $join->setJoinValue($rand_int);
 
-    $query = db_select('node');
+    $query = db_select('views_test_data');
     $table = array('alias' => 'users');
     $join->buildJoin($query, $table, $view->query);
 
     $tables = $query->getTables();
     $join_info = $tables['users'];
-    debug($join_info);
-    $this->assertTrue(strpos($join_info['condition'], "node.uid = $rand_int") !== FALSE, 'Make sure that the custom join plugin can extend the join base and alter the result.');
+    $this->assertTrue(strpos($join_info['condition'], "views_test_data.uid = $rand_int") !== FALSE, 'Make sure that the custom join plugin can extend the join base and alter the result.');
   }
 
   /**
@@ -77,14 +85,14 @@ public function testExamplePlugin() {
   public function testBasePlugin() {
 
     // Setup a simple join and test the result sql.
-    $view = views_get_view('frontpage');
+    $view = views_get_view('test_view');
     $view->initDisplay();
     $view->initQuery();
 
     // First define a simple join without an extra condition.
     // Set the various options on the join object.
     $configuration = array(
-      'left_table' => 'node',
+      'left_table' => 'views_test_data',
       'left_field' => 'uid',
       'table' => 'users',
       'field' => 'uid',
@@ -97,7 +105,7 @@ public function testBasePlugin() {
 
     // Build the actual join values and read them back from the dbtng query
     // object.
-    $query = db_select('node');
+    $query = db_select('views_test_data');
     $table = array('alias' => 'users');
     $join->buildJoin($query, $table, $view->query);
 
@@ -106,7 +114,7 @@ public function testBasePlugin() {
     $this->assertEqual($join_info['join type'], 'LEFT', 'Make sure the default join type is LEFT');
     $this->assertEqual($join_info['table'], $configuration['table']);
     $this->assertEqual($join_info['alias'], 'users');
-    $this->assertEqual($join_info['condition'], 'node.uid = users.uid');
+    $this->assertEqual($join_info['condition'], 'views_test_data.uid = users.uid');
 
     // Set a different alias and make sure table info is as expected.
     $join = $this->manager->createInstance('standard', $configuration);
diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/RelationshipJoinTestBase.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/RelationshipJoinTestBase.php
new file mode 100644
index 000000000000..63a9f230f212
--- /dev/null
+++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/RelationshipJoinTestBase.php
@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\views\Tests\Plugin\RelationshipJoinTestBase.
+ */
+
+namespace Drupal\views\Tests\Plugin;
+
+/**
+ * Provies a base class for a testing a relationship.
+ *
+ * @see \Drupal\views\Tests\Handler\JoinTest
+ * @see \Drupal\views\Tests\Plugin\RelationshipTest
+ */
+abstract class RelationshipJoinTestBase extends PluginTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array('user');
+
+  protected function setUp() {
+    parent::setUp();
+
+    $this->enableViewsTestModule();
+  }
+
+  /**
+   * 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}.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',
+        'base field' => 'uid'
+      )
+    );
+
+    return $data;
+  }
+
+}
diff --git a/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/join/JoinTest.php b/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/join/JoinTest.php
index 5d0cb73d1275..48060f056dc5 100644
--- a/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/join/JoinTest.php
+++ b/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/join/JoinTest.php
@@ -51,7 +51,7 @@ public function setJoinValue($join_value) {
    */
   public function buildJoin($select_query, $table, $view_query) {
     // Add an additional hardcoded condition to the query.
-    $this->extra = 'node.uid = ' . $this->getJoinValue();
+    $this->extra = 'views_test_data.uid = ' . $this->getJoinValue();
     parent::buildJoin($select_query, $table, $view_query);
   }
 
-- 
GitLab