[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Tests for the topics component topic template functions.
   4   *
   5   * @group topics
   6   * @group template
   7   * @group topic
   8   */
   9  class BBP_Tests_Topics_Template_Topic extends BBP_UnitTestCase {
  10  
  11      /**
  12       * @covers ::bbp_show_lead_topic
  13       * @todo   Implement test_bbp_show_lead_topic().
  14       */
  15  	public function test_bbp_show_lead_topic() {
  16          // Remove the following lines when you implement this test.
  17          $this->markTestIncomplete(
  18              'This test has not been implemented yet.'
  19          );
  20      }
  21  
  22      /**
  23       * @covers ::bbp_topic_id
  24       * @covers ::bbp_get_topic_id
  25       */
  26  	public function test_bbp_get_topic_id() {
  27          $f = $this->factory->forum->create();
  28          $t = $this->factory->topic->create( array(
  29              'post_parent' => $f,
  30              'topic_meta' => array(
  31                  'forum_id' => $f,
  32              ),
  33          ) );
  34  
  35          $topic_id = bbp_get_topic_id( $t );
  36          $this->assertSame( $t, $topic_id );
  37      }
  38  
  39      /**
  40       * @covers ::bbp_get_topic
  41       * @todo   Implement test_bbp_get_topic().
  42       */
  43  	public function test_bbp_get_topic() {
  44          // Remove the following lines when you implement this test.
  45          $this->markTestIncomplete(
  46              'This test has not been implemented yet.'
  47          );
  48      }
  49  
  50      /**
  51       * @covers ::bbp_topic_permalink
  52       * @covers ::bbp_get_topic_permalink
  53       */
  54  	public function test_bbp_get_topic_permalink() {
  55          if ( is_multisite() ) {
  56              $this->markTestSkipped( 'Skipping URL tests in multiste for now.' );
  57          }
  58          $f = $this->factory->forum->create();
  59          $t = $this->factory->topic->create( array(
  60              'post_title' => 'Topic 1',
  61              'post_parent' => $f,
  62              'topic_meta' => array(
  63                  'forum_id' => $f,
  64              ),
  65          ) );
  66  
  67          $topic_permalink = bbp_get_topic_permalink( $t );
  68  
  69          $this->expectOutputString( $topic_permalink );
  70          bbp_topic_permalink( $t );
  71  
  72          $this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/?topic=topic-1', $topic_permalink );
  73      }
  74  
  75      /**
  76       * @covers ::bbp_topic_title
  77       * @covers ::bbp_get_topic_title
  78       */
  79  	public function test_bbp_get_topic_title() {
  80          $f = $this->factory->forum->create();
  81          $t = $this->factory->topic->create( array(
  82              'post_title' => 'Topic 1',
  83              'post_parent' => $f,
  84              'topic_meta' => array(
  85                  'forum_id' => $f,
  86              ),
  87          ) );
  88  
  89          $topic_title = bbp_get_topic_title( $t );
  90          $this->assertSame( 'Topic 1', $topic_title );
  91      }
  92  
  93      /**
  94       * @covers ::bbp_topic_title
  95       * @covers ::bbp_get_topic_title
  96       * @group  bbp_xss
  97       */
  98      public function test_bbp_get_topic_title_with_script_and_quotes() {
  99          $f = $this->factory->forum->create();
 100          $t = $this->factory->topic->create( array(
 101              'post_title'  => '<script src="https://bbpress.org">Script</script> Topic',
 102              'post_parent' => $f,
 103              'topic_meta'  => array(
 104                  'forum_id' => $f,
 105              ),
 106          ) );
 107  
 108          $topic_title = bbp_get_topic_title( $t );
 109          $this->assertSame( 'Script Topic', $topic_title );
 110      }
 111  
 112      /**
 113       * @covers ::bbp_topic_title
 114       * @covers ::bbp_get_topic_title
 115       * @group  bbp_xss
 116       */
 117      public function test_bbp_get_topic_title_with_script_no_quotes() {
 118          $f = $this->factory->forum->create();
 119          $t = $this->factory->topic->create( array(
 120              'post_title'  => '<script src=https://bbpress.org>Script</script> Topic',
 121              'post_parent' => $f,
 122              'topic_meta'  => array(
 123                  'forum_id' => $f,
 124              ),
 125          ) );
 126  
 127          $topic_title = bbp_get_topic_title( $t );
 128          $this->assertSame( 'Script Topic', $topic_title );
 129      }
 130  
 131      /**
 132       * @covers ::bbp_topic_title
 133       * @covers ::bbp_get_topic_title
 134       * @group  bbp_xss
 135       */
 136  	public function test_bbp_get_topic_title_with_quotes() {
 137          $f = $this->factory->forum->create();
 138          $t = $this->factory->topic->create( array(
 139              'post_title'  => '"Quoted" Topic',
 140              'post_parent' => $f,
 141              'topic_meta'  => array(
 142                  'forum_id' => $f,
 143              ),
 144          ) );
 145  
 146          $topic_title = bbp_get_topic_title( $t );
 147          $this->assertSame( '&#8220;Quoted&#8221; Topic', $topic_title );
 148      }
 149  
 150      /**
 151       * @covers ::bbp_topic_title
 152       * @covers ::bbp_get_topic_title
 153       * @group  bbp_xss
 154       */
 155  	public function test_bbp_get_topic_title_with_js_as_img_src() {
 156          $f = $this->factory->forum->create();
 157          $t = $this->factory->topic->create( array(
 158              'post_title'  => '<img src="javascript:alert(\'Oh, bother!\');">Topic 1',
 159              'post_parent' => $f,
 160              'topic_meta'  => array(
 161                  'forum_id' => $f,
 162              ),
 163          ) );
 164  
 165          $topic_title = bbp_get_topic_title( $t );
 166          $this->assertSame( 'Topic 1', $topic_title );
 167      }
 168  
 169      /**
 170       * @covers ::bbp_topic_title
 171       * @covers ::bbp_get_topic_title
 172       * @group  bbp_xss
 173       */
 174      public function test_bbp_get_topic_title_with_extra_open_brackets() {
 175          $f = $this->factory->forum->create();
 176          $t = $this->factory->topic->create( array(
 177              'post_title'  => '<<script>alert("XSS");//<</script>',
 178              'post_parent' => $f,
 179              'topic_meta'  => array(
 180                  'forum_id' => $f,
 181              ),
 182          ) );
 183  
 184          $topic_title = bbp_get_topic_title( $t );
 185          $this->assertSame( '&lt;alert(&#8220;XSS&#8221;);//&lt;', $topic_title );
 186      }
 187  
 188      /**
 189       * @covers ::bbp_topic_archive_title
 190       * @covers ::bbp_get_topic_archive_title
 191       * @todo   Implement test_bbp_get_topic_archive_title().
 192       */
 193  	public function test_bbp_get_topic_archive_title() {
 194          // Remove the following lines when you implement this test.
 195          $this->markTestIncomplete(
 196              'This test has not been implemented yet.'
 197          );
 198      }
 199  
 200      /**
 201       * @covers ::bbp_topic_content
 202       * @covers ::bbp_get_topic_content
 203       */
 204  	public function test_bbp_get_topic_content() {
 205          $f = $this->factory->forum->create();
 206          $t = $this->factory->topic->create( array(
 207              'post_content' => 'Content of Topic 1',
 208              'post_parent' => $f,
 209              'topic_meta' => array(
 210                  'forum_id' => $f,
 211              ),
 212          ) );
 213  
 214          remove_all_filters( 'bbp_get_topic_content' );
 215          $topic_content = bbp_get_topic_content( $t );
 216          $this->assertSame( 'Content of Topic 1', $topic_content );
 217      }
 218  
 219      /**
 220       * @covers ::bbp_topic_excerpt
 221       * @covers ::bbp_get_topic_excerpt
 222       */
 223  	public function test_bbp_get_topic_excerpt() {
 224          $f = $this->factory->forum->create();
 225          $t = $this->factory->topic->create( array(
 226              'post_parent' => $f,
 227              'post_content'  => 'Talk about telekinetic activity, look at this mess!',
 228              'topic_meta' => array(
 229                  'forum_id' => $f,
 230              ),
 231          ) );
 232  
 233          remove_all_filters( 'bbp_get_topic_content' );
 234          $topic_excerpt = bbp_get_topic_excerpt( $t, 23 );
 235          $this->assertSame( 'Talk about telekinetic&hellip;', $topic_excerpt );
 236      }
 237  
 238      /**
 239       * @covers ::bbp_topic_post_date
 240       * @covers ::bbp_get_topic_post_date
 241       */
 242  	public function test_bbp_get_topic_post_date() {
 243          $f = $this->factory->forum->create();
 244  
 245          $now = time();
 246          $post_date = date( 'Y-m-d H:i:s', $now - 60*60*100 );
 247  
 248          $t = $this->factory->topic->create( array(
 249              'post_parent' => $f,
 250              'post_date' => $post_date,
 251              'topic_meta' => array(
 252                  'forum_id' => $f,
 253              ),
 254          ) );
 255  
 256          // Configue our written date time, August 4, 2012 at 2:37 pm.
 257          $gmt = false;
 258          $date   = get_post_time( get_option( 'date_format' ), $gmt, $t, true );
 259          $time   = get_post_time( get_option( 'time_format' ), $gmt, $t, true );
 260          $result = sprintf( '%1$s at %2$s', $date, $time );
 261  
 262          // Output, string, August 4, 2012 at 2:37 pm.
 263          $this->expectOutputString( $result );
 264          bbp_topic_post_date( $t );
 265  
 266          // String, August 4, 2012 at 2:37 pm.
 267          $datetime = bbp_get_topic_post_date( $t, false, false );
 268          $this->assertSame( $result, $datetime );
 269  
 270          // Humanized string, 4 days, 4 hours ago.
 271          $datetime = bbp_get_topic_post_date( $t, true, false );
 272          $this->assertSame( '4 days, 4 hours ago', $datetime );
 273  
 274          // Humanized string using GMT formatted date, 4 days, 4 hours ago.
 275          $datetime = bbp_get_topic_post_date( $t, true, true );
 276          $this->assertSame( '4 days, 4 hours ago', $datetime );
 277      }
 278  
 279      /**
 280       * @covers ::bbp_topic_pagination
 281       * @covers ::bbp_get_topic_pagination
 282       * @todo   Implement test_bbp_get_topic_pagination().
 283       */
 284  	public function test_bbp_get_topic_pagination() {
 285          // Remove the following lines when you implement this test.
 286          $this->markTestIncomplete(
 287              'This test has not been implemented yet.'
 288          );
 289      }
 290  
 291      /**
 292       * @covers ::bbp_topic_forum_title
 293       * @covers ::bbp_get_topic_forum_title
 294       */
 295  	public function test_bbp_get_topic_forum_title() {
 296          $f = $this->factory->forum->create();
 297          $t = $this->factory->topic->create( array(
 298              'post_parent' => $f,
 299              'topic_meta' => array(
 300                  'forum_id' => $f,
 301              ),
 302          ) );
 303  
 304          $topic_forum_title = bbp_get_topic_forum_title( $t );
 305          $this->assertSame( bbp_get_forum_title( $f ), $topic_forum_title );
 306      }
 307  
 308      /**
 309       * @covers ::bbp_topic_forum_id
 310       * @covers ::bbp_get_topic_forum_id
 311       */
 312  	public function test_bbp_get_topic_forum_id() {
 313          $f = $this->factory->forum->create();
 314          $t = $this->factory->topic->create( array(
 315              'post_parent' => $f,
 316              'topic_meta' => array(
 317                  'forum_id' => $f,
 318              ),
 319          ) );
 320  
 321          $topic_forum_id = bbp_get_topic_forum_id( $t );
 322          $this->assertSame( $f, $topic_forum_id );
 323      }
 324  
 325      /**
 326       * @covers ::bbp_topic_class
 327       * @covers ::bbp_get_topic_class
 328       * @todo   Implement test_bbp_get_topic_class().
 329       */
 330  	public function test_bbp_get_topic_class() {
 331          // Remove the following lines when you implement this test.
 332          $this->markTestIncomplete(
 333              'This test has not been implemented yet.'
 334          );
 335      }
 336  
 337      /**
 338       * @covers ::bbp_forum_pagination_count
 339       * @covers ::bbp_get_forum_pagination_count
 340       * @todo   Implement test_bbp_get_forum_pagination_count().
 341       */
 342  	public function test_bbp_get_forum_pagination_count() {
 343          // Remove the following lines when you implement this test.
 344          $this->markTestIncomplete(
 345              'This test has not been implemented yet.'
 346          );
 347      }
 348  
 349      /**
 350       * @covers ::bbp_topic_notices
 351       * @todo   Implement test_bbp_topic_notices().
 352       */
 353  	public function test_bbp_topic_notices() {
 354          // Remove the following lines when you implement this test.
 355          $this->markTestIncomplete(
 356              'This test has not been implemented yet.'
 357          );
 358      }
 359  
 360      /**
 361       * @covers ::bbp_topic_type_select
 362       * @todo   Implement test_bbp_topic_type_select().
 363       */
 364  	public function test_bbp_topic_type_select() {
 365          // Remove the following lines when you implement this test.
 366          $this->markTestIncomplete(
 367              'This test has not been implemented yet.'
 368          );
 369      }
 370  
 371      /**
 372       * @covers ::bbp_single_topic_description
 373       * @covers ::bbp_get_single_topic_description
 374       * @todo   Implement test_bbp_get_single_topic_description().
 375       */
 376  	public function test_bbp_get_single_topic_description() {
 377          // Remove the following lines when you implement this test.
 378          $this->markTestIncomplete(
 379              'This test has not been implemented yet.'
 380          );
 381      }
 382  
 383      /**
 384       * @covers ::bbp_topic_row_actions
 385       * @todo   Implement test_bbp_topic_row_actions().
 386       */
 387  	public function test_bbp_topic_row_actions() {
 388          // Remove the following lines when you implement this test.
 389          $this->markTestIncomplete(
 390              'This test has not been implemented yet.'
 391          );
 392      }
 393  }


Generated: Mon Jul 22 01:01:32 2019 Cross-referenced by PHPXref 0.7.1