Unverified Commit 30e300fe authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3109767 by quietone, mtodor, Kristen Pol, larowlan: Unable generate...

Issue #3109767 by quietone, mtodor, Kristen Pol, larowlan: Unable generate sample data with defined random seed for the "string" or "link" field type
parent a5103bb8
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -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",
+20 −0
Original line number Diff line number Diff line
@@ -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.
   *