Skip to:
Content

bbPress.org

Changeset 5880


Ignore:
Timestamp:
07/24/2015 11:21:28 AM (7 years ago)
Author:
netweb
Message:

Replies: In bbp_update_reply_walker() always update the topics last active time with bbp_update_topic_last_active_time() regardless of reply's published status.

This changeset including unit tests ensures that when calling reply actions spam/unspam, trash/untrash, approve/unapprove the reply's parent topic's last active time is updated to the time of the last published reply.

Props netweb. See #2838

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/replies/functions.php

    r5866 r5880  
    973973                }
    974974
    975                 // Only update if reply is published
    976                 if ( bbp_is_reply_published( $reply_id ) ) {
    977                     bbp_update_topic_last_active_time( $ancestor, $topic_last_active_time );
    978                 }
     975                // Update the topic last active time regardless of reply status.
     976                // See https://bbpress.trac.wordpress.org/ticket/2838
     977                bbp_update_topic_last_active_time( $ancestor, $topic_last_active_time );
    979978
    980979                // Counts
  • trunk/tests/phpunit/testcases/forums/template/forum.php

    r5865 r5880  
    108108            'post_parent' => $f,
    109109            'post_date' => $post_date,
    110         ) );
    111 
    112         bbp_update_forum( array(
    113             'forum_id' => $f,
     110            'topic_meta' => array(
     111                'forum_id' => $f,
     112            ),
    114113        ) );
    115114
    116115        $fresh_link = bbp_get_forum_freshness_link( $f );
    117         $this->assertSame( '<a href="http://example.org/?topic=topic-1" title="Topic 1">4 days, 4 hours ago</a>', $fresh_link );
     116        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1" title="Topic 1">4 days, 4 hours ago</a>', $fresh_link );
     117    }
     118
     119    /**
     120     * @covers ::bbp_get_forum_freshness_link
     121     */
     122    public function test_bbp_get_forum_freshness_link_with_unpublished_replies() {
     123
     124        if ( is_multisite() ) {
     125            $this->markTestSkipped( 'Skipping URL tests in multiste for now.' );
     126        }
     127
     128        $now = time();
     129        $post_date_t1 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 18 ); // 18 hours ago
     130        $post_date_t2 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 16 ); // 16 hours ago
     131        $post_date_t3 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 14 ); // 14 hours ago
     132        $post_date_t4 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 12 ); // 12 hours ago
     133        $post_date_t5 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 10 ); // 1o hours ago
     134
     135        $f = $this->factory->forum->create();
     136
     137        $link = bbp_get_forum_freshness_link( $f );
     138        $this->assertSame( 'No Topics', $link );
     139
     140        $t1 = $this->factory->topic->create( array(
     141            'post_parent' => $f,
     142            'post_date' => $post_date_t1,
     143            'topic_meta' => array(
     144                'forum_id' => $f,
     145            ),
     146        ) );
     147
     148        $link = bbp_get_forum_freshness_link( $f );
     149        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1" title="Topic 1">18 hours ago</a>', $link );
     150
     151        $t2 = $this->factory->topic->create( array(
     152            'post_parent' => $f,
     153            'post_date' => $post_date_t2,
     154            'topic_meta' => array(
     155                'forum_id' => $f,
     156            ),
     157        ) );
     158
     159        $link = bbp_get_forum_freshness_link( $f );
     160        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-2" title="Topic 2">16 hours ago</a>', $link );
     161
     162        bbp_spam_topic( $t2 );
     163
     164        $link = bbp_get_forum_freshness_link( $f );
     165        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1" title="Topic 1">18 hours ago</a>', $link );
     166
     167        $t3 = $this->factory->topic->create( array(
     168            'post_parent' => $f,
     169            'post_date' => $post_date_t3,
     170            'topic_meta' => array(
     171                'forum_id' => $f,
     172            ),
     173        ) );
     174
     175        $link = bbp_get_forum_freshness_link( $f );
     176        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-3" title="Topic 3">14 hours ago</a>', $link );
     177
     178        // Todo: Use bbp_trash_topic() and not wp_trash_post()
     179        wp_trash_post( $t3 );
     180
     181        $link = bbp_get_forum_freshness_link( $f );
     182        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1" title="Topic 1">18 hours ago</a>', $link );
     183
     184        $t4 = $this->factory->topic->create( array(
     185            'post_parent' => $f,
     186            'post_date' => $post_date_t4,
     187            'topic_meta' => array(
     188                'forum_id' => $f,
     189            ),
     190        ) );
     191
     192        $link = bbp_get_forum_freshness_link( $f );
     193        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-4" title="Topic 4">12 hours ago</a>', $link );
     194
     195        bbp_unapprove_topic( $t4 );
     196
     197        $link = bbp_get_forum_freshness_link( $f );
     198        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1" title="Topic 1">18 hours ago</a>', $link );
     199
     200        bbp_unspam_topic( $t2 );
     201
     202        $link = bbp_get_forum_freshness_link( $f );
     203        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-2" title="Topic 2">16 hours ago</a>', $link );
     204
     205        // Todo: Use bbp_untrash_topic() and not wp_untrash_post()
     206        wp_untrash_post( $t3 );
     207
     208        $link = bbp_get_forum_freshness_link( $f );
     209        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-3" title="Topic 3">14 hours ago</a>', $link );
     210
     211        bbp_approve_topic( $t4 );
     212
     213        $link = bbp_get_forum_freshness_link( $f );
     214        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-4" title="Topic 4">12 hours ago</a>', $link );
     215
     216        $t5 = $this->factory->topic->create( array(
     217            'post_parent' => $f,
     218            'post_date' => $post_date_t5,
     219            'topic_meta' => array(
     220                'forum_id' => $f,
     221            ),
     222        ) );
     223
     224        $link = bbp_get_forum_freshness_link( $f );
     225        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-5" title="Topic 5">10 hours ago</a>', $link );
    118226    }
    119227
  • trunk/tests/phpunit/testcases/topics/template/links.php

    r5878 r5880  
    5959
    6060        $link = bbp_get_topic_freshness_link( $t );
    61         $this->assertSame( '<a href="http://example.org/?topic=topic-1" title="">4 days, 4 hours ago</a>', $link );
     61        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1" title="">4 days, 4 hours ago</a>', $link );
    6262
    6363        $r1 = $this->factory->reply->create( array(
     
    7171
    7272        $link = bbp_get_topic_freshness_link( $t );
    73         $this->assertSame( '<a href="http://example.org/?topic=topic-1/#post-' . bbp_get_reply_id( $r1 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">3 days, 8 hours ago</a>', $link );
     73        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id( $r1 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">3 days, 8 hours ago</a>', $link );
    7474
    7575        $r2 = $this->factory->reply->create( array(
     
    8383
    8484        $link = bbp_get_topic_freshness_link( $t );
    85         $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 );
     85        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id( $r2 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">2 days, 12 hours ago</a>', $link );
     86
     87        // Retore the user
     88        $this->set_current_user( $this->old_current_user );
     89    }
     90
     91    /**
     92     * @covers ::bbp_get_topic_freshness_link
     93     */
     94    public function test_bbp_get_topic_freshness_link_with_unpublished_replies() {
     95
     96        if ( is_multisite() ) {
     97            $this->markTestSkipped( 'Skipping URL tests in multiste for now.' );
     98        }
     99
     100        $now = time();
     101        $post_date    = date( 'Y-m-d H:i:s', $now - 60 * 60 * 20 ); // 2o hours ago
     102        $post_date_r1 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 18 ); // 18 hours ago
     103        $post_date_r2 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 16 ); // 16 hours ago
     104        $post_date_r3 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 14 ); // 14 hours ago
     105        $post_date_r4 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 12 ); // 12 hours ago
     106        $post_date_r5 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 10 ); // 1o hours ago
     107
     108        $f = $this->factory->forum->create();
     109        $t = $this->factory->topic->create( array(
     110            'post_parent' => $f,
     111            'post_date' => $post_date,
     112            'topic_meta' => array(
     113                'forum_id' => $f,
     114            ),
     115        ) );
     116
     117        $link = bbp_get_topic_freshness_link( $t );
     118        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1" title="">20 hours ago</a>', $link );
     119
     120        $r1 = $this->factory->reply->create( array(
     121            'post_parent' => $t,
     122            'post_date' => $post_date_r1,
     123            'reply_meta' => array(
     124                'forum_id' => $f,
     125                'topic_id' => $t,
     126            ),
     127        ) );
     128
     129        $link = bbp_get_topic_freshness_link( $t );
     130        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id( $r1 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">18 hours ago</a>', $link );
     131
     132        $r2 = $this->factory->reply->create( array(
     133            'post_parent' => $t,
     134            'post_date' => $post_date_r2,
     135            'reply_meta' => array(
     136                'forum_id' => $f,
     137                'topic_id' => $t,
     138            ),
     139        ) );
     140
     141        $link = bbp_get_topic_freshness_link( $t );
     142        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id( $r2 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">16 hours ago</a>', $link );
     143
     144        bbp_spam_reply( $r2 );
     145
     146        $link = bbp_get_topic_freshness_link( $t );
     147        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id( $r1 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">18 hours ago</a>', $link );
     148
     149        $r3 = $this->factory->reply->create( array(
     150            'post_parent' => $t,
     151            'post_date' => $post_date_r3,
     152            'reply_meta' => array(
     153                'forum_id' => $f,
     154                'topic_id' => $t,
     155            ),
     156        ) );
     157
     158        $link = bbp_get_topic_freshness_link( $t );
     159        $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 );
     160
     161        // Todo: Use bbp_trash_reply() and not wp_trash_post()
     162        wp_trash_post( $r3 );
     163
     164        $link = bbp_get_topic_freshness_link( $t );
     165        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id( $r1 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">18 hours ago</a>', $link );
     166
     167        $r4 = $this->factory->reply->create( array(
     168            'post_parent' => $t,
     169            'post_date' => $post_date_r4,
     170            'reply_meta' => array(
     171                'forum_id' => $f,
     172                'topic_id' => $t,
     173            ),
     174        ) );
     175
     176        $link = bbp_get_topic_freshness_link( $t );
     177        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id( $r4 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">12 hours ago</a>', $link );
     178
     179        bbp_unapprove_reply( $r4 );
     180
     181        $link = bbp_get_topic_freshness_link( $t );
     182        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id( $r1 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">18 hours ago</a>', $link );
     183
     184        bbp_unspam_reply( $r2 );
     185
     186        $link = bbp_get_topic_freshness_link( $t );
     187        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id( $r2 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">16 hours ago</a>', $link );
     188
     189        // Todo: Use bbp_untrash_reply() and not wp_untrash_post()
     190        wp_untrash_post( $r3 );
     191
     192        $link = bbp_get_topic_freshness_link( $t );
     193        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id( $r3 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">14 hours ago</a>', $link );
     194
     195        bbp_approve_reply( $r4 );
     196
     197        $link = bbp_get_topic_freshness_link( $t );
     198        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id( $r4 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">12 hours ago</a>', $link );
     199
     200        $r5 = $this->factory->reply->create( array(
     201            'post_parent' => $t,
     202            'post_date' => $post_date_r5,
     203            'reply_meta' => array(
     204                'forum_id' => $f,
     205                'topic_id' => $t,
     206            ),
     207        ) );
     208
     209        $link = bbp_get_topic_freshness_link( $t );
     210        $this->assertSame( '<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id( $r5 ) . '" title="Reply To: ' . bbp_get_topic_title( $t ) . '">10 hours ago</a>', $link );
    86211    }
    87212
Note: See TracChangeset for help on using the changeset viewer.