| 113 | /** |
| 114 | * @ticket 31316 |
| 115 | */ |
| 116 | function test_wp_list_pluck_non_indexed_keys() { |
| 117 | |
| 118 | /** |
| 119 | * A non-sequential array of objects, sometimes returned from get_the_terms. |
| 120 | */ |
| 121 | $test_indexed_array = array( |
| 122 | 3 => array( |
| 123 | 'term_id' => 3, |
| 124 | 'name' => 'Test', |
| 125 | 'slug' => 'test', |
| 126 | ), |
| 127 | 5 => array( |
| 128 | 'term_id' => 5, |
| 129 | 'name' => 'Foo', |
| 130 | 'slug' => 'foo', |
| 131 | ), |
| 132 | 13 => array( |
| 133 | 'term_id' => 13, |
| 134 | 'name' => 'Bar', |
| 135 | 'slug' => 'bar', |
| 136 | ), |
| 137 | ); |
| 138 | |
| 139 | /** |
| 140 | * Test a indexed array for good measure. |
| 141 | */ |
| 142 | $test_non_indexed_array = array( |
| 143 | array( |
| 144 | 'term_id' => 3, |
| 145 | 'name' => 'Test', |
| 146 | 'slug' => 'test', |
| 147 | ), |
| 148 | array( |
| 149 | 'term_id' => 5, |
| 150 | 'name' => 'Foo', |
| 151 | 'slug' => 'foo', |
| 152 | ), |
| 153 | array( |
| 154 | 'term_id' => 13, |
| 155 | 'name' => 'Bar', |
| 156 | 'slug' => 'bar', |
| 157 | ), |
| 158 | ); |
| 159 | |
| 160 | /** |
| 161 | * wp_list_pluck should return the array of found values. |
| 162 | */ |
| 163 | $expected = array( 'test', 'foo', 'bar' ); |
| 164 | |
| 165 | /** |
| 166 | * This works fine with the non indexed array. |
| 167 | */ |
| 168 | $plucked = wp_list_pluck( $test_non_indexed_array, 'slug' ); |
| 169 | $this->assertEquals( $expected, $plucked ); |
| 170 | |
| 171 | /** |
| 172 | * This fails with the indexed array. |
| 173 | */ |
| 174 | $plucked = wp_list_pluck( $test_indexed_array, 'slug' ); |
| 175 | $this->assertEquals( $expected, $plucked ); |
| 176 | } |
| 177 | |