[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/tests/phpunit/testcases/users/functions/ -> subscriptions.php (source)

   1  <?php
   2  
   3  /**
   4   * Tests for the user component subscription functions.
   5   *
   6   * @group users
   7   * @group functions
   8   * @group subscriptions
   9   */
  10  class BBP_Tests_Users_Functions_Subscriptions extends BBP_UnitTestCase {
  11  
  12      /**
  13       * @covers ::bbp_get_forum_subscribers
  14       */
  15  	public function test_bbp_get_forum_subscribers() {
  16          $u = $this->factory->user->create_many( 3 );
  17          $f = $this->factory->forum->create_many( 2 );
  18  
  19          // Add forum subscriptions.
  20          bbp_add_user_forum_subscription( $u[0], $f[0] );
  21          bbp_add_user_forum_subscription( $u[1], $f[0] );
  22          bbp_add_user_forum_subscription( $u[2], $f[0] );
  23  
  24          $subscribers = bbp_get_forum_subscribers( $f[0] );
  25  
  26          $this->assertEqualSets( array( $u[0], $u[1], $u[2] ), $subscribers );
  27  
  28          // Add forum subscriptions.
  29          bbp_add_user_forum_subscription( $u[0], $f[1] );
  30          bbp_add_user_forum_subscription( $u[2], $f[1] );
  31  
  32          $subscribers = bbp_get_forum_subscribers( $f[1] );
  33  
  34          $this->assertEqualSets( array( $u[0], $u[2] ), $subscribers );
  35      }
  36  
  37      /**
  38       * @covers ::bbp_get_topic_subscribers
  39       */
  40  	public function test_bbp_get_topic_subscribers() {
  41          $u = $this->factory->user->create_many( 3 );
  42          $t = $this->factory->topic->create_many( 2 );
  43  
  44          // Add topic subscriptions.
  45          bbp_add_user_topic_subscription( $u[0], $t[0] );
  46          bbp_add_user_topic_subscription( $u[1], $t[0] );
  47          bbp_add_user_topic_subscription( $u[2], $t[0] );
  48  
  49          $subscribers = bbp_get_topic_subscribers( $t[0] );
  50  
  51          $this->assertEqualSets( array( $u[0], $u[1], $u[2] ), $subscribers );
  52  
  53          // Add topic subscriptions.
  54          bbp_add_user_topic_subscription( $u[0], $t[1] );
  55          bbp_add_user_topic_subscription( $u[2], $t[1] );
  56  
  57          $subscribers = bbp_get_topic_subscribers( $t[1] );
  58  
  59          $this->assertEqualSets( array( $u[0], $u[2] ), $subscribers );
  60      }
  61  
  62      /**
  63       * @covers ::bbp_get_user_subscriptions
  64       * @expectedDeprecated bbp_get_user_subscriptions
  65       */
  66  	public function test_bbp_get_user_subscriptions() {
  67          $u = $this->factory->user->create();
  68          $t = $this->factory->topic->create_many( 3 );
  69  
  70          // Add topic subscriptions.
  71          bbp_add_user_topic_subscription( $u, $t[0] );
  72          bbp_add_user_topic_subscription( $u, $t[1] );
  73          bbp_add_user_topic_subscription( $u, $t[2] );
  74  
  75          $expected = bbp_has_topics( array( 'post__in' => array( $t[0], $t[1], $t[2] ) ) );
  76          $subscriptions = bbp_get_user_subscriptions( $u );
  77  
  78          $this->assertEquals( $expected, $subscriptions );
  79  
  80          // Remove topic subscription.
  81          bbp_remove_user_topic_subscription( $u, $t[1] );
  82  
  83          $expected = bbp_has_topics( array( 'post__in' => array( $t[0], $t[2] ) ) );
  84          $subscriptions = bbp_get_user_subscriptions( $u );
  85  
  86          $this->assertEquals( $expected, $subscriptions );
  87      }
  88  
  89      /**
  90       * @covers ::bbp_get_user_topic_subscriptions
  91       */
  92  	public function test_bbp_get_user_topic_subscriptions() {
  93          $u = $this->factory->user->create();
  94          $t = $this->factory->topic->create_many( 3 );
  95  
  96          // Add topic subscriptions.
  97          bbp_add_user_topic_subscription( $u, $t[0] );
  98          bbp_add_user_topic_subscription( $u, $t[1] );
  99          bbp_add_user_topic_subscription( $u, $t[2] );
 100  
 101          $expected = bbp_has_topics( array( 'post__in' => array( $t[0], $t[1], $t[2] ) ) );
 102          $subscriptions = bbp_get_user_topic_subscriptions( $u );
 103  
 104          $this->assertEquals( $expected, $subscriptions );
 105  
 106          // Remove topic subscription.
 107          bbp_remove_user_topic_subscription( $u, $t[1] );
 108  
 109          $expected = bbp_has_topics( array( 'post__in' => array( $t[0], $t[2] ) ) );
 110          $subscriptions = bbp_get_user_topic_subscriptions( $u );
 111  
 112          $this->assertEquals( $expected, $subscriptions );
 113      }
 114  
 115      /**
 116       * @covers ::bbp_get_user_forum_subscriptions
 117       */
 118  	public function test_bbp_get_user_forum_subscriptions() {
 119          $u = $this->factory->user->create();
 120          $f = $this->factory->forum->create_many( 3 );
 121  
 122          // Add forum subscriptions.
 123          bbp_add_user_forum_subscription( $u, $f[0] );
 124          bbp_add_user_forum_subscription( $u, $f[1] );
 125          bbp_add_user_forum_subscription( $u, $f[2] );
 126  
 127          $expected = bbp_has_forums( array( 'post__in' => array( $f[0], $f[1], $f[2] ) ) );
 128          $subscriptions = bbp_get_user_forum_subscriptions( $u );
 129  
 130          $this->assertEquals( $expected, $subscriptions );
 131  
 132          // Remove forum subscription.
 133          bbp_remove_user_forum_subscription( $u, $f[1] );
 134  
 135          $expected = bbp_has_forums( array( 'post__in' => array( $f[0], $f[2] ) ) );
 136          $subscriptions = bbp_get_user_forum_subscriptions( $u );
 137  
 138          $this->assertEquals( $expected, $subscriptions );
 139      }
 140  
 141      /**
 142       * @covers ::bbp_get_user_subscribed_forum_ids
 143       */
 144  	public function test_bbp_get_user_subscribed_forum_ids() {
 145          $u = $this->factory->user->create();
 146          $f = $this->factory->forum->create_many( 3 );
 147  
 148          // Add forum subscriptions.
 149          bbp_add_user_forum_subscription( $u, $f[0] );
 150          bbp_add_user_forum_subscription( $u, $f[1] );
 151          bbp_add_user_forum_subscription( $u, $f[2] );
 152  
 153          $subscriptions = bbp_get_user_subscribed_forum_ids( $u );
 154  
 155          $this->assertEqualSets( array( $f[0], $f[1], $f[2] ), $subscriptions );
 156  
 157          // Remove forum subscription.
 158          bbp_remove_user_forum_subscription( $u, $f[1] );
 159  
 160          $subscriptions = bbp_get_user_subscribed_forum_ids( $u );
 161  
 162          $this->assertEqualSets( array( $f[0], $f[2] ), $subscriptions );
 163      }
 164  
 165      /**
 166       * @covers ::bbp_get_user_subscribed_topic_ids
 167       */
 168  	public function test_bbp_get_user_subscribed_topic_ids() {
 169          $u = $this->factory->user->create();
 170          $t = $this->factory->topic->create_many( 3 );
 171  
 172          // Add topic subscriptions.
 173          bbp_add_user_topic_subscription( $u, $t[0] );
 174          bbp_add_user_topic_subscription( $u, $t[1] );
 175          bbp_add_user_topic_subscription( $u, $t[2] );
 176  
 177          $subscriptions = bbp_get_user_subscribed_topic_ids( $u );
 178  
 179          $this->assertEqualSets( array( $t[0], $t[1], $t[2] ), $subscriptions );
 180  
 181          // Remove topic subscription.
 182          bbp_remove_user_topic_subscription( $u, $t[1] );
 183  
 184          $subscriptions = bbp_get_user_subscribed_topic_ids( $u );
 185  
 186          $this->assertEqualSets( array( $t[0], $t[2] ), $subscriptions );
 187      }
 188  
 189      /**
 190       * @covers ::bbp_is_user_subscribed
 191       */
 192  	public function test_bbp_is_user_subscribed() {
 193          $u = $this->factory->user->create();
 194          $f = $this->factory->forum->create_many( 2 );
 195          $t = $this->factory->topic->create_many( 2 );
 196  
 197          // Add forum subscription.
 198          bbp_add_user_forum_subscription( $u, $f[0] );
 199  
 200          $this->assertTrue( bbp_is_user_subscribed( $u, $f[0] ) );
 201          $this->assertFalse( bbp_is_user_subscribed( $u, $f[1] ) );
 202  
 203          // Add topic subscription.
 204          bbp_add_user_topic_subscription( $u, $t[0] );
 205  
 206          $this->assertTrue( bbp_is_user_subscribed( $u, $t[0] ) );
 207          $this->assertFalse( bbp_is_user_subscribed( $u, $t[1] ) );
 208      }
 209  
 210      /**
 211       * @covers ::bbp_is_user_subscribed_to_forum
 212       */
 213  	public function test_bbp_is_user_subscribed_to_forum() {
 214          $u = $this->factory->user->create();
 215          $f = $this->factory->forum->create_many( 2 );
 216  
 217          // Add forum subscription.
 218          bbp_add_user_forum_subscription( $u, $f[0] );
 219  
 220          $this->assertTrue( bbp_is_user_subscribed_to_forum( $u, $f[0] ) );
 221          $this->assertFalse( bbp_is_user_subscribed_to_forum( $u, $f[1] ) );
 222      }
 223  
 224      /**
 225       * @covers ::bbp_is_user_subscribed_to_topic
 226       */
 227  	public function test_bbp_is_user_subscribed_to_topic() {
 228          $u = $this->factory->user->create();
 229          $t = $this->factory->topic->create_many( 2 );
 230  
 231          // Add topic subscription.
 232          bbp_add_user_topic_subscription( $u, $t[0] );
 233  
 234          $this->assertTrue( bbp_is_user_subscribed_to_topic( $u, $t[0] ) );
 235          $this->assertFalse( bbp_is_user_subscribed_to_topic( $u, $t[1] ) );
 236      }
 237  
 238      /**
 239       * @covers ::bbp_add_user_subscription
 240       */
 241  	public function test_bbp_add_user_subscription() {
 242          $u = $this->factory->user->create();
 243          $f = $this->factory->forum->create();
 244          $t = $this->factory->topic->create( array(
 245              'post_parent' => $f,
 246              'topic_meta' => array(
 247                  'forum_id' => $f,
 248              ),
 249          ) );
 250  
 251          // Add forum subscription.
 252          bbp_add_user_subscription( $u, $f );
 253  
 254          $this->assertTrue( bbp_is_user_subscribed_to_forum( $u, $f ) );
 255  
 256          // Add topic subscription.
 257          bbp_add_user_subscription( $u, $t );
 258  
 259          $this->assertTrue( bbp_is_user_subscribed_to_topic( $u, $t ) );
 260      }
 261  
 262      /**
 263       * @covers ::bbp_add_user_forum_subscription
 264       */
 265  	public function test_bbp_add_user_forum_subscription() {
 266          $u = $this->factory->user->create();
 267          $f = $this->factory->forum->create();
 268  
 269          // Add forum subscription.
 270          bbp_add_user_forum_subscription( $u, $f );
 271  
 272          $this->assertTrue( bbp_is_user_subscribed_to_forum( $u, $f ) );
 273      }
 274  
 275      /**
 276       * @covers ::bbp_add_user_topic_subscription
 277       */
 278  	public function test_bbp_add_user_topic_subscription() {
 279          $u = $this->factory->user->create();
 280          $t = $this->factory->topic->create();
 281  
 282          // Add forum subscription.
 283          bbp_add_user_topic_subscription( $u, $t );
 284  
 285          $this->assertTrue( bbp_is_user_subscribed_to_topic( $u, $t ) );
 286      }
 287  
 288      /**
 289       * @covers ::bbp_remove_user_subscription
 290       */
 291  	public function test_bbp_remove_user_subscription() {
 292          $u = $this->factory->user->create();
 293          $f = $this->factory->forum->create();
 294          $t = $this->factory->topic->create( array(
 295              'post_parent' => $f,
 296              'topic_meta' => array(
 297                  'forum_id' => $f,
 298              ),
 299          ) );
 300  
 301          // Add forum subscription.
 302          bbp_add_user_subscription( $u, $f );
 303  
 304          $this->assertTrue( bbp_is_user_subscribed_to_forum( $u, $f ) );
 305  
 306          // Remove forum subscription.
 307          bbp_remove_user_subscription( $u, $f );
 308  
 309          $this->assertFalse( bbp_is_user_subscribed_to_forum( $u, $f ) );
 310  
 311          // Add topic subscription.
 312          bbp_add_user_subscription( $u, $t );
 313  
 314          $this->assertTrue( bbp_is_user_subscribed_to_topic( $u, $t ) );
 315  
 316          // Remove topic subscription.
 317          bbp_remove_user_subscription( $u, $t );
 318  
 319          $this->assertFalse( bbp_is_user_subscribed_to_topic( $u, $t ) );
 320      }
 321  
 322      /**
 323       * @covers ::bbp_remove_user_forum_subscription
 324       */
 325  	public function test_bbp_remove_user_forum_subscription() {
 326          $u = $this->factory->user->create();
 327          $f = $this->factory->forum->create();
 328  
 329          // Add forum subscription.
 330          bbp_add_user_forum_subscription( $u, $f );
 331  
 332          $this->assertTrue( bbp_is_user_subscribed_to_forum( $u, $f ) );
 333  
 334          // Remove forum subscription.
 335          bbp_remove_user_forum_subscription( $u, $f );
 336  
 337          $this->assertFalse( bbp_is_user_subscribed_to_forum( $u, $f ) );
 338      }
 339  
 340      /**
 341       * @covers ::bbp_remove_user_topic_subscription
 342       */
 343  	public function test_bbp_remove_user_topic_subscription() {
 344          $u = $this->factory->user->create();
 345          $t = $this->factory->topic->create();
 346  
 347          // Add forum subscription.
 348          bbp_add_user_topic_subscription( $u, $t );
 349  
 350          $this->assertTrue( bbp_is_user_subscribed_to_topic( $u, $t ) );
 351  
 352          // Remove topic subscription.
 353          bbp_remove_user_topic_subscription( $u, $t );
 354  
 355          $this->assertFalse( bbp_is_user_subscribed_to_topic( $u, $t ) );
 356      }
 357  
 358      /**
 359       * @covers ::bbp_forum_subscriptions_handler
 360       * @todo   Implement test_bbp_forum_subscriptions_handler().
 361       */
 362  	public function test_bbp_forum_subscriptions_handler() {
 363          // Remove the following lines when you implement this test.
 364          $this->markTestIncomplete(
 365              'This test has not been implemented yet.'
 366          );
 367      }
 368  
 369      /**
 370       * @covers ::bbp_subscriptions_handler
 371       * @todo   Implement test_bbp_subscriptions_handler().
 372       */
 373  	public function test_bbp_subscriptions_handler() {
 374          // Remove the following lines when you implement this test.
 375          $this->markTestIncomplete(
 376              'This test has not been implemented yet.'
 377          );
 378      }
 379  }


Generated: Mon Dec 30 01:00:53 2024 Cross-referenced by PHPXref 0.7.1