Tests: Move wp_list_filter() tests to their own file.

This matches the name of the function being tested.

Follow-up to [38928], [51663-51665].

See #53363, #53987.

git-svn-id: https://develop.svn.wordpress.org/trunk@51666 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2021-08-26 16:20:57 +00:00
parent b683b830ab
commit cd1f879ced
2 changed files with 215 additions and 207 deletions

View File

@ -0,0 +1,215 @@
<?php
/**
* Test wp_list_filter().
*
* @group functions.php
* @covers ::wp_list_filter
*/
class Tests_Functions_wpListFilter extends WP_UnitTestCase {
/**
* @dataProvider data_test_wp_list_filter
*
* @param array $list An array of objects to filter.
* @param array $args An array of key => value arguments to match
* against each object.
* @param string $operator The logical operation to perform.
* @param array $expected Expected result.
*/
public function test_wp_list_filter( $list, $args, $operator, $expected ) {
$this->assertEqualSetsWithIndex( $expected, wp_list_filter( $list, $args, $operator ) );
}
public function data_test_wp_list_filter() {
return array(
'string instead of array' => array(
'foo',
array(),
'AND',
array(),
),
'object instead of array' => array(
(object) array( 'foo' ),
array(),
'AND',
array(),
),
'empty args' => array(
array( 'foo', 'bar' ),
array(),
'AND',
array( 'foo', 'bar' ),
),
'invalid operator' => array(
array(
(object) array( 'foo' => 'bar' ),
(object) array( 'foo' => 'baz' ),
),
array( 'foo' => 'bar' ),
'XOR',
array(),
),
'single argument to match' => array(
array(
(object) array(
'foo' => 'bar',
'bar' => 'baz',
'abc' => 'xyz',
'key' => 'foo',
),
(object) array(
'foo' => 'foo',
'123' => '456',
'lorem' => 'ipsum',
'key' => 'bar',
),
(object) array(
'foo' => 'baz',
'key' => 'value',
),
(object) array(
'foo' => 'bar',
'key' => 'value',
),
),
array( 'foo' => 'bar' ),
'AND',
array(
0 => (object) array(
'foo' => 'bar',
'bar' => 'baz',
'abc' => 'xyz',
'key' => 'foo',
),
3 => (object) array(
'foo' => 'bar',
'key' => 'value',
),
),
),
'all must match' => array(
array(
(object) array(
'foo' => 'bar',
'bar' => 'baz',
'abc' => 'xyz',
'key' => 'foo',
),
(object) array(
'foo' => 'foo',
'123' => '456',
'lorem' => 'ipsum',
'key' => 'bar',
),
(object) array(
'foo' => 'baz',
'key' => 'value',
'bar' => 'baz',
),
(object) array(
'foo' => 'bar',
'key' => 'value',
),
),
array(
'foo' => 'bar',
'bar' => 'baz',
),
'AND',
array(
0 => (object) array(
'foo' => 'bar',
'bar' => 'baz',
'abc' => 'xyz',
'key' => 'foo',
),
),
),
'any must match' => array(
array(
(object) array(
'foo' => 'bar',
'bar' => 'baz',
'abc' => 'xyz',
'key' => 'foo',
),
(object) array(
'foo' => 'foo',
'123' => '456',
'lorem' => 'ipsum',
'key' => 'bar',
),
(object) array(
'foo' => 'baz',
'key' => 'value',
'bar' => 'baz',
),
(object) array(
'foo' => 'bar',
'key' => 'value',
),
),
array(
'key' => 'value',
'bar' => 'baz',
),
'OR',
array(
0 => (object) array(
'foo' => 'bar',
'bar' => 'baz',
'abc' => 'xyz',
'key' => 'foo',
),
2 => (object) array(
'foo' => 'baz',
'key' => 'value',
'bar' => 'baz',
),
3 => (object) array(
'foo' => 'bar',
'key' => 'value',
),
),
),
'none must match' => array(
array(
(object) array(
'foo' => 'bar',
'bar' => 'baz',
'abc' => 'xyz',
'key' => 'foo',
),
(object) array(
'foo' => 'foo',
'123' => '456',
'lorem' => 'ipsum',
'key' => 'bar',
),
(object) array(
'foo' => 'baz',
'key' => 'value',
),
(object) array(
'foo' => 'bar',
'key' => 'value',
),
),
array(
'key' => 'value',
'bar' => 'baz',
),
'NOT',
array(
1 => (object) array(
'foo' => 'foo',
'123' => '456',
'lorem' => 'ipsum',
'key' => 'bar',
),
),
),
);
}
}

View File

@ -5,213 +5,6 @@
*/
class Tests_Functions_wpListUtil extends WP_UnitTestCase {
public function data_test_wp_list_filter() {
return array(
'string instead of array' => array(
'foo',
array(),
'AND',
array(),
),
'object instead of array' => array(
(object) array( 'foo' ),
array(),
'AND',
array(),
),
'empty args' => array(
array( 'foo', 'bar' ),
array(),
'AND',
array( 'foo', 'bar' ),
),
'invalid operator' => array(
array(
(object) array( 'foo' => 'bar' ),
(object) array( 'foo' => 'baz' ),
),
array( 'foo' => 'bar' ),
'XOR',
array(),
),
'single argument to match' => array(
array(
(object) array(
'foo' => 'bar',
'bar' => 'baz',
'abc' => 'xyz',
'key' => 'foo',
),
(object) array(
'foo' => 'foo',
'123' => '456',
'lorem' => 'ipsum',
'key' => 'bar',
),
(object) array(
'foo' => 'baz',
'key' => 'value',
),
(object) array(
'foo' => 'bar',
'key' => 'value',
),
),
array( 'foo' => 'bar' ),
'AND',
array(
0 => (object) array(
'foo' => 'bar',
'bar' => 'baz',
'abc' => 'xyz',
'key' => 'foo',
),
3 => (object) array(
'foo' => 'bar',
'key' => 'value',
),
),
),
'all must match' => array(
array(
(object) array(
'foo' => 'bar',
'bar' => 'baz',
'abc' => 'xyz',
'key' => 'foo',
),
(object) array(
'foo' => 'foo',
'123' => '456',
'lorem' => 'ipsum',
'key' => 'bar',
),
(object) array(
'foo' => 'baz',
'key' => 'value',
'bar' => 'baz',
),
(object) array(
'foo' => 'bar',
'key' => 'value',
),
),
array(
'foo' => 'bar',
'bar' => 'baz',
),
'AND',
array(
0 => (object) array(
'foo' => 'bar',
'bar' => 'baz',
'abc' => 'xyz',
'key' => 'foo',
),
),
),
'any must match' => array(
array(
(object) array(
'foo' => 'bar',
'bar' => 'baz',
'abc' => 'xyz',
'key' => 'foo',
),
(object) array(
'foo' => 'foo',
'123' => '456',
'lorem' => 'ipsum',
'key' => 'bar',
),
(object) array(
'foo' => 'baz',
'key' => 'value',
'bar' => 'baz',
),
(object) array(
'foo' => 'bar',
'key' => 'value',
),
),
array(
'key' => 'value',
'bar' => 'baz',
),
'OR',
array(
0 => (object) array(
'foo' => 'bar',
'bar' => 'baz',
'abc' => 'xyz',
'key' => 'foo',
),
2 => (object) array(
'foo' => 'baz',
'key' => 'value',
'bar' => 'baz',
),
3 => (object) array(
'foo' => 'bar',
'key' => 'value',
),
),
),
'none must match' => array(
array(
(object) array(
'foo' => 'bar',
'bar' => 'baz',
'abc' => 'xyz',
'key' => 'foo',
),
(object) array(
'foo' => 'foo',
'123' => '456',
'lorem' => 'ipsum',
'key' => 'bar',
),
(object) array(
'foo' => 'baz',
'key' => 'value',
),
(object) array(
'foo' => 'bar',
'key' => 'value',
),
),
array(
'key' => 'value',
'bar' => 'baz',
),
'NOT',
array(
1 => (object) array(
'foo' => 'foo',
'123' => '456',
'lorem' => 'ipsum',
'key' => 'bar',
),
),
),
);
}
/**
* @dataProvider data_test_wp_list_filter
*
* @covers ::wp_list_filter
*
* @param array $list An array of objects to filter.
* @param array $args An array of key => value arguments to match
* against each object.
* @param string $operator The logical operation to perform.
* @param array $expected Expected result.
*/
public function test_wp_list_filter( $list, $args, $operator, $expected ) {
$this->assertEqualSetsWithIndex( $expected, wp_list_filter( $list, $args, $operator ) );
}
public function data_test_wp_list_sort() {
return array(
'single orderby ascending' => array(