Changeset 51663 for trunk/tests/phpunit/tests/functions/wpListFilter.php
- Timestamp:
- 08/26/2021 03:54:29 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/functions/wpListFilter.php
r51568 r51663 2 2 3 3 /** 4 * Test wp_filter_object_list() , wp_list_filter(), wp_list_pluck().4 * Test wp_filter_object_list(). 5 5 * 6 6 * @group functions.php 7 7 * @covers ::wp_filter_object_list 8 * @covers ::wp_list_pluck9 8 */ 10 9 class Tests_Functions_wpListFilter extends WP_UnitTestCase { … … 136 135 } 137 136 138 function test_wp_list_pluck() {139 $list = wp_list_pluck( $this->object_list, 'name' );140 $this->assertSame(141 array(142 'foo' => 'foo',143 'bar' => 'bar',144 'baz' => 'baz',145 ),146 $list147 );148 149 $list = wp_list_pluck( $this->array_list, 'name' );150 $this->assertSame(151 array(152 'foo' => 'foo',153 'bar' => 'bar',154 'baz' => 'baz',155 ),156 $list157 );158 }159 160 /**161 * @ticket 28666162 */163 function test_wp_list_pluck_index_key() {164 $list = wp_list_pluck( $this->array_list, 'name', 'id' );165 $this->assertSame(166 array(167 'f' => 'foo',168 'b' => 'bar',169 'z' => 'baz',170 ),171 $list172 );173 }174 175 /**176 * @ticket 28666177 */178 function test_wp_list_pluck_object_index_key() {179 $list = wp_list_pluck( $this->object_list, 'name', 'id' );180 $this->assertSame(181 array(182 'f' => 'foo',183 'b' => 'bar',184 'z' => 'baz',185 ),186 $list187 );188 }189 190 /**191 * @ticket 28666192 */193 function test_wp_list_pluck_missing_index_key() {194 $list = wp_list_pluck( $this->array_list, 'name', 'nonexistent' );195 $this->assertSame(196 array(197 0 => 'foo',198 1 => 'bar',199 2 => 'baz',200 ),201 $list202 );203 }204 205 /**206 * @ticket 28666207 */208 function test_wp_list_pluck_partial_missing_index_key() {209 $array_list = $this->array_list;210 unset( $array_list['bar']['id'] );211 $list = wp_list_pluck( $array_list, 'name', 'id' );212 $this->assertSame(213 array(214 'f' => 'foo',215 0 => 'bar',216 'z' => 'baz',217 ),218 $list219 );220 }221 222 /**223 * @ticket 28666224 */225 function test_wp_list_pluck_mixed_index_key() {226 $mixed_list = $this->array_list;227 $mixed_list['bar'] = (object) $mixed_list['bar'];228 $list = wp_list_pluck( $mixed_list, 'name', 'id' );229 $this->assertSame(230 array(231 'f' => 'foo',232 'b' => 'bar',233 'z' => 'baz',234 ),235 $list236 );237 }238 239 /**240 * @ticket 16895241 */242 function test_wp_list_pluck_containing_references() {243 $ref_list = array(244 & $this->object_list['foo'],245 & $this->object_list['bar'],246 );247 248 $this->assertInstanceOf( 'stdClass', $ref_list[0] );249 $this->assertInstanceOf( 'stdClass', $ref_list[1] );250 251 $list = wp_list_pluck( $ref_list, 'name' );252 $this->assertSame(253 array(254 'foo',255 'bar',256 ),257 $list258 );259 260 $this->assertInstanceOf( 'stdClass', $ref_list[0] );261 $this->assertInstanceOf( 'stdClass', $ref_list[1] );262 }263 264 /**265 * @ticket 16895266 */267 function test_wp_list_pluck_containing_references_keys() {268 $ref_list = array(269 & $this->object_list['foo'],270 & $this->object_list['bar'],271 );272 273 $this->assertInstanceOf( 'stdClass', $ref_list[0] );274 $this->assertInstanceOf( 'stdClass', $ref_list[1] );275 276 $list = wp_list_pluck( $ref_list, 'name', 'id' );277 $this->assertSame(278 array(279 'f' => 'foo',280 'b' => 'bar',281 ),282 $list283 );284 285 $this->assertInstanceOf( 'stdClass', $ref_list[0] );286 $this->assertInstanceOf( 'stdClass', $ref_list[1] );287 }288 289 137 function test_filter_object_list_nested_array_and() { 290 138 $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'blue' ) ), 'AND' );
Note: See TracChangeset
for help on using the changeset viewer.