diff --git a/tests/modules/fillpdf_test/composer.json b/tests/modules/fillpdf_test/composer.json index fb0fa5679efd0b95dc583dc2253058ae65b77d8e..26b2d5cdd46ebfaf388c500b1611f3ec6b817fd4 100644 --- a/tests/modules/fillpdf_test/composer.json +++ b/tests/modules/fillpdf_test/composer.json @@ -9,8 +9,5 @@ "email": "kevin@wizonesolutions.com" } ], - "minimum-stability": "dev", - "require": { - "drupal/webform": "^5.0" - } + "minimum-stability": "dev" } diff --git a/tests/modules/fillpdf_test/fillpdf_test.info.yml b/tests/modules/fillpdf_test/fillpdf_test.info.yml index 4759d03f7826f41e50e3e12e92fcdbd46adc87cd..e1ca9b8b13e412785965b5f2e4a46a5b2d46793e 100644 --- a/tests/modules/fillpdf_test/fillpdf_test.info.yml +++ b/tests/modules/fillpdf_test/fillpdf_test.info.yml @@ -3,6 +3,6 @@ type: module description: Fixtures/support for FillPDF tests. core: 8.x package: Testing +version: VERSION dependencies: - fillpdf:fillpdf - - webform:webform diff --git a/tests/modules/fillpdf_test/fillpdf_test.module b/tests/modules/fillpdf_test/fillpdf_test.module index 4e065c1c800c57e4158628d28767a3283fa916eb..50ff9e041243945d9dc904826e62e82533fb4670 100644 --- a/tests/modules/fillpdf_test/fillpdf_test.module +++ b/tests/modules/fillpdf_test/fillpdf_test.module @@ -2,36 +2,10 @@ /** * @file - * Contains fillpdf_test.module.. + * Contains fillpdf_test.module. */ use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Routing\RouteMatchInterface; - -/** - * Implements hook_help(). - */ -function fillpdf_test_help($route_name, RouteMatchInterface $route_match) { - switch ($route_name) { - // Main module help for the fillpdf_test module. - case 'help.page.fillpdf_test': - $output = ''; - $output .= '<h3>' . t('About') . '</h3>'; - $output .= '<p>' . t('Fixtures/support for FillPDF tests.') . '</p>'; - return $output; - - default: - } -} - -/** - * Implements hook_theme(). - */ -function fillpdf_test_theme() { - $theme = []; - - return $theme; -} /** * Implements hook_entity_operation(). @@ -42,7 +16,7 @@ function fillpdf_test_entity_operation(EntityInterface $entity) { 'test' => [ 'title' => t('Export configuration test'), 'url' => $entity->toUrl('export-form'), - ] + ], ]; } } diff --git a/tests/modules/fillpdf_webform_test/composer.json b/tests/modules/fillpdf_webform_test/composer.json new file mode 100644 index 0000000000000000000000000000000000000000..31ff5409d6d8819ed13948622310ceec7937b5de --- /dev/null +++ b/tests/modules/fillpdf_webform_test/composer.json @@ -0,0 +1,16 @@ +{ + "name": "drupal/fillpdf_webform_test", + "description": "Fixtures/support for FillPDF webform tests.", + "type": "drupal-module", + "license": "GPLv2+", + "authors": [ + { + "name": "Kevin Kaland", + "email": "kevin@wizonesolutions.com" + } + ], + "minimum-stability": "dev", + "require": { + "drupal/webform": "^5.0" + } +} diff --git a/tests/modules/fillpdf_test/config/install/webform.webform.fillpdf_contact.yml b/tests/modules/fillpdf_webform_test/config/install/webform.webform.fillpdf_contact.yml similarity index 100% rename from tests/modules/fillpdf_test/config/install/webform.webform.fillpdf_contact.yml rename to tests/modules/fillpdf_webform_test/config/install/webform.webform.fillpdf_contact.yml diff --git a/tests/modules/fillpdf_webform_test/fillpdf_webform_test.info.yml b/tests/modules/fillpdf_webform_test/fillpdf_webform_test.info.yml new file mode 100644 index 0000000000000000000000000000000000000000..9103dfe83688d2099d6d67cd0fb717e71e52a58f --- /dev/null +++ b/tests/modules/fillpdf_webform_test/fillpdf_webform_test.info.yml @@ -0,0 +1,9 @@ +name: FillPDF webform Testing +type: module +description: Fixtures/support for FillPDF webform tests. +core: 8.x +package: Testing +version: VERSION +dependencies: + - fillpdf:fillpdf_test + - webform:webform diff --git a/tests/src/Functional/FillPdfTestBase.php b/tests/src/Functional/FillPdfTestBase.php index 288908014e7bd2bcfe2139f124ad17b39f3028ae..893e06d1b56d6b529a3600286ea7f65702cf1c03 100644 --- a/tests/src/Functional/FillPdfTestBase.php +++ b/tests/src/Functional/FillPdfTestBase.php @@ -1,29 +1,77 @@ <?php + namespace Drupal\Tests\fillpdf\Functional; -use Drupal\Tests\BrowserTestBase; +use Drupal\Tests\TestFileCreationTrait; +use Drupal\Tests\fillpdf\Traits\TestFillPdfTrait; +use Drupal\Tests\image\Functional\ImageFieldTestBase; +use Drupal\user\Entity\Role; /** * Base class that can be inherited by FillPDF tests. */ -abstract class FillPdfTestBase extends BrowserTestBase { +abstract class FillPdfTestBase extends ImageFieldTestBase { + + use TestFileCreationTrait; + use TestFillPdfTrait; + + /** + * The profile to install as a basis for testing. + * + * @var string + */ + protected $profile = 'minimal'; /** - * @var \Drupal\Core\Session\AccountInterface + * Modules to enable. + * + * The test runner will merge the $modules lists from this class, the class + * it extends, and so on up the class hierarchy. It is not necessary to + * include modules in your list that a parent class has already declared. + * + * @var string[] + * + * @see \Drupal\Tests\BrowserTestBase::installDrupal() + */ + public static $modules = ['fillpdf_test']; + + /** + * The FillPdf backend service manager. + * + * @var \Drupal\fillpdf\FillPdfBackendManager + */ + protected $backendServiceManager; + + /** + * A test image. + * + * @var \stdClass + */ + protected $testImage; + + /** + * {@inheritdoc} */ - protected $adminUser; - public static $modules = ['node', 'image', 'field_ui', 'image_module_test', 'fillpdf_test']; protected function setUp() { parent::setUp(); - // Create Basic page and Article node types. - if ($this->profile != 'standard') { - $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']); - $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']); - } + // Add some roles to the logged in admin user. + $existing_user_roles = $this->adminUser->getRoles(TRUE); + $role_to_modify = Role::load(end($existing_user_roles)); + + // Grant additional permissions to this user. + $this->grantPermissions($role_to_modify, [ + 'access administration pages', + 'administer pdfs', + ]); + + $this->configureBackend(); + + $this->backendServiceManager = $this->container->get('plugin.manager.fillpdf_backend_service'); - $this->adminUser = $this->drupalCreateUser(['access content', 'access administration pages', 'administer site configuration', 'administer content types', 'administer node fields', 'administer nodes', 'create article content', 'edit any article content', 'delete any article content', 'administer image styles', 'administer node display']); - $this->drupalLogin($this->adminUser); + $this->createImageField('field_fillpdf_test_image', 'article'); + $files = $this->getTestFiles('image'); + $this->testImage = reset($files); } } diff --git a/tests/src/Functional/PdfPopulationTest.php b/tests/src/Functional/PdfPopulationTest.php index 2173327cc6d86ac44f7fddeb6ab77e86a896815e..ada03238db74ab2bb5594a5b3c6269f162f177bd 100644 --- a/tests/src/Functional/PdfPopulationTest.php +++ b/tests/src/Functional/PdfPopulationTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\fillpdf\Functional; -use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Url; use Drupal\file\Entity\File; use Drupal\fillpdf\Component\Utility\FillPdf; @@ -11,58 +10,53 @@ use Drupal\fillpdf\FieldMapping\ImageFieldMapping; use Drupal\fillpdf\FieldMapping\TextFieldMapping; use Drupal\fillpdf_test\Plugin\FillPdfBackend\TestFillPdfBackend; use Drupal\node\Entity\Node; -use Drupal\Tests\fillpdf\Traits\TestFillPdfTrait; -use Drupal\Tests\image\Kernel\ImageFieldCreationTrait; -use Drupal\Tests\TestFileCreationTrait; -use Drupal\user\Entity\Role; -use Drupal\webform\Entity\Webform; -use Drupal\webform\Entity\WebformSubmission; /** - * Tests entity and Webform image stamping. + * Tests Core entity population and image stamping. * * @group fillpdf */ class PdfPopulationTest extends FillPdfTestBase { - use ImageFieldCreationTrait; - use TestFileCreationTrait; - use TestFillPdfTrait; - - - protected $profile = 'minimal'; - - /** - * @var \Drupal\fillpdf\FillPdfBackendManager - */ - protected $backendServiceManager; - - protected $testNodeId; - - protected $contentType; - /** + * A test node. + * * @var \Drupal\node\NodeInterface */ protected $testNode; /** - * @var \stdClass + * {@inheritdoc} */ - protected $testImage; + protected function setUp() { + parent::setUp(); + $this->configureBackend(); + + $this->testNode = Node::load( + $this->uploadNodeImage( + $this->testImage, + 'field_fillpdf_test_image', + 'article', + 'FillPDF Test Image' + ) + ); + } + + /** + * Tests Core entity population and image stamping. + */ public function testPdfPopulation() { - // Test with a node. $this->uploadTestPdf('fillpdf_test_v3.pdf'); $this->assertSession()->pageTextContains('New FillPDF form has been created.'); $fillpdf_form = FillPdfForm::load($this->getLatestFillPdfForm()); // Get the field definitions for the form that was created and configure // them. - $fields = $this->container->get('fillpdf.entity_helper') + $form_fields = $this->container->get('fillpdf.entity_helper') ->getFormFields($fillpdf_form); - $this->mapFillPdfFieldsToNodeFields($fields); + $this->mapFillPdfFieldsToNodeFields($form_fields); // Hit the generation route, check the results from the test backend plugin. $fillpdf_route = Url::fromRoute('fillpdf.populate_pdf', [], [ @@ -98,32 +92,31 @@ class PdfPopulationTest extends FillPdfTestBase { $expected_file_hash, 'Hashed filename matches known hash.' ); + self::assertEquals( $populate_result['field_mapping']['fields']['ImageField'], "{image}{$node_file->getFileUri()}", 'URI in metadata matches expected URI.' ); + } - // Test with a Webform. + /** + * Test plugin APIs directly to make sure third-party consumers can use them. + */ + public function testPluginApi() { $this->uploadTestPdf('fillpdf_test_v3.pdf'); - $fillpdf_form2 = FillPdfForm::load($this->getLatestFillPdfForm()); - - // Create a test submission for our Contact form. - $contact_form = Webform::load('fillpdf_contact'); - $contact_form_test_route = Url::fromRoute('entity.webform.test_form', ['webform' => $contact_form->id()]); - $this->drupalPostForm($contact_form_test_route, [], t('Send message')); - - // Load the submission. - $submission = WebformSubmission::load($this->getLastSubmissionId($contact_form)); + $fillpdf_form = FillPdfForm::load($this->getLatestFillPdfForm()); - $fillpdf_form2_fields = $this->container->get('fillpdf.entity_helper') - ->getFormFields($fillpdf_form2); + // Get the field definitions for the form that was created and configure + // them. + $form_fields = $this->container->get('fillpdf.entity_helper') + ->getFormFields($fillpdf_form); $expected_fields = TestFillPdfBackend::getParseResult(); $expected_keys = []; $actual_keys = []; - foreach ($fillpdf_form2_fields as $fillpdf_form2_field) { - $actual_keys[] = $fillpdf_form2_field->pdf_key->value; + foreach ($form_fields as $form_field) { + $actual_keys[] = $form_field->pdf_key->value; } foreach ($expected_fields as $expected_field) { $expected_keys[] = $expected_field['name']; @@ -135,66 +128,7 @@ class PdfPopulationTest extends FillPdfTestBase { self::assertEmpty($differences, 'Parsed fields and fields in fixture match.'); - // Configure the fields for the next test. - $webform_fields = $fillpdf_form2_fields; - /** @var \Drupal\fillpdf\Entity\FillPdfFormField $webform_field */ - foreach ($webform_fields as $webform_field) { - switch ($webform_field->pdf_key->value) { - case 'ImageField': - $webform_field->value = '[webform_submission:values:image]'; - break; - - case 'TextField': - $webform_field->value = '[webform_submission:webform:title]'; - break; - } - $webform_field->save(); - } - - // Hit the generation route, check the results from the test backend plugin. - $fillpdf_route = Url::fromRoute('fillpdf.populate_pdf', [], [ - 'query' => [ - 'fid' => $fillpdf_form2->id(), - 'entity_id' => "webform_submission:{$submission->id()}", - ], - ]); - $this->drupalGet($fillpdf_route); - - // We don't actually care about downloading the fake PDF. We just want to - // check what happened in the backend. - $populate_result = $this->container->get('state') - ->get('fillpdf_test.last_populated_metadata'); - - $submission_values = $submission->getData(); - self::assertEquals( - $populate_result['field_mapping']['fields']['TextField'], - $submission->getWebform()->label(), - 'PDF is populated with the title of the Webform Submission.' - ); - - $submission_file = File::load($submission_values['image'][0]); - self::assertEquals( - $populate_result['field_mapping']['images']['ImageField']['data'], - base64_encode(file_get_contents($submission_file->getFileUri())), - 'Encoded image matches known image.' - ); - - $path_info = pathinfo($submission_file->getFileUri()); - $expected_file_hash = md5($path_info['filename']) . '.' . $path_info['extension']; - self::assertEquals( - $populate_result['field_mapping']['images']['ImageField']['filenamehash'], - $expected_file_hash, - 'Hashed filename matches known hash.' - ); - - self::assertEquals( - $populate_result['field_mapping']['fields']['ImageField'], - "{image}{$submission_file->getFileUri()}", - 'URI in metadata matches expected URI.' - ); - - // Test plugin APIs directly to make sure third-party consumers can use - // them. + // Now create an instance of the backend service. /** @var \Drupal\fillpdf_test\Plugin\BackendService\Test $backend_service */ $backend_service = $this->backendServiceManager->createInstance('test'); @@ -212,8 +146,8 @@ class PdfPopulationTest extends FillPdfTestBase { self::assertEmpty($differences, 'Parsed fields from plugin and fields in fixture match.'); - // Test the merge method. We'd normally pass in values for $webform_fields and - // $options, but since this is a stub anyway, there isn't much point. + // Test the merge method. We'd normally pass in values for $webform_fields + // and $options, but since this is a stub anyway, there isn't much point. // @todo: Test deeper using the State API. $merged_pdf = $backend_service->merge($original_pdf, [ 'Foo' => new TextFieldMapping('bar'), @@ -232,10 +166,12 @@ class PdfPopulationTest extends FillPdfTestBase { } /** - * @param $fields + * Maps FillPdf fields to node fields. + * + * @param \Drupal\fillpdf\Entity\FillPdfFormField[] $fields + * Array of FillPdfFormFields. */ - protected function mapFillPdfFieldsToNodeFields($fields) { - /** @var \Drupal\fillpdf\Entity\FillPdfFormField $field */ + protected function mapFillPdfFieldsToNodeFields(array $fields) { foreach ($fields as $field) { switch ($field->pdf_key->value) { case 'ImageField': @@ -253,29 +189,12 @@ class PdfPopulationTest extends FillPdfTestBase { } /** - * Get the last submission id. - * - * @param \Drupal\webform\WebformInterface $webform + * Tests PDF population using local service. * - * @return int - * The last submission id. + * @throws \PHPUnit_Framework_SkippedTestError + * Thrown when test had to be skipped as FillPDF LocalServer is not + * available. */ - protected function getLastSubmissionId($webform) { - // Get submission sid. - $url = UrlHelper::parse($this->getUrl()); - if (isset($url['query']['sid'])) { - return $url['query']['sid']; - } - - $entity_ids = $this->container->get('entity_type.manager') - ->getStorage('webform_submission') - ->getQuery() - ->sort('sid', 'DESC') - ->condition('webform_id', $webform->id()) - ->execute(); - return reset($entity_ids); - } - public function testLocalServicePdfPopulation() { // For local container testing, we require the Docker container to be // running on port 18085. If http://127.0.0.1:18085/ping does not return a @@ -292,46 +211,24 @@ class PdfPopulationTest extends FillPdfTestBase { $this->backendTest(); } + /** + * Tests PDF population using a local install of pdftk. + * + * @throws \PHPUnit_Framework_SkippedTestError + * Thrown when test had to be skipped as local pdftk install is not + * available. + * + * @todo Implementation missing. + */ public function testPdftkPdfPopulation() { throw new \PHPUnit_Framework_SkippedTestError('Not implemented yet, so skipping test.'); } - protected function setUp() { - parent::setUp(); - - $this->configureBackend(); - - // Add some roles to this user. - $existing_user_roles = $this->adminUser->getRoles(TRUE); - $role_to_modify = Role::load(end($existing_user_roles)); - - // Grant additional permissions to this user. - $this->grantPermissions($role_to_modify, [ - 'access administration pages', - 'administer pdfs', - 'administer webform', - 'access webform submission log', - 'create webform', - ]); - - $this->backendServiceManager = $this->container->get('plugin.manager.fillpdf_backend_service'); - - $this->createImageField('field_fillpdf_test_image', 'article'); - $files = $this->getTestFiles('image'); - $image = reset($files); - $this->testNode = Node::load( - $this->uploadNodeImage( - $image, - 'field_fillpdf_test_image', - 'article', - 'FillPDF Test Image' - ) - ); - $this->testImage = $image; - } - + /** + * Tests a backend. + */ protected function backendTest() { -// If we can upload a PDF, parsing is working. + // If we can upload a PDF, parsing is working. // Test with a node. $this->uploadTestPdf('fillpdf_test_v3.pdf'); $fillpdf_form = FillPdfForm::load($this->getLatestFillPdfForm()); diff --git a/tests/src/Functional/PdfWebformPopulationTest.php b/tests/src/Functional/PdfWebformPopulationTest.php new file mode 100644 index 0000000000000000000000000000000000000000..923bdb4bd950dbaa49f83b82d35c257e78e482ff --- /dev/null +++ b/tests/src/Functional/PdfWebformPopulationTest.php @@ -0,0 +1,172 @@ +<?php + +namespace Drupal\Tests\fillpdf\Functional; + +use Drupal\Component\Utility\UrlHelper; +use Drupal\Core\Url; +use Drupal\file\Entity\File; +use Drupal\fillpdf\Entity\FillPdfForm; +use Drupal\user\Entity\Role; +use Drupal\webform\WebformInterface; +use Drupal\webform\Entity\Webform; +use Drupal\webform\Entity\WebformSubmission; + +/** + * Tests Webform population and image stamping. + * + * @group fillpdf + */ +class PdfWebformPopulationTest extends FillPdfTestBase { + + /** + * Modules to enable. + * + * The test runner will merge the $modules lists from this class, the class + * it extends, and so on up the class hierarchy. It is not necessary to + * include modules in your list that a parent class has already declared. + * + * @var string[] + * + * @see \Drupal\Tests\BrowserTestBase::installDrupal() + */ + public static $modules = ['webform', 'fillpdf_webform_test']; + + /** + * A test webform submission. + * + * @var \Drupal\webform\WebformSubmissionInterface + */ + protected $testSubmission; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + // Add some roles to this user. + $existing_user_roles = $this->adminUser->getRoles(TRUE); + $role_to_modify = Role::load(end($existing_user_roles)); + + // Grant additional permissions to this user. + $this->grantPermissions($role_to_modify, [ + 'administer webform', + 'access webform submission log', + 'create webform', + ]); + + // Create a test submission for our Contact form. + $contact_form = Webform::load('fillpdf_contact'); + $contact_form_test_route = Url::fromRoute('entity.webform.test_form', ['webform' => $contact_form->id()]); + $this->drupalPostForm($contact_form_test_route, [], t('Send message')); + + // Load the submission. + $this->testSubmission = WebformSubmission::load($this->getLastSubmissionId($contact_form)); + } + + /** + * Tests Webform population and image stamping. + */ + public function testPdfPopulation() { + $this->uploadTestPdf('fillpdf_test_v3.pdf'); + $this->assertSession()->pageTextContains('New FillPDF form has been created.'); + $fillpdf_form = FillPdfForm::load($this->getLatestFillPdfForm()); + + // Get the field definitions for the form that was created and configure + // them. + $form_fields = $this->container->get('fillpdf.entity_helper') + ->getFormFields($fillpdf_form); + + $this->mapFillPdfFieldsToWebformFields($form_fields); + + // Hit the generation route, check the results from the test backend plugin. + $fillpdf_route = Url::fromRoute('fillpdf.populate_pdf', [], [ + 'query' => [ + 'fid' => $fillpdf_form->id(), + 'entity_id' => "webform_submission:{$this->testSubmission->id()}", + ], + ]); + $this->drupalGet($fillpdf_route); + + // We don't actually care about downloading the fake PDF. We just want to + // check what happened in the backend. + $populate_result = $this->container->get('state') + ->get('fillpdf_test.last_populated_metadata'); + + $submission_values = $this->testSubmission->getData(); + self::assertEquals( + $populate_result['field_mapping']['fields']['TextField'], + $this->testSubmission->getWebform()->label(), + 'PDF is populated with the title of the Webform Submission.' + ); + + $submission_file = File::load($submission_values['image'][0]); + self::assertEquals( + $populate_result['field_mapping']['images']['ImageField']['data'], + base64_encode(file_get_contents($submission_file->getFileUri())), + 'Encoded image matches known image.' + ); + + $path_info = pathinfo($submission_file->getFileUri()); + $expected_file_hash = md5($path_info['filename']) . '.' . $path_info['extension']; + self::assertEquals( + $populate_result['field_mapping']['images']['ImageField']['filenamehash'], + $expected_file_hash, + 'Hashed filename matches known hash.' + ); + + self::assertEquals( + $populate_result['field_mapping']['fields']['ImageField'], + "{image}{$submission_file->getFileUri()}", + 'URI in metadata matches expected URI.' + ); + } + + /** + * Get the last submission id. + * + * @param \Drupal\webform\WebformInterface $webform + * A webform. + * + * @return int + * The last submission id. + */ + protected function getLastSubmissionId(WebformInterface $webform) { + // Get submission sid. + $url = UrlHelper::parse($this->getUrl()); + if (isset($url['query']['sid'])) { + return $url['query']['sid']; + } + + $entity_ids = $this->container->get('entity_type.manager') + ->getStorage('webform_submission') + ->getQuery() + ->sort('sid', 'DESC') + ->condition('webform_id', $webform->id()) + ->execute(); + return reset($entity_ids); + } + + /** + * Maps FillPdf fields to node fields. + * + * @param \Drupal\fillpdf\Entity\FillPdfFormField[] $fields + * Array of FillPdfFormFields. + */ + protected function mapFillPdfFieldsToWebformFields(array $fields) { + foreach ($fields as $field) { + switch ($field->pdf_key->value) { + case 'ImageField': + $field->value = '[webform_submission:values:image]'; + break; + + case 'TextField': + $field->value = '[webform_submission:webform:title]'; + break; + } + $field->save(); + } + + } + +} diff --git a/tests/src/Traits/TestFillPdfTrait.php b/tests/src/Traits/TestFillPdfTrait.php index f4a7b10caece936d7834ed4c28144d9dd953209b..37bb5e37922f07583f3a431787f93531b78561b0 100644 --- a/tests/src/Traits/TestFillPdfTrait.php +++ b/tests/src/Traits/TestFillPdfTrait.php @@ -2,10 +2,16 @@ namespace Drupal\Tests\fillpdf\Traits; -use Drupal\node\NodeInterface; - +/** + * Provides methods for testing FillPdf. + * + * This trait is meant to be used only by test classes. + */ trait TestFillPdfTrait { + /** + * Configures the FillPdf test backend. + */ protected function configureBackend() { // FillPDF needs to be configured. /** @var \Drupal\Core\Config\Config $fillpdf_settings */ @@ -16,6 +22,9 @@ trait TestFillPdfTrait { $fillpdf_settings->save(); } + /** + * Configures the FillPdf local service backend. + */ protected function configureLocalServiceBackend() { // Configure our local filling service. You need to set up your development // environment to run the Docker container at http://127.0.0.1:8085 if you @@ -28,6 +37,9 @@ trait TestFillPdfTrait { $this->drupalPostForm('admin/config/media/fillpdf', $edit, t('Save configuration')); } + /** + * Configures the FillPdf service backend. + */ protected function configureFillPdfServiceBackend($api_key, $api_endpoint = 'https://www.fillpdf.io') { // Configure FillPDF Service. $edit = [ @@ -39,6 +51,9 @@ trait TestFillPdfTrait { $this->drupalPostForm('admin/config/media/fillpdf', $edit, t('Save configuration')); } + /** + * Creates a privileged user account and logs in. + */ protected function initializeUser() { // Create and log in our privileged user. $account = $this->drupalCreateUser([ @@ -68,6 +83,8 @@ trait TestFillPdfTrait { } /** + * Gets the latest FillPdf form. + * * @return mixed */ protected function getLatestFillPdfForm() { @@ -83,6 +100,8 @@ trait TestFillPdfTrait { } /** + * Gets the absolute local filepath of a PDF test file. + * * @param string $filename * Filename of the PDF testfile. * @@ -95,42 +114,4 @@ trait TestFillPdfTrait { return $file_system->realpath(drupal_get_path('module', 'fillpdf') . '/tests/modules/fillpdf_test/files/' . $filename); } - /** - * Upload an image to a node. - * - * This is a fixed version of this method. The one from core is currently - * broken. - * - * @todo: Keep an eye on https://www.drupal.org/project/drupal/issues/2863626 - * and consider switching back to that when it's done. - * - * @see \Drupal\Tests\image\Functional\ImageFieldTestBase::uploadNodeImage() - * - * @param $image - * A file object representing the image to upload. - * @param $field_name - * Name of the image field the image should be attached to. - * @param $type - * The type of node to create. - * @param $alt - * The alt text for the image. Use if the field settings require alt text. - */ - public function uploadNodeImage($image, $field_name, $type, $alt = '') { - $edit = [ - 'title[0][value]' => $this->randomMachineName(), - ]; - $edit['files[' . $field_name . '_0]'] = drupal_realpath($image->uri); - $edit['status[value]'] = NodeInterface::PUBLISHED; - $this->drupalPostForm('node/add/' . $type, $edit, t('Save')); - if ($alt) { - // Add alt text. - $this->drupalPostForm(NULL, [$field_name . '[0][alt]' => $alt], t('Save')); - } - - // Retrieve ID of the newly created node from the current URL. - $matches = []; - preg_match('/node\/([0-9]+)/', $this->getUrl(), $matches); - return isset($matches[1]) ? $matches[1] : FALSE; - } - }