You are here

public function JsonLogDataTest::testClientIpWillBeSetWithMaxLength in JSONlog 8

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/JsonLogDataTest.php \Drupal\Tests\jsonlog\Unit\JsonLogDataTest::testClientIpWillBeSetWithMaxLength()
  2. 3.x tests/src/Unit/JsonLogDataTest.php \Drupal\Tests\jsonlog\Unit\JsonLogDataTest::testClientIpWillBeSetWithMaxLength()

File

tests/src/Unit/JsonLogDataTest.php, line 144

Class

JsonLogDataTest
Unit tests for JsonLogData class

Namespace

Drupal\Tests\jsonlog\Unit

Code

public function testClientIpWillBeSetWithMaxLength() {
  $this->data = new JsonLogData('test_site_id', 'test_canonical');
  $this->data
    ->setClient_ip('127.0.0.1');
  $this
    ->assertEquals('127.0.0.1', $this->data
    ->getClientIp(), 'Client IP set.');

  // Try bigger
  $string = random_bytes(1024);
  $this->data
    ->setClient_ip($string);
  $this
    ->assertFalse(strlen($string) == strlen($this->data
    ->getClientIp()), 'Client IP was truncated.');
}