function CommentResourceTestBase::testPostSkipCommentApproval

Same name in other branches
  1. 9 core/modules/comment/tests/src/Functional/Rest/CommentResourceTestBase.php \Drupal\Tests\comment\Functional\Rest\CommentResourceTestBase::testPostSkipCommentApproval()
  2. 10 core/modules/comment/tests/src/Functional/Rest/CommentResourceTestBase.php \Drupal\Tests\comment\Functional\Rest\CommentResourceTestBase::testPostSkipCommentApproval()
  3. 11.x core/modules/comment/tests/src/Functional/Rest/CommentResourceTestBase.php \Drupal\Tests\comment\Functional\Rest\CommentResourceTestBase::testPostSkipCommentApproval()

Tests POSTing a comment with and without 'skip comment approval'

3 methods override CommentResourceTestBase::testPostSkipCommentApproval()
CommentXmlAnonTest::testPostSkipCommentApproval in core/modules/comment/tests/src/Functional/Rest/CommentXmlAnonTest.php
Tests POSTing a comment with and without 'skip comment approval'
CommentXmlBasicAuthTest::testPostSkipCommentApproval in core/modules/comment/tests/src/Functional/Rest/CommentXmlBasicAuthTest.php
Tests POSTing a comment with and without 'skip comment approval'
CommentXmlCookieTest::testPostSkipCommentApproval in core/modules/comment/tests/src/Functional/Rest/CommentXmlCookieTest.php
Tests POSTing a comment with and without 'skip comment approval'

File

core/modules/comment/tests/src/Functional/Rest/CommentResourceTestBase.php, line 338

Class

CommentResourceTestBase

Namespace

Drupal\Tests\comment\Functional\Rest

Code

public function testPostSkipCommentApproval() {
    $this->initAuthentication();
    $this->provisionEntityResource();
    $this->setUpAuthorization('POST');
    // Create request.
    $request_options = [];
    $request_options[RequestOptions::HEADERS]['Accept'] = static::$mimeType;
    $request_options[RequestOptions::HEADERS]['Content-Type'] = static::$mimeType;
    $request_options = array_merge_recursive($request_options, $this->getAuthenticationRequestOptions('POST'));
    $request_options[RequestOptions::BODY] = $this->serializer
        ->encode($this->getNormalizedPostEntity(), static::$format);
    $url = $this->getEntityResourcePostUrl()
        ->setOption('query', [
        '_format' => static::$format,
    ]);
    // Status should be FALSE when posting as anonymous.
    $response = $this->request('POST', $url, $request_options);
    $unserialized = $this->serializer
        ->deserialize((string) $response->getBody(), get_class($this->entity), static::$format);
    $this->assertResourceResponse(201, FALSE, $response);
    $this->assertFalse($unserialized->isPublished());
    // Grant anonymous permission to skip comment approval.
    $this->grantPermissionsToTestedRole([
        'skip comment approval',
    ]);
    // Status should be TRUE when posting as anonymous and skip comment approval.
    $response = $this->request('POST', $url, $request_options);
    $unserialized = $this->serializer
        ->deserialize((string) $response->getBody(), get_class($this->entity), static::$format);
    $this->assertResourceResponse(201, FALSE, $response);
    $this->assertTrue($unserialized->isPublished());
}

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