| 1 |
<?php |
| 2 |
/** |
| 3 |
* Tests stream main class |
| 4 |
* |
| 5 |
* @author X-Team |
| 6 |
* @author Jonathan Bardo <jonathan.bardo@x-team.com> |
| 7 |
*/ |
| 8 |
class WP_StreamTestCase extends WP_UnitTestCase { |
| 9 |
|
| 10 |
/** |
| 11 |
* Holds the plugin base class |
| 12 |
* |
| 13 |
* @return void |
| 14 |
*/ |
| 15 |
protected $plugin; |
| 16 |
|
| 17 |
/** |
| 18 |
* Custom action prefix for test custom triggered actions |
| 19 |
* @var string |
| 20 |
*/ |
| 21 |
protected $action_prefix = 'wp_stream_test_'; |
| 22 |
|
| 23 |
/** |
| 24 |
* PHP unit setup function |
| 25 |
* |
| 26 |
* @return void |
| 27 |
*/ |
| 28 |
function setUp() { |
| 29 |
parent::setUp(); |
| 30 |
$this->plugin = $GLOBALS['wp_stream']; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Make sure the plugin is initialized with it's global variable |
| 35 |
* |
| 36 |
* @return void |
| 37 |
*/ |
| 38 |
public function test_plugin_initialized() { |
| 39 |
$this->assertFalse( null == $this->plugin ); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Helper function to check validity of action |
| 44 |
* |
| 45 |
* @param array $tests |
| 46 |
* @param string $function_call |
| 47 |
*/ |
| 48 |
protected function do_action_validation( array $tests = array(), $function_call = 'has_action' ){ |
| 49 |
foreach ( $tests as $test ) { |
| 50 |
list( $action, $class, $function ) = $test; |
| 51 |
|
| 52 |
//Default WP priority |
| 53 |
$priority = isset( $test[3] ) ? $test[3] : 10; |
| 54 |
|
| 55 |
//Default function call |
| 56 |
$function_call = ( in_array( $function_call, array( 'has_action', 'has_filter' ) ) ) ? $function_call : 'has_action'; |
| 57 |
|
| 58 |
//Run assertion here |
| 59 |
$this->assertEquals( |
| 60 |
$priority, |
| 61 |
$function_call( $action, array( $class, $function ) ), |
| 62 |
"$action $function_call is not attached to $class::$function. It might also have the wrong priority (validated priority: $priority)" |
| 63 |
); |
| 64 |
$this->assertTrue( |
| 65 |
method_exists( $class, $function ), |
| 66 |
"Class '$class' doesn't implement the '$function' function" |
| 67 |
); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Helper function to check validity of filters |
| 73 |
* @param array $tests |
| 74 |
*/ |
| 75 |
protected function do_filter_validation( array $tests = array() ){ |
| 76 |
$this->do_action_validation( $tests, 'has_filter' ); |
| 77 |
} |
| 78 |
|
| 79 |
} |
| 80 |
|