function RandomTest::testRandomWordValidator

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Component/Utility/RandomTest.php \Drupal\Tests\Component\Utility\RandomTest::testRandomWordValidator()
  2. 11.x core/tests/Drupal/Tests/Component/Utility/RandomTest.php \Drupal\Tests\Component\Utility\RandomTest::testRandomWordValidator()

Tests random word.

@covers ::word

File

core/tests/Drupal/Tests/Component/Utility/RandomTest.php, line 150

Class

RandomTest
Tests random data generation.

Namespace

Drupal\Tests\Component\Utility

Code

public function testRandomWordValidator() {
    $random = new Random();
    // Without a seed, test a different word is returned each time.
    $this->firstStringGenerated = $random->word(5);
    $next_str = $random->word(5);
    $this->assertNotEquals($this->firstStringGenerated, $next_str);
    // With a seed, test the same word is returned each time.
    mt_srand(0);
    $this->firstStringGenerated = $random->word(5);
    mt_srand(0);
    $next_str = $random->word(5);
    $this->assertEquals($this->firstStringGenerated, $next_str);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.