public function TestSubContext::cleanFiles in Panopoly 7
Same name and namespace in other branches
- 8.2 modules/panopoly/panopoly_test/behat/steps/panopoly_test.behat.inc \TestSubContext::cleanFiles()
Cleans up files after every scenario.
@AfterScenario @api
File
- modules/
panopoly/ panopoly_test/ behat/ steps/ panopoly_test.behat.inc, line 526 - Provide Behat step-definitions for generic Panopoly tests.
Class
Code
public function cleanFiles($event) {
// Get UIDs of users created during this scenario.
$uids = $this
->getUIDs();
if (!empty($uids)) {
// Add any files created by test users to the $files variable.
$file_ids = db_query('SELECT fid FROM {file_managed} WHERE uid IN (:uids)', array(
':uids' => $uids,
))
->fetchAll();
if (!empty($file_ids)) {
// The file_delete() function expects an object.
foreach ($file_ids as $fid) {
$file = file_load($fid->fid);
$this->files[] = $file;
}
}
}
// Delete any files that were created by test users or our Given step.
if (!empty($this->files)) {
foreach ($this->files as $file) {
$this
->fileDelete($file);
}
}
// Reset the arrays to empty after deletion.
$this->files = array();
}