- Timestamp:
- 02/14/2014 12:17:53 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/testcases/xprofile/class-bp-xprofile-profiledata.php
r7835 r7873 14 14 $f = $this->factory->xprofile_field->create( array( 15 15 'type' => 'textbox', 16 'field_group_id' => $g ->id,17 ) ); 18 19 $d = new BP_XProfile_ProfileData( $f ->id, $u );16 'field_group_id' => $g, 17 ) ); 18 19 $d = new BP_XProfile_ProfileData( $f, $u ); 20 20 21 21 $this->assertFalse( $d->exists() ); … … 30 30 $f = $this->factory->xprofile_field->create( array( 31 31 'type' => 'textbox', 32 'field_group_id' => $g ->id,33 ) ); 34 35 xprofile_set_field_data( $f ->id, $u, 'foo' );36 37 $d = new BP_XProfile_ProfileData( $f ->id, $u );38 39 wp_cache_delete( $f ->id, 'bp_xprofile_data_' . $u );32 'field_group_id' => $g, 33 ) ); 34 35 xprofile_set_field_data( $f, $u, 'foo' ); 36 37 $d = new BP_XProfile_ProfileData( $f, $u ); 38 39 wp_cache_delete( $f, 'bp_xprofile_data_' . $u ); 40 40 41 41 $this->assertTrue( $d->exists() ); … … 50 50 $f = $this->factory->xprofile_field->create( array( 51 51 'type' => 'textbox', 52 'field_group_id' => $g ->id,53 ) ); 54 $d = new BP_XProfile_ProfileData( $f ->id, $u );52 'field_group_id' => $g, 53 ) ); 54 $d = new BP_XProfile_ProfileData( $f, $u ); 55 55 56 56 // Fake the cache 57 wp_cache_set( $f ->id, 'foo', 'bp_xprofile_data_' . $u );57 wp_cache_set( $f, 'foo', 'bp_xprofile_data_' . $u ); 58 58 59 59 $this->assertTrue( $d->exists() ); … … 68 68 $f = $this->factory->xprofile_field->create( array( 69 69 'type' => 'textbox', 70 'field_group_id' => $g ->id,70 'field_group_id' => $g, 71 71 ) ); 72 72 73 73 // Just to be sure 74 wp_cache_delete( $f ->id, 'bp_xprofile_data_' . $u );75 76 $this->assertEquals( 0, BP_XProfile_ProfileData::get_fielddataid_byid( $f ->id, $u ) );74 wp_cache_delete( $f, 'bp_xprofile_data_' . $u ); 75 76 $this->assertEquals( 0, BP_XProfile_ProfileData::get_fielddataid_byid( $f, $u ) ); 77 77 } 78 78 … … 85 85 $f = $this->factory->xprofile_field->create( array( 86 86 'type' => 'textbox', 87 'field_group_id' => $g ->id,87 'field_group_id' => $g, 88 88 ) ); 89 89 90 90 $d = new BP_XProfile_ProfileData(); 91 91 $d->user_id = $u; 92 $d->field_id = $f ->id;92 $d->field_id = $f; 93 93 $d->value = 'foo'; 94 94 $d->save(); 95 95 96 96 // Ensure it's deleted from cache 97 wp_cache_delete( $f ->id, 'bp_xprofile_data_' . $u );98 99 $this->assertEquals( $d->id, BP_XProfile_ProfileData::get_fielddataid_byid( $f ->id, $u ) );97 wp_cache_delete( $f, 'bp_xprofile_data_' . $u ); 98 99 $this->assertEquals( $d->id, BP_XProfile_ProfileData::get_fielddataid_byid( $f, $u ) ); 100 100 } 101 101 … … 108 108 $f = $this->factory->xprofile_field->create( array( 109 109 'type' => 'textbox', 110 'field_group_id' => $g ->id,110 'field_group_id' => $g, 111 111 ) ); 112 112 … … 114 114 $d = new stdClass; 115 115 $d->id = 5; 116 wp_cache_set( $f ->id, $d, 'bp_xprofile_data_' . $u );117 118 $this->assertSame( 5, BP_XProfile_ProfileData::get_fielddataid_byid( $f ->id, $u ) );116 wp_cache_set( $f, $d, 'bp_xprofile_data_' . $u ); 117 118 $this->assertSame( 5, BP_XProfile_ProfileData::get_fielddataid_byid( $f, $u ) ); 119 119 } 120 120 … … 127 127 $f = $this->factory->xprofile_field->create( array( 128 128 'type' => 'textbox', 129 'field_group_id' => $g ->id,129 'field_group_id' => $g, 130 130 ) ); 131 131 132 132 $d = new BP_XProfile_ProfileData(); 133 133 $d->user_id = $u; 134 $d->field_id = $f ->id;134 $d->field_id = $f; 135 135 $d->value = 'foo'; 136 136 $d->save(); 137 137 138 138 // Ensure it's deleted from cache 139 wp_cache_delete( $f ->id, 'bp_xprofile_data_' . $u );140 141 $this->assertSame( 'foo', BP_XProfile_ProfileData::get_value_byid( $f ->id, $u ) );139 wp_cache_delete( $f, 'bp_xprofile_data_' . $u ); 140 141 $this->assertSame( 'foo', BP_XProfile_ProfileData::get_value_byid( $f, $u ) ); 142 142 } 143 143 … … 151 151 $f = $this->factory->xprofile_field->create( array( 152 152 'type' => 'textbox', 153 'field_group_id' => $g ->id,153 'field_group_id' => $g, 154 154 ) ); 155 155 … … 158 158 $d1 = new BP_XProfile_ProfileData(); 159 159 $d1->user_id = $u1; 160 $d1->field_id = $f ->id;160 $d1->field_id = $f; 161 161 $d1->value = 'foo'; 162 162 $d1->last_updated = $time; … … 165 165 $d2 = new BP_XProfile_ProfileData(); 166 166 $d2->user_id = $u2; 167 $d2->field_id = $f ->id;167 $d2->field_id = $f; 168 168 $d2->value = 'bar'; 169 169 $d2->last_updated = $time; … … 171 171 172 172 // Ensure it's deleted from cache 173 wp_cache_delete( $f ->id, 'bp_xprofile_data_' . $u1 );174 wp_cache_delete( $f ->id, 'bp_xprofile_data_' . $u2 );173 wp_cache_delete( $f, 'bp_xprofile_data_' . $u1 ); 174 wp_cache_delete( $f, 'bp_xprofile_data_' . $u2 ); 175 175 176 176 $eu1 = new stdClass; … … 178 178 $eu1->value = 'foo'; 179 179 $eu1->id = $d1->id; 180 $eu1->field_id = $f ->id;180 $eu1->field_id = $f; 181 181 $eu1->last_updated = $time; 182 182 … … 185 185 $eu2->value = 'bar'; 186 186 $eu2->id = $d2->id; 187 $eu2->field_id = $f ->id;187 $eu2->field_id = $f; 188 188 $eu2->last_updated = $time; 189 189 190 190 $expected = array( $eu1, $eu2 ); 191 191 192 $this->assertEquals( $expected, BP_XProfile_ProfileData::get_value_byid( $f ->id, array( $u1, $u2 ) ) );192 $this->assertEquals( $expected, BP_XProfile_ProfileData::get_value_byid( $f, array( $u1, $u2 ) ) ); 193 193 } 194 194 … … 201 201 $f = $this->factory->xprofile_field->create( array( 202 202 'type' => 'textbox', 203 'field_group_id' => $g ->id,203 'field_group_id' => $g, 204 204 ) ); 205 205 … … 209 209 $d = new stdClass; 210 210 $d->value = 'foo'; 211 $d->field_id = $f ->id;212 wp_cache_set( $f ->id, $d, 'bp_xprofile_data_' . $u );213 214 $this->assertSame( 'foo', BP_XProfile_ProfileData::get_value_byid( $f ->id, $u ) );211 $d->field_id = $f; 212 wp_cache_set( $f, $d, 'bp_xprofile_data_' . $u ); 213 214 $this->assertSame( 'foo', BP_XProfile_ProfileData::get_value_byid( $f, $u ) ); 215 215 } 216 216 … … 224 224 $f = $this->factory->xprofile_field->create( array( 225 225 'type' => 'textbox', 226 'field_group_id' => $g ->id,226 'field_group_id' => $g, 227 227 ) ); 228 228 … … 233 233 $d1->id = 10; 234 234 $d1->user_id = $u1; 235 $d1->field_id = $f ->id;235 $d1->field_id = $f; 236 236 $d1->value = 'foo'; 237 237 $d1->last_updated = $time; … … 240 240 $d1->id = 21; 241 241 $d2->user_id = $u2; 242 $d2->field_id = $f ->id;242 $d2->field_id = $f; 243 243 $d2->value = 'bar'; 244 244 $d2->last_updated = $time; 245 245 246 wp_cache_set( $f ->id, $d1, 'bp_xprofile_data_' . $u1 );247 wp_cache_set( $f ->id, $d2, 'bp_xprofile_data_' . $u2 );246 wp_cache_set( $f, $d1, 'bp_xprofile_data_' . $u1 ); 247 wp_cache_set( $f, $d2, 'bp_xprofile_data_' . $u2 ); 248 248 249 249 $eu1 = new stdClass; 250 250 $eu1->id = 10; 251 251 $eu1->user_id = $u1; 252 $eu1->field_id = $f ->id;252 $eu1->field_id = $f; 253 253 $eu1->value = 'foo'; 254 254 $eu1->last_updated = $time; … … 257 257 $eu1->id = 21; 258 258 $eu2->user_id = $u2; 259 $eu2->field_id = $f ->id;259 $eu2->field_id = $f; 260 260 $eu2->value = 'bar'; 261 261 $eu2->last_updated = $time; … … 263 263 $expected = array( $eu1, $eu2 ); 264 264 265 $this->assertEquals( $expected, BP_XProfile_ProfileData::get_value_byid( $f ->id, array( $u1, $u2 ) ) );265 $this->assertEquals( $expected, BP_XProfile_ProfileData::get_value_byid( $f, array( $u1, $u2 ) ) ); 266 266 } 267 267 … … 275 275 $f1 = $this->factory->xprofile_field->create( array( 276 276 'type' => 'textbox', 277 'field_group_id' => $g1 ->id,277 'field_group_id' => $g1, 278 278 ) ); 279 279 $f2 = $this->factory->xprofile_field->create( array( 280 280 'type' => 'radio', 281 'field_group_id' => $g2 ->id,281 'field_group_id' => $g2, 282 282 ) ); 283 283 … … 292 292 $d1 = new BP_XProfile_ProfileData(); 293 293 $d1->user_id = $u; 294 $d1->field_id = $f1 ->id;294 $d1->field_id = $f1; 295 295 $d1->value = 'foo'; 296 296 $d1->last_updated = $time; … … 299 299 $d2 = new BP_XProfile_ProfileData(); 300 300 $d2->user_id = $u; 301 $d2->field_id = $f2 ->id;301 $d2->field_id = $f2; 302 302 $d2->value = 'bar'; 303 303 $d2->last_updated = $time; … … 305 305 306 306 // Ensure it's deleted from cache 307 wp_cache_delete( $f1 ->id, 'bp_xprofile_data_' . $u );308 wp_cache_delete( $f2 ->id, 'bp_xprofile_data_' . $u );307 wp_cache_delete( $f1, 'bp_xprofile_data_' . $u ); 308 wp_cache_delete( $f2, 'bp_xprofile_data_' . $u ); 309 309 310 310 $u_obj = new WP_User( $u ); 311 312 $g1_obj = new BP_XProfile_Group( $g1 ); 313 $g2_obj = new BP_XProfile_Group( $g2 ); 314 $f1_obj = new BP_XProfile_Field( $f1 ); 315 $f2_obj = new BP_XProfile_Field( $f2 ); 311 316 312 317 $expected = array( … … 321 326 'field_data' => $d0->value, 322 327 ), 323 $f1 ->name => array(324 'field_group_id' => $g1 ->id,325 'field_group_name' => $g1 ->name,326 'field_id' => $f1 ->id,327 'field_type' => $f1 ->type,328 $f1_obj->name => array( 329 'field_group_id' => $g1, 330 'field_group_name' => $g1_obj->name, 331 'field_id' => $f1, 332 'field_type' => $f1_obj->type, 328 333 'field_data' => $d1->value, 329 334 ), 330 $f2 ->name => array(331 'field_group_id' => $g2 ->id,332 'field_group_name' => $g2 ->name,333 'field_id' => $f2 ->id,334 'field_type' => $f2 ->type,335 $f2_obj->name => array( 336 'field_group_id' => $g2, 337 'field_group_name' => $g2_obj->name, 338 'field_id' => $f2, 339 'field_type' => $f2_obj->type, 335 340 'field_data' => $d2->value, 336 341 ), … … 349 354 $f1 = $this->factory->xprofile_field->create( array( 350 355 'type' => 'textbox', 351 'field_group_id' => $g1 ->id,356 'field_group_id' => $g1, 352 357 ) ); 353 358 $f2 = $this->factory->xprofile_field->create( array( 354 359 'type' => 'radio', 355 'field_group_id' => $g2 ->id,360 'field_group_id' => $g2, 356 361 ) ); 357 362 … … 364 369 $d1 = new stdClass; 365 370 $d1->user_id = $u; 366 $d1->field_id = $f1 ->id;371 $d1->field_id = $f1; 367 372 $d1->value = 'foo'; 368 373 $d1->last_updated = $time; … … 371 376 $d2 = new stdClass; 372 377 $d2->user_id = $u; 373 $d2->field_id = $f2 ->id;378 $d2->field_id = $f2; 374 379 $d2->value = 'bar'; 375 380 $d2->last_updated = $time; 376 381 $d2->id = 2; 377 382 378 wp_cache_set( $f1 ->id, $d1, 'bp_xprofile_data_' . $u );379 wp_cache_set( $f2 ->id, $d2, 'bp_xprofile_data_' . $u );383 wp_cache_set( $f1, $d1, 'bp_xprofile_data_' . $u ); 384 wp_cache_set( $f2, $d2, 'bp_xprofile_data_' . $u ); 380 385 381 386 $u_obj = new WP_User( $u ); 387 388 $g1_obj = new BP_XProfile_Group( $g1 ); 389 $g2_obj = new BP_XProfile_Group( $g2 ); 390 $f1_obj = new BP_XProfile_Field( $f1 ); 391 $f2_obj = new BP_XProfile_Field( $f2 ); 382 392 383 393 $expected = array( … … 392 402 'field_data' => $d0->value, 393 403 ), 394 $f1 ->name => array(395 'field_group_id' => $g1 ->id,396 'field_group_name' => $g1 ->name,397 'field_id' => $f1 ->id,398 'field_type' => $f1 ->type,404 $f1_obj->name => array( 405 'field_group_id' => $g1, 406 'field_group_name' => $g1_obj->name, 407 'field_id' => $f1, 408 'field_type' => $f1_obj->type, 399 409 'field_data' => $d1->value, 400 410 ), 401 $f2 ->name => array(402 'field_group_id' => $g2 ->id,403 'field_group_name' => $g2 ->name,404 'field_id' => $f2 ->id,405 'field_type' => $f2 ->type,411 $f2_obj->name => array( 412 'field_group_id' => $g2, 413 'field_group_name' => $g2_obj->name, 414 'field_id' => $f2, 415 'field_type' => $f2_obj->type, 406 416 'field_data' => $d2->value, 407 417 ),
Note: See TracChangeset
for help on using the changeset viewer.