Skip to:
Content

BuddyPress.org

Ticket #5038: 5038.01.patch

File 5038.01.patch, 4.2 KB (added by r-a-y, 11 years ago)
  • tests/bootstrap.php

    if ( ! defined( 'BP_TESTS_DIR' ) ) { 
    77}
    88
    99require_once getenv( 'WP_TESTS_DIR' ) . '/includes/functions.php';
     10require BP_TESTS_DIR . '/includes/functions.php';
    1011
    1112function _install_and_load_buddypress() {
    1213        require BP_TESTS_DIR . '/includes/loader.php';
    1314}
    1415tests_add_filter( 'muplugins_loaded', '_install_and_load_buddypress' );
    1516
     17
    1618require getenv( 'WP_TESTS_DIR' ) . '/includes/bootstrap.php';
    1719
    1820// Load the BP-specific testing tools
  • tests/includes/functions.php

    new file mode 100644
     
     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 */
     10function _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
  • tests/includes/testcase.php

     
    11<?php
    22
    3 /**
    4  * WP's test suite wipes out BP's directory page mappings with _delete_all_posts()
    5  * We must reestablish them before our tests can be successfully run
    6  */
    7 bp_core_add_page_mappings( bp_get_option( 'bp-active-components' ), 'delete' );
    8 
    93require_once dirname( __FILE__ ) . '/factory.php';
    104
    115class BP_UnitTestCase extends WP_UnitTestCase {
    class BP_UnitTestCase extends WP_UnitTestCase { 
    137        public function setUp() {
    148                parent::setUp();
    159
    16                 // Make sure all users are deleted
    17                 // There's a bug in the multisite tests that causes the
    18                 // transaction rollback to fail for the first user created,
    19                 // which busts every other attempt to create users. This is a
    20                 // hack workaround
    21                 global $wpdb;
    22                 $wpdb->query( "TRUNCATE TABLE {$wpdb->users}" );
     10                _bp_reset_data();
    2311
    2412                $this->factory = new BP_UnitTest_Factory;
    2513        }