class CryptTest

Tests random bytes generation.

Hierarchy

  • class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
    • class \Drupal\Tests\Component\Utility\CryptTest

Expanded class hierarchy of CryptTest

See also

\Drupal\Component\Utility\Crypt

File

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

Namespace

Drupal\Tests\Component\Utility
View source
class CryptTest extends UnitTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Crypt generator tests',
      'description' => 'Test functionality of Crypt component.',
    );
  }

  /**
   * Tests \Drupal\Component\Utility\Crypt::randomBytes().
   */
  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);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CryptTest::getInfo public static function This method exists to support the simpletest UI runner. Overrides UnitTestCase::getInfo
CryptTest::testRandomBytes public function Tests \Drupal\Component\Utility\Crypt::randomBytes().
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::randomName public static function Generates a random string containing letters and numbers.