[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/core/functions/ -> bpCoreGetDirectoryPageIds.php (source)

   1  <?php
   2  
   3  /**
   4   * @group core
   5   * @covers ::bp_core_get_directory_page_ids
   6   */
   7  class BP_Tests_Core_Functions_BpCoreGetDirectoryPageIds extends BP_UnitTestCase {
   8      public function test_bp_core_get_directory_page_ids_on_directory_page_to_trash() {
   9          $old_page_ids = bp_core_get_directory_page_ids();
  10  
  11          // Grab the and remove the first page.
  12          foreach ( $old_page_ids as $component => $page_id ) {
  13              $p = $page_id;
  14              unset( $old_page_ids[ $component ] );
  15              break;
  16          }
  17  
  18          // Move page to trash.
  19          wp_delete_post( $p, false );
  20  
  21          $new_page_ids = bp_core_get_directory_page_ids();
  22  
  23          $this->assertEquals( $old_page_ids, $new_page_ids );
  24      }
  25  
  26      public function test_bp_core_get_directory_page_ids_on_directory_page_delete() {
  27          $old_page_ids = bp_core_get_directory_page_ids();
  28  
  29          // Grab the and remove the first page.
  30          foreach ( $old_page_ids as $component => $page_id ) {
  31              $p = $page_id;
  32              unset( $old_page_ids[ $component ] );
  33              break;
  34          }
  35  
  36          // Force delete page.
  37          wp_delete_post( $p, true );
  38  
  39          $new_page_ids = bp_core_get_directory_page_ids();
  40  
  41          $this->assertEquals( $old_page_ids, $new_page_ids );
  42      }
  43  
  44      public function test_bp_core_get_directory_page_ids_on_non_directory_page_delete() {
  45          $old_page_ids = bp_core_get_directory_page_ids();
  46  
  47          $p = self::factory()->post->create( array(
  48              'post_status' => 'publish',
  49              'post_type' => 'page',
  50          ) );
  51  
  52          // Force delete page.
  53          wp_delete_post( $p, true );
  54  
  55          $new_page_ids = bp_core_get_directory_page_ids();
  56  
  57          $this->assertEquals( $old_page_ids, $new_page_ids );
  58      }
  59  
  60      public function test_bp_core_get_directory_page_ids_non_active_component() {
  61          $old_page_ids = bp_core_get_directory_page_ids();
  62          $bp = buddypress();
  63  
  64          // Grab the and remove the first page.
  65          foreach ( $old_page_ids as $component => $page_id ) {
  66              $p = $page_id;
  67              $c = $component;
  68              unset( $old_page_ids[ $component ] );
  69              break;
  70          }
  71  
  72          // Deactivate component.
  73          unset( $bp->active_components[ $c ] );
  74  
  75          $new_page_ids = bp_core_get_directory_page_ids();
  76  
  77          // Restore components.
  78          $bp->active_components[ $c ] = 1;
  79  
  80          $this->assertEquals( $old_page_ids, $new_page_ids );
  81      }
  82  
  83      /**
  84       * @ticket BP6280
  85       */
  86      public function test_inactive_components_should_not_be_removed_if_status_is_all() {
  87          $old_page_ids = bp_core_get_directory_page_ids( 'all' );
  88  
  89          $page_ids = $old_page_ids;
  90          $page_ids['foo'] = 12345;
  91  
  92          bp_core_update_directory_page_ids( $page_ids );
  93          $found = bp_core_get_directory_page_ids( 'all' );
  94  
  95          $this->assertEquals( 12345, $found['foo'] );
  96      }
  97  
  98      /**
  99       * @ticket BP6280
 100       */
 101      public function test_inactive_components_should_be_removed_if_status_is_active() {
 102          $old_page_ids = bp_core_get_directory_page_ids( 'all' );
 103  
 104          $page_ids = $old_page_ids;
 105          $page_ids['foo'] = 12345;
 106  
 107          bp_core_update_directory_page_ids( $page_ids );
 108          $found = bp_core_get_directory_page_ids( 'active' );
 109  
 110          $this->assertFalse( isset( $found['foo'] ) );
 111      }
 112  
 113      /**
 114       * @ticket BP6280
 115       */
 116      public function test_inactive_components_should_be_removed_if_status_is_unspecified() {
 117          $old_page_ids = bp_core_get_directory_page_ids( 'all' );
 118  
 119          $page_ids = $old_page_ids;
 120          $page_ids['foo'] = 12345;
 121  
 122          bp_core_update_directory_page_ids( $page_ids );
 123          $found = bp_core_get_directory_page_ids( 'active' );
 124  
 125          $this->assertFalse( isset( $found['foo'] ) );
 126      }
 127  
 128      public function test_bp_core_get_directory_page_ids_should_contain_register_and_activet_pages_when_registration_is_open() {
 129          add_filter( 'bp_get_signup_allowed', '__return_true', 999 );
 130  
 131          $ac = buddypress()->active_components;
 132          bp_core_add_page_mappings( array_keys( $ac ) );
 133  
 134          $page_ids = bp_core_get_directory_page_ids();
 135          $page_names = array_keys( $page_ids );
 136  
 137          $this->assertContains( 'register', $page_names );
 138          $this->assertContains( 'activate', $page_names );
 139  
 140          remove_filter( 'bp_get_signup_allowed', '__return_true', 999 );
 141      }
 142  
 143      public function test_bp_core_get_directory_page_ids_should_not_contain_register_and_activet_pages_when_registration_is_closed() {
 144  
 145          // Make sure the pages exist, to verify they're filtered out.
 146          add_filter( 'bp_get_signup_allowed', '__return_true', 999 );
 147          $ac = buddypress()->active_components;
 148          bp_core_add_page_mappings( array_keys( $ac ) );
 149          remove_filter( 'bp_get_signup_allowed', '__return_true', 999 );
 150  
 151          // Get page ids
 152          $page_ids = bp_core_get_directory_page_ids();
 153  
 154          // Need to delete these pages as previously created.
 155          wp_delete_post( $page_ids['register'], true );
 156          wp_delete_post( $page_ids['activate'], true );
 157  
 158          add_filter( 'bp_get_signup_allowed', '__return_false', 999 );
 159          bp_core_add_page_mappings( array_keys( $ac ) );
 160          $page_ids = bp_core_get_directory_page_ids();
 161          remove_filter( 'bp_get_signup_allowed', '__return_false', 999 );
 162  
 163          $page_names = array_keys( $page_ids );
 164  
 165          $this->assertNotContains( 'register', $page_names );
 166          $this->assertNotContains( 'activate', $page_names );
 167      }
 168  
 169      public function test_bp_core_get_directory_pages_register_activate_page_created_signups_allowed() {
 170          add_filter( 'bp_get_signup_allowed', '__return_true', 999 );
 171  
 172          $ac = buddypress()->active_components;
 173          bp_core_add_page_mappings( array_keys( $ac ) );
 174          $directory_pages = bp_core_get_directory_pages();
 175  
 176          remove_filter( 'bp_get_signup_allowed', '__return_true', 999 );
 177  
 178          $this->assertTrue( isset( $directory_pages->register ) );
 179          $this->assertTrue( isset( $directory_pages->activate ) );
 180  
 181          $r = get_post( $directory_pages->register->id );
 182          $this->assertTrue( 'publish' == $r->post_status );
 183  
 184          $a = get_post( $directory_pages->activate->id );
 185          $this->assertTrue( 'publish' == $a->post_status );
 186      }
 187  
 188      public function test_bp_core_get_directory_pages_register_activate_page_notcreated_signups_allowed() {
 189          add_filter( 'bp_get_signup_allowed', '__return_false', 999 );
 190  
 191          $ac = buddypress()->active_components;
 192          bp_core_add_page_mappings( array_keys( $ac ) );
 193  
 194          remove_filter( 'bp_get_signup_allowed', '__return_false', 999 );
 195  
 196          add_filter( 'bp_get_signup_allowed', '__return_true', 999 );
 197  
 198          $directory_pages = bp_core_get_directory_pages();
 199  
 200          remove_filter( 'bp_get_signup_allowed', '__return_true', 999 );
 201  
 202          $this->assertFalse( isset( $directory_pages->register ) );
 203          $this->assertFalse( isset( $directory_pages->activate ) );
 204      }
 205  
 206      public function test_bp_core_get_directory_pages_register_activate_page_created_signups_notallowed() {
 207          add_filter( 'bp_get_signup_allowed', '__return_true', 999 );
 208  
 209          $ac = buddypress()->active_components;
 210          bp_core_add_page_mappings( array_keys( $ac ) );
 211  
 212          remove_filter( 'bp_get_signup_allowed', '__return_true', 999 );
 213  
 214          add_filter( 'bp_get_signup_allowed', '__return_false', 999 );
 215  
 216          $directory_pages = bp_core_get_directory_pages();
 217  
 218          remove_filter( 'bp_get_signup_allowed', '__return_false', 999 );
 219  
 220          $this->assertTrue( isset( $directory_pages->register ) );
 221          $this->assertTrue( isset( $directory_pages->activate ) );
 222  
 223          $r = get_post( $directory_pages->register->id );
 224          $this->assertTrue( 'publish' == $r->post_status );
 225  
 226          $a = get_post( $directory_pages->activate->id );
 227          $this->assertTrue( 'publish' == $a->post_status );
 228      }
 229  
 230      public function test_bp_core_get_directory_pages_register_activate_page_notcreated_signups_notallowed() {
 231  
 232          add_filter( 'bp_get_signup_allowed', '__return_false', 999 );
 233  
 234          $ac = buddypress()->active_components;
 235          bp_core_add_page_mappings( array_keys( $ac ) );
 236          $directory_pages = bp_core_get_directory_pages();
 237  
 238          remove_filter( 'bp_get_signup_allowed', '__return_false', 999 );
 239  
 240          $this->assertFalse( isset( $directory_pages->register ) );
 241          $this->assertFalse( isset( $directory_pages->activate ) );
 242      }
 243  
 244      public function test_bp_core_get_directory_pages_pages_settings_update() {
 245          // Set the cache
 246          $pages = bp_core_get_directory_pages();
 247  
 248          // Mess with it but put it back
 249          $v = bp_get_option( 'bp-pages' );
 250          bp_update_option( 'bp-pages', 'foo' );
 251  
 252          $this->assertFalse( wp_cache_get( 'directory_pages', 'bp' ) );
 253  
 254          bp_update_option( 'bp-pages', $v );
 255      }
 256  
 257      public function test_bp_core_get_directory_pages_multisite_delete_post_with_same_bp_page_id() {
 258          if ( ! is_multisite() ) {
 259              $this->markTestSkipped();
 260          }
 261  
 262          $dir_pages = bp_core_get_directory_pages();
 263  
 264          // create a blog
 265          $u = self::factory()->user->create();
 266          $b1 = self::factory()->blog->create( array( 'user_id' => $u ) );
 267  
 268          // Switch to blog and create a post with the same BP activity page ID.
 269          switch_to_blog( $b1 );
 270          $p = self::factory()->post->create( array(
 271              'import_id' => $dir_pages->activity->id
 272          ) );
 273  
 274          // delete the post that matches the BP activity page ID on this sub-site
 275          wp_delete_post( $dir_pages->activity->id, true );
 276  
 277          // restore blog
 278          restore_current_blog();
 279  
 280          // refetch BP directory pages
 281          $dir_pages = bp_core_get_directory_pages();
 282  
 283          // Now verify that our BP activity page was not wiped out
 284          $this->assertNotEmpty( $dir_pages->activity );
 285      }
 286  
 287      /**
 288       * @ticket BP8592
 289       */
 290      public function test_bp_core_get_directory_pages_ids_ms_non_root_blog_trashed_same_page_id() {
 291          if ( ! is_multisite() ) {
 292              $this->markTestSkipped();
 293          }
 294  
 295          // create a blog
 296          $u  = self::factory()->user->create();
 297          $b1 = self::factory()->blog->create(
 298              array(
 299                  'user_id' => $u,
 300              )
 301          );
 302  
 303          // Switch to blog and create a post with the same BP Members page ID.
 304          switch_to_blog( $b1 );
 305  
 306          $dir_page_ids = bp_core_get_directory_page_ids();
 307  
 308          $p = self::factory()->post->create(
 309              array(
 310                  'import_id' => $dir_page_ids['members'],
 311              )
 312          );
 313  
 314          // Trash the post that matches the BP Members page ID on this sub-site
 315          wp_trash_post( $dir_page_ids['members'] );
 316  
 317          // refetch BP directory page IDs
 318          $page_ids = bp_core_get_directory_page_ids();
 319  
 320          // restore blog
 321          restore_current_blog();
 322  
 323          // Now verify that our BP Members page was not wiped out
 324          $this->assertTrue( $dir_page_ids['members'] === $page_ids['members'] );
 325      }
 326  
 327      /**
 328       * @ticket BP7193
 329       */
 330      public function test_bp_core_get_directory_pages_autocreate_register_pages_single_site() {
 331          if ( is_multisite() ) {
 332              $this->markTestSkipped();
 333          }
 334  
 335          require BP_PLUGIN_DIR . 'bp-members/bp-members-admin.php';
 336  
 337          // Emulate being in the admin area.
 338          if ( ! class_exists( 'BP_Members_Admin', false ) ) {
 339              require BP_PLUGIN_DIR . 'bp-members/classes/class-bp-members-admin.php';
 340          }
 341          $admin = new BP_Members_Admin;
 342          add_action( 'update_option_users_can_register', array( $admin, 'single_site_registration_on' ), 10, 2 );
 343  
 344          // Emulate turning registration on.
 345          update_option( 'users_can_register', 1 );
 346  
 347          // Now check directory pages.
 348          $pages = bp_core_get_directory_pages();
 349  
 350          $this->assertNotEmpty( $pages->register );
 351          $this->assertNotEmpty( $pages->activate );
 352  
 353          remove_action( 'update_option_users_can_register', array( $admin, 'single_site_registration_on' ), 10 );
 354      }
 355  
 356      /**
 357       * @ticket BP7193
 358       */
 359      public function test_bp_core_get_directory_pages_autocreate_register_pages_multisite() {
 360          if ( ! is_multisite() ) {
 361              $this->markTestSkipped();
 362          }
 363  
 364          require BP_PLUGIN_DIR . 'bp-members/bp-members-admin.php';
 365  
 366          // Emulate being in the network admin area.
 367          if ( ! class_exists( 'BP_Members_Admin', false ) ) {
 368              require BP_PLUGIN_DIR . 'bp-members/classes/class-bp-members-admin.php';
 369          }
 370          $admin = new BP_Members_Admin;
 371          add_action( 'update_site_option_registration', array( $admin, 'multisite_registration_on' ), 10, 2 );
 372  
 373          // Emulate turning registration on.
 374          update_site_option( 'registration', 'user' );
 375  
 376          // Now check directory pages.
 377          $pages = bp_core_get_directory_pages();
 378  
 379          $this->assertNotEmpty( $pages->register );
 380          $this->assertNotEmpty( $pages->activate );
 381  
 382          remove_action( 'update_site_option_registration', array( $admin, 'multisite_registration_on' ), 10 );
 383      }
 384  }


Generated: Tue Oct 15 01:00:54 2024 Cross-referenced by PHPXref 0.7.1