public function TestSubContext::createManagedFile in Panopoly 8.2
Same name and namespace in other branches
- 7 modules/panopoly/panopoly_test/behat/steps/panopoly_test.behat.inc \TestSubContext::createManagedFile()
 
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
- modules/
panopoly/ panopoly_test/ behat/ steps/ panopoly_test.behat.inc, line 457  - Provide Behat step-definitions for generic Panopoly tests.
 
Class
- TestSubContext
 - Behat sub-context for Panopoly.
 
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);
}