X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcomment%2Ftests%2Fsrc%2FKernel%2FCommentItemTest.php;fp=web%2Fcore%2Fmodules%2Fcomment%2Ftests%2Fsrc%2FKernel%2FCommentItemTest.php;h=85f6112561886c2767c2bf5a715a5c1a1c7d53f0;hp=7b9a263c2deff03711e1bf70ab83a37652d1dc0f;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/comment/tests/src/Kernel/CommentItemTest.php b/web/core/modules/comment/tests/src/Kernel/CommentItemTest.php index 7b9a263c2..85f611256 100644 --- a/web/core/modules/comment/tests/src/Kernel/CommentItemTest.php +++ b/web/core/modules/comment/tests/src/Kernel/CommentItemTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\comment\Kernel; +use Drupal\comment\Entity\Comment; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\comment\Tests\CommentTestTrait; use Drupal\Core\Field\FieldItemListInterface; @@ -64,4 +65,57 @@ class CommentItemTest extends FieldKernelTestBase { $this->assertEqual('status', $mainProperty); } + /** + * Tests comment author name. + */ + public function testCommentAuthorName() { + $this->installEntitySchema('comment'); + + $host = EntityTest::create(['name' => $this->randomString()]); + $host->save(); + + // Create some comments. + $comment = Comment::create([ + 'subject' => 'My comment title', + 'uid' => 1, + 'name' => 'entity-test', + 'mail' => 'entity@localhost', + 'entity_type' => 'entity_test', + 'entity_id' => $host->id(), + 'comment_type' => 'entity_test', + 'status' => 1, + ]); + $comment->save(); + + // The entity fields for name and mail have no meaning if the user is not + // Anonymous. + $this->assertNull($comment->name->value); + $this->assertNull($comment->mail->value); + + $comment_anonymous = Comment::create([ + 'subject' => 'Anonymous comment title', + 'uid' => 0, + 'name' => 'barry', + 'mail' => 'test@example.com', + 'homepage' => 'https://example.com', + 'entity_type' => 'entity_test', + 'entity_id' => $host->id(), + 'comment_type' => 'entity_test', + 'status' => 1, + ]); + $comment_anonymous->save(); + + // The entity fields for name and mail have retained their values when + // comment belongs to an anonymous user. + $this->assertNotNull($comment_anonymous->name->value); + $this->assertNotNull($comment_anonymous->mail->value); + + $comment_anonymous->setOwnerId(1) + ->save(); + // The entity fields for name and mail have no meaning if the user is not + // Anonymous. + $this->assertNull($comment_anonymous->name->value); + $this->assertNull($comment_anonymous->mail->value); + } + }