FillPdfFormDeleteFormTest.php in FillPDF 5.0.x
File
tests/src/Functional/FillPdfFormDeleteFormTest.php
View source
<?php
namespace Drupal\Tests\fillpdf\Functional;
use Drupal\fillpdf\Entity\FillPdfForm;
use Drupal\fillpdf\Entity\FillPdfFormField;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\fillpdf\Traits\TestFillPdfTrait;
use Drupal\Core\Url;
class FillPdfFormDeleteFormTest extends BrowserTestBase {
use TestFillPdfTrait;
public static $modules = [
'fillpdf_test',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->configureFillPdf();
$this
->initializeUser();
}
public function testDeleteFormCancel() {
$this
->uploadTestPdf('fillpdf_test_v3.pdf');
$fillpdf_form = FillPdfForm::load($this
->getLatestFillPdfForm());
$this
->assertSession()
->pageTextContains('New FillPDF form has been created.');
$admin_title = 'Test';
$this
->drupalPostForm(NULL, [
'admin_title[0][value]' => $admin_title,
], 'Save');
$this
->assertSession()
->pageTextContains("FillPDF Form {$admin_title} has been updated.");
$this
->clickLink('Delete');
$this
->assertSession()
->pageTextContains("Are you sure you want to delete {$admin_title}?");
$this
->clickLink('Cancel');
$this
->assertSession()
->addressEquals($fillpdf_form
->toUrl('canonical'));
$overview_url = Url::fromRoute('fillpdf.forms_admin');
$this
->drupalGet($overview_url);
$this
->clickLink('Delete');
$this
->assertSession()
->pageTextContains("Are you sure you want to delete {$admin_title}?");
$this
->clickLink('Cancel');
$this
->assertSession()
->addressEquals($overview_url);
$this
->drupalGet($overview_url);
$this
->clickLink('Edit');
$this
->clickLink('Delete');
$this
->assertSession()
->pageTextContains("Are you sure you want to delete {$admin_title}?");
$this
->clickLink('Cancel');
$this
->assertSession()
->addressEquals($fillpdf_form
->toUrl('canonical'));
}
public function testDeleteForm() {
$this
->uploadTestPdf('fillpdf_test_v3.pdf');
$form_id = $this
->getLatestFillPdfForm();
$field_ids = \Drupal::entityQuery('fillpdf_form_field')
->condition('fillpdf_form', $form_id)
->execute();
$this
->assertCount(4, $field_ids, "4 FillPdfFormFields have been created.");
$this
->clickLink('Delete');
$this
->drupalPostForm(NULL, NULL, 'Delete');
$this
->assertSession()
->pageTextContains('FillPDF form deleted.');
$this
->assertSession()
->addressEquals(Url::fromRoute('fillpdf.forms_admin'));
$this
->assertNull(FillPdfForm::load($form_id), "The FillPdfForm #{$form_id} doesn't exist anymore.");
foreach ($field_ids as $id) {
$this
->assertNull(FillPdfFormField::load($id), "The FillPdfFormField #{$id} doesn't exist anymore.");
}
}
}