[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
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 $this->old_current_user = get_current_user_id(); 11 $this->set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); 12 13 if ( ! function_exists( 'bp_admin' ) ) { 14 require_once( BP_PLUGIN_DIR . 'bp-core/bp-core-admin.php' ); 15 } 16 17 if ( ! function_exists( 'bp_new_site' ) ) { 18 bp_admin(); 19 } 20 } 21 22 public function tearDown() { 23 parent::tearDown(); 24 $this->set_current_user( $this->old_current_user ); 25 } 26 27 public function test_bp_admin_list_table_current_bulk_action() { 28 $_REQUEST['action'] = 'foo'; 29 $_REQUEST['action2'] = '-1'; 30 $this->assertEquals( bp_admin_list_table_current_bulk_action(), 'foo' ); 31 32 $_REQUEST['action'] = '-1'; 33 $_REQUEST['action2'] = 'foo'; 34 $this->assertEquals( bp_admin_list_table_current_bulk_action(), 'foo' ); 35 36 $_REQUEST['action'] = 'bar'; 37 $_REQUEST['action2'] = 'foo'; 38 $this->assertEquals( bp_admin_list_table_current_bulk_action(), 'foo' ); 39 } 40 41 /** 42 * @group bp_core_admin_get_active_components_from_submitted_settings 43 */ 44 public function test_bp_core_admin_get_active_components_from_submitted_settings() { 45 $get_action = isset( $_GET['action'] ) ? $_GET['action'] : null; 46 $ac = buddypress()->active_components; 47 48 // Standard deactivation from All screen 49 unset( $_GET['action'] ); 50 buddypress()->active_components = array( 51 'activity' => 1, 52 'friends' => 1, 53 'groups' => 1, 54 'members' => 1, 55 'messages' => 1, 56 'settings' => 1, 57 'xprofile' => 1, 58 ); 59 60 $submitted = array( 61 'groups' => 1, 62 'members' => 1, 63 'messages' => 1, 64 'settings' => 1, 65 'xprofile' => 1, 66 ); 67 68 $this->assertEquals( bp_core_admin_get_active_components_from_submitted_settings( $submitted ), array( 'groups' => 1, 'members' => 1, 'messages' => 1, 'settings' => 1, 'xprofile' => 1 ) ); 69 70 // Activating deactivated components from the Inactive screen 71 $_GET['action'] = 'inactive'; 72 buddypress()->active_components = array( 73 'activity' => 1, 74 'members' => 1, 75 'messages' => 1, 76 'settings' => 1, 77 'xprofile' => 1, 78 ); 79 80 $submitted2 = array( 81 'groups' => 1, 82 ); 83 84 $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 ) ); 85 86 // Deactivating from the Retired screen 87 $_GET['action'] = 'retired'; 88 buddypress()->active_components = array( 89 'activity' => 1, 90 'members' => 1, 91 'messages' => 1, 92 'settings' => 1, 93 'xprofile' => 1, 94 ); 95 96 $submitted4 = array(); 97 98 $this->assertEquals( bp_core_admin_get_active_components_from_submitted_settings( $submitted4 ), array( 'activity' => 1, 'members' => 1, 'messages' => 1, 'settings' => 1, 'xprofile' => 1 ) ); 99 100 // reset 101 if ( $get_action ) { 102 $_GET['action'] = $get_action; 103 } else { 104 unset( $_GET['action'] ); 105 } 106 107 buddypress()->active_components = $ac; 108 } 109 110 /** 111 * @group BP6244 112 * @group bp_core_admin_get_active_components_from_submitted_settings 113 */ 114 public function test_bp_core_admin_get_active_components_from_submitted_settings_should_keep_custom_component_directory_page() { 115 $bp = buddypress(); 116 $reset_active_components = $bp->active_components; 117 118 // Create and activate the foo component 119 $bp->foo = new BP_Component; 120 $bp->foo->id = 'foo'; 121 $bp->foo->slug = 'foo'; 122 $bp->foo->name = 'Foo'; 123 $bp->active_components[ $bp->foo->id ] = 1; 124 $new_page_ids = array( $bp->foo->id => self::factory()->post->create( array( 125 'post_type' => 'page', 126 'post_title' => $bp->foo->name, 127 'post_name' => $bp->foo->slug, 128 ) ) ); 129 130 $page_ids = array_merge( $new_page_ids, bp_core_get_directory_page_ids( 'all' ) ); 131 bp_core_update_directory_page_ids( $page_ids ); 132 133 $bp->active_components = bp_core_admin_get_active_components_from_submitted_settings( $reset_active_components ); 134 bp_core_add_page_mappings( $bp->active_components ); 135 136 $this->assertContains( $bp->foo->id, array_keys( bp_core_get_directory_page_ids( 'all' ) ) ); 137 138 // Reset buddypress() vars 139 $bp->active_components = $reset_active_components; 140 } 141 142 /** 143 * @group bp_core_activation_notice 144 */ 145 public function test_bp_core_activation_notice_register_activate_pages_notcreated_signup_allowed() { 146 $bp = buddypress(); 147 $reset_bp_pages = $bp->pages; 148 $reset_admin_notices = $bp->admin->notices; 149 150 // Reset pages 151 $bp->pages = bp_core_get_directory_pages(); 152 153 add_filter( 'bp_get_signup_allowed', '__return_true', 999 ); 154 155 bp_core_activation_notice(); 156 157 remove_filter( 'bp_get_signup_allowed', '__return_true', 999 ); 158 159 $missing_pages = array(); 160 foreach( buddypress()->admin->notices as $notice ) { 161 preg_match_all( '/<strong>(.+?)<\/strong>/', $notice['message'], $missing_pages ); 162 } 163 164 $this->assertContains( 'Register', $missing_pages[1] ); 165 $this->assertContains( 'Activate', $missing_pages[1] ); 166 167 // Reset buddypress() vars 168 $bp->pages = $reset_bp_pages; 169 $bp->admin->notices = $reset_admin_notices; 170 } 171 172 /** 173 * @group bp_core_activation_notice 174 */ 175 public function test_bp_core_activation_notice_register_activate_pages_created_signup_allowed() { 176 $bp = buddypress(); 177 $reset_bp_pages = $bp->pages; 178 $reset_admin_notices = $bp->admin->notices; 179 180 add_filter( 'bp_get_signup_allowed', '__return_true', 999 ); 181 182 $ac = buddypress()->active_components; 183 bp_core_add_page_mappings( array_keys( $ac ) ); 184 185 // Reset pages 186 $bp->pages = bp_core_get_directory_pages(); 187 188 bp_core_activation_notice(); 189 190 remove_filter( 'bp_get_signup_allowed', '__return_true', 999 ); 191 192 $missing_pages = array(); 193 foreach( buddypress()->admin->notices as $notice ) { 194 if ( false !== strpos( $notice['message'], 'BuddyPress is almost ready' ) ) { 195 continue; 196 } 197 198 preg_match_all( '/<strong>(.+?)<\/strong>/', $notice['message'], $missing_pages ); 199 } 200 201 $this->assertEmpty( $missing_pages ); 202 203 // Reset buddypress() vars 204 $bp->pages = $reset_bp_pages; 205 $bp->admin->notices = $reset_admin_notices; 206 } 207 208 /** 209 * @ticket BP6936 210 */ 211 public function test_email_type_descriptions_should_match_when_split_terms_exist() { 212 global $wpdb; 213 214 // Delete all existing email types and descriptions. 215 $emails = get_posts( array( 216 'fields' => 'ids', 217 'post_type' => bp_get_email_post_type(), 218 ) ); 219 foreach ( $emails as $email ) { 220 wp_delete_post( $email, true ); 221 } 222 223 $descriptions = get_terms( bp_get_email_tax_type(), array( 224 'fields' => 'ids', 225 'hide_empty' => false, 226 ) ); 227 foreach ( $descriptions as $description ) { 228 wp_delete_term( (int) $description, bp_get_email_tax_type() ); 229 } 230 231 // Fake the existence of split terms by offsetting the term_taxonomy table. 232 $wpdb->insert( $wpdb->term_taxonomy, array( 'term_id' => 9999, 'taxonomy' => 'post_tag', 'description' => 'foo description', 'parent' => 0, 'count' => 0 ) ); 233 234 require_once( BP_PLUGIN_DIR . '/bp-core/admin/bp-core-admin-schema.php' ); 235 bp_core_install_emails(); 236 237 $d_terms = get_terms( bp_get_email_tax_type(), array( 238 'hide_empty' => false, 239 ) ); 240 241 $correct_descriptions = bp_email_get_type_schema( 'description' ); 242 foreach ( $d_terms as $d_term ) { 243 $correct_description = $correct_descriptions[ $d_term->slug ]; 244 $this->assertSame( $correct_description, $d_term->description ); 245 } 246 } 247 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sat Dec 7 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |