Wordpress/tests/phpunit/includes/functions.php
Scott Taylor d6a3c2a0de Add access modifiers to methods and members of list table classes:
* `WP_List_Table` is the base class that implements `__get()` and `__call()` for BC
* Adds unit tests to confirm that subclasses properly inherit magic methods
* Add modifiers to subclasses: `WP_Links_List_Table`, `WP_Media_List_Table`, `WP_MS_Sites_List_Table`, `WP_MS_Themes_List_Table`, `WP_MS_Users_List_Table`, `WP_Plugin_Install_List_Table`, `WP_Plugins_List_Table`, `WP_Posts_List_Table`, `WP_Terms_List_Table`, `WP_Theme_Install_List_Table`, `WP_Themes_List_Table`

See #27881, #22234.


git-svn-id: https://develop.svn.wordpress.org/trunk@28493 602fd350-edb4-49c9-b593-d223f7449a82
2014-05-19 01:16:16 +00:00

61 lines
1.4 KiB
PHP

<?php
// For adding hooks before loading WP
function tests_add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
global $wp_filter, $merged_filters;
$idx = _test_filter_build_unique_id($tag, $function_to_add, $priority);
$wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
unset( $merged_filters[ $tag ] );
return true;
}
function _test_filter_build_unique_id($tag, $function, $priority) {
global $wp_filter;
static $filter_id_count = 0;
if ( is_string($function) )
return $function;
if ( is_object($function) ) {
// Closures are currently implemented as objects
$function = array( $function, '' );
} else {
$function = (array) $function;
}
if (is_object($function[0]) ) {
return spl_object_hash($function[0]) . $function[1];
} else if ( is_string($function[0]) ) {
// Static Calling
return $function[0].$function[1];
}
}
function _delete_all_posts() {
global $wpdb;
$all_posts = $wpdb->get_col("SELECT ID from {$wpdb->posts}");
if ($all_posts) {
foreach ($all_posts as $id)
wp_delete_post( $id, true );
}
}
class Basic_Object {
private $foo = 'bar';
public function __get( $name ) {
return $this->$name;
}
public function __call( $name, $arguments ) {
return call_user_func_array( array( $this, $name ), $arguments );
}
private function callMe() {
return 'maybe';
}
}
class Basic_Subclass extends Basic_Object {}