You are here

public function ServicesResourceNodetests::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.

1 call to ServicesResourceNodetests::uploadTestFile()
ServicesResourceNodetests::testNodeRelationshipFiles in tests/functional/ServicesResourceNodeTests.test
Test files relationship.

File

tests/functional/ServicesResourceNodeTests.test, line 522

Class

ServicesResourceNodetests
Run test cases for the endpoint with no authentication turned on.

Code

public function uploadTestFile($file = NULL) {
  if (empty($file)) {
    $file = next($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);
  file_check_directory($dirname, FILE_CREATE_DIRECTORY);
  file_copy($source, $destination);
  drupal_write_record('files', $testfile);
  return $testfile;
}