- Patch #295864 by boombatower: cleaned up the randomName() method by removing unnecessary prefix code, and added a new randomString() method which includes characters like spaces.
							parent
							
								
									7bf8e72aaa
								
							
						
					
					
						commit
						e721147363
					
				| 
						 | 
				
			
			@ -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,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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.'));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,24 +641,44 @@ 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 str_replace('simpletest', 's', $db_prefix) . $str;
 | 
			
		||||
  }
 | 
			
		||||
    return $prefix;
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 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;
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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'));
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,
 | 
			
		||||
    );
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue