You are here

public function FillPdfSettingsFormTest::testTemplateSchemePublic in FillPDF 5.0.x

Same name and namespace in other branches
  1. 8.4 tests/src/Functional/FillPdfSettingsFormTest.php \Drupal\Tests\fillpdf\Functional\FillPdfSettingsFormTest::testTemplateSchemePublic()

Tests the scheme settings with the 'public' stream wrapper.

File

tests/src/Functional/FillPdfSettingsFormTest.php, line 135

Class

FillPdfSettingsFormTest
@coversDefaultClass \Drupal\fillpdf\Form\FillPdfSettingsForm @group fillpdf

Namespace

Drupal\Tests\fillpdf\Functional

Code

public function testTemplateSchemePublic() {

  // FillPDF is not yet configured.
  // Configure FillPDF with the 'test' backend and the site default scheme,
  // which at this point is 'public'.
  $this
    ->configureFillPdf();

  // On the settings page, verify the 'public' scheme is set both in the form
  // and in config.
  $this
    ->drupalGet(Url::fromRoute('fillpdf.settings'));
  $this
    ->assertSession()
    ->fieldValueEquals('template_scheme', 'public');
  $this
    ->assertEqual($this
    ->config('fillpdf.settings')
    ->get('template_scheme'), 'public');

  // Verify the subdirectory doesn't exist yet.
  $directory = 'public://fillpdf';
  $this
    ->assertFalse(is_dir($directory), 'Directory does not exist prior to testing.');

  // Now on the settings form, save the unchanged configuration to create the
  // subdirectory. Verify it does exist now and is writeable.
  $this
    ->drupalPostForm(NULL, [], 'Save configuration');
  $this
    ->assertSession()
    ->pageTextContains('The configuration options have been saved.');
  $this
    ->assertTrue(is_dir($directory), 'Directory exists now.');
  $this
    ->assertTrue(\Drupal::service('file_system')
    ->prepareDirectory($directory), 'Directory is writeable.');

  // Now delete the directory and replace it with a file with the same name,
  // so the directory can't be recreated. Try saving again and verify an error
  // is set.

  /** @var \Drupal\Core\File\FileSystemInterface $file_system */
  $file_system = $this->container
    ->get('file_system');
  $file_system
    ->rmdir($directory);
  \Drupal::service('file_system')
    ->copy('public://.htaccess', $directory);
  $this
    ->drupalPostForm(NULL, [], 'Save configuration');
  $this
    ->assertSession()
    ->pageTextNotContains('The configuration options have been saved.');
  $this
    ->assertSession()
    ->pageTextContains('Could not automatically create the subdirectory');
}