Commit bc70eaeb authored by Dries's avatar Dries

- Patch #535440 by andypost, carlos8f, boombatower: random strings in SimpleTest should not contain

parent 19aaebcb
......@@ -181,7 +181,7 @@ class DBLogTestCase extends DrupalWebTestCase {
*/
private function doUser() {
// Set user variables.
$name = $this->randomName();
$name = $this->randomName(4);
$pass = user_password();
// Add user using form to generate add user event (which is not triggered by drupalCreateUser).
$edit = array();
......
......@@ -498,7 +498,7 @@ class SearchCommentTestCase extends DrupalWebTestCase {
* Verify that comments are rendered using proper format in search results.
*/
function testSearchResultsComment() {
$comment_body = $this->randomName(5);
$comment_body = 'Test comment body';
variable_set('comment_preview_article', DRUPAL_OPTIONAL);
// Enable check_plain() for 'Filtered HTML' text format.
......@@ -523,7 +523,7 @@ class SearchCommentTestCase extends DrupalWebTestCase {
$node = $this->drupalCreateNode(array('type' => 'article'));
// Post a comment using 'Full HTML' text format.
$edit_comment = array();
$edit_comment['subject'] = $this->randomName(2);
$edit_comment['subject'] = 'Test comment subject';
$edit_comment['comment_body[' . LANGUAGE_NONE . '][0][value]'] = '<h1>' . $comment_body . '</h1>';
$edit_comment['comment_body[' . LANGUAGE_NONE . '][0][value_format]'] = 2;
$this->drupalPost('comment/reply/' . $node->nid, $edit_comment, t('Save'));
......@@ -534,7 +534,7 @@ class SearchCommentTestCase extends DrupalWebTestCase {
// Search for the comment subject.
$edit = array(
'search_block_form' => $edit_comment['subject'],
'search_block_form' => "'" . $edit_comment['subject'] . "'",
);
$this->drupalPost('', $edit, t('Search'));
$this->assertText($node->title, t('Node found in search results.'));
......@@ -542,7 +542,7 @@ class SearchCommentTestCase extends DrupalWebTestCase {
// Search for the comment body.
$edit = array(
'search_block_form' => $comment_body,
'search_block_form' => "'" . $comment_body . "'",
);
$this->drupalPost('', $edit, t('Search'));
$this->assertText($node->title, t('Node found in search results.'));
......
......@@ -505,45 +505,41 @@ protected function exceptionHandler($exception) {
* is not restricted.
*
* @param $length
* Length of random string to generate which will be appended to $db_prefix.
* Length of random string to generate.
* @return
* Randomly generated string.
*/
public static function randomString($length = 8) {
global $db_prefix;
$str = '';
for ($i = 0; $i < $length; $i++) {
$str .= chr(mt_rand(32, 126));
}
return str_replace('simpletest', 's', $db_prefix) . $str;
return $str;
}
/**
* Generates a random string containing letters and numbers.
*
* The letters may be upper or lower case. This method is better for
* restricted inputs that do not accept certain characters. For example,
* when testing input fields that require machine readable values (ie without
* spaces and non-standard characters) this method is best.
* The string will always start with a letter. The letters may be upper or
* lower case. This method is better for restricted inputs that do not
* accept certain characters. For example, when testing input fields that
* require machine readable values (i.e. without spaces and non-standard
* characters) this method is best.
*
* @param $length
* Length of random string to generate which will be appended to $db_prefix.
* Length of random string to generate.
* @return
* Randomly generated string.
*/
public static function randomName($length = 8) {
global $db_prefix;
$values = array_merge(range(65, 90), range(97, 122), range(48, 57));
$max = count($values) - 1;
$str = '';
for ($i = 0; $i < $length; $i++) {
$str = chr(mt_rand(97, 122));
for ($i = 1; $i < $length; $i++) {
$str .= chr($values[mt_rand(0, $max)]);
}
return str_replace('simpletest', 's', $db_prefix) . $str;
return $str;
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment