[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/blogs/ -> template.php (source)

   1  <?php
   2  
   3  /**
   4   * @group blogs
   5   */
   6  class BP_Tests_Blogs_Template extends BP_UnitTestCase {
   7      /**
   8       * @group bp_get_blog_last_active
   9       */
  10  	public function test_bp_get_blog_last_active_default_params() {
  11          // Fake the global
  12          global $blogs_template;
  13  
  14          $time = date( 'Y-m-d h:i:s', time() - 24 * 60 * 60 );
  15          $blogs_template = new stdClass;
  16          $blogs_template->blog = new stdClass;
  17          $blogs_template->blog->last_activity = $time;
  18  
  19          $this->assertEquals( bp_core_get_last_activity( $time, __( 'Active %s', 'buddypress' ) ), bp_get_blog_last_active() );
  20  
  21          $blogs_template->blog = null;
  22      }
  23  
  24      /**
  25       * @group bp_get_blog_last_active
  26       */
  27      public function test_bp_get_blog_last_active_active_format_true() {
  28          // Fake the global
  29          global $blogs_template;
  30  
  31          $time = date( 'Y-m-d h:i:s', time() - 24 * 60 * 60 );
  32          $blogs_template = new stdClass;
  33          $blogs_template->blog = new stdClass;
  34          $blogs_template->blog->last_activity = $time;
  35  
  36          $this->assertEquals( bp_core_get_last_activity( $time, __( 'Active %s', 'buddypress' ) ), bp_get_blog_last_active( array( 'active_format' => true, ) ) );
  37  
  38          $blogs_template->blog = null;
  39      }
  40  
  41      /**
  42       * @group bp_get_blog_last_active
  43       */
  44      public function test_bp_get_blog_last_active_active_format_false() {
  45          // Fake the global
  46          global $blogs_template;
  47  
  48          $time = date( 'Y-m-d h:i:s', time() - 24 * 60 * 60 );
  49          $blogs_template = new stdClass;
  50          $blogs_template->blog = new stdClass;
  51          $blogs_template->blog->last_activity = $time;
  52  
  53          $this->assertEquals( bp_core_time_since( $time ), bp_get_blog_last_active( array( 'active_format' => false, ) ) );
  54  
  55          $blogs_template->blog = null;
  56      }
  57  
  58      /**
  59       * @group bp_get_blog_last_active
  60       */
  61      public function test_bp_get_blog_last_active_active_no_last_activity() {
  62          $this->assertEquals( __( 'Never active', 'buddypress' ), bp_get_blog_last_active() );
  63      }
  64  
  65      /**
  66       * @group bp_get_blog_latest_post
  67       */
  68  	public function test_bp_get_blog_latest_post_default_params() {
  69          // Fake the global
  70          global $blogs_template;
  71  
  72          $blogs_template = new stdClass;
  73          $blogs_template->blog = new stdClass;
  74          $blogs_template->blog->latest_post = new stdClass;
  75          $blogs_template->blog->latest_post->guid = 'foo';
  76          $blogs_template->blog->latest_post->post_title = 'bar';
  77  
  78          $this->assertSame( sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="foo">bar</a>' ), bp_get_blog_latest_post() );
  79  
  80          $blogs_template->blog = null;
  81      }
  82  
  83      /**
  84       * @group bp_get_blog_latest_post
  85       */
  86      public function test_bp_get_blog_latest_post_latest_format_true() {
  87          // Fake the global
  88          global $blogs_template;
  89  
  90          $blogs_template = new stdClass;
  91          $blogs_template->blog = new stdClass;
  92          $blogs_template->blog->latest_post = new stdClass;
  93          $blogs_template->blog->latest_post->guid = 'foo';
  94          $blogs_template->blog->latest_post->post_title = 'bar';
  95  
  96          $this->assertSame( sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="foo">bar</a>' ), bp_get_blog_latest_post( array( 'latest_format' => true, ) ) );
  97  
  98          $blogs_template->blog = null;
  99      }
 100  
 101      /**
 102       * @group bp_get_blog_latest_post
 103       */
 104      public function test_bp_get_blog_latest_post_latest_format_false() {
 105          // Fake the global
 106          global $blogs_template;
 107  
 108          $blogs_template = new stdClass;
 109          $blogs_template->blog = new stdClass;
 110          $blogs_template->blog->latest_post = new stdClass;
 111          $blogs_template->blog->latest_post->guid = 'foo';
 112          $blogs_template->blog->latest_post->post_title = 'bar';
 113  
 114          $this->assertSame( '<a href="foo">bar</a>', bp_get_blog_latest_post( array( 'latest_format' => false, ) ) );
 115  
 116          $blogs_template->blog = null;
 117      }
 118  
 119      /**
 120       * @group bp_blog_signup_enabled
 121       */
 122      public function test_bp_signup_enabled_when_registration_setting_does_not_exist_should_default_to_true() {
 123          $old_settings = $settings = buddypress()->site_options;
 124          if ( is_array( $settings ) && isset( $settings['registration'] ) ) {
 125              unset( $settings['registration'] );
 126          }
 127          buddypress()->site_options = $settings;
 128  
 129          $this->assertTrue( bp_blog_signup_enabled() );
 130  
 131          buddypress()->site_options = $old_settings;
 132      }
 133  
 134      /**
 135       * @group bp_blog_signup_enabled
 136       */
 137      public function test_bp_signup_enabled_when_registration_setting_is_all_should_return_true() {
 138          $old_settings = $settings = buddypress()->site_options;
 139  
 140          if ( ! is_array( $settings ) ) {
 141              $settings = array();
 142          }
 143  
 144          $settings['registration'] = 'all';
 145          buddypress()->site_options = $settings;
 146  
 147          $this->assertTrue( bp_blog_signup_enabled() );
 148  
 149          buddypress()->site_options = $old_settings;
 150      }
 151  
 152      /**
 153       * @group bp_blog_signup_enabled
 154       */
 155      public function test_bp_signup_enabled_when_registration_setting_is_blog_should_return_true() {
 156          $old_settings = $settings = buddypress()->site_options;
 157  
 158          if ( ! is_array( $settings ) ) {
 159              $settings = array();
 160          }
 161  
 162          $settings['registration'] = 'blog';
 163          buddypress()->site_options = $settings;
 164  
 165          $this->assertTrue( bp_blog_signup_enabled() );
 166  
 167          buddypress()->site_options = $old_settings;
 168      }
 169  
 170      /**
 171       * @group bp_blog_signup_enabled
 172       */
 173      public function test_bp_signup_enabled_when_registration_setting_is_user_should_return_false() {
 174          $old_settings = $settings = buddypress()->site_options;
 175  
 176          if ( ! is_array( $settings ) ) {
 177              $settings = array();
 178          }
 179  
 180          $settings['registration'] = 'user';
 181          buddypress()->site_options = $settings;
 182  
 183          $this->assertFalse( bp_blog_signup_enabled() );
 184  
 185          buddypress()->site_options = $old_settings;
 186      }
 187  
 188      /**
 189       * @group bp_blog_signup_enabled
 190       */
 191      public function test_bp_signup_enabled_when_registration_setting_is_none_should_return_false() {
 192          $old_settings = $settings = buddypress()->site_options;
 193  
 194          if ( ! is_array( $settings ) ) {
 195              $settings = array();
 196          }
 197  
 198          $settings['registration'] = 'none';
 199          buddypress()->site_options = $settings;
 200  
 201          $this->assertFalse( bp_blog_signup_enabled() );
 202  
 203          buddypress()->site_options = $old_settings;
 204      }
 205  
 206      /**
 207       * @group pagination
 208       * @group BP_Blogs_Template
 209       */
 210      public function test_bp_blogs_template_should_give_precedence_to_bpage_URL_param() {
 211          if ( ! is_multisite() ) {
 212              $this->markTestSkipped();
 213          }
 214  
 215          $request = $_REQUEST;
 216          $_REQUEST['bpage'] = '5';
 217  
 218          $r = array(
 219              'type'              => 'active',
 220              'page_arg'          => 'bpage',
 221              'page'              => 8,
 222              'per_page'          => 20,
 223              'max'               => false,
 224              'user_id'           => 0,
 225              'include_blog_ids'  => false,
 226              'search_terms'      => '',
 227              'update_meta_cache' => true
 228          );
 229  
 230          $at = new BP_Blogs_Template( $r );
 231  
 232          $this->assertEquals( 5, $at->pag_page );
 233  
 234          $_REQUEST = $request;
 235      }
 236  
 237      /**
 238       * @group pagination
 239       * @group BP_Blogs_Template
 240       */
 241      public function test_bp_blogs_template_should_reset_0_pag_page_URL_param_to_default_pag_page_value() {
 242          if ( ! is_multisite() ) {
 243              $this->markTestSkipped();
 244          }
 245  
 246          $request = $_REQUEST;
 247          $_REQUEST['bpage'] = '0';
 248  
 249          $r = array(
 250              'type'              => 'active',
 251              'page_arg'          => 'bpage',
 252              'page'              => 8,
 253              'per_page'          => 20,
 254              'max'               => false,
 255              'user_id'           => 0,
 256              'include_blog_ids'  => false,
 257              'search_terms'      => '',
 258              'update_meta_cache' => true
 259          );
 260  
 261          $at = new BP_Blogs_Template( $r );
 262  
 263          $this->assertEquals( 8, $at->pag_page );
 264  
 265          $_REQUEST = $request;
 266      }
 267  
 268      /**
 269       * @group pagination
 270       * @group BP_Blogs_Template
 271       */
 272      public function test_bp_blogs_template_should_give_precedence_to_num_URL_param() {
 273          if ( ! is_multisite() ) {
 274              $this->markTestSkipped();
 275          }
 276  
 277          $request = $_REQUEST;
 278          $_REQUEST['num'] = '14';
 279  
 280          $r = array(
 281              'type'              => 'active',
 282              'page_arg'          => 'bpage',
 283              'page'              => 1,
 284              'per_page'          => 13,
 285              'max'               => false,
 286              'user_id'           => 0,
 287              'include_blog_ids'  => false,
 288              'search_terms'      => '',
 289              'update_meta_cache' => true
 290          );
 291  
 292          $at = new BP_Blogs_Template( $r );
 293  
 294          $this->assertEquals( 14, $at->pag_num );
 295  
 296          $_REQUEST = $request;
 297      }
 298  
 299      /**
 300       * @group pagination
 301       * @group BP_Blogs_Template
 302       */
 303      public function test_bp_blogs_template_should_reset_0_pag_num_URL_param_to_default_pag_num_value() {
 304          if ( ! is_multisite() ) {
 305              $this->markTestSkipped();
 306          }
 307  
 308          $request = $_REQUEST;
 309          $_REQUEST['num'] = '0';
 310  
 311          $r = array(
 312              'type'              => 'active',
 313              'page_arg'          => 'bpage',
 314              'page'              => 1,
 315              'per_page'          => 13,
 316              'max'               => false,
 317              'user_id'           => 0,
 318              'include_blog_ids'  => false,
 319              'search_terms'      => '',
 320              'update_meta_cache' => true
 321          );
 322  
 323          $at = new BP_Blogs_Template( $r );
 324  
 325          $this->assertEquals( 13, $at->pag_num );
 326  
 327          $_REQUEST = $request;
 328      }
 329  
 330      /**
 331       * @group avatar
 332       * @group BP_Blogs_Template
 333       * @group bp_get_blog_avatar
 334       */
 335  	public function test_bp_get_blog_avatar_ids_provided() {
 336          if ( ! is_multisite() ) {
 337              $this->markTestSkipped();
 338          }
 339  
 340          global $blogs_template;
 341          $reset_blogs_template = $blogs_template;
 342          $blogs_template = null;
 343  
 344          $u = self::factory()->user->create();
 345          $b = self::factory()->blog->create( array(
 346              'title' => 'The Foo Bar Blog',
 347              'user_id' => $u,
 348          ) );
 349  
 350          $avatar = bp_get_blog_avatar( array(
 351              'type'          => 'full',
 352              'admin_user_id' => $u,
 353              'blog_id'       => $b,
 354              'alt'           => 'test',
 355              'no_grav'       => true,
 356              'class'         => 'avatar',
 357          ) );
 358  
 359          $blogs_template = $reset_blogs_template;
 360          $expected       = bp_core_fetch_avatar(
 361              array(
 362                  'type'    => 'full',
 363                  'item_id' => $u,
 364                  'alt'     => 'test',
 365                  'no_grav' => true,
 366                  'class'   => 'avatar',
 367              )
 368          );
 369  
 370          $this->assertTrue( $avatar === $expected );
 371      }
 372  
 373      /**
 374       * @group avatar
 375       * @group BP_Blogs_Template
 376       * @group bp_get_blog_avatar
 377       */
 378  	public function test_bp_get_blog_avatar_has_site_icon() {
 379          if ( ! is_multisite() ) {
 380              $this->markTestSkipped();
 381          }
 382  
 383          global $blogs_template;
 384          $reset_blogs_template = $blogs_template;
 385          $blogs_template = null;
 386  
 387          $u = self::factory()->user->create();
 388          $b = self::factory()->blog->create( array(
 389              'title' => 'The Bar Foo Blog',
 390              'user_id' => $u,
 391          ) );
 392  
 393          add_filter( 'get_site_icon_url', array( $this, 'filter_blog_avatar' ) );
 394          add_filter( 'bp_is_network_activated', '__return_true' );
 395  
 396          $avatar = bp_get_blog_avatar( array(
 397              'type'          => 'full',
 398              'admin_user_id' => $u,
 399              'blog_id'       => $b,
 400              'alt'           => 'test',
 401              'no_grav'       => true,
 402              'class'         => 'avatar',
 403          ) );
 404  
 405          remove_filter( 'bp_is_network_activated', '__return_true' );
 406          remove_filter( 'get_site_icon_url', array( $this, 'filter_blog_avatar' ) );
 407          $blogs_template = $reset_blogs_template;
 408  
 409          $this->assertTrue( false !== strpos( $avatar, BP_TESTS_DIR . 'assets/upside-down.jpg' ) );
 410      }
 411  
 412      /**
 413       * @group avatar
 414       * @group BP_Blogs_Template
 415       * @group bp_get_blog_avatar
 416       */
 417  	public function test_bp_get_blog_default_avatar() {
 418          if ( ! is_multisite() ) {
 419              $this->markTestSkipped();
 420          }
 421  
 422          global $blogs_template;
 423          $reset_blogs_template = $blogs_template;
 424          $blogs_template = null;
 425  
 426          $u = self::factory()->user->create();
 427          $b = self::factory()->blog->create( array(
 428              'title' => 'The Foo Bar Blog',
 429              'user_id' => $u,
 430          ) );
 431  
 432          $avatar = bp_get_blog_avatar(
 433              array(
 434                  'type'    => 'thumb',
 435                  'blog_id' => $b,
 436                  'html'    => false,
 437              )
 438          );
 439  
 440          $blogs_template = $reset_blogs_template;
 441          $expected       = buddypress()->plugin_url . "bp-core/images/mystery-blog-50.png";
 442  
 443          $this->assertTrue( $avatar === $expected );
 444      }
 445  
 446  	public function filter_blog_avatar() {
 447          return BP_TESTS_DIR . 'assets/upside-down.jpg';
 448      }
 449  }


Generated: Wed Jun 29 01:00:59 2022 Cross-referenced by PHPXref 0.7.1