Changeset 62797 for trunk/tests/phpunit/tests/functions/wpParseList.php
- Timestamp:
- 07/19/2026 04:53:46 PM (7 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/functions/wpParseList.php
r57737 r62797 14 14 * 15 15 * @dataProvider data_wp_parse_list 16 * 17 * @param mixed[]|string $input_list 18 * @param array<scalar> $expected 16 19 */ 17 public function test_wp_parse_list( $input_list, $expected ) { 18 $this->assertSameSets( $expected, wp_parse_list( $input_list ) ); 20 public function test_wp_parse_list( $input_list, array $expected ): void { 21 $parsed_list = wp_parse_list( $input_list ); 22 $this->assertThat( 23 $parsed_list, 24 $this->callback( 25 static fn ( array $arr ) => array_all( 26 $arr, 27 static fn ( $v ) => is_scalar( $v ) 28 ) 29 ), 30 'Array should contain only scalars.' 31 ); 32 $this->assertSame( $expected, $parsed_list ); 19 33 } 20 34 … … 22 36 * Data provider. 23 37 * 24 * @return array []38 * @return array<string, array{ input_list: mixed[]|string, expected: array<scalar> }> 25 39 */ 26 public function data_wp_parse_list() {40 public function data_wp_parse_list(): array { 27 41 return array( 28 'ids only' => array(42 'ids only' => array( 29 43 'input_list' => '1,2,3,4', 30 44 'expected' => array( '1', '2', '3', '4' ), 31 45 ), 32 'slugs only' => array(46 'slugs only' => array( 33 47 'input_list' => 'apple,banana,carrot,dog', 34 48 'expected' => array( 'apple', 'banana', 'carrot', 'dog' ), 35 49 ), 36 'ids and slugs' => array(50 'ids and slugs' => array( 37 51 'input_list' => '1,2,apple,banana', 38 52 'expected' => array( '1', '2', 'apple', 'banana' ), 39 53 ), 40 'space after comma' => array(54 'space after comma' => array( 41 55 'input_list' => '1, 2,apple,banana', 42 56 'expected' => array( '1', '2', 'apple', 'banana' ), 43 57 ), 44 'double comma' => array(58 'double comma' => array( 45 59 'input_list' => '1,2,apple,,banana', 46 60 'expected' => array( '1', '2', 'apple', 'banana' ), 47 61 ), 48 'leading comma' => array(62 'leading comma' => array( 49 63 'input_list' => ',1,2,apple,banana', 50 64 'expected' => array( '1', '2', 'apple', 'banana' ), 51 65 ), 52 'trailing comma' => array(66 'trailing comma' => array( 53 67 'input_list' => '1,2,apple,banana,', 54 68 'expected' => array( '1', '2', 'apple', 'banana' ), 55 69 ), 56 'space before comma' => array(70 'space before comma' => array( 57 71 'input_list' => '1,2 ,apple,banana', 58 72 'expected' => array( '1', '2', 'apple', 'banana' ), 59 73 ), 60 'empty string' => array(74 'empty string' => array( 61 75 'input_list' => '', 62 76 'expected' => array(), 63 77 ), 64 'comma only' => array(78 'comma only' => array( 65 79 'input_list' => ',', 66 80 'expected' => array(), 67 81 ), 68 'double comma only' => array(82 'double comma only' => array( 69 83 'input_list' => ',,', 70 84 'expected' => array(), 85 ), 86 'passed scalar array' => array( 87 'input_list' => array( 'foo', true, false, 1, 3.14 ), 88 'expected' => array( 'foo', true, false, 1, 3.14 ), 89 ), 90 'passed mixed array' => array( 91 'input_list' => array( null, 'foo', array(), true, new stdClass(), false, 1, 3.14 ), 92 'expected' => array( 93 1 => 'foo', 94 3 => true, 95 5 => false, 96 6 => 1, 97 7 => 3.14, 98 ), 99 ), 100 'passed assoc array' => array( 101 'input_list' => array( 102 'foo' => 1, 103 'bar' => true, 104 'baz' => 3.14, 105 ), 106 'expected' => array( 107 'foo' => 1, 108 'bar' => true, 109 'baz' => 3.14, 110 ), 71 111 ), 72 112 );
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)