Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
jakejackson1 committed Mar 21, 2024
1 parent 9173274 commit f962c1e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Model/Model_Shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public function process( $attributes ) {
$attributes = apply_filters( 'gfpdf_gravityforms_shortcode_attributes', $attributes );

try {
$attributes['entry'] = $this->get_entry_id_if_empty( $attributes['entry'] );
$original_entry_id = $attributes['entry'];
$attributes['entry'] = $this->get_entry_id_if_empty( $original_entry_id );

/* Do PDF validation */
$this->get_pdf_config( $attributes['entry'], $attributes['id'] );
Expand All @@ -103,7 +104,7 @@ public function process( $attributes ) {
$attributes['url'] = $pdf->get_pdf_url( $attributes['id'], $attributes['entry'], $download, $print );

/* Sign the URL to allow direct access to the PDF until it expires */
if ( ! empty( $attributes['signed'] ) ) {
if ( ! empty( $attributes['signed'] ) && ! empty ( $original_entry_id ) ) {

Check failure on line 107 in src/Model/Model_Shortcodes.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Space before opening parenthesis of function call prohibited
$attributes['url'] = $this->url_signer->sign( $attributes['url'], $attributes['expires'] );
}

Expand Down
18 changes: 18 additions & 0 deletions tests/phpunit/unit-tests/test-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,24 @@ public function test_gravitypdf_shortcode() {
$_GET['lid'] = $entry['id'];
$this->assertStringContainsString( 'Download PDF', $this->model->process( [ 'id' => '556690c67856b' ] ) );

unset( $_GET['lid'] );
$_GET['entry'] = $entry['id'];
$this->assertStringContainsString( 'Download PDF', $this->model->process( [ 'id' => '556690c67856b' ] ) );

/* Test we ignore the signed feature if the entry ID is taken from a URL parameter */
$url2 = $this->model->process(
[
'id' => '556690c67856b',
'signed' => '1',
]
);

$this->assertStringContainsString( 'Download PDF', $url2 );
$this->assertStringContainsString( '<a href=', $url2 );
$this->assertStringNotContainsString( '&#038;signature=', $url2 );
$this->assertStringNotContainsString( '&#038;expires=', $url2 );

/* Test for errors */
$_GET['lid'] = '5000';
$this->assertStringContainsString( '<pre class="gravitypdf-error">', $this->model->process( [ 'id' => '556690c67856b' ] ) );

Expand Down

0 comments on commit f962c1e

Please sign in to comment.