You are here

public function AuditFilesNotInDatabaseTest::testFileCanBeDeleted in Audit Files 8.2

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/AuditFilesNotInDatabaseTest.php \Drupal\Tests\auditfiles\Functional\AuditFilesNotInDatabaseTest::testFileCanBeDeleted()

Tests that an orphan file can be deleted.

An "orphan" file is one in the file system that has no corresponding record in the database.

File

tests/src/Functional/AuditFilesNotInDatabaseTest.php, line 119

Class

AuditFilesNotInDatabaseTest
Tests that the "Not in Database" report is reachable with no errors.

Namespace

Drupal\Tests\auditfiles\Functional

Code

public function testFileCanBeDeleted() {

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

  // 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("Not in database");
  $session
    ->elementExists('css', '#edit-files-html-2html');

  // Check box for file to delete from server, and submit form.
  $edit = [
    'edit-files-html-2html' => TRUE,
  ];
  $this
    ->submitForm($edit, 'Delete selected items from the server');

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

  // Check that target file is no longer listed.
  $session
    ->pageTextContains("Not in database");
  $session
    ->pageTextContains("Sucessfully deleted html-2.html from the server.");
  $session
    ->elementNotExists('css', '#edit-files-html-2html');
}