1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.test.*
5 import net.pterodactylus.sone.web.*
6 import net.pterodactylus.sone.web.page.*
7 import net.pterodactylus.util.web.Method.*
8 import org.hamcrest.MatcherAssert.*
9 import org.hamcrest.Matchers.*
11 import org.mockito.Mockito.*
14 * Unit test for [CreateReplyPage].
16 class CreateReplyPageTest : WebPageTest(::CreateReplyPage) {
19 fun `page returns correct path`() {
20 assertThat(page.path, equalTo("createReply.html"))
24 fun `page requires login`() {
25 assertThat(page.requiresLogin(), equalTo(true))
29 fun `reply is created correctly`() {
31 addHttpRequestPart("returnPage", "return.html")
32 addHttpRequestPart("post", "post-id")
33 addHttpRequestPart("text", "new text")
34 val post = mock<Post>().apply { addPost("post-id", this) }
35 verifyRedirect("return.html") {
36 verify(core).createReply(currentSone, post, "new text")
41 fun `reply is filtered`() {
43 addHttpRequestPart("returnPage", "return.html")
44 addHttpRequestPart("post", "post-id")
45 addHttpRequestPart("text", "new http://localhost:12345/KSK@foo text")
46 addHttpRequestHeader("Host", "localhost:12345")
47 val post = mock<Post>().apply { addPost("post-id", this) }
48 verifyRedirect("return.html") {
49 verify(core).createReply(currentSone, post, "new KSK@foo text")
54 fun `reply is created with correct sender`() {
56 addHttpRequestPart("returnPage", "return.html")
57 addHttpRequestPart("post", "post-id")
58 addHttpRequestPart("text", "new text")
59 addHttpRequestPart("sender", "sender-id")
60 val sender = mock<Sone>().apply { addLocalSone("sender-id", this) }
61 val post = mock<Post>().apply { addPost("post-id", this) }
62 verifyRedirect("return.html") {
63 verify(core).createReply(sender, post, "new text")
68 fun `empty text sets parameters in template contexty`() {
70 addHttpRequestPart("returnPage", "return.html")
71 addHttpRequestPart("post", "post-id")
72 addHttpRequestPart("text", " ")
73 page.processTemplate(freenetRequest, templateContext)
74 assertThat(templateContext["errorTextEmpty"], equalTo<Any>(true))
75 assertThat(templateContext["returnPage"], equalTo<Any>("return.html"))
76 assertThat(templateContext["postId"], equalTo<Any>("post-id"))
77 assertThat(templateContext["text"], equalTo<Any>(""))
81 fun `user is redirected to no permissions page if post does not exist`() {
83 addHttpRequestPart("returnPage", "return.html")
84 addHttpRequestPart("post", "post-id")
85 addHttpRequestPart("text", "new text")
86 verifyRedirect("noPermission.html")
90 fun `page can be created by dependency injection`() {
91 assertThat(baseInjector.getInstance<CreateReplyPage>(), notNullValue())
95 fun `page is annotated with correct template path`() {
96 assertThat(page.templatePath, equalTo("/templates/createReply.html"))