public function AuditFilesManagedNotUsedTest::testFileEntityCanBeDeleted in Audit Files 8.2
Same name and namespace in other branches
- 8.3 tests/src/Functional/AuditFilesManagedNotUsedTest.php \Drupal\Tests\auditfiles\Functional\AuditFilesManagedNotUsedTest::testFileEntityCanBeDeleted()
Tests that an orphan file can be deleted.
An "orphan" file entity is one with an entry in the file_managed table that has no corresponding file in the file_usage table.
File
- tests/
src/ Functional/ AuditFilesManagedNotUsedTest.php, line 96
Class
- AuditFilesManagedNotUsedTest
- Tests that the "Managed not used" report is reachable with no errors.
Namespace
Drupal\Tests\auditfiles\FunctionalCode
public function testFileEntityCanBeDeleted() {
// Form to test.
$path = URL::fromRoute('auditfiles.audit_files_managednotused');
// Establish session.
$session = $this
->assertSession();
// Log in as admin user.
$this
->drupalLogin($this->user);
// Load the report page.
$this
->drupalGet($path);
// Check for the report title.
$session
->pageTextContains("Managed not used");
$session
->elementExists('css', '#edit-files-1');
// Check box for file ID to delete from database, and delete.
$edit = [
'edit-files-1' => TRUE,
];
$this
->submitForm($edit, 'Delete selected items from the file_managed table');
// Check for correct confirmation page and submit.
$session
->pageTextContains("Delete these items from the file_managed table?");
$session
->pageTextContains('example_1.png');
$edit = [];
$this
->submitForm($edit, 'Confirm');
// Check that target file is no longer listed.
$this
->drupalGet($path);
$session
->pageTextContains("Managed not used");
$session
->pageTextNotContains('example_1.png');
$session
->elementNotExists('css', '#edit-files-1');
}