annotate core/modules/comment/tests/src/Kernel/CommentHostnameTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@17 1 <?php
Chris@17 2
Chris@17 3 namespace Drupal\Tests\comment\Kernel;
Chris@17 4
Chris@17 5 use Drupal\comment\Entity\Comment;
Chris@17 6 use Drupal\comment\Entity\CommentType;
Chris@17 7 use Drupal\KernelTests\KernelTestBase;
Chris@17 8 use Symfony\Component\HttpFoundation\Request;
Chris@17 9
Chris@17 10 /**
Chris@17 11 * Tests the hostname base field.
Chris@17 12 *
Chris@17 13 * @coversDefaultClass \Drupal\comment\Entity\Comment
Chris@17 14 *
Chris@17 15 * @group comment
Chris@17 16 */
Chris@17 17 class CommentHostnameTest extends KernelTestBase {
Chris@17 18
Chris@17 19 /**
Chris@17 20 * {@inheritdoc}
Chris@17 21 */
Chris@17 22 protected static $modules = ['comment', 'entity_test', 'user'];
Chris@17 23
Chris@17 24 /**
Chris@17 25 * Tests hostname default value callback.
Chris@17 26 *
Chris@17 27 * @covers ::getDefaultHostname
Chris@17 28 */
Chris@17 29 public function testGetDefaultHostname() {
Chris@17 30 // Create a fake request to be used for testing.
Chris@17 31 $request = Request::create('/', 'GET', [], [], [], ['REMOTE_ADDR' => '203.0.113.1']);
Chris@17 32 /** @var \Symfony\Component\HttpFoundation\RequestStack $stack */
Chris@17 33 $stack = $this->container->get('request_stack');
Chris@17 34 $stack->push($request);
Chris@17 35
Chris@17 36 CommentType::create([
Chris@17 37 'id' => 'foo',
Chris@17 38 'target_entity_type_id' => 'entity_test',
Chris@17 39 ])->save();
Chris@18 40
Chris@18 41 // Check that the hostname is empty by default.
Chris@17 42 $comment = Comment::create(['comment_type' => 'foo']);
Chris@18 43 $this->assertEquals('', $comment->getHostname());
Chris@17 44
Chris@18 45 \Drupal::configFactory()
Chris@18 46 ->getEditable('comment.settings')
Chris@18 47 ->set('log_ip_addresses', TRUE)
Chris@18 48 ->save(TRUE);
Chris@17 49 // Check that the hostname was set correctly.
Chris@18 50 $comment = Comment::create(['comment_type' => 'foo']);
Chris@17 51 $this->assertEquals('203.0.113.1', $comment->getHostname());
Chris@17 52 }
Chris@17 53
Chris@17 54 }