function MessageTest::testCollection

Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/MessageTest.php \Drupal\Tests\jsonapi\Functional\MessageTest::testCollection()
  2. 8.9.x core/modules/jsonapi/tests/src/Functional/MessageTest.php \Drupal\Tests\jsonapi\Functional\MessageTest::testCollection()
  3. 10 core/modules/jsonapi/tests/src/Functional/MessageTest.php \Drupal\Tests\jsonapi\Functional\MessageTest::testCollection()

Overrides ResourceTestBase::testCollection

File

core/modules/jsonapi/tests/src/Functional/MessageTest.php, line 178

Class

MessageTest
JSON:API integration test for the "Message" content entity type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

public function testCollection() : void {
    $collection_url = Url::fromRoute('jsonapi.contact_message--camelids.collection.post')->setAbsolute(TRUE);
    $request_options = [];
    $request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
    $request_options = NestedArray::mergeDeep($request_options, $this->getAuthenticationRequestOptions());
    // 405 because Message entities are not stored, so they cannot be retrieved,
    // yet the same URL can be used to POST them.
    $response = $this->request('GET', $collection_url, $request_options);
    $this->assertSame(405, $response->getStatusCode());
    $this->assertSame([
        'POST',
    ], $response->getHeader('Allow'));
}

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