diff --git a/.gitignore b/.gitignore index 0f2ab9c..6a70856 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -.bin +bin .idea *.iml .gitignore \ No newline at end of file diff --git a/ssp-includes/class-ssp-dependencies.php b/ssp-includes/class-ssp-dependencies.php index 8f55a93..ee8c879 100644 --- a/ssp-includes/class-ssp-dependencies.php +++ b/ssp-includes/class-ssp-dependencies.php @@ -1,4 +1,5 @@ =' ) ) { + if ( version_compare( $ssp_version, $minimum_version, '>=' ) ) { return true; } } else { @@ -37,4 +38,4 @@ public static function ssp_active_check( $minimum_version = '' ) { return false; } -} \ No newline at end of file +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 14ad230..a2c3873 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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' ); diff --git a/tests/test-functions.php b/tests/test-ssp-stats.php similarity index 75% rename from tests/test-functions.php rename to tests/test-ssp-stats.php index ed09b67..50b3335 100755 --- a/tests/test-functions.php +++ b/tests/test-ssp-stats.php @@ -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.' ); }