wordpress-develop/tests/phpunit/tests/formatting/sanitizeOrderby.php
Tonya Mork 40ac5de838 Coding Standards: Add visibility to methods in tests/phpunit/tests/.
Adds a `public` visibility to test fixtures, tests, data providers, and callbacks methods.

Adds a `private` visibility to helper methods within test classes.

Renames callbacks and helpers that previously started with a `_` prefix. Why? For consistency and to leverage using the method visibility. Further naming standardizations is beyond the scope of this commit.

Props costdev, jrf, hellofromTonya.
Fixes #54177.

git-svn-id: https://develop.svn.wordpress.org/trunk@52010 602fd350-edb4-49c9-b593-d223f7449a82
2021-11-04 15:22:47 +00:00

58 lines
1.3 KiB
PHP

<?php
/**
* @group sanitize_sql_orderby
*/
class Tests_Formatting_SanitizeOrderby extends WP_UnitTestCase {
/**
* @covers ::sanitize_sql_orderby
* @dataProvider valid_orderbys
*/
public function test_valid( $orderby ) {
$this->assertSame( $orderby, sanitize_sql_orderby( $orderby ) );
}
public function valid_orderbys() {
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( ) ' ),
);
}
/**
* @covers ::sanitize_sql_orderby
* @dataProvider invalid_orderbys
*/
public function test_invalid( $orderby ) {
$this->assertFalse( sanitize_sql_orderby( $orderby ) );
}
public function invalid_orderbys() {
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, !@#$%^' ),
);
}
}