diff options
author | Andrew Nacin <nacin@git.wordpress.org> | 2013-08-29 18:39:34 +0000 |
---|---|---|
committer | Andrew Nacin <nacin@git.wordpress.org> | 2013-08-29 18:39:34 +0000 |
commit | 8045afd81b7c80f6ef5b327c115a5bbb43e4b65c (patch) | |
tree | 15d457007610c451577debda89bd9e9cd3d74551 /tests/phpunit/includes/functions.php | |
parent | d34baebc1d8111c9c1014e11001957face778e52 (diff) | |
download | wordpress-8045afd81b7c80f6ef5b327c115a5bbb43e4b65c.tar.gz wordpress-8045afd81b7c80f6ef5b327c115a5bbb43e4b65c.zip |
Move PHPUnit tests into a tests/phpunit directory.
wp-tests-config.php can/should reside in the root of a develop checkout. `phpunit` should be run from the root.
see #25088.
git-svn-id: https://develop.svn.wordpress.org/trunk@25165 602fd350-edb4-49c9-b593-d223f7449a82
Diffstat (limited to 'tests/phpunit/includes/functions.php')
-rw-r--r-- | tests/phpunit/includes/functions.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/phpunit/includes/functions.php b/tests/phpunit/includes/functions.php new file mode 100644 index 0000000000..5759d530c9 --- /dev/null +++ b/tests/phpunit/includes/functions.php @@ -0,0 +1,44 @@ +<?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 ); + } +} + |