Skip to content

Commit

Permalink
Issue #60 - environment independence - tests really only work when BW…
Browse files Browse the repository at this point in the history
…_TRACE_ON is not defined
  • Loading branch information
bobbingwide committed Dec 21, 2017
1 parent cc2cf25 commit 62865d9
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions tests/test--oik-bwtrace.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,30 @@
*/
class Tests_oik_bwtrace extends BW_UnitTestCase {

public $bw_trace_on = null;

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

function test_constant_bw_trace_on() {

if ( defined( 'BW_TRACE_ON' ) ) {
if ( BW_TRACE_ON ) {
//echo "BW_TRACE_ON is true!";
$this->bw_trace_on = true;
} else {
//echo "BW_TRACE_ON is false";
$this->bw_trace_on = false;
}
} else {
//echo "BW_TRACE_ON is not set";
$this->bw_trace_on = null;
}
$this->assertTrue( true );
}


/**
* Tests for bw_trace_status are rather limited by the values of constants
* If the constants are already set then we haven't really got much choice.
Expand All @@ -19,9 +39,13 @@ function setUp() {
function test_bw_trace_status() {
global $bw_trace_on;
if ( defined( 'BW_TRACE_ON' ) && BW_TRACE_ON ) {
$saved = $bw_trace_on;
$bw_trace_on = true;
$status = bw_trace_status();
$this->assertTrue( $status );
$bw_trace_on = $saved;

return;
}
$this->save_bw_trace_options();
$this->init_bw_trace_options();
Expand Down Expand Up @@ -204,25 +228,30 @@ function test_bw_torf() {

/**
* Test trace plugin startup with tracing off
*
* Note: There's a lot of faffing to cater for the fact that trace may already have been started.
*/
function test_bw_trace_plugin_startup_tracing_off() {
global $bw_trace_options;
global $bw_action_options;

$this->save_bw_trace_options();
if ( $bw_trace_options['trace'] == "on" ) {
$bw_trace_options['trace'] = '0';
bw_trace_off();
}
$this->init_bw_trace_options();
$this->update_bw_trace_options();
$this->save_bw_action_options();
$this->init_bw_action_options();

bw_trace_plugin_startup();

$this->restore_bw_trace_options();
$this->restore_bw_action_options();

$tracing = bw_trace_status();
$this->assertFalse( $tracing );


$this->restore_bw_trace_options();
$this->restore_bw_action_options();
}

/**
Expand All @@ -248,8 +277,13 @@ function test_bw_trace_plugin_startup_tracing_on() {
$tracing = bw_trace_status();
$this->assertTrue( $tracing );


$this->restore_bw_trace_options();
$this->restore_bw_action_options();

if ( $bw_trace_options['trace'] == 0 ) {
bw_trace_off();
}
}

/**
Expand Down

0 comments on commit 62865d9

Please sign in to comment.