Skip to content
Snippets Groups Projects
Commit e56ec17a authored by Liam Morland's avatar Liam Morland
Browse files

Coding standards

parent 99c4204c
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,6 @@ function fillpdf_settings($form, &$form_state) {
$fillpdf_service = variable_get('fillpdf_service');
$scheme_options = _fillpdf_scheme_options();
$form['fillpdf_scheme'] = array(
'#type' => 'radios',
'#title' => t('Template download method'),
......@@ -65,6 +64,7 @@ function fillpdf_settings($form, &$form_state) {
'#default_value' => $fillpdf_service,
'#options' => $options,
);
$form['remote'] = array(
'#type' => 'fieldset',
'#title' => t('Configure FillPDF Service'),
......@@ -94,12 +94,14 @@ function fillpdf_settings($form, &$form_state) {
'http' => t('Do not use HTTPS'),
),
);
$form['fillpdf_local_service_endpoint'] = array(
'#type' => 'textfield',
'#title' => t('Configure FillPDF LocalServer endpoint (address)'),
'#default_value' => variable_get('fillpdf_local_service_endpoint'),
'#description' => t("Enter the network address of your FillPDF LocalServer installation. If you are running the Docker container on port 8085 locally, then the address is <em>http://127.0.0.1:8085</em>. Don't worry; the module will check if it can communicate with LocalServer once you fill in this information."),
);
$form['fillpdf_pdftk_path'] = array(
'#type' => 'textfield',
'#title' => t('Configure path to pdftk'),
......
<?php
/**
* @file
* The module file.
*/
require_once __DIR__ . '/fillpdf.deprecated.inc';
define("FILLPDF_DEFAULT_SERVLET_URL", variable_get('fillpdf_remote_protocol', 'https') . "://" . variable_get('fillpdf_remote_endpoint', "fillpdf.io/xmlrpc.php"));
......@@ -154,7 +159,8 @@ function fillpdf_modules_enabled($modules) {
/**
* Implements hook_file_download().
*
* @todo: Rewrite this to not nest so deeply, if possible. It would be better to return early.
* @todo: Rewrite this to not nest so deeply, if possible. It would be better to
* return early.
*/
function fillpdf_file_download($uri) {
// Do we handle this kind of file? Check using string functions for
......@@ -421,6 +427,7 @@ function fillpdf_link_to_stub_context($uri) {
/**
* Translates a FillPDF context array into a link.
*
* @throws \EntityMalformedException
*/
function fillpdf_context_to_link($fid, $context, $sample = FALSE) {
......@@ -499,7 +506,7 @@ function fillpdf_context_to_link($fid, $context, $sample = FALSE) {
* Boolean. If TRUE, handle the PDF, which usually consists of sending it to
* the users's browser or saving it as a file.
* @param int[] $uc_order_ids
* Array of integer IDs of Ubercart orders from which to
* Array of integer IDs of Ubercart orders from which to.
* @param int[] $uc_order_product_ids
* Array of integer IDs of Ubercart ordered products from which to draw data.
* @param array $entity_ids
......@@ -893,7 +900,7 @@ function fillpdf_load_entities($fillpdf_info, $nids, $webform_array, $uc_order_i
foreach ($entity_ids as $entity_id) {
list($type, $id) = strpos($entity_id, ':') ? explode(':', $entity_id) : array(
$entity_id,
NULL
NULL,
);
// Type might be missing, in which case we default to either the default
// entity type (if exists) or 'node' if none is set.
......@@ -1005,6 +1012,7 @@ function _fillpdf_merge_pdf_token_replace($value, $token_objects, &$existing_tok
* @param $token_objects
* @param bool $sample
* @param $entities
*
* @return object
*/
function _fillpdf_build_options_object($force_download, $flatten, $fillpdf_info, $data, $nodes, $webforms, $uc_orders, $uc_order_products, $token_objects, $sample = FALSE, $entities) {
......@@ -1202,13 +1210,16 @@ function fillpdf_fillpdf_merge_pre_handle($fillpdf) {
/**
* Make sure the user has access to data they want to populate the PDF.
*
* @todo: Support passing $account, for testability.
* @param array $nodes
* @param array $webforms
* @param array $uc_orders
* @param array $uc_order_products
* @param array $entities
*
* @return bool
* Whether the user has access.
*
* @todo: Support passing $account, for testability.
*/
function fillpdf_merge_pdf_access($nodes = array(), $webforms = array(), $uc_orders = array(), $uc_order_products = array(), $entities = array()) {
if (user_access('administer pdfs') || user_access('publish all pdfs')) {
......@@ -2068,6 +2079,7 @@ function fillpdf_file_usage_delete(stdClass $file) {
/**
* @param int $fcid
* The fcid of the context object to load.
*
* @return object|bool
* Returns the decoded context object or FALSE if the fcid cannot be found.
*/
......
......@@ -31,7 +31,12 @@ class FillPdfMergeTestCase extends ImageFieldTestCase {
// ImageFieldTestCase::setUp() is dumb, so we have to enable some modules
// ourselves.
$modules = array('fillpdf', 'fillpdf_test_webform', 'entity_token', 'fillpdf_test');
$modules = array(
'fillpdf',
'fillpdf_test_webform',
'entity_token',
'fillpdf_test',
);
$success = module_enable($modules, TRUE);
$this->assertTrue($success, t('Enabled modules: %modules', array('%modules' => implode(', ', $modules))));
......@@ -103,17 +108,14 @@ class FillPdfMergeTestCase extends ImageFieldTestCase {
'PDF is populated with the title of the node.'
);
/**
* These tests cover the official (and some unofficial) ways of building
* FillPDF Links for entities. Official: entity_id, entity_ids, entity_type
* + entity_id. Unofficial: entity (synonym for entity_id), entities
* (synonym for entity_ids). It doesn't test entity_type + entity, but that
* should work too. It's not officially supported, though. It's just that
* the contributed patch already had those working, and there was no good
* reason to take them out and make it harder for people to update their
* version of FillPDF later.
*/
// These tests cover the official (and some unofficial) ways of building
// FillPDF Links for entities. Official: entity_id, entity_ids, entity_type
// + entity_id. Unofficial: entity (synonym for entity_id), entities
// (synonym for entity_ids). It doesn't test entity_type + entity, but that
// should work too. It's not officially supported, though. It's just that
// the contributed patch already had those working, and there was no good
// reason to take them out and make it harder for people to update their
// version of FillPDF later.
$this->testEntity = node_load($this->uploadNodeImage($image, 'field_test_image', 'article'));
// Test with a node.
......@@ -145,7 +147,6 @@ class FillPdfMergeTestCase extends ImageFieldTestCase {
and single-entity format).'
);
// Hit the FillPDF URL, check the results from the test fill method.
$this->drupalGet('fillpdf', array(
'query' => array(
......@@ -223,7 +224,6 @@ class FillPdfMergeTestCase extends ImageFieldTestCase {
// test. They weren't worth renaming.
unset($path_info, $expected_file_hash);
// Hit the FillPDF URL, check the results from the test fill method.
$this->drupalGet('fillpdf', array(
'query' => array(
......@@ -242,7 +242,6 @@ class FillPdfMergeTestCase extends ImageFieldTestCase {
'PDF is populated with the title of the taxonomy term.'
);
// Hit the FillPDF URL, check the results from the test fill method.
$this->drupalGet('fillpdf', array(
'query' => array(
......@@ -263,7 +262,6 @@ class FillPdfMergeTestCase extends ImageFieldTestCase {
simplified format).'
);
// Test filename title generation. Configure it, merge the PDF without
// handling, and then save it as a file and check the name.
db_update('fillpdf_forms')
......@@ -296,7 +294,6 @@ class FillPdfMergeTestCase extends ImageFieldTestCase {
$expected_filename = 'Token_Test_term_title.pdf';
$this->assertEqual($expected_filename, $filename, t('Filename of generated file (@actual) matches specified entity token pattern (@expected). Current page URL: @url', array('@actual' => $filename, '@expected' => $expected_filename, '@url' => $where_are_we)));
// Test that node access via entity access works.
// Make a basic page.
$entity_access_test_node = new stdClass();
......@@ -357,7 +354,6 @@ class FillPdfMergeTestCase extends ImageFieldTestCase {
$default_nid_merge_result = variable_get('fillpdf_test_last_merge_metadata');
$this->assertEqual('Entity access test', $default_nid_merge_result['fields']['TextField'], 'Configured node properly used as default when no parameters specified.');
// Re-enable Entity Tokens.
module_enable(array('entity_token'));
......@@ -376,7 +372,6 @@ class FillPdfMergeTestCase extends ImageFieldTestCase {
$default_entity_merge_result = variable_get('fillpdf_test_last_merge_metadata');
$this->assertEqual('Test term', $default_entity_merge_result['fields']['TextField'], 'Test term set as default entity properly used when no parameters specified.');
$field_test_image = field_get_items('node', $this->testNode, 'field_test_image');
$node_file = file_load($field_test_image[0]['fid']);
$this->assertEqual(
......
......@@ -59,6 +59,7 @@ class FillPdfTestCase extends FileFieldTestCase {
/**
* Ensure that fillpdf_link_from_context() functions properly.
*
* @throws \EntityMalformedException
*/
public function testLinkFromContext() {
......@@ -188,7 +189,6 @@ class FillPdfTestCase extends FileFieldTestCase {
$this->drupalGet('system/files/fillpdf/output/fillpdf_test_v4.pdf');
$this->assertResponse(403, 'User without Administer PDFs and without Publish All PDFs cannot access PDF they cannot view the node for.');
// Test access when generated through entities.
$this->drupalLogin($this->privilegedUser);
$fillpdf_object = fillpdf_merge_pdf($fid, NULL, NULL, NULL, FALSE, FALSE, TRUE, FALSE, NULL, NULL, array("node:{$new_node->nid}"));
......
......@@ -72,20 +72,24 @@ trait FillPdfTestHelper {
/**
* Create a new image field against a taxonomy term type.
* @see \ImageFieldTestCase::createImageField()
*
* @param $name
* @param string $name
* The name of the new field (all lowercase), exclude the "field_" prefix.
* @param $type_name
* The node type that this field will be added to.
* @param $field_settings
* @param array $field_settings
* A list of field settings that will be added to the defaults.
* @param $instance_settings
* @param array $instance_settings
* A list of instance settings that will be added to the instance defaults.
* @param $widget_settings
* @param array $widget_settings
* A list of widget settings that will be added to the widget defaults.
*
* @return mixed
* The return value of field_create_instance().
*
* @throws \FieldException
*
* @see \ImageFieldTestCase::createImageField()
*/
protected function createImageFieldForTaxonomyTerm($name, $type_name, $field_settings = array(), $instance_settings = array(), $widget_settings = array()) {
$field = array(
......
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