diff options
Diffstat (limited to 'modules/simpletest/tests')
-rw-r--r-- | modules/simpletest/tests/common.test | 3 | ||||
-rw-r--r-- | modules/simpletest/tests/error.test | 10 | ||||
-rw-r--r-- | modules/simpletest/tests/file.test | 379 | ||||
-rw-r--r-- | modules/simpletest/tests/file_test.module | 2 | ||||
-rw-r--r-- | modules/simpletest/tests/filetransfer.test | 2 | ||||
-rw-r--r-- | modules/simpletest/tests/image.test | 2 | ||||
-rw-r--r-- | modules/simpletest/tests/session.test | 2 |
7 files changed, 179 insertions, 221 deletions
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index cdd10f5ea..c302a727a 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -403,8 +403,9 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase { drupal_get_path('module', 'simpletest') . '/simpletest.css', ); + $styles = drupal_get_css(); - if (preg_match_all('/href="' . preg_quote(base_path(), '/') . '([^?]+)\?/', $styles, $matches)) { + if (preg_match_all('/href="' . preg_quote($GLOBALS['base_url'] . '/', '/') . '([^?]+)\?/', $styles, $matches)) { $result = $matches[1]; } else { diff --git a/modules/simpletest/tests/error.test b/modules/simpletest/tests/error.test index 28d6e0830..fe4ee4526 100644 --- a/modules/simpletest/tests/error.test +++ b/modules/simpletest/tests/error.test @@ -26,21 +26,21 @@ class DrupalErrorHandlerUnitTest extends DrupalWebTestCase { '%message' => 'Undefined variable: bananas', '%function' => 'error_test_generate_warnings()', '%line' => 44, - '%file' => realpath('modules/simpletest/tests/error_test.module'), + '%file' => drupal_realpath('modules/simpletest/tests/error_test.module'), ); $error_warning = array( '%type' => 'Warning', '%message' => 'Division by zero', '%function' => 'error_test_generate_warnings()', '%line' => 46, - '%file' => realpath('modules/simpletest/tests/error_test.module'), + '%file' => drupal_realpath('modules/simpletest/tests/error_test.module'), ); $error_user_notice = array( '%type' => 'User warning', '%message' => 'Drupal is awesome', '%function' => 'error_test_generate_warnings()', '%line' => 48, - '%file' => realpath('modules/simpletest/tests/error_test.module'), + '%file' => drupal_realpath('modules/simpletest/tests/error_test.module'), ); // Set error reporting to collect notices. @@ -77,14 +77,14 @@ class DrupalErrorHandlerUnitTest extends DrupalWebTestCase { '%message' => 'Drupal is awesome', '%function' => 'error_test_trigger_exception()', '%line' => 57, - '%file' => realpath('modules/simpletest/tests/error_test.module'), + '%file' => drupal_realpath('modules/simpletest/tests/error_test.module'), ); $error_pdo_exception = array( '%type' => 'PDOException', '%message' => 'SELECT * FROM bananas_are_awesome', '%function' => 'error_test_trigger_pdo_exception()', '%line' => 65, - '%file' => realpath('modules/simpletest/tests/error_test.module'), + '%file' => drupal_realpath('modules/simpletest/tests/error_test.module'), ); $this->drupalGet('error-test/trigger-exception'); diff --git a/modules/simpletest/tests/file.test b/modules/simpletest/tests/file.test index 23c1d1241..26bb05154 100644 --- a/modules/simpletest/tests/file.test +++ b/modules/simpletest/tests/file.test @@ -61,7 +61,7 @@ class FileTestCase extends DrupalWebTestCase { $this->assertEqual($before->fid, $after->fid, t('File id is the same: %file1 == %file2.', array('%file1' => $before->fid, '%file2' => $after->fid)), 'File unchanged'); $this->assertEqual($before->uid, $after->uid, t('File owner is the same: %file1 == %file2.', array('%file1' => $before->uid, '%file2' => $after->uid)), 'File unchanged'); $this->assertEqual($before->filename, $after->filename, t('File name is the same: %file1 == %file2.', array('%file1' => $before->filename, '%file2' => $after->filename)), 'File unchanged'); - $this->assertEqual($before->filepath, $after->filepath, t('File path is the same: %file1 == %file2.', array('%file1' => $before->filepath, '%file2' => $after->filepath)), 'File unchanged'); + $this->assertEqual($before->uri, $after->uri, t('File path is the same: %file1 == %file2.', array('%file1' => $before->uri, '%file2' => $after->uri)), 'File unchanged'); $this->assertEqual($before->filemime, $after->filemime, t('File MIME type is the same: %file1 == %file2.', array('%file1' => $before->filemime, '%file2' => $after->filemime)), 'File unchanged'); $this->assertEqual($before->filesize, $after->filesize, t('File size is the same: %file1 == %file2.', array('%file1' => $before->filesize, '%file2' => $after->filesize)), 'File unchanged'); $this->assertEqual($before->status, $after->status, t('File status is the same: %file1 == %file2.', array('%file1' => $before->status, '%file2' => $after->status)), 'File unchanged'); @@ -77,7 +77,7 @@ class FileTestCase extends DrupalWebTestCase { */ function assertDifferentFile($file1, $file2) { $this->assertNotEqual($file1->fid, $file2->fid, t('Files have different ids: %file1 != %file2.', array('%file1' => $file1->fid, '%file2' => $file2->fid)), 'Different file'); - $this->assertNotEqual($file1->filepath, $file2->filepath, t('Files have different paths: %file1 != %file2.', array('%file1' => $file1->filepath, '%file2' => $file2->filepath)), 'Different file'); + $this->assertNotEqual($file1->uri, $file2->uri, t('Files have different paths: %file1 != %file2.', array('%file1' => $file1->uri, '%file2' => $file2->uri)), 'Different file'); } /** @@ -90,7 +90,7 @@ class FileTestCase extends DrupalWebTestCase { */ function assertSameFile($file1, $file2) { $this->assertEqual($file1->fid, $file2->fid, t('Files have the same ids: %file1 == %file2.', array('%file1' => $file1->fid, '%file2-fid' => $file2->fid)), 'Same file'); - $this->assertEqual($file1->filepath, $file2->filepath, t('Files have the same path: %file1 == %file2.', array('%file1' => $file1->filepath, '%file2' => $file2->filepath)), 'Same file'); + $this->assertEqual($file1->uri, $file2->uri, t('Files have the same path: %file1 == %file2.', array('%file1' => $file1->uri, '%file2' => $file2->uri)), 'Same file'); } /** @@ -151,7 +151,7 @@ class FileTestCase extends DrupalWebTestCase { if (is_null($path)) { $path = file_directory_path() . '/' . $this->randomName(); } - $this->assertTrue(mkdir($path) && is_dir($path), t('Directory was created successfully.')); + $this->assertTrue(drupal_mkdir($path) && is_dir($path), t('Directory was created successfully.')); return $path; } @@ -165,13 +165,17 @@ class FileTestCase extends DrupalWebTestCase { * @param $contents * Optional contents to save into the file. If a NULL value is provided an * arbitrary string will be used. + * @param $scheme + * Optional string indicating the stream scheme to use. Drupal core includes + * public, private, and temporary. The public wrapper is the default. * @return * File object. */ - function createFile($filepath = NULL, $contents = NULL) { + function createFile($filepath = NULL, $contents = NULL, $scheme = 'public') { if (is_null($filepath)) { - $filepath = file_directory_path() . '/' . $this->randomName(); + $filepath = $this->randomName(); } + $filepath = $scheme . '://' . $filepath; if (is_null($contents)) { $contents = "file_put_contents() doesn't seem to appreciate empty strings so let's put in some data."; @@ -181,16 +185,16 @@ class FileTestCase extends DrupalWebTestCase { $this->assertTrue(is_file($filepath), t('The test file exists on the disk.'), 'Create test file'); $file = new stdClass(); - $file->filepath = $filepath; - $file->filename = basename($file->filepath); + $file->uri = $filepath; + $file->filename = basename($file->uri); $file->filemime = 'text/plain'; $file->uid = 1; $file->timestamp = REQUEST_TIME; - $file->filesize = filesize($file->filepath); + $file->filesize = filesize($file->uri); $file->status = 0; // Write the record directly rather than calling file_save() so we don't // invoke the hooks. - $this->assertNotIdentical(drupal_write_record('files', $file), FALSE, t('The file was added to the database.'), 'Create test file'); + $this->assertNotIdentical(drupal_write_record('file', $file), FALSE, t('The file was added to the database.'), 'Create test file'); return $file; } @@ -284,16 +288,16 @@ class FileSpaceUsedTest extends FileTestCase { parent::setUp(); // Create records for a couple of users with different sizes. - drupal_write_record('files', $file = array('uid' => 2, 'filesize' => 50, 'status' => FILE_STATUS_PERMANENT)); - drupal_write_record('files', $file = array('uid' => 2, 'filesize' => 20, 'status' => FILE_STATUS_PERMANENT)); - drupal_write_record('files', $file = array('uid' => 3, 'filesize' => 100, 'status' => FILE_STATUS_PERMANENT)); - drupal_write_record('files', $file = array('uid' => 3, 'filesize' => 200, 'status' => FILE_STATUS_PERMANENT)); + drupal_write_record('file', $file = array('uid' => 2, 'uri' => 'public://example1.txt', 'filesize' => 50, 'status' => FILE_STATUS_PERMANENT)); + drupal_write_record('file', $file = array('uid' => 2, 'uri' => 'public://example2.txt', 'filesize' => 20, 'status' => FILE_STATUS_PERMANENT)); + drupal_write_record('file', $file = array('uid' => 3, 'uri' => 'public://example3.txt', 'filesize' => 100, 'status' => FILE_STATUS_PERMANENT)); + drupal_write_record('file', $file = array('uid' => 3, 'uri' => 'public://example4.txt', 'filesize' => 200, 'status' => FILE_STATUS_PERMANENT)); // Now create some with other statuses. These values were chosen arbitrarily // for the sole purpose of testing that bitwise operators were used // correctly on the field. - drupal_write_record('files', $file = array('uid' => 2, 'filesize' => 1, 'status' => 2 | 8)); - drupal_write_record('files', $file = array('uid' => 3, 'filesize' => 3, 'status' => 2 | 4)); + drupal_write_record('file', $file = array('uid' => 2, 'uri' => 'public://example5.txt', 'filesize' => 1, 'status' => 2 | 8)); + drupal_write_record('file', $file = array('uid' => 3, 'uri' => 'public://example6.txt', 'filesize' => 3, 'status' => 2 | 4)); } /** @@ -344,12 +348,12 @@ class FileValidatorTest extends DrupalWebTestCase { parent::setUp(); $this->image = new stdClass(); - $this->image->filepath = 'misc/druplicon.png'; - $this->image->filename = basename($this->image->filepath); + $this->image->uri = 'misc/druplicon.png'; + $this->image->filename = basename($this->image->uri); $this->non_image = new stdClass(); - $this->non_image->filepath = 'misc/jquery.js'; - $this->non_image->filename = basename($this->non_image->filepath); + $this->non_image->uri = 'misc/jquery.js'; + $this->non_image->filename = basename($this->non_image->uri); } /** @@ -370,11 +374,11 @@ class FileValidatorTest extends DrupalWebTestCase { * This ensures a specific file is actually an image. */ function testFileValidateIsImage() { - $this->assertTrue(file_exists($this->image->filepath), t('The image being tested exists.'), 'File'); + $this->assertTrue(file_exists($this->image->uri), t('The image being tested exists.'), 'File'); $errors = file_validate_is_image($this->image); $this->assertEqual(count($errors), 0, t('No error reported for our image file.'), 'File'); - $this->assertTrue(file_exists($this->non_image->filepath), t('The non-image being tested exists.'), 'File'); + $this->assertTrue(file_exists($this->non_image->uri), t('The non-image being tested exists.'), 'File'); $errors = file_validate_is_image($this->non_image); $this->assertEqual(count($errors), 1, t('An error reported for our non-image file.'), 'File'); } @@ -403,18 +407,18 @@ class FileValidatorTest extends DrupalWebTestCase { // Maximum size. if (image_get_toolkit()) { // Copy the image so that the original doesn't get resized. - $temp_dir = file_directory_temp(); - copy(realpath('misc/druplicon.png'), realpath($temp_dir) . '/druplicon.png'); - $this->image->filepath = $temp_dir . '/druplicon.png'; + $temp_dir = file_directory_path('temporary'); + copy(drupal_realpath('misc/druplicon.png'), drupal_realpath($temp_dir) . '/druplicon.png'); + $this->image->uri = $temp_dir . '/druplicon.png'; $errors = file_validate_image_resolution($this->image, '10x5'); $this->assertEqual(count($errors), 0, t('No errors should be reported when an oversized image can be scaled down.'), 'File'); - $info = image_get_info($this->image->filepath); + $info = image_get_info($this->image->uri); $this->assertTrue($info['width'] <= 10, t('Image scaled to correct width.'), 'File'); $this->assertTrue($info['height'] <= 5, t('Image scaled to correct height.'), 'File'); - unlink(realpath($temp_dir . '/druplicon.png')); + unlink(drupal_realpath($temp_dir . '/druplicon.png')); } else { // TODO: should check that the error is returned if no toolkit is available. @@ -431,15 +435,15 @@ class FileValidatorTest extends DrupalWebTestCase { $file = new stdClass(); // Add a filename with an allowed length and test it. - $file->filename = str_repeat('x', 255); - $this->assertEqual(strlen($file->filename), 255); + $file->filename = str_repeat('x', 240); + $this->assertEqual(strlen($file->filename), 240); $errors = file_validate_name_length($file); - $this->assertEqual(count($errors), 0, t('No errors reported for 255 length filename.'), 'File'); + $this->assertEqual(count($errors), 0, t('No errors reported for 240 length filename.'), 'File'); // Add a filename with a length too long and test it. - $file->filename = str_repeat('x', 256); + $file->filename = str_repeat('x', 241); $errors = file_validate_name_length($file); - $this->assertEqual(count($errors), 1, t('An error reported for 256 length filename.'), 'File'); + $this->assertEqual(count($errors), 1, t('An error reported for 241 length filename.'), 'File'); // Add a filename with an empty string and test it. $file->filename = ''; @@ -507,15 +511,15 @@ class FileUnmanagedSaveDataTest extends FileTestCase { // No filename. $filepath = file_unmanaged_save_data($contents); $this->assertTrue($filepath, t('Unnamed file saved correctly.')); - $this->assertEqual(file_directory_path(), dirname($filepath), t("File was placed in Drupal's files directory.")); - $this->assertEqual($contents, file_get_contents(realpath($filepath)), t('Contents of the file are correct.')); + $this->assertEqual(file_directory_path('public'), file_directory_path(file_stream_wrapper_valid_scheme($filepath)), t("File was placed in Drupal's files directory.")); + $this->assertEqual($contents, file_get_contents(drupal_realpath($filepath)), t('Contents of the file are correct.')); // Provide a filename. - $filepath = file_unmanaged_save_data($contents, 'asdf.txt', FILE_EXISTS_REPLACE); + $filepath = file_unmanaged_save_data($contents, 'public://asdf.txt', FILE_EXISTS_REPLACE); $this->assertTrue($filepath, t('Unnamed file saved correctly.')); - $this->assertEqual(file_directory_path(), dirname($filepath), t("File was placed in Drupal's files directory.")); + $this->assertEqual(file_directory_path('public'), file_directory_path(file_uri_scheme($filepath)), t("File was placed in Drupal's files directory.")); $this->assertEqual('asdf.txt', basename($filepath), t('File was named correctly.')); - $this->assertEqual($contents, file_get_contents(realpath($filepath)), t('Contents of the file are correct.')); + $this->assertEqual($contents, file_get_contents(drupal_realpath($filepath)), t('Contents of the file are correct.')); $this->assertFilePermissions($filepath, variable_get('file_chmod_file', 0664)); } } @@ -548,14 +552,14 @@ class FileSaveUploadTest extends FileHookTestCase { $this->drupalLogin($account); $this->image = current($this->drupalGetTestFiles('image')); - $this->assertTrue(is_file($this->image->filepath), t("The file we're going to upload exists.")); + $this->assertTrue(is_file($this->image->uri), t("The file we're going to upload exists.")); - $this->maxFidBefore = db_query('SELECT MAX(fid) AS fid FROM {files}')->fetchField(); + $this->maxFidBefore = db_query('SELECT MAX(fid) AS fid FROM {file}')->fetchField(); // Upload with replace to gurantee there's something there. $edit = array( 'file_test_replace' => FILE_EXISTS_REPLACE, - 'files[file_test_upload]' => realpath($this->image->filepath) + '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.')); @@ -571,7 +575,7 @@ class FileSaveUploadTest extends FileHookTestCase { * Test the file_save_upload() function. */ function testNormal() { - $max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {files}')->fetchField(); + $max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file}')->fetchField(); $this->assertTrue($max_fid_after > $this->maxFidBefore, t('A new file was created.')); $file1 = file_load($max_fid_after); $this->assertTrue($file1, t('Loaded the file.')); @@ -580,13 +584,13 @@ class FileSaveUploadTest extends FileHookTestCase { file_test_reset(); // Upload a second file. - $max_fid_before = db_query('SELECT MAX(fid) AS fid FROM {files}')->fetchField(); + $max_fid_before = db_query('SELECT MAX(fid) AS fid FROM {file}')->fetchField(); $image2 = current($this->drupalGetTestFiles('image')); - $edit = array('files[file_test_upload]' => realpath($image2->filepath)); + $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->assertRaw(t('You WIN!')); - $max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {files}')->fetchField(); + $max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file}')->fetchField(); // Check that the correct hooks were called. $this->assertFileHooksCalled(array('validate', 'insert')); @@ -610,7 +614,7 @@ class FileSaveUploadTest extends FileHookTestCase { function testExistingRename() { $edit = array( 'file_test_replace' => FILE_EXISTS_RENAME, - 'files[file_test_upload]' => realpath($this->image->filepath) + '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.')); @@ -626,7 +630,7 @@ class FileSaveUploadTest extends FileHookTestCase { function testExistingReplace() { $edit = array( 'file_test_replace' => FILE_EXISTS_REPLACE, - 'files[file_test_upload]' => realpath($this->image->filepath) + '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.')); @@ -642,7 +646,7 @@ class FileSaveUploadTest extends FileHookTestCase { function testExistingError() { $edit = array( 'file_test_replace' => FILE_EXISTS_ERROR, - 'files[file_test_upload]' => realpath($this->image->filepath) + '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.')); @@ -682,95 +686,55 @@ class FileDirectoryTest extends FileTestCase { $this->assertFalse(is_dir($directory), t('Directory does not exist prior to testing.')); // Non-existent directory. - $form_element = $this->randomName(); - $this->assertFalse(file_check_directory($directory, 0, $form_element), t('Error reported for non-existing directory.'), 'File'); - - // Check that an error was set for the form element above. - $errors = form_get_errors(); - $this->assertEqual($errors[$form_element], t('The directory %directory does not exist.', array('%directory' => $directory)), t('Properly generated an error for the passed form element.'), 'File'); + $this->assertFalse(file_prepare_directory($directory, 0), t('Error reported for non-existing directory.'), 'File'); // Make a directory. - $this->assertTrue(file_check_directory($directory, FILE_CREATE_DIRECTORY), t('No error reported when creating a new directory.'), 'File'); + $this->assertTrue(file_prepare_directory($directory, FILE_CREATE_DIRECTORY), t('No error reported when creating a new directory.'), 'File'); // Make sure directory actually exists. $this->assertTrue(is_dir($directory), t('Directory actually exists.'), 'File'); // Make directory read only. @chmod($directory, 0444); - $form_element = $this->randomName(); - $this->assertFalse(file_check_directory($directory, 0, $form_element), t('Error reported for a non-writeable directory.'), 'File'); - - // Check if form error was set. - $errors = form_get_errors(); - $this->assertEqual($errors[$form_element], t('The directory %directory is not writable', array('%directory' => $directory)), t('Properly generated an error for the passed form element.'), 'File'); + $this->assertFalse(file_prepare_directory($directory, 0), t('Error reported for a non-writeable directory.'), 'File'); // Test directory permission modification. - $this->assertTrue(file_check_directory($directory, FILE_MODIFY_PERMISSIONS), t('No error reported when making directory writeable.'), 'File'); + $this->assertTrue(file_prepare_directory($directory, FILE_MODIFY_PERMISSIONS), t('No error reported when making directory writeable.'), 'File'); // Test directory permission modification actually set correct permissions. $this->assertDirectoryPermissions($directory, variable_get('file_chmod_directory', 0775)); // Remove .htaccess file to then test that it gets re-created. - @unlink(file_directory_path() . '/.htaccess'); $directory = file_directory_path(); - file_check_directory($directory); - $this->assertTrue(is_file(file_directory_path() . '/.htaccess'), t('Successfully created the .htaccess file in the files directory.'), 'File'); - + @unlink($directory . '/.htaccess'); + $this->assertFalse(is_file($directory . '/.htaccess'), t('Successfully removed the .htaccess file in the files directory.'), 'File'); + file_ensure_htaccess(); + $this->assertTrue(is_file($directory . '/.htaccess'), t('Successfully re-created the .htaccess file in the files directory.'), 'File'); // Verify contents of .htaccess file. $file = file_get_contents(file_directory_path() . '/.htaccess'); $this->assertEqual($file, "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006\nOptions None\nOptions +FollowSymLinks", t('The .htaccess file contains the proper content.'), 'File'); } /** - * Check file_directory_path() and file_directory_temp(). + * Check file_directory_path('public'). */ function testFileDirectoryPath() { // Directory path. - $path = variable_get('file_directory_path', conf_path() . '/files'); - $this->assertEqual($path, file_directory_path(), t('Properly returns the stored file directory path.'), 'File'); + $path = variable_get('file_public_path', ''); + $this->assertEqual($path, file_directory_path('public'), t('Properly returns the stored file directory path.'), 'File'); } /** - * Check file_directory_path() and file_directory_temp(). + * Check file_directory_path() and file_directory_path('temporary'). */ function testFileDirectoryTemp() { // Temporary directory handling. variable_set('file_directory_temp', NULL); - $temp = file_directory_temp(); + $temp = file_directory_path('temporary'); $this->assertTrue(!is_null($temp), t('Properly set and retrieved temp directory %directory.', array('%directory' => $temp)), 'File'); } /** - * This tests that a file is actually in the specified directory, to prevent - * exploits. - */ - function testFileCheckLocation() { - $source = 'misc/xyz.txt'; - $directory = 'misc'; - $result = file_check_location($source, $directory); - $this->assertTrue($result, t('Non-existent file validates when checked for location in existing directory.'), 'File'); - - $source = 'fake/xyz.txt'; - $directory = 'fake'; - $result = file_check_location($source, $directory); - $this->assertTrue($result, t('Non-existent file validates when checked for location in non-existing directory.'), 'File'); - - $source = 'misc/../install.php'; - $directory = 'misc'; - $result = file_check_location($source, $directory); - $this->assertFalse($result, t('Existing file fails validation when it exists outside the directory path, using a /../ exploit.'), 'File'); - - $source = 'misc/druplicon.png'; - $directory = 'misc'; - $result = file_check_location($source, $directory); - $this->assertTrue($result, t('Existing file passes validation when checked for location in directory path, and filepath contains a subfolder of the checked path.'), 'File'); - - $result = file_check_location($source, $directory); - $this->assertTrue($result, t('Existing file passes validation, returning the source when checked for location in directory.'), 'File'); - } - - - /** * This will take a directory and path, and find a valid filepath that is not * taken by another file. */ @@ -855,15 +819,15 @@ class FileScanDirectoryTest extends FileTestCase { // Check the first file. $file = reset($all_files); - $this->assertEqual(key($all_files), $file->filepath, t('Correct array key was used for the first returned file.')); - $this->assertEqual($file->filepath, $this->path . '/javascript-1.txt', t('First file name was set correctly.')); + $this->assertEqual(key($all_files), $file->uri, t('Correct array key was used for the first returned file.')); + $this->assertEqual($file->uri, $this->path . '/javascript-1.txt', t('First file name was set correctly.')); $this->assertEqual($file->filename, 'javascript-1.txt', t('First basename was set correctly')); $this->assertEqual($file->name, 'javascript-1', t('First name was set correctly.')); // Check the second file. $file = next($all_files); - $this->assertEqual(key($all_files), $file->filepath, t('Correct array key was used for the second returned file.')); - $this->assertEqual($file->filepath, $this->path . '/javascript-2.script', t('Second file name was set correctly.')); + $this->assertEqual(key($all_files), $file->uri, t('Correct array key was used for the second returned file.')); + $this->assertEqual($file->uri, $this->path . '/javascript-2.script', t('Second file name was set correctly.')); $this->assertEqual($file->filename, 'javascript-2.script', t('Second basename was set correctly')); $this->assertEqual($file->name, 'javascript-2', t('Second name was set correctly.')); } @@ -976,8 +940,8 @@ class FileUnmanagedDeleteTest extends FileTestCase { $file = $this->createFile(); // Delete a regular file - $this->assertTrue(file_unmanaged_delete($file->filepath), t('Deleted worked.')); - $this->assertFalse(file_exists($file->filepath), t('Test file has actually been deleted.')); + $this->assertTrue(file_unmanaged_delete($file->uri), t('Deleted worked.')); + $this->assertFalse(file_exists($file->uri), t('Test file has actually been deleted.')); } /** @@ -1099,16 +1063,16 @@ class FileUnmanagedMoveTest extends FileTestCase { $file = $this->createFile(); // Moving to a new name. - $desired_filepath = file_directory_path() . '/' . $this->randomName(); - $new_filepath = file_unmanaged_move($file->filepath, $desired_filepath, FILE_EXISTS_ERROR); + $desired_filepath = 'public://' . $this->randomName(); + $new_filepath = file_unmanaged_move($file->uri, $desired_filepath, FILE_EXISTS_ERROR); $this->assertTrue($new_filepath, t('Move was successful.')); $this->assertEqual($new_filepath, $desired_filepath, t('Returned expected filepath.')); $this->assertTrue(file_exists($new_filepath), t('File exists at the new location.')); - $this->assertFalse(file_exists($file->filepath), t('No file remains at the old location.')); + $this->assertFalse(file_exists($file->uri), t('No file remains at the old location.')); $this->assertFilePermissions($new_filepath, variable_get('file_chmod_file', 0664)); // Moving with rename. - $desired_filepath = file_directory_path() . '/' . $this->randomName(); + $desired_filepath = 'public://' . $this->randomName(); $this->assertTrue(file_exists($new_filepath), t('File exists before moving.')); $this->assertTrue(file_put_contents($desired_filepath, ' '), t('Created a file so a rename will have to happen.')); $newer_filepath = file_unmanaged_move($new_filepath, $desired_filepath, FILE_EXISTS_RENAME); @@ -1119,6 +1083,7 @@ class FileUnmanagedMoveTest extends FileTestCase { $this->assertFilePermissions($newer_filepath, variable_get('file_chmod_file', 0664)); // TODO: test moving to a directory (rather than full directory/file path) + // TODO: test creating and moving normal files (rather than streams) } /** @@ -1138,14 +1103,14 @@ class FileUnmanagedMoveTest extends FileTestCase { $file = $this->createFile(); // Move the file onto itself without renaming shouldn't make changes. - $new_filepath = file_unmanaged_move($file->filepath, $file->filepath, FILE_EXISTS_REPLACE); + $new_filepath = file_unmanaged_move($file->uri, $file->uri, FILE_EXISTS_REPLACE); $this->assertFalse($new_filepath, t('Moving onto itself without renaming fails.')); - $this->assertTrue(file_exists($file->filepath), t('File exists after moving onto itself.')); + $this->assertTrue(file_exists($file->uri), t('File exists after moving onto itself.')); // Move the file onto itself with renaming will result in a new filename. - $new_filepath = file_unmanaged_move($file->filepath, $file->filepath, FILE_EXISTS_RENAME); + $new_filepath = file_unmanaged_move($file->uri, $file->uri, FILE_EXISTS_RENAME); $this->assertTrue($new_filepath, t('Moving onto itself with renaming works.')); - $this->assertFalse(file_exists($file->filepath), t('Original file has been removed.')); + $this->assertFalse(file_exists($file->uri), t('Original file has been removed.')); $this->assertTrue(file_exists($new_filepath), t('File exists after moving onto itself.')); } } @@ -1171,25 +1136,26 @@ class FileUnmanagedCopyTest extends FileTestCase { $file = $this->createFile(); // Copying to a new name. - $desired_filepath = file_directory_path() . '/' . $this->randomName(); - $new_filepath = file_unmanaged_copy($file->filepath, $desired_filepath, FILE_EXISTS_ERROR); + $desired_filepath = 'public://' . $this->randomName(); + $new_filepath = file_unmanaged_copy($file->uri, $desired_filepath, FILE_EXISTS_ERROR); $this->assertTrue($new_filepath, t('Copy was successful.')); $this->assertEqual($new_filepath, $desired_filepath, t('Returned expected filepath.')); - $this->assertTrue(file_exists($file->filepath), t('Original file remains.')); + $this->assertTrue(file_exists($file->uri), t('Original file remains.')); $this->assertTrue(file_exists($new_filepath), t('New file exists.')); $this->assertFilePermissions($new_filepath, variable_get('file_chmod_file', 0664)); // Copying with rename. - $desired_filepath = file_directory_path() . '/' . $this->randomName(); + $desired_filepath = 'public://' . $this->randomName(); $this->assertTrue(file_put_contents($desired_filepath, ' '), t('Created a file so a rename will have to happen.')); - $newer_filepath = file_unmanaged_copy($file->filepath, $desired_filepath, FILE_EXISTS_RENAME); + $newer_filepath = file_unmanaged_copy($file->uri, $desired_filepath, FILE_EXISTS_RENAME); $this->assertTrue($newer_filepath, t('Copy was successful.')); $this->assertNotEqual($newer_filepath, $desired_filepath, t('Returned expected filepath.')); - $this->assertTrue(file_exists($file->filepath), t('Original file remains.')); + $this->assertTrue(file_exists($file->uri), t('Original file remains.')); $this->assertTrue(file_exists($newer_filepath), t('New file exists.')); $this->assertFilePermissions($newer_filepath, variable_get('file_chmod_file', 0664)); // TODO: test copying to a directory (rather than full directory/file path) + // TODO: test copying normal files using normal paths (rather than only streams) } /** @@ -1211,28 +1177,28 @@ class FileUnmanagedCopyTest extends FileTestCase { $file = $this->createFile(); // Copy the file onto itself with renaming works. - $new_filepath = file_unmanaged_copy($file->filepath, $file->filepath, FILE_EXISTS_RENAME); + $new_filepath = file_unmanaged_copy($file->uri, $file->uri, FILE_EXISTS_RENAME); $this->assertTrue($new_filepath, t('Copying onto itself with renaming works.')); - $this->assertNotEqual($new_filepath, $file->filepath, t('Copied file has a new name.')); - $this->assertTrue(file_exists($file->filepath), t('Original file exists after copying onto itself.')); + $this->assertNotEqual($new_filepath, $file->uri, t('Copied file has a new name.')); + $this->assertTrue(file_exists($file->uri), t('Original file exists after copying onto itself.')); $this->assertTrue(file_exists($new_filepath), t('Copied file exists after copying onto itself.')); $this->assertFilePermissions($new_filepath, variable_get('file_chmod_file', 0664)); // Copy the file onto itself without renaming fails. - $new_filepath = file_unmanaged_copy($file->filepath, $file->filepath, FILE_EXISTS_ERROR); + $new_filepath = file_unmanaged_copy($file->uri, $file->uri, FILE_EXISTS_ERROR); $this->assertFalse($new_filepath, t('Copying onto itself without renaming fails.')); - $this->assertTrue(file_exists($file->filepath), t('File exists after copying onto itself.')); + $this->assertTrue(file_exists($file->uri), t('File exists after copying onto itself.')); // Copy the file into same directory without renaming fails. - $new_filepath = file_unmanaged_copy($file->filepath, dirname($file->filepath), FILE_EXISTS_ERROR); + $new_filepath = file_unmanaged_copy($file->uri, drupal_dirname($file->uri), FILE_EXISTS_ERROR); $this->assertFalse($new_filepath, t('Copying onto itself fails.')); - $this->assertTrue(file_exists($file->filepath), t('File exists after copying onto itself.')); + $this->assertTrue(file_exists($file->uri), t('File exists after copying onto itself.')); // Copy the file into same directory with renaming works. - $new_filepath = file_unmanaged_copy($file->filepath, dirname($file->filepath), FILE_EXISTS_RENAME); + $new_filepath = file_unmanaged_copy($file->uri, drupal_dirname($file->uri), FILE_EXISTS_RENAME); $this->assertTrue($new_filepath, t('Copying into same directory works.')); - $this->assertNotEqual($new_filepath, $file->filepath, t('Copied file has a new name.')); - $this->assertTrue(file_exists($file->filepath), t('Original file exists after copying onto itself.')); + $this->assertNotEqual($new_filepath, $file->uri, t('Copied file has a new name.')); + $this->assertTrue(file_exists($file->uri), t('Original file exists after copying onto itself.')); $this->assertTrue(file_exists($new_filepath), t('Copied file exists after copying onto itself.')); $this->assertFilePermissions($new_filepath, variable_get('file_chmod_file', 0664)); } @@ -1257,10 +1223,10 @@ class FileDeleteTest extends FileHookTestCase { $file = $this->createFile(); // Check that deletion removes the file and database record. - $this->assertTrue(is_file($file->filepath), t("File exists.")); + $this->assertTrue(is_file($file->uri), t("File exists.")); $this->assertIdentical(file_delete($file), TRUE, t("Delete worked.")); $this->assertFileHooksCalled(array('references', 'delete')); - $this->assertFalse(file_exists($file->filepath), t("Test file has actually been deleted.")); + $this->assertFalse(file_exists($file->uri), t("Test file has actually been deleted.")); $this->assertFalse(file_load($file->fid), t('File was removed from the database.')); // TODO: implement hook_file_references() in file_test.module and report a @@ -1287,7 +1253,7 @@ class FileMoveTest extends FileHookTestCase { function testNormal() { $contents = $this->randomName(10); $source = $this->createFile(NULL, $contents); - $desired_filepath = file_directory_path() . '/' . $this->randomName(); + $desired_filepath = 'public://' . $this->randomName(); // Clone the object so we don't have to worry about the function changing // our reference copy. @@ -1295,8 +1261,8 @@ class FileMoveTest extends FileHookTestCase { // Check the return status and that the contents changed. $this->assertTrue($result, t('File moved sucessfully.')); - $this->assertFalse(file_exists($source->filepath)); - $this->assertEqual($contents, file_get_contents($result->filepath), t('Contents of file correctly written.')); + $this->assertFalse(file_exists($source->uri)); + $this->assertEqual($contents, file_get_contents($result->uri), t('Contents of file correctly written.')); // Check that the correct hooks were called. $this->assertFileHooksCalled(array('move', 'update')); @@ -1323,12 +1289,12 @@ class FileMoveTest extends FileHookTestCase { // Clone the object so we don't have to worry about the function changing // our reference copy. - $result = file_move(clone $source, $target->filepath, FILE_EXISTS_RENAME); + $result = file_move(clone $source, $target->uri, FILE_EXISTS_RENAME); // Check the return status and that the contents changed. $this->assertTrue($result, t('File moved sucessfully.')); - $this->assertFalse(file_exists($source->filepath)); - $this->assertEqual($contents, file_get_contents($result->filepath), t('Contents of file correctly written.')); + $this->assertFalse(file_exists($source->uri)); + $this->assertEqual($contents, file_get_contents($result->uri), t('Contents of file correctly written.')); // Check that the correct hooks were called. $this->assertFileHooksCalled(array('move', 'update')); @@ -1343,7 +1309,7 @@ class FileMoveTest extends FileHookTestCase { // Compare the source and results. $loaded_source = file_load($source->fid, TRUE); $this->assertEqual($loaded_source->fid, $result->fid, t("Returned file's id matches the source.")); - $this->assertNotEqual($loaded_source->filepath, $source->filepath, t("Returned file path has changed from the original.")); + $this->assertNotEqual($loaded_source->uri, $source->uri, t("Returned file path has changed from the original.")); } /** @@ -1358,11 +1324,11 @@ class FileMoveTest extends FileHookTestCase { // Clone the object so we don't have to worry about the function changing // our reference copy. - $result = file_move(clone $source, $target->filepath, FILE_EXISTS_REPLACE); + $result = file_move(clone $source, $target->uri, FILE_EXISTS_REPLACE); // Look at the results. - $this->assertEqual($contents, file_get_contents($result->filepath), t('Contents of file were overwritten.')); - $this->assertFalse(file_exists($source->filepath)); + $this->assertEqual($contents, file_get_contents($result->uri), t('Contents of file were overwritten.')); + $this->assertFalse(file_exists($source->uri)); $this->assertTrue($result, t('File moved sucessfully.')); // Check that the correct hooks were called. @@ -1388,9 +1354,9 @@ class FileMoveTest extends FileHookTestCase { // Copy the file over itself. Clone the object so we don't have to worry // about the function changing our reference copy. - $result = file_move(clone $source, $source->filepath, FILE_EXISTS_REPLACE); + $result = file_move(clone $source, $source->uri, FILE_EXISTS_REPLACE); $this->assertFalse($result, t('File move failed.')); - $this->assertEqual($contents, file_get_contents($source->filepath), t('Contents of file were not altered.')); + $this->assertEqual($contents, file_get_contents($source->uri), t('Contents of file were not altered.')); // Check that no hooks were called while failing. $this->assertFileHooksCalled(array()); @@ -1412,12 +1378,12 @@ class FileMoveTest extends FileHookTestCase { // Clone the object so we don't have to worry about the function changing // our reference copy. - $result = file_move(clone $source, $target->filepath, FILE_EXISTS_ERROR); + $result = file_move(clone $source, $target->uri, FILE_EXISTS_ERROR); // Check the return status and that the contents did not change. $this->assertFalse($result, t('File move failed.')); - $this->assertTrue(file_exists($source->filepath)); - $this->assertEqual($contents, file_get_contents($target->filepath), t('Contents of file were not altered.')); + $this->assertTrue(file_exists($source->uri)); + $this->assertEqual($contents, file_get_contents($target->uri), t('Contents of file were not altered.')); // Check that no hooks were called while failing. $this->assertFileHooksCalled(array()); @@ -1448,23 +1414,23 @@ class FileCopyTest extends FileHookTestCase { function testNormal() { $contents = $this->randomName(10); $source = $this->createFile(NULL, $contents); - $desired_filepath = file_directory_path() . '/' . $this->randomName(); + $desired_uri = 'public://' . $this->randomName(); // Clone the object so we don't have to worry about the function changing // our reference copy. - $result = file_copy(clone $source, $desired_filepath, FILE_EXISTS_ERROR); + $result = file_copy(clone $source, $desired_uri, FILE_EXISTS_ERROR); // Check the return status and that the contents changed. $this->assertTrue($result, t('File copied sucessfully.')); - $this->assertEqual($contents, file_get_contents($result->filepath), t('Contents of file were copied correctly.')); + $this->assertEqual($contents, file_get_contents($result->uri), t('Contents of file were copied correctly.')); // Check that the correct hooks were called. $this->assertFileHooksCalled(array('copy', 'insert')); $this->assertDifferentFile($source, $result); - $this->assertEqual($result->filepath, $desired_filepath, t('The copied file object has the desired filepath.')); - $this->assertTrue(file_exists($source->filepath), t('The original file still exists.')); - $this->assertTrue(file_exists($result->filepath), t('The copied file exists.')); + $this->assertEqual($result->uri, $desired_uri, t('The copied file object has the desired filepath.')); + $this->assertTrue(file_exists($source->uri), t('The original file still exists.')); + $this->assertTrue(file_exists($result->uri), t('The copied file exists.')); // Reload the file from the database and check that the changes were // actually saved. @@ -1483,12 +1449,12 @@ class FileCopyTest extends FileHookTestCase { // Clone the object so we don't have to worry about the function changing // our reference copy. - $result = file_copy(clone $source, $target->filepath, FILE_EXISTS_RENAME); + $result = file_copy(clone $source, $target->uri, FILE_EXISTS_RENAME); // Check the return status and that the contents changed. $this->assertTrue($result, t('File copied sucessfully.')); - $this->assertEqual($contents, file_get_contents($result->filepath), t('Contents of file were copied correctly.')); - $this->assertNotEqual($result->filepath, $source->filepath, t('Returned file path has changed from the original.')); + $this->assertEqual($contents, file_get_contents($result->uri), t('Contents of file were copied correctly.')); + $this->assertNotEqual($result->uri, $source->uri, t('Returned file path has changed from the original.')); // Check that the correct hooks were called. $this->assertFileHooksCalled(array('copy', 'insert')); @@ -1523,11 +1489,11 @@ class FileCopyTest extends FileHookTestCase { // Clone the object so we don't have to worry about the function changing // our reference copy. - $result = file_copy(clone $source, $target->filepath, FILE_EXISTS_REPLACE); + $result = file_copy(clone $source, $target->uri, FILE_EXISTS_REPLACE); // Check the return status and that the contents changed. $this->assertTrue($result, t('File copied sucessfully.')); - $this->assertEqual($contents, file_get_contents($result->filepath), t('Contents of file were overwritten.')); + $this->assertEqual($contents, file_get_contents($result->uri), t('Contents of file were overwritten.')); $this->assertDifferentFile($source, $result); // Check that the correct hooks were called. @@ -1561,11 +1527,11 @@ class FileCopyTest extends FileHookTestCase { // Clone the object so we don't have to worry about the function changing // our reference copy. - $result = file_copy(clone $source, $target->filepath, FILE_EXISTS_ERROR); + $result = file_copy(clone $source, $target->uri, FILE_EXISTS_ERROR); // Check the return status and that the contents were not changed. $this->assertFalse($result, t('File copy failed.')); - $this->assertEqual($contents, file_get_contents($target->filepath), t('Contents of file were not altered.')); + $this->assertEqual($contents, file_get_contents($target->uri), t('Contents of file were not altered.')); // Check that the correct hooks were called. $this->assertFileHooksCalled(array()); @@ -1597,10 +1563,10 @@ class FileLoadTest extends FileHookTestCase { } /** - * Try to load a non-existent file by filepath. + * Try to load a non-existent file by URI. */ function testLoadMissingFilepath() { - $this->assertFalse(reset(file_load_multiple(array(), array('filepath' => 'misc/druplicon.png'))), t("Try to load a file that doesn't exist in the database fails.")); + $this->assertFalse(reset(file_load_multiple(array(), array('uri' => 'foobar://misc/druplicon.png'))), t("Try to load a file that doesn't exist in the database fails.")); $this->assertFileHooksCalled(array()); } @@ -1617,21 +1583,13 @@ class FileLoadTest extends FileHookTestCase { */ function testSingleValues() { // Create a new file object from scratch so we know the values. - $file = array( - 'uid' => 1, - 'filename' => 'druplicon.png', - 'filepath' => 'misc/druplicon.png', - 'filemime' => 'image/png', - 'timestamp' => 1, - 'status' => FILE_STATUS_PERMANENT, - ); - $file = file_save($file); + $file = $this->createFile('druplicon.txt', NULL, 'public'); $by_fid_file = file_load($file->fid); $this->assertFileHookCalled('load'); $this->assertTrue(is_object($by_fid_file), t('file_load() returned an object.')); $this->assertEqual($by_fid_file->fid, $file->fid, t("Loading by fid got the same fid."), 'File'); - $this->assertEqual($by_fid_file->filepath, $file->filepath, t("Loading by fid got the correct filepath."), 'File'); + $this->assertEqual($by_fid_file->uri, $file->uri, t("Loading by fid got the correct filepath."), 'File'); $this->assertEqual($by_fid_file->filename, $file->filename, t("Loading by fid got the correct filename."), 'File'); $this->assertEqual($by_fid_file->filemime, $file->filemime, t("Loading by fid got the correct MIME type."), 'File'); $this->assertEqual($by_fid_file->status, $file->status, t("Loading by fid got the correct status."), 'File'); @@ -1643,19 +1601,11 @@ class FileLoadTest extends FileHookTestCase { */ function testMultiple() { // Create a new file object. - $file = array( - 'uid' => 1, - 'filename' => 'druplicon.png', - 'filepath' => 'misc/druplicon.png', - 'filemime' => 'image/png', - 'timestamp' => 1, - 'status' => FILE_STATUS_PERMANENT, - ); - $file = file_save($file); + $file = $this->createFile('druplicon.txt', NULL, 'public'); // Load by path. file_test_reset(); - $by_path_files = file_load_multiple(array(), array('filepath' => $file->filepath)); + $by_path_files = file_load_multiple(array(), array('uri' => $file->uri)); $this->assertFileHookCalled('load'); $this->assertEqual(1, count($by_path_files), t('file_load_multiple() returned an array of the correct size.')); $by_path_file = reset($by_path_files); @@ -1669,7 +1619,7 @@ class FileLoadTest extends FileHookTestCase { $this->assertEqual(1, count($by_fid_files), t('file_load_multiple() returned an array of the correct size.')); $by_fid_file = reset($by_fid_files); $this->assertTrue($by_fid_file->file_test['loaded'], t('file_test_file_load() was able to modify the file during load.')); - $this->assertEqual($by_fid_file->filepath, $file->filepath, t("Loading by fid got the correct filepath."), 'File'); + $this->assertEqual($by_fid_file->uri, $file->uri, t("Loading by fid got the correct filepath."), 'File'); } } @@ -1689,13 +1639,14 @@ class FileSaveTest extends FileHookTestCase { // Create a new file object. $file = array( 'uid' => 1, - 'filename' => 'druplicon.png', - 'filepath' => 'misc/druplicon.png', - 'filemime' => 'image/png', + 'filename' => 'druplicon.txt', + 'uri' => 'public://druplicon.txt', + 'filemime' => 'text/plain', 'timestamp' => 1, 'status' => FILE_STATUS_PERMANENT, ); $file = (object) $file; + file_put_contents($file->uri, 'hello world'); // Save it, inserting a new record. $saved_file = file_save($file); @@ -1705,10 +1656,10 @@ class FileSaveTest extends FileHookTestCase { $this->assertNotNull($saved_file, t("Saving the file should give us back a file object."), 'File'); $this->assertTrue($saved_file->fid > 0, t("A new file ID is set when saving a new file to the database."), 'File'); - $loaded_file = db_query('SELECT * FROM {files} f WHERE f.fid = :fid', array(':fid' => $saved_file->fid))->fetch(PDO::FETCH_OBJ); + $loaded_file = db_query('SELECT * FROM {file} f WHERE f.fid = :fid', array(':fid' => $saved_file->fid))->fetch(PDO::FETCH_OBJ); $this->assertNotNull($loaded_file, t("Record exists in the database.")); $this->assertEqual($loaded_file->status, $file->status, t("Status was saved correctly.")); - $this->assertEqual($saved_file->filesize, filesize($file->filepath), t("File size was set correctly."), 'File'); + $this->assertEqual($saved_file->filesize, filesize($file->uri), t("File size was set correctly."), 'File'); $this->assertTrue($saved_file->timestamp > 1, t("File size was set correctly."), 'File'); @@ -1722,7 +1673,7 @@ class FileSaveTest extends FileHookTestCase { $this->assertEqual($resaved_file->fid, $saved_file->fid, t("The file ID of an existing file is not changed when updating the database."), 'File'); $this->assertTrue($resaved_file->timestamp >= $saved_file->timestamp, t("Timestamp didn't go backwards."), 'File'); - $loaded_file = db_query('SELECT * FROM {files} f WHERE f.fid = :fid', array(':fid' => $saved_file->fid))->fetch(PDO::FETCH_OBJ); + $loaded_file = db_query('SELECT * FROM {file} f WHERE f.fid = :fid', array(':fid' => $saved_file->fid))->fetch(PDO::FETCH_OBJ); $this->assertNotNull($loaded_file, t("Record still exists in the database."), 'File'); $this->assertEqual($loaded_file->status, $saved_file->status, t("Status was saved correctly.")); } @@ -1789,9 +1740,9 @@ class FileSaveDataTest extends FileHookTestCase { $result = file_save_data($contents); $this->assertTrue($result, t('Unnamed file saved correctly.')); - $this->assertEqual(file_directory_path(), dirname($result->filepath), t("File was placed in Drupal's files directory.")); - $this->assertEqual($result->filename, basename($result->filepath), t("Filename was set to the file's basename.")); - $this->assertEqual($contents, file_get_contents($result->filepath), t('Contents of the file are correct.')); + $this->assertEqual(file_directory_path('public'), file_directory_path(file_stream_wrapper_valid_scheme($result->uri)), t("File was placed in Drupal's files directory.")); + $this->assertEqual($result->filename, basename($result->uri), t("Filename was set to the file's basename.")); + $this->assertEqual($contents, file_get_contents($result->uri), t('Contents of the file are correct.')); $this->assertEqual($result->filemime, 'application/octet-stream', t('A MIME type was set.')); $this->assertEqual($result->status, FILE_STATUS_PERMANENT, t("The file's status was set to permanent.")); @@ -1808,12 +1759,12 @@ class FileSaveDataTest extends FileHookTestCase { function testWithFilename() { $contents = $this->randomName(8); - $result = file_save_data($contents, 'asdf.txt'); + $result = file_save_data($contents, 'public://' . 'asdf.txt'); $this->assertTrue($result, t('Unnamed file saved correctly.')); - $this->assertEqual(file_directory_path(), dirname($result->filepath), t("File was placed in Drupal's files directory.")); - $this->assertEqual('asdf.txt', basename($result->filepath), t('File was named correctly.')); - $this->assertEqual($contents, file_get_contents($result->filepath), t('Contents of the file are correct.')); + $this->assertEqual(file_directory_path('public'), file_directory_path(file_stream_wrapper_valid_scheme($result->uri)), t("File was placed in Drupal's files directory.")); + $this->assertEqual('asdf.txt', basename($result->uri), t('File was named correctly.')); + $this->assertEqual($contents, file_get_contents($result->uri), t('Contents of the file are correct.')); $this->assertEqual($result->filemime, 'text/plain', t('A MIME type was set.')); $this->assertEqual($result->status, FILE_STATUS_PERMANENT, t("The file's status was set to permanent.")); @@ -1832,12 +1783,12 @@ class FileSaveDataTest extends FileHookTestCase { $existing = $this->createFile(); $contents = $this->randomName(8); - $result = file_save_data($contents, $existing->filepath, FILE_EXISTS_RENAME); + $result = file_save_data($contents, $existing->uri, FILE_EXISTS_RENAME); $this->assertTrue($result, t("File saved sucessfully.")); - $this->assertEqual(file_directory_path(), dirname($result->filepath), t("File was placed in Drupal's files directory.")); + $this->assertEqual(file_directory_path('public'), file_directory_path(file_stream_wrapper_valid_scheme($result->uri)), t("File was placed in Drupal's files directory.")); $this->assertEqual($result->filename, $existing->filename, t("Filename was set to the basename of the source, rather than that of the renamed file.")); - $this->assertEqual($contents, file_get_contents($result->filepath), t("Contents of the file are correct.")); + $this->assertEqual($contents, file_get_contents($result->uri), t("Contents of the file are correct.")); $this->assertEqual($result->filemime, 'application/octet-stream', t("A MIME type was set.")); $this->assertEqual($result->status, FILE_STATUS_PERMANENT, t("The file's status was set to permanent.")); @@ -1860,12 +1811,12 @@ class FileSaveDataTest extends FileHookTestCase { $existing = $this->createFile(); $contents = $this->randomName(8); - $result = file_save_data($contents, $existing->filepath, FILE_EXISTS_REPLACE); + $result = file_save_data($contents, $existing->uri, FILE_EXISTS_REPLACE); $this->assertTrue($result, t('File saved sucessfully.')); - $this->assertEqual(file_directory_path(), dirname($result->filepath), t("File was placed in Drupal's files directory.")); + $this->assertEqual(file_directory_path('public'), file_directory_path(file_stream_wrapper_valid_scheme($result->uri)), t("File was placed in Drupal's files directory.")); $this->assertEqual($result->filename, $existing->filename, t('Filename was set to the basename of the existing file, rather than preserving the original name.')); - $this->assertEqual($contents, file_get_contents($result->filepath), t('Contents of the file are correct.')); + $this->assertEqual($contents, file_get_contents($result->uri), t('Contents of the file are correct.')); $this->assertEqual($result->filemime, 'application/octet-stream', t('A MIME type was set.')); $this->assertEqual($result->status, FILE_STATUS_PERMANENT, t("The file's status was set to permanent.")); @@ -1887,9 +1838,9 @@ class FileSaveDataTest extends FileHookTestCase { $existing = $this->createFile(NULL, $contents); // Check the overwrite error. - $result = file_save_data('asdf', $existing->filepath, FILE_EXISTS_ERROR); + $result = file_save_data('asdf', $existing->uri, FILE_EXISTS_ERROR); $this->assertFalse($result, t('Overwriting a file fails when FILE_EXISTS_ERROR is specified.')); - $this->assertEqual($contents, file_get_contents($existing->filepath), t('Contents of existing file were unchanged.')); + $this->assertEqual($contents, file_get_contents($existing->uri), t('Contents of existing file were unchanged.')); // Check that no hooks were called while failing. $this->assertFileHooksCalled(array()); @@ -1920,11 +1871,10 @@ class FileDownloadTest extends FileTestCase { */ function testPrivateFileTransfer() { // Set file downloads to private so handler functions get called. - variable_set('file_downloads', FILE_DOWNLOADS_PRIVATE); // Create a file. - $file = $this->createFile(); - $url = file_create_url($file->filename); + $file = $this->createFile(NULL, NULL, 'private'); + $url = file_create_url($file->uri); // Set file_test access header to allow the download. file_test_set_return('download', array('x-foo' => 'Bar')); @@ -1939,7 +1889,7 @@ class FileDownloadTest extends FileTestCase { $this->assertResponse(403, t('Correctly denied access to a file when file_test sets the header to -1.')); // Try non-existent file. - $url = file_create_url($this->randomName()); + $url = file_create_url('private://' . $this->randomName()); $this->drupalHead($url); $this->assertResponse(404, t('Correctly returned 404 response for a non-existent file.')); } @@ -2022,6 +1972,8 @@ class FileMimeTypeTest extends DrupalWebTestCase { * Test mapping of mimetypes from filenames. */ public function testFileMimeTypeDetection() { + $prefix = 'simpletest://'; + $test_case = array( 'test.jar' => 'application/java-archive', 'test.jpeg' => 'image/jpeg', @@ -2068,6 +2020,11 @@ class FileMimeTypeTest extends DrupalWebTestCase { variable_set('mime_extension_mapping', $mapping); foreach ($test_case as $input => $expected) { + // Test stream [URI]. + $output = file_get_mimetype($prefix . $input); + $this->assertIdentical($output, $expected, t('Mimetype for %input is %output (expected: %expected).', array('%input' => $input, '%output' => $output, '%expected' => $expected))); + + // Test normal path equivalent $output = file_get_mimetype($input); $this->assertIdentical($output, $expected, t('Mimetype (using mappings from variable) for %input is %output (expected: %expected).', array('%input' => $input, '%output' => $output, '%expected' => $expected))); } @@ -2098,8 +2055,8 @@ class StreamWrapperRegistryTest extends DrupalWebTestCase { } function setUp() { - drupal_static_reset('file_get_stream_wrappers'); parent::setUp('file_test'); + drupal_static_reset('file_get_stream_wrappers'); } function tearDown() { @@ -2139,9 +2096,9 @@ class StreamWrapperRegistryTest extends DrupalWebTestCase { $this->assertEqual('DrupalPublicStreamWrapper', get_class($instance), t('Got correct class type for public URI.')); // Test file_stream_wrapper_uri_normalize. - $uri = 'public:///' . $this->originalFileDirectory . '/foo/bar/'; + $uri = 'public:///' . file_directory_path() . '/foo/bar/'; $uri = file_stream_wrapper_uri_normalize($uri); - $this->assertEqual('public://foo/bar', $uri, t('Got a properly normalized URI')); + $this->assertEqual('public://foo/bar', $uri, t('Got a properly normalized URI @uri', array('@uri' => $uri))); // Test file_uri_taget(). $this->assertEqual('foo/bar.txt', file_uri_target('public://foo/bar.txt'), t('Got a valid stream target from public://foo/bar.txt')); diff --git a/modules/simpletest/tests/file_test.module b/modules/simpletest/tests/file_test.module index dc6a56b4e..9670d1ab3 100644 --- a/modules/simpletest/tests/file_test.module +++ b/modules/simpletest/tests/file_test.module @@ -70,7 +70,7 @@ function _file_test_form_submit(&$form, &$form_state) { $file = file_save_upload('file_test_upload', array('file_validate_is_image' => array()), FALSE, $form_state['values']['file_test_replace']); if ($file) { $form_state['values']['file_test_upload'] = $file; - drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->filepath))); + drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->uri))); drupal_set_message(t('You WIN!')); } elseif ($file === FALSE) { diff --git a/modules/simpletest/tests/filetransfer.test b/modules/simpletest/tests/filetransfer.test index 4320c1d2a..37e14fdd4 100644 --- a/modules/simpletest/tests/filetransfer.test +++ b/modules/simpletest/tests/filetransfer.test @@ -36,7 +36,7 @@ class FileTranferTest extends DrupalWebTestCase { } function _buildFakeModule() { - $location = file_directory_temp() . '/fake'; + $location = file_directory_path('temporary') . '/fake'; if (is_dir($location)) { $ret = 0; $output = array(); diff --git a/modules/simpletest/tests/image.test b/modules/simpletest/tests/image.test index c5fb93fea..7047576b6 100644 --- a/modules/simpletest/tests/image.test +++ b/modules/simpletest/tests/image.test @@ -444,7 +444,7 @@ class ImageToolkitGdTestCase extends DrupalWebTestCase { } $directory = file_directory_path() . '/imagetests'; - file_check_directory($directory, FILE_CREATE_DIRECTORY); + file_prepare_directory($directory, FILE_CREATE_DIRECTORY); image_save($image, $directory . '/' . $op . '.' . $image->info['extension']); $this->assertTrue($correct_dimensions_real, t('Image %file after %action action has proper dimensions.', array('%file' => $file, '%action' => $op))); diff --git a/modules/simpletest/tests/session.test b/modules/simpletest/tests/session.test index 536f2abf1..6a2b4d32d 100644 --- a/modules/simpletest/tests/session.test +++ b/modules/simpletest/tests/session.test @@ -219,7 +219,7 @@ class SessionTestCase extends DrupalWebTestCase { $this->loggedInUser = FALSE; // Change cookie file for user. - $this->cookieFile = file_directory_temp() . '/cookie.' . $uid . '.txt'; + $this->cookieFile = file_directory_path('temporary') . '/cookie.' . $uid . '.txt'; $this->additionalCurlOptions[CURLOPT_COOKIEFILE] = $this->cookieFile; $this->additionalCurlOptions[CURLOPT_COOKIESESSION] = TRUE; $this->drupalGet('session-test/get'); |