public function ServicesResourceFileTests::uploadTestFile in Services 6.3
Emulate uploaded file.
Copy file from simpletest file samples and create record in files table.
Return value
array File data.
2 calls to ServicesResourceFileTests::uploadTestFile()
- ServicesResourceFileTests::testResourceFileDelete in tests/
functional/ ServicesResourceFileTests.test - Test delete method.
- ServicesResourceFileTests::testResourceFileRetrieve in tests/
functional/ ServicesResourceFileTests.test - Test retrieve method.
File
- tests/
functional/ ServicesResourceFileTests.test, line 165
Class
- ServicesResourceFileTests
- Test class.
Code
public function uploadTestFile($file = NULL) {
if (empty($file)) {
$file = current($this->testfiles);
}
$testfile = array(
'fid' => NULL,
'uid' => $this->privileged_user->uid,
'filename' => trim(basename($file->filename), '.'),
'filepath' => $file->filename,
'filemime' => file_get_mimetype($file->filename),
'filesize' => filesize($file->filename),
'status' => FILE_STATUS_PERMANENT,
'timestamp' => time(),
);
$source = $testfile['filepath'];
$destination = file_directory_path() . '/' . $testfile['filepath'];
$dirname = dirname($destination);
// Build the destination folder tree if it doesn't already exists.
// @see http://drupal.org/node/180970
$dir_array = explode('/', $dirname);
$file_check_directory_array = array();
foreach ($dir_array as $dir_element) {
$file_check_directory_array[] = $dir_element;
$dir_path_element = implode('/', $file_check_directory_array);
file_check_directory($dir_path_element, FILE_CREATE_DIRECTORY);
}
file_copy($source, $destination);
drupal_write_record('files', $testfile);
return $testfile;
}