123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- <?php
- require_once __DIR__ . '/class-basic-object.php';
- function tests_get_phpunit_version() {
- if ( class_exists( 'PHPUnit_Runner_Version' ) ) {
- $version = PHPUnit_Runner_Version::id();
- } elseif ( class_exists( 'PHPUnit\Runner\Version' ) ) {
- $version = PHPUnit\Runner\Version::id();
- } else {
- $version = 0;
- }
- return $version;
- }
- function tests_reset__SERVER() {
- $_SERVER['HTTP_HOST'] = WP_TESTS_DOMAIN;
- $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
- $_SERVER['REQUEST_METHOD'] = 'GET';
- $_SERVER['REQUEST_URI'] = '';
- $_SERVER['SERVER_NAME'] = WP_TESTS_DOMAIN;
- $_SERVER['SERVER_PORT'] = '80';
- $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
- unset( $_SERVER['HTTP_REFERER'] );
- unset( $_SERVER['HTTPS'] );
- }
- function tests_add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
- global $wp_filter;
- if ( function_exists( 'add_filter' ) ) {
- add_filter( $tag, $function_to_add, $priority, $accepted_args );
- } else {
- $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,
- );
- }
- return true;
- }
- function _test_filter_build_unique_id( $tag, $function, $priority ) {
- if ( is_string( $function ) ) {
- return $function;
- }
- if ( is_object( $function ) ) {
-
- $function = array( $function, '' );
- } else {
- $function = (array) $function;
- }
- if ( is_object( $function[0] ) ) {
-
- return spl_object_hash( $function[0] ) . $function[1];
- } elseif ( is_string( $function[0] ) ) {
-
- return $function[0] . '::' . $function[1];
- }
- }
- function _delete_all_data() {
- global $wpdb;
- foreach ( array(
- $wpdb->posts,
- $wpdb->postmeta,
- $wpdb->comments,
- $wpdb->commentmeta,
- $wpdb->term_relationships,
- $wpdb->termmeta,
- ) as $table ) {
-
- $wpdb->query( "DELETE FROM {$table}" );
- }
- foreach ( array(
- $wpdb->terms,
- $wpdb->term_taxonomy,
- ) as $table ) {
-
- $wpdb->query( "DELETE FROM {$table} WHERE term_id != 1" );
- }
- $wpdb->query( "UPDATE {$wpdb->term_taxonomy} SET count = 0" );
- $wpdb->query( "DELETE FROM {$wpdb->users} WHERE ID != 1" );
- $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE user_id != 1" );
- }
- function _delete_all_posts() {
- global $wpdb;
- $all_posts = $wpdb->get_results( "SELECT ID, post_type from {$wpdb->posts}", ARRAY_A );
- if ( ! $all_posts ) {
- return;
- }
- foreach ( $all_posts as $data ) {
- if ( 'attachment' === $data['post_type'] ) {
- wp_delete_attachment( $data['ID'], true );
- } else {
- wp_delete_post( $data['ID'], true );
- }
- }
- }
- function _wp_die_handler( $message, $title = '', $args = array() ) {
- if ( ! $GLOBALS['_wp_die_disabled'] ) {
- _wp_die_handler_txt( $message, $title, $args );
- } else {
-
- }
- }
- function _disable_wp_die() {
- $GLOBALS['_wp_die_disabled'] = true;
- }
- function _enable_wp_die() {
- $GLOBALS['_wp_die_disabled'] = false;
- }
- function _wp_die_handler_filter() {
- return '_wp_die_handler';
- }
- function _wp_die_handler_filter_exit() {
- return '_wp_die_handler_exit';
- }
- function _wp_die_handler_txt( $message, $title, $args ) {
- echo "\nwp_die called\n";
- echo "Message: $message\n";
- if ( ! empty( $title ) ) {
- echo "Title: $title\n";
- }
- if ( ! empty( $args ) ) {
- echo "Args: \n";
- foreach ( $args as $k => $v ) {
- echo "\t $k : $v\n";
- }
- }
- }
- function _wp_die_handler_exit( $message, $title, $args ) {
- echo "\nwp_die called\n";
- echo "Message: $message\n";
- if ( ! empty( $title ) ) {
- echo "Title: $title\n";
- }
- if ( ! empty( $args ) ) {
- echo "Args: \n";
- foreach ( $args as $k => $v ) {
- echo "\t $k : $v\n";
- }
- }
- exit( 1 );
- }
- function _set_default_permalink_structure_for_tests() {
- update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
- }
- function _upload_dir_no_subdir( $uploads ) {
- $subdir = $uploads['subdir'];
- $uploads['subdir'] = '';
- $uploads['path'] = str_replace( $subdir, '', $uploads['path'] );
- $uploads['url'] = str_replace( $subdir, '', $uploads['url'] );
- return $uploads;
- }
- function _upload_dir_https( $uploads ) {
- $uploads['url'] = str_replace( 'http://', 'https://', $uploads['url'] );
- $uploads['baseurl'] = str_replace( 'http://', 'https://', $uploads['baseurl'] );
- return $uploads;
- }
- function _wp_rest_server_class_filter() {
- return 'Spy_REST_Server';
- }
- tests_add_filter( 'send_auth_cookies', '__return_false' );
- function _unhook_block_registration() {
- remove_action( 'init', 'register_block_core_archives' );
- remove_action( 'init', 'register_block_core_block' );
- remove_action( 'init', 'register_block_core_calendar' );
- remove_action( 'init', 'register_block_core_categories' );
- remove_action( 'init', 'register_block_core_latest_comments' );
- remove_action( 'init', 'register_block_core_latest_posts' );
- remove_action( 'init', 'register_block_core_rss' );
- remove_action( 'init', 'register_block_core_search' );
- remove_action( 'init', 'register_block_core_shortcode' );
- remove_action( 'init', 'register_block_core_social_link' );
- remove_action( 'init', 'register_block_core_social_link' );
- remove_action( 'init', 'register_block_core_tag_cloud' );
- remove_action( 'init', 'register_core_block_types_from_metadata' );
- }
- tests_add_filter( 'init', '_unhook_block_registration', 1000 );
|