[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/activity/functions/ -> bpActivityGetCommentDepth.php (source)

   1  <?php
   2  
   3  /**
   4   * @group activity
   5   * @group bp_activity_get_comment_depth
   6   */
   7  class BP_Tests_Activity_Functions_BpActivityGetCommentDepth extends BP_UnitTestCase {
   8      /**
   9       * @ticket BP7329
  10       */
  11  	public function test_depth_inside_activity_comment_loop() {
  12          $u = self::factory()->user->create();
  13  
  14          // create an activity update
  15          $parent_activity = self::factory()->activity->create( array(
  16              'type'    => 'activity_update',
  17              'user_id' => $u
  18          ) );
  19  
  20          // create some activity comments
  21          $comment_one = bp_activity_new_comment( array(
  22              'user_id'     => $u,
  23              'activity_id' => $parent_activity,
  24              'content'     => 'depth 1'
  25          ) );
  26  
  27          $comment_one_one = bp_activity_new_comment( array(
  28              'user_id'     => $u,
  29              'activity_id' => $parent_activity,
  30              'parent_id'   => $comment_one,
  31              'content'     => 'depth 2'
  32          ) );
  33  
  34          $comment_two = bp_activity_new_comment( array(
  35              'user_id'     => $u,
  36              'activity_id' => $parent_activity,
  37              'content'     => 'depth 1'
  38          ) );
  39  
  40          // Instantiate activity loop, which also includes activity comments.
  41          bp_has_activities( 'display_comments=threaded' );
  42  
  43          // Loop through activity comments generated in activity loop.
  44          $recursive = new RecursiveIteratorIterator( new RecursiveArrayIterator( $GLOBALS['activities_template']->activities[0]->children ), RecursiveIteratorIterator::SELF_FIRST );
  45          foreach ( $recursive as $aid => $a ) {
  46              if ( ! is_numeric( $aid ) || ! is_object( $a ) ) {
  47                  continue;
  48              }
  49  
  50              /*
  51               * Emulate activity comment loop global, which bp_activity_get_comment_depth()
  52               * relies on by default.
  53               */
  54              $GLOBALS['activities_template']->activity = new stdClass;
  55              $GLOBALS['activities_template']->activity->current_comment = $a;
  56  
  57              // $aid is the activity ID for the current activity comment.
  58              switch ( $aid ) {
  59                  case $comment_one :
  60                  case $comment_two :
  61                      $this->assertSame( bp_activity_get_comment_depth(), 1 );
  62                      break;
  63  
  64                  case $comment_one_one :
  65                      $this->assertSame( bp_activity_get_comment_depth(), 2 );
  66                      break;
  67              }
  68  
  69          }
  70  
  71          // Clean up after ourselves!
  72          $GLOBALS['activities_template'] = null;
  73      }
  74  
  75      /**
  76       * @ticket BP7329
  77       */
  78  	public function test_depth_outside_of_activity_comment_loop() {
  79          $u = self::factory()->user->create();
  80  
  81          // create an activity update
  82          $parent_activity = self::factory()->activity->create( array(
  83              'type'    => 'activity_update',
  84              'user_id' => $u
  85          ) );
  86  
  87          // create some activity comments
  88          $comment_one = bp_activity_new_comment( array(
  89              'user_id'     => $u,
  90              'activity_id' => $parent_activity,
  91              'content'     => 'depth 1'
  92          ) );
  93  
  94          $comment_one_one = bp_activity_new_comment( array(
  95              'user_id'     => $u,
  96              'activity_id' => $parent_activity,
  97              'parent_id'   => $comment_one,
  98              'content'     => 'depth 2'
  99          ) );
 100  
 101          $comment_two = bp_activity_new_comment( array(
 102              'user_id'     => $u,
 103              'activity_id' => $parent_activity,
 104              'content'     => 'depth 1'
 105          ) );
 106  
 107          $this->assertSame( bp_activity_get_comment_depth( $comment_one ), 1 );
 108          $this->assertSame( bp_activity_get_comment_depth( $comment_one_one ), 2 );
 109          $this->assertSame( bp_activity_get_comment_depth( $comment_two ), 1 );
 110      }
 111  }


Generated: Thu Dec 5 01:00:58 2024 Cross-referenced by PHPXref 0.7.1