You are here

public function AuditFilesReferencedNotUsedTest::testFileEntityCanBeDeletedFromFileUsageTable in Audit Files 8.3

Same name and namespace in other branches
  1. 8.2 tests/src/FunctionalJavascript/AuditFilesReferencedNotUsedTest.php \Drupal\Tests\auditfiles\FunctionalJavascript\AuditFilesReferencedNotUsedTest::testFileEntityCanBeDeletedFromFileUsageTable()
  2. 4.x tests/src/FunctionalJavascript/AuditFilesReferencedNotUsedTest.php \Drupal\Tests\auditfiles\FunctionalJavascript\AuditFilesReferencedNotUsedTest::testFileEntityCanBeDeletedFromFileUsageTable()

Tests that orphan file entity can be deleted from file_usage.

An "orphan" file entity is one with an entry in the file_managed and a refererence in existence in a field, but has no corresponding file in the file_usage table.

File

tests/src/FunctionalJavascript/AuditFilesReferencedNotUsedTest.php, line 203

Class

AuditFilesReferencedNotUsedTest
Tests that the "Referenced not used" report is reachable with no errors.

Namespace

Drupal\Tests\auditfiles\FunctionalJavascript

Code

public function testFileEntityCanBeDeletedFromFileUsageTable() {

  // Delete file_usage entry.
  \Drupal::database()
    ->query("DELETE FROM {file_usage} WHERE type='node' AND fid='1'")
    ->execute();

  // Form to test.
  $path = Url::fromRoute('auditfiles.audit_files_referencednotused');

  // 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("Referenced not used");
  $session
    ->elementExists('css', '#audit-files-referenced-not-used');
  $session
    ->elementExists('xpath', '//*[@id="edit-files"]/tbody/tr[1]/td[1]/div/input');
  $edit = [
    'edit-files-node-field-imagefield-image-target-id1node1' => TRUE,
  ];
  $this
    ->submitForm($edit, 'Delete selected references');

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

  // Check that target file is no longer listed.
  $session
    ->waitForElementVisible('css', '#audit-files-referenced-not-used');
  $session
    ->pageTextContains("Referenced not used");
  $session
    ->elementNotExists('css', '#edit-files-node-field-imagefield-image-target-id1node1');
  $session
    ->pageTextContains("file ID 1 deleted successfully.");
  $session
    ->pageTextContains("No items found.");
}