public function CryptTest::testRandomBytes

Tests \Drupal\Component\Utility\Crypt::randomBytes().

File

drupal/core/tests/Drupal/Tests/Component/Utility/CryptTest.php, line 30
Contains \Drupal\Tests\Component\Utility\CryptTest.

Class

CryptTest
Tests random bytes generation.

Namespace

Drupal\Tests\Component\Utility

Code

public function testRandomBytes() {
  for ($i = 1; $i < 10; $i++) {
    $count = rand(10, 10000);

    // Check that different values are being generated.
    $this
      ->assertNotEquals(Crypt::randomBytes($count), Crypt::randomBytes($count));

    // Check the length.
    $this
      ->assertEquals(strlen(Crypt::randomBytes($count)), $count);
  }
}