public function DisplayPageTest::testPageResponses

Checks the behavior of the page for access denied/not found behaviours.

File

drupal/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayPageTest.php, line 69
Contains \Drupal\views\Tests\Plugin\DisplayPageTest.

Class

DisplayPageTest
Tests the page display plugin.

Namespace

Drupal\views\Tests\Plugin

Code

public function testPageResponses() {

  // @todo Importing a route should fire a container rebuild.
  $this->container
    ->get('router.builder')
    ->rebuild();
  $subrequest = Request::create('/test_page_display_403', 'GET');
  $response = $this->container
    ->get('http_kernel')
    ->handle($subrequest, HttpKernelInterface::SUB_REQUEST);
  $this
    ->assertEqual($response
    ->getStatusCode(), 403);
  $subrequest = Request::create('/test_page_display_404', 'GET');
  $response = $this->container
    ->get('http_kernel')
    ->handle($subrequest, HttpKernelInterface::SUB_REQUEST);
  $this
    ->assertEqual($response
    ->getStatusCode(), 404);
  $subrequest = Request::create('/test_page_display_200', 'GET');
  $response = $this->container
    ->get('http_kernel')
    ->handle($subrequest, HttpKernelInterface::SUB_REQUEST);
  $this
    ->assertEqual($response
    ->getStatusCode(), 200);

  // Test accessing a disabled page for a view.
  $view = views_get_view('test_page_display');

  // Disable the view, rebuild menu, and request the page again.
  $view->storage
    ->disable()
    ->save();
  $subrequest = Request::create('/test_page_display_200', 'GET');
  $response = $this->container
    ->get('http_kernel')
    ->handle($subrequest, HttpKernelInterface::SUB_REQUEST);
  $this
    ->assertEqual($response
    ->getStatusCode(), 404);
}