|
7 | 7 | use BookStack\Entities\Models\Page; |
8 | 8 | use Tests\TestCase; |
9 | 9 |
|
10 | | -class CommentTest extends TestCase |
| 10 | +class CommentStoreTest extends TestCase |
11 | 11 | { |
12 | 12 | public function test_add_comment() |
13 | 13 | { |
@@ -166,6 +166,29 @@ public function test_archive_endpoints_require_delete_or_edit_permissions() |
166 | 166 | } |
167 | 167 | } |
168 | 168 |
|
| 169 | + public function test_non_top_level_comments_cant_be_archived_or_unarchived() |
| 170 | + { |
| 171 | + $this->asAdmin(); |
| 172 | + $page = $this->entities->page(); |
| 173 | + |
| 174 | + $comment = Comment::factory()->make(); |
| 175 | + $page->comments()->save($comment); |
| 176 | + $subComment = Comment::factory()->make(['parent_id' => $comment->id]); |
| 177 | + $page->comments()->save($subComment); |
| 178 | + $subComment->refresh(); |
| 179 | + |
| 180 | + $resp = $this->putJson("/comment/$subComment->id/archive"); |
| 181 | + $resp->assertStatus(400); |
| 182 | + |
| 183 | + $this->assertDatabaseHas('comments', [ |
| 184 | + 'id' => $subComment->id, |
| 185 | + 'archived' => false, |
| 186 | + ]); |
| 187 | + |
| 188 | + $resp = $this->putJson("/comment/$subComment->id/unarchive"); |
| 189 | + $resp->assertStatus(400); |
| 190 | + } |
| 191 | + |
169 | 192 | public function test_scripts_cannot_be_injected_via_comment_html() |
170 | 193 | { |
171 | 194 | $page = $this->entities->page(); |
@@ -225,96 +248,4 @@ public function test_comment_html_is_limited() |
225 | 248 | 'html' => $expected, |
226 | 249 | ]); |
227 | 250 | } |
228 | | - |
229 | | - public function test_reply_comments_are_nested() |
230 | | - { |
231 | | - $this->asAdmin(); |
232 | | - $page = $this->entities->page(); |
233 | | - |
234 | | - $this->postJson("/comment/$page->id", ['html' => '<p>My new comment</p>']); |
235 | | - $this->postJson("/comment/$page->id", ['html' => '<p>My new comment</p>']); |
236 | | - |
237 | | - $respHtml = $this->withHtml($this->get($page->getUrl())); |
238 | | - $respHtml->assertElementCount('.comment-branch', 3); |
239 | | - $respHtml->assertElementNotExists('.comment-branch .comment-branch'); |
240 | | - |
241 | | - $comment = $page->comments()->first(); |
242 | | - $resp = $this->postJson("/comment/$page->id", [ |
243 | | - 'html' => '<p>My nested comment</p>', 'parent_id' => $comment->local_id |
244 | | - ]); |
245 | | - $resp->assertStatus(200); |
246 | | - |
247 | | - $respHtml = $this->withHtml($this->get($page->getUrl())); |
248 | | - $respHtml->assertElementCount('.comment-branch', 4); |
249 | | - $respHtml->assertElementContains('.comment-branch .comment-branch', 'My nested comment'); |
250 | | - } |
251 | | - |
252 | | - public function test_comments_are_visible_in_the_page_editor() |
253 | | - { |
254 | | - $page = $this->entities->page(); |
255 | | - |
256 | | - $this->asAdmin()->postJson("/comment/$page->id", ['html' => '<p>My great comment to see in the editor</p>']); |
257 | | - |
258 | | - $respHtml = $this->withHtml($this->get($page->getUrl('/edit'))); |
259 | | - $respHtml->assertElementContains('.comment-box .content', 'My great comment to see in the editor'); |
260 | | - } |
261 | | - |
262 | | - public function test_comment_creator_name_truncated() |
263 | | - { |
264 | | - [$longNamedUser] = $this->users->newUserWithRole(['name' => 'Wolfeschlegelsteinhausenbergerdorff'], ['comment-create-all', 'page-view-all']); |
265 | | - $page = $this->entities->page(); |
266 | | - |
267 | | - $comment = Comment::factory()->make(); |
268 | | - $this->actingAs($longNamedUser)->postJson("/comment/$page->id", $comment->getAttributes()); |
269 | | - |
270 | | - $pageResp = $this->asAdmin()->get($page->getUrl()); |
271 | | - $pageResp->assertSee('Wolfeschlegels…'); |
272 | | - } |
273 | | - |
274 | | - public function test_comment_editor_js_loaded_with_create_or_edit_permissions() |
275 | | - { |
276 | | - $editor = $this->users->editor(); |
277 | | - $page = $this->entities->page(); |
278 | | - |
279 | | - $resp = $this->actingAs($editor)->get($page->getUrl()); |
280 | | - $resp->assertSee('tinymce.min.js?', false); |
281 | | - $resp->assertSee('window.editor_translations', false); |
282 | | - $resp->assertSee('component="entity-selector"', false); |
283 | | - |
284 | | - $this->permissions->removeUserRolePermissions($editor, ['comment-create-all']); |
285 | | - $this->permissions->grantUserRolePermissions($editor, ['comment-update-own']); |
286 | | - |
287 | | - $resp = $this->actingAs($editor)->get($page->getUrl()); |
288 | | - $resp->assertDontSee('tinymce.min.js?', false); |
289 | | - $resp->assertDontSee('window.editor_translations', false); |
290 | | - $resp->assertDontSee('component="entity-selector"', false); |
291 | | - |
292 | | - Comment::factory()->create([ |
293 | | - 'created_by' => $editor->id, |
294 | | - 'entity_type' => 'page', |
295 | | - 'entity_id' => $page->id, |
296 | | - ]); |
297 | | - |
298 | | - $resp = $this->actingAs($editor)->get($page->getUrl()); |
299 | | - $resp->assertSee('tinymce.min.js?', false); |
300 | | - $resp->assertSee('window.editor_translations', false); |
301 | | - $resp->assertSee('component="entity-selector"', false); |
302 | | - } |
303 | | - |
304 | | - public function test_comment_displays_relative_times() |
305 | | - { |
306 | | - $page = $this->entities->page(); |
307 | | - $comment = Comment::factory()->create(['entity_id' => $page->id, 'entity_type' => $page->getMorphClass()]); |
308 | | - $comment->created_at = now()->subWeek(); |
309 | | - $comment->updated_at = now()->subDay(); |
310 | | - $comment->save(); |
311 | | - |
312 | | - $pageResp = $this->asAdmin()->get($page->getUrl()); |
313 | | - $html = $this->withHtml($pageResp); |
314 | | - |
315 | | - // Create date shows relative time as text to user |
316 | | - $html->assertElementContains('.comment-box', 'commented 1 week ago'); |
317 | | - // Updated indicator has full time as title |
318 | | - $html->assertElementContains('.comment-box span[title^="Updated ' . $comment->updated_at->format('Y-m-d') . '"]', 'Updated'); |
319 | | - } |
320 | 251 | } |
0 commit comments