Make WordPress Core


Ignore:
Timestamp:
09/23/2014 03:51:24 AM (10 years ago)
Author:
wonderboymusic
Message:

Ordering by RAND():

The shortcode callbacks for gallery and playlist check for 'RAND' == $atts['order'], which isn't a valid value for order. Remove those checks and update the docs.

In WP_Query, if the value of orderby is rand, order is irrelevant and should be unset.

Adds unit tests.

Fixes #29629.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/query.php

    r29027 r29760  
    832832        );
    833833    }
     834
     835    /**
     836     * @ticket 29629
     837     */
     838    function test_orderby() {
     839        // 'rand' is a valid value
     840        $q = new WP_Query( array( 'orderby' => 'rand' ) );
     841        $this->assertContains( 'ORDER BY RAND()', $q->request );
     842        $this->assertNotContains( 'ASC', $q->request );
     843        $this->assertNotContains( 'DESC', $q->request );
     844
     845        // This isn't allowed
     846        $q2 = new WP_Query( array( 'order' => 'rand' ) );
     847        $this->assertContains( 'ORDER BY', $q2->request );
     848        $this->assertNotContains( 'RAND()', $q2->request );
     849        $this->assertContains( 'DESC', $q2->request );
     850
     851        // 'none' is a valid value
     852        $q3 = new WP_Query( array( 'orderby' => 'none' ) );
     853        $this->assertNotContains( 'ORDER BY', $q3->request );
     854        $this->assertNotContains( 'DESC', $q3->request );
     855        $this->assertNotContains( 'ASC', $q3->request );
     856
     857        // false is a valid value
     858        $q4 = new WP_Query( array( 'orderby' => false ) );
     859        $this->assertNotContains( 'ORDER BY', $q4->request );
     860        $this->assertNotContains( 'DESC', $q4->request );
     861        $this->assertNotContains( 'ASC', $q4->request );
     862
     863        // empty array() is a valid value
     864        $q5 = new WP_Query( array( 'orderby' => array() ) );
     865        $this->assertNotContains( 'ORDER BY', $q5->request );
     866        $this->assertNotContains( 'DESC', $q5->request );
     867        $this->assertNotContains( 'ASC', $q5->request );
     868    }
    834869}
Note: See TracChangeset for help on using the changeset viewer.