Skip to content

Commit

Permalink
Tests enable (#3)
Browse files Browse the repository at this point in the history
* scaffolded tests from wpcli

* Add first test

* Don't check tests or bin directory with phpcs

* Remove commented out code

* Fix comments

* maybe exclude default index.php files in project??

* some param and comments updates

* Spacing fixes

* Fix missed spacing correction

* Add a comment above the sample tests to stop phpcs shouting at us.
  The directory should be excluded but it isn't. See here for reasoning:
squizlabs/PHP_CodeSniffer#1731

* Added some tests for class existance.

* Try again to exclude the test file

* Don't test on php 5.3. Add test on  7.0,7.1,7.2

* Test on 4.8... not time for 4.9 yet

* Try readd php 5.3, also try 5.6 and 7.0 in martix

* Try again with php 5.3 compat

* PHP 5.3 instaed of 5.2...

* PHP 5.3/5.2 compat - no shorthad arrays in early versions.

* Try better matrix for travis
  • Loading branch information
pattonwebz authored Oct 28, 2017
1 parent d92e5e1 commit 8b267a6
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 35 deletions.
20 changes: 13 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@ branches:
only:
- master

php:
- 5.3
- 5.6
jobs:
fast_finish: true
include:
- php: 5.3
# As 'trusty' is not supporting PHP 5.2/5.3 anymore, we need to force using 'precise'.
dist: precise
- php: 5.6
- php: 7.0

env:
- WP_VERSION=latest WP_MULTISITE=0
- WP_VERSION=4.4 WP_MULTISITE=0
- WP_VERSION=4.9 WP_MULTISITE=0
- WP_VERSION=4.8 WP_MULTISITE=0

matrix:
include:
- php: 5.3
env: WP_VERSION=latest WP_MULTISITE=1
- php: 5.6
env: WP_VERSION=latest WP_MULTISITE=1
- php: 7.0
env: WP_VERSION=latest WP_MULTISITE=1

before_script:
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
Expand Down
8 changes: 4 additions & 4 deletions inc/actions-and-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
function pwwp_pc_filter_widget_args( $args ) {
// merge the existing args with ours containing a meta_key value.
$args = array_merge( $args, array(
'meta_key' => '_pwwp_pc_selected_id',
'meta_key' => '_pwwp_pc_selected_id',
) );
// return modified args.
return $args;
Expand Down Expand Up @@ -53,14 +53,14 @@ function pwwp_pc_filter_wp_query_object_on_categories( $query ) {

// build an array of args to pass as meta query.
$mq = array(
'key' => '_pwwp_pc_selected_id',
'key' => '_pwwp_pc_selected_id',
);
// if we have a term in $cat use it's ID as the value of meta key.
if ( $cat && ! is_wp_error( $cat ) ) {
// merge these args into the one containing just the key.
$mq = array_merge( $mq, array(
'value' => $cat->term_id,
'compare' => '=',
'value' => $cat->term_id,
'compare' => '=',
) );
}

Expand Down
24 changes: 12 additions & 12 deletions inc/class-pwwp-pc-query-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function primary_category_query_shortcode( $atts ) {
'id' => '',
'slug' => '',
'name' => '',
'post_type' => 'post',
'post_type' => 'post',
'limit' => '10',
), $atts, 'primary_category_query' );
// if we have neither an ID, a slug or a name then we should return nothing...
Expand All @@ -46,30 +46,30 @@ public function primary_category_query_shortcode( $atts ) {
// here we have either an id, a slug or a name.
if ( '' !== $atts['id'] ) {
$tax_query_field = array(
'meta_key' => '_pwwp_pc_selected_id',
'meta_value' => $atts['id'],
'meta_key' => '_pwwp_pc_selected_id',
'meta_value' => $atts['id'],
);
} elseif ( '' !== $atts['slug'] ) {
$tax_query_field = array(
'meta_key' => '_pwwp_pc_selected_slug',
'meta_value' => $atts['slug'],
'meta_key' => '_pwwp_pc_selected_slug',
'meta_value' => $atts['slug'],
);
} elseif ( '' !== $atts['name'] ) {
$tax_query_field = array(
'meta_key' => '_pwwp_pc_selected',
'meta_value' => $atts['name'],
'meta_key' => '_pwwp_pc_selected',
'meta_value' => $atts['name'],
);
}

// WP_Query arguments.
$sticky_posts = get_option( 'sticky_posts' );

$args = array(
'post_type' => array( $atts['post_type'] ),
'post_status' => array( 'published' ),
'nopaging' => true,
'posts_per_page' => $atts['limit'],
'post__not_in' => $sticky_posts,
'post_type' => array( $atts['post_type'] ),
'post_status' => array( 'published' ),
'nopaging' => true,
'posts_per_page' => $atts['limit'],
'post__not_in' => $sticky_posts,
);

// merge the $args array with the generated meta_key and meta_value args.
Expand Down
14 changes: 7 additions & 7 deletions inc/class-pwwp-primary-category-metabox-modifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public function output_primary_category_admin_script( $hook ) {
// get the id of the current primary category.
$current_primary_category_id = get_post_meta( $post_id, '_pwwp_pc_selected_id', true );

wp_localize_script( 'pwwp-pc-functions', 'pwwp_pc_data', [
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'pwwp-pc-functions' ),
'post_id' => $post_id,
'primary_category' => esc_js( $current_primary_category ),
'primary_category_id' => (int) $current_primary_category_id,
]);
wp_localize_script( 'pwwp-pc-functions', 'pwwp_pc_data', array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'pwwp-pc-functions' ),
'post_id' => $post_id,
'primary_category' => esc_js( $current_primary_category ),
'primary_category_id' => (int) $current_primary_category_id,
) );

}

Expand Down
2 changes: 1 addition & 1 deletion inc/class-pwwp-widget-primary-categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function form( $instance ) {
'title' => '',
) );
$title = sanitize_text_field( $instance['title'] );
$count = isset( $instance['count'] ) ? (bool) $instance['count'] :false;
$count = isset( $instance['count'] ) ? (bool) $instance['count'] : false;
$hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
$dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
?>
Expand Down
2 changes: 1 addition & 1 deletion phpcs.ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>
<exclude-pattern>test-*.php</exclude-pattern>
<exclude-pattern>*/bin/*</exclude-pattern>
<exclude-pattern>**/index.php</exclude-pattern>
</ruleset>
2 changes: 1 addition & 1 deletion primary-category-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@

/**
* TODO: Work out how to save and get term_meta properly
* NOTE: setting and deleting posts from meta in a sane way could be done by having 1 more post meta key which is not updated through ajax - use this as a note of the previous term and remove from it while adding to the new term.
* NOTE: setting and deleting posts from meta in a sane way could be done by having 1 more post meta key which is not updated through ajax - use this as a note of the previous term and remove from it while adding to the new term.
* TODO: Deal with unchecking of primary category.
*/
31 changes: 29 additions & 2 deletions tests/test-sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,35 @@ function test_sample() {
$this->assertTrue( true );
}

function test_plugin_loaded() {
// we load a constant in the plugin so if we're loaded this should be true.
/**
* Test if a constant defined by plugin is available.
*/
function test_plugin_loaded_const_dir() {
$this->assertTrue( defined( 'PRIMARY_CATEGORY_PLUGIN_DIR' ) );
}
/**
* Test if a constant defined by plugin is available.
*/
function test_plugin_loaded_const_url() {
$this->assertTrue( defined( 'PRIMARY_CATEGORY_PLUGIN_URL' ) );
}
/**
* Test if this from our plugin is loaded and exists.
*/
function test_metabox_modifications_class() {
$this->assertTrue( class_exists( 'PWWP_Primary_Category_Metabox_Modifications' ) );
}
/**
* Test if this from our plugin is loaded and exists.
*/
function test_widget_class() {
$this->assertTrue( class_exists( 'PWWP_Widget_Primary_Categories' ) );
}
/**
* Test if this from our plugin is loaded and exists.
*/
function test_metabox_shortcode_class() {
$this->assertTrue( class_exists( 'PWWP_PC_Query_Shortcode' ) );
}

}

0 comments on commit 8b267a6

Please sign in to comment.