[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/tests/phpunit/testcases/extend/buddypress/ -> activity.php (source)

   1  <?php
   2  
   3  /**
   4   * BuddyPress Extension Activity Tests.
   5   *
   6   * @group extend
   7   * @group buddypress
   8   * @group activity
   9   */
  10  class BBP_Tests_Extend_BuddyPress_Activity extends BBP_UnitTestCase {
  11  
  12      /**
  13       * Copied from `BBP_Forums_Group_Extension::new_forum()`.
  14       *
  15       * @since x.x.x
  16       *
  17       * @param int $forum_id The forum id.
  18       * @param int $group_id The group id.
  19       */
  20  	private function attach_forum_to_group( $forum_id, $group_id ) {
  21          bbp_add_forum_id_to_group( $group_id, $forum_id );
  22          bbp_add_group_id_to_forum( $forum_id, $group_id );
  23      }
  24  
  25      /**
  26       * Dynamic activity actions for site-wide forum topics.
  27       *
  28       * @since 2.6.0 bbPress (r6370)
  29       *
  30       * @ticket BBP2794
  31       */
  32      public function test_bp_activity_actions_for_site_wide_forum_topic() {
  33          $u = $this->factory->user->create();
  34          $f = $this->factory->forum->create();
  35          $t = $this->factory->topic->create( array(
  36              'post_parent' => $f,
  37              'post_author' => $u,
  38          ) );
  39  
  40          // Set up our activity text test string.
  41          $user_link       = bbp_get_user_profile_link( $u );
  42          $topic_permalink = bbp_get_topic_permalink( $t );
  43          $topic_title     = get_post_field( 'post_title',   $t, 'raw' );
  44          $topic_link      = '<a href="' . $topic_permalink . '">' . $topic_title . '</a>';
  45          $forum_permalink = bbp_get_forum_permalink( $f );
  46          $forum_title     = get_post_field( 'post_title', $f, 'raw' );
  47          $forum_link      = '<a href="' . $forum_permalink . '">' . $forum_title . '</a>';
  48          $activity_text   = sprintf( esc_html__( '%1$s started the topic %2$s in the forum %3$s', 'bbpress' ), $user_link, $topic_link, $forum_link );
  49  
  50          // Create the activity.
  51          bbpress()->extend->buddypress->activity->topic_create( $t, $f, array(), $u );
  52  
  53          $activity_id = (int) get_post_meta( $t, '_bbp_activity_id', true );
  54          $activity    = new BP_Activity_Activity( $activity_id );
  55  
  56          // Test the default generated string.
  57          $this->assertEquals( $activity_text, $activity->action );
  58  
  59          // Update a few items for testing.
  60          wp_update_user( array( 'ID' => $u, 'display_name' => 'New Name' ) );
  61          $user_link = bbp_get_user_profile_link( $u );
  62  
  63          wp_update_post( array( 'ID' => $f, 'post_title' => 'New Forum Title' ) );
  64          $forum_link = '<a href="' . $forum_permalink . '">New Forum Title</a>';
  65  
  66          wp_update_post( array( 'ID' => $t, 'post_title' => 'New Topic Title' ) );
  67          $topic_link = '<a href="' . $topic_permalink . '">New Topic Title</a>';
  68  
  69          // Set up our new test string.
  70          $activity_text = sprintf( esc_html__( '%1$s started the topic %2$s in the forum %3$s', 'bbpress' ), $user_link, $topic_link, $forum_link );
  71  
  72          $activity = new BP_Activity_Activity( $activity_id );
  73  
  74          // Are we dynamic?
  75          $this->assertEquals( $activity_text, $activity->action );
  76      }
  77  
  78      /**
  79       * Dynamic activity actions for replies to site-wide forum topics.
  80       *
  81       * @since 2.6.0 bbPress (r6370)
  82       *
  83       * @ticket BBP2794
  84       */
  85      public function test_bp_activity_actions_for_reply_to_site_wide_forum_topic() {
  86          $u = $this->factory->user->create();
  87          $f = $this->factory->forum->create();
  88          $t = $this->factory->topic->create( array(
  89              'post_parent' => $f,
  90              'post_author' => $u,
  91          ) );
  92          $r = $this->factory->reply->create( array(
  93              'post_parent' => $t,
  94              'post_author' => $u,
  95          ) );
  96  
  97          // Set up our activity text test string.
  98          $user_link       = bbp_get_user_profile_link( $u );
  99          $topic_permalink = bbp_get_topic_permalink( $t );
 100          $topic_title     = get_post_field( 'post_title',   $t, 'raw' );
 101          $topic_link      = '<a href="' . $topic_permalink . '">' . $topic_title . '</a>';
 102          $forum_permalink = bbp_get_forum_permalink( $f );
 103          $forum_title     = get_post_field( 'post_title', $f, 'raw' );
 104          $forum_link      = '<a href="' . $forum_permalink . '">' . $forum_title . '</a>';
 105          $activity_text   = sprintf( esc_html__( '%1$s replied to the topic %2$s in the forum %3$s', 'bbpress' ), $user_link, $topic_link, $forum_link );
 106  
 107          // Create the activity.
 108          bbpress()->extend->buddypress->activity->reply_create( $r, $t, $f, array(), $u );
 109  
 110          $activity_id = (int) get_post_meta( $r, '_bbp_activity_id', true );
 111          $activity    = new BP_Activity_Activity( $activity_id );
 112  
 113          // Test the default generated string.
 114          $this->assertEquals( $activity_text, $activity->action );
 115  
 116          // Update a few items for testing.
 117          wp_update_user( array( 'ID' => $u, 'display_name' => 'New Name' ) );
 118          $user_link = bbp_get_user_profile_link( $u );
 119  
 120          wp_update_post( array( 'ID' => $f, 'post_title' => 'New Forum Title' ) );
 121          $forum_link = '<a href="' . $forum_permalink . '">New Forum Title</a>';
 122  
 123          wp_update_post( array( 'ID' => $t, 'post_title' => 'New Topic Title' ) );
 124          $topic_link = '<a href="' . $topic_permalink . '">New Topic Title</a>';
 125  
 126          // Set up our new test string.
 127          $activity_text = sprintf( esc_html__( '%1$s replied to the topic %2$s in the forum %3$s', 'bbpress' ), $user_link, $topic_link, $forum_link );
 128  
 129          $activity = new BP_Activity_Activity( $activity_id );
 130  
 131          // Are we dynamic?
 132          $this->assertEquals( $activity_text, $activity->action );
 133      }
 134  
 135      /**
 136       * Dynamic activity actions for group forum topics.
 137       *
 138       * @since 2.6.0 bbPress (r6370)
 139       *
 140       * @ticket BBP2794
 141       */
 142      public function test_bp_activity_actions_for_group_forum_topic() {
 143  
 144          // See https://bbpress.trac.wordpress.org/ticket/2794.
 145          // See https://bbpress.trac.wordpress.org/ticket/3089.
 146          $this->markTestSkipped( 'Skipping dynamic group activity action tests.' );
 147  
 148          $g = $this->bp_factory->group->create();
 149          $group = groups_get_group( array( 'group_id' => $g ) );
 150          $u = $group->creator_id;
 151          $f = $this->factory->forum->create();
 152          $t = $this->factory->topic->create( array(
 153              'post_parent' => $f,
 154              'post_author' => $u,
 155          ) );
 156          $r = $this->factory->reply->create( array(
 157              'post_parent' => $t,
 158              'post_author' => $u,
 159          ) );
 160          $this->attach_forum_to_group( $f, $g );
 161          buddypress()->groups->current_group = $group;
 162  
 163          // Set up our activity text test string.
 164          $user_link       = bbp_get_user_profile_link( $u );
 165          $topic_permalink = bbp_get_topic_permalink( $t );
 166          $topic_title     = get_post_field( 'post_title', $t, 'raw' );
 167          $topic_link      = '<a href="' . $topic_permalink . '">' . $topic_title . '</a>';
 168          $forum_permalink = bbp_get_forum_permalink( $f );
 169          $forum_title     = get_post_field( 'post_title', $f, 'raw' );
 170          $forum_link      = '<a href="' . $forum_permalink . '">' . $forum_title . '</a>';
 171          $activity_text   = sprintf( esc_html__( '%1$s started the topic %2$s in the forum %3$s', 'bbpress' ), $user_link, $topic_link, $forum_link );
 172  
 173          // Create the activity.
 174          bbpress()->extend->buddypress->activity->topic_create( $t, $f, array(), $u );
 175  
 176          $activity_id = (int) get_post_meta( $t, '_bbp_activity_id', true );
 177          $activity    = new BP_Activity_Activity( $activity_id );
 178  
 179          // Test the default generated string.
 180          $this->assertEquals( $activity_text, $activity->action );
 181  
 182          // Update a few items for testing.
 183          wp_update_user( array( 'ID' => $u, 'display_name' => 'New Name' ) );
 184          $user_link = bbp_get_user_profile_link( $u );
 185  
 186          wp_update_post( array( 'ID' => $f, 'post_title' => 'New Forum Title' ) );
 187          $forum_link = '<a href="' . $forum_permalink . '">New Forum Title</a>';
 188  
 189          wp_update_post( array( 'ID' => $t, 'post_title' => 'New Topic Title' ) );
 190          $topic_link = '<a href="' . $topic_permalink . '">New Topic Title</a>';
 191  
 192          // Set up our new test string.
 193          $activity_text = sprintf( esc_html__( '%1$s started the topic %2$s in the forum %3$s', 'bbpress' ), $user_link, $topic_link, $forum_link );
 194  
 195          $activity = new BP_Activity_Activity( $activity_id );
 196  
 197          // Are we dynamic?
 198          $this->assertEquals( $activity_text, $activity->action );
 199      }
 200  
 201      /**
 202       * Dynamic activity actions for replies to group forum topics.
 203       *
 204       * @since 2.6.0 bbPress (r6370)
 205       *
 206       * @ticket BBP2794
 207       */
 208      public function test_bp_activity_actions_for_reply_to_group_forum_topic() {
 209  
 210          // See https://bbpress.trac.wordpress.org/ticket/2794.
 211          // See https://bbpress.trac.wordpress.org/ticket/3089.
 212          $this->markTestSkipped( 'Skipping dynamic group activity action tests.' );
 213  
 214          $g = $this->bp_factory->group->create();
 215          $group = groups_get_group( array( 'group_id' => $g ) );
 216          $u = $group->creator_id;
 217          $f = $this->factory->forum->create();
 218          $t = $this->factory->topic->create( array(
 219              'post_parent' => $f,
 220              'post_author' => $u,
 221          ) );
 222          $r = $this->factory->reply->create( array(
 223              'post_parent' => $t,
 224              'post_author' => $u,
 225          ) );
 226          $this->attach_forum_to_group( $f, $g );
 227          buddypress()->groups->current_group = $group;
 228  
 229          // Set up our activity text test string.
 230          $user_link       = bbp_get_user_profile_link( $u );
 231          $topic_permalink = bbp_get_topic_permalink( $t );
 232          $topic_title     = get_post_field( 'post_title',   $t, 'raw' );
 233          $topic_link      = '<a href="' . $topic_permalink . '">' . $topic_title . '</a>';
 234          $forum_permalink = bbp_get_forum_permalink( $f );
 235          $forum_title     = get_post_field( 'post_title', $f, 'raw' );
 236          $forum_link      = '<a href="' . $forum_permalink . '">' . $forum_title . '</a>';
 237          $activity_text   = sprintf( esc_html__( '%1$s replied to the topic %2$s in the forum %3$s', 'bbpress' ), $user_link, $topic_link, $forum_link );
 238  
 239          // Create the activity.
 240          bbpress()->extend->buddypress->activity->reply_create( $r, $t, $f, array(), $u );
 241  
 242          $activity_id = (int) get_post_meta( $r, '_bbp_activity_id', true );
 243          $activity    = new BP_Activity_Activity( $activity_id );
 244  
 245          // Test the default generated string.
 246          $this->assertEquals( $activity_text, $activity->action );
 247  
 248          // Update a few items for testing.
 249          wp_update_user( array( 'ID' => $u, 'display_name' => 'New Name' ) );
 250          $user_link = bbp_get_user_profile_link( $u );
 251  
 252          wp_update_post( array( 'ID' => $f, 'post_title' => 'New Forum Title' ) );
 253          $forum_link = '<a href="' . $forum_permalink . '">New Forum Title</a>';
 254  
 255          wp_update_post( array( 'ID' => $t, 'post_title' => 'New Topic Title' ) );
 256          $topic_link = '<a href="' . $topic_permalink . '">New Topic Title</a>';
 257  
 258          // Set up our new test string.
 259          $activity_text = sprintf( esc_html__( '%1$s replied to the topic %2$s in the forum %3$s', 'bbpress' ), $user_link, $topic_link, $forum_link );
 260  
 261          $activity = new BP_Activity_Activity( $activity_id );
 262  
 263          // Are we dynamic?
 264          $this->assertEquals( $activity_text, $activity->action );
 265      }
 266  }


Generated: Sun Apr 28 01:00:59 2024 Cross-referenced by PHPXref 0.7.1