| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Make sure all DB tables are cleared and reset some data. |
| 5 | * |
| 6 | * BP creates multiple tables that should be cleared before PHPUnit is run. |
| 7 | * WP does something similar with {@link _delete_all_posts()} to delete all |
| 8 | * posts and its metadata. However, that only handles posts. |
| 9 | */ |
| 10 | function _bp_reset_data() { |
| 11 | global $wpdb; |
| 12 | |
| 13 | $bp = buddypress(); |
| 14 | |
| 15 | /** clear tables *******************************************************/ |
| 16 | |
| 17 | $clear_tables = array(); |
| 18 | |
| 19 | // activity |
| 20 | $clear_tables[] = $bp->activity->table_name; |
| 21 | $clear_tables[] = $bp->activity->table_name_meta; |
| 22 | |
| 23 | // blogs |
| 24 | // @todo delete individual, created site tables |
| 25 | $clear_tables[] = $bp->blogs->table_name_blogmeta; |
| 26 | |
| 27 | // friends |
| 28 | $clear_tables[] = $bp->friends->table_name; |
| 29 | //$clear_tables[] = $bp->friends->table_name_meta; |
| 30 | |
| 31 | // groups |
| 32 | $clear_tables[] = $bp->groups->table_name; |
| 33 | $clear_tables[] = $bp->groups->table_name_members; |
| 34 | $clear_tables[] = $bp->groups->table_name_groupmeta; |
| 35 | |
| 36 | // messages |
| 37 | $clear_tables[] = $bp->messages->table_name_notices; |
| 38 | $clear_tables[] = $bp->messages->table_name_messages; |
| 39 | $clear_tables[] = $bp->messages->table_name_recipients; |
| 40 | |
| 41 | // xprofile |
| 42 | $clear_tables[] = $bp->profile->table_name_data; |
| 43 | $clear_tables[] = $bp->profile->table_name_groups; |
| 44 | $clear_tables[] = $bp->profile->table_name_fields; |
| 45 | $clear_tables[] = $bp->profile->table_name_meta; |
| 46 | |
| 47 | // userdata |
| 48 | $clear_tables[] = $wpdb->users; |
| 49 | $clear_tables[] = $wpdb->usermeta; |
| 50 | |
| 51 | // wipe out tables! |
| 52 | foreach ( $clear_tables as $table ) { |
| 53 | $wpdb->query( "TRUNCATE TABLE {$table}" ); |
| 54 | } |
| 55 | |
| 56 | |
| 57 | /** reset data *********************************************************/ |
| 58 | |
| 59 | // WP's test suite wipes out BP's directory page mappings with _delete_all_posts() |
| 60 | // We must reestablish them before our tests can be successfully run |
| 61 | bp_core_add_page_mappings( bp_get_option( 'bp-active-components' ), 'delete' ); |
| 62 | |
| 63 | // record existing blogs |
| 64 | bp_blogs_record_existing_blogs(); |
| 65 | |
| 66 | // Insert the default xprofile group and field |
| 67 | xprofile_insert_field_group( array( |
| 68 | 'name' => 'Base', |
| 69 | 'description' => '', |
| 70 | 'can_delete' => 0 |
| 71 | ) ); |
| 72 | |
| 73 | xprofile_insert_field( array( |
| 74 | 'field_group_id' => 1, |
| 75 | 'parent_id' => 0, |
| 76 | 'type' => 'textbox', |
| 77 | 'name' => 'Name', |
| 78 | 'description' => '', |
| 79 | 'is_required' => 1, |
| 80 | 'can_delete' => 0 |
| 81 | ) ); |
| 82 | |
| 83 | } |
| 84 | No newline at end of file |