public function RandomTest::testRandomWordValidator in Drupal 10
Same name and namespace in other branches
- 9 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\UtilityCode
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);
}