-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jonathan Bardo
committed
Dec 17, 2013
1 parent
9573d9b
commit 8f402cf
Showing
9 changed files
with
257 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/** | ||
* Tests stream main class | ||
* | ||
* @author X-Team | ||
* @author Jonathan Bardo <jonathan.bardo@x-team.com> | ||
*/ | ||
class WP_StreamTestCase extends WP_UnitTestCase { | ||
|
||
/** | ||
* Holds the plugin base class | ||
* | ||
* @return void | ||
*/ | ||
protected $plugin; | ||
|
||
/** | ||
* PHP unit setup function | ||
* | ||
* @return void | ||
*/ | ||
function setUp() { | ||
parent::setUp(); | ||
$this->plugin = $GLOBALS['wp_stream']; | ||
} | ||
|
||
/** | ||
* Make sure the plugin is initialized with it's global variable | ||
* | ||
* @return void | ||
*/ | ||
public function test_plugin_initialized() { | ||
$this->assertFalse( null == $this->plugin ); | ||
} | ||
|
||
/** | ||
* Helper function to check validity of action | ||
* | ||
* @param array $tests | ||
* @param string $function_call | ||
*/ | ||
protected function do_action_validation( array $tests = array(), $function_call = 'has_action' ){ | ||
foreach ( $tests as $test ) { | ||
list( $action, $class, $function ) = $test; | ||
|
||
//Default WP priority | ||
$priority = isset( $test[3] ) ? $test[3] : 10; | ||
|
||
//Default function call | ||
$function_call = ( in_array( $function_call, array( 'has_action', 'has_filter' ) ) ) ? $function_call : 'has_action'; | ||
|
||
//Run assertion here | ||
$this->assertEquals( | ||
$priority, | ||
$function_call( $action, array( $class, $function ) ), | ||
"$action $function_call is not attached to $class::$function. It might also have the wrong priority (validated priority: $priority)" | ||
); | ||
$this->assertTrue( | ||
method_exists( $class, $function ), | ||
"Class '$class' doesn't implement the '$function' function" | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Helper function to check validity of filters | ||
* @param array $tests | ||
*/ | ||
protected function do_filter_validation( array $tests = array() ){ | ||
$this->do_action_validation( $tests, 'has_filter' ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
/** | ||
* Tests stream main class | ||
* | ||
* @author X-Team | ||
* @author Jonathan Bardo <jonathan.bardo@x-team.com> | ||
* | ||
* @ToDo Test all remaining function of the admin class | ||
* - erase_stream_records | ||
* - purge_schedule_setup | ||
*/ | ||
class Test_WP_Stream_Admin extends WP_StreamTestCase { | ||
|
||
//Name of the class to test | ||
const CLASSNAME = 'WP_Stream_Admin'; | ||
|
||
/** | ||
* Change to admin page | ||
*/ | ||
public function setUp() { | ||
parent::setUp(); | ||
|
||
//Add admin user to test caps | ||
// We need to change user to verify editing option as admin or editor | ||
$administrator_id = $this->factory->user->create( | ||
array( | ||
'role' => 'administrator', | ||
'user_login' => 'test_admin', | ||
'email' => 'test@land.com', | ||
) | ||
); | ||
wp_set_current_user( $administrator_id ); | ||
|
||
//Load the class manually like if we were in the admin | ||
require_once WP_STREAM_INC_DIR . 'admin.php'; | ||
call_user_func( array( self::CLASSNAME, 'load' ) ); | ||
} | ||
|
||
/** | ||
* Check constructor composition | ||
* | ||
* @return void | ||
*/ | ||
public function test_constructor() { | ||
//Check all constructor action | ||
$test_actions = array( | ||
array( 'admin_menu', self::CLASSNAME, 'register_menu' ), | ||
array( 'admin_enqueue_scripts', self::CLASSNAME, 'admin_enqueue_scripts' ), | ||
array( 'admin_enqueue_scripts', self::CLASSNAME, 'admin_menu_css' ), | ||
array( 'wp_ajax_wp_stream_reset', self::CLASSNAME, 'wp_ajax_reset' ), | ||
array( 'init', self::CLASSNAME, 'purge_schedule_setup' ), | ||
array( 'stream_auto_purge', self::CLASSNAME, 'purge_scheduled_action' ), | ||
); | ||
|
||
$this->do_action_validation( $test_actions ); | ||
|
||
//Check all constuctor filters | ||
$test_actions = array( | ||
array( 'user_has_cap', self::CLASSNAME, '_filter_user_caps' ), | ||
array( 'role_has_cap', self::CLASSNAME, '_filter_role_caps' ), | ||
array( 'plugin_action_links', self::CLASSNAME, 'plugin_action_links' ), | ||
); | ||
|
||
$this->do_filter_validation( $test_actions ); | ||
} | ||
|
||
/** | ||
* Check is menu is present in menu array | ||
*/ | ||
public function test_register_menu(){ | ||
do_action( 'admin_menu' ); | ||
global $menu, $submenu; | ||
|
||
//Check main menu | ||
$this->assertTrue( in_array( 'wp_stream', reset( $menu ) ) ); | ||
|
||
//Check submenu | ||
$this->assertQueryTrue( 'wp_stream_settings', $submenu['wp_stream'][1] ); | ||
} | ||
|
||
/** | ||
* Check if script are enqueued properly if on wp_stream page | ||
*/ | ||
public function test_admin_enqueue_script() { | ||
set_current_screen( 'toplevel_page_wp_stream' ); | ||
do_action( 'admin_enqueue_scripts', 'toplevel_page_wp_stream' ); | ||
|
||
//Check if chosen is present | ||
$this->assertTrue( wp_script_is( 'wp-stream-chosen', 'enqueued' ), 'jQuery Chosen js is not enqueud' ); | ||
$this->assertTrue( wp_style_is( 'wp-stream-chosen', 'enqueued' ), 'jQuery Chosen css is not enqueud' ); | ||
$this->assertTrue( wp_script_is( 'jquery-core', 'registered' ), 'jQuery is not enqueud' ); | ||
$this->assertTrue( wp_script_is( 'wp-stream-admin', 'enqueued' ), 'wp-stream-admin is not enqueud' ); | ||
$this->assertTrue( wp_style_is( 'wp-stream-admin', 'enqueued' ), 'wp-stream-admin is not enqueud' ); | ||
|
||
//Check wp localise script | ||
$localize_data = $GLOBALS['wp_scripts']->get_data( 'wp-stream-admin', 'data' ); | ||
$this->assertTrue( strrpos( $localize_data, 'i18n' ) > 0 ); | ||
} | ||
|
||
/** | ||
* Check the output of the plugin action links function | ||
*/ | ||
public function test_plugin_action_links() { | ||
$filter_output = apply_filters( 'plugin_action_links', array(), plugin_basename( WP_STREAM_DIR . 'stream.php' ) ); | ||
$this->assertTrue( strrpos( $filter_output[0], '/wp-admin/admin.php?page=wp_stream_settings' ) >= 0 ); | ||
} | ||
|
||
} |
Oops, something went wrong.