public function TestSubContext::fileCreate in Drupal Commons 7.3
Create a managed Drupal file.
Parameters
$source_path: A file object passed in with the URI already set.
$destination: (Optional) The desired URI where the file will be uploaded.
Return value
A single Drupal file object.
1 call to TestSubContext::fileCreate()
- TestSubContext::createManagedFile in tests/
steps/ commons_test.behat.inc - Copies the provided file into the site's files directory.
File
- tests/
steps/ commons_test.behat.inc, line 196 - Provide Behat step-definitions for generic Commons tests.
Class
Code
public function fileCreate($source_path, $destination = NULL) {
$data = file_get_contents($source_path);
// Before working with files, we need to change our current directory to
// DRUPAL_ROOT so that the relative paths that define the stream wrappers
// (like public:// or temporary://) actually work.
$cwd = getcwd();
chdir(DRUPAL_ROOT);
if ($file = file_save_data($data, $destination)) {
$this->files[] = $file;
}
// Then change back.
chdir($cwd);
return $file;
}