Skip to:
Content

BuddyPress.org

Ticket #7112: 7112-alt-test.diff

File 7112-alt-test.diff, 1.7 KB (added by dcavins, 8 years ago)

Testing that the position is updated rather than the cache freshness.

  • src/bp-xprofile/classes/class-bp-xprofile-field.php

    diff --git src/bp-xprofile/classes/class-bp-xprofile-field.php src/bp-xprofile/classes/class-bp-xprofile-field.php
    index 511a097..11c48fd 100644
    class BP_XProfile_Field { 
    943943                        $sql = $wpdb->prepare( "UPDATE {$table_name} SET group_id = %d WHERE parent_id = %d", $field_group_id, $field_id );
    944944                        $wpdb->query( $sql );
    945945
     946                        // Invalidate profile field cache.
     947                        wp_cache_delete( $field_id, 'bp_xprofile_fields' );
     948
    946949                        return $parent;
    947950                }
    948951
  • tests/phpunit/testcases/xprofile/class-bp-xprofile-field.php

    diff --git tests/phpunit/testcases/xprofile/class-bp-xprofile-field.php tests/phpunit/testcases/xprofile/class-bp-xprofile-field.php
    index 816a7ef..2e9370a 100644
    class BP_Tests_BP_XProfile_Field_TestCases extends BP_UnitTestCase { 
    183183
    184184                $this->assertFalse( wp_cache_get( 12345, 'bp_xprofile_fields' ) );
    185185        }
     186
     187        /**
     188         * @ticket BP7112
     189         */
     190        public function test_update_position_should_invalidate_cache() {
     191                $group = $this->factory->xprofile_group->create();
     192                $field = $this->factory->xprofile_field->create( array(
     193                        'field_group_id' => $group,
     194                ) );
     195
     196                // Prime cache.
     197                $fetched_field = xprofile_get_field( $field );
     198                $new_field_order = 12345;
     199
     200                // Update field position.
     201                BP_XProfile_Field::update_position( $field, $new_field_order, $group );
     202
     203                // Cache call should miss and fresh data is fetched.
     204                $updated_fetched_field = xprofile_get_field( $field );
     205                $this->assertEquals( $new_field_order, $updated_fetched_field->field_order );
     206        }
    186207}