You are here

public function AuditFilesUsedNotManagedTest::testFileEntityCanBeDeleted in Audit Files 4.x

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/FunctionalJavascript/AuditFilesUsedNotManagedTest.php, line 96

Class

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

Namespace

Drupal\Tests\auditfiles\FunctionalJavascript

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");

  // 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?");
  $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.");
}