FillPdfFormDuplicateFormTest.php in FillPDF 5.0.x
File
tests/src/Functional/FillPdfFormDuplicateFormTest.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 FillPdfFormDuplicateFormTest extends BrowserTestBase {
use TestFillPdfTrait;
public static $modules = [
'fillpdf_test',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->configureFillPdf();
$this
->initializeUser();
}
public function testDuplicateForm() {
$this
->uploadTestPdf('fillpdf_test_v3.pdf');
$form_id = $this
->getLatestFillPdfForm();
$template_fid = FillPdfForm::load($form_id)->fid->value;
$field_ids = \Drupal::entityQuery('fillpdf_form_field')
->condition('fillpdf_form', $form_id)
->execute();
$this
->assertCount(4, $field_ids, "4 FillPdfFormFields have been created.");
$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.");
$overview_url = Url::fromRoute('fillpdf.forms_admin');
$this
->drupalGet($overview_url);
$this
->clickLink('Duplicate');
$this
->assertSession()
->pageTextContains("Create duplicate of {$admin_title}?");
$this
->assertSession()
->fieldValueEquals('new_admin_title', "Duplicate of {$admin_title}");
$this
->clickLink('Cancel');
$this
->assertSession()
->addressEquals($overview_url);
$this
->clickLink('Duplicate');
$this
->drupalPostForm(NULL, [
'new_admin_title' => 'Another test',
], 'Save');
$this
->assertSession()
->pageTextContains('FillPDF form has been duplicated.');
$this
->assertSession()
->addressEquals(Url::fromRoute('fillpdf.forms_admin'));
$new_form_id = $this
->getLatestFillPdfForm();
$this
->assertNotEquals($new_form_id, $form_id);
$field_ids = \Drupal::entityQuery('fillpdf_form_field')
->condition('fillpdf_form', $new_form_id)
->execute();
foreach ($field_ids as $id) {
$this
->assertNotNull(FillPdfFormField::load($id), "The FillPdfFormField #{$id} has ben duplicated.");
}
$this
->assertEquals($template_fid, FillPdfForm::load($form_id)->fid->value);
}
}