1 package net.pterodactylus.sone.web.pages
3 import com.google.common.base.Optional.*
4 import net.pterodactylus.sone.data.*
5 import net.pterodactylus.sone.test.*
6 import net.pterodactylus.sone.utils.*
7 import net.pterodactylus.sone.web.*
8 import net.pterodactylus.sone.web.page.*
9 import net.pterodactylus.util.web.Method.*
10 import org.hamcrest.MatcherAssert.*
11 import org.hamcrest.Matchers.*
13 import org.mockito.Mockito.*
16 * Unit test for [CreatePostPage].
18 class CreatePostPageTest : WebPageTest(::CreatePostPage) {
21 fun `page returns correct path`() {
22 assertThat(page.path, equalTo("createPost.html"))
26 fun `page requires login`() {
27 assertThat(page.requiresLogin(), equalTo(true))
31 fun `return page is set in template context`() {
32 addHttpRequestPart("returnPage", "return.html")
33 page.processTemplate(freenetRequest, templateContext)
34 assertThat(templateContext["returnPage"], equalTo<Any>("return.html"))
38 fun `post is created correctly`() {
40 addHttpRequestPart("returnPage", "return.html")
41 addHttpRequestPart("text", "post text")
42 verifyRedirect("return.html") {
43 verify(core).createPost(currentSone, null, "post text")
48 fun `creating an empty post is denied`() {
50 addHttpRequestPart("returnPage", "return.html")
51 addHttpRequestPart("text", " ")
52 page.processTemplate(freenetRequest, templateContext)
53 assertThat(templateContext["errorTextEmpty"], equalTo<Any>(true))
57 fun `a sender can be selected`() {
59 addHttpRequestPart("returnPage", "return.html")
60 addHttpRequestPart("text", "post text")
61 addHttpRequestPart("sender", "sender-id")
62 val sender = mock<Sone>()
63 addLocalSone("sender-id", sender)
64 verifyRedirect("return.html") {
65 verify(core).createPost(sender, null, "post text")
70 fun `a recipient can be selected`() {
72 addHttpRequestPart("returnPage", "return.html")
73 addHttpRequestPart("text", "post text")
74 addHttpRequestPart("recipient", "recipient-id")
75 val recipient = mock<Sone>()
76 addSone("recipient-id", recipient)
77 verifyRedirect("return.html") {
78 verify(core).createPost(currentSone, recipient, "post text")
83 fun `text is filtered correctly`() {
85 addHttpRequestPart("returnPage", "return.html")
86 addHttpRequestPart("text", "post http://localhost:12345/KSK@foo text")
87 addHttpRequestHeader("Host", "localhost:12345")
88 verifyRedirect("return.html") {
89 verify(core).createPost(currentSone, null, "post KSK@foo text")
94 fun `page can be created by dependency injection`() {
95 assertThat(baseInjector.getInstance<CreatePostPage>(), notNullValue())
99 fun `page is annotated with correct template path`() {
100 assertThat(page.templatePath, equalTo("/templates/createPost.html"))