comparison core/modules/comment/tests/src/Kernel/CommentHostnameTest.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents
children 12f9dff5fda9
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
1 <?php
2
3 namespace Drupal\Tests\comment\Kernel;
4
5 use Drupal\comment\Entity\Comment;
6 use Drupal\comment\Entity\CommentType;
7 use Drupal\KernelTests\KernelTestBase;
8 use Symfony\Component\HttpFoundation\Request;
9
10 /**
11 * Tests the hostname base field.
12 *
13 * @coversDefaultClass \Drupal\comment\Entity\Comment
14 *
15 * @group comment
16 */
17 class CommentHostnameTest extends KernelTestBase {
18
19 /**
20 * {@inheritdoc}
21 */
22 protected static $modules = ['comment', 'entity_test', 'user'];
23
24 /**
25 * Tests hostname default value callback.
26 *
27 * @covers ::getDefaultHostname
28 */
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);
35
36 CommentType::create([
37 'id' => 'foo',
38 'target_entity_type_id' => 'entity_test',
39 ])->save();
40 $comment = Comment::create(['comment_type' => 'foo']);
41
42 // Check that the hostname was set correctly.
43 $this->assertEquals('203.0.113.1', $comment->getHostname());
44 }
45
46 }