Skip to content

Commit

Permalink
Modified unit test bootstrap to include required class files and star…
Browse files Browse the repository at this point in the history
…t up functions
  • Loading branch information
jonathanbossenger committed May 28, 2018
1 parent b63ef60 commit 2f36770
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.bin
bin
.idea
*.iml
.gitignore
9 changes: 5 additions & 4 deletions ssp-includes/class-ssp-dependencies.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* SSP Dependency Checker
*
Expand All @@ -23,10 +24,10 @@ public static function ssp_active_check( $minimum_version = '' ) {
self::init();
}

if( in_array( 'seriously-simple-podcasting/seriously-simple-podcasting.php', self::$active_plugins ) || array_key_exists( 'seriously-simple-podcasting/seriously-simple-podcasting.php', self::$active_plugins ) ) {
if( $minimum_version ) {
if ( in_array( 'seriously-simple-podcasting/seriously-simple-podcasting.php', self::$active_plugins, true ) || array_key_exists( 'seriously-simple-podcasting/seriously-simple-podcasting.php', self::$active_plugins ) ) {
if ( $minimum_version ) {
$ssp_version = get_option( 'ssp_version', '1.0' );
if( version_compare( $ssp_version, $minimum_version, '>=' ) ) {
if ( version_compare( $ssp_version, $minimum_version, '>=' ) ) {
return true;
}
} else {
Expand All @@ -37,4 +38,4 @@ public static function ssp_active_check( $minimum_version = '' ) {
return false;
}

}
}
15 changes: 15 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,26 @@
// Give access to tests_add_filter() function.
require_once $_tests_dir . '/includes/functions.php';

/**
* Recreated the SSP_Stats function from the main plugin file
* This is because the plugin file checks to ensure that a verion of SSP is installed
* and for unit tests that check would fail
*
* @return Main
*/
function SSP_Stats() {
$instance = SSP_Stats::instance( __FILE__, SSP_STATS_VERSION, '1.0.0' );

return $instance;
}

/**
* Manually load the plugin being tested.
*/
function _manually_load_plugin() {
require dirname( dirname( __FILE__ ) ) . '/seriously-simple-stats.php';
// Manually include the class-ssp-stats.php file
require_once( 'includes/class-ssp-stats.php' );
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );

Expand Down
12 changes: 8 additions & 4 deletions tests/test-functions.php → tests/test-ssp-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@
*/

/**
* Sample test case.
* SSP Stats test case.
*/
class FunctionsTest extends WP_UnitTestCase {
class SSPStatsTest extends WP_UnitTestCase {

/**
* A single example test.
* Tests the anonymise ip function that it
* returns a valid ip address format and
* returns the last octet as a zero
*/
public function test_ss_stats_anonymise_ip() {
$ip = '192.168.0.233';
$ssp_stats = SSP_Stats();

$ip = '192.168.0.233';
$new_ip = $ssp_stats->anonymise_ip( $ip );

// check that the string still resembles an ip address
$this->assertStringMatchesFormat( '%x.%x.%x.%x', $new_ip, 'The address does not match a valid ip address format.' );

// assert that the string ends with .0
$this->assertStringEndsWith( '.0', $new_ip, 'The address does not end with a zero.' );
}
Expand Down

0 comments on commit 2f36770

Please sign in to comment.