Loading core/lib/Drupal/Component/Utility/Random.php +0 −2 Original line number Diff line number Diff line Loading @@ -139,8 +139,6 @@ public function name($length = 8, $unique = FALSE) { * @return string */ public function word($length) { mt_srand((double) microtime() * 1000000); $vowels = ["a", "e", "i", "o", "u"]; $cons = ["b", "c", "d", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "u", "v", "w", "tr", "cr", "br", "fr", "th", "dr", "ch", "ph", "wr", "st", "sp", "sw", "pr", Loading core/tests/Drupal/Tests/Component/Utility/RandomTest.php +20 −0 Original line number Diff line number Diff line Loading @@ -142,6 +142,26 @@ public function testRandomStringValidator() { $this->assertNotEquals($this->firstStringGenerated, $str); } /** * Tests random word. * * @covers ::word */ 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); } /** * Callback for random string validation. * Loading Loading
core/lib/Drupal/Component/Utility/Random.php +0 −2 Original line number Diff line number Diff line Loading @@ -139,8 +139,6 @@ public function name($length = 8, $unique = FALSE) { * @return string */ public function word($length) { mt_srand((double) microtime() * 1000000); $vowels = ["a", "e", "i", "o", "u"]; $cons = ["b", "c", "d", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "u", "v", "w", "tr", "cr", "br", "fr", "th", "dr", "ch", "ph", "wr", "st", "sp", "sw", "pr", Loading
core/tests/Drupal/Tests/Component/Utility/RandomTest.php +20 −0 Original line number Diff line number Diff line Loading @@ -142,6 +142,26 @@ public function testRandomStringValidator() { $this->assertNotEquals($this->firstStringGenerated, $str); } /** * Tests random word. * * @covers ::word */ 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); } /** * Callback for random string validation. * Loading