public function MediaWYSIWYGFileUsageTest::testFileUsageIncrementingDelete in D7 Media 7.4
Same name and namespace in other branches
- 7.2 modules/media_wysiwyg/tests/media_wysiwyg.file_usage.test \MediaWYSIWYGFileUsageTest::testFileUsageIncrementingDelete()
- 7.3 modules/media_wysiwyg/tests/media_wysiwyg.file_usage.test \MediaWYSIWYGFileUsageTest::testFileUsageIncrementingDelete()
Tests the behavior of node and file deletion.
File
- modules/
media_wysiwyg/ tests/ media_wysiwyg.file_usage.test, line 167 - Tests for the file usage in entity fields with the Media filter markup.
Class
- MediaWYSIWYGFileUsageTest
- @file Tests for the file usage in entity fields with the Media filter markup.
Code
public function testFileUsageIncrementingDelete() {
// Create a node with file markup in the body field with a new file.
$files = $this
->drupalGetTestFiles('image');
$file = file_save($files[1]);
$fid = $file->fid;
$file_uses = file_usage_list($file);
$this
->assertEqual(empty($file_uses), TRUE, t('Created a new file with zero uses.'));
// Create a new node with file markup.
$nid = $this
->createNode($fid);
$file_uses = file_usage_list($file);
$this
->assertEqual($file_uses['media']['node'][$nid], 1, t('Incremented file usage on node save.'));
// Try to delete the file. file_delete() should return file_usage().
$deleted = file_delete($file);
$this
->assertTrue(is_array($deleted), t('File cannot be deleted while in use by a node.'));
// Delete the node.
node_delete($nid);
$node = node_load($nid);
$file_uses = file_usage_list($file);
$this
->assertEqual(empty($node), TRUE, t('Node has been deleted.'));
$this
->assertEqual(empty($file_uses), TRUE, t('File has zero usage after node is deleted.'));
$deleted = file_delete($file);
$this
->assertTrue($deleted, t('File can be deleted with no usage.'));
$file = file_load($fid);
$this
->assertTrue(empty($file), t('File no longer exists after delete.'));
}