Skip to content

Commit

Permalink
Merge pull request #1503 from INN/1404-fix-failing-test
Browse files Browse the repository at this point in the history
Update Travis CI config, fix broken tests, update README, and diverse minor fixes
  • Loading branch information
benlk committed Jul 26, 2018
2 parents 72cc843 + ff1e345 commit 1c1023e
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 115 deletions.
72 changes: 50 additions & 22 deletions .travis.yml
Expand Up @@ -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:
Expand All @@ -49,8 +82,3 @@ before_script:
- cd "$WP_CORE_DIR/src/wp-content/themes/$SLUG"

script: phpunit

notifications:
hipchat:
rooms:
secure: mrJDwl2LYmWGY6gKUEsSnbGp3mQ8UhVQkb9oBmRSDx9T/hCSDx4Q2KDLo0OqCFIwDB5BevP16vDDWVmsg8Ldwk+Hh0YAmdUqBAXe21+17ojqSIAdQg6LgLrEFEBNVBlPu89xonRMnsai34RDCoRt5c9OLuWgGVMAcTojpQvPiII=
24 changes: 24 additions & 0 deletions inc/deprecated.php
Expand Up @@ -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;
}

27 changes: 0 additions & 27 deletions inc/helpers.php
Expand Up @@ -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 <table>.
* Usernames that can be followed have <tables>.
* 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 . '&amp;width&amp;height=80&amp;colorscheme=light&amp;layout=button&amp;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
*
Expand Down Expand Up @@ -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
Expand All @@ -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', '<b>' . $fb_suspect . '</b> ' . __( 'is an invalid Facebook username.', 'largo' ) . '</p>' . '<p>' . __('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',' <b>' . $fb_suspect . '</b> ' . __( 'does not allow followers on Facebook.', 'largo' ) . '</p>' . '<p>' . __('<a href="https://www.facebook.com/help/201148673283205#How-can-I-let-people-follow-me?">Follow these instructions</a> to allow others to follow you.', 'largo' ) );
}
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions inc/post-social.php
Expand Up @@ -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 = '<span class="facebook"><a target="_blank" href="http://www.facebook.com/sharer/sharer.php?u=%1$s"><i class="icon-facebook"></i><span class="hidden-phone">%2$s</span></a></span>';
$output .= sprintf(
$fb_share,
Expand All @@ -41,7 +41,7 @@ function largo_post_social_links( $echo = true ) {
);
}

if ( $utilities['twitter'] === '1' ) {
if ( isset( $utilities['twitter'] ) && '1' === $utilities['twitter'] ) {
$twitter_share = '<span class="twitter"><a target="_blank" href="https://twitter.com/intent/tweet?text=%1$s&url=%2$s%3$s"><i class="icon-twitter"></i><span class="hidden-phone">%4$s</span></a></span>';

// By default, don't set a via.
Expand Down Expand Up @@ -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(
'<span data-service="email" class="email share-button"><a href="mailto:?subject=%2$s&body=%3$s%0D%0A%4$s" target="_blank"><i class="icon-mail"></i> <span class="hidden-phone">%1$s</span></a></span>',
esc_attr( __( 'Email', 'largo' ) ),
Expand All @@ -97,8 +97,7 @@ function largo_post_social_links( $echo = true ) {
);
}


if ( $utilities['print'] === '1' ) {
if ( isset( $utilities['print'] ) && '1' === $utilities['print'] ) {
$output .= '<span class="print"><a href="#" onclick="window.print()" title="' . esc_attr( __( 'Print this article', 'largo' ) ) . '" rel="nofollow"><i class="icon-print"></i><span class="hidden-phone">' . esc_attr( __( 'Print', 'largo' ) ) . '</span></a></span>';
}

Expand Down
8 changes: 5 additions & 3 deletions inc/post-templates.php
Expand Up @@ -195,8 +195,7 @@ function largo_remove_hero( $content ) {
// Creates the array:
// $matches[0] = <img src="..." class="..." id="..." />
// $matches[1] = image id from class="wp-image-[id]"
// $matches[2] = value of src.
$pattern = '/<img\s+[^>]*class="[^"]*?wp-image-(\d+)[^"]*?"\s+[^>]*src="([^"]*)"[^>]*>/';
$pattern = '/<img\s+[^>]*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.
Expand All @@ -208,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 <p></p> tag, even if it contains HTML attributes,
// but not if it's not empty
return trim( preg_replace( '/^<p[^>]?><\/p>/m', '', $minus_image, 1 ) );
}

return $content;
Expand Down
17 changes: 13 additions & 4 deletions lib/options-framework/options-sanitize.php
Expand Up @@ -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";
Expand Down Expand Up @@ -373,4 +382,4 @@ function of_validate_hex( $hex ) {
else {
return true;
}
}
}
19 changes: 9 additions & 10 deletions readme.md
Expand Up @@ -34,19 +34,19 @@ 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

Follow the [setup instructions in the documentation](http://largo.readthedocs.io/users/download.html).

## 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.

Expand All @@ -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:

Expand Down
29 changes: 4 additions & 25 deletions tests/inc/test-helpers.php
Expand Up @@ -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 <table> 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.');
}
Expand Down

0 comments on commit 1c1023e

Please sign in to comment.