SanitizeOrderby.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /* // @todo These tests need to be rewritten for sanitize_sql_orderby
  3. class Tests_Formatting_SanitizeOrderby extends WP_UnitTestCase {
  4. function test_empty() {
  5. $cols = array('a' => 'a');
  6. $this->assertEquals( '', sanitize_sql_orderby('', $cols) );
  7. $this->assertEquals( '', sanitize_sql_orderby(' ', $cols) );
  8. $this->assertEquals( '', sanitize_sql_orderby("\t", $cols) );
  9. $this->assertEquals( '', sanitize_sql_orderby(null, $cols) );
  10. $this->assertEquals( '', sanitize_sql_orderby(0, $cols) );
  11. $this->assertEquals( '', sanitize_sql_orderby('+', $cols) );
  12. $this->assertEquals( '', sanitize_sql_orderby('-', $cols) );
  13. }
  14. function test_unknown_column() {
  15. $cols = array('name' => 'post_name', 'date' => 'post_date');
  16. $this->assertEquals( '', sanitize_sql_orderby('unknown_column', $cols) );
  17. $this->assertEquals( '', sanitize_sql_orderby('+unknown_column', $cols) );
  18. $this->assertEquals( '', sanitize_sql_orderby('-unknown_column', $cols) );
  19. $this->assertEquals( '', sanitize_sql_orderby('-unknown1,+unknown2,unknown3', $cols) );
  20. $this->assertEquals( 'post_name ASC', sanitize_sql_orderby('name,unknown_column', $cols) );
  21. $this->assertEquals( '', sanitize_sql_orderby('!@#$%^&*()_=~`\'",./', $cols) );
  22. }
  23. function test_valid() {
  24. $cols = array('name' => 'post_name', 'date' => 'post_date', 'random' => 'rand()');
  25. $this->assertEquals( 'post_name ASC', sanitize_sql_orderby('name', $cols) );
  26. $this->assertEquals( 'post_name ASC', sanitize_sql_orderby('+name', $cols) );
  27. $this->assertEquals( 'post_name DESC', sanitize_sql_orderby('-name', $cols) );
  28. $this->assertEquals( 'post_date ASC, post_name ASC', sanitize_sql_orderby('date,name', $cols) );
  29. $this->assertEquals( 'post_date ASC, post_name ASC', sanitize_sql_orderby(' date , name ', $cols) );
  30. $this->assertEquals( 'post_name DESC, post_date ASC', sanitize_sql_orderby('-name,date', $cols) );
  31. $this->assertEquals( 'post_name ASC, post_date ASC', sanitize_sql_orderby('name ,+ date', $cols) );
  32. $this->assertEquals( 'rand() ASC', sanitize_sql_orderby('random', $cols) );
  33. }
  34. }
  35. */