1 package net.pterodactylus.sone.web.pages
3 import com.google.common.base.Optional.absent
4 import net.pterodactylus.sone.data.Sone
5 import net.pterodactylus.sone.test.mock
6 import net.pterodactylus.sone.utils.asOptional
7 import net.pterodactylus.util.web.Method.POST
8 import org.hamcrest.MatcherAssert.assertThat
9 import org.hamcrest.Matchers.equalTo
11 import org.mockito.Mockito.verify
14 * Unit test for [CreatePostPage].
16 class CreatePostPageTest: WebPageTest(::CreatePostPage) {
19 fun `page returns correct path`() {
20 assertThat(page.path, equalTo("createPost.html"))
24 fun `page requires login`() {
25 assertThat(page.requiresLogin(), equalTo(true))
29 fun `return page is set in template context`() {
30 addHttpRequestPart("returnPage", "return.html")
31 page.processTemplate(freenetRequest, templateContext)
32 assertThat(templateContext["returnPage"], equalTo<Any>("return.html"))
36 fun `post is created correctly`() {
38 addHttpRequestPart("returnPage", "return.html")
39 addHttpRequestPart("text", "post text")
40 verifyRedirect("return.html") {
41 verify(core).createPost(currentSone, absent(), "post text")
46 fun `creating an empty post is denied`() {
48 addHttpRequestPart("returnPage", "return.html")
49 addHttpRequestPart("text", " ")
50 page.processTemplate(freenetRequest, templateContext)
51 assertThat(templateContext["errorTextEmpty"], equalTo<Any>(true))
55 fun `a sender can be selected`() {
57 addHttpRequestPart("returnPage", "return.html")
58 addHttpRequestPart("text", "post text")
59 addHttpRequestPart("sender", "sender-id")
60 val sender = mock<Sone>()
61 addLocalSone("sender-id", sender)
62 verifyRedirect("return.html") {
63 verify(core).createPost(sender, absent(), "post text")
68 fun `a recipient can be selected`() {
70 addHttpRequestPart("returnPage", "return.html")
71 addHttpRequestPart("text", "post text")
72 addHttpRequestPart("recipient", "recipient-id")
73 val recipient = mock<Sone>()
74 addSone("recipient-id", recipient)
75 verifyRedirect("return.html") {
76 verify(core).createPost(currentSone, recipient.asOptional(), "post text")
81 fun `text is filtered correctly`() {
83 addHttpRequestPart("returnPage", "return.html")
84 addHttpRequestPart("text", "post http://localhost:12345/KSK@foo text")
85 addHttpRequestHeader("Host", "localhost:12345")
86 verifyRedirect("return.html") {
87 verify(core).createPost(currentSone, absent(), "post KSK@foo text")