Changeset 55423
- Timestamp:
- 02/25/2023 10:57:14 AM (23 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-list-util.php
r54855 r55423 167 167 if ( is_object( $value ) ) { 168 168 $newlist[ $key ] = $value->$field; 169 } elseif ( is_array( $value ) ) { 170 $newlist[ $key ] = $value[ $field ]; 169 171 } else { 170 $newlist[ $key ] = $value[ $field ]; 172 _doing_it_wrong( 173 __METHOD__, 174 __( 'Values for the input array must be either objects or arrays.' ), 175 '6.2.0' 176 ); 171 177 } 172 178 } … … 188 194 $newlist[] = $value->$field; 189 195 } 190 } else {196 } elseif ( is_array( $value ) ) { 191 197 if ( isset( $value[ $index_key ] ) ) { 192 198 $newlist[ $value[ $index_key ] ] = $value[ $field ]; … … 194 200 $newlist[] = $value[ $field ]; 195 201 } 202 } else { 203 _doing_it_wrong( 204 __METHOD__, 205 __( 'Values for the input array must be either objects or arrays.' ), 206 '6.2.0' 207 ); 196 208 } 197 209 } -
trunk/tests/phpunit/tests/functions/wpListUtil.php
r54855 r55423 86 86 87 87 /** 88 * Data provider for test_wp_list_util_pluck _simple().88 * Data provider for test_wp_list_util_pluck(). 89 89 * 90 90 * @return array[] … … 106 106 'expected' => array( 'bar' ), 107 107 ), 108 ); 109 } 110 111 /** 112 * Tests that wp_list_pluck() throws _doing_it_wrong() with invalid input. 113 * 114 * @ticket 56650 115 * 116 * @dataProvider data_wp_list_pluck_should_throw_doing_it_wrong_with_invalid_input 117 * 118 * @covers WP_List_Util::pluck 119 * @covers ::wp_list_pluck 120 * 121 * @expectedIncorrectUsage WP_List_Util::pluck 122 * 123 * @param array $input An invalid input array. 124 */ 125 public function test_wp_list_pluck_should_throw_doing_it_wrong_with_invalid_input( $input ) { 126 $this->assertSame( array(), wp_list_pluck( $input, 'a_field' ) ); 127 } 128 129 /** 130 * Tests that wp_list_pluck() throws _doing_it_wrong() with an index key and invalid input. 131 * 132 * @ticket 56650 133 * 134 * @dataProvider data_wp_list_pluck_should_throw_doing_it_wrong_with_invalid_input 135 * 136 * @covers WP_List_Util::pluck 137 * @covers ::wp_list_pluck 138 * 139 * @expectedIncorrectUsage WP_List_Util::pluck 140 * 141 * @param array $input An invalid input array. 142 */ 143 public function test_wp_list_pluck_should_throw_doing_it_wrong_with_index_key_and_invalid_input( $input ) { 144 $this->assertSame( array(), wp_list_pluck( $input, 'a_field', 'an_index_key' ) ); 145 } 146 147 /** 148 * Data provider that provides invalid input arrays. 149 * 150 * @return array 151 */ 152 public function data_wp_list_pluck_should_throw_doing_it_wrong_with_invalid_input() { 153 return array( 154 'int[] 0' => array( array( 0 ) ), 155 'int[] 1' => array( array( 1 ) ), 156 'int[] -1' => array( array( -1 ) ), 157 'float[] 0.0' => array( array( 0.0 ) ), 158 'float[] 1.0' => array( array( 1.0 ) ), 159 'float[] -1.0' => array( array( -1.0 ) ), 160 'string[] and empty string' => array( array( '' ) ), 161 'string[] and "0"' => array( array( '0' ) ), 162 'string[] and "1"' => array( array( '1' ) ), 163 'string[] and "-1"' => array( array( '-1' ) ), 164 'array and null' => array( array( null ) ), 165 'array and false' => array( array( false ) ), 166 'array and true' => array( array( true ) ), 108 167 ); 109 168 }
Note: See TracChangeset
for help on using the changeset viewer.