summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/aggregator/aggregator.test14
-rw-r--r--modules/field/field.test6
-rw-r--r--modules/field/modules/text/text.test4
-rw-r--r--modules/profile/profile.test6
-rw-r--r--modules/simpletest/drupal_web_test_case.php52
-rw-r--r--modules/simpletest/tests/cache.test4
-rw-r--r--modules/tracker/tracker.test8
-rw-r--r--modules/upload/upload.test2
8 files changed, 55 insertions, 41 deletions
diff --git a/modules/aggregator/aggregator.test b/modules/aggregator/aggregator.test
index 7d71760a5..bc29e933f 100644
--- a/modules/aggregator/aggregator.test
+++ b/modules/aggregator/aggregator.test
@@ -7,8 +7,6 @@
*/
class AggregatorTestCase extends DrupalWebTestCase {
- private static $prefix = 'simpletest_aggregator_';
-
function setUp() {
parent::setUp('aggregator', 'aggregator_test');
$web_user = $this->drupalCreateUser(array('administer news feeds', 'access news feeds', 'create article content'));
@@ -55,7 +53,7 @@ class AggregatorTestCase extends DrupalWebTestCase {
* A feed array.
*/
function getFeedEditArray($feed_url = NULL) {
- $feed_name = $this->randomName(10, self::$prefix);
+ $feed_name = $this->randomName(10);
if (!$feed_url) {
$feed_url = $GLOBALS['base_url'] . '/rss.xml?feed=' . $feed_name;
}
@@ -452,8 +450,6 @@ class RemoveFeedItemTestCase extends AggregatorTestCase {
}
class CategorizeFeedItemTestCase extends AggregatorTestCase {
- private static $prefix = 'simpletest_aggregator_';
-
public static function getInfo() {
return array(
'name' => t('Categorize feed item functionality'),
@@ -470,7 +466,7 @@ class CategorizeFeedItemTestCase extends AggregatorTestCase {
$this->createSampleNodes();
// Simulate form submission on "admin/content/aggregator/add/category".
- $edit = array('title' => $this->randomName(10, self::$prefix), 'description' => '');
+ $edit = array('title' => $this->randomName(10), 'description' => '');
$this->drupalPost('admin/content/aggregator/add/category', $edit, t('Save'));
$this->assertRaw(t('The category %title has been added.', array('%title' => $edit['title'])), t('The category %title has been added.', array('%title' => $edit['title'])));
@@ -511,8 +507,6 @@ class CategorizeFeedItemTestCase extends AggregatorTestCase {
}
class ImportOPMLTestCase extends AggregatorTestCase {
- private static $prefix = 'simpletest_aggregator_';
-
public static function getInfo() {
return array(
'name' => t('Import feeds from OPML functionality'),
@@ -527,7 +521,7 @@ class ImportOPMLTestCase extends AggregatorTestCase {
function openImportForm() {
db_delete('aggregator_category')->execute();
- $category = $this->randomName(10, self::$prefix);
+ $category = $this->randomName(10);
$cid = db_insert('aggregator_category')
->fields(array(
'title' => $category,
@@ -590,7 +584,7 @@ class ImportOPMLTestCase extends AggregatorTestCase {
db_delete('aggregator_category')->execute();
db_delete('aggregator_category_feed')->execute();
- $category = $this->randomName(10, self::$prefix);
+ $category = $this->randomName(10);
db_insert('aggregator_category')
->fields(array(
'cid' => 1,
diff --git a/modules/field/field.test b/modules/field/field.test
index 7030b9543..9df1bb997 100644
--- a/modules/field/field.test
+++ b/modules/field/field.test
@@ -724,9 +724,9 @@ class FieldFormTestCase extends DrupalWebTestCase {
$web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content'));
$this->drupalLogin($web_user);
- $this->field_single = array('field_name' => drupal_strtolower($this->randomName(). '_field_name'), 'type' => 'test_field');
- $this->field_multiple = array('field_name' => drupal_strtolower($this->randomName(). '_field_name'), 'type' => 'test_field', 'cardinality' => 4);
- $this->field_unlimited = array('field_name' => drupal_strtolower($this->randomName(). '_field_name'), 'type' => 'test_field', 'cardinality' => FIELD_CARDINALITY_UNLIMITED);
+ $this->field_single = array('field_name' => drupal_strtolower($this->randomName()), 'type' => 'test_field');
+ $this->field_multiple = array('field_name' => drupal_strtolower($this->randomName()), 'type' => 'test_field', 'cardinality' => 4);
+ $this->field_unlimited = array('field_name' => drupal_strtolower($this->randomName()), 'type' => 'test_field', 'cardinality' => FIELD_CARDINALITY_UNLIMITED);
$this->instance = array(
'bundle' => 'test_bundle',
diff --git a/modules/field/modules/text/text.test b/modules/field/modules/text/text.test
index 8f7459370..cb240b6c9 100644
--- a/modules/field/modules/text/text.test
+++ b/modules/field/modules/text/text.test
@@ -76,7 +76,7 @@ class TextFieldTestCase extends DrupalWebTestCase {
function _testTextfieldWidgets($field_type, $widget_type) {
// Setup a field and instance
$entity_type = 'test_entity';
- $this->field_name = drupal_strtolower($this->randomName() . '_field_name');
+ $this->field_name = drupal_strtolower($this->randomName());
$this->field = array('field_name' => $this->field_name, 'type' => $field_type);
field_create_field($this->field);
$this->instance = array(
@@ -128,7 +128,7 @@ class TextFieldTestCase extends DrupalWebTestCase {
function _testTextfieldWidgetsFormatted($field_type, $widget_type) {
// Setup a field and instance
$entity_type = 'test_entity';
- $this->field_name = drupal_strtolower($this->randomName() . '_field_name');
+ $this->field_name = drupal_strtolower($this->randomName());
$this->field = array('field_name' => $this->field_name, 'type' => $field_type);
field_create_field($this->field);
$this->instance = array(
diff --git a/modules/profile/profile.test b/modules/profile/profile.test
index 4a211c31d..3d35f153b 100644
--- a/modules/profile/profile.test
+++ b/modules/profile/profile.test
@@ -31,7 +31,7 @@ class ProfileTestCase extends DrupalWebTestCase {
* The fid of the field that was just created.
*/
function createProfileField($type = 'textfield', $category = 'simpletest', $edit = array()) {
- $edit['title'] = $title = $this->randomName(4, $type . '_');
+ $edit['title'] = $title = $this->randomName(8);
$edit['name'] = $form_name = 'profile_' . $title;
$edit['category'] = $category;
$edit['explanation'] = $this->randomName(50);
@@ -224,8 +224,8 @@ class ProfileTestWeights extends ProfileTestCase {
$field1 = $this->createProfileField('textfield', $category, array('weight' => 1));
$field2 = $this->createProfileField('textfield', $category, array('weight' => -1));
- $this->setProfileField($field1, $this->randomName(4, 'first_'));
- $this->setProfileField($field2, $this->randomName(4, 'second_'));
+ $this->setProfileField($field1, $this->randomName(8));
+ $this->setProfileField($field2, $this->randomName(8));
$profile_edit = $this->drupalGet('user/' . $this->normal_user->uid . '/edit/' . $category);
$this->assertTrue(strpos($profile_edit, $field1['title']) > strpos($profile_edit, $field2['title']), t('Profile field weights are respected on the user edit form.'));
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 86b827886..424e1f335 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -120,7 +120,7 @@ class DrupalWebTestCase {
* Time limit for the test.
*/
protected $timeLimit = 180;
-
+
/**
* HTTP authentication credentials (<username>:<password>).
*/
@@ -519,7 +519,7 @@ class DrupalWebTestCase {
// Add the default teaser.
if (!isset($settings['teaser'])) {
- $settings['teaser'] = $settings['body'];
+ $settings['teaser'] = $settings['body'];
}
// If the node's user uid is not specified manually, use the currently
@@ -554,7 +554,7 @@ class DrupalWebTestCase {
protected function drupalCreateContentType($settings = array()) {
// find a non-existent random type name.
do {
- $name = strtolower($this->randomName(3, 'type_'));
+ $name = strtolower($this->randomName(8));
} while (node_get_types('type', $name));
// Populate defaults array
@@ -641,27 +641,47 @@ class DrupalWebTestCase {
}
/**
- * Generates a random string.
+ * Generates a random string of ASCI characters of codes 32 to 126. That
+ * includes alpha-numeric characters and common misc characters.
*
- * @param $number
- * Number of characters in length to append to the prefix.
- * @param $prefix
- * Prefix to use.
+ * @param $length
+ * Length of random string to generate which will be appended to $db_prefx.
* @return
* Randomly generated string.
*/
- public static function randomName($number = 4, $prefix = 'simpletest_') {
- $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_';
- for ($x = 0; $x < $number; $x++) {
- $prefix .= $chars{mt_rand(0, strlen($chars) - 1)};
- if ($x == 0) {
- $chars .= '0123456789';
- }
+ public static function randomString($length = 8) {
+ global $db_prefix;
+
+ $str = '';
+ for ($i = 0; $i < $length; $i++) {
+ $str .= chr(mt_rand(32, 126));
}
- return $prefix;
+ return str_replace('simpletest', 's', $db_prefix) . $str;
}
/**
+ * Generates a random string containing letters, both capital and lower, and
+ * numbers. This method is better for restricted inputs that do not accept
+ * certain characters.
+ *
+ * @param $length
+ * Length of random string to generate which will be appended to $db_prefx.
+ * @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($values[mt_rand(0, $max)]);
+ }
+ return str_replace('simpletest', 's', $db_prefix) . $str;
+ }
+
+ /**
* Create a user with a given set of permissions. The permissions correspond to the
* names given on the privileges page.
*
diff --git a/modules/simpletest/tests/cache.test b/modules/simpletest/tests/cache.test
index 31d13c3e7..35baea8af 100644
--- a/modules/simpletest/tests/cache.test
+++ b/modules/simpletest/tests/cache.test
@@ -114,7 +114,7 @@ class CacheSavingCase extends CacheTestCase {
* Test the saving and restoring of a string.
*/
function testString() {
- $this->checkVariable($this->randomName('100'));
+ $this->checkVariable($this->randomName(100));
}
/**
@@ -143,7 +143,7 @@ class CacheSavingCase extends CacheTestCase {
*/
function testObject() {
$test_object = new stdClass();
- $test_object->test1 = $this->randomName('100');
+ $test_object->test1 = $this->randomName(100);
$test_object->test2 = 100;
$test_object->test3 = array('drupal1', 'drupal2' => 'drupal3', 'drupal4' => array('drupal5', 'drupal6'));
diff --git a/modules/tracker/tracker.test b/modules/tracker/tracker.test
index 2f2249738..c5e853d82 100644
--- a/modules/tracker/tracker.test
+++ b/modules/tracker/tracker.test
@@ -29,11 +29,11 @@ class TrackerTest extends DrupalWebTestCase {
$this->drupalLogin($this->user);
$page1 = array(
- 'title' => $this->randomName(4, 'published_'),
+ 'title' => $this->randomName(8),
'status' => 1,
);
$page2 = array(
- 'title' => $this->randomName(4, 'unpublished_'),
+ 'title' => $this->randomName(8),
'status' => 0,
);
$this->drupalCreateNode($page1);
@@ -52,12 +52,12 @@ class TrackerTest extends DrupalWebTestCase {
$this->drupalLogin($this->user);
$page1 = array(
- 'title' => $this->randomName(4, 'published_'),
+ 'title' => $this->randomName(8),
'uid' => $this->user->uid,
'status' => 1,
);
$page2 = array(
- 'title' => $this->randomName(4, 'unpublished_'),
+ 'title' => $this->randomName(8),
'uid' => $this->user->uid,
'status' => 0,
);
diff --git a/modules/upload/upload.test b/modules/upload/upload.test
index 1fabe2c62..ffbfd8680 100644
--- a/modules/upload/upload.test
+++ b/modules/upload/upload.test
@@ -218,7 +218,7 @@ class UploadTestCase extends DrupalWebTestCase {
*/
function getSimpletestRoleId($user) {
foreach ($user->roles as $rid => $role) {
- if (strpos($role, 'simpletest') !== FALSE) {
+ if (preg_match('/s\d+/', $role)) {
return $rid;
}
}