Skip to:
Content

bbPress.org


Ignore:
Timestamp:
07/24/2015 11:21:28 AM (11 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.