Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1/tests/phpunit/tests/date/query.php

    r30142 r31396  
    858858        public function test_validate_date_values_hour() {
    859859                // Valid values.
    860                 $hours = range( 1, 23 );
     860                $hours = range( 0, 23 );
    861861                foreach ( $hours as $hour ) {
    862862                        $this->assertTrue( $this->q->validate_date_values( array( 'hour' => $hour ) ) );
    … …  
    864864
    865865                // Invalid values.
    866                 $hours = array( -1, 24, 25, 'string who wants to be a int' );
     866                $hours = array( -1, 24, 25, 'string' );
    867867                foreach ( $hours as $hour ) {
    868868                        $this->assertFalse( $this->q->validate_date_values( array( 'hour' => $hour ) ) );
    … …  
    961961        }
    962962
     963        /**
     964         * @ticket 31001
     965         */
     966        public function test_validate_date_values_should_process_array_value_for_year() {
     967                $p1 = $this->factory->post->create( array( 'post_date' => '2015-01-12' ) );
     968                $p2 = $this->factory->post->create( array( 'post_date' => '2013-01-12' ) );
     969
     970                $q = new WP_Query( array(
     971                        'date_query' => array(
     972                                array(
     973                                        'compare' => 'BETWEEN',
     974                                        'year' => array( 2012, 2014 ),
     975                                ),
     976                        ),
     977                        'fields' => 'ids',
     978                ) );
     979
     980                $this->assertEquals( array( $p2 ), $q->posts );
     981        }
     982
     983        /**
     984         * @ticket 31001
     985         */
     986        public function test_validate_date_values_should_process_array_value_for_day() {
     987                $p1 = $this->factory->post->create( array( 'post_date' => '2015-01-12' ) );
     988                $p2 = $this->factory->post->create( array( 'post_date' => '2015-01-10' ) );
     989
     990                $q = new WP_Query( array(
     991                        'date_query' => array(
     992                                array(
     993                                        'compare' => 'BETWEEN',
     994                                        'day' => array( 9, 11 ),
     995                                ),
     996                        ),
     997                        'fields' => 'ids',
     998                ) );
     999
     1000                $this->assertEquals( array( $p2 ), $q->posts );
     1001        }
     1002
     1003        /**
     1004         * @ticket 31001
     1005         * @expectedIncorrectUsage WP_Date_Query
     1006         */
     1007        public function test_validate_date_values_should_process_array_value_for_day_when_values_are_invalid() {
     1008                $p1 = $this->factory->post->create( array( 'post_date' => '2015-01-12' ) );
     1009                $p2 = $this->factory->post->create( array( 'post_date' => '2015-01-10' ) );
     1010
     1011                $q = new WP_Query( array(
     1012                        'date_query' => array(
     1013                                array(
     1014                                        'compare' => 'BETWEEN',
     1015                                        'day' => array( 9, 32 ),
     1016                                ),
     1017                        ),
     1018                        'fields' => 'ids',
     1019                ) );
     1020
     1021                // MySQL ignores the invalid clause.
     1022                $this->assertEquals( array( $p1, $p2 ), $q->posts );
     1023        }
     1024
    9631025        /** Helpers **********************************************************/
    9641026
Note: See TracChangeset for help on using the changeset viewer.