You are here

public function TestSubContext::fileDelete in Panopoly 7

Same name and namespace in other branches
  1. 8.2 modules/panopoly/panopoly_test/behat/steps/panopoly_test.behat.inc \TestSubContext::fileDelete()

Delete a managed Drupal file.

Parameters

$file: A file object to delete.

1 call to TestSubContext::fileDelete()
TestSubContext::cleanFiles in modules/panopoly/panopoly_test/behat/steps/panopoly_test.behat.inc
Cleans up files after every scenario.

File

modules/panopoly/panopoly_test/behat/steps/panopoly_test.behat.inc, line 559
Provide Behat step-definitions for generic Panopoly tests.

Class

TestSubContext

Code

public function fileDelete($file) {

  // Figure out if there's usage in any nodes.
  $fid = $file->fid;
  $node_usage = db_query('SELECT id AS nid FROM {file_usage} WHERE fid = (:fid) AND module = (:module) and type = (:node)', array(
    ':fid' => $fid,
    ':module' => 'media',
    ':node' => 'node',
  ))
    ->fetchAll();

  // If there is, it should be safe to unregister it, because we already know the file is owned by a current test user.
  if (!empty($node_usage)) {
    foreach ($node_usage as $nid) {
      file_usage_delete($file, 'media', 'node', $nid->nid);
    }
  }

  // See PanopolyContext::fileCreate() for information on why we do this.
  $cwd = getcwd();
  chdir(DRUPAL_ROOT);
  file_delete($file);
  chdir($cwd);
}