diff --git a/modules/simpletest/tests/file.test b/modules/simpletest/tests/file.test index 3633bae..f0a250e 100644 --- a/modules/simpletest/tests/file.test +++ b/modules/simpletest/tests/file.test @@ -610,7 +610,7 @@ class FileSaveUploadTest extends FileHookTestCase { 'files[file_test_upload]' => drupal_realpath($this->image->uri), ); $this->drupalPost('file-test/upload', $edit, t('Submit')); - $this->assertResponse(200, t('Received a 200 response for posted test file.')); + $this->assertResponse(200, t('Received a 200 response for posted test file (first).')); $this->assertRaw(t('You WIN!'), t('Found the success message.')); // Check that the correct hooks were called then clean out the hook @@ -638,7 +638,7 @@ class FileSaveUploadTest extends FileHookTestCase { $image2 = current($this->drupalGetTestFiles('image')); $edit = array('files[file_test_upload]' => drupal_realpath($image2->uri)); $this->drupalPost('file-test/upload', $edit, t('Submit')); - $this->assertResponse(200, t('Received a 200 response for posted test file.')); + $this->assertResponse(200, t('Received a 200 response for posted test file (second).')); $this->assertRaw(t('You WIN!')); $max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField(); @@ -652,8 +652,8 @@ class FileSaveUploadTest extends FileHookTestCase { // Load both files using file_load_multiple(). $files = file_load_multiple(array($file1->fid, $file2->fid)); - $this->assertTrue(isset($files[$file1->fid]), t('File was loaded successfully')); - $this->assertTrue(isset($files[$file2->fid]), t('File was loaded successfully')); + $this->assertTrue(isset($files[$file1->fid]), t('File was loaded successfully (first).')); + $this->assertTrue(isset($files[$file2->fid]), t('File was loaded successfully (second).')); // Upload a third file to a subdirectory. $image3 = current($this->drupalGetTestFiles('image')); @@ -664,10 +664,30 @@ class FileSaveUploadTest extends FileHookTestCase { 'file_subdir' => $dir, ); $this->drupalPost('file-test/upload', $edit, t('Submit')); - $this->assertResponse(200, t('Received a 200 response for posted test file.')); + $this->assertResponse(200, t('Received a 200 response for posted test file (subdirectory).')); $this->assertRaw(t('You WIN!')); $this->assertTrue(is_file('temporary://' . $dir . '/' . trim(basename($image3_realpath)))); + // Upload a fourth file to test open_basedir support. + $image4 = current($this->drupalGetTestFiles('image')); + $image4_realpath = drupal_realpath($image4->uri); + // The open_basedir directive needs to include the DRUPAL_ROOT, upload file, + // temporary and destination directories. + $open_basedir = DRUPAL_ROOT . ':' . dirname($image4_realpath) . ':' . drupal_realpath(file_directory_temp()) . ':' . drupal_realpath('public://'); + if (strpos(DRUPAL_ROOT, ':') !== FALSE) { + // For Windows, use semi-colon delimiter; + $open_basedir = DRUPAL_ROOT . ';' . dirname($image4_realpath) . ';' . drupal_realpath(file_directory_temp()) . ';' . drupal_realpath('public://'); + } + // There's no point performing these tests unless open_basedir can be set by + // PHP (PHP >= 5.3). + if (ini_set('open_basedir', $open_basedir) != FALSE) { + $edit = array('files[file_test_upload]' => $image4_realpath); + $this->drupalPost('file-test/upload', $edit, t('Submit')); + $this->assertResponse(200, t('Received a 200 response for posted test file (open_basedir).')); + $this->assertRaw(t('You WIN!')); + ini_restore('open_basedir'); + } + // Check that file_load_multiple() with no arguments returns FALSE. $this->assertFalse(file_load_multiple(), t('No files were loaded.')); }