Skip to content
Snippets Groups Projects
Commit 67c67ddf authored by Bernd Oliver Suenderhauf's avatar Bernd Oliver Suenderhauf
Browse files

Issue #3040790 by Pancho: FillPdfFormForm::validateForm() throws exception...

Issue #3040790 by Pancho: FillPdfFormForm::validateForm() throws exception when used programmatically
parent 9f5ae6fd
No related branches found
No related tags found
No related merge requests found
......@@ -258,12 +258,10 @@ class FillPdfFormForm extends ContentEntityForm {
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
$files = $this->getRequest()->files->get('files');
/** @var \Symfony\Component\HttpFoundation\File\UploadedFile|null $file_upload */
$file_upload = array_key_exists('upload_pdf', $files) ? $files['upload_pdf'] : NULL;
if ($file_upload) {
$this->validatePdfUpload($form, $form_state, $file_upload);
$files = $this->getRequest()->files->get('files');
if (isset($files['upload_pdf'])) {
$this->validatePdfUpload($form, $form_state, $files['upload_pdf']);
}
}
......
......@@ -4,6 +4,7 @@ namespace Drupal\Tests\fillpdf\Functional;
use Drupal\fillpdf\Entity\FillPdfForm;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\TestFileCreationTrait;
use Drupal\Tests\fillpdf\Traits\TestFillPdfTrait;
/**
......@@ -13,6 +14,7 @@ use Drupal\Tests\fillpdf\Traits\TestFillPdfTrait;
*/
class AdminIdTest extends BrowserTestBase {
use TestFileCreationTrait;
use TestFillPdfTrait;
static public $modules = ['fillpdf_test'];
......@@ -34,15 +36,22 @@ class AdminIdTest extends BrowserTestBase {
public function testOverviewFormUpload() {
$this->drupalGet('admin/structure/fillpdf');
// Check if on the overview form's upload widget, the 'accept' attribute is
// correctly set.
// Check if the 'accept' attribute is correctly set.
$this->assertSession()->elementAttributeContains('css', '#edit-upload-pdf', 'accept', 'application/pdf');
// Without a PDF file being supplied, no FillPdf form should be created.
// Without a PDF file being supplied, no FillPdfForm should be created.
$this->uploadTestPdf(NULL);
$this->assertSession()->pageTextNotContains('New FillPDF form has been created.');
// With a PDF file being supplied, a new FillPdf form should be created.
// With a .txt file being supplied, validation should set an error.
$files = $this->getTestFiles('text');
$file = reset($files);
$this->drupalPostForm(NULL, ['files[upload_pdf]' => $file->uri], 'Upload');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextNotContains('New FillPDF form has been created.');
$this->assertSession()->pageTextContains('Only PDF files are supported, and they must end in .pdf.');
// With a PDF file being supplied, a new FillPdfForm should be created.
$this->uploadTestPdf('fillpdf_test_v3.pdf');
$this->assertSession()->pageTextContains('New FillPDF form has been created.');
}
......@@ -52,8 +61,18 @@ class AdminIdTest extends BrowserTestBase {
*/
public function testOverviewFormLinks() {
$this->uploadTestPdf('fillpdf_test_v3.pdf');
// Set the administrative title.
$admin_title = 'Example form';
$this->drupalPostForm(NULL, ['admin_title[0][value]' => $admin_title], 'Save');
$this->assertSession()->statusCodeEquals(200);
// Go back to the overview page.
$this->drupalGet('admin/structure/fillpdf');
// Check if the administrative title has been set and appears in the view.
$this->assertSession()->pageTextContains($admin_title);
// Check hook_entity_operation_alter(). Only the altered link should exist.
$this->assertSession()->linkExistsExact('Import configuration test');
$this->assertSession()->linkNotExistsExact('Import configuration');
......@@ -64,9 +83,9 @@ class AdminIdTest extends BrowserTestBase {
}
/**
* Tests the overview form's edit links.
* Tests the FillPdfForm entity's edit form.
*/
public function testEditLink() {
public function testFillPdfFormForm() {
$this->uploadTestPdf('fillpdf_test_v3.pdf');
$latest_fid = $this->getLatestFillPdfForm();
......@@ -75,10 +94,15 @@ class AdminIdTest extends BrowserTestBase {
$this->drupalGet('admin/structure/fillpdf/' . $max_fid_after);
$this->assertSession()->statusCodeEquals(200);
// Check if on the entity form's upload widget, the 'accept' attribute is
// correctly set.
// @todo This test doesn't belong here.
// Check if the 'accept' attribute is correctly set.
$this->assertSession()->elementAttributeContains('css', '#edit-upload-pdf', 'accept', 'application/pdf');
// When trying to upload a .txt file, validation should set an error.
$files = $this->getTestFiles('text');
$file = reset($files);
$this->drupalPostForm(NULL, ['files[upload_pdf]' => $file->uri], 'Save');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('Only PDF files are supported, and they must end in .pdf.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment