public function FillPdfOverviewFormTest::testEntityReference in FillPDF 8.4
Same name and namespace in other branches
- 5.0.x tests/src/Functional/FillPdfOverviewFormTest.php \Drupal\Tests\fillpdf\Functional\FillPdfOverviewFormTest::testEntityReference()
Tests an entity reference to a FillPdfForm.
@todo: This doesn't belong here.
File
- tests/
src/ Functional/ FillPdfOverviewFormTest.php, line 77
Class
- FillPdfOverviewFormTest
- @coversDefaultClass \Drupal\fillpdf\Form\FillPdfOverviewForm @group fillpdf
Namespace
Drupal\Tests\fillpdf\FunctionalCode
public function testEntityReference() {
// Create new FillPdfForm.
$this
->uploadTestPdf('fillpdf_test_v3.pdf');
$fid = $this
->getLatestFillPdfForm();
// Set the administrative title.
$admin_title = 'Example form';
$this
->drupalPostForm("admin/structure/fillpdf/{$fid}", [
'admin_title[0][value]' => $admin_title,
], self::OP_SAVE);
$this
->assertSession()
->statusCodeEquals(200);
// Create host content type.
$bundle = $this
->drupalCreateContentType();
$bundle_id = $bundle
->id();
// Create an entity reference to our FillPdfForm.
$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();
// 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, [
"create {$bundle_id} content",
]);
// On a new node, check if the select contains an option with the
// administrative title we have set.
$this
->drupalGet("/node/add/{$bundle_id}");
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->optionExists('edit-field-fillpdf-form', $admin_title);
// Select our FillPdfForm reference, save and see the label is rendered as
// canonical link.
$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());
}