public function TestSubContext::createManagedFile in Drupal Commons 7.3
Copies the provided file into the site's files directory.
@Given the managed file :filename
Creates a file object with the URI, and passes that object to a file creation function to create the entity. The function has to be here for now, as it needs some Mink functions.
@todo See if it can be done without Mink functions? @todo Allow creating private files. @todo Add before and after event dispatchers. @todo Add ability to create multiple files at once using Table.
File
- tests/
steps/ commons_test.behat.inc, line 168 - Provide Behat step-definitions for generic Commons tests.
Class
Code
public function createManagedFile($filename, $public = TRUE) {
// Get location of source file.
if ($this
->getMinkParameter('files_path')) {
$source_path = rtrim(realpath($this
->getMinkParameter('files_path'))) . DIRECTORY_SEPARATOR . $filename;
if (!is_file($source_path)) {
throw new \Exception(sprintf("Cannot find the file at '%s'", $source_path));
}
}
else {
throw new \Exception("files_path not set");
}
$prefix = $public ? 'public://' : 'private://';
$uri = $prefix . $filename;
$this
->fileCreate($source_path, $uri);
}