Skip to content
Snippets Groups Projects
Commit c1f64956 authored by Bernd Oliver Suenderhauf's avatar Bernd Oliver Suenderhauf
Browse files

Issue #3043010 by Pancho: Split AdminIdTest to TemplateUploadTest and...

Issue #3043010 by Pancho: Split AdminIdTest to TemplateUploadTest and FillPdfOverviewFormTest preserving history (4)
parent 4e07ba9e
No related branches found
No related tags found
No related merge requests found
......@@ -3,24 +3,21 @@
namespace Drupal\Tests\fillpdf\Functional;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\file\Entity\File;
use Drupal\fillpdf\Entity\FillPdfForm;
use Drupal\simpletest\ContentTypeCreationTrait;
use Drupal\user\Entity\Role;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\TestFileCreationTrait;
use Drupal\Tests\fillpdf\Traits\TestFillPdfTrait;
/**
* Ensure Edit links for PDFs at /admin/structure/fillpdf function correctly.
*
* @coversDefaultClass \Drupal\fillpdf\Form\FillPdfOverviewForm
* @group fillpdf
*/
class AdminIdTest extends BrowserTestBase {
class FillPdfOverviewFormTest extends BrowserTestBase {
use ContentTypeCreationTrait;
use EntityReferenceTestTrait;
use TestFileCreationTrait;
use TestFillPdfTrait;
static public $modules = ['fillpdf_test'];
......@@ -37,29 +34,10 @@ class AdminIdTest extends BrowserTestBase {
}
/**
* Tests the overview form's PDF file upload functionality.
* Tests the overview form is accessible.
*/
public function testOverviewFormUpload() {
$this->drupalGet('admin/structure/fillpdf');
// Check if the 'accept' attribute is correctly set.
$this->assertSession()->elementAttributeContains('css', '#edit-upload-pdf', 'accept', 'application/pdf');
// Without a PDF file being supplied, no FillPdfForm should be created.
$this->uploadTestPdf(NULL);
$this->assertSession()->pageTextNotContains('New FillPDF form has been created.');
// With a .txt file being supplied, validation should set an error.
$files = $this->getTestFiles('text');
$file = reset($files);
$this->drupalPostForm(NULL, ['files[upload_pdf]' => $file->uri], 'Upload');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextNotContains('New FillPDF form has been created.');
$this->assertSession()->pageTextContains('Only PDF files are supported, and they must end in .pdf.');
// With a PDF file being supplied, a new FillPdfForm should be created.
$this->uploadTestPdf('fillpdf_test_v3.pdf');
$this->assertSession()->pageTextContains('New FillPDF form has been created.');
public function testOverviewForm() {
$this->drupalGet(Url::fromRoute('fillpdf.forms_admin'));
}
/**
......@@ -89,65 +67,6 @@ class AdminIdTest extends BrowserTestBase {
$this->assertSession()->linkExistsExact('Export configuration');
}
/**
* Tests the FillPdfForm entity's edit form.
*/
public function testFillPdfFormForm() {
$this->uploadTestPdf('fillpdf_test_v3.pdf');
$latest_fid = $this->getLatestFillPdfForm();
$latest_fillpdf_form = FillPdfForm::load($latest_fid);
$max_fid_after = $latest_fillpdf_form->fid->value;
$this->drupalGet('admin/structure/fillpdf/' . $max_fid_after);
$this->assertSession()->statusCodeEquals(200);
// Check if the 'accept' attribute is correctly set.
$this->assertSession()->elementAttributeContains('css', '#edit-upload-pdf', 'accept', 'application/pdf');
// When trying to upload a .txt file, validation should set an error.
$files = $this->getTestFiles('text');
$file = reset($files);
$this->drupalPostForm(NULL, ['files[upload_pdf]' => $file->uri], 'Save');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('Only PDF files are supported, and they must end in .pdf.');
}
/**
* Tests proper registration of managed_files.
*/
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], '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());
}
/**
* Tests an entity reference to a FillPdfForm.
*/
......
<?php
namespace Drupal\Tests\fillpdf\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the main FillPDF upload form.
*
* @group fillpdf
*/
class OverviewFormTest extends BrowserTestBase {
static public $modules = ['fillpdf'];
protected $profile = 'minimal';
/**
* Tests that upload form is accessible.
*/
public function testUploadForm() {
// Create and log in our privileged user.
$user = $this->createUser([
'access administration pages',
'administer pdfs',
]);
$this->drupalLogin($user);
$this->drupalGet(Url::fromRoute('fillpdf.forms_admin'));
}
}
......@@ -2,24 +2,20 @@
namespace Drupal\Tests\fillpdf\Functional;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\file\Entity\File;
use Drupal\fillpdf\Entity\FillPdfForm;
use Drupal\simpletest\ContentTypeCreationTrait;
use Drupal\user\Entity\Role;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\TestFileCreationTrait;
use Drupal\Tests\fillpdf\Traits\TestFillPdfTrait;
/**
* Ensure Edit links for PDFs at /admin/structure/fillpdf function correctly.
* Test everything around uploading PDF template files.
*
* @group fillpdf
*/
class AdminIdTest extends BrowserTestBase {
class TemplateUploadTest extends BrowserTestBase {
use ContentTypeCreationTrait;
use EntityReferenceTestTrait;
use TestFileCreationTrait;
use TestFillPdfTrait;
......@@ -39,7 +35,7 @@ class AdminIdTest extends BrowserTestBase {
/**
* Tests the overview form's PDF file upload functionality.
*/
public function testOverviewFormUpload() {
public function testFillPdfOverviewFormUpload() {
$this->drupalGet('admin/structure/fillpdf');
// Check if the 'accept' attribute is correctly set.
......@@ -62,37 +58,10 @@ class AdminIdTest extends BrowserTestBase {
$this->assertSession()->pageTextContains('New FillPDF form has been created.');
}
/**
* Tests the overview form's operation links.
*/
public function testOverviewFormLinks() {
$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], 'Save');
$this->assertSession()->pageTextContains("FillPDF Form $admin_title has been updated.");
$this->assertSession()->fieldValueEquals('edit-admin-title-0-value', $admin_title);
// Go back to the overview page.
$this->drupalGet('admin/structure/fillpdf');
// Check if the administrative title appears in the view.
$this->assertSession()->pageTextContains($admin_title);
// Check hook_entity_operation_alter(). Only the altered link should exist.
$this->assertSession()->linkExistsExact('Import configuration test');
$this->assertSession()->linkNotExistsExact('Import configuration');
// Check hook_entity_operation(). Both links should exist.
$this->assertSession()->linkExistsExact('Export configuration test');
$this->assertSession()->linkExistsExact('Export configuration');
}
/**
* Tests the FillPdfForm entity's edit form.
*/
public function testFillPdfFormForm() {
public function testFillPdfFormFormUpload() {
$this->uploadTestPdf('fillpdf_test_v3.pdf');
$latest_fid = $this->getLatestFillPdfForm();
......@@ -118,12 +87,6 @@ class AdminIdTest extends BrowserTestBase {
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], '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));
......@@ -148,60 +111,4 @@ class AdminIdTest extends BrowserTestBase {
$this->assertSession()->linkByHrefExists($fillpdf_form->toUrl()->toString());
}
/**
* Tests an entity reference to a FillPdfForm.
*/
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], 'Save');
$this->assertSession()->statusCodeEquals(200);
// Create host content type.
$bundle = $this->createContentType();
$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());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment