function EditorFileUsageTest::testFileUsageForcefullyDeleted in Editor 7
Tests usage tracking after forcefully deleting content or files.
File
- ./
editor.test, line 1255 - Tests for Editor module.
Class
- EditorFileUsageTest
- Tests file usage.
Code
function testFileUsageForcefullyDeleted() {
// Create a file.
$files = $this
->drupalGetTestFiles('image');
$file = file_save($files[1]);
$fid = $file->fid;
// The file should start without any usage.
$file_uses = file_usage_list($file);
$this
->assertEqual(empty($file_uses), TRUE, t('Created a new file without any usage.'));
// Create a node with an embedded file.
$content = '<img src="awesome-llama.jpg" data-entity-type="file" data-entity-id="' . $fid . '" />';
$settings = array();
$settings['body'] = array(
LANGUAGE_NONE => array(
array(
'value' => $content,
'format' => 'custom_format',
),
),
);
$node = $this
->drupalCreateNode($settings);
$nid = $node->nid;
// Verify that file usage increased.
$file_uses = file_usage_list($file);
$this
->assertEqual($file_uses['editor']['node'][$nid], 1, t('File usage increases after embedding a file in a new node.'));
// Forcefully delete the file.
$deleted = file_delete($file, TRUE);
$this
->assertTrue($deleted, t('File was deleted despite having usage.'));
// Try to update the node that references a non-existent file.
$account = $this
->drupalCreateUser(array(
'edit any page content',
'use text format custom_format',
));
$node = node_load($nid);
$this
->drupalLogin($account);
$this
->drupalGet('node/' . $nid . '/edit');
$this
->assertRaw(check_plain($node->body['und'][0]['value']), t('Reference to deleted file found in node body.'));
$edit = array(
'body[und][0][value]' => '',
);
$this
->drupalPost(NULL, $edit, t('Save'));
// Verify that the node was save successfully.
$type = node_type_load($node->type);
$this
->assertRaw(t('@type %title has been updated.', array(
'@type' => $type->name,
'%title' => $node->title,
)), t('Node without reference to deleted file saved successfully.'));
}