Commit 1451a548 authored by jhodgdon's avatar jhodgdon

Issue #1797296 by Lars Toomre: Remove t() in test assertions in file sub-system

parent 45b49610
......@@ -126,6 +126,6 @@ function testFileDirectoryTemp() {
$tmp_directory = file_directory_temp();
$this->assertEqual(empty($tmp_directory), FALSE, t('file_directory_temp() returned a non-empty value.'));
$setting = variable_get('file_temporary_path', '');
$this->assertEqual($setting, $tmp_directory, t("The 'file_temporary_path' variable has the same value that file_directory_temp() returned."));
$this->assertEqual($setting, $tmp_directory, "The 'file_temporary_path' variable has the same value that file_directory_temp() returned.");
}
}
......@@ -154,7 +154,7 @@ function createDirectory($path = NULL) {
if (!isset($path)) {
$path = file_default_scheme() . '://' . $this->randomName();
}
$this->assertTrue(drupal_mkdir($path) && is_dir($path), t('Directory was created successfully.'));
$this->assertTrue(drupal_mkdir($path) && is_dir($path), 'Directory was created successfully.');
return $path;
}
......
......@@ -56,11 +56,11 @@ public function testFileMimeTypeDetection() {
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)));
$this->assertIdentical($output, $expected, format_string('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 default mappings) for %input is %output (expected: %expected).', array('%input' => $input, '%output' => $output, '%expected' => $expected)));
$this->assertIdentical($output, $expected, format_string('Mimetype (using default mappings) for %input is %output (expected: %expected).', array('%input' => $input, '%output' => $output, '%expected' => $expected)));
}
// Now test passing in the map.
......@@ -93,7 +93,7 @@ public function testFileMimeTypeDetection() {
foreach ($test_case as $input => $expected) {
$output = file_get_mimetype($input, $mapping);
$this->assertIdentical($output, $expected, t('Mimetype (using passed-in mappings) for %input is %output (expected: %expected).', array('%input' => $input, '%output' => $output, '%expected' => $expected)));
$this->assertIdentical($output, $expected, format_string('Mimetype (using passed-in mappings) for %input is %output (expected: %expected).', array('%input' => $input, '%output' => $output, '%expected' => $expected)));
}
}
}
......@@ -33,8 +33,8 @@ function testMunging() {
variable_set('allow_insecure_uploads', 0);
$munged_name = file_munge_filename($this->name, '', TRUE);
$messages = drupal_get_messages();
$this->assertTrue(in_array(t('For security reasons, your upload has been renamed to %filename.', array('%filename' => $munged_name)), $messages['status']), t('Alert properly set when a file is renamed.'));
$this->assertNotEqual($munged_name, $this->name, t('The new filename (%munged) has been modified from the original (%original)', array('%munged' => $munged_name, '%original' => $this->name)));
$this->assertTrue(in_array(t('For security reasons, your upload has been renamed to %filename.', array('%filename' => $munged_name)), $messages['status']), 'Alert properly set when a file is renamed.');
$this->assertNotEqual($munged_name, $this->name, format_string('The new filename (%munged) has been modified from the original (%original)', array('%munged' => $munged_name, '%original' => $this->name)));
}
/**
......@@ -44,7 +44,7 @@ function testMunging() {
function testMungeIgnoreInsecure() {
variable_set('allow_insecure_uploads', 1);
$munged_name = file_munge_filename($this->name, '');
$this->assertIdentical($munged_name, $this->name, t('The original filename (%original) matches the munged filename (%munged) when insecure uploads are enabled.', array('%munged' => $munged_name, '%original' => $this->name)));
$this->assertIdentical($munged_name, $this->name, format_string('The original filename (%original) matches the munged filename (%munged) when insecure uploads are enabled.', array('%munged' => $munged_name, '%original' => $this->name)));
}
/**
......@@ -53,7 +53,7 @@ function testMungeIgnoreInsecure() {
function testMungeIgnoreWhitelisted() {
// Declare our extension as whitelisted.
$munged_name = file_munge_filename($this->name, $this->bad_extension);
$this->assertIdentical($munged_name, $this->name, t('The new filename (%munged) matches the original (%original) once the extension has been whitelisted.', array('%munged' => $munged_name, '%original' => $this->name)));
$this->assertIdentical($munged_name, $this->name, format_string('The new filename (%munged) matches the original (%original) once the extension has been whitelisted.', array('%munged' => $munged_name, '%original' => $this->name)));
}
/**
......@@ -62,6 +62,6 @@ function testMungeIgnoreWhitelisted() {
function testUnMunge() {
$munged_name = file_munge_filename($this->name, '', FALSE);
$unmunged_name = file_unmunge_filename($munged_name);
$this->assertIdentical($unmunged_name, $this->name, t('The unmunged (%unmunged) filename matches the original (%original)', array('%unmunged' => $unmunged_name, '%original' => $this->name)));
$this->assertIdentical($unmunged_name, $this->name, format_string('The unmunged (%unmunged) filename matches the original (%original)', array('%unmunged' => $unmunged_name, '%original' => $this->name)));
}
}
......@@ -40,21 +40,21 @@ function testReturn() {
// passed to the callback.
$all_files = file_scan_directory($this->path, '/^javascript-/');
ksort($all_files);
$this->assertEqual(2, count($all_files), t('Found two, expected javascript files.'));
$this->assertEqual(2, count($all_files), 'Found two, expected javascript files.');
// Check the first file.
$file = reset($all_files);
$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.'));
$this->assertEqual(key($all_files), $file->uri, 'Correct array key was used for the first returned file.');
$this->assertEqual($file->uri, $this->path . '/javascript-1.txt', 'First file name was set correctly.');
$this->assertEqual($file->filename, 'javascript-1.txt', 'First basename was set correctly');
$this->assertEqual($file->name, 'javascript-1', 'First name was set correctly.');
// Check the second file.
$file = next($all_files);
$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.'));
$this->assertEqual(key($all_files), $file->uri, 'Correct array key was used for the second returned file.');
$this->assertEqual($file->uri, $this->path . '/javascript-2.script', 'Second file name was set correctly.');
$this->assertEqual($file->filename, 'javascript-2.script', 'Second basename was set correctly');
$this->assertEqual($file->name, 'javascript-2', 'Second name was set correctly.');
}
/**
......@@ -65,18 +65,18 @@ function testOptionCallback() {
// When nothing is matched nothing should be passed to the callback.
$all_files = file_scan_directory($this->path, '/^NONEXISTINGFILENAME/', array('callback' => 'file_test_file_scan_callback'));
$this->assertEqual(0, count($all_files), t('No files were found.'));
$this->assertEqual(0, count($all_files), 'No files were found.');
$results = file_test_file_scan_callback();
file_test_file_scan_callback_reset();
$this->assertEqual(0, count($results), t('No files were passed to the callback.'));
$this->assertEqual(0, count($results), 'No files were passed to the callback.');
// Grab a listing of all the JavaSscript files and check that they're
// passed to the callback.
$all_files = file_scan_directory($this->path, '/^javascript-/', array('callback' => 'file_test_file_scan_callback'));
$this->assertEqual(2, count($all_files), t('Found two, expected javascript files.'));
$this->assertEqual(2, count($all_files), 'Found two, expected javascript files.');
$results = file_test_file_scan_callback();
file_test_file_scan_callback_reset();
$this->assertEqual(2, count($results), t('Files were passed to the callback.'));
$this->assertEqual(2, count($results), 'Files were passed to the callback.');
}
/**
......@@ -85,11 +85,11 @@ function testOptionCallback() {
function testOptionNoMask() {
// Grab a listing of all the JavaSscript files.
$all_files = file_scan_directory($this->path, '/^javascript-/');
$this->assertEqual(2, count($all_files), t('Found two, expected javascript files.'));
$this->assertEqual(2, count($all_files), 'Found two, expected javascript files.');
// Now use the nomast parameter to filter out the .script file.
$filtered_files = file_scan_directory($this->path, '/^javascript-/', array('nomask' => '/.script$/'));
$this->assertEqual(1, count($filtered_files), t('Filtered correctly.'));
$this->assertEqual(1, count($filtered_files), 'Filtered correctly.');
}
/**
......@@ -100,25 +100,25 @@ function testOptionKey() {
$expected = array($this->path . '/javascript-1.txt', $this->path . '/javascript-2.script');
$actual = array_keys(file_scan_directory($this->path, '/^javascript-/', array('key' => 'filepath')));
sort($actual);
$this->assertEqual($expected, $actual, t('Returned the correct values for the filename key.'));
$this->assertEqual($expected, $actual, 'Returned the correct values for the filename key.');
// "basename", for the basename of the file.
$expected = array('javascript-1.txt', 'javascript-2.script');
$actual = array_keys(file_scan_directory($this->path, '/^javascript-/', array('key' => 'filename')));
sort($actual);
$this->assertEqual($expected, $actual, t('Returned the correct values for the basename key.'));
$this->assertEqual($expected, $actual, 'Returned the correct values for the basename key.');
// "name" for the name of the file without an extension.
$expected = array('javascript-1', 'javascript-2');
$actual = array_keys(file_scan_directory($this->path, '/^javascript-/', array('key' => 'name')));
sort($actual);
$this->assertEqual($expected, $actual, t('Returned the correct values for the name key.'));
$this->assertEqual($expected, $actual, 'Returned the correct values for the name key.');
// Invalid option that should default back to "filename".
$expected = array($this->path . '/javascript-1.txt', $this->path . '/javascript-2.script');
$actual = array_keys(file_scan_directory($this->path, '/^javascript-/', array('key' => 'INVALID')));
sort($actual);
$this->assertEqual($expected, $actual, t('An invalid key defaulted back to the default.'));
$this->assertEqual($expected, $actual, 'An invalid key defaulted back to the default.');
}
/**
......@@ -126,10 +126,10 @@ function testOptionKey() {
*/
function testOptionRecurse() {
$files = file_scan_directory(drupal_get_path('module', 'simpletest'), '/^javascript-/', array('recurse' => FALSE));
$this->assertTrue(empty($files), t("Without recursion couldn't find javascript files."));
$this->assertTrue(empty($files), "Without recursion couldn't find javascript files.");
$files = file_scan_directory(drupal_get_path('module', 'simpletest'), '/^javascript-/', array('recurse' => TRUE));
$this->assertEqual(2, count($files), t('With recursion we found the expected javascript files.'));
$this->assertEqual(2, count($files), 'With recursion we found the expected javascript files.');
}
......@@ -139,9 +139,9 @@ function testOptionRecurse() {
*/
function testOptionMinDepth() {
$files = file_scan_directory($this->path, '/^javascript-/', array('min_depth' => 0));
$this->assertEqual(2, count($files), t('No minimum-depth gets files in current directory.'));
$this->assertEqual(2, count($files), 'No minimum-depth gets files in current directory.');
$files = file_scan_directory($this->path, '/^javascript-/', array('min_depth' => 1));
$this->assertTrue(empty($files), t("Minimum-depth of 1 successfully excludes files from current directory."));
$this->assertTrue(empty($files), 'Minimum-depth of 1 successfully excludes files from current directory.');
}
}
......@@ -47,9 +47,9 @@ function tearDown() {
*/
function testGetClassName() {
// Check the dummy scheme.
$this->assertEqual($this->classname, file_stream_wrapper_get_class($this->scheme), t('Got correct class name for dummy scheme.'));
$this->assertEqual($this->classname, file_stream_wrapper_get_class($this->scheme), 'Got correct class name for dummy scheme.');
// Check core's scheme.
$this->assertEqual('Drupal\Core\StreamWrapper\PublicStream', file_stream_wrapper_get_class('public'), t('Got correct class name for public scheme.'));
$this->assertEqual('Drupal\Core\StreamWrapper\PublicStream', file_stream_wrapper_get_class('public'), 'Got correct class name for public scheme.');
}
/**
......@@ -57,10 +57,10 @@ function testGetClassName() {
*/
function testGetInstanceByScheme() {
$instance = file_stream_wrapper_get_instance_by_scheme($this->scheme);
$this->assertEqual($this->classname, get_class($instance), t('Got correct class type for dummy scheme.'));
$this->assertEqual($this->classname, get_class($instance), 'Got correct class type for dummy scheme.');
$instance = file_stream_wrapper_get_instance_by_scheme('public');
$this->assertEqual('Drupal\Core\StreamWrapper\PublicStream', get_class($instance), t('Got correct class type for public scheme.'));
$this->assertEqual('Drupal\Core\StreamWrapper\PublicStream', get_class($instance), 'Got correct class type for public scheme.');
}
/**
......@@ -68,31 +68,31 @@ function testGetInstanceByScheme() {
*/
function testUriFunctions() {
$instance = file_stream_wrapper_get_instance_by_uri($this->scheme . '://foo');
$this->assertEqual($this->classname, get_class($instance), t('Got correct class type for dummy URI.'));
$this->assertEqual($this->classname, get_class($instance), 'Got correct class type for dummy URI.');
$instance = file_stream_wrapper_get_instance_by_uri('public://foo');
$this->assertEqual('Drupal\Core\StreamWrapper\PublicStream', get_class($instance), t('Got correct class type for public URI.'));
$this->assertEqual('Drupal\Core\StreamWrapper\PublicStream', get_class($instance), 'Got correct class type for public URI.');
// Test file_uri_target().
$this->assertEqual(file_uri_target('public://foo/bar.txt'), 'foo/bar.txt', t('Got a valid stream target from public://foo/bar.txt.'));
$this->assertFalse(file_uri_target('foo/bar.txt'), t('foo/bar.txt is not a valid stream.'));
$this->assertEqual(file_uri_target('public://foo/bar.txt'), 'foo/bar.txt', 'Got a valid stream target from public://foo/bar.txt.');
$this->assertFalse(file_uri_target('foo/bar.txt'), 'foo/bar.txt is not a valid stream.');
// Test file_build_uri() and
// Drupal\Core\StreamWrapper\LocalStream::getDirectoryPath().
$this->assertEqual(file_build_uri('foo/bar.txt'), 'public://foo/bar.txt', t('Expected scheme was added.'));
$this->assertEqual(file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(), variable_get('file_public_path'), t('Expected default directory path was returned.'));
$this->assertEqual(file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath(), variable_get('file_temporary_path'), t('Expected temporary directory path was returned.'));
$this->assertEqual(file_build_uri('foo/bar.txt'), 'public://foo/bar.txt', 'Expected scheme was added.');
$this->assertEqual(file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(), variable_get('file_public_path'), 'Expected default directory path was returned.');
$this->assertEqual(file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath(), variable_get('file_temporary_path'), 'Expected temporary directory path was returned.');
variable_set('file_default_scheme', 'private');
$this->assertEqual(file_build_uri('foo/bar.txt'), 'private://foo/bar.txt', t('Got a valid URI from foo/bar.txt.'));
$this->assertEqual(file_build_uri('foo/bar.txt'), 'private://foo/bar.txt', 'Got a valid URI from foo/bar.txt.');
}
/**
* Test the scheme functions.
*/
function testGetValidStreamScheme() {
$this->assertEqual('foo', file_uri_scheme('foo://pork//chops'), t('Got the correct scheme from foo://asdf'));
$this->assertTrue(file_stream_wrapper_valid_scheme(file_uri_scheme('public://asdf')), t('Got a valid stream scheme from public://asdf'));
$this->assertFalse(file_stream_wrapper_valid_scheme(file_uri_scheme('foo://asdf')), t('Did not get a valid stream scheme from foo://asdf'));
$this->assertEqual('foo', file_uri_scheme('foo://pork//chops'), 'Got the correct scheme from foo://asdf');
$this->assertTrue(file_stream_wrapper_valid_scheme(file_uri_scheme('public://asdf')), 'Got a valid stream scheme from public://asdf');
$this->assertFalse(file_stream_wrapper_valid_scheme(file_uri_scheme('foo://asdf')), 'Did not get a valid stream scheme from foo://asdf');
}
}
......@@ -29,20 +29,20 @@ function testNormal() {
// Copying to a new name.
$desired_filepath = 'public://' . $this->randomName();
$new_filepath = file_unmanaged_copy($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($uri), t('Original file remains.'));
$this->assertTrue(file_exists($new_filepath), t('New file exists.'));
$this->assertTrue($new_filepath, 'Copy was successful.');
$this->assertEqual($new_filepath, $desired_filepath, 'Returned expected filepath.');
$this->assertTrue(file_exists($uri), 'Original file remains.');
$this->assertTrue(file_exists($new_filepath), 'New file exists.');
$this->assertFilePermissions($new_filepath, variable_get('file_chmod_file', 0664));
// Copying with rename.
$desired_filepath = 'public://' . $this->randomName();
$this->assertTrue(file_put_contents($desired_filepath, ' '), t('Created a file so a rename will have to happen.'));
$this->assertTrue(file_put_contents($desired_filepath, ' '), 'Created a file so a rename will have to happen.');
$newer_filepath = file_unmanaged_copy($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($uri), t('Original file remains.'));
$this->assertTrue(file_exists($newer_filepath), t('New file exists.'));
$this->assertNotEqual($newer_filepath, $desired_filepath, 'Returned expected filepath.');
$this->assertTrue(file_exists($uri), 'Original file remains.');
$this->assertTrue(file_exists($newer_filepath), '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)
......@@ -55,9 +55,9 @@ function testNormal() {
function testNonExistent() {
// Copy non-existent file
$desired_filepath = $this->randomName();
$this->assertFalse(file_exists($desired_filepath), t("Randomly named file doesn't exists."));
$this->assertFalse(file_exists($desired_filepath), "Randomly named file doesn't exists.");
$new_filepath = file_unmanaged_copy($desired_filepath, $this->randomName());
$this->assertFalse($new_filepath, t('Copying a missing file fails.'));
$this->assertFalse($new_filepath, 'Copying a missing file fails.');
}
/**
......@@ -69,28 +69,28 @@ function testOverwriteSelf() {
// Copy the file onto itself with renaming works.
$new_filepath = file_unmanaged_copy($uri, $uri, FILE_EXISTS_RENAME);
$this->assertTrue($new_filepath, t('Copying onto itself with renaming works.'));
$this->assertNotEqual($new_filepath, $uri, t('Copied file has a new name.'));
$this->assertTrue(file_exists($uri), t('Original file exists after copying onto itself.'));
$this->assertTrue(file_exists($new_filepath), t('Copied file exists after copying onto itself.'));
$this->assertTrue($new_filepath, 'Copying onto itself with renaming works.');
$this->assertNotEqual($new_filepath, $uri, 'Copied file has a new name.');
$this->assertTrue(file_exists($uri), 'Original file exists after copying onto itself.');
$this->assertTrue(file_exists($new_filepath), '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($uri, $uri, FILE_EXISTS_ERROR);
$this->assertFalse($new_filepath, t('Copying onto itself without renaming fails.'));
$this->assertTrue(file_exists($uri), t('File exists after copying onto itself.'));
$this->assertFalse($new_filepath, 'Copying onto itself without renaming fails.');
$this->assertTrue(file_exists($uri), 'File exists after copying onto itself.');
// Copy the file into same directory without renaming fails.
$new_filepath = file_unmanaged_copy($uri, drupal_dirname($uri), FILE_EXISTS_ERROR);
$this->assertFalse($new_filepath, t('Copying onto itself fails.'));
$this->assertFalse($new_filepath, 'Copying onto itself fails.');
$this->assertTrue(file_exists($uri), t('File exists after copying onto itself.'));
// Copy the file into same directory with renaming works.
$new_filepath = file_unmanaged_copy($uri, drupal_dirname($uri), FILE_EXISTS_RENAME);
$this->assertTrue($new_filepath, t('Copying into same directory works.'));
$this->assertNotEqual($new_filepath, $uri, t('Copied file has a new name.'));
$this->assertTrue(file_exists($uri), t('Original file exists after copying onto itself.'));
$this->assertTrue(file_exists($new_filepath), t('Copied file exists after copying onto itself.'));
$this->assertTrue($new_filepath, 'Copying into same directory works.');
$this->assertNotEqual($new_filepath, $uri, 'Copied file has a new name.');
$this->assertTrue(file_exists($uri), 'Original file exists after copying onto itself.');
$this->assertTrue(file_exists($new_filepath), 'Copied file exists after copying onto itself.');
$this->assertFilePermissions($new_filepath, variable_get('file_chmod_file', 0664));
}
}
......@@ -28,8 +28,8 @@ function testSingleFile() {
file_put_contents($filepath, '');
// Delete the file.
$this->assertTrue(file_unmanaged_delete_recursive($filepath), t('Function reported success.'));
$this->assertFalse(file_exists($filepath), t('Test file has been deleted.'));
$this->assertTrue(file_unmanaged_delete_recursive($filepath), 'Function reported success.');
$this->assertFalse(file_exists($filepath), 'Test file has been deleted.');
}
/**
......@@ -40,8 +40,8 @@ function testEmptyDirectory() {
$directory = $this->createDirectory();
// Delete the directory.
$this->assertTrue(file_unmanaged_delete_recursive($directory), t('Function reported success.'));
$this->assertFalse(file_exists($directory), t('Directory has been deleted.'));
$this->assertTrue(file_unmanaged_delete_recursive($directory), 'Function reported success.');
$this->assertFalse(file_exists($directory), 'Directory has been deleted.');
}
/**
......@@ -56,10 +56,10 @@ function testDirectory() {
file_put_contents($filepathB, '');
// Delete the directory.
$this->assertTrue(file_unmanaged_delete_recursive($directory), t('Function reported success.'));
$this->assertFalse(file_exists($filepathA), t('Test file A has been deleted.'));
$this->assertFalse(file_exists($filepathB), t('Test file B has been deleted.'));
$this->assertFalse(file_exists($directory), t('Directory has been deleted.'));
$this->assertTrue(file_unmanaged_delete_recursive($directory), 'Function reported success.');
$this->assertFalse(file_exists($filepathA), 'Test file A has been deleted.');
$this->assertFalse(file_exists($filepathB), 'Test file B has been deleted.');
$this->assertFalse(file_exists($directory), 'Directory has been deleted.');
}
/**
......@@ -75,10 +75,10 @@ function testSubDirectory() {
file_put_contents($filepathB, '');
// Delete the directory.
$this->assertTrue(file_unmanaged_delete_recursive($directory), t('Function reported success.'));
$this->assertFalse(file_exists($filepathA), t('Test file A has been deleted.'));
$this->assertFalse(file_exists($filepathB), t('Test file B has been deleted.'));
$this->assertFalse(file_exists($subdirectory), t('Subdirectory has been deleted.'));
$this->assertFalse(file_exists($directory), t('Directory has been deleted.'));
$this->assertTrue(file_unmanaged_delete_recursive($directory), 'Function reported success.');
$this->assertFalse(file_exists($filepathA), 'Test file A has been deleted.');
$this->assertFalse(file_exists($filepathB), 'Test file B has been deleted.');
$this->assertFalse(file_exists($subdirectory), 'Subdirectory has been deleted.');
$this->assertFalse(file_exists($directory), 'Directory has been deleted.');
}
}
......@@ -27,8 +27,8 @@ function testNormal() {
$uri = $this->createUri();
// Delete a regular file
$this->assertTrue(file_unmanaged_delete($uri), t('Deleted worked.'));
$this->assertFalse(file_exists($uri), t('Test file has actually been deleted.'));
$this->assertTrue(file_unmanaged_delete($uri), 'Deleted worked.');
$this->assertFalse(file_exists($uri), 'Test file has actually been deleted.');
}
/**
......@@ -36,7 +36,7 @@ function testNormal() {
*/
function testMissing() {
// Try to delete a non-existing file
$this->assertTrue(file_unmanaged_delete(file_default_scheme() . '/' . $this->randomName()), t('Returns true when deleting a non-existent file.'));
$this->assertTrue(file_unmanaged_delete(file_default_scheme() . '/' . $this->randomName()), 'Returns true when deleting a non-existent file.');
}
/**
......@@ -47,7 +47,7 @@ function testDirectory() {
$directory = $this->createDirectory();
// Try to delete a directory
$this->assertFalse(file_unmanaged_delete($directory), t('Could not delete the delete directory.'));
$this->assertTrue(file_exists($directory), t('Directory has not been deleted.'));
$this->assertFalse(file_unmanaged_delete($directory), 'Could not delete the delete directory.');
$this->assertTrue(file_exists($directory), 'Directory has not been deleted.');
}
}
......@@ -29,21 +29,21 @@ function testNormal() {
// Moving to a new name.
$desired_filepath = 'public://' . $this->randomName();
$new_filepath = file_unmanaged_move($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($uri), t('No file remains at the old location.'));
$this->assertTrue($new_filepath, 'Move was successful.');
$this->assertEqual($new_filepath, $desired_filepath, 'Returned expected filepath.');
$this->assertTrue(file_exists($new_filepath), 'File exists at the new location.');
$this->assertFalse(file_exists($uri), 'No file remains at the old location.');
$this->assertFilePermissions($new_filepath, variable_get('file_chmod_file', 0664));
// Moving with rename.
$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.'));
$this->assertTrue(file_exists($new_filepath), 'File exists before moving.');
$this->assertTrue(file_put_contents($desired_filepath, ' '), 'Created a file so a rename will have to happen.');
$newer_filepath = file_unmanaged_move($new_filepath, $desired_filepath, FILE_EXISTS_RENAME);
$this->assertTrue($newer_filepath, t('Move was successful.'));
$this->assertNotEqual($newer_filepath, $desired_filepath, t('Returned expected filepath.'));
$this->assertTrue(file_exists($newer_filepath), t('File exists at the new location.'));
$this->assertFalse(file_exists($new_filepath), t('No file remains at the old location.'));
$this->assertTrue($newer_filepath, 'Move was successful.');
$this->assertNotEqual($newer_filepath, $desired_filepath, 'Returned expected filepath.');
$this->assertTrue(file_exists($newer_filepath), 'File exists at the new location.');
$this->assertFalse(file_exists($new_filepath), 'No file remains at the old location.');
$this->assertFilePermissions($newer_filepath, variable_get('file_chmod_file', 0664));
// TODO: test moving to a directory (rather than full directory/file path)
......@@ -56,7 +56,7 @@ function testNormal() {
function testMissing() {
// Move non-existent file.
$new_filepath = file_unmanaged_move($this->randomName(), $this->randomName());
$this->assertFalse($new_filepath, t('Moving a missing file fails.'));
$this->assertFalse($new_filepath, 'Moving a missing file fails.');
}
/**
......@@ -68,13 +68,13 @@ function testOverwriteSelf() {
// Move the file onto itself without renaming shouldn't make changes.
$new_filepath = file_unmanaged_move($uri, $uri, FILE_EXISTS_REPLACE);
$this->assertFalse($new_filepath, t('Moving onto itself without renaming fails.'));
$this->assertTrue(file_exists($uri), t('File exists after moving onto itself.'));
$this->assertFalse($new_filepath, 'Moving onto itself without renaming fails.');
$this->assertTrue(file_exists($uri), 'File exists after moving onto itself.');
// Move the file onto itself with renaming will result in a new filename.
$new_filepath = file_unmanaged_move($uri, $uri, FILE_EXISTS_RENAME);
$this->assertTrue($new_filepath, t('Moving onto itself with renaming works.'));
$this->assertFalse(file_exists($uri), t('Original file has been removed.'));
$this->assertTrue(file_exists($new_filepath), t('File exists after moving onto itself.'));
$this->assertTrue($new_filepath, 'Moving onto itself with renaming works.');
$this->assertFalse(file_exists($uri), 'Original file has been removed.');
$this->assertTrue(file_exists($new_filepath), 'File exists after moving onto itself.');
}
}
......@@ -27,15 +27,15 @@ function testFileSaveData() {
// No filename.
$filepath = file_unmanaged_save_data($contents);
$this->assertTrue($filepath, t('Unnamed file saved correctly.'));
$this->assertEqual(file_uri_scheme($filepath), file_default_scheme(), t("File was placed in Drupal's files directory."));
$this->assertEqual($contents, file_get_contents($filepath), t('Contents of the file are correct.'));
$this->assertTrue($filepath, 'Unnamed file saved correctly.');
$this->assertEqual(file_uri_scheme($filepath), file_default_scheme(), "File was placed in Drupal's files directory.");
$this->assertEqual($contents, file_get_contents($filepath), 'Contents of the file are correct.');
// Provide a filename.
$filepath = file_unmanaged_save_data($contents, 'public://asdf.txt', FILE_EXISTS_REPLACE);
$this->assertTrue($filepath, t('Unnamed file saved correctly.'));
$this->assertEqual('asdf.txt', drupal_basename($filepath), t('File was named correctly.'));
$this->assertEqual($contents, file_get_contents($filepath), t('Contents of the file are correct.'));
$this->assertTrue($filepath, 'Unnamed file saved correctly.');
$this->assertEqual('asdf.txt', drupal_basename($filepath), 'File was named correctly.');
$this->assertEqual($contents, file_get_contents($filepath), 'Contents of the file are correct.');
$this->assertFilePermissions($filepath, variable_get('file_chmod_file', 0664));
}
}
......@@ -38,28 +38,28 @@ function testShippedFileURL() {
variable_set('file_test_hook_file_url_alter', 'cdn');
$filepath = 'core/misc/jquery.js';
$url = file_create_url($filepath);
$this->assertEqual(FILE_URL_TEST_CDN_1 . '/' . $filepath, $url, t('Correctly generated a CDN URL for a shipped file.'));
$this->assertEqual(FILE_URL_TEST_CDN_1 . '/' . $filepath, $url, 'Correctly generated a CDN URL for a shipped file.');
$filepath = 'core/misc/favicon.ico';
$url = file_create_url($filepath);
$this->assertEqual(FILE_URL_TEST_CDN_2 . '/' . $filepath, $url, t('Correctly generated a CDN URL for a shipped file.'));
$this->assertEqual(FILE_URL_TEST_CDN_2 . '/' . $filepath, $url, 'Correctly generated a CDN URL for a shipped file.');
// Test alteration of file URLs to use root-relative URLs.
variable_set('file_test_hook_file_url_alter', 'root-relative');
$filepath = 'core/misc/jquery.js';
$url = file_create_url($filepath);
$this->assertEqual(base_path() . '/' . $filepath, $url, t('Correctly generated a root-relative URL for a shipped file.'));
$this->assertEqual(base_path() . '/' . $filepath, $url, 'Correctly generated a root-relative URL for a shipped file.');
$filepath = 'core/misc/favicon.ico';
$url = file_create_url($filepath);
$this->assertEqual(base_path() . '/' . $filepath, $url, t('Correctly generated a root-relative URL for a shipped file.'));
$this->assertEqual(base_path() . '/' . $filepath, $url, 'Correctly generated a root-relative URL for a shipped file.');
// Test alteration of file URLs to use protocol-relative URLs.
variable_set('file_test_hook_file_url_alter', 'protocol-relative');
$filepath = 'core/misc/jquery.js';
$url = file_create_url($filepath);
$this->assertEqual('/' . base_path() . '/' . $filepath, $url, t('Correctly generated a protocol-relative URL for a shipped file.'));
$this->assertEqual('/' . base_path() . '/' . $filepath, $url, 'Correctly generated a protocol-relative URL for a shipped file.');
$filepath = 'core/misc/favicon.ico';
$url = file_create_url($filepath);
$this->assertEqual('/' . base_path() . '/' . $filepath, $url, t('Correctly generated a protocol-relative URL for a shipped file.'));
$this->assertEqual('/' . base_path() . '/' . $filepath, $url, 'Correctly generated a protocol-relative URL for a shipped file.');
}
/**
......@@ -73,18 +73,18 @@ function testPublicCreatedFileURL() {
$uri = $this->createUri();
$url = file_create_url($uri);
$public_directory_path = file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath();
$this->assertEqual(FILE_URL_TEST_CDN_2 . '/' . $public_directory_path . '/' . drupal_basename($uri), $url, t('Correctly generated a CDN URL for a created file.'));
$this->assertEqual(FILE_URL_TEST_CDN_2 . '/' . $public_directory_path . '/' . drupal_basename($uri), $url, 'Correctly generated a CDN URL for a created file.');
// Test alteration of file URLs to use root-relative URLs.
variable_set('file_test_hook_file_url_alter', 'root-relative');
$uri = $this->createUri();
$url = file_create_url($uri);
$this->assertEqual(base_path() . '/' . $public_directory_path . '/' . drupal_basename($uri), $url, t('Correctly generated a root-relative URL for a created file.'));
$this->assertEqual(base_path() . '/' . $public_directory_path . '/' . drupal_basename($uri), $url, 'Correctly generated a root-relative URL for a created file.');
// Test alteration of file URLs to use a protocol-relative URLs.
variable_set('file_test_hook_file_url_alter', 'protocol-relative');
$uri = $this->createUri();
$url = file_create_url($uri);
$this->assertEqual('/' . base_path() . '/' . $public_directory_path . '/' . drupal_basename($uri), $url, t('Correctly generated a protocol-relative URL for a created file.'));
$this->assertEqual('/' . base_path() . '/' . $public_directory_path . '/' . drupal_basename($uri), $url, 'Correctly generated a protocol-relative URL for a created file.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment