Issue #1893850 by dawehner, xjm: Cleanup relationship tests and don't use the node module.
parent
df4d1789bd
commit
252f0c8ed6
core/modules/views
lib/Drupal/views/Tests
tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/join
|
@ -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 @@ class RelationshipTest extends ViewUnitTestBase {
|
|||
);
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
|
|
|
@ -13,13 +13,23 @@ use Drupal\views\Plugin\views\join\JoinPluginBase;
|
|||
|
||||
/**
|
||||
* 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 @@ class JoinTest extends PluginTestBase {
|
|||
$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 @@ class JoinTest extends PluginTestBase {
|
|||
$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 @@ class JoinTest extends PluginTestBase {
|
|||
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 @@ class JoinTest extends PluginTestBase {
|
|||
|
||||
// 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 @@ class JoinTest extends PluginTestBase {
|
|||
$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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -51,7 +51,7 @@ class JoinTest extends JoinPluginBase {
|
|||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue