14 | | $this->array_list['foo'] = array( 'name' => 'foo', 'field1' => true, 'field2' => true, 'field3' => true, 'field4' => array( 'red' ) ); |
15 | | $this->array_list['bar'] = array( 'name' => 'bar', 'field1' => true, 'field2' => true, 'field3' => false, 'field4' => array( 'green' ) ); |
16 | | $this->array_list['baz'] = array( 'name' => 'baz', 'field1' => true, 'field2' => false, 'field3' => false, 'field4' => array( 'blue' ) ); |
| 14 | $this->array_list['foo'] = array( 'name' => 'foo', 'id' => 'f', 'field1' => true, 'field2' => true, 'field3' => true, 'field4' => array( 'red' ) ); |
| 15 | $this->array_list['bar'] = array( 'name' => 'bar', 'id' => 'b', 'field1' => true, 'field2' => true, 'field3' => false, 'field4' => array( 'green' ) ); |
| 16 | $this->array_list['baz'] = array( 'name' => 'baz', 'id' => 'z', 'field1' => true, 'field2' => false, 'field3' => false, 'field4' => array( 'blue' ) ); |
| 69 | /** |
| 70 | * @ticket 28666 |
| 71 | */ |
| 72 | function test_wp_list_pluck_index_key() { |
| 73 | $list = wp_list_pluck( $this->array_list, 'name', 'id' ); |
| 74 | $this->assertEquals( array( 'f' => 'foo', 'b' => 'bar', 'z' => 'baz' ), $list ); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @ticket 28666 |
| 79 | */ |
| 80 | function test_wp_list_pluck_object_index_key() { |
| 81 | $list = wp_list_pluck( $this->object_list, 'name', 'id' ); |
| 82 | $this->assertEquals( array( 'f' => 'foo', 'b' => 'bar', 'z' => 'baz' ), $list ); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @ticket 28666 |
| 87 | */ |
| 88 | function test_wp_list_pluck_missing_index_key() { |
| 89 | $list = wp_list_pluck( $this->array_list, 'name', 'nonexistent' ); |
| 90 | $this->assertEquals( array( 0 => 'foo', 1 => 'bar', 2 => 'baz' ), $list ); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @ticket 28666 |
| 95 | */ |
| 96 | function test_wp_list_pluck_partial_missing_index_key() { |
| 97 | $array_list = $this->array_list; |
| 98 | unset( $array_list[ 'bar']['id'] ); |
| 99 | $list = wp_list_pluck( $array_list, 'name', 'id' ); |
| 100 | $this->assertEquals( array( 'f' => 'foo', 0 => 'bar', 'z' => 'baz' ), $list ); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * @ticket 28666 |
| 105 | */ |
| 106 | function test_wp_list_pluck_mixed_index_key() { |
| 107 | $mixed_list = $this->array_list; |
| 108 | $mixed_list['bar'] = (object) $mixed_list['bar']; |
| 109 | $list = wp_list_pluck( $mixed_list, 'name', 'id' ); |
| 110 | $this->assertEquals( array( 'f' => 'foo', 'b' => 'bar', 'z' => 'baz' ), $list ); |
| 111 | } |
| 112 | |