From bdc34e25b30e8e2a7c03747fb96ffc40ce4cee22 Mon Sep 17 00:00:00 2001 From: Lance Willett Date: Wed, 11 Mar 2020 14:21:35 -0700 Subject: [PATCH 1/5] Shortcodes: enable inline PDFs --- modules/shortcodes/inline-pdfs.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 modules/shortcodes/inline-pdfs.php diff --git a/modules/shortcodes/inline-pdfs.php b/modules/shortcodes/inline-pdfs.php new file mode 100644 index 0000000000000..67cc2e6709c2a --- /dev/null +++ b/modules/shortcodes/inline-pdfs.php @@ -0,0 +1,16 @@ + +

%2$s

+ ', + esc_attr( $url ) + ); +} From 83fd27059577fb806d6bc51f3fe58014e2fe8ff1 Mon Sep 17 00:00:00 2001 From: Lance Willett Date: Wed, 11 Mar 2020 15:06:38 -0700 Subject: [PATCH 2/5] Fix sprintf replacement --- modules/shortcodes/inline-pdfs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/shortcodes/inline-pdfs.php b/modules/shortcodes/inline-pdfs.php index 67cc2e6709c2a..41d76396d768c 100644 --- a/modules/shortcodes/inline-pdfs.php +++ b/modules/shortcodes/inline-pdfs.php @@ -9,7 +9,7 @@ function inline_pdf_embed_handler( $matches, $attr, $url ) { return sprintf( ' -

%2$s

+

%1$s

', esc_attr( $url ) ); From f25dafc5823bb5ac2bda675901a905b069cbf709 Mon Sep 17 00:00:00 2001 From: Lance Willett Date: Sun, 29 Mar 2020 16:32:51 -0700 Subject: [PATCH 3/5] Add unit tests and fix lint errors --- .../shortcodes/test-class.inline-pdf.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/php/modules/shortcodes/test-class.inline-pdf.php diff --git a/tests/php/modules/shortcodes/test-class.inline-pdf.php b/tests/php/modules/shortcodes/test-class.inline-pdf.php new file mode 100644 index 0000000000000..1ae2b8f79b73b --- /dev/null +++ b/tests/php/modules/shortcodes/test-class.inline-pdf.php @@ -0,0 +1,32 @@ +factory()->post->create_and_get( array( 'post_content' => $url ) ); + + setup_postdata( $post ); + + // Test HTML version. + ob_start(); + the_content(); + $actual = ob_get_clean(); + $this->assertContains( + sprintf( + ' +

%1$s

+
', + $url + ), + $actual + ); + } +} From 54134e5fa3c89cbb28ca9639e5173db725730b9c Mon Sep 17 00:00:00 2001 From: Lance Willett Date: Sun, 29 Mar 2020 16:34:47 -0700 Subject: [PATCH 4/5] Fix lint errors, add prefix, and other fixes Add unit test --- modules/shortcodes/inline-pdfs.php | 22 +++++++++++++++---- .../shortcodes/test-class.inline-pdf.php | 17 +++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/modules/shortcodes/inline-pdfs.php b/modules/shortcodes/inline-pdfs.php index 41d76396d768c..8e1c475af386c 100644 --- a/modules/shortcodes/inline-pdfs.php +++ b/modules/shortcodes/inline-pdfs.php @@ -1,12 +1,26 @@

%1$s

diff --git a/tests/php/modules/shortcodes/test-class.inline-pdf.php b/tests/php/modules/shortcodes/test-class.inline-pdf.php index 1ae2b8f79b73b..a2b348b5e0e50 100644 --- a/tests/php/modules/shortcodes/test-class.inline-pdf.php +++ b/tests/php/modules/shortcodes/test-class.inline-pdf.php @@ -1,8 +1,15 @@ factory()->post->create_and_get( array( 'post_content' => $url ) ); + $url = 'https://jetpackme.files.wordpress.com/2017/08/jetpack-tips-for-hosts.pdf'; + $post = $this->factory()->post->create_and_get( array( 'post_content' => $url ) ); setup_postdata( $post ); @@ -21,9 +28,7 @@ public function test_shortcodes_inline_pdf() { $actual = ob_get_clean(); $this->assertContains( sprintf( - ' -

%1$s

-
', + '

%1$s

' . "\n", $url ), $actual From fc617a919939a6668fe5f079c5f1de983bdc57aa Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Mon, 30 Mar 2020 13:44:50 +0200 Subject: [PATCH 5/5] Fix unit test --- tests/php/modules/shortcodes/test-class.inline-pdf.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/php/modules/shortcodes/test-class.inline-pdf.php b/tests/php/modules/shortcodes/test-class.inline-pdf.php index a2b348b5e0e50..a18208f7839f0 100644 --- a/tests/php/modules/shortcodes/test-class.inline-pdf.php +++ b/tests/php/modules/shortcodes/test-class.inline-pdf.php @@ -26,9 +26,12 @@ public function test_shortcodes_inline_pdf() { ob_start(); the_content(); $actual = ob_get_clean(); + + wp_reset_postdata(); + $this->assertContains( sprintf( - '

%1$s

' . "\n", + '

%1$s

' . "\n", $url ), $actual