You are here

public function UninstallTest::testUninstall in FillPDF 8.4

Same name and namespace in other branches
  1. 5.0.x tests/src/Functional/UninstallTest.php \Drupal\Tests\fillpdf\Functional\UninstallTest::testUninstall()

Tests uninstalling the module.

File

tests/src/Functional/UninstallTest.php, line 54

Class

UninstallTest
Tests uninstalling the module.

Namespace

Drupal\Tests\fillpdf\Functional

Code

public function testUninstall() {
  $this
    ->uploadTestPdf('fillpdf_test_v3.pdf');

  // Go to the uninstall page and check the requirements.
  $this
    ->drupalGet(Url::fromRoute('system.modules_uninstall'));
  $this
    ->assertSession()
    ->pageTextContains('The following reasons prevent FillPDF from being uninstalled');
  $this
    ->assertSession()
    ->pageTextContains('There is content for the entity type: FillPDF form. Remove fillpdf form entities');
  $this
    ->assertSession()
    ->pageTextNotContains('There is content for the entity type: FillPDF form field. Remove fillpdf form field entities');

  // Check the fillpdf form fields are discovered.
  $this
    ->drupalGet(Url::fromRoute('system.prepare_modules_entity_uninstall', [
    'entity_type_id' => 'fillpdf_form_field',
  ]));
  $this
    ->assertSession()
    ->pageTextContains('This will delete 4 fillpdf form field entities');

  // Now delete all fillpdf forms.
  $this
    ->drupalGet(Url::fromRoute('system.prepare_modules_entity_uninstall', [
    'entity_type_id' => 'fillpdf_form',
  ]));
  $this
    ->assertSession()
    ->pageTextContains('Are you sure you want to delete all fillpdf form entities?');
  $this
    ->drupalPostForm(NULL, [], 'Delete all fillpdf form entities');
  $this
    ->assertSession()
    ->pageTextContains('All fillpdf form entities have been deleted');

  // Make sure all fillpdf form fields have been deleted as well.
  $this
    ->drupalGet(Url::fromRoute('system.prepare_modules_entity_uninstall', [
    'entity_type_id' => 'fillpdf_form_field',
  ]));
  $this
    ->assertSession()
    ->pageTextContains('There are 0 fillpdf form field entities to delete');

  // Now go back to the uninstall page and uninstall fillpdf_test and fillpdf.
  foreach ([
    'fillpdf_test',
    'fillpdf_legacy',
    'fillpdf',
  ] as $module) {
    $this
      ->drupalPostForm(Url::fromRoute('system.modules_uninstall'), [
      "uninstall[{$module}]" => TRUE,
    ], 'Uninstall');
    $this
      ->assertSession()
      ->pageTextContains('The following modules will be completely uninstalled from your site, and all data from these modules will be lost');
    $this
      ->drupalPostForm(NULL, [], 'Uninstall');
    $this
      ->assertSession()
      ->pageTextContains('The selected modules have been uninstalled');
  }
}