forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapDeep.php
More file actions
63 lines (50 loc) · 2.28 KB
/
MapDeep.php
File metadata and controls
63 lines (50 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* @group formatting
* @ticket 22300
*/
class Tests_Formatting_MapDeep extends WP_UnitTestCase {
function setUp() {
if ( ! function_exists( 'map_deep' ) ) {
$this->markTestSkipped( "map_deep function doesn't exist" );
}
parent::setUp();
}
function test_map_deep_with_any_function_over_empty_array_should_return_empty_array() {
$this->assertEquals( array(), map_deep( array( $this, 'return_baba' ), array() ) );
}
function test_map_deep_should_map_each_element_of_array_one_level_deep() {
$this->assertEquals( array( 'ababa', 'xbaba' ), map_deep( array( $this, 'append_baba' ), array( 'a', 'x' ) ) );
}
function test_map_deep_should_map_each_element_of_array_two_levels_deep() {
$this->assertEquals( array( 'ababa', array( 'xbaba' ) ), map_deep( array( $this, 'append_baba' ), array( 'a', array( 'x' ) ) ) );
}
function test_map_deep_should_map_each_object_element_of_an_array() {
$this->assertEquals( array( 'var0' => 'ababa', 'var1' => (object)array( 'xbaba' ) ),
map_deep( array( $this, 'append_baba' ), array( 'var0' => 'a', 'var1' => (object)array( 'x' ) ) ) );
}
function test_map_deep_should_apply_the_function_to_a_string() {
$this->assertEquals( 'xbaba', map_deep( array( $this, 'append_baba' ), 'x' ) );
}
function test_map_deep_should_apply_the_function_to_an_integer() {
$this->assertEquals( '5baba' , map_deep( array( $this, 'append_baba' ), 5 ) );
}
function test_map_deep_should_map_each_property_of_an_object() {
$this->assertEquals( (object)array( 'var0' => 'ababa', 'var1' => 'xbaba' ),
map_deep( array( $this, 'append_baba' ), (object)array( 'var0' => 'a', 'var1' => 'x' ) ) );
}
function test_map_deep_should_map_each_array_property_of_an_object() {
$this->assertEquals( (object)array( 'var0' => 'ababa', 'var1' => array( 'xbaba' ) ),
map_deep( array( $this, 'append_baba' ), (object)array( 'var0' => 'a', 'var1' => array( 'x' ) ) ) );
}
function test_map_deep_should_map_each_object_property_of_an_object() {
$this->assertEquals( (object)array( 'var0' => 'ababa', 'var1' => (object)array( 'xbaba' ) ),
map_deep( array( $this, 'append_baba' ), (object)array( 'var0' => 'a', 'var1' => (object)array( 'x' ) ) ) );
}
function return_baba( $value ) {
return 'baba';
}
function append_baba( $value ) {
return $value . 'baba';
}
}