Ticket #4889: 4889.patch
| File 4889.patch, 34.9 KB (added by , 13 years ago) |
|---|
-
new file phpunit.xml
diff --git phpunit.xml phpunit.xml new file mode 100644 index 0000000..a99d962
- + 1 <phpunit 2 bootstrap="tests/bootstrap.php" 3 backupGlobals="false" 4 colors="true" 5 convertErrorsToExceptions="true" 6 convertNoticesToExceptions="true" 7 convertWarningsToExceptions="true" 8 > 9 <testsuites> 10 <testsuite> 11 <directory suffix=".php">./tests/testcases/</directory> 12 </testsuite> 13 </testsuites> 14 </phpunit> -
new file tests/bootstrap.php
diff --git tests/bootstrap.php tests/bootstrap.php new file mode 100644 index 0000000..61fff51
- + 1 <?php 2 3 require_once getenv( 'WP_TESTS_DIR' ) . '/includes/functions.php'; 4 5 function _install_and_load_buddypress() { 6 require dirname( __FILE__ ) . '/includes/loader.php'; 7 } 8 tests_add_filter( 'muplugins_loaded', '_install_and_load_buddypress' ); 9 10 require getenv( 'WP_TESTS_DIR' ) . '/includes/bootstrap.php'; 11 12 // Load the BP-specific testing tools 13 require dirname( __FILE__ ) . '/includes/testcase.php'; -
new file tests/includes/factory.php
diff --git tests/includes/factory.php tests/includes/factory.php new file mode 100644 index 0000000..8c7d60c
- + 1 <?php 2 class BP_UnitTest_Factory extends WP_UnitTest_Factory { 3 public $activity = null; 4 5 function __construct() { 6 parent::__construct(); 7 8 $this->activity = new BP_UnitTest_Factory_For_Activity( $this ); 9 $this->group = new BP_UnitTest_Factory_For_Group( $this ); 10 $this->xprofile_group = new BP_UnitTest_Factory_For_XProfileGroup( $this ); 11 $this->xprofile_field = new BP_UnitTest_Factory_For_XProfileField( $this ); 12 } 13 } 14 15 class BP_UnitTest_Factory_For_Activity extends WP_UnitTest_Factory_For_Thing { 16 17 function __construct( $factory = null ) { 18 parent::__construct( $factory ); 19 20 $this->default_generation_definitions = array( 21 'action' => new WP_UnitTest_Generator_Sequence( 'Activity action %s' ), 22 'component' => buddypress()->activity->id, 23 'content' => new WP_UnitTest_Generator_Sequence( 'Activity content %s' ), 24 'primary_link' => 'http://example.com', 25 'type' => 'activity_update', 26 ); 27 } 28 29 function create_object( $args ) { 30 if ( ! isset( $args['user_id'] ) ) 31 $args['user_id'] = get_current_user_id(); 32 33 return $this->get_object_by_id( bp_activity_add( $args ) ); 34 } 35 36 function update_object( $activity_id, $fields ) { 37 $activity = new BP_Activity_Activity( $activity_id ); 38 39 foreach ( $fields as $field_name => $value ) { 40 if ( isset( $activity->$field_name ) ) 41 $activity->$field_name = $value; 42 } 43 44 $activity->save(); 45 return $activity; 46 } 47 48 function get_object_by_id( $user_id ) { 49 return new BP_Activity_Activity( $user_id ); 50 } 51 } 52 53 class BP_UnitTest_Factory_For_Group extends WP_UnitTest_Factory_For_Thing { 54 55 function __construct( $factory = null ) { 56 parent::__construct( $factory ); 57 58 $this->default_generation_definitions = array( 59 'name' => new WP_UnitTest_Generator_Sequence( 'Group %s' ), 60 'description' => new WP_UnitTest_Generator_Sequence( 'Group description %s' ), 61 'slug' => new WP_UnitTest_Generator_Sequence( 'group-slug-%s' ), 62 'status' => 'public', 63 'enable_forum' => true, 64 'date_created' => bp_core_current_time(), 65 ); 66 } 67 68 function create_object( $args ) { 69 if ( ! isset( $args['creator_id'] ) ) { 70 $args['creator_id'] = get_current_user_id(); 71 } 72 73 $group_id = groups_create_group( $args ); 74 75 groups_update_groupmeta( $group_id, 'total_member_count', 1 ); 76 groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() ); 77 78 return $this->get_object_by_id( $group_id ); 79 } 80 81 function update_object( $group_id, $fields ) { 82 $group = new BP_Groups_Group( $group_id ); 83 84 foreach ( $fields as $field_name => $value ) { 85 if ( isset( $group->field_name ) ) 86 $group->field_name = $value; 87 } 88 89 $group->save(); 90 return $group; 91 } 92 93 function get_object_by_id( $group_id ) { 94 return new BP_Groups_Group( $group_id ); 95 } 96 } 97 98 class BP_UnitTest_Factory_For_XProfileGroup extends WP_UnitTest_Factory_For_Thing { 99 100 function __construct( $factory = null ) { 101 parent::__construct( $factory ); 102 103 $this->default_generation_definitions = array( 104 'name' => new WP_UnitTest_Generator_Sequence( 'XProfile group %s' ), 105 'description' => new WP_UnitTest_Generator_Sequence( 'XProfile group description %s' ), 106 'slug' => new WP_UnitTest_Generator_Sequence( 'xprofile-group-slug-%s' ), 107 ); 108 } 109 110 function create_object( $args ) { 111 $group_id = xprofile_insert_field_group( $args ); 112 return $this->get_object_by_id( $group_id ); 113 } 114 115 function update_object( $group_id, $fields ) { 116 } 117 118 function get_object_by_id( $group_id ) { 119 return new BP_XProfile_Group( $group_id ); 120 } 121 } 122 123 class BP_UnitTest_Factory_For_XProfileField extends WP_UnitTest_Factory_For_Thing { 124 125 function __construct( $factory = null ) { 126 parent::__construct( $factory ); 127 128 $this->default_generation_definitions = array( 129 'name' => new WP_UnitTest_Generator_Sequence( 'XProfile field %s' ), 130 'description' => new WP_UnitTest_Generator_Sequence( 'XProfile field description %s' ), 131 ); 132 } 133 134 function create_object( $args ) { 135 $field_id = xprofile_insert_field( $args ); 136 return $this->get_object_by_id( $field_id ); 137 } 138 139 function update_object( $field_id, $fields ) { 140 } 141 142 function get_object_by_id( $field_id ) { 143 return new BP_XProfile_Field( $field_id ); 144 } 145 } -
new file tests/includes/install.php
diff --git tests/includes/install.php tests/includes/install.php new file mode 100644 index 0000000..800bf7a
- + 1 <?php 2 /** 3 * Installs BuddyPress for the purpose of the unit-tests 4 * 5 * @todo Reuse the init/load code in init.php 6 * @todo Support MULTIBLOG 7 */ 8 error_reporting( E_ALL & ~E_DEPRECATED & ~E_STRICT ); 9 10 $config_file_path = $argv[1]; 11 $multisite = ! empty( $argv[2] ); 12 13 require_once $config_file_path; 14 require_once dirname( $config_file_path ) . '/includes/functions.php'; 15 16 // Set BP to be an active plugin 17 $GLOBALS['wp_tests_options'] = array( 18 'active_plugins' => 'buddypress/bp-loader.php', 19 ); 20 define( 'BP_ROOT_BLOG', 1 ); 21 22 // Always load admin bar 23 tests_add_filter( 'show_admin_bar', '__return_true' ); 24 25 function wp_tests_options( $value ) { 26 $key = substr( current_filter(), strlen( 'pre_option_' ) ); 27 return $GLOBALS['wp_tests_options'][$key]; 28 } 29 foreach ( array_keys( $GLOBALS['wp_tests_options'] ) as $key ) { 30 tests_add_filter( 'pre_option_'.$key, 'wp_tests_options' ); 31 } 32 33 function wp_test_bp_install( $value ) { 34 return array( 'activity' => 1, 'friends' => 1, 'groups' => 1, 'members' => 1, 'messages' => 1, 'settings' => 1, 'xprofile' => 1, ); 35 } 36 tests_add_filter( 'bp_new_install_default_components', 'wp_test_bp_install' ); 37 38 $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; 39 $_SERVER['HTTP_HOST'] = WP_TESTS_DOMAIN; 40 $PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php'; 41 42 require_once ABSPATH . '/wp-settings.php'; 43 define( 'BP_TESTS_DB_VERSION_FILE', ABSPATH . '.bp-tests-version' ); 44 45 // Check if BuddyPress has already been installed 46 $db_version = bp_get_db_version_raw(); 47 48 if ( $db_version && file_exists( BP_TESTS_DB_VERSION_FILE ) ) { 49 $file_version = file_get_contents( BP_TESTS_DB_VERSION_FILE ); 50 51 if ( $db_version == (int) $file_version ) 52 return; 53 } 54 55 echo "Installing BuddyPress...\n"; 56 57 // Install BuddyPress 58 bp_version_updater(); 59 60 file_put_contents( BP_TESTS_DB_VERSION_FILE, bp_get_db_version_raw() ); -
new file tests/includes/loader.php
diff --git tests/includes/loader.php tests/includes/loader.php new file mode 100644 index 0000000..84420b0
- + 1 <?php 2 3 // Install BP 4 $config_file_path = getenv( 'WP_TESTS_DIR' ) . '/wp-tests-config.php'; 5 $multisite = (int) ( defined( 'WP_TESTS_MULTISITE') && WP_TESTS_MULTISITE ); 6 system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite ); 7 8 // Bootstrap BP 9 require dirname( __FILE__ ) . '/../../bp-loader.php'; -
new file tests/includes/testcase.php
diff --git tests/includes/testcase.php tests/includes/testcase.php new file mode 100644 index 0000000..3fb0dc3
- + 1 <?php 2 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 9 require_once dirname( __FILE__ ) . '/factory.php'; 10 11 class BP_UnitTestCase extends WP_UnitTestCase { 12 13 public function setUp() { 14 parent::setUp(); 15 $this->factory = new BP_UnitTest_Factory; 16 } 17 18 function clean_up_global_scope() { 19 buddypress()->bp_nav = buddypress()->bp_options_nav = buddypress()->action_variables = buddypress()->canonical_stack = buddypress()->unfiltered_uri = $GLOBALS['bp_unfiltered_uri'] = array(); 20 buddypress()->current_component = buddypress()->current_item = buddypress()->current_action = ''; 21 buddypress()->unfiltered_uri_offset = 0; 22 buddypress()->is_single_item = false; 23 buddypress()->current_user = new stdClass(); 24 buddypress()->displayed_user = new stdClass(); 25 buddypress()->loggedin_user = new stdClass(); 26 27 parent::clean_up_global_scope(); 28 } 29 30 function assertPreConditions() { 31 parent::assertPreConditions(); 32 33 // Reinit some of the globals that might have been cleared by BP_UnitTestCase::clean_up_global_scope(). 34 // This is here because it didn't work in clean_up_global_scope(); I don't know why. 35 do_action( 'bp_setup_globals' ); 36 } 37 38 function go_to( $url ) { 39 // Set this for bp_core_set_uri_globals() 40 $GLOBALS['_SERVER']['REQUEST_URI'] = $url = str_replace( network_home_url(), '', $url ); 41 42 // note: the WP and WP_Query classes like to silently fetch parameters 43 // from all over the place (globals, GET, etc), which makes it tricky 44 // to run them more than once without very carefully clearing everything 45 $_GET = $_POST = array(); 46 foreach (array('query_string', 'id', 'postdata', 'authordata', 'day', 'currentmonth', 'page', 'pages', 'multipage', 'more', 'numpages', 'pagenow') as $v) { 47 if ( isset( $GLOBALS[$v] ) ) unset( $GLOBALS[$v] ); 48 } 49 $parts = parse_url($url); 50 if (isset($parts['scheme'])) { 51 $req = $parts['path']; 52 if (isset($parts['query'])) { 53 $req .= '?' . $parts['query']; 54 // parse the url query vars into $_GET 55 parse_str($parts['query'], $_GET); 56 } 57 } else { 58 $req = $url; 59 } 60 if ( ! isset( $parts['query'] ) ) { 61 $parts['query'] = ''; 62 } 63 64 // Scheme 65 if ( 0 === strpos( $req, '/wp-admin' ) && force_ssl_admin() ) { 66 $_SERVER['HTTPS'] = 'on'; 67 } else { 68 unset( $_SERVER['HTTPS'] ); 69 } 70 71 $_SERVER['REQUEST_URI'] = $req; 72 unset($_SERVER['PATH_INFO']); 73 74 $this->flush_cache(); 75 unset($GLOBALS['wp_query'], $GLOBALS['wp_the_query']); 76 $GLOBALS['wp_the_query'] =& new WP_Query(); 77 $GLOBALS['wp_query'] =& $GLOBALS['wp_the_query']; 78 $GLOBALS['wp'] =& new WP(); 79 80 // clean out globals to stop them polluting wp and wp_query 81 foreach ($GLOBALS['wp']->public_query_vars as $v) { 82 unset($GLOBALS[$v]); 83 } 84 foreach ($GLOBALS['wp']->private_query_vars as $v) { 85 unset($GLOBALS[$v]); 86 } 87 88 $GLOBALS['wp']->main($parts['query']); 89 90 // For BuddyPress, James. 91 do_action( 'bp_init' ); 92 } 93 94 protected function checkRequirements() { 95 if ( WP_TESTS_FORCE_KNOWN_BUGS ) 96 return; 97 98 parent::checkRequirements(); 99 100 $tickets = PHPUnit_Util_Test::getTickets( get_class( $this ), $this->getName( false ) ); 101 foreach ( $tickets as $ticket ) { 102 if ( 'BP' == substr( $ticket, 0, 2 ) ) { 103 $ticket = substr( $ticket, 2 ); 104 if ( $ticket && is_numeric( $ticket ) ) 105 $this->knownBPBug( $ticket ); 106 } 107 } 108 } 109 110 /** 111 * Skips the current test if there is an open BuddyPress ticket with id $ticket_id 112 */ 113 function knownBPBug( $ticket_id ) { 114 if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( $ticket_id, self::$forced_tickets ) ) 115 return; 116 117 if ( ! TracTickets::isTracTicketClosed( 'http://buddypress.trac.wordpress.org', $ticket_id ) ) 118 $this->markTestSkipped( sprintf( 'BuddyPress Ticket #%d is not fixed', $ticket_id ) ); 119 } 120 121 /** 122 * WP's core tests use wp_set_current_user() to change the current 123 * user during tests. BP caches the current user differently, so we 124 * have to do a bit more work to change it 125 * 126 * @global BuddyPres $bp 127 */ 128 function set_current_user( $user_id ) { 129 global $bp; 130 $bp->loggedin_user->id = $user_id; 131 wp_set_current_user( $user_id ); 132 } 133 } -
new file tests/testcases/activity/class.BP_Activity_Activity.php
diff --git tests/testcases/activity/class.BP_Activity_Activity.php tests/testcases/activity/class.BP_Activity_Activity.php new file mode 100644 index 0000000..1b9bcd6
- + 1 <?php 2 /** 3 * @group activity 4 */ 5 class BP_Tests_Activity_Class extends BP_UnitTestCase { 6 protected $old_current_user = 0; 7 8 public function setUp() { 9 parent::setUp(); 10 11 $this->old_current_user = get_current_user_id(); 12 wp_set_current_user( $this->factory->user->create( array( 'role' => 'subscriber' ) ) ); 13 } 14 15 public function tearDown() { 16 parent::tearDown(); 17 wp_set_current_user( $this->old_current_user ); 18 } 19 20 public function test_check_exists_by_content() { 21 $content = 'A classy girl who know how to enjoy the freedom of a cup of coffee'; 22 $activity = $this->factory->activity->create( array( 23 'content' => $content, 24 'type' => 'activity_update', 25 ) ); 26 27 $result = BP_Activity_Activity::check_exists_by_content( $content ); 28 $this->assertEquals( $activity->id, $result ); 29 } 30 31 public function test_delete_activity_item_comments() { 32 $parent_activity = $this->factory->activity->create( array( 33 'type' => 'activity_update', 34 ) ); 35 36 $comments = $this->factory->activity->create_many( 3, array( 37 'item_id' => $parent_activity->id, 38 'type' => 'activity_comment', 39 ) ); 40 41 BP_Activity_Activity::delete_activity_item_comments( $parent_activity->id ); 42 43 $result = BP_Activity_Activity::get( array( 'in' => wp_list_pluck( $comments, 'id' ), ) ); 44 $this->assertEmpty( $result['activities'] ); 45 } 46 47 /** 48 * @ticket BP4765 49 */ 50 public function test_delete_activity_meta_entries() { 51 $activity = $this->factory->activity->create( array( 52 'type' => 'activity_update', 53 ) ); 54 55 bp_activity_update_meta( $activity->id, 'Paul', 'is cool' ); 56 BP_Activity_Activity::delete_activity_meta_entries( $activity->id ); 57 58 $meta = bp_activity_get_meta( $activity->id, 'Paul' ); 59 $this->assertFalse( $meta ); 60 } 61 62 public function test_hide_all_for_user() { 63 $activity = $this->factory->activity->create( array( 64 'type' => 'activity_update', 65 ) ); 66 67 BP_Activity_Activity::hide_all_for_user( get_current_user_id() ); 68 69 $activity = BP_Activity_Activity::get( array( 70 'in' => $activity->id, 71 'show_hidden' => true, 72 ) ); 73 $this->assertEquals( $activity['activities'][0]->hide_sitewide, 1 ); 74 } 75 } -
new file tests/testcases/activity/functions.php
diff --git tests/testcases/activity/functions.php tests/testcases/activity/functions.php new file mode 100644 index 0000000..d6dbd80
- + 1 <?php 2 /** 3 * @group activity 4 */ 5 class BP_Tests_Activity_Functions extends BP_UnitTestCase { 6 protected $old_current_user = 0; 7 8 public function setUp() { 9 parent::setUp(); 10 11 $this->old_current_user = get_current_user_id(); 12 wp_set_current_user( $this->factory->user->create( array( 'role' => 'subscriber' ) ) ); 13 } 14 15 public function tearDown() { 16 parent::tearDown(); 17 wp_set_current_user( $this->old_current_user ); 18 } 19 20 /** 21 * @ticket BP4488 22 */ 23 public function test_thumbnail_content_images() { 24 // No images 25 $post_content = 'foo bar'; 26 $this->assertEquals( bp_activity_thumbnail_content_images( $post_content ), 'foo bar' ); 27 28 // Image first, no caption. See #BP4488 29 $post_content = '<img src="http://example.com/foo.jpg" alt="foo" width="40" height="40" class="alignnone size-full wp-image-236" /> foo bar'; 30 $this->assertEquals( bp_activity_thumbnail_content_images( $post_content ), '<img src="http://example.com/foo.jpg" width="40" height="40" alt="Thumbnail" class="align-left thumbnail" /> foo bar' ); 31 32 // Image first, caption. See #BP4488 33 $post_content = '[caption id="attachment_236" align="alignnone" width="40"]<img src="http://example.com/foo.jpg" alt="FOO!" width="40" height="40" class="size-full wp-image-236" /> FOO![/caption] Awesome.'; 34 $this->assertEquals( bp_activity_thumbnail_content_images( $post_content ), '<img src="http://example.com/foo.jpg" width="40" height="40" alt="Thumbnail" class="align-left thumbnail" /> Awesome.' ); 35 } 36 37 } -
new file tests/testcases/activity/template.php
diff --git tests/testcases/activity/template.php tests/testcases/activity/template.php new file mode 100644 index 0000000..f7f9274
- + 1 <?php 2 /** 3 * @group activity 4 */ 5 class BP_Tests_Activity_Template extends BP_UnitTestCase { 6 protected $old_current_user = 0; 7 8 public function setUp() { 9 parent::setUp(); 10 11 $this->old_current_user = get_current_user_id(); 12 $this->set_current_user( $this->factory->user->create( array( 'role' => 'subscriber' ) ) ); 13 } 14 15 public function tearDown() { 16 parent::tearDown(); 17 $this->set_current_user( $this->old_current_user ); 18 } 19 20 /** 21 * @ticket BP4735 22 */ 23 public function test_user_can_delete() { 24 global $bp; 25 26 $activity = $this->factory->activity->create( array( 27 'type' => 'activity_update', 28 ) ); 29 30 // User can delete his own items 31 $this->assertTrue( bp_activity_user_can_delete( $activity ) ); 32 33 // Stash original user 34 $original_user = get_current_user_id(); 35 36 // Logged-out user can't delete 37 $this->set_current_user( 0 ); 38 $this->assertFalse( bp_activity_user_can_delete( $activity ) ); 39 40 // Miscellaneous user can't delete 41 $misc_user = $this->factory->user->create( array( 'role' => 'subscriber' ) ); 42 $this->set_current_user( $misc_user ); 43 $this->assertFalse( bp_activity_user_can_delete( $activity ) ); 44 45 // Item admin can delete 46 $is_single_item = $bp->is_single_item; 47 $bp->is_single_item = true; 48 49 $is_item_admin = $bp->is_item_admin; 50 $bp->is_item_admin = true; 51 52 $this->assertTrue( bp_activity_user_can_delete( $activity ) ); 53 54 $bp->is_single_item = $is_single_item; 55 $bp->is_item_admin = $is_item_admin; 56 $this->set_current_user( $original_user ); 57 } 58 59 } -
new file tests/testcases/admin/functions.php
diff --git tests/testcases/admin/functions.php tests/testcases/admin/functions.php new file mode 100644 index 0000000..6d36628
- + 1 <?php 2 /** 3 * @group admin 4 */ 5 class BP_Tests_Admin_Functions extends BP_UnitTestCase { 6 protected $old_current_user = 0; 7 8 public function setUp() { 9 parent::setUp(); 10 11 $this->old_current_user = get_current_user_id(); 12 wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); 13 14 if ( ! function_exists( 'bp_admin' ) ) { 15 require_once( BP_PLUGIN_DIR . 'bp-core/bp-core-admin.php' ); 16 } 17 18 if ( ! function_exists( 'bp_new_site' ) ) { 19 bp_admin(); 20 } 21 } 22 23 public function tearDown() { 24 parent::tearDown(); 25 wp_set_current_user( $this->old_current_user ); 26 } 27 28 public function test_bp_admin_list_table_current_bulk_action() { 29 $_REQUEST['action'] = 'foo'; 30 $_REQUEST['action2'] = '-1'; 31 $this->assertEquals( bp_admin_list_table_current_bulk_action(), 'foo' ); 32 33 $_REQUEST['action'] = '-1'; 34 $_REQUEST['action2'] = 'foo'; 35 $this->assertEquals( bp_admin_list_table_current_bulk_action(), 'foo' ); 36 37 $_REQUEST['action'] = 'bar'; 38 $_REQUEST['action2'] = 'foo'; 39 $this->assertEquals( bp_admin_list_table_current_bulk_action(), 'foo' ); 40 } 41 42 public function test_bp_core_admin_get_active_components_from_submitted_settings() { 43 $get_action = isset( $_GET['action'] ) ? $_GET['action'] : null; 44 $ac = buddypress()->active_components; 45 46 // Standard deactivation from All screen 47 unset( $_GET['action'] ); 48 buddypress()->active_components = array( 49 'activity' => 1, 50 'friends' => 1, 51 'groups' => 1, 52 'members' => 1, 53 'messages' => 1, 54 'settings' => 1, 55 'xprofile' => 1, 56 ); 57 58 $submitted = array( 59 'groups' => 1, 60 'members' => 1, 61 'messages' => 1, 62 'settings' => 1, 63 'xprofile' => 1, 64 ); 65 66 $this->assertEquals( bp_core_admin_get_active_components_from_submitted_settings( $submitted ), array( 'groups' => 1, 'members' => 1, 'messages' => 1, 'settings' => 1, 'xprofile' => 1 ) ); 67 68 // Activating deactivated components from the Inactive screen 69 $_GET['action'] = 'inactive'; 70 buddypress()->active_components = array( 71 'activity' => 1, 72 'members' => 1, 73 'messages' => 1, 74 'settings' => 1, 75 'xprofile' => 1, 76 ); 77 78 $submitted2 = array( 79 'groups' => 1, 80 ); 81 82 $this->assertEquals( bp_core_admin_get_active_components_from_submitted_settings( $submitted2 ), array( 'activity' => 1, 'groups' => 1, 'members' => 1, 'messages' => 1, 'settings' => 1, 'xprofile' => 1 ) ); 83 84 // Activating from the Retired screen 85 $_GET['action'] = 'retired'; 86 buddypress()->active_components = array( 87 'activity' => 1, 88 'members' => 1, 89 'messages' => 1, 90 'settings' => 1, 91 'xprofile' => 1, 92 ); 93 94 $submitted3 = array( 95 'forums' => 1, 96 ); 97 98 $this->assertEquals( bp_core_admin_get_active_components_from_submitted_settings( $submitted3 ), array( 'activity' => 1, 'forums' => 1, 'members' => 1, 'messages' => 1, 'settings' => 1, 'xprofile' => 1 ) ); 99 100 // Deactivating from the Retired screen 101 $_GET['action'] = 'retired'; 102 buddypress()->active_components = array( 103 'activity' => 1, 104 'forums' => 1, 105 'members' => 1, 106 'messages' => 1, 107 'settings' => 1, 108 'xprofile' => 1, 109 ); 110 111 $submitted4 = array(); 112 113 $this->assertEquals( bp_core_admin_get_active_components_from_submitted_settings( $submitted4 ), array( 'activity' => 1, 'members' => 1, 'messages' => 1, 'settings' => 1, 'xprofile' => 1 ) ); 114 115 // reset 116 if ( $get_action ) { 117 $_GET['action'] = $get_action; 118 } else { 119 unset( $_GET['action'] ); 120 } 121 122 buddypress()->active_components = $ac; 123 } 124 } -
new file tests/testcases/routing/activity.php
diff --git tests/testcases/routing/activity.php tests/testcases/routing/activity.php new file mode 100644 index 0000000..fe1b271
- + 1 <?php 2 /** 3 * @group activity 4 * @group routing 5 */ 6 class BP_Tests_Routing_Activity extends BP_UnitTestCase { 7 protected $old_current_user = 0; 8 9 public function setUp() { 10 parent::setUp(); 11 12 $this->old_current_user = get_current_user_id(); 13 wp_set_current_user( $this->factory->user->create( array( 'role' => 'subscriber' ) ) ); 14 } 15 16 public function tearDown() { 17 parent::tearDown(); 18 wp_set_current_user( $this->old_current_user ); 19 } 20 21 function test_activity_directory() { 22 $this->go_to( bp_get_activity_directory_permalink() ); 23 $this->assertEquals( bp_get_activity_root_slug(), bp_current_component() ); 24 } 25 26 /** 27 * Can't test using bp_activity_get_permalink(); see bp_activity_action_permalink_router(). 28 */ 29 function test_activity_permalink() { 30 $activity = $this->factory->activity->create(); 31 32 $url = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/'; 33 $this->go_to( $url ); 34 $this->assertTrue( bp_is_single_activity() ); 35 } 36 37 function test_member_activity() { 38 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_activity_slug() ); 39 $this->assertTrue( bp_is_user_activity() ); 40 } 41 42 function test_member_activity_mentions() { 43 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_activity_slug() . '/mentions' ); 44 $this->assertTrue( bp_is_user_activity() ); 45 } 46 47 function test_member_activity_favourites() { 48 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_activity_slug() . '/favorites' ); 49 $this->assertTrue( bp_is_user_activity() ); 50 } 51 52 /** 53 * @group friends 54 */ 55 function test_member_activity_friends() { 56 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_activity_slug() . '/' . bp_get_friends_slug() ); 57 $this->assertTrue( bp_is_user_friends_activity() ); 58 } 59 60 /** 61 * @group groups 62 */ 63 function test_member_activity_groups() { 64 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_activity_slug() . '/' . bp_get_groups_slug() ); 65 $this->assertTrue( bp_is_user_groups_activity() ); 66 } 67 } -
new file tests/testcases/routing/anonymous.php
diff --git tests/testcases/routing/anonymous.php tests/testcases/routing/anonymous.php new file mode 100644 index 0000000..bfabb5a
- + 1 <?php 2 /** 3 * @group routing 4 */ 5 class BP_Tests_Routing_Anonymous extends BP_UnitTestCase { 6 7 function test_wordpress_page() { 8 $this->go_to( '/' ); 9 $this->assertEmpty( bp_current_component() ); 10 } 11 12 function test_nav_menu() { 13 $this->go_to( '/' ); 14 $this->assertEmpty( buddypress()->bp_nav ); 15 } 16 } -
new file tests/testcases/routing/core.php
diff --git tests/testcases/routing/core.php tests/testcases/routing/core.php new file mode 100644 index 0000000..68a1dfa
- + 1 <?php 2 /** 3 * @group core 4 * @group routing 5 */ 6 class BP_Tests_Routing_Core extends BP_UnitTestCase { 7 protected $old_current_user = 0; 8 9 public function setUp() { 10 parent::setUp(); 11 12 $this->old_current_user = get_current_user_id(); 13 wp_set_current_user( $this->factory->user->create( array( 'role' => 'subscriber' ) ) ); 14 } 15 16 public function tearDown() { 17 parent::tearDown(); 18 wp_set_current_user( $this->old_current_user ); 19 } 20 21 function test_wordpress_page() { 22 $this->go_to( '/' ); 23 $this->assertEmpty( bp_current_component() ); 24 } 25 26 function test_nav_menu() { 27 $this->go_to( '/' ); 28 $this->assertArrayHasKey( 'activity', buddypress()->bp_nav ); 29 $this->assertArrayHasKey( 'profile', buddypress()->bp_nav ); 30 } 31 } -
new file tests/testcases/routing/friends.php
diff --git tests/testcases/routing/friends.php tests/testcases/routing/friends.php new file mode 100644 index 0000000..2f6fa82
- + 1 <?php 2 /** 3 * @group friends 4 * @group routing 5 */ 6 class BP_Tests_Routing_Friends extends BP_UnitTestCase { 7 protected $old_current_user = 0; 8 9 public function setUp() { 10 parent::setUp(); 11 12 $this->old_current_user = get_current_user_id(); 13 wp_set_current_user( $this->factory->user->create( array( 'role' => 'subscriber' ) ) ); 14 } 15 16 public function tearDown() { 17 parent::tearDown(); 18 wp_set_current_user( $this->old_current_user ); 19 } 20 21 function test_member_friends() { 22 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_friends_slug() ); 23 $this->assertTrue( bp_is_user_friends() ); 24 } 25 26 function test_member_friends_requests() { 27 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_friends_slug() . '/requests' ); 28 $this->assertTrue( bp_is_user_friend_requests() ); 29 } 30 } -
new file tests/testcases/routing/groups.php
diff --git tests/testcases/routing/groups.php tests/testcases/routing/groups.php new file mode 100644 index 0000000..9d0c8ac
- + 1 <?php 2 /** 3 * @group groups 4 * @group routing 5 */ 6 class BP_Tests_Routing_Groups extends BP_UnitTestCase { 7 protected $old_current_user = 0; 8 9 public function setUp() { 10 parent::setUp(); 11 12 $this->old_current_user = get_current_user_id(); 13 wp_set_current_user( $this->factory->user->create( array( 'role' => 'subscriber' ) ) ); 14 } 15 16 public function tearDown() { 17 parent::tearDown(); 18 wp_set_current_user( $this->old_current_user ); 19 } 20 21 function test_member_groups() { 22 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_groups_slug() ); 23 $this->assertTrue( bp_is_user_groups() ); 24 } 25 26 function test_member_groups_invitations() { 27 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_groups_slug() . '/invites' ); 28 $this->assertTrue( bp_is_user_groups() && bp_is_current_action( 'invites' ) ); 29 } 30 } -
new file tests/testcases/routing/members.php
diff --git tests/testcases/routing/members.php tests/testcases/routing/members.php new file mode 100644 index 0000000..a705d6e
- + 1 <?php 2 /** 3 * @group members 4 * @group routing 5 */ 6 class BP_Tests_Routing_Members extends BP_UnitTestCase { 7 protected $old_current_user = 0; 8 9 public function setUp() { 10 parent::setUp(); 11 12 $this->old_current_user = get_current_user_id(); 13 wp_set_current_user( $this->factory->user->create( array( 'user_login' => 'paulgibbs', 'role' => 'subscriber' ) ) ); 14 } 15 16 public function tearDown() { 17 parent::tearDown(); 18 wp_set_current_user( $this->old_current_user ); 19 } 20 21 function test_members_directory() { 22 $this->go_to( bp_get_members_directory_permalink() ); 23 $this->assertEquals( bp_get_members_root_slug(), bp_current_component() ); 24 } 25 26 function test_member_permalink() { 27 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) ); 28 $this->assertTrue( bp_is_my_profile() ); 29 } 30 } -
new file tests/testcases/routing/messages.php
diff --git tests/testcases/routing/messages.php tests/testcases/routing/messages.php new file mode 100644 index 0000000..bf10cd8
- + 1 <?php 2 /** 3 * @group messages 4 * @group routing 5 */ 6 class BP_Tests_Routing_Messages extends BP_UnitTestCase { 7 protected $old_current_user = 0; 8 9 public function setUp() { 10 parent::setUp(); 11 12 $this->old_current_user = get_current_user_id(); 13 wp_set_current_user( $this->factory->user->create( array( 'role' => 'subscriber' ) ) ); 14 } 15 16 public function tearDown() { 17 parent::tearDown(); 18 wp_set_current_user( $this->old_current_user ); 19 } 20 21 function test_member_messages() { 22 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_messages_slug() ); 23 $this->assertTrue( bp_is_messages_inbox() ); 24 } 25 26 function test_member_messages_sentbox() { 27 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_messages_slug() . '/sentbox' ); 28 $this->assertTrue( bp_is_messages_sentbox() ); 29 } 30 31 function test_member_messages_compose() { 32 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_messages_slug() . '/compose' ); 33 $this->assertTrue( bp_is_messages_compose_screen() ); 34 } 35 36 function test_member_messages_notices() { 37 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_messages_slug() . '/notices' ); 38 $this->assertTrue( bp_is_notices() ); 39 } 40 } -
new file tests/testcases/routing/settings.php
diff --git tests/testcases/routing/settings.php tests/testcases/routing/settings.php new file mode 100644 index 0000000..f205f9a
- + 1 <?php 2 /** 3 * @group settings 4 * @group routing 5 */ 6 class BP_Tests_Routing_Settings extends BP_UnitTestCase { 7 protected $old_current_user = 0; 8 9 public function setUp() { 10 parent::setUp(); 11 12 $this->old_current_user = get_current_user_id(); 13 wp_set_current_user( $this->factory->user->create( array( 'role' => 'subscriber' ) ) ); 14 } 15 16 public function tearDown() { 17 parent::tearDown(); 18 wp_set_current_user( $this->old_current_user ); 19 } 20 21 function test_member_settings() { 22 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_settings_slug() ); 23 $this->assertTrue( bp_is_user_settings_general() ); 24 } 25 26 function test_member_settings_notifications() { 27 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_settings_slug() . '/notifications' ); 28 $this->assertTrue( bp_is_user_settings_notifications() ); 29 } 30 31 // @todo How best to test this? 32 /*function bp_is_user_settings_account_capbilities() { 33 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_settings_slug() . '/capabilities' ); 34 }*/ 35 36 function bp_is_user_settings_account_delete() { 37 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_settings_slug() . '/delete-account' ); 38 $this->assertTrue( bp_is_user_settings_account_delete() ); 39 } 40 } -
new file tests/testcases/routing/xprofile.php
diff --git tests/testcases/routing/xprofile.php tests/testcases/routing/xprofile.php new file mode 100644 index 0000000..93316bb
- + 1 <?php 2 /** 3 * @group xprofile 4 * @group routing 5 */ 6 class BP_Tests_Routing_XProfile extends BP_UnitTestCase { 7 protected $old_current_user = 0; 8 9 public function setUp() { 10 parent::setUp(); 11 12 $this->old_current_user = get_current_user_id(); 13 wp_set_current_user( $this->factory->user->create( array( 'role' => 'subscriber' ) ) ); 14 } 15 16 public function tearDown() { 17 parent::tearDown(); 18 wp_set_current_user( $this->old_current_user ); 19 } 20 21 function test_member_profile() { 22 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . buddypress()->profile->slug ); 23 $this->assertTrue( bp_is_user_profile() ); 24 } 25 26 function test_member_profile_edit() { 27 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . buddypress()->profile->slug . '/edit' ); 28 $this->assertTrue( bp_is_user_profile_edit() ); 29 } 30 31 function test_member_profile_change_avatar() { 32 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . buddypress()->profile->slug . '/change-avatar' ); 33 $this->assertTrue( bp_is_user_change_avatar() ); 34 } 35 } -
new file tests/testcases/url/url.php
diff --git tests/testcases/url/url.php tests/testcases/url/url.php new file mode 100644 index 0000000..809b523
- + 1 <?php 2 /** 3 * @group url 4 */ 5 class BP_Tests_URL extends BP_UnitTestCase { 6 protected $old_current_user = 0; 7 8 public function setUp() { 9 parent::setUp(); 10 11 $this->old_current_user = get_current_user_id(); 12 wp_set_current_user( $this->factory->user->create( array( 'role' => 'subscriber' ) ) ); 13 } 14 15 public function tearDown() { 16 parent::tearDown(); 17 wp_set_current_user( $this->old_current_user ); 18 } 19 20 function test_bp_core_ajax_url() { 21 $forced = force_ssl_admin(); 22 23 // (1) HTTPS off 24 force_ssl_admin( false ); 25 $_SERVER['HTTPS'] = 'off'; 26 27 // (1a) Front-end 28 $this->go_to( '/' ); 29 $this->assertEquals( bp_core_ajax_url(), 'http://example.org/wp-admin/admin-ajax.php' ); 30 31 // (1b) Dashboard 32 $this->go_to( '/wp-admin' ); 33 $this->assertEquals( bp_core_ajax_url(), 'http://example.org/wp-admin/admin-ajax.php' ); 34 35 // (2) FORCE_SSL_ADMIN 36 force_ssl_admin( true ); 37 38 // (2a) Front-end 39 $this->go_to( '/' ); 40 $this->assertEquals( bp_core_ajax_url(), 'http://example.org/wp-admin/admin-ajax.php' ); 41 42 // (2b) Dashboard 43 $this->go_to( '/wp-admin' ); 44 $this->assertEquals( bp_core_ajax_url(), 'https://example.org/wp-admin/admin-ajax.php' ); 45 46 force_ssl_admin( $forced ); 47 48 // (3) Multisite, root blog other than 1 49 if ( is_multisite() ) { 50 $original_root_blog = bp_get_root_blog_id(); 51 $blog_id = $this->factory->blog->create(); 52 buddypress()->root_blog_id = $blog_id; 53 54 switch_to_blog( $blog_id ); 55 $blog_details = get_blog_details(); 56 57 $this->go_to( '/' ); 58 $this->assertEquals( bp_core_ajax_url(), $blog_details->siteurl . '/wp-admin/admin-ajax.php' ); 59 60 restore_current_blog(); 61 buddypress()->root_blog_id = $original_root_blog; 62 } 63 64 } 65 }