Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests enable #4

Merged
merged 30 commits into from
Oct 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d1ede94
scaffolded tests from wpcli
pattonwebz Oct 28, 2017
ab41b18
Add first test
pattonwebz Oct 28, 2017
9debea0
Don't check tests or bin directory with phpcs
pattonwebz Oct 28, 2017
0f9b46d
Remove commented out code
pattonwebz Oct 28, 2017
8125325
Fix comments
pattonwebz Oct 28, 2017
170824d
maybe exclude default index.php files in project??
pattonwebz Oct 28, 2017
9bab9e4
some param and comments updates
pattonwebz Oct 28, 2017
d10b6e3
Spacing fixes
pattonwebz Oct 28, 2017
33a3b34
Merge branch 'master' into tests_enable
pattonwebz Oct 28, 2017
7bfd4e4
Fix missed spacing correction
pattonwebz Oct 28, 2017
7d5a652
Add a comment above the sample tests to stop phpcs shouting at us.
pattonwebz Oct 28, 2017
102f21c
Added some tests for class existance.
pattonwebz Oct 28, 2017
c84ae94
Try again to exclude the test file
pattonwebz Oct 28, 2017
aad71ab
Don't test on php 5.3. Add test on 7.0,7.1,7.2
pattonwebz Oct 28, 2017
c8ddd02
Test on 4.8... not time for 4.9 yet
pattonwebz Oct 28, 2017
63bb3b1
Try readd php 5.3, also try 5.6 and 7.0 in martix
pattonwebz Oct 28, 2017
0faa76e
Try again with php 5.3 compat
pattonwebz Oct 28, 2017
7eaa141
PHP 5.3 instaed of 5.2...
pattonwebz Oct 28, 2017
7090f32
PHP 5.3/5.2 compat - no shorthad arrays in early versions.
pattonwebz Oct 28, 2017
057bfde
Try better matrix for travis
pattonwebz Oct 28, 2017
727b6b7
These tests identified an issue with the shortcode if no id/anything …
pattonwebz Oct 29, 2017
e863047
Tests added for shortcode class
pattonwebz Oct 29, 2017
5273713
Merge branch 'master' into tests_enable
pattonwebz Oct 29, 2017
feb4260
Fix type for 'parent'
pattonwebz Oct 29, 2017
2ee84d9
Merge branch 'master' of github.com:pattonwebz/primary-category-pluigin
pattonwebz Oct 29, 2017
0632f02
Simple test that shortcode exists
pattonwebz Oct 29, 2017
43d4155
Testing that classes added exists and can be instansiated
pattonwebz Oct 29, 2017
0a8c1aa
Assert both constants are defined in a single test
pattonwebz Oct 29, 2017
8477966
Make the class instanceof test php 5.4 compatible and below
pattonwebz Oct 30, 2017
6c125e6
Merge branch 'tests_enable' of github.com:pattonwebz/primary-category…
pattonwebz Oct 30, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/test-metabox-class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* MetaboxClassTest
*
* @package Primary_Category_Plugin
*/

/**
* Tests to make sure the metabox is working as expected.
*/

class MetaboxClassTest extends WP_UnitTestCase {

public function setUp() {
parent::setUp();
}

public function test_widget_class_exists() {
// if the class exists instansiate and return it's object
$metabox_obj = false;
if( class_exists( 'PWWP_Primary_Category_Metabox_Modifications' ) ) {
$metabox_obj = new PWWP_Primary_Category_Metabox_Modifications;
}
// in php 5.4 or below this ::class doesn't work :( .
//$this->assertInstanceOf( PWWP_Primary_Category_Metabox_Modifications::class, $metabox_obj );
$this->assertTrue( $metabox_obj instanceof PWWP_Primary_Category_Metabox_Modifications );
return $metabox_obj;
}

}
39 changes: 4 additions & 35 deletions tests/test-sample.php
Original file line number Diff line number Diff line change
@@ -1,52 +1,21 @@
<?php
/**
* Class SampleTest
* Class PluginActiveTest
*
* @package Primary_Category_Plugin
*/

/**
* Sample test case.
* PluginActiveTest.
*/
class SampleTest extends WP_UnitTestCase {

/**
* A single example test.
*/
function test_sample() {
// Replace this with some actual testing code.
$this->assertTrue( true );
}
class PluginActiveTest extends WP_UnitTestCase {

/**
* 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' ) );
}


}
110 changes: 110 additions & 0 deletions tests/test-shortcode-class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/**
* ShortcodeClassTest
*
* @package Primary_Category_Plugin
*/

/**
* Tests to make sure the shortcode is working as expected.
*/
class ShortcodeClassTest extends WP_UnitTestCase {

private $post_with_meta;

private $term_for_meta;

/**
* Test if this class from our plugin is loaded and exists.
*/

public function setUp() {

parent::setUp();
// create a post for use in test.
$this->post_with_meta = $this->factory->post->create_and_get();

// create a term to use in testing.
$this->term_for_meta = $this->factory->term->create_and_get();

// set some meta on the post.
update_post_meta( $this->post_with_meta->ID, '_pwwp_pc_selected_id', $this->term_for_meta->term_id );
update_post_meta( $this->post_with_meta->ID, '_pwwp_pc_selected_slug', $this->term_for_meta->slug );
update_post_meta( $this->post_with_meta->ID, '_pwwp_pc_selected', $this->term_for_meta->name );

}

public function test_shortcode_class_exists() {
// if the class exists instansiate and return it's object
$shortcode_obj = false;
if( class_exists( 'PWWP_PC_Query_Shortcode' ) ) {
$shortcode_obj = new PWWP_PC_Query_Shortcode;
}
// in php 5.4 or below this ::class doesn't work :( .
//$this->assertInstanceOf( PWWP_PC_Query_Shortcode::class, $shortcode_obj );
$this->assertTrue( $shortcode_obj instanceof PWWP_PC_Query_Shortcode );
return $shortcode_obj;
}

public function test_shortcode_exists() {
// test the shortcode exists.
$this->assertTrue( shortcode_exists( 'primary_category_query' ) );
}

/**
* @depends test_shortcode_class_exists
*/
public function test_shortcode_return_no_posts( $shortcode_obj ) {
// this term id we're asking for shouldn't exist in any post meta.
$shortcode_html = $shortcode_obj->primary_category_query_shortcode( array( 'id' => 9999999 ) );
// is a string?
$this->assertInternalType( 'string', $shortcode_html );
// should contain this string indicating that shortcode returns a fail.
$this->assertContains( '<p class="pwwp-pc-none">', $shortcode_html, "Doesn't have the failed string." );
// and it shouldn't contain this string that would be present on success.
$this->assertNotContains( '<ul class="pwwp-pc-query-wrapper">', $shortcode_html, "Has the success string (which is a failure when we're testing a fail)" );
}
/**
* @depends test_shortcode_class_exists
*/
public function test_shortcode_return_posts( $shortcode_obj ) {
$shortcode_html = $shortcode_obj->primary_category_query_shortcode( array( 'id' => $this->post_with_meta->term_id ) );
// is a string?
$this->assertInternalType( 'string', $shortcode_html );
// should NOT contain this string indicating that shortcode returns a fail.
$this->assertNotContains( '<p class="pwwp-pc-none">', $shortcode_html, "Doesn't have the failed string (which is a failure when we're testing a fail)." );
// and it should contain this string that would be present on success.
$this->assertNotContains( '<ul class="pwwp-pc-query-wrapper">', $shortcode_html, "Has the success string." );
}

/**
* @depends test_shortcode_class_exists
*/
public function test_shortcode_shortcode_passing_no_required_args( $shortcode_obj ) {
$shortcode_html = $shortcode_obj->primary_category_query_shortcode( array() );
// is a string?
$this->assertInternalType( 'string', $shortcode_html );
$this->assertContains( '<!-- no id, slug or name passed to shortcode -->', $shortcode_html, "Reurned no failure comment" );
$this->assertNotContains( '<ul class="pwwp-pc-query-wrapper">', $shortcode_html, "Has the the success string (which is fail here)." );
}

/**
* Shortcodes can be generated through id, slug, or nicename of a term.
* This test makes sure that the html returned is matching regardless of
* the atts passed to the shortcode function.
*
* @depends test_shortcode_class_exists
*/
public function test_shortcode_success_returns_same_for_different_atts( $shortcode_obj ) {
$shortcode_html['id'] = $shortcode_obj->primary_category_query_shortcode( array( 'id' => $this->post_with_meta->term_id ) );
$shortcode_html['slug'] = $shortcode_obj->primary_category_query_shortcode( array( 'slug' => $this->post_with_meta->slug ) );
$shortcode_html['name'] = $shortcode_obj->primary_category_query_shortcode( array( 'name' => $this->post_with_meta->name ) );
// is a string?
$this->assertEquals( $shortcode_html['id'], $shortcode_html['slug'] );
$this->assertEquals( $shortcode_html['id'], $shortcode_html['name'] );
$this->assertEquals( $shortcode_html['slug'], $shortcode_html['name'] );

}


}
31 changes: 31 additions & 0 deletions tests/test-widget-class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* WidgetClassTest
*
* @package Primary_Category_Plugin
*/

/**
* Tests to make sure the widget is working as expected.
*/

class WidgetClassTest extends WP_UnitTestCase {

public function setUp() {
parent::setUp();
}

public function test_widget_class_exists() {
// if the class exists instansiate and return it's object
$widget_obj = false;
if( class_exists( 'PWWP_Widget_Primary_Categories' ) ) {
$widget_obj = new PWWP_Widget_Primary_Categories;
}
// in php 5.4 or below this ::class doesn't work :( .
//$this->assertInstanceOf( PWWP_Widget_Primary_Categories::class, $widget_obj );
$this->assertTrue( $widget_obj instanceof PWWP_Widget_Primary_Categories );

return $widget_obj;
}

}