Newer
Older
Damian Lee
committed
<?php
/**
* @file
* Contains \Drupal\views\Tests\Handler\HandlerAliasTest.
Damian Lee
committed
*/
namespace Drupal\views\Tests\Handler;
Alex Pott
committed
use Drupal\views\Tests\ViewKernelTestBase;
catch
committed
use Drupal\views\Views;
Damian Lee
committed
/**
* Tests handler table and field aliases.
*
* @group views
Damian Lee
committed
*/
Alex Pott
committed
class HandlerAliasTest extends ViewKernelTestBase {
Damian Lee
committed
public static $modules = array('user');
catch
committed
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_filter', 'test_alias');
Damian Lee
committed
protected function setUp() {
parent::setUp();
$this->installEntitySchema('user');
Damian Lee
committed
}
/**
* Overrides Drupal\views\Tests\ViewTestBase::viewsData().
*/
protected function viewsData() {
$data = parent::viewsData();
// User the existing test_filter plugin.
$data['views_test_data_alias']['table']['real table'] = 'views_test_data';
$data['views_test_data_alias']['name_alias']['filter']['id'] = 'test_filter';
$data['views_test_data_alias']['name_alias']['filter']['real field'] = 'name';
return $data;
}
public function testPluginAliases() {
catch
committed
$view = Views::getView('test_filter');
Damian Lee
committed
$view->initDisplay();
// Change the filtering.
$view->displayHandlers->get('default')->overrideOption('filters', array(
Damian Lee
committed
'test_filter' => array(
'id' => 'test_filter',
'table' => 'views_test_data_alias',
'field' => 'name_alias',
'operator' => '=',
'value' => 'John',
'group' => 0,
),
));
$this->executeView($view);
$filter = $view->filter['test_filter'];
// Check the definition values are present.
$this->assertIdentical($filter->definition['real table'], 'views_test_data');
$this->assertIdentical($filter->definition['real field'], 'name');
$this->assertIdentical($filter->table, 'views_test_data');
$this->assertIdentical($filter->realField, 'name');
// Test an existing user uid field.
catch
committed
$view = Views::getView('test_alias');
Damian Lee
committed
$view->initDisplay();
$this->executeView($view);
$filter = $view->filter['uid_raw'];
$this->assertIdentical($filter->definition['real field'], 'uid');
$this->assertIdentical($filter->field, 'uid_raw');
Angie Byron
committed
$this->assertIdentical($filter->table, 'users_field_data');
Damian Lee
committed
$this->assertIdentical($filter->realField, 'uid');
}
}