Make WordPress Core


Ignore:
Timestamp:
09/05/2013 04:56:36 PM (13 years ago)
Author:
wonderboymusic
Message:

When meta_type is passed with orderby => meta_value, orderby must also use CAST() to avoid scenarios like: SELECTing by UNSIGNED and then ordering by CHAR. Adds unit test.

Fixes #21621.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/meta.php

    r25254 r25255  
    151151                $this->assertEquals( $expected2, get_metadata( 'user', $this->author->ID, $key, true ) );
    152152        }
     153
     154        function test_meta_type_cast() {
     155                $post_id1 = $this->factory->post->create();
     156                add_post_meta( $post_id1, 'num_as_longtext', 123 );
     157                $post_id2 = $this->factory->post->create();
     158                add_post_meta( $post_id2, 'num_as_longtext', 99 );
     159
     160                $posts = new WP_Query( array(
     161                        'fields' => 'ids',
     162                        'post_type' => 'any',
     163                        'meta_key' => 'num_as_longtext',
     164                        'meta_value' => '0',
     165                        'meta_compare' => '>',
     166                        'meta_type' => 'UNSIGNED',
     167                        'orderby' => 'meta_value',
     168                        'order' => 'ASC'
     169                ) );
     170
     171                $this->assertEquals( array( $post_id2, $post_id1 ), $posts->posts );
     172                $this->assertEquals( 2, substr_count( $posts->request, 'CAST(' ) );
     173        }
    153174}
Note: See TracChangeset for help on using the changeset viewer.