Index: tests/phpunit/testcases/topics/template/links.php
===================================================================
--- tests/phpunit/testcases/topics/template/links.php	(revision 5878)
+++ tests/phpunit/testcases/topics/template/links.php	(working copy)
@@ -83,9 +83,141 @@
 
 		$link = bbp_get_topic_freshness_link( $t );
 		$this->assertSame( '<a href="http://example.org/?topic=topic-1/#post-' . bbp_get_reply_id( $r2 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">2 days, 12 hours ago</a>', $link );
+
+		// Retore the user
+		$this->set_current_user( $this->old_current_user );
 	}
 
 	/**
+	 * @covers ::bbp_get_topic_freshness_link
+	 */
+	public function test_bbp_get_topic_freshness_link_with_unpublished_replies() {
+
+		if ( is_multisite() ) {
+			$this->markTestSkipped( 'Skipping URL tests in multiste for now.' );
+		}
+
+		$old_current_user = 0;
+		$this->old_current_user = get_current_user_id();
+		$this->set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
+		$this->keymaster_id = get_current_user_id();
+		bbp_set_user_role( $this->keymaster_id, bbp_get_keymaster_role() );
+
+		$now = time();
+		$post_date    = date( 'Y-m-d H:i:s', $now - 60 * 60 * 20 ); // 2o hours ago
+		$post_date_r1 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 18 ); // 18 hours ago
+		$post_date_r2 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 16 ); // 16 hours ago
+		$post_date_r3 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 14 ); // 14 hours ago
+		$post_date_r4 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 12 ); // 12 hours ago
+		$post_date_r5 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 10 ); // 1o hours ago
+
+		$f = $this->factory->forum->create();
+		$t = $this->factory->topic->create( array(
+			'post_parent' => $f,
+			'post_date' => $post_date,
+			'topic_meta' => array(
+				'forum_id' => $f,
+			),
+		) );
+
+		$link = bbp_get_topic_freshness_link( $t );
+		$this->assertSame( '<a href="http://example.org/?topic=topic-1" title="">20 hours ago</a>', $link );
+
+		$r1 = $this->factory->reply->create( array(
+			'post_parent' => $t,
+			'post_date' => $post_date_r1,
+			'reply_meta' => array(
+				'forum_id' => $f,
+				'topic_id' => $t,
+			),
+		) );
+
+		$link = bbp_get_topic_freshness_link( $t );
+		$this->assertSame( '<a href="http://example.org/?topic=topic-1/#post-' . bbp_get_reply_id( $r1 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">18 hours ago</a>', $link );
+
+		$r2 = $this->factory->reply->create( array(
+			'post_parent' => $t,
+			'post_date' => $post_date_r2,
+			'reply_meta' => array(
+				'forum_id' => $f,
+				'topic_id' => $t,
+			),
+		) );
+
+		$link = bbp_get_topic_freshness_link( $t );
+		$this->assertSame( '<a href="http://example.org/?topic=topic-1/#post-' . bbp_get_reply_id( $r2 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">16 hours ago</a>', $link );
+
+		bbp_spam_reply( $r2 );
+
+		$link = bbp_get_topic_freshness_link( $t );
+		$this->assertSame( '<a href="http://example.org/?topic=topic-1/#post-' . bbp_get_reply_id( $r1 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">18 hours ago</a>', $link );
+
+		$r3 = $this->factory->reply->create( array(
+			'post_parent' => $t,
+			'post_date' => $post_date_r3,
+			'reply_meta' => array(
+				'forum_id' => $f,
+				'topic_id' => $t,
+			),
+		) );
+
+		$link = bbp_get_topic_freshness_link( $t );
+		$this->assertSame( '<a href="http://example.org/?topic=topic-1/#post-' . bbp_get_reply_id( $r3 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">14 hours ago</a>', $link );
+
+		bbp_trash_reply( $r3 );
+
+		$link = bbp_get_topic_freshness_link( $t );
+		$this->assertSame( '<a href="http://example.org/?topic=topic-1/#post-' . bbp_get_reply_id( $r1 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">18 hours ago</a>', $link );
+
+		$r4 = $this->factory->reply->create( array(
+			'post_parent' => $t,
+			'post_date' => $post_date_r4,
+			'reply_meta' => array(
+				'forum_id' => $f,
+				'topic_id' => $t,
+			),
+		) );
+
+		$link = bbp_get_topic_freshness_link( $t );
+		$this->assertSame( '<a href="http://example.org/?topic=topic-1/#post-' . bbp_get_reply_id( $r4 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">12 hours ago</a>', $link );
+
+		bbp_unapprove_reply( $r4 );
+
+		$link = bbp_get_topic_freshness_link( $t );
+		$this->assertSame( '<a href="http://example.org/?topic=topic-1/#post-' . bbp_get_reply_id( $r1 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">18 hours ago</a>', $link );
+
+		bbp_unspam_reply( $r2 );
+
+		$link = bbp_get_topic_freshness_link( $t );
+		$this->assertSame( '<a href="http://example.org/?topic=topic-1/#post-' . bbp_get_reply_id( $r2 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">16 hours ago</a>', $link );
+
+		bbp_untrash_reply( $r3 );
+
+		$link = bbp_get_topic_freshness_link( $t );
+		$this->assertSame( '<a href="http://example.org/?topic=topic-1/#post-' . bbp_get_reply_id( $r3 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">14 hours ago</a>', $link );
+
+		bbp_approve_reply( $r4 );
+
+		$link = bbp_get_topic_freshness_link( $t );
+		$this->assertSame( '<a href="http://example.org/?topic=topic-1/#post-' . bbp_get_reply_id( $r4 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">12 hours ago</a>', $link );
+
+		$r5 = $this->factory->reply->create( array(
+			'post_parent' => $t,
+			'post_date' => $post_date_r5,
+			'reply_meta' => array(
+				'forum_id' => $f,
+				'topic_id' => $t,
+			),
+		) );
+
+		$link = bbp_get_topic_freshness_link( $t );
+		$this->assertSame( '<a href="http://example.org/?topic=topic-1/#post-' . bbp_get_reply_id( $r5 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">10 hours ago</a>', $link );
+
+		// Retore the user
+		$this->set_current_user( $this->old_current_user );
+	}
+
+	/**
 	 * @covers ::bbp_topic_replies_link
 	 * @covers ::bbp_get_topic_replies_link
 	 * @todo   Implement test_bbp_get_topic_replies_link().
