X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FCreateReplyPageTest.kt;h=71e83bcaf5af8116a8c6533b3e468bb05109a54a;hp=052620a4a8f7ba08bcd95343dff01665700bb261;hb=2dd40fba7031cffb35a5156435547a5d964535c9;hpb=de7568a82eb4150bf6d2b0553841b7b69f84c968 diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPageTest.kt index 052620a..71e83bc 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPageTest.kt @@ -3,8 +3,6 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Post import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.test.mock -import net.pterodactylus.sone.web.pages.WebPageTest -import net.pterodactylus.sone.web.pages.CreateReplyPage import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -14,10 +12,7 @@ import org.mockito.Mockito.verify /** * Unit test for [CreateReplyPage]. */ -class CreateReplyPageTest: WebPageTest() { - - private val page = CreateReplyPage(template, webInterface) - override fun getPage() = page +class CreateReplyPageTest: WebPageTest(::CreateReplyPage) { @Test fun `page returns correct path`() { @@ -31,10 +26,10 @@ class CreateReplyPageTest: WebPageTest() { @Test fun `reply is created correctly`() { - request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("text", "new text") + setMethod(POST) + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("post", "post-id") + addHttpRequestPart("text", "new text") val post = mock().apply { addPost("post-id", this) } verifyRedirect("return.html") { verify(core).createReply(currentSone, post, "new text") @@ -43,10 +38,10 @@ class CreateReplyPageTest: WebPageTest() { @Test fun `reply is filtered`() { - request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("text", "new http://localhost:12345/KSK@foo text") + setMethod(POST) + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("post", "post-id") + addHttpRequestPart("text", "new http://localhost:12345/KSK@foo text") addHttpRequestHeader("Host", "localhost:12345") val post = mock().apply { addPost("post-id", this) } verifyRedirect("return.html") { @@ -56,11 +51,11 @@ class CreateReplyPageTest: WebPageTest() { @Test fun `reply is created with correct sender`() { - request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("text", "new text") - addHttpRequestParameter("sender", "sender-id") + setMethod(POST) + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("post", "post-id") + addHttpRequestPart("text", "new text") + addHttpRequestPart("sender", "sender-id") val sender = mock().apply { addLocalSone("sender-id", this) } val post = mock().apply { addPost("post-id", this) } verifyRedirect("return.html") { @@ -70,10 +65,10 @@ class CreateReplyPageTest: WebPageTest() { @Test fun `empty text sets parameters in template contexty`() { - request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("text", " ") + setMethod(POST) + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("post", "post-id") + addHttpRequestPart("text", " ") page.processTemplate(freenetRequest, templateContext) assertThat(templateContext["errorTextEmpty"], equalTo(true)) assertThat(templateContext["returnPage"], equalTo("return.html")) @@ -83,22 +78,11 @@ class CreateReplyPageTest: WebPageTest() { @Test fun `user is redirected to no permissions page if post does not exist`() { - request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("text", "new text") + setMethod(POST) + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("post", "post-id") + addHttpRequestPart("text", "new text") verifyRedirect("noPermission.html") } - @Test - fun `get request stores parameters in template context`() { - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("text", "new text") - page.processTemplate(freenetRequest, templateContext) - assertThat(templateContext["returnPage"], equalTo("return.html")) - assertThat(templateContext["postId"], equalTo("post-id")) - assertThat(templateContext["text"], equalTo("new text")) - } - }