function HandlerAliasTest::testPluginAliases

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Kernel/Handler/HandlerAliasTest.php \Drupal\Tests\views\Kernel\Handler\HandlerAliasTest::testPluginAliases()
  2. 10 core/modules/views/tests/src/Kernel/Handler/HandlerAliasTest.php \Drupal\Tests\views\Kernel\Handler\HandlerAliasTest::testPluginAliases()
  3. 11.x core/modules/views/tests/src/Kernel/Handler/HandlerAliasTest.php \Drupal\Tests\views\Kernel\Handler\HandlerAliasTest::testPluginAliases()

File

core/modules/views/tests/src/Kernel/Handler/HandlerAliasTest.php, line 46

Class

HandlerAliasTest
Tests handler table and field aliases.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testPluginAliases() {
    $view = Views::getView('test_filter');
    $view->initDisplay();
    // Change the filtering.
    $view->displayHandlers
        ->get('default')
        ->overrideOption('filters', [
        'test_filter' => [
            '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->assertSame('views_test_data', $filter->definition['real table']);
    $this->assertSame('name', $filter->definition['real field']);
    $this->assertSame('views_test_data', $filter->table);
    $this->assertSame('name', $filter->realField);
    // Test an existing user uid field.
    $view = Views::getView('test_alias');
    $view->initDisplay();
    $this->executeView($view);
    $filter = $view->filter['uid_raw'];
    $this->assertSame('uid', $filter->definition['real field']);
    $this->assertSame('uid_raw', $filter->field);
    $this->assertSame('users_field_data', $filter->table);
    $this->assertSame('uid', $filter->realField);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.