Make WordPress Core

Ticket #38268: 38268.patch

File 38268.patch, 14.1 KB (added by AdamWills, 7 years ago)

First core contribution attempt

  • src/wp-includes/class-wp-comment-query.php

    diff --git src/wp-includes/class-wp-comment-query.php src/wp-includes/class-wp-comment-query.php
    index 67dfcae..ef8b6d5 100644
    class WP_Comment_Query { 
    183183         *                                                   See WP_Meta_Query. Default empty.
    184184         *     @type int          $number                    Maximum number of comments to retrieve.
    185185         *                                                   Default empty (no limit).
    186          *     @type int          $paged                     When used with number, defines the page of results to return.
    187          *                                                   Default 1.
    188186         *     @type int          $offset                    Number of comments to offset the query. Used to build
    189187         *                                                   LIMIT clause. Default 0.
    190188         *     @type bool         $no_found_rows             Whether to disable the `SQL_CALC_FOUND_ROWS` query.
    class WP_Comment_Query { 
    278276                        'no_found_rows' => true,
    279277                        'orderby' => '',
    280278                        'order' => 'DESC',
    281                         'paged' => '1',
    282279                        'parent' => '',
    283280                        'parent__in' => '',
    284281                        'parent__not_in' => '',
    class WP_Comment_Query { 
    643640
    644641                $number = absint( $this->query_vars['number'] );
    645642                $offset = absint( $this->query_vars['offset'] );
    646                 $paged = absint( $this->query_vars['paged'] );
    647643
    648644                if ( ! empty( $number ) ) {
    649645                        if ( $offset ) {
    650646                                $limits = 'LIMIT ' . $offset . ',' . $number;
    651647                        } else {
    652                                 $limits = 'LIMIT ' . ( $number * ( $paged - 1 ) ) . ',' . $number;
     648                                $limits = 'LIMIT ' . $number;
    653649                        }
    654650                }
    655651
  • src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php

    diff --git src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php
    index 8bffb0e..802d67e 100644
    class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting { 
    604604                }
    605605
    606606                // Ensure nav menu item URL is set according to linked object.
    607                 if ( ! empty( $post->object_id ) ) {
    608                         if ( 'post_type' === $post->type ) {
    609                                 $post->url = get_permalink( $post->object_id );
    610                         } elseif ( 'post_type_archive' === $post->type && ! empty( $post->object ) ) {
    611                                 $post->url = get_post_type_archive_link( $post->object );
    612                         } elseif ( 'taxonomy' == $post->type && ! empty( $post->object ) ) {
    613                                 $post->url = get_term_link( (int) $post->object, $post->object );
    614                         }
     607                if ( 'post_type' === $post->type && ! empty( $post->object_id ) ) {
     608                        $post->url = get_permalink( $post->object_id );
     609                } elseif ( 'taxonomy' === $post->type && ! empty( $post->object ) && ! empty( $post->object_id ) ) {
     610                        $post->url = get_term_link( (int) $post->object_id, $post->object );
     611                } elseif ( 'post_type_archive' === $post->type && ! empty( $post->object ) ) {
     612                        $post->url = get_post_type_archive_link( $post->object );
     613                }
     614                if ( is_wp_error( $post->url ) ) {
     615                        $post->url = '';
    615616                }
    616617
    617618                /** This filter is documented in wp-includes/nav-menu.php */
  • tests/phpunit/tests/auth.php

    diff --git tests/phpunit/tests/auth.php tests/phpunit/tests/auth.php
    index 581e856..e025459 100644
    class Tests_Auth extends WP_UnitTestCase { 
    239239
    240240                // A valid key should be accepted
    241241                $check = check_password_reset_key( $key, $this->user->user_login );
     242                $this->assertNotWPError( $check );
    242243                $this->assertInstanceOf( 'WP_User', $check );
    243244                $this->assertSame( $this->user->ID, $check->ID );
    244245
  • tests/phpunit/tests/comment/query.php

    diff --git tests/phpunit/tests/comment/query.php tests/phpunit/tests/comment/query.php
    index beb8c43..ff4e3ac 100644
    class Tests_Comment_Query extends WP_UnitTestCase { 
    15611561                $this->assertEquals( 2, $found );
    15621562        }
    15631563
    1564         /**
    1565          * @ticket 38268
    1566          */
    1567         public function test_pagination_query() {
    1568                 $comments = self::factory()->comment->create_many( 4, array(
    1569                         'comment_post_ID' => self::$post_id,
    1570                 ) );
    1571 
    1572                 $query1 = new WP_Comment_Query();
    1573                 $found1 = $query1->query( array(
    1574                         'paged' => 2,
    1575                         'number' => 2
    1576                 ) );
    1577 
    1578                 $query2 = new WP_Comment_Query();
    1579                 $found2 = $query2->query(
    1580                         array(
    1581                                 'offset' => 2,
    1582                                 'number' => 2
    1583                         )
    1584                 );
    1585                 $this->assertEqualSets( $found1, $found2 );
    1586         }
    1587 
    1588         /**
    1589          * @ticket 38268
    1590          */
    1591         public function test_pagination_offset_conflict() {
    1592                 $comments = self::factory()->comment->create_many( 4, array(
    1593                         'comment_post_ID' => self::$post_id,
    1594                 ) );
    1595                 $query1 = new WP_Comment_Query();
    1596                 $found1 = $query1->query( array(
    1597                         'paged' => 2,
    1598                         'offset' => 1,
    1599                         'number' => 2
    1600                 ) );
    1601 
    1602                 $query2 = new WP_Comment_Query();
    1603                 $found2 = $query2->query(
    1604                         array(
    1605                                 'offset' => 1,
    1606                                 'number' => 2
    1607                         )
    1608                 );
    1609                 $this->assertEqualSets( $found1, $found2 );
    1610         }
    1611 
    16121564        public function test_post_type_single_value() {
    16131565                register_post_type( 'post-type-1' );
    16141566                register_post_type( 'post-type-2' );
  • tests/phpunit/tests/customize/nav-menu-item-setting.php

    diff --git tests/phpunit/tests/customize/nav-menu-item-setting.php tests/phpunit/tests/customize/nav-menu-item-setting.php
    index ebb9748..45aefb9 100644
    class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase { 
    834834        }
    835835
    836836        /**
     837         * Test WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item() to set url for posts, terms, and post type archives.
     838         *
     839         * @ticket 38945
     840         * @covers WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item()
     841         */
     842        function test_value_as_wp_post_nav_menu_item_term_urls() {
     843                $term_id = self::factory()->term->create( array( 'taxonomy' => 'category' ) );
     844                register_post_type( 'press_release', array(
     845                        'has_archive' => true,
     846                ) );
     847                $post_id = self::factory()->post->create( array( 'post_type' => 'press_release' ) );
     848
     849                // Term.
     850                $setting = new WP_Customize_Nav_Menu_Item_Setting(
     851                        $this->wp_customize,
     852                        'nav_menu_item[-1]'
     853                );
     854                $this->wp_customize->set_post_value( $setting->id, array(
     855                        'type' => 'taxonomy',
     856                        'object' => 'category',
     857                        'object_id' => $term_id,
     858                        'title' => 'Category',
     859                        'url' => '',
     860                ) );
     861                $setting->preview();
     862                $nav_menu_item = $setting->value_as_wp_post_nav_menu_item();
     863                $this->assertEquals( get_term_link( $term_id ), $nav_menu_item->url );
     864
     865                // Post.
     866                $setting = new WP_Customize_Nav_Menu_Item_Setting(
     867                        $this->wp_customize,
     868                        'nav_menu_item[-2]'
     869                );
     870                $this->wp_customize->set_post_value( $setting->id, array(
     871                        'type' => 'post_type',
     872                        'object' => 'press_release',
     873                        'object_id' => $post_id,
     874                        'title' => 'PR',
     875                        'url' => '',
     876                ) );
     877                $setting->preview();
     878                $nav_menu_item = $setting->value_as_wp_post_nav_menu_item();
     879                $this->assertEquals( get_permalink( $post_id ), $nav_menu_item->url );
     880
     881                // Post type archive.
     882                $setting = new WP_Customize_Nav_Menu_Item_Setting(
     883                        $this->wp_customize,
     884                        'nav_menu_item[-3]'
     885                );
     886                $this->wp_customize->set_post_value( $setting->id, array(
     887                        'type' => 'post_type_archive',
     888                        'object' => 'press_release',
     889                        'title' => 'PR',
     890                        'url' => '',
     891                ) );
     892                $setting->preview();
     893                $nav_menu_item = $setting->value_as_wp_post_nav_menu_item();
     894                $this->assertEquals( get_post_type_archive_link( 'press_release' ), $nav_menu_item->url );
     895        }
     896
     897        /**
    837898         * Test WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item() where title is empty.
    838899         *
    839900         * @ticket 38015
  • tests/phpunit/tests/post/listPages.php

    diff --git tests/phpunit/tests/post/listPages.php tests/phpunit/tests/post/listPages.php
    index d214631..a550c38 100644
     
    33class Tests_List_Pages extends WP_UnitTestCase {
    44        var $pages;
    55
     6        protected $time = null;
     7
    68        /*
    79        $defaults = array(
    810                'depth' => 0,
    class Tests_List_Pages extends WP_UnitTestCase { 
    2729                parent::setUp();
    2830                global $wpdb;
    2931                $wpdb->query( 'TRUNCATE ' . $wpdb->prefix . 'posts' );
     32                $this->time = time();
     33                $post_date = date( 'Y-m-d H:i:s', $this->time );
    3034                $pages = array();
    3135                self::factory()->user->create();
    32                 $pages[] = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Parent 1' ) );
    33                 $pages[] = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Parent 2' ) );
    34                 $pages[] = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Parent 3', 'post_author' => '2' ) );
     36                $pages[] = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Parent 1', 'post_date' => $post_date ) );
     37                $pages[] = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Parent 2', 'post_date' => $post_date ) );
     38                $pages[] = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Parent 3', 'post_author' => '2', 'post_date' => $post_date ) );
    3539
    3640                foreach ( $pages as $page ) {
    37                         $this->pages[$page] = self::factory()->post->create( array( 'post_parent' => $page, 'post_type' => 'page', 'post_title' => 'Child 1' ) );
    38                         $this->pages[$page] = self::factory()->post->create( array( 'post_parent' => $page, 'post_type' => 'page', 'post_title' => 'Child 2' ) );
    39                         $this->pages[$page] = self::factory()->post->create( array( 'post_parent' => $page, 'post_type' => 'page', 'post_title' => 'Child 3' ) );
     41                        $this->pages[$page] = self::factory()->post->create( array( 'post_parent' => $page, 'post_type' => 'page', 'post_title' => 'Child 1', 'post_date' => $post_date ) );
     42                        $this->pages[$page] = self::factory()->post->create( array( 'post_parent' => $page, 'post_type' => 'page', 'post_title' => 'Child 2', 'post_date' => $post_date ) );
     43                        $this->pages[$page] = self::factory()->post->create( array( 'post_parent' => $page, 'post_type' => 'page', 'post_title' => 'Child 3', 'post_date' => $post_date ) );
    4044                }
    4145        }
    4246
    class Tests_List_Pages extends WP_UnitTestCase { 
    8993                        'depth' => 1,
    9094                        'show_date' => true
    9195                );
    92                 $expected['show_date'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a> ' . date( 'F j, Y' ) . '</li>
    93 <li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a> ' . date( 'F j, Y' ) . '</li>
    94 <li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a> ' . date( 'F j, Y' ) . '</li>
     96                $date = date( get_option( 'date_format' ), $this->time );
     97                $expected['show_date'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a> ' . $date . '</li>
     98<li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a> ' . $date . '</li>
     99<li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a> ' . $date . '</li>
    95100</ul></li>';
    96101                $actual = wp_list_pages( $args );
    97102                $this->AssertEquals( $expected['show_date'], $actual );
    class Tests_List_Pages extends WP_UnitTestCase { 
    103108                        'show_date' => true,
    104109                        'date_format' => 'l, F j, Y'
    105110                );
    106                 $expected['date_format'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a> ' . date( 'l, F j, Y' ) . '
     111                $date = date( $args['date_format'], $this->time );
     112                $expected['date_format'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a> ' . $date . '
    107113<ul class=\'children\'>
    108         <li class="page_item page-item-4"><a href="' . get_permalink( 4 ) . '">Child 1</a> ' . date( 'l, F j, Y' ) . '</li>
    109         <li class="page_item page-item-5"><a href="' . get_permalink( 5 ) . '">Child 2</a> ' . date( 'l, F j, Y' ) . '</li>
    110         <li class="page_item page-item-6"><a href="' . get_permalink( 6 ) . '">Child 3</a> ' . date( 'l, F j, Y' ) . '</li>
     114        <li class="page_item page-item-4"><a href="' . get_permalink( 4 ) . '">Child 1</a> ' . $date . '</li>
     115        <li class="page_item page-item-5"><a href="' . get_permalink( 5 ) . '">Child 2</a> ' . $date . '</li>
     116        <li class="page_item page-item-6"><a href="' . get_permalink( 6 ) . '">Child 3</a> ' . $date . '</li>
    111117</ul>
    112118</li>
    113 <li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a> ' . date( 'l, F j, Y' ) . '
     119<li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a> ' . $date . '
    114120<ul class=\'children\'>
    115         <li class="page_item page-item-7"><a href="' . get_permalink( 7 ) . '">Child 1</a> ' . date( 'l, F j, Y' ) . '</li>
    116         <li class="page_item page-item-8"><a href="' . get_permalink( 8 ) . '">Child 2</a> ' . date( 'l, F j, Y' ) . '</li>
    117         <li class="page_item page-item-9"><a href="' . get_permalink( 9 ) . '">Child 3</a> ' . date( 'l, F j, Y' ) . '</li>
     121        <li class="page_item page-item-7"><a href="' . get_permalink( 7 ) . '">Child 1</a> ' . $date . '</li>
     122        <li class="page_item page-item-8"><a href="' . get_permalink( 8 ) . '">Child 2</a> ' . $date . '</li>
     123        <li class="page_item page-item-9"><a href="' . get_permalink( 9 ) . '">Child 3</a> ' . $date . '</li>
    118124</ul>
    119125</li>
    120 <li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a> ' . date( 'l, F j, Y' ) . '
     126<li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a> ' . $date . '
    121127<ul class=\'children\'>
    122         <li class="page_item page-item-10"><a href="' . get_permalink( 10 ) . '">Child 1</a> ' . date( 'l, F j, Y' ) . '</li>
    123         <li class="page_item page-item-11"><a href="' . get_permalink( 11 ) . '">Child 2</a> ' . date( 'l, F j, Y' ) . '</li>
    124         <li class="page_item page-item-12"><a href="' . get_permalink( 12 ) . '">Child 3</a> ' . date( 'l, F j, Y' ) . '</li>
     128        <li class="page_item page-item-10"><a href="' . get_permalink( 10 ) . '">Child 1</a> ' . $date . '</li>
     129        <li class="page_item page-item-11"><a href="' . get_permalink( 11 ) . '">Child 2</a> ' . $date . '</li>
     130        <li class="page_item page-item-12"><a href="' . get_permalink( 12 ) . '">Child 3</a> ' . $date . '</li>
    125131</ul>
    126132</li>
    127133</ul></li>';