X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Frest%2Ftests%2Fsrc%2FFunctional%2FEntityResource%2FComment%2FCommentResourceTestBase.php;h=43a0e3d05e89efbad39874066d076acb9a27c669;hp=8355f86cc5d1939d31f43c505fcae73b9ff2e23d;hb=bfbba508964731508b9bd6d5835c2edc858db95b;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae diff --git a/web/core/modules/rest/tests/src/Functional/EntityResource/Comment/CommentResourceTestBase.php b/web/core/modules/rest/tests/src/Functional/EntityResource/Comment/CommentResourceTestBase.php index 8355f86cc..43a0e3d05 100644 --- a/web/core/modules/rest/tests/src/Functional/EntityResource/Comment/CommentResourceTestBase.php +++ b/web/core/modules/rest/tests/src/Functional/EntityResource/Comment/CommentResourceTestBase.php @@ -328,4 +328,37 @@ abstract class CommentResourceTestBase extends EntityResourceTestBase { } } + /** + * Tests POSTing a comment with and without 'skip comment approval' + */ + 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->getStatus()); + + // 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->getStatus()); + } + }