Make WordPress Core

Ticket #25835: unit-test.25835.diff

File unit-test.25835.diff, 2.3 KB (added by oso96_2000, 11 years ago)

Unit test and fixed diff route

  • src/wp-includes/date.php

    diff --git src/wp-includes/date.php src/wp-includes/date.php
    index 0c42766..ed8fff7 100644
    class WP_Date_Query { 
    256256
    257257                if ( isset( $query['month'] ) && $value = $this->build_value( $compare, $query['month'] ) )
    258258                        $where_parts[] = "MONTH( $column ) $compare $value";
    259 
    260                 // Legacy
    261                 if ( isset( $query['monthnum'] ) && $value = $this->build_value( $compare, $query['monthnum'] ) )
     259                else if ( isset( $query['monthnum'] ) && $value = $this->build_value( $compare, $query['monthnum'] ) )
    262260                        $where_parts[] = "MONTH( $column ) $compare $value";
    263261
    264262                if ( isset( $query['week'] ) && false !== ( $value = $this->build_value( $compare, $query['week'] ) ) )
    265263                        $where_parts[] = _wp_mysql_week( $column ) . " $compare $value";
    266 
    267                 // Legacy
    268                 if ( isset( $query['w'] ) && false !== ( $value = $this->build_value( $compare, $query['w'] ) ) )
     264                else if ( isset( $query['w'] ) && false !== ( $value = $this->build_value( $compare, $query['w'] ) ) )
    269265                        $where_parts[] = _wp_mysql_week( $column ) . " $compare $value";
    270266
    271267                if ( isset( $query['dayofyear'] ) && $value = $this->build_value( $compare, $query['dayofyear'] ) )
  • tests/phpunit/tests/query/dateQuery.php

    diff --git tests/phpunit/tests/query/dateQuery.php tests/phpunit/tests/query/dateQuery.php
    index 47cc71d..17fe779 100644
    class Tests_Query_DateQuery extends WP_UnitTestCase { 
    555555
    556556                $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
    557557        }
     558
     559        public function test_date_params_monthnum_m_duplicate() {
     560                $this->q->query( array(
     561                        'date_query' => array(
     562                                'month' => 10,
     563                                'monthnum' => 11
     564                        ),
     565                ) );
     566
     567                $this->assertContains( "AND ( ( MONTH( post_date ) = 10 ) ) AND", $this->q->request );
     568
     569                $this->assertNotContains( "AND ( ( MONTH( post_date ) = 10 AND MONTH( post_date ) = 11 ) ) AND", $this->q->request );
     570        }
     571
     572        public function test_date_params_week_w_duplicate() {
     573                $this->q->query( array(
     574                        'date_query' => array(
     575                                'week' => 10,
     576                                'w' => 11
     577                        ),
     578                ) );
     579
     580                $this->assertContains( "AND ( ( WEEK( post_date, 1 ) = 10 ) ) AND", $this->q->request );
     581
     582                $this->assertNotContains( "AND ( ( WEEK( post_date, 1 ) = 10 AND WEEK( post_date, 1 ) = 11 ) ) AND", $this->q->request );
     583        }
    558584}
     585 No newline at end of file