public function FillPdfFormFormTest::testFillPdfFileUsage in FillPDF 8.4
Same name and namespace in other branches
- 5.0.x tests/src/Functional/FillPdfFormFormTest.php \Drupal\Tests\fillpdf\Functional\FillPdfFormFormTest::testFillPdfFileUsage()
Tests proper registration of managed_files.
File
- tests/
src/ Functional/ FillPdfFormFormTest.php, line 195
Class
- FillPdfFormFormTest
- @coversDefaultClass \Drupal\fillpdf\Form\FillPdfFormForm @group fillpdf
Namespace
Drupal\Tests\fillpdf\FunctionalCode
public function testFillPdfFileUsage() {
$this
->uploadTestPdf('fillpdf_test_v3.pdf');
// Set the administrative title and check if it has been successfully set.
$admin_title = 'Example form';
$this
->drupalPostForm(NULL, [
'admin_title[0][value]' => $admin_title,
], self::OP_SAVE);
$this
->assertSession()
->pageTextContains("FillPDF Form {$admin_title} has been updated.");
$this
->assertSession()
->fieldValueEquals('edit-admin-title-0-value', $admin_title);
// Grant additional permission to the logged in user.
$existing_user_roles = $this->loggedInUser
->getRoles(TRUE);
$role_to_modify = Role::load(end($existing_user_roles));
$this
->grantPermissions($role_to_modify, [
'access files overview',
]);
// Check if the uploaded test PDF file is properly registered as a permanent
// managed_file.
$fillpdf_form = FillPdfForm::load($this
->getLatestFillPdfForm());
$file_id = $fillpdf_form
->get('file')
->first()
->getValue()['target_id'];
$this
->drupalPostForm('admin/content/files', [
'edit-filename' => 'fillpdf_test_v3.pdf',
], 'Filter');
$this
->assertSession()
->elementsCount('css', 'table td.views-field.views-field-filename', 1);
$this
->assertSession()
->pageTextContains('Permanent');
// @todo Past 8.6.x, use File::load($file_id)->createFileUrl() directly.
// See https://www.drupal.org/project/fillpdf/issues/3023341.
$file_uri = File::load($file_id)
->getFileUri();
$this
->assertSession()
->linkByHrefExists(file_create_url($file_uri));
// Now go check the File usage screen and see if the FillPdfForm is listed
// with its canonical link.
$this
->drupalGet("admin/content/files/usage/{$file_id}");
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->linkByHrefExists($fillpdf_form
->toUrl()
->toString());
}