function HandlerTest::testAccess

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

Tests access to a handler.

See also

views_test_data_handler_test_access_callback

File

core/modules/views/tests/src/Functional/Handler/HandlerTest.php, line 357

Class

HandlerTest
Tests abstract handler definitions.

Namespace

Drupal\Tests\views\Functional\Handler

Code

public function testAccess() {
    $view = Views::getView('test_handler_test_access');
    $views_data = $this->viewsData();
    $views_data = $views_data['views_test_data'];
    // Enable access to callback only field and deny for callback + arguments.
    $this->config('views_test_data.tests')
        ->set('handler_access_callback', TRUE)
        ->save();
    $this->config('views_test_data.tests')
        ->set('handler_access_callback_argument', FALSE)
        ->save();
    $view->initDisplay();
    $view->initHandlers();
    foreach ($views_data['access_callback'] as $type => $info) {
        if (!in_array($type, [
            'title',
            'help',
        ])) {
            $this->assertInstanceOf(HandlerBase::class, $view->field['access_callback']);
            $this->assertFalse(isset($view->field['access_callback_arguments']), 'Make sure the user got no access to the access_callback_arguments field ');
        }
    }
    // Enable access to the callback + argument handlers and deny for callback.
    $this->config('views_test_data.tests')
        ->set('handler_access_callback', FALSE)
        ->save();
    $this->config('views_test_data.tests')
        ->set('handler_access_callback_argument', TRUE)
        ->save();
    $view->destroy();
    $view->initDisplay();
    $view->initHandlers();
    foreach ($views_data['access_callback'] as $type => $info) {
        if (!in_array($type, [
            'title',
            'help',
        ])) {
            $this->assertFalse(isset($view->field['access_callback']), 'Make sure the user got no access to the access_callback field ');
            $this->assertInstanceOf(HandlerBase::class, $view->field['access_callback_arguments']);
        }
    }
}

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