Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/14/2014 12:17:53 PM (11 years ago)
Author:
boonebgorges
Message:

Tests: xprofile factory create() methods should return IDs, not objects

This is more consistent with other components

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/testcases/xprofile/class-bp-xprofile-profiledata.php

    r7835 r7873  
    1414        $f = $this->factory->xprofile_field->create( array(
    1515            '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 );
    2020
    2121        $this->assertFalse( $d->exists() );
     
    3030        $f = $this->factory->xprofile_field->create( array(
    3131            '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 );
    4040
    4141        $this->assertTrue( $d->exists() );
     
    5050        $f = $this->factory->xprofile_field->create( array(
    5151            '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 );
    5555
    5656        // Fake the cache
    57         wp_cache_set( $f->id, 'foo', 'bp_xprofile_data_' . $u );
     57        wp_cache_set( $f, 'foo', 'bp_xprofile_data_' . $u );
    5858
    5959        $this->assertTrue( $d->exists() );
     
    6868        $f = $this->factory->xprofile_field->create( array(
    6969            'type' => 'textbox',
    70             'field_group_id' => $g->id,
     70            'field_group_id' => $g,
    7171        ) );
    7272
    7373        // 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 ) );
    7777    }
    7878
     
    8585        $f = $this->factory->xprofile_field->create( array(
    8686            'type' => 'textbox',
    87             'field_group_id' => $g->id,
     87            'field_group_id' => $g,
    8888        ) );
    8989
    9090        $d = new BP_XProfile_ProfileData();
    9191        $d->user_id = $u;
    92         $d->field_id = $f->id;
     92        $d->field_id = $f;
    9393        $d->value = 'foo';
    9494        $d->save();
    9595
    9696        // 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 ) );
    100100    }
    101101
     
    108108        $f = $this->factory->xprofile_field->create( array(
    109109            'type' => 'textbox',
    110             'field_group_id' => $g->id,
     110            'field_group_id' => $g,
    111111        ) );
    112112
     
    114114        $d = new stdClass;
    115115        $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 ) );
    119119    }
    120120
     
    127127        $f = $this->factory->xprofile_field->create( array(
    128128            'type' => 'textbox',
    129             'field_group_id' => $g->id,
     129            'field_group_id' => $g,
    130130        ) );
    131131
    132132        $d = new BP_XProfile_ProfileData();
    133133        $d->user_id = $u;
    134         $d->field_id = $f->id;
     134        $d->field_id = $f;
    135135        $d->value = 'foo';
    136136        $d->save();
    137137
    138138        // 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 ) );
    142142    }
    143143
     
    151151        $f = $this->factory->xprofile_field->create( array(
    152152            'type' => 'textbox',
    153             'field_group_id' => $g->id,
     153            'field_group_id' => $g,
    154154        ) );
    155155
     
    158158        $d1 = new BP_XProfile_ProfileData();
    159159        $d1->user_id = $u1;
    160         $d1->field_id = $f->id;
     160        $d1->field_id = $f;
    161161        $d1->value = 'foo';
    162162        $d1->last_updated = $time;
     
    165165        $d2 = new BP_XProfile_ProfileData();
    166166        $d2->user_id = $u2;
    167         $d2->field_id = $f->id;
     167        $d2->field_id = $f;
    168168        $d2->value = 'bar';
    169169        $d2->last_updated = $time;
     
    171171
    172172        // 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 );
    175175
    176176        $eu1 = new stdClass;
     
    178178        $eu1->value = 'foo';
    179179        $eu1->id = $d1->id;
    180         $eu1->field_id = $f->id;
     180        $eu1->field_id = $f;
    181181        $eu1->last_updated = $time;
    182182
     
    185185        $eu2->value = 'bar';
    186186        $eu2->id = $d2->id;
    187         $eu2->field_id = $f->id;
     187        $eu2->field_id = $f;
    188188        $eu2->last_updated = $time;
    189189
    190190        $expected = array( $eu1, $eu2 );
    191191
    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 ) ) );
    193193    }
    194194
     
    201201        $f = $this->factory->xprofile_field->create( array(
    202202            'type' => 'textbox',
    203             'field_group_id' => $g->id,
     203            'field_group_id' => $g,
    204204        ) );
    205205
     
    209209        $d = new stdClass;
    210210        $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 ) );
    215215    }
    216216
     
    224224        $f = $this->factory->xprofile_field->create( array(
    225225            'type' => 'textbox',
    226             'field_group_id' => $g->id,
     226            'field_group_id' => $g,
    227227        ) );
    228228
     
    233233        $d1->id = 10;
    234234        $d1->user_id = $u1;
    235         $d1->field_id = $f->id;
     235        $d1->field_id = $f;
    236236        $d1->value = 'foo';
    237237        $d1->last_updated = $time;
     
    240240        $d1->id = 21;
    241241        $d2->user_id = $u2;
    242         $d2->field_id = $f->id;
     242        $d2->field_id = $f;
    243243        $d2->value = 'bar';
    244244        $d2->last_updated = $time;
    245245
    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 );
    248248
    249249        $eu1 = new stdClass;
    250250        $eu1->id = 10;
    251251        $eu1->user_id = $u1;
    252         $eu1->field_id = $f->id;
     252        $eu1->field_id = $f;
    253253        $eu1->value = 'foo';
    254254        $eu1->last_updated = $time;
     
    257257        $eu1->id = 21;
    258258        $eu2->user_id = $u2;
    259         $eu2->field_id = $f->id;
     259        $eu2->field_id = $f;
    260260        $eu2->value = 'bar';
    261261        $eu2->last_updated = $time;
     
    263263        $expected = array( $eu1, $eu2 );
    264264
    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 ) ) );
    266266    }
    267267
     
    275275        $f1 = $this->factory->xprofile_field->create( array(
    276276            'type' => 'textbox',
    277             'field_group_id' => $g1->id,
     277            'field_group_id' => $g1,
    278278        ) );
    279279        $f2 = $this->factory->xprofile_field->create( array(
    280280            'type' => 'radio',
    281             'field_group_id' => $g2->id,
     281            'field_group_id' => $g2,
    282282        ) );
    283283
     
    292292        $d1 = new BP_XProfile_ProfileData();
    293293        $d1->user_id = $u;
    294         $d1->field_id = $f1->id;
     294        $d1->field_id = $f1;
    295295        $d1->value = 'foo';
    296296        $d1->last_updated = $time;
     
    299299        $d2 = new BP_XProfile_ProfileData();
    300300        $d2->user_id = $u;
    301         $d2->field_id = $f2->id;
     301        $d2->field_id = $f2;
    302302        $d2->value = 'bar';
    303303        $d2->last_updated = $time;
     
    305305
    306306        // 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 );
    309309
    310310        $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 );
    311316
    312317        $expected = array(
     
    321326                'field_data' => $d0->value,
    322327            ),
    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,
    328333                'field_data' => $d1->value,
    329334            ),
    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,
    335340                'field_data' => $d2->value,
    336341            ),
     
    349354        $f1 = $this->factory->xprofile_field->create( array(
    350355            'type' => 'textbox',
    351             'field_group_id' => $g1->id,
     356            'field_group_id' => $g1,
    352357        ) );
    353358        $f2 = $this->factory->xprofile_field->create( array(
    354359            'type' => 'radio',
    355             'field_group_id' => $g2->id,
     360            'field_group_id' => $g2,
    356361        ) );
    357362
     
    364369        $d1 = new stdClass;
    365370        $d1->user_id = $u;
    366         $d1->field_id = $f1->id;
     371        $d1->field_id = $f1;
    367372        $d1->value = 'foo';
    368373        $d1->last_updated = $time;
     
    371376        $d2 = new stdClass;
    372377        $d2->user_id = $u;
    373         $d2->field_id = $f2->id;
     378        $d2->field_id = $f2;
    374379        $d2->value = 'bar';
    375380        $d2->last_updated = $time;
    376381        $d2->id = 2;
    377382
    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 );
    380385
    381386        $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 );
    382392
    383393        $expected = array(
     
    392402                'field_data' => $d0->value,
    393403            ),
    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,
    399409                'field_data' => $d1->value,
    400410            ),
    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,
    406416                'field_data' => $d2->value,
    407417            ),
Note: See TracChangeset for help on using the changeset viewer.