Changeset 42343 for trunk/tests/phpunit/tests/functions/listFilter.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/functions/listFilter.php
r35950 r42343 8 8 class Tests_Functions_ListFilter extends WP_UnitTestCase { 9 9 var $object_list = array(); 10 var $array_list = array();10 var $array_list = array(); 11 11 12 12 function setUp() { 13 13 parent::setUp(); 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' ) ); 14 $this->array_list['foo'] = array( 15 'name' => 'foo', 16 'id' => 'f', 17 'field1' => true, 18 'field2' => true, 19 'field3' => true, 20 'field4' => array( 'red' ), 21 ); 22 $this->array_list['bar'] = array( 23 'name' => 'bar', 24 'id' => 'b', 25 'field1' => true, 26 'field2' => true, 27 'field3' => false, 28 'field4' => array( 'green' ), 29 ); 30 $this->array_list['baz'] = array( 31 'name' => 'baz', 32 'id' => 'z', 33 'field1' => true, 34 'field2' => false, 35 'field3' => false, 36 'field4' => array( 'blue' ), 37 ); 17 38 foreach ( $this->array_list as $key => $value ) { 18 39 $this->object_list[ $key ] = (object) $value; … … 21 42 22 43 function test_filter_object_list_and() { 23 $list = wp_filter_object_list( $this->object_list, array( 'field1' => true, 'field2' => true ), 'AND' ); 44 $list = wp_filter_object_list( 45 $this->object_list, array( 46 'field1' => true, 47 'field2' => true, 48 ), 'AND' 49 ); 24 50 $this->assertEquals( 2, count( $list ) ); 25 51 $this->assertArrayHasKey( 'foo', $list ); … … 28 54 29 55 function test_filter_object_list_or() { 30 $list = wp_filter_object_list( $this->object_list, array( 'field1' => true, 'field2' => true ), 'OR' ); 56 $list = wp_filter_object_list( 57 $this->object_list, array( 58 'field1' => true, 59 'field2' => true, 60 ), 'OR' 61 ); 31 62 $this->assertEquals( 3, count( $list ) ); 32 63 $this->assertArrayHasKey( 'foo', $list ); … … 36 67 37 68 function test_filter_object_list_not() { 38 $list = wp_filter_object_list( $this->object_list, array( 'field2' => true, 'field3' => true ), 'NOT' ); 69 $list = wp_filter_object_list( 70 $this->object_list, array( 71 'field2' => true, 72 'field3' => true, 73 ), 'NOT' 74 ); 39 75 $this->assertEquals( 1, count( $list ) ); 40 76 $this->assertArrayHasKey( 'baz', $list ); … … 42 78 43 79 function test_filter_object_list_and_field() { 44 $list = wp_filter_object_list( $this->object_list, array( 'field1' => true, 'field2' => true ), 'AND', 'name' ); 45 $this->assertEquals( 2, count( $list ) ); 46 $this->assertEquals( array( 'foo' => 'foo', 'bar' => 'bar' ) , $list ); 80 $list = wp_filter_object_list( 81 $this->object_list, array( 82 'field1' => true, 83 'field2' => true, 84 ), 'AND', 'name' 85 ); 86 $this->assertEquals( 2, count( $list ) ); 87 $this->assertEquals( 88 array( 89 'foo' => 'foo', 90 'bar' => 'bar', 91 ), $list 92 ); 47 93 } 48 94 49 95 function test_filter_object_list_or_field() { 50 $list = wp_filter_object_list( $this->object_list, array( 'field2' => true, 'field3' => true ), 'OR', 'name' ); 51 $this->assertEquals( 2, count( $list ) ); 52 $this->assertEquals( array( 'foo' => 'foo', 'bar' => 'bar' ) , $list ); 96 $list = wp_filter_object_list( 97 $this->object_list, array( 98 'field2' => true, 99 'field3' => true, 100 ), 'OR', 'name' 101 ); 102 $this->assertEquals( 2, count( $list ) ); 103 $this->assertEquals( 104 array( 105 'foo' => 'foo', 106 'bar' => 'bar', 107 ), $list 108 ); 53 109 } 54 110 55 111 function test_filter_object_list_not_field() { 56 $list = wp_filter_object_list( $this->object_list, array( 'field2' => true, 'field3' => true ), 'NOT', 'name' ); 57 $this->assertEquals( 1, count( $list ) ); 58 $this->assertEquals( array( 'baz' => 'baz' ) , $list ); 112 $list = wp_filter_object_list( 113 $this->object_list, array( 114 'field2' => true, 115 'field3' => true, 116 ), 'NOT', 'name' 117 ); 118 $this->assertEquals( 1, count( $list ) ); 119 $this->assertEquals( array( 'baz' => 'baz' ), $list ); 59 120 } 60 121 61 122 function test_wp_list_pluck() { 62 123 $list = wp_list_pluck( $this->object_list, 'name' ); 63 $this->assertEquals( array( 'foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz' ) , $list ); 124 $this->assertEquals( 125 array( 126 'foo' => 'foo', 127 'bar' => 'bar', 128 'baz' => 'baz', 129 ), $list 130 ); 64 131 65 132 $list = wp_list_pluck( $this->array_list, 'name' ); 66 $this->assertEquals( array( 'foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz' ) , $list ); 133 $this->assertEquals( 134 array( 135 'foo' => 'foo', 136 'bar' => 'bar', 137 'baz' => 'baz', 138 ), $list 139 ); 67 140 } 68 141 … … 72 145 function test_wp_list_pluck_index_key() { 73 146 $list = wp_list_pluck( $this->array_list, 'name', 'id' ); 74 $this->assertEquals( array( 'f' => 'foo', 'b' => 'bar', 'z' => 'baz' ), $list ); 147 $this->assertEquals( 148 array( 149 'f' => 'foo', 150 'b' => 'bar', 151 'z' => 'baz', 152 ), $list 153 ); 75 154 } 76 155 … … 80 159 function test_wp_list_pluck_object_index_key() { 81 160 $list = wp_list_pluck( $this->object_list, 'name', 'id' ); 82 $this->assertEquals( array( 'f' => 'foo', 'b' => 'bar', 'z' => 'baz' ), $list ); 161 $this->assertEquals( 162 array( 163 'f' => 'foo', 164 'b' => 'bar', 165 'z' => 'baz', 166 ), $list 167 ); 83 168 } 84 169 … … 88 173 function test_wp_list_pluck_missing_index_key() { 89 174 $list = wp_list_pluck( $this->array_list, 'name', 'nonexistent' ); 90 $this->assertEquals( array( 0 => 'foo', 1 => 'bar', 2 => 'baz' ), $list ); 175 $this->assertEquals( 176 array( 177 0 => 'foo', 178 1 => 'bar', 179 2 => 'baz', 180 ), $list 181 ); 91 182 } 92 183 … … 96 187 function test_wp_list_pluck_partial_missing_index_key() { 97 188 $array_list = $this->array_list; 98 unset( $array_list[ 189 unset( $array_list['bar']['id'] ); 99 190 $list = wp_list_pluck( $array_list, 'name', 'id' ); 100 $this->assertEquals( array( 'f' => 'foo', 0 => 'bar', 'z' => 'baz' ), $list ); 191 $this->assertEquals( 192 array( 193 'f' => 'foo', 194 0 => 'bar', 195 'z' => 'baz', 196 ), $list 197 ); 101 198 } 102 199 … … 105 202 */ 106 203 function test_wp_list_pluck_mixed_index_key() { 107 $mixed_list = $this->array_list;204 $mixed_list = $this->array_list; 108 205 $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 ); 206 $list = wp_list_pluck( $mixed_list, 'name', 'id' ); 207 $this->assertEquals( 208 array( 209 'f' => 'foo', 210 'b' => 'bar', 211 'z' => 'baz', 212 ), $list 213 ); 111 214 } 112 215 … … 125 228 126 229 function test_filter_object_list_nested_array_or() { 127 $list = wp_filter_object_list( $this->object_list, array( 'field3' => true, 'field4' => array( 'blue' ) ), 'OR' ); 230 $list = wp_filter_object_list( 231 $this->object_list, array( 232 'field3' => true, 233 'field4' => array( 'blue' ), 234 ), 'OR' 235 ); 128 236 $this->assertEquals( 2, count( $list ) ); 129 237 $this->assertArrayHasKey( 'foo', $list ); … … 141 249 $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'blue' ) ), 'AND', 'name' ); 142 250 $this->assertEquals( 1, count( $list ) ); 143 $this->assertEquals( array( 'baz' => 'baz' ) 251 $this->assertEquals( array( 'baz' => 'baz' ), $list ); 144 252 } 145 253 … … 147 255 $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'green' ) ), 'NOT', 'name' ); 148 256 $this->assertEquals( 2, count( $list ) ); 149 $this->assertEquals( array( 'foo' => 'foo', 'baz' => 'baz' ), $list ); 257 $this->assertEquals( 258 array( 259 'foo' => 'foo', 260 'baz' => 'baz', 261 ), $list 262 ); 150 263 } 151 264 152 265 function test_filter_object_list_nested_array_or_field() { 153 $list = wp_filter_object_list( $this->object_list, array( 'field3' => true, 'field4' => array( 'blue' ) ), 'OR', 'name' ); 154 $this->assertEquals( 2, count( $list ) ); 155 $this->assertEquals( array( 'foo' => 'foo', 'baz' => 'baz' ), $list ); 266 $list = wp_filter_object_list( 267 $this->object_list, array( 268 'field3' => true, 269 'field4' => array( 'blue' ), 270 ), 'OR', 'name' 271 ); 272 $this->assertEquals( 2, count( $list ) ); 273 $this->assertEquals( 274 array( 275 'foo' => 'foo', 276 'baz' => 'baz', 277 ), $list 278 ); 156 279 } 157 280 }
Note: See TracChangeset
for help on using the changeset viewer.