function EntityEmbedFileUsageTest::testFileUsageForcefullyDeleted in Entity Embed 7
Same name and namespace in other branches
- 7.2 entity_embed.test \EntityEmbedFileUsageTest::testFileUsageForcefullyDeleted()
Tests usage tracking after forcefully deleting content or files.
File
- ./
entity_embed.test, line 757 - Test integration for the entity_embed module.
Class
- EntityEmbedFileUsageTest
- 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 = '<drupal-entity data-entity-type="file" data-entity-id="' . $fid . '" data-view-mode="full"></drupal-entity>';
$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['entity_embed']['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.'));
}