3 namespace Drupal\Tests\comment\Kernel;
5 use Drupal\comment\Entity\Comment;
6 use Drupal\comment\Entity\CommentType;
7 use Drupal\KernelTests\KernelTestBase;
8 use Symfony\Component\HttpFoundation\Request;
11 * Tests the hostname base field.
13 * @coversDefaultClass \Drupal\comment\Entity\Comment
17 class CommentHostnameTest extends KernelTestBase {
22 protected static $modules = ['comment', 'entity_test', 'user'];
25 * Tests hostname default value callback.
27 * @covers ::getDefaultHostname
29 public function testGetDefaultHostname() {
30 // Create a fake request to be used for testing.
31 $request = Request::create('/', 'GET', [], [], [], ['REMOTE_ADDR' => '203.0.113.1']);
32 /** @var \Symfony\Component\HttpFoundation\RequestStack $stack */
33 $stack = $this->container->get('request_stack');
34 $stack->push($request);
38 'target_entity_type_id' => 'entity_test',
40 $comment = Comment::create(['comment_type' => 'foo']);
42 // Check that the hostname was set correctly.
43 $this->assertEquals('203.0.113.1', $comment->getHostname());