Commit fb2225fb authored by Erick Hitter's avatar Erick Hitter

Merge branch 'fix/phpcs' into 'master'

v0.6

See merge request !4
parents f1c6070c fca42b16
Pipeline #1003 passed with stages
in 3 minutes and 32 seconds
......@@ -17,6 +17,3 @@ indent_size = 4
[{.jshintrc,*.json,*.yml}]
indent_style = space
indent_size = 2
[{*.txt,wp-config-sample.php}]
end_of_line = crlf
......@@ -2,6 +2,7 @@ variables:
# Configure mysql service (https://hub.docker.com/_/mysql/)
MYSQL_DATABASE: wordpress_tests
MYSQL_ROOT_PASSWORD: mysql
WP_VERSION: latest
cache:
paths:
......@@ -10,7 +11,7 @@ cache:
before_script:
# Set up WordPress tests
- bash bin/install-wp-tests.sh $MYSQL_DATABASE root $MYSQL_ROOT_PASSWORD mysql latest true
- bash bin/install-wp-tests.sh $MYSQL_DATABASE root $MYSQL_ROOT_PASSWORD mysql $WP_VERSION true
# PHPUnit
- |
......@@ -20,10 +21,43 @@ before_script:
composer global require "phpunit/phpunit=4.8.*"
fi
# Install PHPCS and WPCS
- composer global require automattic/vipwpcs
- composer global require phpcompatibility/phpcompatibility-wp
- phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs,$HOME/.composer/vendor/automattic/vipwpcs,$HOME/.composer/vendor/phpcompatibility/php-compatibility,$HOME/.composer/vendor/phpcompatibility/phpcompatibility-paragonie,$HOME/.composer/vendor/phpcompatibility/phpcompatibility-wp
PHPunit:PHP5.3:MySQL:
stage: test
variables:
WP_VERSION: 5.1.1
image: containers.ethitter.com:443/docker/images/php:5.3
services:
- mysql:5.6
script:
- find . -type "f" -iname "*.php" | xargs -L "1" php -l
- phpunit
PHPunit:PHP5.6:MySQL:
stage: test
image: containers.ethitter.com:443/docker/images/php:5.6
services:
- mysql:5.6
script:
- find . -type "f" -iname "*.php" | xargs -L "1" php -l
- phpunit
PHPunit:PHP7.0:MySQL:
stage: test
image: containers.ethitter.com:443/docker/images/php:7.0
services:
- mysql:5.6
script:
- find . -type "f" -iname "*.php" | xargs -L "1" php -l
- phpunit
PHPunit:PHP7.1:MySQL:
stage: test
image: containers.ethitter.com:443/docker/images/php:7.1
services:
- mysql:5.6
script:
- find . -type "f" -iname "*.php" | xargs -L "1" php -l
- phpunit
PHPunit:PHP7.2:MySQL:
stage: test
......@@ -32,9 +66,7 @@ PHPunit:PHP7.2:MySQL:
- mysql:5.6
script:
- find . -type "f" -iname "*.php" | xargs -L "1" php -l
- phpcs -n
- phpunit
allow_failure: true
PHPunit:PHP7.3:MySQL:
stage: test
......@@ -43,13 +75,21 @@ PHPunit:PHP7.3:MySQL:
- mysql:5.6
script:
- find . -type "f" -iname "*.php" | xargs -L "1" php -l
- phpcs -n
- phpunit
allow_failure: true
PHPCS:
stage: test
image: containers.ethitter.com:443/docker/images/php:7.3
before_script:
- composer global require automattic/vipwpcs
- composer global require phpcompatibility/phpcompatibility-wp
- phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs,$HOME/.composer/vendor/automattic/vipwpcs,$HOME/.composer/vendor/phpcompatibility/php-compatibility,$HOME/.composer/vendor/phpcompatibility/phpcompatibility-paragonie,$HOME/.composer/vendor/phpcompatibility/phpcompatibility-wp
script:
- phpcs -n
PluginSVN:
stage: deploy
image: containers.ethitter.com:443/docker/images/php:7.3
image: containers.ethitter.com:443/docker/wp-org-plugin-deploy:latest
before_script:
- curl -o ./bin/deploy.sh https://git-cdn.e15r.co/open-source/wp-org-plugin-deploy/raw/master/scripts/deploy.sh
- chmod +x ./bin/deploy.sh
......
......@@ -26,7 +26,7 @@
<!-- Rules: WordPress Coding Standards -->
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards -->
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties -->
<config name="minimum_supported_wp_version" value="3.2.1"/>
<config name="minimum_supported_wp_version" value="4.4"/>
<rule ref="WordPress" />
<rule ref="WordPressVIPMinimum" />
<rule ref="WordPress-VIP-Go" />
......
......@@ -4,7 +4,7 @@
**Tags:** seo, meta tags
**Requires at least:** 4.4
**Tested up to:** 5.2
**Stable tag:** 0.5
**Stable tag:** 0.6
**License:** GPLv2 or later
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html
......@@ -30,8 +30,25 @@ For example, http://example.com/?p=123 becomes http://example.com/p/123/.
No, shortlinks use the posts' IDs, so aren't available for modification.
### Why aren't redirects validated? ###
Sites may use plugins that allow a post object's permalink to be set to an external URL, and this plugin is designed to respect those plugins.
If you wish to validate the redirects issued by this plugin, you can use the `eth_simple_shortlinks_redirect_url` filter to apply `wp_validate_redirect()` to the destination URL.
### After upgrading to 0.6, redirects stopped working ###
Beginning with release 0.6, before performing a redirect, the plugin checks that the post type and post status are supported. Previously, these checks were only applied when overriding an object's shortlink.
If, after upgrading, redirects stop working, use the `eth_simple_shortlinks_allowed_post_types` and `eth_simple_shortlinks_allowed_post_statuses` filters to permit additional types and statuses, or use the `eth_simple_shortlinks_verify_requested_post_support` filter to disable the supports checks.
## Changelog ##
### 0.6 ###
* Introduce filters in redirection handling.
* Apply supported post-type and post-status checks before redirecting.
* Conform to WordPress VIP's Coding Standards.
### 0.5 ###
* Admin notices when permalinks won't support the plugin
* Disable plugin functionality when permalink structure is incompatible
......@@ -39,3 +56,9 @@ No, shortlinks use the posts' IDs, so aren't available for modification.
### 0.4 ###
* Initial release
## Upgrade Notice ##
### 0.6 ###
Applies supported post-type and post-status checks before performing redirect. If, after upgrading, redirects stop working, see the "After upgrading to 0.6, redirects stopped working" section of the FAQ.
This diff is collapsed.
This diff is collapsed.
......@@ -2,10 +2,10 @@
# This file is distributed under the same license as the ETH Simple Shortlinks package.
msgid ""
msgstr ""
"Project-Id-Version: ETH Simple Shortlinks 0.5\n"
"Project-Id-Version: ETH Simple Shortlinks 0.6\n"
"Report-Msgid-Bugs-To: "
"https://wordpress.org/support/plugin/eth-simple-shortlinks\n"
"POT-Creation-Date: 2019-04-14 04:31:11+00:00\n"
"POT-Creation-Date: 2019-05-12 23:21:03+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
......@@ -25,31 +25,35 @@ msgstr ""
"X-Poedit-Bookmarks: \n"
"X-Textdomain-Support: yes\n"
#: eth-simple-shortlinks.php:51 eth-simple-shortlinks.php:52
#: inc/class-eth-simple-shortlinks.php:38
#: inc/class-eth-simple-shortlinks.php:45
msgid "Cheatin&#8217; uh?"
msgstr ""
#: eth-simple-shortlinks.php:138
#: inc/class-eth-simple-shortlinks.php:191
#. translators: 1: URL of permalink options page.
msgid ""
"Please visit the <a href=\"%1$s\">Permalinks</a> settings page to refresh "
"your permalinks. Doing so will add the rules this plugin requires."
msgstr ""
#: eth-simple-shortlinks.php:141
#: inc/class-eth-simple-shortlinks.php:201
#. translators: 1: URL of permalink options page.
msgid ""
"Please enable <a href=\"%1$s\">pretty permalinks</a>, otherwise disable "
"this plugin as it is not compatible with \"Plain\" permalinks."
msgstr ""
#: eth-simple-shortlinks.php:146
#: inc/class-eth-simple-shortlinks.php:213
#. translators: 1: Plugin name, 2: Notice text.
msgid "<strong>%1$s</strong>: %2$s"
msgstr ""
#: eth-simple-shortlinks.php:251
#: inc/class-eth-simple-shortlinks.php:422
msgid "Shortlink"
msgstr ""
#: eth-simple-shortlinks.php:293
#: inc/class-eth-simple-shortlinks.php:479
msgid ""
"Shortlinks cannot be generated until after <code>wp_loaded</code>; this "
"ensures that all post types are registered."
......
......@@ -4,7 +4,7 @@ Donate link: https://ethitter.com/donate/
Tags: seo, meta tags
Requires at least: 4.4
Tested up to: 5.2
Stable tag: 0.5
Stable tag: 0.6
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
......@@ -30,8 +30,25 @@ For example, http://example.com/?p=123 becomes http://example.com/p/123/.
No, shortlinks use the posts' IDs, so aren't available for modification.
= Why aren't redirects validated? =
Sites may use plugins that allow a post object's permalink to be set to an external URL, and this plugin is designed to respect those plugins.
If you wish to validate the redirects issued by this plugin, you can use the `eth_simple_shortlinks_redirect_url` filter to apply `wp_validate_redirect()` to the destination URL.
= After upgrading to 0.6, redirects stopped working =
Beginning with release 0.6, before performing a redirect, the plugin checks that the post type and post status are supported. Previously, these checks were only applied when overriding an object's shortlink.
If, after upgrading, redirects stop working, use the `eth_simple_shortlinks_allowed_post_types` and `eth_simple_shortlinks_allowed_post_statuses` filters to permit additional types and statuses, or use the `eth_simple_shortlinks_verify_requested_post_support` filter to disable the supports checks.
== Changelog ==
= 0.6 =
* Introduce filters in redirection handling.
* Apply supported post-type and post-status checks before redirecting.
* Conform to WordPress VIP's Coding Standards.
= 0.5 =
* Admin notices when permalinks won't support the plugin
* Disable plugin functionality when permalink structure is incompatible
......@@ -39,3 +56,9 @@ No, shortlinks use the posts' IDs, so aren't available for modification.
= 0.4 =
* Initial release
== Upgrade Notice ==
= 0.6 =
Applies supported post-type and post-status checks before performing redirect. If, after upgrading, redirects stop working, see the "After upgrading to 0.6, redirects stopped working" section of the FAQ.
......@@ -23,6 +23,9 @@ require_once $_tests_dir . '/includes/functions.php';
* Manually load the plugin being tested.
*/
function _manually_load_plugin() {
// Plugin requires a permalink structure to operate.
_set_default_permalink_structure_for_tests();
require dirname( dirname( __FILE__ ) ) . '/eth-simple-shortlinks.php';
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
......
<?php
/**
* Class PluginTest
*
* @package ETH_Simple_Shortlinks
*/
/**
* Plugin test case.
*/
class PluginTest extends WP_UnitTestCase {
/**
* Post ID for published tests.
*
* @var int
*/
protected static $post_id_published;
/**
* Post ID for draft tests.
*
* @var int
*/
protected static $post_id_draft;
/**
* Create a post to test with.
*/
public function setUp() {
parent::setUp();
static::$post_id_published = $this->factory->post->create();
static::$post_id_draft = $this->factory->post->create(
array(
'post_status' => 'draft',
)
);
}
/**
* Test shortlink overrides.
*/
public function test_shortlink_filters() {
$expected_published = user_trailingslashit( home_url( 'p/' . static::$post_id_published ) );
$expected_draft = add_query_arg( 'p', static::$post_id_draft, user_trailingslashit( home_url() ) );
$this->assertEquals( $expected_published, wp_get_shortlink( static::$post_id_published ), 'Failed to assert that published post has a simple shortlink.' );
$this->assertEquals( $expected_draft, wp_get_shortlink( static::$post_id_draft ), 'Failed to assert that draft post did not have its shortlink modified.' );
}
/**
* Test redirect parsing for supported post.
*/
public function test_published_post_redirect() {
$fake_request = new \stdClass();
$fake_request->query_vars = array(
'p' => static::$post_id_published,
'eth-shortlink' => true,
);
$redirect = ETH_Simple_Shortlinks::get_instance()->get_redirect_for_request( $fake_request );
$this->assertEquals( get_permalink( static::$post_id_published ), $redirect->destination, 'Failed to assert that redirect destination is post\'s permalink.' );
$this->assertEquals( 301, $redirect->status_code, 'Failed to assert that redirect status code is that for a permanent redirect.' );
}
/**
* Test redirect parsing for unsupported post.
*/
public function test_draft_post_redirect() {
$fake_request = new \stdClass();
$fake_request->query_vars = array(
'p' => static::$post_id_draft,
'eth-shortlink' => true,
);
$redirect = ETH_Simple_Shortlinks::get_instance()->get_redirect_for_request( $fake_request );
$this->assertNull( $redirect, 'Failed to assert that redirect is not generated for unsupported post status.' );
}
}
<?php
/**
* Class SampleTest
*
* @package ETH_Simple_Shortlinks
*/
/**
* Sample test case.
*/
class SampleTest extends WP_UnitTestCase {
/**
* A single example test.
*/
public function test_sample() {
// Replace this with some actual testing code.
$this->assertTrue( true );
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment