You are here

public function ViewAjaxTest::testNonAjaxViewViaAjax in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Functional/ViewAjaxTest.php \Drupal\Tests\views\Functional\ViewAjaxTest::testNonAjaxViewViaAjax()
  2. 10 core/modules/views/tests/src/Functional/ViewAjaxTest.php \Drupal\Tests\views\Functional\ViewAjaxTest::testNonAjaxViewViaAjax()

Ensures that non-ajax view cannot be accessed via an ajax HTTP request.

File

core/modules/views/tests/src/Functional/ViewAjaxTest.php, line 49

Class

ViewAjaxTest
Tests the ajax view functionality.

Namespace

Drupal\Tests\views\Functional

Code

public function testNonAjaxViewViaAjax() {
  $client = $this
    ->getHttpClient();
  $response = $client
    ->request('POST', $this
    ->buildUrl('views/ajax'), [
    'form_params' => [
      'view_name' => 'test_ajax_view',
      'view_display_id' => 'default',
    ],
    'query' => [
      MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax',
    ],
  ]);
  $this
    ->assertEquals(200, $response
    ->getStatusCode());
  $response = $client
    ->request('POST', $this
    ->buildUrl('views/ajax'), [
    'form_params' => [
      'view_name' => 'test_view',
      'view_display_id' => 'default',
    ],
    'query' => [
      MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax',
    ],
    'http_errors' => FALSE,
  ]);
  $this
    ->assertEquals(403, $response
    ->getStatusCode());
}