function ViewAjaxTest::testNonAjaxViewViaAjax

Same name in other branches
  1. 9 core/modules/views/tests/src/Functional/ViewAjaxTest.php \Drupal\Tests\views\Functional\ViewAjaxTest::testNonAjaxViewViaAjax()
  2. 8.9.x core/modules/views/tests/src/Functional/ViewAjaxTest.php \Drupal\Tests\views\Functional\ViewAjaxTest::testNonAjaxViewViaAjax()
  3. 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 54

Class

ViewAjaxTest
Tests the ajax view functionality.

Namespace

Drupal\Tests\views\Functional

Code

public function testNonAjaxViewViaAjax() : void {
    $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());
}

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