View source
<?php
namespace Drupal\Tests\fillpdf\Functional;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\fillpdf\Entity\FillPdfForm;
use Drupal\user\Entity\Role;
use Drupal\Core\Url;
class FillPdfOverviewFormTest extends FillPdfUploadTestBase {
use EntityReferenceTestTrait;
public function testOverviewForm() {
$this
->drupalGet(Url::fromRoute('fillpdf.forms_admin'));
}
public function testOverviewFormUpload() {
$this
->uploadTestPdf(NULL);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextNotContains('New FillPDF form has been created.');
$this
->assertSession()
->elementAttributeContains('css', 'input#edit-upload-pdf-upload', 'accept', 'application/pdf');
$this
->assertNotUploadTextFile(self::OP_UPLOAD);
$this
->assertNotUploadTextFile(self::OP_CREATE);
$this
->assertUploadPdfFile(self::OP_UPLOAD, FALSE);
$this
->assertUploadPdfFile(self::OP_CREATE, FALSE);
}
public function testOverviewFormLinks() {
$this
->uploadTestPdf('fillpdf_test_v3.pdf');
$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);
$this
->drupalGet('admin/structure/fillpdf');
$this
->assertSession()
->pageTextContains($admin_title);
$this
->assertSession()
->linkExistsExact('Import configuration test');
$this
->assertSession()
->linkNotExistsExact('Import configuration');
$this
->assertSession()
->linkExistsExact('Export configuration test');
$this
->assertSession()
->linkExistsExact('Export configuration');
}
public function testEntityReference() {
$this
->uploadTestPdf('fillpdf_test_v3.pdf');
$fid = $this
->getLatestFillPdfForm();
$admin_title = 'Example form';
$this
->drupalPostForm("admin/structure/fillpdf/{$fid}", [
'admin_title[0][value]' => $admin_title,
], self::OP_SAVE);
$this
->assertSession()
->statusCodeEquals(200);
$bundle = $this
->drupalCreateContentType();
$bundle_id = $bundle
->id();
$this
->createEntityReferenceField('node', $bundle_id, 'field_fillpdf_form', 'FillPDF form', 'fillpdf_form');
$this->container
->get('entity_type.manager')
->getStorage('entity_form_display')
->load("node.{$bundle_id}.default")
->setComponent('field_fillpdf_form', [
'type' => 'options_select',
])
->save();
$this->container
->get('entity_type.manager')
->getStorage('entity_view_display')
->load("node.{$bundle_id}.default")
->setComponent('field_fillpdf_form', [
'type' => 'entity_reference_label',
'settings' => [
'link' => TRUE,
],
])
->save();
$existing_user_roles = $this->loggedInUser
->getRoles(TRUE);
$role_to_modify = Role::load(end($existing_user_roles));
$this
->grantPermissions($role_to_modify, [
"create {$bundle_id} content",
]);
$this
->drupalGet("/node/add/{$bundle_id}");
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->optionExists('edit-field-fillpdf-form', $admin_title);
$edit = [
'title[0][value]' => 'Test node',
'field_fillpdf_form' => $fid,
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$fillpdf_form = FillPdfForm::load($fid);
$this
->assertSession()
->linkByHrefExists($fillpdf_form
->toUrl()
->toString());
}
}