Index: modules/upload/upload.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/upload/upload.test,v
retrieving revision 1.7
diff -u -p -r1.7 upload.test
--- modules/upload/upload.test	13 Oct 2008 12:43:30 -0000	1.7
+++ modules/upload/upload.test	17 Oct 2008 09:50:12 -0000
@@ -51,6 +51,10 @@ class UploadTestCase extends DrupalWebTe
     $this->assertText(basename($files[0]), basename($files[0]) . ' found on node.');
     $this->assertText(basename($files[1]), basename($files[1]) . ' found on node.');
 
+    // Check to see that the admin setting "List files by default:on" works.
+    $this->drupalGet('node/' . $node->nid);
+    $this->assertText(t('Attachment'), 'File listed on page.');
+
     $this->checkUploadedFile(basename($files[0]));
     $this->checkUploadedFile(basename($files[1]));
 
@@ -98,6 +102,7 @@ class UploadTestCase extends DrupalWebTe
     $settings['upload_usersize'] = '1';
     $this->setUploadSettings($settings, $this->getSimpletestRoleId($web_user));
 
+    $this->drupalLogout();
     $this->drupalLogin($web_user);
 
     $node = $this->drupalCreateNode();
@@ -121,11 +126,12 @@ class UploadTestCase extends DrupalWebTe
     $this->assertNoRaw(t('The specified file %name could not be uploaded.', array('%name' => basename($html_file))), t('File '. $html_file . ' was allowed to be uploaded'));
   }
 
+
   /**
    * Attempt to upload a file that is larger than the maxsize and see that it fails.
    */
-  function testLimit() {
-    $files = $this->drupalGetTestFiles('text', 1310720); // 1 MB.
+  function testFileSizeLimit() {
+    $files = $this->drupalGetTestFiles('text', 1310720); // > 1 MB.
     $file = current($files)->filename;
 
     $admin_user = $this->drupalCreateUser(array('administer site configuration'));
@@ -141,6 +147,7 @@ class UploadTestCase extends DrupalWebTe
     $settings['upload_usersize'] = '1.5';
     $this->setUploadSettings($settings, $this->getSimpletestRoleId($web_user));
 
+    $this->drupalLogout();
     $this->drupalLogin($web_user);
 
     $node = $this->drupalCreateNode();
@@ -158,6 +165,102 @@ class UploadTestCase extends DrupalWebTe
     $this->assertRaw(t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => $filesize, '%maxsize' => $maxsize)), t('File size cited as problem with upload'));
   }
 
+  /**
+   * Check to see that the admin setting "List files by default:off" works.
+   */
+  function testUploadSettingsListFiles() {
+    global $base_url;
+    $admin_user = $this->drupalCreateUser(array('administer site configuration'));
+    $web_user = $this->drupalCreateUser(array('access content', 'edit any page content', 'upload files', 'view uploaded files'));
+
+    $this->drupalLogin($admin_user);
+
+    // Setup upload settings.
+    $edit = array();
+    $edit['upload_list_default'] = '0'; // No.
+    $this->drupalPost('admin/settings/uploads', $edit, t('Save configuration'));
+    $this->assertText('The configuration options have been saved.', 'Upload setting saved.');
+
+    $this->drupalLogout();
+    $this->drupalLogin($web_user);
+
+    // Create a node and attempt to attach files.
+    $node = $this->drupalCreateNode();
+    $text_files = $this->drupalGetTestFiles('text');
+    $files = array(current($text_files)->filename, next($text_files)->filename);
+
+    $this->uploadFile($node, $files[0]);
+
+    $this->drupalGet('node/' . $node->nid);
+    $this->assertNoText(t('Attachment'), 'File listed on page.');
+  }
+
+  /*
+   * Test uploadsize > usersize in admin settings page.
+   */
+  function testUploadSettings() {
+    $admin_user = $this->drupalCreateUser(array('administer site configuration'));
+    $web_user = $this->drupalCreateUser(array('access content', 'edit any page content', 'upload files', 'view uploaded files'));
+
+    $this->drupalLogin($admin_user);
+
+    $rid = $this->getSimpletestRoleId($web_user);
+    $settings = array();
+    $settings['upload_list'] = '1'; // Yes.
+    $settings['upload_extensions'] = 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp';
+    $settings['upload_uploadsize'] = '2';
+    $settings['upload_usersize'] = '1';
+    $edit = array();
+    foreach ($settings as $key => $value) {
+      $edit[$key . '_default'] = $value;
+      if ($rid !== NULL && $key != 'upload_list' && $key != 'upload_max_resolution') {
+        $edit[$key . '_' . $rid] = $value;
+      }
+    }
+    $this->drupalPost('admin/settings/uploads', $edit, 'Save configuration');
+    $this->assertText('The default maximum file size per upload is greater than the total file size allowed per user', 'Upload setting warning.');
+  }
+
+  /**
+   * Attempt to upload a file that is larger than the maxsize and see that it fails.
+   */
+  function testUserLimit() {
+    $files = $this->drupalGetTestFiles('text', 1310720); // > 1 MB.
+    $file = current($files)->filename;
+
+    $admin_user = $this->drupalCreateUser(array('administer site configuration'));
+    $web_user = $this->drupalCreateUser(array('access content', 'edit any page content', 'upload files', 'view uploaded files'));
+
+    $this->drupalLogin($admin_user);
+
+    // Setup upload settings.
+    $settings = array();
+    $settings['upload_list'] = '1'; // Yes.
+    $settings['upload_extensions'] = 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp';
+    $settings['upload_uploadsize'] = '1.5';
+    $settings['upload_usersize'] = '1.5';
+    $this->setUploadSettings($settings, $this->getSimpletestRoleId($web_user));
+
+    $this->drupalLogout();
+    $this->drupalLogin($web_user);
+
+    $node = $this->drupalCreateNode();
+
+    // Attempt to upload 2 files of 1 MB each where the user limit is 1.5 MB
+    $this->uploadFile($node, $file, FALSE);
+    $node = $this->drupalCreateNode();
+    $this->uploadFile($node, $file, FALSE);
+
+    $info = stat($file);
+    $filename = basename($file);
+    $filesize = $info['size'];
+    $max_usersize = $settings['upload_usersize'] * 1024 * 1024;
+    // Test the error message in two steps in case there are additional errors
+    // that change the error message's format.
+    $this->assertRaw(t('The specified file %name could not be uploaded.', array('%name' => $filename)), t('File upload was blocked'));
+    $this->assertRaw(t('The file is %filesize which would exceed your disk quota of %quota.', array('%filesize' => format_size($filesize), '%quota' => format_size($max_usersize))), t('User quota cited as problem with upload'));
+  }
+
   function setUploadSettings($settings, $rid = NULL) {
     $edit = array();
     foreach ($settings as $key => $value) {
@@ -167,7 +270,7 @@ class UploadTestCase extends DrupalWebTe
       }
     }
     $this->drupalPost('admin/settings/uploads', $edit, 'Save configuration');
-    $this->assertText('The configuration options have been saved.', 'Upload setting saved.');
+    $this->assertText(t('The configuration options have been saved.'), 'Upload setting saved.');
   }
 
   /**
