CommentHostnameTest.php in Drupal 8
File
core/modules/comment/tests/src/Kernel/CommentHostnameTest.php
View source
<?php
namespace Drupal\Tests\comment\Kernel;
use Drupal\comment\Entity\Comment;
use Drupal\comment\Entity\CommentType;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\HttpFoundation\Request;
class CommentHostnameTest extends KernelTestBase {
protected static $modules = [
'comment',
'entity_test',
'user',
];
public function testGetDefaultHostname() {
$request = Request::create('/', 'GET', [], [], [], [
'REMOTE_ADDR' => '203.0.113.1',
]);
$stack = $this->container
->get('request_stack');
$stack
->push($request);
CommentType::create([
'id' => 'foo',
'target_entity_type_id' => 'entity_test',
])
->save();
$comment = Comment::create([
'comment_type' => 'foo',
]);
$this
->assertEquals('', $comment
->getHostname());
\Drupal::configFactory()
->getEditable('comment.settings')
->set('log_ip_addresses', TRUE)
->save(TRUE);
$comment = Comment::create([
'comment_type' => 'foo',
]);
$this
->assertEquals('203.0.113.1', $comment
->getHostname());
}
}