mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
This aims to bring more consistency to the test suite, as the vast majority of data providers already use that prefix. Includes moving some data providers next to the tests they are used in. Follow-up to [55464]. See #57841. git-svn-id: https://develop.svn.wordpress.org/trunk@55562 602fd350-edb4-49c9-b593-d223f7449a82
58 lines
1.4 KiB
PHP
58 lines
1.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group sanitize_sql_orderby
|
|
*
|
|
* @covers ::sanitize_sql_orderby
|
|
*/
|
|
class Tests_Formatting_SanitizeOrderby extends WP_UnitTestCase {
|
|
|
|
/**
|
|
* @dataProvider data_sanitize_sql_orderby_valid
|
|
*/
|
|
public function test_sanitize_sql_orderby_valid( $orderby ) {
|
|
$this->assertSame( $orderby, sanitize_sql_orderby( $orderby ) );
|
|
}
|
|
public function data_sanitize_sql_orderby_valid() {
|
|
return array(
|
|
array( '1' ),
|
|
array( '1 ASC' ),
|
|
array( '1 ASC, 2' ),
|
|
array( '1 ASC, 2 DESC' ),
|
|
array( '1 ASC, 2 DESC, 3' ),
|
|
array( ' 1 DESC' ),
|
|
array( 'field ASC' ),
|
|
array( 'field1 ASC, field2' ),
|
|
array( 'field_1 ASC, field_2 DESC' ),
|
|
array( 'field1, field2 ASC' ),
|
|
array( '`field1`' ),
|
|
array( '`field1` ASC' ),
|
|
array( '`field` ASC, `field2`' ),
|
|
array( 'RAND()' ),
|
|
array( ' RAND( ) ' ),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider data_sanitize_sql_orderby_invalid
|
|
*/
|
|
public function test_sanitize_sql_orderby_invalid( $orderby ) {
|
|
$this->assertFalse( sanitize_sql_orderby( $orderby ) );
|
|
}
|
|
public function data_sanitize_sql_orderby_invalid() {
|
|
return array(
|
|
array( '' ),
|
|
array( '1 2' ),
|
|
array( '1, 2 3' ),
|
|
array( '1 DESC, ' ),
|
|
array( 'field-1' ),
|
|
array( 'field DESC,' ),
|
|
array( 'field1 field2' ),
|
|
array( 'field RAND()' ),
|
|
array( 'RAND() ASC' ),
|
|
array( '`field1` ASC, `field2' ),
|
|
array( 'field, !@#$%^' ),
|
|
);
|
|
}
|
|
}
|