You are here

public function AccessTest::testStaticAccessPlugin in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Functional/Plugin/AccessTest.php \Drupal\Tests\views\Functional\Plugin\AccessTest::testStaticAccessPlugin()
  2. 9 core/modules/views/tests/src/Functional/Plugin/AccessTest.php \Drupal\Tests\views\Functional\Plugin\AccessTest::testStaticAccessPlugin()

Tests static access check.

See also

\Drupal\views_test\Plugin\views\access\StaticTest

File

core/modules/views/tests/src/Functional/Plugin/AccessTest.php, line 89

Class

AccessTest
Tests pluggable access for views.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testStaticAccessPlugin() {
  $view = Views::getView('test_access_static');
  $view
    ->setDisplay();
  $access_plugin = $view->display_handler
    ->getPlugin('access');
  $this
    ->assertFalse($access_plugin
    ->access($this->normalUser));
  $this
    ->drupalGet('test_access_static');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $display =& $view->storage
    ->getDisplay('default');
  $display['display_options']['access']['options']['access'] = TRUE;
  $access_plugin->options['access'] = TRUE;
  $view
    ->save();

  // Saving a view will cause the router to be rebuilt when the kernel
  // termination event fires. Simulate that here.
  $this->container
    ->get('router.builder')
    ->rebuildIfNeeded();
  $this
    ->assertTrue($access_plugin
    ->access($this->normalUser));
  $this
    ->drupalGet('test_access_static');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
}