function QuickEditEndPointAccessTest::assertAccessIsBlocked

Same name in other branches
  1. 8.9.x core/modules/quickedit/tests/src/Functional/QuickEditEndPointAccessTest.php \Drupal\Tests\quickedit\Functional\QuickEditEndPointAccessTest::assertAccessIsBlocked()

Asserts that access to the passed URL is blocked.

@internal

Parameters

string $url: The URL to check.

array $body: The payload to send with the request.

1 call to QuickEditEndPointAccessTest::assertAccessIsBlocked()
QuickEditEndPointAccessTest::testEndPointAccess in core/modules/quickedit/tests/src/Functional/QuickEditEndPointAccessTest.php
Tests that Quick Edit endpoints are protected from anonymous requests.

File

core/modules/quickedit/tests/src/Functional/QuickEditEndPointAccessTest.php, line 83

Class

QuickEditEndPointAccessTest
Tests accessing the Quick Edit endpoints.

Namespace

Drupal\Tests\quickedit\Functional

Code

protected function assertAccessIsBlocked(string $url, array $body) : void {
    $client = $this->getHttpClient();
    $message = [
        'message' => "The 'access in-place editing' permission is required.",
    ];
    $response = $client->post($url, [
        RequestOptions::BODY => http_build_query($body),
        RequestOptions::QUERY => [
            MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax',
        ],
        RequestOptions::COOKIES => $this->getSessionCookies(),
        RequestOptions::HEADERS => [
            'Accept' => 'application/json',
            'Content-Type' => 'application/x-www-form-urlencoded',
        ],
        RequestOptions::HTTP_ERRORS => FALSE,
    ]);
    $this->assertEquals(403, $response->getStatusCode());
    $response_message = Json::decode($response->getBody());
    $this->assertSame($message, $response_message);
}

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