You are here

public function HandlePdfControllerTest::testSaveAction in FillPDF 8.4

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

Tests SaveAction.

File

tests/src/Functional/HandlePdfControllerTest.php, line 73

Class

HandlePdfControllerTest
@coversDefaultClass \Drupal\fillpdf\Controller\HandlePdfController

Namespace

Drupal\Tests\fillpdf\Functional

Code

public function testSaveAction() {
  $this
    ->uploadTestPdf('fillpdf_test_v3.pdf');
  $form_id = $this
    ->getLatestFillPdfForm();
  $edit = [
    'scheme' => 'public',
  ];
  $this
    ->drupalPostForm("admin/structure/fillpdf/{$form_id}", $edit, 'Save');
  $fid_before = $this
    ->getLastFileId();
  $fillpdf_route = Url::fromRoute('fillpdf.populate_pdf', [], [
    'query' => [
      'fid' => $form_id,
      'sample' => 1,
    ],
  ]);
  $this
    ->drupalGet($fillpdf_route);
  $fid_after = $this
    ->getLastFileId();

  // Make sure the PDF file has been saved.
  $this
    ->assertEquals($fid_before + 1, $fid_after);

  // Make sure we are /not/ redirected to the PDF.
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $maybe_pdf = $this
    ->getSession()
    ->getPage()
    ->getContent();
  static::assertNotEquals('application/pdf', $this
    ->getMimeType($maybe_pdf), "The file has the correct MIME type.");
}