| 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 | $old_current_user = 0; |
| 101 | $this->old_current_user = get_current_user_id(); |
| 102 | $this->set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); |
| 103 | $this->keymaster_id = get_current_user_id(); |
| 104 | bbp_set_user_role( $this->keymaster_id, bbp_get_keymaster_role() ); |
| 105 | |
| 106 | $now = time(); |
| 107 | $post_date = date( 'Y-m-d H:i:s', $now - 60 * 60 * 20 ); // 2o hours ago |
| 108 | $post_date_r1 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 18 ); // 18 hours ago |
| 109 | $post_date_r2 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 16 ); // 16 hours ago |
| 110 | $post_date_r3 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 14 ); // 14 hours ago |
| 111 | $post_date_r4 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 12 ); // 12 hours ago |
| 112 | $post_date_r5 = date( 'Y-m-d H:i:s', $now - 60 * 60 * 10 ); // 1o hours ago |
| 113 | |
| 114 | $f = $this->factory->forum->create(); |
| 115 | $t = $this->factory->topic->create( array( |
| 116 | 'post_parent' => $f, |
| 117 | 'post_date' => $post_date, |
| 118 | 'topic_meta' => array( |
| 119 | 'forum_id' => $f, |
| 120 | ), |
| 121 | ) ); |
| 122 | |
| 123 | $link = bbp_get_topic_freshness_link( $t ); |
| 124 | $this->assertSame( '<a href="http://example.org/?topic=topic-1" title="">20 hours ago</a>', $link ); |
| 125 | |
| 126 | $r1 = $this->factory->reply->create( array( |
| 127 | 'post_parent' => $t, |
| 128 | 'post_date' => $post_date_r1, |
| 129 | 'reply_meta' => array( |
| 130 | 'forum_id' => $f, |
| 131 | 'topic_id' => $t, |
| 132 | ), |
| 133 | ) ); |
| 134 | |
| 135 | $link = bbp_get_topic_freshness_link( $t ); |
| 136 | $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 ); |
| 137 | |
| 138 | $r2 = $this->factory->reply->create( array( |
| 139 | 'post_parent' => $t, |
| 140 | 'post_date' => $post_date_r2, |
| 141 | 'reply_meta' => array( |
| 142 | 'forum_id' => $f, |
| 143 | 'topic_id' => $t, |
| 144 | ), |
| 145 | ) ); |
| 146 | |
| 147 | $link = bbp_get_topic_freshness_link( $t ); |
| 148 | $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 ); |
| 149 | |
| 150 | bbp_spam_reply( $r2 ); |
| 151 | |
| 152 | $link = bbp_get_topic_freshness_link( $t ); |
| 153 | $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 ); |
| 154 | |
| 155 | $r3 = $this->factory->reply->create( array( |
| 156 | 'post_parent' => $t, |
| 157 | 'post_date' => $post_date_r3, |
| 158 | 'reply_meta' => array( |
| 159 | 'forum_id' => $f, |
| 160 | 'topic_id' => $t, |
| 161 | ), |
| 162 | ) ); |
| 163 | |
| 164 | $link = bbp_get_topic_freshness_link( $t ); |
| 165 | $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 ); |
| 166 | |
| 167 | bbp_trash_reply( $r3 ); |
| 168 | |
| 169 | $link = bbp_get_topic_freshness_link( $t ); |
| 170 | $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 ); |
| 171 | |
| 172 | $r4 = $this->factory->reply->create( array( |
| 173 | 'post_parent' => $t, |
| 174 | 'post_date' => $post_date_r4, |
| 175 | 'reply_meta' => array( |
| 176 | 'forum_id' => $f, |
| 177 | 'topic_id' => $t, |
| 178 | ), |
| 179 | ) ); |
| 180 | |
| 181 | $link = bbp_get_topic_freshness_link( $t ); |
| 182 | $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 ); |
| 183 | |
| 184 | bbp_unapprove_reply( $r4 ); |
| 185 | |
| 186 | $link = bbp_get_topic_freshness_link( $t ); |
| 187 | $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 ); |
| 188 | |
| 189 | bbp_unspam_reply( $r2 ); |
| 190 | |
| 191 | $link = bbp_get_topic_freshness_link( $t ); |
| 192 | $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 ); |
| 193 | |
| 194 | bbp_untrash_reply( $r3 ); |
| 195 | |
| 196 | $link = bbp_get_topic_freshness_link( $t ); |
| 197 | $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 ); |
| 198 | |
| 199 | bbp_approve_reply( $r4 ); |
| 200 | |
| 201 | $link = bbp_get_topic_freshness_link( $t ); |
| 202 | $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 ); |
| 203 | |
| 204 | $r5 = $this->factory->reply->create( array( |
| 205 | 'post_parent' => $t, |
| 206 | 'post_date' => $post_date_r5, |
| 207 | 'reply_meta' => array( |
| 208 | 'forum_id' => $f, |
| 209 | 'topic_id' => $t, |
| 210 | ), |
| 211 | ) ); |
| 212 | |
| 213 | $link = bbp_get_topic_freshness_link( $t ); |
| 214 | $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 ); |
| 215 | |
| 216 | // Retore the user |
| 217 | $this->set_current_user( $this->old_current_user ); |
| 218 | } |
| 219 | |
| 220 | /** |