You are here

public function AuditFilesUsedNotManagedTest::testFileEntityCanBeDeleted in Audit Files 8.2

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/AuditFilesUsedNotManagedTest.php \Drupal\Tests\auditfiles\Functional\AuditFilesUsedNotManagedTest::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/AuditFilesUsedNotManagedTest.php, line 105

Class

AuditFilesUsedNotManagedTest
Tests that the "Used not managed" report is reachable with no errors.

Namespace

Drupal\Tests\auditfiles\Functional

Code

public function testFileEntityCanBeDeleted() {

  // Form to test.
  $path = URL::fromRoute('auditfiles.audit_files_usednotmanaged');

  // 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("Used not managed");
  $session
    ->pageTextContains("Found at least 3 files in the file_usage table that are not in the file_managed table.");
  $session
    ->elementExists('css', '#audit-files-used-not-managed');
  $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_usage table');

  // Check for correct confirmation page and submit.
  $session
    ->pageTextContains("Delete these items from the file_usage table?");
  $session
    ->pageTextContains("File ID 1 will be deleted from the file_usage table.");
  $edit = [];
  $this
    ->submitForm($edit, 'Confirm');

  // Check that target file is no longer listed.
  $session
    ->pageTextContains("Used not managed");
  $session
    ->pageTextContains("Sucessfully deleted File ID : 1 from the file_usages table.");
  $session
    ->pageTextContains("Found at least 2 files in the file_usage table that are not in the file_managed table.");
  $session
    ->elementNotExists('css', '#edit-files-1');
}