UninstallTest.php in FillPDF 5.0.x        
                          
                  
                        
  
  
  
  
File
  tests/src/Functional/UninstallTest.php
  
    View source  
  <?php
namespace Drupal\Tests\fillpdf\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\fillpdf\Traits\TestFillPdfTrait;
use Drupal\Core\Url;
class UninstallTest extends BrowserTestBase {
  use TestFillPdfTrait;
  
  public static $modules = [
    'fillpdf_test',
  ];
  
  protected $defaultTheme = 'stark';
  
  protected $adminUser;
  
  protected function setUp() : void {
    parent::setUp();
    $this
      ->configureFillPdf();
    $this->adminUser = $this
      ->drupalCreateUser([
      'access administration pages',
      'administer modules',
      'administer pdfs',
    ]);
    $this
      ->drupalLogin($this->adminUser);
  }
  
  public function testUninstall() {
    $this
      ->uploadTestPdf('fillpdf_test_v3.pdf');
    
    $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');
    
    $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');
    
    $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');
    
    $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');
    
    foreach ([
      'fillpdf_test',
      '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');
    }
  }
}