? simpletest
? simpletest_drupal5.patch
Index: tests/upload_tests.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/tests/upload_tests.test,v
retrieving revision 1.9
diff -u -r1.9 upload_tests.test
--- tests/upload_tests.test	24 Jun 2007 08:05:07 -0000	1.9
+++ tests/upload_tests.test	24 Jun 2007 13:27:49 -0000
@@ -58,25 +58,9 @@
   }
 
   /**
-   * Logs in a user with the internal browser
-   *
-   * @param object user object with pass_raw property!
-   */
-  function _loginUser($user) {
-    $this->drupalGet( url("user", NULL, NULL, TRUE) );
-    // Going to the page retrieves the cookie, as the browser should save it
-    
-    $edit = array('name' => $user->name, 'pass' => $user->pass_raw);
-    $this->drupalPostRequest('user', $edit, 'Log in');
-    
-    $this->assertText($user->name, ' [login] found name: ' . $user->name);
-    $this->assertNoText(t('The username %name has been blocked.', array('%name' => $user->name)), ' [login] not blocked');
-    $this->assertNoText(t('The name %name is a reserved username.', array('%name' => $user->name)), ' [login] not reserved');
-
-  }
-
-  /**
    * Implementation of tearDown, cleaning up created users/roles in db
+   * TODO Place this tearDown globally in drupal_test_case.php and 
+   * and jst called parent::tearDown()
    */
   function tearDown() {
     while (sizeof($this->_cleanup_roles) > 0) {
@@ -120,13 +104,15 @@
     variable_set('user_pictures', 1);
 
     /* Prepare a user to do the stuff */
-    $user = $this->_createUserRolePerm(array('access content'));
-    $this->_loginUser($user);
+    // create and login a new user
+    $perm = array('access content');
+    $account = $this->drupalCreateUserRolePerm($perm);
+    $this->drupalLoginUser($account);
 
     // not a image
     $img_path = realpath(drupal_get_path('module', 'simpletest'). "/tests/upload_tests.test");
     $edit = array('files[picture_upload]' => $img_path);
-    $this->drupalPostRequest('user/'.$user->uid.'/edit', $edit, 'Submit' );
+    $this->drupalPostRequest('user/'.$account->uid.'/edit', $edit, 'Submit' );
     $this->assertWantedText(t('The uploaded file was not an image.'), 'The uploaded file was not an image.');
      variable_set('user_pictures', $old_pic_set);
 
@@ -155,8 +141,10 @@
         variable_set('user_pictures', 1);
 
         /* Prepare a user to do the stuff */
-        $user = $this->_createUserRolePerm(array('access content'));
-        $this->_loginUser($user);
+        // create and login a new user
+        $perm = array('access content');
+        $account = $this->drupalCreateUserRolePerm($perm);
+        $this->drupalLoginUser($account);
 
         // changing actual setting;
         $old_dim = variable_get('user_picture_dimensions', '85x85');
@@ -172,10 +160,10 @@
 
         // TEST:
         $edit = array('picture' => $img_path);
-        $this->drupalPostRequest('user/'.$user->uid.'/edit', $edit, 'Submit' );
+        $this->drupalPostRequest('user/'.$account->uid.'/edit', $edit, 'Submit' );
         $file_dir = variable_get('file_directory_path', 'files');
         $picture_dir = variable_get('user_picture_path', 'pictures');
-        $pic_path = $file_dir .'/'.$picture_dir .'/picture-'.$user->uid.'.jpg';
+        $pic_path = $file_dir .'/'.$picture_dir .'/picture-'.$account->uid.'.jpg';
 
         // get full url to the user's image
         $picture = file_create_url($pic_path);
@@ -212,8 +200,10 @@
         variable_set('user_pictures', 1);
 
         /* Prepare a user to do the stuff */
-        $user = $this->_createUserRolePerm(array('access content'));
-        $this->_loginUser($user);
+        // create and login a new user
+        $perm = array('access content');
+        $account = $this->drupalCreateUserRolePerm($perm);
+        $this->drupalLoginUser($account);
 
         // changing actual setting;
         $old_dim = variable_get('user_picture_dimensions', '85x85');
@@ -229,10 +219,10 @@
 
         // TEST:
         $edit = array('picture' => $img_path);
-        $this->drupalPostRequest('user/'.$user->uid.'/edit', $edit, 'Submit' );
+        $this->drupalPostRequest('user/'.$account->uid.'/edit', $edit, 'Submit' );
         $file_dir = variable_get('file_directory_path', 'files');
         $picture_dir = variable_get('user_picture_path', 'pictures');
-        $pic_path = $file_dir .'/'.$picture_dir .'/picture-'.$user->uid.'.jpg';
+        $pic_path = $file_dir .'/'.$picture_dir .'/picture-'.$account->uid.'.jpg';
 
         // get full url to the user's image
         $picture = file_create_url($pic_path);
@@ -268,8 +258,10 @@
         variable_set('user_pictures', 1);
 
         /* Prepare a user to do the stuff */
-        $user = $this->_createUserRolePerm(array('access content'));
-        $this->_loginUser($user);
+        // create and login a new user
+        $perm = array('access content');
+        $account = $this->drupalCreateUserRolePerm($perm);
+        $this->drupalLoginUser($account);
 
         // changing actual setting;
         $old_dim = variable_get('user_picture_dimensions', '85x85');
@@ -284,14 +276,14 @@
 
         // TEST:
         $edit = array('picture' => $img_path);
-        $this->drupalPostRequest('user/'.$user->uid.'/edit', $edit, 'Submit' );
+        $this->drupalPostRequest('user/'.$account->uid.'/edit', $edit, 'Submit' );
         $text = t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85')));
         $this->assertWantedText($text, 'Checking response on invalid image (dimensions).');
 
         // check if file is not uploaded
         $file_dir = variable_get('file_directory_path', 'files');
         $picture_dir = variable_get('user_picture_path', 'pictures');
-        $pic_path = $file_dir .'/'.$picture_dir .'/picture-'.$user->uid.'.jpg';
+        $pic_path = $file_dir .'/'.$picture_dir .'/picture-'.$account->uid.'.jpg';
         $this->assertFalse(is_file($pic_path), "File is not uploaded");
 
         // restore variables;
@@ -317,8 +309,10 @@
         variable_set('user_pictures', 1);
 
         /* Prepare a user to do the stuff */
-        $user = $this->_createUserRolePerm(array('access content'));
-        $this->_loginUser($user);
+        // create and login a new user
+        $perm = array('access content');
+        $account = $this->drupalCreateUserRolePerm($perm);
+        $this->drupalLoginUser($account);
 
         // changing actual setting;
         $old_dim = variable_get('user_picture_dimensions', '85x85');
@@ -333,14 +327,14 @@
         variable_set('user_picture_file_size', $test_size);
 
         $edit = array('picture' => $img_path);
-        $this->drupalPostRequest('user/'.$user->uid.'/edit', $edit, 'Submit' );
+        $this->drupalPostRequest('user/'.$account->uid.'/edit', $edit, 'Submit' );
         $text = t('The uploaded image is too large; the maximum file size is %size kB.', array('%size' => variable_get('user_picture_file_size', '30')));
         $this->assertWantedText($text, 'Checking response on invalid image size.');
 
         // check if file is not uploaded
         $file_dir = variable_get('file_directory_path', 'files');
         $picture_dir = variable_get('user_picture_path', 'pictures');
-        $pic_path = $file_dir .'/'.$picture_dir .'/picture-'.$user->uid.'.jpg';
+        $pic_path = $file_dir .'/'.$picture_dir .'/picture-'.$account->uid.'.jpg';
         $this->assertFalse(is_file($pic_path), "File is not uploaded");
         // restore variables;
         variable_set('user_picture_file_size', $old_size);
@@ -365,8 +359,10 @@
       variable_set('user_pictures', 1);
 
       /* Prepare a user to do the stuff */
-      $user = $this->_createUserRolePerm(array('access content'));
-      $this->_loginUser($user);
+      // create and login a new user
+      $perm = array('access content');
+      $account = $this->drupalCreateUserRolePerm($perm);
+      $this->drupalLoginUser($account);
 
       // changing actual setting;
       $old_dim = variable_get('user_picture_dimensions', '85x85');
@@ -384,9 +380,9 @@
 
       // TEST:
       $edit = array('files[picture_upload]' => $img_path);
-      $this->drupalPostRequest('user/'.$user->uid.'/edit', $edit, 'Submit' );
+      $this->drupalPostRequest('user/'.$account->uid.'/edit', $edit, 'Submit' );
       $picture_dir = variable_get('user_picture_path', 'pictures');
-      $pic_path = file_directory_path() .'/'.$picture_dir .'/picture-'.$user->uid.'.jpg';
+      $pic_path = file_directory_path() .'/'.$picture_dir .'/picture-'.$account->uid.'.jpg';
 
       // get full url to the user's image
       $picture = file_create_url($pic_path);
