mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Follow-up to [42971], [45371], [46159], [46175], [47779], [50962], [50964], [51910], [52778]. Props azouamauriac, SergeyBiryukov. See #54725. git-svn-id: https://develop.svn.wordpress.org/trunk@52780 602fd350-edb4-49c9-b593-d223f7449a82
286 lines
3.7 KiB
PHP
286 lines
3.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Tests for the _wp_array_get() function
|
|
*
|
|
* @since 5.6.0
|
|
*
|
|
* @group functions.php
|
|
* @covers ::_wp_array_get
|
|
*/
|
|
class Tests_Functions_wpArrayGet extends WP_UnitTestCase {
|
|
|
|
/**
|
|
* Tests _wp_array_get() with invalid parameters.
|
|
*
|
|
* @ticket 51720
|
|
*/
|
|
public function test_wp_array_get_invalid_parameters() {
|
|
$this->assertSame(
|
|
_wp_array_get(
|
|
null,
|
|
array( 'a' )
|
|
),
|
|
null
|
|
);
|
|
|
|
$this->assertSame(
|
|
_wp_array_get(
|
|
array(
|
|
'key' => 4,
|
|
),
|
|
null
|
|
),
|
|
null
|
|
);
|
|
|
|
$this->assertSame(
|
|
_wp_array_get(
|
|
array(
|
|
'key' => 4,
|
|
),
|
|
array()
|
|
),
|
|
null
|
|
);
|
|
|
|
$this->assertSame(
|
|
_wp_array_get(
|
|
array(
|
|
'key' => 4,
|
|
),
|
|
array(),
|
|
true
|
|
),
|
|
true
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Tests _wp_array_get() with non-subtree paths.
|
|
*
|
|
* @ticket 51720
|
|
*/
|
|
public function test_wp_array_get_simple_non_subtree() {
|
|
// Simple non-subtree test.
|
|
$this->assertSame(
|
|
_wp_array_get(
|
|
array(
|
|
'key' => 4,
|
|
),
|
|
array( 'key' )
|
|
),
|
|
4
|
|
);
|
|
|
|
// Simple non-subtree not found.
|
|
$this->assertSame(
|
|
_wp_array_get(
|
|
array(
|
|
'key' => 4,
|
|
),
|
|
array( 'invalid' )
|
|
),
|
|
null
|
|
);
|
|
|
|
// Simple non-subtree not found with a default.
|
|
$this->assertSame(
|
|
_wp_array_get(
|
|
array(
|
|
'key' => 4,
|
|
),
|
|
array( 'invalid' ),
|
|
1
|
|
),
|
|
1
|
|
);
|
|
|
|
// Simple non-subtree integer path.
|
|
$this->assertSame(
|
|
_wp_array_get(
|
|
array(
|
|
'a',
|
|
'b',
|
|
'c',
|
|
),
|
|
array( 1 )
|
|
),
|
|
'b'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Tests _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
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Tests _wp_array_get() with zero strings.
|
|
*
|
|
* @ticket 51720
|
|
*/
|
|
public function test_wp_array_get_handle_zeros() {
|
|
$this->assertSame(
|
|
_wp_array_get(
|
|
array(
|
|
'-0' => 'a',
|
|
'0' => 'b',
|
|
),
|
|
array( 0 )
|
|
),
|
|
'b'
|
|
);
|
|
|
|
$this->assertSame(
|
|
_wp_array_get(
|
|
array(
|
|
'-0' => 'a',
|
|
'0' => 'b',
|
|
),
|
|
array( -0 )
|
|
),
|
|
'b'
|
|
);
|
|
|
|
$this->assertSame(
|
|
_wp_array_get(
|
|
array(
|
|
'-0' => 'a',
|
|
'0' => 'b',
|
|
),
|
|
array( '-0' )
|
|
),
|
|
'a'
|
|
);
|
|
|
|
$this->assertSame(
|
|
_wp_array_get(
|
|
array(
|
|
'-0' => 'a',
|
|
'0' => 'b',
|
|
),
|
|
array( '0' )
|
|
),
|
|
'b'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Tests _wp_array_get() with null values.
|
|
*
|
|
* @ticket 51720
|
|
*/
|
|
public function test_wp_array_get_null() {
|
|
$this->assertSame(
|
|
_wp_array_get(
|
|
array(
|
|
'key' => null,
|
|
),
|
|
array( 'key' ),
|
|
true
|
|
),
|
|
null
|
|
);
|
|
|
|
$this->assertSame(
|
|
_wp_array_get(
|
|
array(
|
|
'key' => null,
|
|
),
|
|
array( 'key', 'subkey' ),
|
|
true
|
|
),
|
|
true
|
|
);
|
|
|
|
$this->assertSame(
|
|
_wp_array_get(
|
|
array(
|
|
'key' => array(
|
|
null => 4,
|
|
),
|
|
),
|
|
array( 'key', null ),
|
|
true
|
|
),
|
|
4
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Tests _wp_array_get() with empty paths.
|
|
*
|
|
* @ticket 51720
|
|
*/
|
|
public function test_wp_array_get_empty_paths() {
|
|
$this->assertSame(
|
|
_wp_array_get(
|
|
array(
|
|
'a' => 4,
|
|
),
|
|
array()
|
|
),
|
|
null
|
|
);
|
|
|
|
$this->assertSame(
|
|
_wp_array_get(
|
|
array(
|
|
'a' => array(
|
|
'b' => array(
|
|
'c' => 1,
|
|
),
|
|
),
|
|
),
|
|
array( 'a', 'b', array() )
|
|
),
|
|
null
|
|
);
|
|
}
|
|
}
|