1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Post
4 import net.pterodactylus.sone.data.Sone
5 import net.pterodactylus.sone.test.mock
6 import net.pterodactylus.util.web.Method.POST
7 import org.hamcrest.MatcherAssert.assertThat
8 import org.hamcrest.Matchers.equalTo
10 import org.mockito.Mockito.verify
13 * Unit test for [CreateReplyPage].
15 class CreateReplyPageTest: WebPageTest() {
17 private val page = CreateReplyPage(template, webInterface)
18 override fun getPage() = page
21 fun `page returns correct path`() {
22 assertThat(page.path, equalTo("createReply.html"))
26 fun `page requires login`() {
27 assertThat(page.requiresLogin(), equalTo(true))
31 fun `reply is created correctly`() {
33 addHttpRequestPart("returnPage", "return.html")
34 addHttpRequestPart("post", "post-id")
35 addHttpRequestPart("text", "new text")
36 val post = mock<Post>().apply { addPost("post-id", this) }
37 verifyRedirect("return.html") {
38 verify(core).createReply(currentSone, post, "new text")
43 fun `reply is filtered`() {
45 addHttpRequestPart("returnPage", "return.html")
46 addHttpRequestPart("post", "post-id")
47 addHttpRequestPart("text", "new http://localhost:12345/KSK@foo text")
48 addHttpRequestHeader("Host", "localhost:12345")
49 val post = mock<Post>().apply { addPost("post-id", this) }
50 verifyRedirect("return.html") {
51 verify(core).createReply(currentSone, post, "new KSK@foo text")
56 fun `reply is created with correct sender`() {
58 addHttpRequestPart("returnPage", "return.html")
59 addHttpRequestPart("post", "post-id")
60 addHttpRequestPart("text", "new text")
61 addHttpRequestPart("sender", "sender-id")
62 val sender = mock<Sone>().apply { addLocalSone("sender-id", this) }
63 val post = mock<Post>().apply { addPost("post-id", this) }
64 verifyRedirect("return.html") {
65 verify(core).createReply(sender, post, "new text")
70 fun `empty text sets parameters in template contexty`() {
72 addHttpRequestPart("returnPage", "return.html")
73 addHttpRequestPart("post", "post-id")
74 addHttpRequestPart("text", " ")
75 page.processTemplate(freenetRequest, templateContext)
76 assertThat(templateContext["errorTextEmpty"], equalTo<Any>(true))
77 assertThat(templateContext["returnPage"], equalTo<Any>("return.html"))
78 assertThat(templateContext["postId"], equalTo<Any>("post-id"))
79 assertThat(templateContext["text"], equalTo<Any>(""))
83 fun `user is redirected to no permissions page if post does not exist`() {
85 addHttpRequestPart("returnPage", "return.html")
86 addHttpRequestPart("post", "post-id")
87 addHttpRequestPart("text", "new text")
88 verifyRedirect("noPermission.html")