General: Some documentation and test improvements for the _wp_array_set():

* Update the function DocBlock per the documentation standards.
* Move the unit tests to a more appropriate place.
* Rename and reorder the tests for consistency with `_wp_array_get()` tests.

Follow-up to [50958], [50962], [50964].

See #53175, #52625.

git-svn-id: https://develop.svn.wordpress.org/trunk@50965 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2021-05-24 12:24:14 +00:00
parent cea9485383
commit fa0fca4670
3 changed files with 119 additions and 111 deletions
+54 -55
View File
@@ -57,12 +57,12 @@ class Tests_Functions_wpArrayGet extends WP_UnitTestCase {
}
/**
* Test _wp_array_get() with non subtree paths.
* Test _wp_array_get() with non-subtree paths.
*
* @ticket 51720
*/
public function test_wp_array_get_simple_non_subtree() {
// Simple non sub tree test.
// Simple non-subtree test.
$this->assertSame(
_wp_array_get(
array(
@@ -73,7 +73,7 @@ class Tests_Functions_wpArrayGet extends WP_UnitTestCase {
4
);
// Simple non sub tree not found.
// Simple non-subtree not found.
$this->assertSame(
_wp_array_get(
array(
@@ -84,7 +84,7 @@ class Tests_Functions_wpArrayGet extends WP_UnitTestCase {
null
);
// Simple non sub tree not found with a default.
// Simple non-subtree not found with a default.
$this->assertSame(
_wp_array_get(
array(
@@ -96,7 +96,7 @@ class Tests_Functions_wpArrayGet extends WP_UnitTestCase {
1
);
// Simple non sub tree integer path.
// Simple non-subtree integer path.
$this->assertSame(
_wp_array_get(
array(
@@ -110,6 +110,55 @@ class Tests_Functions_wpArrayGet extends WP_UnitTestCase {
);
}
/**
* Test _wp_array_get() with subtrees.
*
* @ticket 51720
*/
public function test_wp_array_get_subtree() {
$this->assertSame(
_wp_array_get(
array(
'a' => array(
'b' => array(
'c' => 1,
),
),
),
array( 'a', 'b' )
),
array( 'c' => 1 )
);
$this->assertSame(
_wp_array_get(
array(
'a' => array(
'b' => array(
'c' => 1,
),
),
),
array( 'a', 'b', 'c' )
),
1
);
$this->assertSame(
_wp_array_get(
array(
'a' => array(
'b' => array(
'c' => 1,
),
),
),
array( 'a', 'b', 'c', 'd' )
),
null
);
}
/**
* Test _wp_array_get() with zero strings.
*
@@ -161,56 +210,6 @@ class Tests_Functions_wpArrayGet extends WP_UnitTestCase {
);
}
/**
* Test _wp_array_get() with subtrees.
*
* @ticket 51720
*/
public function test_wp_array_get_subtree() {
$this->assertSame(
_wp_array_get(
array(
'a' => array(
'b' => array(
'c' => 1,
),
),
),
array( 'a', 'b' )
),
array( 'c' => 1 )
);
$this->assertSame(
_wp_array_get(
array(
'a' => array(
'b' => array(
'c' => 1,
),
),
),
array( 'a', 'b', 'c' )
),
1
);
$this->assertSame(
_wp_array_get(
array(
'a' => array(
'b' => array(
'c' => 1,
),
),
),
array( 'a', 'b', 'c', 'd' )
),
null
);
}
/**
* Test _wp_array_get() with null values.
*
@@ -1,22 +1,63 @@
<?php
/**
* _wp_array_set.
*
* @package WordPress
*/
/**
* Test _wp_array_set function.
* Tests for the _wp_array_get() function
*
* @package WordPress
* @since 5.8.0
*
* @group functions.php
* @covers ::_wp_array_get
*/
class WP_Array_Set_Test extends WP_UnitTestCase {
class Tests_Functions_wpArraySet extends WP_UnitTestCase {
/**
* Test _wp_array_set() with simple non subtree path.
* Test _wp_array_set() with invalid parameters.
*
* @ticket 53175
*/
public function test_simple_not_subtree_set() {
public function test_wp_array_set_invalid_parameters() {
$test = 3;
_wp_array_set( $test, array( 'a' ), 1 );
$this->assertSame(
$test,
3
);
$test_array = array( 'a' => 2 );
_wp_array_set( $test_array, 'a', 3 );
$this->assertSame(
$test_array,
array( 'a' => 2 )
);
$test_array = array( 'a' => 2 );
_wp_array_set( $test_array, null, 3 );
$this->assertSame(
$test_array,
array( 'a' => 2 )
);
$test_array = array( 'a' => 2 );
_wp_array_set( $test_array, array(), 3 );
$this->assertSame(
$test_array,
array( 'a' => 2 )
);
$test_array = array( 'a' => 2 );
_wp_array_set( $test_array, array( 'a', array() ), 3 );
$this->assertSame(
$test_array,
array( 'a' => 2 )
);
}
/**
* Test _wp_array_set() with simple non-subtree path.
*
* @ticket 53175
*/
public function test_wp_array_set_simple_non_subtree() {
$test_array = array();
_wp_array_set( $test_array, array( 'a' ), 1 );
$this->assertSame(
@@ -47,7 +88,7 @@ class WP_Array_Set_Test extends WP_UnitTestCase {
*
* @ticket 53175
*/
public function test_subtree_set() {
public function test_wp_array_set_subtree() {
$test_array = array();
_wp_array_set( $test_array, array( 'a', 'b', 'c' ), 1 );
$this->assertSame(
@@ -91,46 +132,4 @@ class WP_Array_Set_Test extends WP_UnitTestCase {
)
);
}
/**
* Test _wp_array_set() with invalid parameters.
*
* @ticket 53175
*/
public function test_invalid_parameters_set() {
$test = 3;
_wp_array_set( $test, array( 'a' ), 1 );
$this->assertSame(
$test,
3
);
$test_array = array( 'a' => 2 );
_wp_array_set( $test_array, 'a', 3 );
$this->assertSame(
$test_array,
array( 'a' => 2 )
);
$test_array = array( 'a' => 2 );
_wp_array_set( $test_array, null, 3 );
$this->assertSame(
$test_array,
array( 'a' => 2 )
);
$test_array = array( 'a' => 2 );
_wp_array_set( $test_array, array(), 3 );
$this->assertSame(
$test_array,
array( 'a' => 2 )
);
$test_array = array( 'a' => 2 );
_wp_array_set( $test_array, array( 'a', array() ), 3 );
$this->assertSame(
$test_array,
array( 'a' => 2 )
);
}
}