[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * Tests for the `bbp_*_forum_*()` template functions.
   5   *
   6   * @group forums
   7   * @group template
   8   * @group forum
   9   */
  10  class BBP_Tests_Forums_Template_Forum extends BBP_UnitTestCase {
  11  
  12      /**
  13       * @covers ::bbp_forum_id
  14       * @covers ::bbp_get_forum_id
  15       */
  16  	public function test_bbp_get_forum_id() {
  17          $f = $this->factory->forum->create();
  18  
  19          $forum_id = bbp_get_forum_id( $f );
  20          $this->assertSame( $f, $forum_id );
  21      }
  22  
  23      /**
  24       * @covers ::bbp_get_forum
  25       * @todo   Implement test_bbp_get_forum().
  26       */
  27  	public function test_bbp_get_forum() {
  28          // Remove the following lines when you implement this test.
  29          $this->markTestIncomplete(
  30              'This test has not been implemented yet.'
  31          );
  32      }
  33  
  34      /**
  35       * @covers ::bbp_forum_permalink
  36       * @covers ::bbp_get_forum_permalink
  37       */
  38  	public function test_bbp_get_forum_permalink() {
  39  
  40          if ( is_multisite() ) {
  41              $this->markTestSkipped( 'Skipping URL tests in multiste for now.' );
  42          }
  43  
  44          // Public category.
  45          $c = $this->factory->forum->create( array(
  46              'post_title' => 'Public Category',
  47          ) );
  48  
  49          $category = bbp_get_forum_permalink( $c );
  50          $this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/?forum=public-category', $category );
  51  
  52          // Public forum of public category.
  53          $f = $this->factory->forum->create( array(
  54              'post_title' => 'Public Forum',
  55              'post_parent' => $c,
  56          ) );
  57  
  58          $forum_permalink = bbp_get_forum_permalink( $f );
  59          $this->expectOutputString( $forum_permalink );
  60          bbp_forum_permalink( $f );
  61  
  62          $forum = bbp_get_forum_permalink( $f );
  63          $this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/?forum=public-category/public-forum', $forum );
  64  
  65          // Private category.
  66          $c = $this->factory->forum->create( array(
  67              'post_title' => 'Private Category',
  68          ) );
  69  
  70          $category = bbp_get_forum_permalink( $c );
  71  
  72          $forum = bbp_get_forum_permalink( $f );
  73          $this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/?forum=private-category', $category );
  74  
  75          // Private forum of private category.
  76          $f = $this->factory->forum->create( array(
  77              'post_title' => 'Private Forum',
  78              'post_parent' => $c,
  79          ) );
  80  
  81          bbp_privatize_forum( $c );
  82          $forum = bbp_get_forum_permalink( $f );
  83          $this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/?forum=private-category/private-forum', $forum );
  84  
  85          // Hidden category.
  86          $c = $this->factory->forum->create( array(
  87              'post_title' => 'Hidden Category',
  88          ) );
  89  
  90          bbp_hide_forum( $c );
  91          $category = bbp_get_forum_permalink( $c );
  92          $this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/?forum=hidden-category', $category );
  93  
  94          // Hidden forum of hidden category.
  95          $f = $this->factory->forum->create( array(
  96              'post_title' => 'Hidden Forum',
  97              'post_parent' => $c,
  98          ) );
  99  
 100          $forum = bbp_get_forum_permalink( $f );
 101          $this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/?forum=hidden-category/hidden-forum', $forum );
 102      }
 103  
 104      /**
 105       * @covers ::bbp_forum_title
 106       * @covers ::bbp_get_forum_title
 107       */
 108  	public function test_bbp_get_forum_title() {
 109          $f = $this->factory->forum->create( array(
 110              'post_title' => 'Forum 1',
 111          ) );
 112  
 113          $forum = bbp_get_forum_title( $f );
 114          $this->assertSame( 'Forum 1', $forum );
 115      }
 116  
 117      /**
 118       * @covers ::bbp_forum_archive_title
 119       * @covers ::bbp_get_forum_archive_title
 120       * @todo   Implement test_bbp_forum_archive_title().
 121       * @todo   Implement test_bbp_get_forum_archive_title().
 122       */
 123  	public function test_bbp_get_forum_archive_title() {
 124          // Remove the following lines when you implement this test.
 125          $this->markTestIncomplete(
 126              'This test has not been implemented yet.'
 127          );
 128      }
 129  
 130      /**
 131       * @covers ::bbp_forum_content
 132       * @covers ::bbp_get_forum_content
 133       */
 134  	public function test_bbp_get_forum_content() {
 135          $f = $this->factory->forum->create( array(
 136              'post_content' => 'Content of Forum 1',
 137          ) );
 138  
 139          $forum = bbp_get_forum_content( $f );
 140          $this->assertSame( 'Content of Forum 1', $forum );
 141      }
 142  
 143      /**
 144       * @covers ::bbp_forum_freshness_link
 145       * @covers ::bbp_get_forum_freshness_link
 146       */
 147  	public function test_bbp_get_forum_freshness_link() {
 148  
 149          if ( is_multisite() ) {
 150              $this->markTestSkipped( 'Skipping URL tests in multiste for now.' );
 151          }
 152  
 153          $now = time();
 154          $post_date = date( 'Y-m-d H:i:s', $now - 60*60*100 );
 155  
 156          $f = $this->factory->forum->create();
 157  
 158          $fresh_link = bbp_get_forum_freshness_link( $f );
 159          $this->assertSame( 'No Topics', $fresh_link );
 160  
 161          $t = $this->factory->topic->create( array(
 162              'post_title' => 'Topic 1',
 163              'post_parent' => $f,
 164              'post_date' => $post_date,
 165              'topic_meta' => array(
 166                  'forum_id' => $f,
 167              ),
 168          ) );
 169  
 170          $fresh_link = bbp_get_forum_freshness_link( $f );
 171          $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1" title="Topic 1">4 days, 4 hours ago</a>', $fresh_link );
 172      }
 173  
 174      /**
 175       * @covers ::bbp_get_forum_freshness_link
 176       */
 177      public function test_bbp_get_forum_freshness_link_with_unpublished_replies() {
 178  
 179          if ( is_multisite() ) {
 180              $this->markTestSkipped( 'Skipping URL tests in multiste for now.' );
 181          }
 182  
 183          $now = time();
 184          $post_date_t1 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 18 ); // 18 hours ago
 185          $post_date_t2 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 16 ); // 16 hours ago
 186          $post_date_t3 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 14 ); // 14 hours ago
 187          $post_date_t4 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 12 ); // 12 hours ago
 188          $post_date_t5 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 10 ); // 1o hours ago
 189  
 190          $f = $this->factory->forum->create();
 191  
 192          $link = bbp_get_forum_freshness_link( $f );
 193          $this->assertSame( 'No Topics', $link );
 194  
 195          $t1 = $this->factory->topic->create( array(
 196              'post_title' => 'Topic 1',
 197              'post_parent' => $f,
 198              'post_date' => $post_date_t1,
 199              'topic_meta' => array(
 200                  'forum_id' => $f,
 201              ),
 202          ) );
 203  
 204          $link = bbp_get_forum_freshness_link( $f );
 205          $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1" title="Topic 1">18 hours ago</a>', $link );
 206  
 207          $t2 = $this->factory->topic->create( array(
 208              'post_title' => 'Topic 2',
 209              'post_parent' => $f,
 210              'post_date' => $post_date_t2,
 211              'topic_meta' => array(
 212                  'forum_id' => $f,
 213              ),
 214          ) );
 215  
 216          $link = bbp_get_forum_freshness_link( $f );
 217          $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-2" title="Topic 2">16 hours ago</a>', $link );
 218  
 219          bbp_spam_topic( $t2 );
 220  
 221          $link = bbp_get_forum_freshness_link( $f );
 222          $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1" title="Topic 1">18 hours ago</a>', $link );
 223  
 224          $t3 = $this->factory->topic->create( array(
 225              'post_title' => 'Topic 3',
 226              'post_parent' => $f,
 227              'post_date' => $post_date_t3,
 228              'topic_meta' => array(
 229                  'forum_id' => $f,
 230              ),
 231          ) );
 232  
 233          $link = bbp_get_forum_freshness_link( $f );
 234          $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-3" title="Topic 3">14 hours ago</a>', $link );
 235  
 236          // Todo: Use bbp_trash_topic() and not wp_trash_post()
 237          wp_trash_post( $t3 );
 238  
 239          $link = bbp_get_forum_freshness_link( $f );
 240          $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1" title="Topic 1">18 hours ago</a>', $link );
 241  
 242          $t4 = $this->factory->topic->create( array(
 243              'post_title' => 'Topic 4',
 244              'post_parent' => $f,
 245              'post_date' => $post_date_t4,
 246              'topic_meta' => array(
 247                  'forum_id' => $f,
 248              ),
 249          ) );
 250  
 251          $link = bbp_get_forum_freshness_link( $f );
 252          $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-4" title="Topic 4">12 hours ago</a>', $link );
 253  
 254          bbp_unapprove_topic( $t4 );
 255  
 256          $link = bbp_get_forum_freshness_link( $f );
 257          $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1" title="Topic 1">18 hours ago</a>', $link );
 258  
 259          bbp_unspam_topic( $t2 );
 260  
 261          $link = bbp_get_forum_freshness_link( $f );
 262          $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-2" title="Topic 2">16 hours ago</a>', $link );
 263  
 264          // Todo: Use bbp_untrash_topic() and not wp_untrash_post()
 265          wp_untrash_post( $t3 );
 266  
 267          $link = bbp_get_forum_freshness_link( $f );
 268          $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-3" title="Topic 3">14 hours ago</a>', $link );
 269  
 270          bbp_approve_topic( $t4 );
 271  
 272          $link = bbp_get_forum_freshness_link( $f );
 273          $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-4" title="Topic 4">12 hours ago</a>', $link );
 274  
 275          $t5 = $this->factory->topic->create( array(
 276              'post_title' => 'Topic 5',
 277              'post_parent' => $f,
 278              'post_date' => $post_date_t5,
 279              'topic_meta' => array(
 280                  'forum_id' => $f,
 281              ),
 282          ) );
 283  
 284          $link = bbp_get_forum_freshness_link( $f );
 285          $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-5" title="Topic 5">10 hours ago</a>', $link );
 286      }
 287  
 288      /**
 289       * @covers ::bbp_forum_parent_id
 290       * @covers ::bbp_get_forum_parent_id
 291       */
 292  	public function test_bbp_get_forum_parent_id() {
 293          $f1 = $this->factory->forum->create();
 294  
 295          $forum_id = bbp_get_forum_parent_id( $f1 );
 296          $this->assertSame( 0, $forum_id );
 297  
 298          $f2 = $this->factory->forum->create( array(
 299              'post_parent' => $f1,
 300          ) );
 301  
 302          $forum_id = bbp_get_forum_parent_id( $f2 );
 303          $this->assertSame( $f1, $forum_id );
 304      }
 305  
 306      /**
 307       * @covers ::bbp_get_forum_ancestors
 308       * @todo   Implement test_bbp_get_forum_ancestors().
 309       */
 310  	public function test_bbp_get_forum_ancestors() {
 311          // Remove the following lines when you implement this test.
 312          $this->markTestIncomplete(
 313              'This test has not been implemented yet.'
 314          );
 315      }
 316  
 317      /**
 318       * @covers ::bbp_forum_get_subforums
 319       * @todo   Implement test_bbp_forum_get_subforums().
 320       */
 321  	public function test_bbp_forum_get_subforums() {
 322          // Remove the following lines when you implement this test.
 323          $this->markTestIncomplete(
 324              'This test has not been implemented yet.'
 325          );
 326      }
 327  
 328      /**
 329       * @covers ::bbp_list_forums
 330       * @todo   Implement test_bbp_list_forums().
 331       */
 332  	public function test_bbp_list_forums() {
 333          // Remove the following lines when you implement this test.
 334          $this->markTestIncomplete(
 335              'This test has not been implemented yet.'
 336          );
 337      }
 338  
 339      /**
 340       * @covers ::bbp_forum_subscription_link
 341       * @covers ::bbp_get_forum_subscription_link
 342       * @todo   Implement test_bbp_get_forum_subscription_link().
 343       */
 344  	public function test_bbp_get_forum_subscription_link() {
 345          // Remove the following lines when you implement this test.
 346          $this->markTestIncomplete(
 347              'This test has not been implemented yet.'
 348          );
 349      }
 350  
 351      /**
 352       * @covers ::bbp_forum_topics_link
 353       * @covers ::bbp_get_forum_topics_link
 354       * @todo   Implement test_bbp_get_forum_topics_link().
 355       */
 356  	public function test_bbp_get_forum_topics_link() {
 357          // Remove the following lines when you implement this test.
 358          $this->markTestIncomplete(
 359              'This test has not been implemented yet.'
 360          );
 361      }
 362  
 363      /**
 364       * @covers ::bbp_forum_class
 365       * @covers ::bbp_get_forum_class
 366       * @todo   Implement test_bbp_get_forum_class().
 367       */
 368  	public function test_bbp_get_forum_class() {
 369          // Remove the following lines when you implement this test.
 370          $this->markTestIncomplete(
 371              'This test has not been implemented yet.'
 372          );
 373      }
 374  
 375      /**
 376       * @covers ::bbp_single_forum_description
 377       * @covers ::bbp_get_single_forum_description
 378       */
 379  	public function test_bbp_get_single_forum_description() {
 380          $f = $this->factory->forum->create();
 381  
 382          $forum = bbp_get_single_forum_description( $f );
 383          $this->assertSame( '<div class="bbp-template-notice info"><ul><li class="bbp-forum-description">This forum is empty.</li></ul></div>', $forum );
 384      }
 385  }


Generated: Sat Apr 27 01:00:49 2024 Cross-referenced by PHPXref 0.7.1