Unverified Commit 0b8908a1 authored by alexpott's avatar alexpott

Issue #2975217 by Sam152, Berdir: Update the default comment entity owner to the current user

parent d3784a13
...@@ -319,13 +319,6 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ...@@ -319,13 +319,6 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
return $fields; return $fields;
} }
/**
* {@inheritdoc}
*/
public static function getDefaultEntityOwner() {
return 0;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -314,7 +314,7 @@ public function testPostDxWithoutCriticalBaseFields() { ...@@ -314,7 +314,7 @@ public function testPostDxWithoutCriticalBaseFields() {
// $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\nentity_type: This value should not be null.\n", $response); // $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\nentity_type: This value should not be null.\n", $response);
// DX: 422 when missing 'entity_type' field. // DX: 422 when missing 'entity_type' field.
$request_options[RequestOptions::BODY] = $this->serializer->encode(array_diff_key($this->getNormalizedPostEntity(), ['field_name' => TRUE]), static::$format); $request_options[RequestOptions::BODY] = $this->serializer->encode(array_diff_key($this->getNormalizedPostEntity(), ['entity_type' => TRUE]), static::$format);
$response = $this->request('POST', $url, $request_options); $response = $this->request('POST', $url, $request_options);
// @todo Uncomment, remove next 2 lines in https://www.drupal.org/node/2820364. // @todo Uncomment, remove next 2 lines in https://www.drupal.org/node/2820364.
$this->assertSame(500, $response->getStatusCode()); $this->assertSame(500, $response->getStatusCode());
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\Tests\comment\Kernel; namespace Drupal\Tests\comment\Kernel;
use Drupal\comment\Entity\Comment;
use Drupal\comment\Entity\CommentType; use Drupal\comment\Entity\CommentType;
use Drupal\Core\Database\Database; use Drupal\Core\Database\Database;
use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Core\Entity\Entity\EntityViewDisplay;
...@@ -9,6 +10,7 @@ ...@@ -9,6 +10,7 @@
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\KernelTestBase; use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;
/** /**
* Tests integration of comment with other components. * Tests integration of comment with other components.
...@@ -17,6 +19,8 @@ ...@@ -17,6 +19,8 @@
*/ */
class CommentIntegrationTest extends KernelTestBase { class CommentIntegrationTest extends KernelTestBase {
use UserCreationTrait;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -31,11 +35,13 @@ protected function setUp() { ...@@ -31,11 +35,13 @@ protected function setUp() {
$this->installEntitySchema('user'); $this->installEntitySchema('user');
$this->installEntitySchema('comment'); $this->installEntitySchema('comment');
$this->installSchema('dblog', ['watchdog']); $this->installSchema('dblog', ['watchdog']);
$this->installSchema('system', ['sequences']);
// Create a new 'comment' comment-type. // Create a new 'comment' comment-type.
CommentType::create([ CommentType::create([
'id' => 'comment', 'id' => 'comment',
'label' => $this->randomString(), 'label' => $this->randomString(),
'target_entity_type_id' => 'entity_test',
])->save(); ])->save();
} }
...@@ -134,4 +140,21 @@ public function testViewMode() { ...@@ -134,4 +140,21 @@ public function testViewMode() {
$this->assertTrue($host_display->get('hidden')[$field_name]); $this->assertTrue($host_display->get('hidden')[$field_name]);
} }
/**
* Test the default owner of comment entities.
*/
public function testCommentDefaultOwner() {
$comment = Comment::create([
'comment_type' => 'comment',
]);
$this->assertEquals(0, $comment->getOwnerId());
$user = $this->createUser();
$this->container->get('current_user')->setAccount($user);
$comment = Comment::create([
'comment_type' => 'comment',
]);
$this->assertEquals($user->id(), $comment->getOwnerId());
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment