Skip to:
Content

bbPress.org

Changeset 5873


Ignore:
Timestamp:
07/21/2015 10:06:59 AM (11 years ago)
Author:
netweb
Message:

Tests: Complete topic template tests in BBP_Tests_Topics_Template_Get_Topic_Last_Thing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/topics/template/get-last-thing.php

    r5751 r5873  
    1313     * @covers ::bbp_topic_last_active_id
    1414     * @covers ::bbp_get_topic_last_active_id
    15      * @todo   Implement test_bbp_get_topic_last_active_id().
    1615     */
    1716    public function test_bbp_get_topic_last_active_id() {
    18         // Remove the following lines when you implement this test.
    19         $this->markTestIncomplete(
    20             'This test has not been implemented yet.'
    21         );
     17        $f = $this->factory->forum->create();
     18        $t = $this->factory->topic->create( array(
     19            'post_parent' => $f,
     20            'topic_meta' => array(
     21                'forum_id' => $f,
     22            )
     23        ) );
     24
     25        $topic_last_active_id = bbp_get_topic_last_active_id( $t );
     26        $this->assertSame( $t, $topic_last_active_id );
     27
     28        $r = $this->factory->reply->create( array(
     29            'post_parent' => $t,
     30            'reply_meta' => array(
     31                'forum_id' => $f,
     32                'topic_id' => $t,
     33            )
     34        ) );
     35
     36        $topic_last_active_id = bbp_get_topic_last_active_id( $t );
     37        $this->assertSame( $r, $topic_last_active_id );
    2238    }
    2339
     
    2541     * @covers ::bbp_topic_last_active_time
    2642     * @covers ::bbp_get_topic_last_active_time
    27      * @todo   Implement test_bbp_get_topic_last_active_time().
    2843     */
    2944    public function test_bbp_get_topic_last_active_time() {
    30         // Remove the following lines when you implement this test.
    31         $this->markTestIncomplete(
    32             'This test has not been implemented yet.'
    33         );
     45        $f = $this->factory->forum->create();
     46
     47        $now = time();
     48        $post_date_topic = date( 'Y-m-d H:i:s', $now - 60*60*100 );
     49        $post_date_reply = date( 'Y-m-d H:i:s', $now - 60*60*80 );
     50
     51        $topic_time = '4 days, 4 hours ago';
     52        $reply_time = '1 hour, 6 minutes ago';
     53
     54        $t = $this->factory->topic->create( array(
     55            'post_parent' => $f,
     56            'post_date' => $post_date_topic,
     57            'topic_meta' => array(
     58                'forum_id' => $f,
     59            ),
     60        ) );
     61
     62        // Output.
     63        $this->expectOutputString( $topic_time );
     64        bbp_topic_last_active_time( $t );
     65
     66        // Topic time.
     67        $datetime = bbp_get_topic_last_active_time( $t );
     68        $this->assertSame( $topic_time, $datetime );
     69
     70        $this->factory->reply->create( array(
     71            'post_parent' => $t,
     72            'post_date' => $post_date_reply,
     73            'reply_meta' => array(
     74                'forum_id' => $f,
     75                'topic_id' => $t,
     76            ),
     77        ) );
     78
     79        // Reply time.
     80        $datetime = bbp_get_topic_last_active_time( $t );
     81        $this->assertSame( '1 hour, 6 minutes ago', $reply_time );
     82
    3483    }
    3584
     
    3786     * @covers ::bbp_topic_last_reply_id
    3887     * @covers ::bbp_get_topic_last_reply_id
    39      * @todo   Implement test_bbp_get_topic_last_reply_id().
    4088     */
    4189    public function test_bbp_get_topic_last_reply_id() {
    42         // Remove the following lines when you implement this test.
    43         $this->markTestIncomplete(
    44             'This test has not been implemented yet.'
    45         );
     90        $f = $this->factory->forum->create();
     91        $t = $this->factory->topic->create( array(
     92            'post_parent' => $f,
     93            'topic_meta' => array(
     94                'forum_id' => $f,
     95            )
     96        ) );
     97
     98        $topic_last_reply_id = bbp_get_topic_last_reply_id( $t );
     99        $this->assertSame( 0, $topic_last_reply_id );
     100
     101        $r = $this->factory->reply->create( array(
     102            'post_parent' => $t,
     103            'reply_meta' => array(
     104                'forum_id' => $f,
     105                'topic_id' => $t,
     106            )
     107        ) );
     108
     109        $topic_last_reply_id = bbp_get_topic_last_reply_id( $t );
     110        $this->assertSame( $r, $topic_last_reply_id );
    46111    }
    47112
     
    49114     * @covers ::bbp_topic_last_reply_title
    50115     * @covers ::bbp_get_topic_last_reply_title
    51      * @todo   Implement test_bbp_get_topic_last_reply_title().
    52116     */
    53117    public function test_bbp_get_topic_last_reply_title() {
    54         // Remove the following lines when you implement this test.
    55         $this->markTestIncomplete(
    56             'This test has not been implemented yet.'
    57         );
     118        $f = $this->factory->forum->create();
     119        $t = $this->factory->topic->create( array(
     120            'post_parent' => $f,
     121            'topic_meta' => array(
     122                'forum_id' => $f,
     123            )
     124        ) );
     125
     126        $title = bbp_get_topic_last_reply_title( $t );
     127        $this->assertSame( '', $title );
     128
     129        $this->factory->reply->create( array(
     130            'post_parent' => $t,
     131            'reply_meta' => array(
     132                'forum_id' => $f,
     133                'topic_id' => $t,
     134            )
     135        ) );
     136
     137        $title = bbp_get_topic_last_reply_title( $t );
     138        $this->assertSame( 'Reply To: ' . bbp_get_topic_title( $t ), $title );
    58139    }
    59140
     
    61142     * @covers ::bbp_topic_last_reply_permalink
    62143     * @covers ::bbp_get_topic_last_reply_permalink
    63      * @todo   Implement test_bbp_get_topic_last_reply_permalink().
    64144     */
    65145    public function test_bbp_get_topic_last_reply_permalink() {
    66         // Remove the following lines when you implement this test.
    67         $this->markTestIncomplete(
    68             'This test has not been implemented yet.'
    69         );
     146        if ( is_multisite() ) {
     147            $this->markTestSkipped( 'Skipping URL tests in multiste for now.' );
     148        }
     149
     150        $f = $this->factory->forum->create();
     151
     152        $t = $this->factory->topic->create( array(
     153            'post_parent' => $f,
     154            'topic_meta' => array(
     155                'forum_id' => $f,
     156            )
     157        ) );
     158
     159        $topic_last_reply_permalink = bbp_get_topic_last_reply_permalink( $f );
     160        $this->assertSame( bbp_get_topic_permalink( $t ), $topic_last_reply_permalink );
     161
     162        $r = $this->factory->reply->create( array(
     163            'post_parent' => $t,
     164            'reply_meta' => array(
     165                'forum_id' => $f,
     166                'topic_id' => $t,
     167            )
     168        ) );
     169
     170        $topic_last_reply_permalink = bbp_get_topic_last_reply_permalink( $f );
     171        $this->assertSame( bbp_get_reply_permalink( $r ), $topic_last_reply_permalink );
    70172    }
    71173
     
    73175     * @covers ::bbp_topic_last_reply_url
    74176     * @covers ::bbp_get_topic_last_reply_url
    75      * @todo   Implement test_bbp_get_topic_last_reply_url().
    76177     */
    77178    public function test_bbp_get_topic_last_reply_url() {
    78         // Remove the following lines when you implement this test.
    79         $this->markTestIncomplete(
    80             'This test has not been implemented yet.'
    81         );
     179        if ( is_multisite() ) {
     180            $this->markTestSkipped( 'Skipping URL tests in multiste for now.' );
     181        }
     182
     183        $f = $this->factory->forum->create();
     184
     185        $t = $this->factory->topic->create( array(
     186            'post_parent' => $f,
     187            'topic_meta' => array(
     188                'forum_id' => $f,
     189            )
     190        ) );
     191
     192        $topic_last_reply_url = bbp_get_topic_last_reply_url( $t );
     193        $this->assertSame( get_permalink( $t ), $topic_last_reply_url );
     194
     195        $r = $this->factory->reply->create( array(
     196            'post_parent' => $t,
     197            'reply_meta' => array(
     198                'forum_id' => $f,
     199                'topic_id' => $t,
     200            )
     201        ) );
     202
     203        $topic_last_reply_url = bbp_get_topic_last_reply_url( $t );
     204        $this->assertSame( bbp_get_reply_url( $r ), $topic_last_reply_url );
    82205    }
    83206}
Note: See TracChangeset for help on using the changeset viewer.