Skip to content

Commit

Permalink
Tests: Move wp_parse_list() tests to their own file.
Browse files Browse the repository at this point in the history
This aims to make the tests more discoverable and easier to expand.

Follow-up to [44546].

See #59647.

git-svn-id: https://develop.svn.wordpress.org/trunk@57284 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Jan 14, 2024
1 parent 3d19b28 commit ba40e28
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
24 changes: 0 additions & 24 deletions tests/phpunit/tests/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -726,30 +726,6 @@ public function test_canonical_charset() {
update_option( 'blog_charset', $orig_blog_charset );
}

/**
* @ticket 43977
* @dataProvider data_wp_parse_list
*/
public function test_wp_parse_list( $expected, $actual ) {
$this->assertSame( $expected, array_values( wp_parse_list( $actual ) ) );
}

public function data_wp_parse_list() {
return array(
array( array( '1', '2', '3', '4' ), '1,2,3,4' ),
array( array( 'apple', 'banana', 'carrot', 'dog' ), 'apple,banana,carrot,dog' ),
array( array( '1', '2', 'apple', 'banana' ), '1,2,apple,banana' ),
array( array( '1', '2', 'apple', 'banana' ), '1, 2,apple,banana' ),
array( array( '1', '2', 'apple', 'banana' ), '1,2,apple,,banana' ),
array( array( '1', '2', 'apple', 'banana' ), ',1,2,apple,banana' ),
array( array( '1', '2', 'apple', 'banana' ), '1,2,apple,banana,' ),
array( array( '1', '2', 'apple', 'banana' ), '1,2 ,apple,banana' ),
array( array(), '' ),
array( array(), ',' ),
array( array(), ',,' ),
);
}

/**
* @dataProvider data_wp_parse_id_list
*/
Expand Down
35 changes: 35 additions & 0 deletions tests/phpunit/tests/functions/wpParseList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* Tests for the wp_parse_list() function.
*
* @group functions
*
* @covers ::wp_parse_list
*/
class Tests_Functions_wpParseList extends WP_UnitTestCase {

/**
* @ticket 43977
* @dataProvider data_wp_parse_list
*/
public function test_wp_parse_list( $expected, $actual ) {
$this->assertSame( $expected, array_values( wp_parse_list( $actual ) ) );
}

public function data_wp_parse_list() {
return array(
array( array( '1', '2', '3', '4' ), '1,2,3,4' ),
array( array( 'apple', 'banana', 'carrot', 'dog' ), 'apple,banana,carrot,dog' ),
array( array( '1', '2', 'apple', 'banana' ), '1,2,apple,banana' ),
array( array( '1', '2', 'apple', 'banana' ), '1, 2,apple,banana' ),
array( array( '1', '2', 'apple', 'banana' ), '1,2,apple,,banana' ),
array( array( '1', '2', 'apple', 'banana' ), ',1,2,apple,banana' ),
array( array( '1', '2', 'apple', 'banana' ), '1,2,apple,banana,' ),
array( array( '1', '2', 'apple', 'banana' ), '1,2 ,apple,banana' ),
array( array(), '' ),
array( array(), ',' ),
array( array(), ',,' ),
);
}
}

0 comments on commit ba40e28

Please sign in to comment.