Skip to:
Content

bbPress.org

Ticket #2811: 2811.topics_tests.01.patch

File 2811.topics_tests.01.patch, 3.4 KB (added by thebrandonallen, 9 years ago)
  • tests/phpunit/testcases/topics/functions/update-last-thing.php

    diff --git tests/phpunit/testcases/topics/functions/update-last-thing.php tests/phpunit/testcases/topics/functions/update-last-thing.php
    index c666597..3a6b808 100644
    class BBP_Tests_Topics_Functions_Update_Topic_Last_Thing extends BBP_UnitTestCas 
    1111
    1212        /**
    1313         * @covers ::bbp_update_topic_last_active_id
    14          * @todo   Implement test_bbp_update_topic_last_active_id().
    1514         */
    1615        public function test_bbp_update_topic_last_active_id() {
    17                 // Remove the following lines when you implement this test.
    18                 $this->markTestIncomplete(
    19                         'This test has not been implemented yet.'
    20                 );
     16                $f = $this->factory->forum->create();
     17                $t = $this->factory->topic->create( array(
     18                        'post_parent' => $f,
     19                ) );
     20                $r1 = $this->factory->reply->create( array(
     21                        'post_parent' => $t,
     22                ) );
     23
     24                $id = bbp_update_topic_last_active_id( $t, $r1 );
     25                $this->assertSame( $r1, $id );
     26
     27                $id = bbp_get_topic_last_active_id( $t );
     28                $this->assertSame( $r1, $id );
     29
     30                $r2 = $this->factory->reply->create_many( 2, array(
     31                        'post_parent' => $t,
     32                ) );
     33
     34                bbp_update_topic_last_active_id( $t );
     35                $id = bbp_get_topic_last_active_id( $t );
     36                $this->assertSame( $r2[1], $id );
    2137        }
    2238
    2339        /**
    2440         * @covers ::bbp_update_topic_last_active_time
    25          * @todo   Implement test_bbp_update_topic_last_active_time().
    2641         */
    2742        public function test_bbp_update_topic_last_active_time() {
    28                 // Remove the following lines when you implement this test.
    29                 $this->markTestIncomplete(
    30                         'This test has not been implemented yet.'
    31                 );
     43                $f = $this->factory->forum->create();
     44                $t = $this->factory->topic->create( array(
     45                        'post_parent' => $f,
     46                ) );
     47                $r1 = $this->factory->reply->create( array(
     48                        'post_parent' => $t,
     49                ) );
     50
     51                $r1_time_raw       = get_post_field( 'post_date', $r1 );
     52                $r1_time_formatted = bbp_get_time_since( bbp_convert_date( $r1_time_raw ) );
     53
     54                $time = bbp_update_topic_last_active_time( $t, $r1_time_raw );
     55                $this->assertSame( $r1_time_raw, $time );
     56
     57                $time = bbp_get_topic_last_active_time( $t );
     58                $this->assertSame( $r1_time_formatted, $time );
     59
     60                $r2 = $this->factory->reply->create_many( 2, array(
     61                        'post_parent' => $t,
     62                ) );
     63
     64                $r2_time_raw       = get_post_field( 'post_date', $r2[1] );
     65                $r2_time_formatted = bbp_get_time_since( bbp_convert_date( $r2_time_raw ) );
     66
     67                bbp_update_topic_last_active_time( $t );
     68                $time = bbp_get_topic_last_active_time( $t );
     69                $this->assertSame( $r2_time_formatted, $time );
    3270        }
    3371
    3472        /**
    3573         * @covers ::bbp_update_topic_last_reply_id
    36          * @todo   Implement test_bbp_update_topic_last_reply_id().
    3774         */
    3875        public function test_bbp_update_topic_last_reply_id() {
    39                 // Remove the following lines when you implement this test.
    40                 $this->markTestIncomplete(
    41                         'This test has not been implemented yet.'
    42                 );
     76                $f = $this->factory->forum->create();
     77                $t = $this->factory->topic->create( array(
     78                        'post_parent' => $f,
     79                ) );
     80                $r1 = $this->factory->reply->create( array(
     81                        'post_parent' => $t,
     82                ) );
     83
     84                $id = bbp_update_topic_last_reply_id( $t, $r1 );
     85                $this->assertSame( $r1, $id );
     86
     87                $id = bbp_get_topic_last_reply_id( $t );
     88                $this->assertSame( $r1, $id );
     89
     90                $r2 = $this->factory->reply->create_many( 2, array(
     91                        'post_parent' => $t,
     92                ) );
     93
     94                bbp_update_topic_last_reply_id( $t );
     95                $id = bbp_get_topic_last_reply_id( $t );
     96                $this->assertSame( $r2[1], $id );
    4397        }
    4498}