Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/14/2014 06:29:30 PM (10 years ago)
Author:
boonebgorges
Message:

Tests: more reliable last_updated for profiledata tests

Requires a hackish filter because BP doesn't make this very extensible

File:
1 edited

Legend:

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

    r7880 r7882  
    146146     */
    147147    public function test_get_value_byid_multipleusers_uncached() {
    148         $time = bp_core_current_time();
    149 
    150         $u1 = $this->create_user( array(
    151             'last_activity' => $time,
    152         ) );
    153         $u2 = $this->create_user( array(
    154             'last_activity' => $time,
    155         ) );
    156         $g = $this->factory->xprofile_group->create();
    157         $f = $this->factory->xprofile_field->create( array(
    158             'type' => 'textbox',
    159             'field_group_id' => $g,
    160         ) );
     148        $time = date( 'Y-m-d h:i:s', time() - 60*60*24 );
     149
     150        $u1 = $this->create_user();
     151        $u2 = $this->create_user();
     152        $g = $this->factory->xprofile_group->create();
     153        $f = $this->factory->xprofile_field->create( array(
     154            'type' => 'textbox',
     155            'field_group_id' => $g,
     156        ) );
     157
     158        // To make the tests reliable, we have to force the last_updated
     159        // BP doesn't easily allow this except via filter
     160        $this->last_updated = $time;
     161        add_filter( 'xprofile_data_last_updated_before_save', array( $this, 'filter_time' ) );
    161162
    162163        $d1 = new BP_XProfile_ProfileData();
     
    174175        $d2->save();
    175176
     177        remove_filter( 'xprofile_data_last_updated_before_save', array( $this, 'filter_time' ) );
     178
    176179        // Ensure it's deleted from cache
    177180        wp_cache_delete( $f, 'bp_xprofile_data_' . $u1 );
     
    223226     */
    224227    public function test_get_value_byid_multipleusers_cached() {
    225         $time = bp_core_current_time();
    226 
    227         $u1 = $this->create_user( array(
    228             'last_activity' => $time,
    229         ) );
    230         $u2 = $this->create_user( array(
    231             'last_activity' => $time,
    232         ) );
     228        $time = date( 'Y-m-d h:i:s', time() - 60*60*24 );
     229
     230        $u1 = $this->create_user();
     231        $u2 = $this->create_user();
    233232        $g = $this->factory->xprofile_group->create();
    234233        $f = $this->factory->xprofile_field->create( array(
     
    429428    }
    430429
     430    public function filter_time() {
     431        return $this->last_updated;
     432    }
    431433}
Note: See TracChangeset for help on using the changeset viewer.