WordPress.org

Make WordPress Core

Changeset 196 in tests


Ignore:
Timestamp:
04/01/08 23:47:06 (6 years ago)
Author:
tellyworth
Message:

add TestSanitizeOrderby

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_includes_formatting.php

    r172 r196  
    147147} 
    148148 
     149class TestSanitizeOrderby extends WPTestCase { 
     150     
     151    function test_empty() { 
     152        if ( !is_callable('sanitize_orderby') ) 
     153            $this->markTestSkipped(); 
     154 
     155        $cols = array('a' => 'a'); 
     156        $this->assertEquals( '', sanitize_orderby('', $cols) ); 
     157        $this->assertEquals( '', sanitize_orderby('  ', $cols) ); 
     158        $this->assertEquals( '', sanitize_orderby("\t", $cols) ); 
     159        $this->assertEquals( '', sanitize_orderby(null, $cols) ); 
     160        $this->assertEquals( '', sanitize_orderby(0, $cols) ); 
     161        $this->assertEquals( '', sanitize_orderby('+', $cols) ); 
     162        $this->assertEquals( '', sanitize_orderby('-', $cols) ); 
     163    } 
     164     
     165    function test_unknown_column() { 
     166        if ( !is_callable('sanitize_orderby') ) 
     167            $this->markTestSkipped(); 
     168 
     169        $cols = array('name' => 'post_name', 'date' => 'post_date'); 
     170        $this->assertEquals( '', sanitize_orderby('unknown_column', $cols) ); 
     171        $this->assertEquals( '', sanitize_orderby('+unknown_column', $cols) ); 
     172        $this->assertEquals( '', sanitize_orderby('-unknown_column', $cols) ); 
     173        $this->assertEquals( '', sanitize_orderby('-unknown1,+unknown2,unknown3', $cols) ); 
     174        $this->assertEquals( 'post_name ASC', sanitize_orderby('name,unknown_column', $cols) ); 
     175        $this->assertEquals( '', sanitize_orderby('!@#$%^&*()_=~`\'",./', $cols) ); 
     176    } 
     177 
     178    function test_valid() { 
     179        if ( !is_callable('sanitize_orderby') ) 
     180            $this->markTestSkipped(); 
     181 
     182        $cols = array('name' => 'post_name', 'date' => 'post_date', 'random' => 'rand()'); 
     183        $this->assertEquals( 'post_name ASC', sanitize_orderby('name', $cols) ); 
     184        $this->assertEquals( 'post_name ASC', sanitize_orderby('+name', $cols) ); 
     185        $this->assertEquals( 'post_name DESC', sanitize_orderby('-name', $cols) ); 
     186        $this->assertEquals( 'post_date ASC, post_name ASC', sanitize_orderby('date,name', $cols) ); 
     187        $this->assertEquals( 'post_date ASC, post_name ASC', sanitize_orderby(' date , name ', $cols) ); 
     188        $this->assertEquals( 'post_name DESC, post_date ASC', sanitize_orderby('-name,date', $cols) ); 
     189        $this->assertEquals( 'post_name ASC, post_date ASC', sanitize_orderby('name ,+ date', $cols) ); 
     190        $this->assertEquals( 'rand() ASC', sanitize_orderby('random', $cols) ); 
     191    } 
     192 
     193} 
     194 
    149195?> 
Note: See TracChangeset for help on using the changeset viewer.