Skip to:
Content

bbPress.org

Ticket #2806: 2806.diff

File 2806.diff, 2.0 KB (added by netweb, 11 years ago)
  • src/includes/topics/template.php

     
    19991999        echo bbp_get_topic_last_reply_id( $topic_id );
    20002000}
    20012001        /**
    2002          * Return the topics last update date/time (aka freshness)
     2002         * Return the topics last reply id
    20032003         *
    20042004         * @since bbPress (r2625)
    20052005         *
     
    20142014                $topic_id = bbp_get_topic_id( $topic_id );
    20152015                $reply_id = get_post_meta( $topic_id, '_bbp_last_reply_id', true );
    20162016
    2017                 if ( empty( $reply_id ) ) {
    2018                         $reply_id = $topic_id;
    2019                 }
    2020 
    20212017                return (int) apply_filters( 'bbp_get_topic_last_reply_id', (int) $reply_id, $topic_id );
    20222018        }
    20232019
  • tests/phpunit/testcases/2806.php

     
     1<?php
     2
     3/**
     4 * Tests for the topic component functions.
     5 *
     6 * @group get_last_thing
     7 */
     8class BBP_Tests_2806 extends BBP_UnitTestCase {
     9
     10        /**
     11         * @ticket 2806
     12         */
     13        public function test_bbp_get_forum_and_topic_last_topic_and_last_reply_id() {
     14
     15                $f = $this->factory->forum->create();
     16
     17                // Get the forums last topic id _bbp_last_topic_id
     18                $this->assertSame( 0, bbp_get_forum_last_topic_id( $f ) );
     19
     20                $t = $this->factory->topic->create( array(
     21                        'post_parent' => $f,
     22                        'topic_meta' => array(
     23                                'forum_id' => $f,
     24                        )
     25                ) );
     26
     27                // Get the forums last topic id _bbp_last_topic_id
     28                $this->assertSame( $t, bbp_get_forum_last_topic_id( $f ) );
     29
     30                // Get the topics last reply id _bbp_last_reply_id
     31                $this->assertSame( 0, bbp_get_topic_last_reply_id( $t ) );
     32
     33                // Create another reply
     34                $r = $this->factory->reply->create( array(
     35                        'post_parent' => $t,
     36                        'reply_meta' => array(
     37                                'forum_id' => $f,
     38                                'topic_id' => $t,
     39                        )
     40                ) );
     41                // Get the topics last reply id _bbp_last_reply_id
     42                $this->assertSame( $r, bbp_get_topic_last_reply_id( $t ) );
     43        }
     44}