From b9aedaf29a1fe219f30bcdf7d6bb8cba351c6e13 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Wed, 25 Jul 2018 13:19:03 -0400 Subject: [PATCH 01/15] remove travis notifications to the defunct hipchat room --- .travis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 22b3a00c5..92167ba9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,8 +49,3 @@ before_script: - cd "$WP_CORE_DIR/src/wp-content/themes/$SLUG" script: phpunit - -notifications: - hipchat: - rooms: - secure: mrJDwl2LYmWGY6gKUEsSnbGp3mQ8UhVQkb9oBmRSDx9T/hCSDx4Q2KDLo0OqCFIwDB5BevP16vDDWVmsg8Ldwk+Hh0YAmdUqBAXe21+17ojqSIAdQg6LgLrEFEBNVBlPu89xonRMnsai34RDCoRt5c9OLuWgGVMAcTojpQvPiII= From 97eb94042766aac21e724542f0955c734cf05166 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Wed, 25 Jul 2018 14:07:54 -0400 Subject: [PATCH 02/15] update version numbers in readme for supported PHP, supported WordPress, and Largo --- readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 228dd703c..9a0f89d6f 100644 --- a/readme.md +++ b/readme.md @@ -34,11 +34,11 @@ The project extends work done by [NPR's Project Argo](http://argoproject.org/). **Support** is available [via our helpdesk system](http://support.largoproject.org/) or by emailing [support@largoproject.org](mailto:support@largoproject.org). -**Current version:** v0.5.5.2 +**Current version:** v0.5.5.4 -**Minimum supported PHP version:** 5.3 +**Minimum PHP version:** We only support the [currently-maintained versions of PHP](https://secure.php.net/supported-versions.php). -**Minimum supported WordPress version:** 4.1, though we usually recommend using the current version of WordPress +**Minimum supported WordPress version:** We recommend using [the current version of WordPress](https://wordpress.org/download/releases/). To see what versions of WordPress automated tests are run against, check out [the Travis CI configuration file](./.travis.yml). ## Setup From 85ba11cd6dfc0b7a3fb56d22b0d044e36342ef26 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Wed, 25 Jul 2018 14:08:15 -0400 Subject: [PATCH 03/15] Fix missing word in welcoming-contribution sentence --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 9a0f89d6f..cbd309107 100644 --- a/readme.md +++ b/readme.md @@ -46,7 +46,7 @@ Follow the [setup instructions in the documentation](http://largo.readthedocs.io ## Contributing -We welcome contributions to any of open source projects. +We welcome contributions to any of our open source projects. If you're not sure where to start, [review the open issues on github](https://github.com/INN/Largo/issues) (you might be particularly interested in the issues labelled [help wanted](https://github.com/INN/Largo/labels/help%20wanted) or [good for beginners](https://github.com/INN/Largo/issues?q=label%3A%22good+for+beginners%22)) and then see [our contributing guidelines](/contributing.md) to get started. From abf6948ea5c798b3f025d851ebab086a73b2849b Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Wed, 25 Jul 2018 14:08:27 -0400 Subject: [PATCH 04/15] Update team list in readme.md --- readme.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index cbd309107..e4e75fdd8 100644 --- a/readme.md +++ b/readme.md @@ -56,13 +56,12 @@ If you're still not sure where to start, that's totally fine! [Just shoot us an Built and maintained by the [Institute for Nonprofit News](http://inn.org) product and technology team ([@INNNerds](http://twitter.com/INNNerds)): -- **[Adam Schweigert](https://github.com/aschweigert)** ([@aschweig](http://twitter.com/aschweig)), Senior Director of Product and Technology -- **[RC Lations](https://github.com/rclations)** ([@rclations](https://twitter.com/rclations)), Lead Developer -- **[Julia Smith](https://github.com/julia67)** ([@julia67](https://twitter.com/julia67)), Lead Designer -- **[Ben Keith](https://github.com/benlk)** ([@benlkeith](http://twitter.com/benlkeith)), News Apps Developer -- **[Gabriel Hongsdusit](https://github.com/gabehong)** ([@ghongsdusit](https://twitter.com/ghongsdusit)), Design Apprentice +- **[Kay Lima](https://github.com/kaylima)**, Acting Director +- **[Ben Keith](https://github.com/benlk)** ([@benlkeith](http://twitter.com/benlkeith)), Lead Developer +- **[Tyler Machado](https://github.com/tylermachado)** ([@tylermachado](https://twitter.com/tylermachado)), Front-End Developer +- **Paola Baradello**, Account Director -Special thanks to everyone who has contributed to the project, including: [rnagle](https://github.com/rnagle), [kaeti](https://github.com/kaeti), [jackbrighton](http://github.com/jackbrighton), [danielbachhuber](http://github.com/danielbachhuber), [willhaynes](http://github.com/willhaynes), [drywall](http://github.com/drywall), [nacin](http://github.com/nacin), [meredithinn](http://github.com/meredithinn), [tothebeat](http://github.com/tothebeat), [lindamood](http://github.com/lindamood), [mospaw](http://github.com/mospaw), [DrewAPicture](http://github.com/drewapicture), [nipoez](http://github.com/nipoez), [palewire](http://github.com/palewire), [GaryJones](http://github.com/garyjones), [seamusleahy](http://github.com/seamusleahy), [joshuarrrr](http://github.com/joshuarrrr), [yayannabelle](https://github.com/yayannabelle), [jmusal](https://github.com/jmusal), [ntwb](https://github.com/ntwb) and [MsPseudolus](https://github.com/MsPseudolus). +Special thanks to everyone who has contributed to the project, including: [rnagle](https://github.com/rnagle), [kaeti](https://github.com/kaeti), [jackbrighton](http://github.com/jackbrighton), [danielbachhuber](http://github.com/danielbachhuber), [willhaynes](http://github.com/willhaynes), [drywall](http://github.com/drywall), [nacin](http://github.com/nacin), [meredithinn](http://github.com/meredithinn), [tothebeat](http://github.com/tothebeat), [lindamood](http://github.com/lindamood), [mospaw](http://github.com/mospaw), [DrewAPicture](http://github.com/drewapicture), [nipoez](http://github.com/nipoez), [palewire](http://github.com/palewire), [GaryJones](http://github.com/garyjones), [seamusleahy](http://github.com/seamusleahy), [joshuarrrr](http://github.com/joshuarrrr), [yayannabelle](https://github.com/yayannabelle), [jmusal](https://github.com/jmusal), [ntwb](https://github.com/ntwb), [MsPseudolus](https://github.com/MsPseudolus), [@gabehong](https://github.com/gabehong), [@julia67](https://github.com/julia67), [@rclations](https://github.com/rclations), [@aschweigert Schweigert](https://github.com/aschweigert) and the whole news nerd and WordPress communities. This project builds on a number of great open source projects, including: From fb049d875e0ed356742a9ba1357d597438c6c6c8 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Wed, 25 Jul 2018 14:17:58 -0400 Subject: [PATCH 05/15] update .travis.yml for modern versions of PHP and WordPress --- .travis.yml | 67 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 92167ba9b..57ac170c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,27 +8,60 @@ sudo: false language: php # PHP version used in first build configuration. -# 5.3 matches the version of php installed in the INN/deploy-tools virtualbox -# 5.5 matches http://phpinfo.wpengine.com/ -php: - - "5.3" - - "5.5" +# We only support PHP-supported versions of PHP. +# https://secure.php.net/supported-versions.php +# php: +# - "5.6" +# - "7.0" +# - "7.1" +# - "7.2" # WordPress version used in first build configuration. -env: - - WP_VERSION=master - - WP_VERSION=4.6 - - WP_VERSION=4.5 - - WP_VERSION=4.4 - - WP_VERSION=4.3 - - WP_VERSION=4.2 - - WP_VERSION=4.1 - -# Only test the unittests branch for now +# env: +# - WP_VERSION=master +# - WP_VERSION=4.9 +# - WP_VERSION=4.8 +# - WP_VERSION=4.7 +# - WP_VERSION=4.6 +# - WP_VERSION=4.5 + +# For a breakdown of why these versions were chosen, see https://github.com/INN/WP-DS-NPR-API/issues/12#issuecomment-374730094 +# This list should be rechecked periodically. +matrix: + include: + # PHPunit 5 + - php: 5.6 + env: WP_VERSION=4.5 WP_TESTS_DIR=/tmp/wordpress/tests/phpunit WP_CORE_DIR=/tmp/wordpress + - php: 5.6 + env: WP_VERSION=4.6 WP_TESTS_DIR=/tmp/wordpress/tests/phpunit WP_CORE_DIR=/tmp/wordpress + - php: 5.6 + env: WP_VERSION=4.7 WP_TESTS_DIR=/tmp/wordpress/tests/phpunit WP_CORE_DIR=/tmp/wordpress + - php: 5.6 + env: WP_VERSION=4.8 WP_TESTS_DIR=/tmp/wordpress/tests/phpunit WP_CORE_DIR=/tmp/wordpress + - php: 5.6 + env: WP_VERSION=4.9 WP_TESTS_DIR=/tmp/wordpress/tests/phpunit WP_CORE_DIR=/tmp/wordpress + # PHPUnit 6 + - php: 7.0 + env: WP_VERSION=4.8 WP_TESTS_DIR=/tmp/wordpress/tests/phpunit WP_CORE_DIR=/tmp/wordpress + - php: 7.0 + env: WP_VERSION=4.9 WP_TESTS_DIR=/tmp/wordpress/tests/phpunit WP_CORE_DIR=/tmp/wordpress + # PHPUnit 6 + - php: 7.1 + env: WP_VERSION=4.8 WP_TESTS_DIR=/tmp/wordpress/tests/phpunit WP_CORE_DIR=/tmp/wordpress + - php: 7.1 + env: WP_VERSION=4.9 WP_TESTS_DIR=/tmp/wordpress/tests/phpunit WP_CORE_DIR=/tmp/wordpress + # PHPUnit 7 support will come with https://core.trac.wordpress.org/ticket/43218 + # - php: 7.2 + # env: WP_VERSION=4.8 WP_TESTS_DIR=/tmp/wordpress/tests/phpunit WP_CORE_DIR=/tmp/wordpress + # - php: 7.2 + # env: WP_VERSION=4.9 WP_TESTS_DIR=/tmp/wordpress/tests/phpunit WP_CORE_DIR=/tmp/wordpress + + +# Only test the main development branches for now branches: only: - - develop - - master + - 0.5 + - 0.5-dev # Clones WordPress and configures our testing environment. before_script: From 7c68ff6d7d75425110e47a32cb33829734b6953b Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Wed, 25 Jul 2018 15:08:11 -0400 Subject: [PATCH 06/15] Deprecate largo_fb_user_is_followable largo_fb_user_is_followable used the Facebook Follow Button, https://developers.facebook.com/docs/archive/docs/plugins/follow-button/ in order to determine whether a user or page was followable. By using this public button's HTML markup, we were able to make the followability check without using the Facebook Graph API. Facebook deprecated that button on February 5, 2018. To query the Graph API, we need to have an API key. To require Largo users to acquire an API key, for the sole purpose of checking whether their Facebook page is followable, seems excessive. Therefore, since there's no reasonable way to check whether a Facebook profile is followable, deprecate the functionality by making the function always return false, and clean out its tests. If WP_DEBUG or LARGO_DEBUG are set, provide a deprecation notice to the error log. --- inc/deprecated.php | 24 ++++++++++++++++++++++++ inc/helpers.php | 27 --------------------------- tests/inc/test-helpers.php | 29 ++++------------------------- 3 files changed, 28 insertions(+), 52 deletions(-) diff --git a/inc/deprecated.php b/inc/deprecated.php index e5f7a475c..c4d47d3a8 100644 --- a/inc/deprecated.php +++ b/inc/deprecated.php @@ -28,3 +28,27 @@ function largo_hero_with_caption( $post_id ) { largo_featured_image_hero($post_id); } } + +/** + * Deprecated function to check whether a Facebook user/page was followable. + * + * This function used to use the Facebook Follow button's HTML markup + * https://developers.facebook.com/docs/archive/docs/plugins/follow-button/ + * to determine whether a page or user could be followed. The button was + * deprecated by Facebook on February 5, 2018, and as a result, this function + * stopped working. + * + * There are no plans to provide similar functionality in the future, because + * the relevant Facebook Graph API calls require Facebook API tokens, + * and it seems excessive to require theme users to get one just for this check. + * + * @param string $username a valid Facebook username or page name. They're generally indistinguishable, except pages get to use '-' + * @return bool False + */ +function largo_fb_user_is_followable( $username = '' ) { + if ( WP_DEBUG || LARGO_DEBUG ) { + error_log( 'largo_db_user_is_followable is deprecated and should not be used.' ); + } + return false; +} + diff --git a/inc/helpers.php b/inc/helpers.php index 3851f2868..8964ead54 100644 --- a/inc/helpers.php +++ b/inc/helpers.php @@ -27,29 +27,6 @@ function largo_fb_url_to_username( $url ) { return $username; } -/** - * Checks to see if a given Facebook username or ID has following enabled by - * checking the iframe of that user's "Follow" button for . - * Usernames that can be followed have . - * Users that can't be followed don't. - * Users that don't exist don't. - * - * @param string $username a valid Facebook username or page name. They're generally indistinguishable, except pages get to use '-' - * @uses wp_remote_get - * @return bool The user specified by the username or ID can be followed - */ -function largo_fb_user_is_followable( $username ) { - // syntax for this iframe taken from https://developers.facebook.com/docs/plugins/follow-button/ - $get = wp_remote_get( 'https://www.facebook.com/plugins/follow.php?href=https%3A%2F%2Fwww.facebook.com%2F' . $username . '&width&height=80&colorscheme=light&layout=button&show_faces=true' ); - if ( ! is_wp_error( $get ) ) { - $response = $get['body']; - if ( strpos( $response, 'table' ) !== false ) { - return true; // can follow - } - return false; // cannot follow - } -} - /** * Cleans a Facebook url to the bare username or id when the user is edited * @@ -84,7 +61,6 @@ function clean_user_fb_username( $user_id ) { * Checks that the Facebook URL submitted is valid and the user is followable and causes an error if not * * @uses largo_fb_url_to_username - * @uses largo_fb_user_is_followable * @param $errors the error object * @param bool $update whether this is a user update * @param object $user a WP_User object @@ -100,9 +76,6 @@ function validate_fb_username( $errors, $update, $user ) { // it's not a valid Facebook username, because it uses an invalid character $errors->add( 'fb_username', '' . $fb_suspect . ' ' . __( 'is an invalid Facebook username.', 'largo' ) . '

' . '

' . __('Facebook usernames only use the uppercase and lowercase alphabet letters (a-z A-Z), the Arabic numbers (0-9), periods (.) and dashes (-)', 'largo' ) ); } - if ( ! largo_fb_user_is_followable( $fb_user ) ) { - $errors->add( 'fb_username',' ' . $fb_suspect . ' ' . __( 'does not allow followers on Facebook.', 'largo' ) . '

' . '

' . __('Follow these instructions to allow others to follow you.', 'largo' ) ); - } } } } diff --git a/tests/inc/test-helpers.php b/tests/inc/test-helpers.php index 83715480b..d8cbd7fbf 100644 --- a/tests/inc/test-helpers.php +++ b/tests/inc/test-helpers.php @@ -67,34 +67,13 @@ function test_largo_fb_url_to_username() { function test_largo_fb_user_is_followable() { /** - * With no input, there should be no

in the resulting iframe + * The function has been changed to always return false. */ - $result = largo_fb_user_is_followable(""); - $this->assertFalse($result, "The Facebook follow button iframe HTML structure has changed and largo_fb_url_to_username no longer operates predictably. Please fix."); - unset($result); - - /** - * With Mark Zuckerberg, we hope that he will remain followable. - */ - $result = largo_fb_user_is_followable("zuck"); - $this->assertTrue($result, "Either Mark Zuckerberg is no longer followable, or the Facebook follow button iframe HTML structure has changed and largo_fb_url_to_username no longer operates predictably. Please log into Facebook and check that https://www.facebook.com/zuck has a 'Follow' button."); - unset($result); - - /** - * With a user that does not exist, we hope that the user will continue to not exist - */ - $result = largo_fb_user_is_followable("fb8c57ff40dda4b6898ae049d8298584"); - $this->assertFalse($result, "Either https://www.facebook.com/fb8c57ff40dda4b6898ae049d8298584 is user that exists and allows follows, or the Facebook follow button iframe HTML structure has changed and largo_fb_url_to_username no longer operates predictably."); - unset($result); - - /** - * With an invalid username, this should return false - */ - $result = largo_fb_user_is_followable("%22Aardvarks+lurk%2C+OK%3F%22"); - $this->assertFalse($result, "Either https://www.facebook.com/%22Aardvarks+lurk%2C+OK%3F%22 is user that exists and allows follows (not at all likely), or the Facebook follow button iframe HTML structure has changed and largo_fb_url_to_username no longer operates predictably."); + $result = largo_fb_user_is_followable( 'zuck' ); + $this->assertFalse($result, "largo_fb_user_is_followable doesn't work, so it shouldn't be returning anything other than False. What changed?"); unset($result); } - + function test_clean_user_fb_username() { $this->markTestIncomplete('This test has not been implemented yet.'); } From 8ede2498f38f16f1c6bd45afb3178aed65eaf5a6 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Wed, 25 Jul 2018 16:04:33 -0400 Subject: [PATCH 07/15] Hopefully resolve invalid-index issue in post-social tests --- inc/post-social.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/inc/post-social.php b/inc/post-social.php index 887a4949a..1acadbb12 100644 --- a/inc/post-social.php +++ b/inc/post-social.php @@ -32,7 +32,7 @@ function largo_post_social_links( $echo = true ) { $values = get_post_custom( $post->ID ); - if ( $utilities['facebook'] === '1' ) { + if ( isset( $utilities['facebook'] ) && '1' === $utilities['facebook'] ) { $fb_share = ''; $output .= sprintf( $fb_share, @@ -41,7 +41,7 @@ function largo_post_social_links( $echo = true ) { ); } - if ( $utilities['twitter'] === '1' ) { + if ( isset( $utilities['twitter'] ) && '1' === $utilities['twitter'] ) { $twitter_share = ''; // By default, don't set a via. @@ -86,8 +86,8 @@ function largo_post_social_links( $echo = true ) { __( 'Tweet', 'largo' ) ); } - - if ( $utilities['email'] === '1' ) { + + if ( isset( $utilities['email'] ) && '1' === $utilities['email'] ) { $output .= sprintf( '', esc_attr( __( 'Email', 'largo' ) ), @@ -97,8 +97,7 @@ function largo_post_social_links( $echo = true ) { ); } - - if ( $utilities['print'] === '1' ) { + if ( isset( $utilities['print'] ) && '1' === $utilities['print'] ) { $output .= '' . esc_attr( __( 'Print', 'largo' ) ) . ''; } From d8731501ecdb8f07cab79ae8eaa8e90670710eb5 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Wed, 25 Jul 2018 16:05:25 -0400 Subject: [PATCH 08/15] Improve error logging in PostTemplatesTestFunctions::test_insert_image_no_thumb --- tests/inc/test-post-templates.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/inc/test-post-templates.php b/tests/inc/test-post-templates.php index 2c18ae026..5f6d78746 100644 --- a/tests/inc/test-post-templates.php +++ b/tests/inc/test-post-templates.php @@ -76,8 +76,8 @@ function test_insert_image_no_thumb() { $final1 = largo_remove_hero( $c1 ); $final2 = largo_remove_hero( $c2 ); - $this->assertEquals( $c1final, $final1 ); - $this->assertEquals( $c2final, $final2 ); + $this->assertEquals( $c1final, $final1, "C1" ); + $this->assertEquals( $c2final, $final2, "C2" ); } From 75aad914bb39737ccbe92071e3fa8bce624ed1e9 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Wed, 25 Jul 2018 16:19:20 -0400 Subject: [PATCH 09/15] largo_remove_hero(): remove regex portion that matches an src in the img tag, as it's not necessary for this function and appears to be the cause of https://github.com/INN/largo/issues/1404 --- inc/post-templates.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/inc/post-templates.php b/inc/post-templates.php index c7188f66c..2c8c61380 100644 --- a/inc/post-templates.php +++ b/inc/post-templates.php @@ -195,8 +195,7 @@ function largo_remove_hero( $content ) { // Creates the array: // $matches[0] = // $matches[1] = image id from class="wp-image-[id]" - // $matches[2] = value of src. - $pattern = '/]*class="[^"]*?wp-image-(\d+)[^"]*?"\s+[^>]*src="([^"]*)"[^>]*>/'; + $pattern = '/]*class="[^"]*?wp-image-(\d+)[^"]*?"\s+[^>]*[^>]*>/'; $has_img = preg_match( $pattern, $p[0], $matches ); // 3: if there's no image, there's nothing to worry about. From 35e9492b963105a81d1477258004ac1e62b98e2b Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Wed, 25 Jul 2018 17:50:44 -0400 Subject: [PATCH 10/15] Afer removing image, remove empty p tag For https://github.com/INN/largo/pull/1503#issuecomment-407901229 This change: - removes an empty

- removes an empty

- removes the image but not the p if it's a

foo

- checks that the foo is left behind - checks that a non-matching image isn't removed --- inc/post-templates.php | 5 +++- tests/inc/test-post-templates.php | 39 ++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/inc/post-templates.php b/inc/post-templates.php index 2c8c61380..21a830894 100644 --- a/inc/post-templates.php +++ b/inc/post-templates.php @@ -207,7 +207,10 @@ function largo_remove_hero( $content ) { $post_img_id = $matches[1]; if ( $featured_img_id === $post_img_id ) { - return str_replace( $matches[0], '', $content ); + $minus_image = str_replace( $matches[0], '', $content ); + // remove leading

tag, even if it contains HTML attributes, + // but not if it's not empty + return preg_replace( '/^]?><\/p>/m', '', $minus_image, 1 ); } return $content; diff --git a/tests/inc/test-post-templates.php b/tests/inc/test-post-templates.php index 5f6d78746..3788ff2a1 100644 --- a/tests/inc/test-post-templates.php +++ b/tests/inc/test-post-templates.php @@ -53,32 +53,49 @@ function test_insert_image_no_thumb() { $attachment_url = wp_get_attachment_image_src( $attachment_id, 'large' ); $attachment_url = $attachment_url[0]; + // create our post and set it up. + $post_id = $this->factory->post->create(); + add_post_meta( $post_id, '_thumbnail_id', $attachment_id ); + $this->go_to( '/?p=' . $post_id ); + + // with a post set up like so, remove the thing $c1 = '

1559758083_cef4ef63d2_o

Headings

Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.

'; - $c1final = '

Headings

Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.

'; + $final1 = largo_remove_hero( $c1 ); + $this->assertEquals( $c1final, $final1, "C1" ); + // with a post set up like so, remove the thing + // @todo: how is this setup different that the above setup? $c2 = '

1559758083_cef4ef63d2_o

Headings

Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.

'; - $c2final = '

1559758083_cef4ef63d2_o

Headings

Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.

'; - - $post_id = $this->factory->post->create(); - - add_post_meta( $post_id, '_thumbnail_id', $attachment_id ); - - $this->go_to( '/?p=$post_id' ); - - $final1 = largo_remove_hero( $c1 ); $final2 = largo_remove_hero( $c2 ); - $this->assertEquals( $c1final, $final1, "C1" ); $this->assertEquals( $c2final, $final2, "C2" ); + // test for https://github.com/INN/largo/pull/1503#issuecomment-407901229 + // if the opening paragraph tag contains a matching image and other stuff, + // remove the matching image but nothing else + $c3 = '

1559758083_cef4ef63d2_ofoo

+

Headings

+

Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.

'; + $c3final = '

foo

+

Headings

+

Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.

'; + $final3 = largo_remove_hero( $c3 ); + $this->assertEquals( $c3final, $final3, "C3" ); + + // don't remove the image if it doesn't match the attachment URL + $c4 = '

1559758083_cef4ef63d2_o

+

Headings

+

Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.

'; + $final4 = largo_remove_hero( $c4 ); + $this->assertEquals( $c4, $final4, "C4" ); } function _make_attachment( $upload, $parent_post_id = 0 ) { From 8c4ad0fe2512ad0abffb8b500f1fb3785d4dba8a Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Wed, 25 Jul 2018 18:02:17 -0400 Subject: [PATCH 11/15] Split the largo_remove_hero tests up into separate test functions --- tests/inc/test-post-templates.php | 97 ++++++++++++++++++++++++++++--- 1 file changed, 88 insertions(+), 9 deletions(-) diff --git a/tests/inc/test-post-templates.php b/tests/inc/test-post-templates.php index 3788ff2a1..6790c8f30 100644 --- a/tests/inc/test-post-templates.php +++ b/tests/inc/test-post-templates.php @@ -1,6 +1,7 @@ markTestIncomplete( 'This test has not yet been implemented.' ); } - function test_largo_remove_hero() { + function test_largo_remove_hero_C1() { // returns unchanged when: // global $post is not set // the current $post does not have a featured media thumbnail @@ -33,13 +34,6 @@ function test_largo_remove_hero() { // // Otherwise, the first paragraph is removed from the post contents - $this->markTestIncomplete( 'This test has not yet been implemented.' ); - } - - private $ids = array(); - - function test_insert_image_no_thumb() { - $filename = ( dirname(__FILE__) .'/../mock/img/cat.jpg' ); $contents = file_get_contents( $filename ); @@ -66,6 +60,36 @@ function test_insert_image_no_thumb() {

Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.

'; $final1 = largo_remove_hero( $c1 ); $this->assertEquals( $c1final, $final1, "C1" ); + } + + function test_largo_remove_hero_C2() { + // returns unchanged when: + // global $post is not set + // the current $post does not have a featured media thumbnail + // of_get_option('single_template') is not normal or classic + // the first paragraph of the post contents doesn't have an image + // the image in the first paragraph has a different src and attachment id than the post's featured media thumbnail + // the image in the first paragraph has the same src, or has a different src but the same id, and the image's classes include 'size-small' or 'size-medium' + // + // Otherwise, the first paragraph is removed from the post contents + + $filename = ( dirname(__FILE__) .'/../mock/img/cat.jpg' ); + $contents = file_get_contents( $filename ); + + $upload = wp_upload_bits( basename( $filename ), null, $contents ); + + print_r( $upload['error'] ); + $this->assertTrue( empty( $upload['error'] ) ); + + $attachment_id = $this->_make_attachment( $upload ); + + $attachment_url = wp_get_attachment_image_src( $attachment_id, 'large' ); + $attachment_url = $attachment_url[0]; + + // create our post and set it up. + $post_id = $this->factory->post->create(); + add_post_meta( $post_id, '_thumbnail_id', $attachment_id ); + $this->go_to( '/?p=' . $post_id ); // with a post set up like so, remove the thing // @todo: how is this setup different that the above setup? @@ -77,7 +101,36 @@ function test_insert_image_no_thumb() {

Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.

'; $final2 = largo_remove_hero( $c2 ); $this->assertEquals( $c2final, $final2, "C2" ); + } + function test_largo_remove_hero_C3() { + // returns unchanged when: + // global $post is not set + // the current $post does not have a featured media thumbnail + // of_get_option('single_template') is not normal or classic + // the first paragraph of the post contents doesn't have an image + // the image in the first paragraph has a different src and attachment id than the post's featured media thumbnail + // the image in the first paragraph has the same src, or has a different src but the same id, and the image's classes include 'size-small' or 'size-medium' + // + // Otherwise, the first paragraph is removed from the post contents + + $filename = ( dirname(__FILE__) .'/../mock/img/cat.jpg' ); + $contents = file_get_contents( $filename ); + + $upload = wp_upload_bits( basename( $filename ), null, $contents ); + + print_r( $upload['error'] ); + $this->assertTrue( empty( $upload['error'] ) ); + + $attachment_id = $this->_make_attachment( $upload ); + + $attachment_url = wp_get_attachment_image_src( $attachment_id, 'large' ); + $attachment_url = $attachment_url[0]; + + // create our post and set it up. + $post_id = $this->factory->post->create(); + add_post_meta( $post_id, '_thumbnail_id', $attachment_id ); + $this->go_to( '/?p=' . $post_id ); // test for https://github.com/INN/largo/pull/1503#issuecomment-407901229 // if the opening paragraph tag contains a matching image and other stuff, // remove the matching image but nothing else @@ -90,6 +143,33 @@ function test_insert_image_no_thumb() { $final3 = largo_remove_hero( $c3 ); $this->assertEquals( $c3final, $final3, "C3" ); + } + + function test_largo_remove_hero_C4() { + // returns unchanged when: + // global $post is not set + // the current $post does not have a featured media thumbnail + // of_get_option('single_template') is not normal or classic + // the first paragraph of the post contents doesn't have an image + // the image in the first paragraph has a different src and attachment id than the post's featured media thumbnail + // the image in the first paragraph has the same src, or has a different src but the same id, and the image's classes include 'size-small' or 'size-medium' + // + // Otherwise, the first paragraph is removed from the post contents + + $filename = ( dirname(__FILE__) .'/../mock/img/cat.jpg' ); + $contents = file_get_contents( $filename ); + + $upload = wp_upload_bits( basename( $filename ), null, $contents ); + + print_r( $upload['error'] ); + $this->assertTrue( empty( $upload['error'] ) ); + + $attachment_id = $this->_make_attachment( $upload ); + + $attachment_url = wp_get_attachment_image_src( $attachment_id, 'large' ); + $attachment_url = $attachment_url[0]; + + // don't remove the image if it doesn't match the attachment URL $c4 = '

1559758083_cef4ef63d2_o

Headings

@@ -123,7 +203,6 @@ function _make_attachment( $upload, $parent_post_id = 0 ) { wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); return $this->ids[] = $id; - } function test_largo_get_partial_by_post_type() { From 79ab0884e028a0b852835a89fd1338254f3fdb52 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Wed, 25 Jul 2018 18:06:16 -0400 Subject: [PATCH 12/15] remove whitespace from start and end of post --- inc/post-templates.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/post-templates.php b/inc/post-templates.php index 21a830894..9f4583a35 100644 --- a/inc/post-templates.php +++ b/inc/post-templates.php @@ -210,7 +210,7 @@ function largo_remove_hero( $content ) { $minus_image = str_replace( $matches[0], '', $content ); // remove leading

tag, even if it contains HTML attributes, // but not if it's not empty - return preg_replace( '/^]?><\/p>/m', '', $minus_image, 1 ); + return trim( preg_replace( '/^]?><\/p>/m', '', $minus_image, 1 ) ); } return $content; From a2a20aa92ef6d9f36a2bbe3cf7445063e3a4c945 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Wed, 25 Jul 2018 18:18:39 -0400 Subject: [PATCH 13/15] largo_remove_hero: Add two more test cases: global post is not set, current post does not have featured media thumbnail --- tests/inc/test-post-templates.php | 77 ++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 7 deletions(-) diff --git a/tests/inc/test-post-templates.php b/tests/inc/test-post-templates.php index 6790c8f30..13cd308c2 100644 --- a/tests/inc/test-post-templates.php +++ b/tests/inc/test-post-templates.php @@ -23,6 +23,37 @@ function test_is_post_template() { $this->markTestIncomplete( 'This test has not yet been implemented.' ); } + // returns unchanged when: + // global $post is not set + function test_largo_remove_hero_C0() { + // the current $post does not have a featured media thumbnail + // of_get_option('single_template') is not normal or classic + // the first paragraph of the post contents doesn't have an image + // the image in the first paragraph has a different src and attachment id than the post's featured media thumbnail + // + // Otherwise, the first paragraph is removed from the post contents + + $filename = ( dirname(__FILE__) .'/../mock/img/cat.jpg' ); + $contents = file_get_contents( $filename ); + + $upload = wp_upload_bits( basename( $filename ), null, $contents ); + + print_r( $upload['error'] ); + $this->assertTrue( empty( $upload['error'] ) ); + + $attachment_id = $this->_make_attachment( $upload ); + + $attachment_url = wp_get_attachment_image_src( $attachment_id, 'large' ); + $attachment_url = $attachment_url[0]; + + // with a post set up like so, remove the thing + $c0 = '

1559758083_cef4ef63d2_o

+

Headings

+

Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.

'; + $final1 = largo_remove_hero( $c0 ); + $this->assertEquals( $c0, $final0, "C0" ); + } + function test_largo_remove_hero_C1() { // returns unchanged when: // global $post is not set @@ -30,7 +61,6 @@ function test_largo_remove_hero_C1() { // of_get_option('single_template') is not normal or classic // the first paragraph of the post contents doesn't have an image // the image in the first paragraph has a different src and attachment id than the post's featured media thumbnail - // the image in the first paragraph has the same src, or has a different src but the same id, and the image's classes include 'size-small' or 'size-medium' // // Otherwise, the first paragraph is removed from the post contents @@ -69,7 +99,6 @@ function test_largo_remove_hero_C2() { // of_get_option('single_template') is not normal or classic // the first paragraph of the post contents doesn't have an image // the image in the first paragraph has a different src and attachment id than the post's featured media thumbnail - // the image in the first paragraph has the same src, or has a different src but the same id, and the image's classes include 'size-small' or 'size-medium' // // Otherwise, the first paragraph is removed from the post contents @@ -92,12 +121,13 @@ function test_largo_remove_hero_C2() { $this->go_to( '/?p=' . $post_id ); // with a post set up like so, remove the thing - // @todo: how is this setup different that the above setup? + // where C1 has the CSS class .size-large, C2 has the CSS class .size-medium. + // That distinction made a difference before pull request #1400 removed the relevant check: + // https://github.com/INN/largo/pull/1400/files#diff-751911f6a0ebcc05da47094668329397L234 $c2 = '

1559758083_cef4ef63d2_o

Headings

Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.

'; - $c2final = '

1559758083_cef4ef63d2_o

-

Headings

+ $c2final = '

Headings

Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.

'; $final2 = largo_remove_hero( $c2 ); $this->assertEquals( $c2final, $final2, "C2" ); @@ -110,7 +140,6 @@ function test_largo_remove_hero_C3() { // of_get_option('single_template') is not normal or classic // the first paragraph of the post contents doesn't have an image // the image in the first paragraph has a different src and attachment id than the post's featured media thumbnail - // the image in the first paragraph has the same src, or has a different src but the same id, and the image's classes include 'size-small' or 'size-medium' // // Otherwise, the first paragraph is removed from the post contents @@ -152,7 +181,6 @@ function test_largo_remove_hero_C4() { // of_get_option('single_template') is not normal or classic // the first paragraph of the post contents doesn't have an image // the image in the first paragraph has a different src and attachment id than the post's featured media thumbnail - // the image in the first paragraph has the same src, or has a different src but the same id, and the image's classes include 'size-small' or 'size-medium' // // Otherwise, the first paragraph is removed from the post contents @@ -178,6 +206,41 @@ function test_largo_remove_hero_C4() { $this->assertEquals( $c4, $final4, "C4" ); } + // returns unchanged when: + // the current $post does not have a featured media thumbnail + function test_largo_remove_hero_C5() { + // returns unchanged when: + // of_get_option('single_template') is not normal or classic + // the first paragraph of the post contents doesn't have an image + // the image in the first paragraph has a different src and attachment id than the post's featured media thumbnail + // + // Otherwise, the first paragraph is removed from the post contents + + $filename = ( dirname(__FILE__) .'/../mock/img/cat.jpg' ); + $contents = file_get_contents( $filename ); + + $upload = wp_upload_bits( basename( $filename ), null, $contents ); + + print_r( $upload['error'] ); + $this->assertTrue( empty( $upload['error'] ) ); + + $attachment_id = $this->_make_attachment( $upload ); + + $attachment_url = wp_get_attachment_image_src( $attachment_id, 'large' ); + $attachment_url = $attachment_url[0]; + + // create our post and set it up. + $post_id = $this->factory->post->create(); + $this->go_to( '/?p=' . $post_id ); + + // with a post set up like so, remove the thing + $c5 = '

1559758083_cef4ef63d2_o

+

Headings

+

Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.

'; + $final1 = largo_remove_hero( $c5 ); + $this->assertEquals( $c5, $final1, "C5" ); + } + function _make_attachment( $upload, $parent_post_id = 0 ) { $type = ''; From b8f778252cafd88fa3083377ec87e859b8388dc0 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Wed, 25 Jul 2018 18:21:23 -0400 Subject: [PATCH 14/15] undefined variable, doh --- tests/inc/test-post-templates.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/inc/test-post-templates.php b/tests/inc/test-post-templates.php index 13cd308c2..03c75d35b 100644 --- a/tests/inc/test-post-templates.php +++ b/tests/inc/test-post-templates.php @@ -50,7 +50,7 @@ function test_largo_remove_hero_C0() { $c0 = '

1559758083_cef4ef63d2_o

Headings

Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.

'; - $final1 = largo_remove_hero( $c0 ); + $final0 = largo_remove_hero( $c0 ); $this->assertEquals( $c0, $final0, "C0" ); } @@ -237,8 +237,8 @@ function test_largo_remove_hero_C5() { $c5 = '

1559758083_cef4ef63d2_o

Headings

Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.

'; - $final1 = largo_remove_hero( $c5 ); - $this->assertEquals( $c5, $final1, "C5" ); + $final5 = largo_remove_hero( $c5 ); + $this->assertEquals( $c5, $final5, "C5" ); } function _make_attachment( $upload, $parent_post_id = 0 ) { From ff1e3457fa5f8d432fa225e0fbbcadbfa0c30d70 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Wed, 25 Jul 2018 21:27:43 -0400 Subject: [PATCH 15/15] Add documentation to of_sanitize_multicheck and fix a type error --- lib/options-framework/options-sanitize.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/options-framework/options-sanitize.php b/lib/options-framework/options-sanitize.php index d33638030..b48c567eb 100644 --- a/lib/options-framework/options-sanitize.php +++ b/lib/options-framework/options-sanitize.php @@ -38,10 +38,19 @@ function of_sanitize_checkbox( $input ) { } add_filter( 'of_sanitize_checkbox', 'of_sanitize_checkbox' ); -/* Multicheck */ - +/** + * Multicheck sanitization function for the options framework + * + * This sanitizes the submitted option for a multiple-checkbox input + * based on the argument $option + * + * @since 0.1 + * @param Array $input An array of options as descriped in the Options Framework. + * @param Array $option An array of valid checkbox values for the input + * @return Array sanitized options + */ function of_sanitize_multicheck( $input, $option ) { - $output = ''; + $output = array(); if ( is_array( $input ) ) { foreach( $option['options'] as $key => $value ) { $output[$key] = "0"; @@ -373,4 +382,4 @@ function of_validate_hex( $hex ) { else { return true; } -} \ No newline at end of file +}