public function TestSubContext::cleanFiles in Drupal Commons 7.3
Cleans up files after every scenario.
@AfterScenario @api
File
- tests/
steps/ commons_test.behat.inc, line 247 - Provide Behat step-definitions for generic Commons 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();
}