[ 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          if ( function_exists( 'wp_initialize_site' ) ) {
 263              $this->setExpectedDeprecated( 'wpmu_new_blog' );
 264          }
 265  
 266          $dir_pages = bp_core_get_directory_pages();
 267  
 268          // create a blog
 269          $u = self::factory()->user->create();
 270          $b1 = self::factory()->blog->create( array( 'user_id' => $u ) );
 271  
 272          // Switch to blog and create a post with the same BP activity page ID.
 273          switch_to_blog( $b1 );
 274          $p = self::factory()->post->create( array(
 275              'import_id' => $dir_pages->activity->id
 276          ) );
 277  
 278          // delete the post that matches the BP activity page ID on this sub-site
 279          wp_delete_post( $dir_pages->activity->id, true );
 280  
 281          // restore blog
 282          restore_current_blog();
 283  
 284          // refetch BP directory pages
 285          $dir_pages = bp_core_get_directory_pages();
 286  
 287          // Now verify that our BP activity page was not wiped out
 288          $this->assertNotEmpty( $dir_pages->activity );
 289      }
 290  
 291      /**
 292       * @ticket BP7193
 293       */
 294      public function test_bp_core_get_directory_pages_autocreate_register_pages_single_site() {
 295          if ( is_multisite() ) {
 296              $this->markTestSkipped();
 297          }
 298  
 299          // Emulate being in the admin area.
 300          if ( ! class_exists( 'BP_Members_Admin', false ) ) {
 301              require BP_PLUGIN_DIR . 'bp-members/classes/class-bp-members-admin.php';
 302          }
 303          $admin = new BP_Members_Admin;
 304          add_action( 'update_option_users_can_register', array( $admin, 'single_site_registration_on' ), 10, 2 );
 305  
 306          // Emulate turning registration on.
 307          update_option( 'users_can_register', 1 );
 308  
 309          // Now check directory pages.
 310          $pages = bp_core_get_directory_pages();
 311  
 312          $this->assertNotEmpty( $pages->register );
 313          $this->assertNotEmpty( $pages->activate );
 314  
 315          remove_action( 'update_option_users_can_register', array( $admin, 'single_site_registration_on' ), 10 );
 316      }
 317  
 318      /**
 319       * @ticket BP7193
 320       */
 321      public function test_bp_core_get_directory_pages_autocreate_register_pages_multisite() {
 322          if ( ! is_multisite() ) {
 323              $this->markTestSkipped();
 324          }
 325  
 326          // Emulate being in the network admin area.
 327          if ( ! class_exists( 'BP_Members_Admin', false ) ) {
 328              require BP_PLUGIN_DIR . 'bp-members/classes/class-bp-members-admin.php';
 329          }
 330          $admin = new BP_Members_Admin;
 331          add_action( 'update_site_option_registration', array( $admin, 'multisite_registration_on' ), 10, 2 );
 332  
 333          // Emulate turning registration on.
 334          update_site_option( 'registration', 'user' );
 335  
 336          // Now check directory pages.
 337          $pages = bp_core_get_directory_pages();
 338  
 339          $this->assertNotEmpty( $pages->register );
 340          $this->assertNotEmpty( $pages->activate );
 341  
 342          remove_action( 'update_site_option_registration', array( $admin, 'multisite_registration_on' ), 10 );
 343      }
 344  }


Generated: Mon Sep 23 01:01:44 2019 Cross-referenced by PHPXref 0.7.1