Make WordPress Core

Ticket #10935: 10935.6.diff

File 10935.6.diff, 5.1 KB (added by wonderboymusic, 12 years ago)
  • tests/phpunit/tests/query/results.php

     
    486486                $author_ids = array_unique( wp_list_pluck( $posts, 'post_author' ) );
    487487                $this->assertEqualSets( array( $author_1 ), $author_ids );
    488488        }
     489
     490        /**
     491         * @ticket 10935
     492         */
     493        function test_query_is_date() {
     494                $this->q->query( array(
     495                        'year' => '2007',
     496                        'monthnum' => '01',
     497                        'day' => '01',
     498                ) );
     499
     500                $this->assertTrue( $this->q->is_date );
     501                $this->assertTrue( $this->q->is_day );
     502                $this->assertFalse( $this->q->is_month );
     503                $this->assertFalse( $this->q->is_year );
     504
     505                $this->q->query( array(
     506                        'year' => '2007',
     507                        'monthnum' => '01',
     508                ) );
     509
     510                $this->assertTrue( $this->q->is_date );
     511                $this->assertFalse( $this->q->is_day );
     512                $this->assertTrue( $this->q->is_month );
     513                $this->assertFalse( $this->q->is_year );
     514
     515                $this->q->query( array(
     516                        'year' => '2007',
     517                ) );
     518
     519                $this->assertTrue( $this->q->is_date );
     520                $this->assertFalse( $this->q->is_day );
     521                $this->assertFalse( $this->q->is_month );
     522                $this->assertTrue( $this->q->is_year );
     523
     524                $this->q->query( array(
     525                        'year' => '2007',
     526                        'monthnum' => '01',
     527                        'day' => '50',
     528                ) );
     529
     530                $this->assertTrue( $this->q->is_404 );
     531                $this->assertFalse( $this->q->is_date );
     532                $this->assertFalse( $this->q->is_day );
     533                $this->assertFalse( $this->q->is_month );
     534                $this->assertFalse( $this->q->is_year );
     535        }
    489536}
  • tests/phpunit/tests/query/conditionals.php

     
    629629        // '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1',
    630630        // '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
    631631        // '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
     632
     633        function test_bad_dates() {
     634                $this->go_to( '/2013/13/13/' );
     635                $this->assertQueryTrue( 'is_404' );
     636
     637                $this->go_to( '/2013/11/41/' );
     638                $this->assertQueryTrue( 'is_404' );
     639        }
    632640}
  • tests/phpunit/tests/canonical.php

     
    239239
    240240                        array( '/?year=2008', '/2008/'),
    241241
     242                        array( '/2012/13/', '/2012/'),
     243                        array( '/2012/11/51/', '/2012/11/'),
     244
    242245                        // Authors
    243246                        array( '/?author=%d', '/author/canonical-author/' ),
    244247//                      array( '/?author=%d&year=2008', '/2008/?author=3'),
  • src/wp-includes/query.php

     
    15131513
    15141514                        if ( $qv['day'] ) {
    15151515                                if ( ! $this->is_date ) {
    1516                                         $this->is_day = true;
    1517                                         $this->is_date = true;
     1516                                        $date = sprintf( '%04d-%02d-%02d', $qv['year'], $qv['monthnum'], $qv['day'] );
     1517                                        if ( $qv['monthnum'] && $qv['year'] && ! wp_checkdate( $qv['monthnum'], $qv['day'], $qv['year'], $date ) ) {
     1518                                                $qv['error'] = '404';
     1519                                        } else {
     1520                                                $this->is_day = true;
     1521                                                $this->is_date = true;
     1522                                        }
    15181523                                }
    15191524                        }
    15201525
    15211526                        if ( $qv['monthnum'] ) {
    15221527                                if ( ! $this->is_date ) {
    1523                                         $this->is_month = true;
    1524                                         $this->is_date = true;
     1528                                        if ( 12 < $qv['monthnum'] ) {
     1529                                                $qv['error'] = '404';
     1530                                        } else {
     1531                                                $this->is_month = true;
     1532                                                $this->is_date = true;
     1533                                        }
    15251534                                }
    15261535                        }
    15271536
  • src/wp-includes/canonical.php

     
    101101                        }
    102102                }
    103103
     104                if ( get_query_var( 'day' ) && get_query_var( 'monthnum' ) && get_query_var( 'year' ) ) {
     105                        $year  = get_query_var( 'year' );
     106                        $month = get_query_var( 'monthnum' );
     107                        $day   = get_query_var( 'day' );
     108                        $date  = sprintf( '%04d-%02d-%02d', $year, $month, $day );
     109                        if ( ! wp_checkdate( $month, $day, $year, $date ) ) {
     110                                $redirect_url = get_month_link( $year, $month );
     111                                $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'year', 'monthnum', 'day' ), $redirect_url );
     112                        }
     113                } elseif ( get_query_var( 'monthnum' ) && get_query_var( 'year' ) && 12 < get_query_var( 'monthnum' ) ) {
     114                        $redirect_url = get_year_link( get_query_var( 'year' ) );
     115                        $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'year', 'monthnum' ), $redirect_url );
     116                }
     117
    104118                if ( ! $redirect_url ) {
    105119                        if ( $redirect_url = redirect_guess_404_permalink() ) {
    106120                                $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url );