Make WordPress Core

Ticket #36824: 36824.3.diff

File 36824.3.diff, 4.2 KB (added by dshanske, 9 years ago)

Attempt to Add Unit Tests

  • src/wp-includes/comment.php

    diff --git src/wp-includes/comment.php src/wp-includes/comment.php
    index ef4b553..a5e4084 100644
    function do_all_pings() { 
    22672267        global $wpdb;
    22682268
    22692269        // Do pingbacks
    2270         while ($ping = $wpdb->get_row("SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) {
    2271                 delete_metadata_by_mid( 'post', $ping->meta_id );
     2270        $pings = get_posts( array( 'post_type' => 'any', 'posts_per_page' => -1, 'meta_value' => '_pingme' ) );
     2271        foreach ( $pings as $ping ) {
     2272                delete_post_meta( $ping->ID, '_pingme' );
    22722273                pingback( $ping->post_content, $ping->ID );
    22732274        }
    22742275
    22752276        // Do Enclosures
    2276         while ($enclosure = $wpdb->get_row("SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) {
    2277                 delete_metadata_by_mid( 'post', $enclosure->meta_id );
     2277        $enclosures = get_posts( array( 'post_type' => 'any', 'posts_per_page' => -1, 'meta_value' => '_encloseme' ) );
     2278        foreach ( $enclosures as $enclosure ) {
     2279                delete_post_meta( $enclosure->ID, '_encloseme' );
    22782280                do_enclose( $enclosure->post_content, $enclosure->ID );
    22792281        }
    22802282
    22812283        // Do Trackbacks
    2282         $trackbacks = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE to_ping <> '' AND post_status = 'publish'");
    2283         if ( is_array($trackbacks) )
    2284                 foreach ( $trackbacks as $trackback )
    2285                         do_trackbacks($trackback);
     2284        $trackbacks = get_posts( array( 'post_type' => 'any', 'posts_per_page' => -1, 'to_ping' => true, 'fields' => 'ids' ) );
     2285        foreach ( $trackbacks as $trackback ) {
     2286                do_trackbacks( $trackback );
     2287        }
    22862288
    22872289        //Do Update Services/Generic Pings
    22882290        generic_ping();
  • src/wp-includes/query.php

    diff --git src/wp-includes/query.php src/wp-includes/query.php
    index 077e7ed..8b206bf 100644
    class WP_Query { 
    15701570         *     @type array        $tax_query               An associative array of WP_Tax_Query arguments.
    15711571         *                                                 See WP_Tax_Query->queries.
    15721572         *     @type string       $title                   Post title.
     1573         *     @type string       $to_ping                 Post ping status. Default false.
    15731574         *     @type bool         $update_post_meta_cache  Whether to update the post meta cache. Default true.
    15741575         *     @type bool         $update_post_term_cache  Whether to update the post term cache. Default true.
    15751576         *     @type bool         $lazy_load_term_meta     Whether to lazy-load term meta. Setting to false will
    class WP_Query { 
    16081609                $qv['pagename'] = trim( $qv['pagename'] );
    16091610                $qv['name'] = trim( $qv['name'] );
    16101611                $qv['title'] = trim( $qv['title'] );
     1612
    16111613                if ( '' !== $qv['hour'] ) $qv['hour'] = absint($qv['hour']);
    16121614                if ( '' !== $qv['minute'] ) $qv['minute'] = absint($qv['minute']);
    16131615                if ( '' !== $qv['second'] ) $qv['second'] = absint($qv['second']);
    class WP_Query { 
    25672569                        else
    25682570                                $q['post_type'] = '';
    25692571                }
     2572                if ( ! isset( $q['to_ping'] ) ) {
     2573                        $q['to_ping'] = false;
     2574                }
    25702575                $post_type = $q['post_type'];
    25712576                if ( empty( $q['posts_per_page'] ) ) {
    25722577                        $q['posts_per_page'] = get_option( 'posts_per_page' );
    class WP_Query { 
    30893094                        $post_type_object = get_post_type_object ( 'post' );
    30903095                }
    30913096
     3097                if ( $q['to_ping'] ) {
     3098                        $where .= " AND {$wpdb->posts}.to_ping <> ''";
     3099                }
     3100
    30923101                $edit_cap = 'edit_post';
    30933102                $read_cap = 'read_post';
    30943103
  • tests/phpunit/tests/post/query.php

    diff --git tests/phpunit/tests/post/query.php tests/phpunit/tests/post/query.php
    index 0ede881..f3fc546 100644
    class Tests_Post_Query extends WP_UnitTestCase { 
    388388                $actual_posts = $q->get_posts();
    389389                $this->assertEqualSets( $requested, $actual_posts );
    390390        }
     391       
     392        /**
     393         * Tests the to_ping attribute of WP_Query.
     394         *
     395         * @ticket 36824
     396         */
     397        public function test_to_ping() {
     398                $q = new WP_Query();
     399
     400                $post_ids[0] = self::factory()->post->create( array(
     401                                                'to_ping' => 'http://www.example.com' ) );
     402                $q->query( array(
     403                                'to_ping' => '',
     404                                'fields' => 'ids' ) );
     405                $actual_posts = $q->get_posts();
     406                $this->assertSame( $post_ids, $actual_posts );
     407        }
     408
    391409
    392410        /**
    393411         * @ticket 36687