Commit a5fcb932 authored by Erick Hitter's avatar Erick Hitter

Merge branch 'fix/2-phpcs-phpunit' into 'master'

Unit tests and coding standards

Closes #2 and #3

See merge request !3
parents e0e11b85 c646a60f
Pipeline #1057 passed with stages
in 3 minutes and 16 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
......
......@@ -19,7 +19,7 @@
<!-- Rules: Check PHP version compatibility -->
<!-- https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
<config name="testVersion" value="7.2-"/>
<config name="testVersion" value="5.3-"/>
<!-- https://github.com/PHPCompatibility/PHPCompatibilityWP -->
<rule ref="PHPCompatibilityWP"/>
......
This diff is collapsed.
......@@ -4,7 +4,7 @@
**Tags:** revision, revisions, admin
**Requires at least:** 3.6
**Tested up to:** 5.2
**Stable tag:** 1.2.1
**Stable tag:** 1.3
**License:** GPLv2 or later
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html
......@@ -35,6 +35,10 @@ Navigate to **Settings > Writing** in your WordPress Dashboard, and look for the
## Changelog ##
### 1.3 ###
* Introduce unit tests.
* Conform to coding standards.
### 1.2.1 ###
* Introduce Spanish translation thanks to Maria Ramos at [WebHostingHub](http://www.webhostinghub.com/).
......
This diff is collapsed.
......@@ -2,10 +2,10 @@
# This file is distributed under the same license as the WP Revisions Control package.
msgid ""
msgstr ""
"Project-Id-Version: WP Revisions Control 1.2.1\n"
"Project-Id-Version: WP Revisions Control 1.3\n"
"Report-Msgid-Bugs-To: "
"https://wordpress.org/support/plugin/wp-revisions-control\n"
"POT-Creation-Date: 2019-04-14 04:52:10+00:00\n"
"POT-Creation-Date: 2019-05-26 17:40:54+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
......@@ -25,71 +25,74 @@ msgstr ""
"X-Poedit-Bookmarks: \n"
"X-Textdomain-Support: yes\n"
#: wp-revisions-control.php:148
#: inc/class-wp-revisions-control.php:149
msgid ""
"Set the number of revisions to save for each post type listed. To retain "
"all revisions for a given post type, leave the field empty."
msgstr ""
#: wp-revisions-control.php:149
#: inc/class-wp-revisions-control.php:150
msgid "If a post type isn't listed, revisions are not enabled for that post type."
msgstr ""
#: wp-revisions-control.php:155
#: inc/class-wp-revisions-control.php:161
#. translators: 1. Filter tag.
msgid ""
"A local change is causing this plugin's functionality to run at a priority "
"other than the default. If you experience difficulties with the plugin, "
"please unhook any functions from the %s filter."
"please unhook any functions from the %1$s filter."
msgstr ""
#: wp-revisions-control.php:274
#: inc/class-wp-revisions-control.php:278
msgid "Revisions"
msgstr ""
#: wp-revisions-control.php:282
#: inc/class-wp-revisions-control.php:300
msgid "Processing&hellip;"
msgstr ""
#: wp-revisions-control.php:283
#: inc/class-wp-revisions-control.php:301
msgid "Are you sure you want to remove revisions from this post?"
msgstr ""
#: wp-revisions-control.php:284
#: inc/class-wp-revisions-control.php:302
msgid "Autosave"
msgstr ""
#: wp-revisions-control.php:285
#: inc/class-wp-revisions-control.php:303
msgid "There are no revisions to remove."
msgstr ""
#: wp-revisions-control.php:286
#: inc/class-wp-revisions-control.php:304
msgid "An error occurred. Please refresh the page and try again."
msgstr ""
#: wp-revisions-control.php:312
#: inc/class-wp-revisions-control.php:325
msgid "Purge these revisions"
msgstr ""
#: wp-revisions-control.php:315
#: inc/class-wp-revisions-control.php:331
#. translators: 1. Text input field.
msgid ""
"Limit this post to %s revisions. Leave this field blank for default "
"Limit this post to %1$s revisions. Leave this field blank for default "
"behavior."
msgstr ""
#: wp-revisions-control.php:341
#: inc/class-wp-revisions-control.php:356
msgid "No post ID was provided. Please refresh the page and try again."
msgstr ""
#: wp-revisions-control.php:343
#: inc/class-wp-revisions-control.php:358
msgid "Invalid request. Please refresh the page and try again."
msgstr ""
#: wp-revisions-control.php:345
#: inc/class-wp-revisions-control.php:360
msgid "You are not allowed to edit this post."
msgstr ""
#: wp-revisions-control.php:357
msgid "Removed %s revisions associated with this post."
#: inc/class-wp-revisions-control.php:392
#. translators: 1. Number of removed revisions, already formatted for locale.
msgid "Removed %1$s revisions associated with this post."
msgstr ""
#. Plugin Name of the plugin/theme
......
......@@ -4,7 +4,7 @@ Donate link: https://ethitter.com/donate/
Tags: revision, revisions, admin
Requires at least: 3.6
Tested up to: 5.2
Stable tag: 1.2.1
Stable tag: 1.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
......@@ -35,6 +35,10 @@ Navigate to **Settings > Writing** in your WordPress Dashboard, and look for the
== Changelog ==
= 1.3 =
* Introduce unit tests.
* Conform to coding standards.
= 1.2.1 =
* Introduce Spanish translation thanks to Maria Ramos at [WebHostingHub](http://www.webhostinghub.com/).
......
<?php
/**
* Test WP hooks.
*
* @package WP_Revisions_Control
*/
/**
* Class TestHooks.
*/
class TestHooks extends WP_UnitTestCase {
/**
* Plugin slug used in many settings etc.
*
* @var string
*/
protected static $settings_section = 'wp_revisions_control';
/**
* Plugin's limit meta key.
*
* @var string
*/
protected static $meta_key = '_wp_rev_ctl_limit';
/**
* Test saving post's revisions limit.
*/
public function test_save_post() {
$post_id = $this->factory->post->create();
$expected = 92;
$_POST[ static::$settings_section . '_limit_nonce' ] = wp_create_nonce( static::$settings_section . '_limit' );
$_POST[ static::$settings_section . '_qty' ] = $expected;
WP_Revisions_Control::get_instance()->action_save_post( $post_id );
$to_keep = (int) get_post_meta( $post_id, static::$meta_key, true );
$to_keep_filtered = wp_revisions_to_keep( get_post( $post_id ) );
$this->assertEquals( $expected, $to_keep );
$this->assertEquals( $expected, $to_keep_filtered );
}
/**
* Test limits, ensuring no leakage.
*/
public function test_limits() {
$post_id_limited = $this->factory->post->create();
$post_id_unlimited = $this->factory->post->create();
$expected = 47;
update_post_meta( $post_id_limited, static::$meta_key, $expected );
$this->assertEquals(
$expected,
wp_revisions_to_keep( get_post( $post_id_limited ) )
);
$this->assertEquals(
-1,
wp_revisions_to_keep( get_post( $post_id_unlimited ) )
);
}
/**
* Test revision purging.
*/
public function test_purge_all() {
$post_id = $this->factory->post->create();
$iterations = 10;
for ( $i = 0; $i < $iterations; $i++ ) {
wp_update_post(
array(
'ID' => $post_id,
'post_content' => wp_rand(),
)
);
}
$revisions_to_purge = count( wp_get_post_revisions( $post_id ) );
$this->assertEquals(
$iterations,
$revisions_to_purge,
'Failed to assert that there are revisions to purge.'
);
$purge = WP_Revisions_Control::get_instance()->do_purge_all( $post_id );
$revisions_remaining = count( wp_get_post_revisions( $post_id ) );
$this->assertEquals(
0,
$revisions_remaining,
'Failed to assert that all revisions were purged.'
);
$this->assertEquals(
10,
$purge['count'],
'Failed to assert that response includes expected count of purged revisions.'
);
$this->assertEquals(
'Removed 10 revisions associated with this post.',
$purge['success'],
'Failed to assert that response includes expected success message.'
);
}
}
<?php
/**
* Class SampleTest
*
* @package WP_Revisions_Control
*/
/**
* 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 );
}
}
This diff is collapsed.
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