X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FEditProfileFieldPageTest.kt;h=b4acc7ed7cb2500d39b36ebb92488576d57e71ab;hp=0990ecea95f044929d4ff646f1e2cba75ca655dd;hb=2dd40fba7031cffb35a5156435547a5d964535c9;hpb=e6b3d4f3022e392ac0d74ba1c298b3dbf7265603 diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPageTest.kt index 0990ece..b4acc7e 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPageTest.kt @@ -2,9 +2,6 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Profile import net.pterodactylus.sone.test.whenever -import net.pterodactylus.sone.web.pages.EditProfileFieldPage -import net.pterodactylus.sone.web.pages.WebPageTest -import net.pterodactylus.util.web.Method.GET import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -16,15 +13,11 @@ import org.mockito.Mockito.verify /** * Unit test for [EditProfileFieldPage]. */ -class EditProfileFieldPageTest : WebPageTest() { - - private val page = EditProfileFieldPage(template, webInterface) +class EditProfileFieldPageTest: WebPageTest(::EditProfileFieldPage) { private val profile = Profile(currentSone) private val field = profile.addField("Name") - override fun getPage() = page - @Before fun setupProfile() { whenever(currentSone.profile).thenReturn(profile) @@ -48,31 +41,29 @@ class EditProfileFieldPageTest : WebPageTest() { @Test fun `get request with invalid field redirects to invalid page`() { - request("", GET) verifyRedirect("invalid.html") } @Test fun `get request with valid field stores field in template context`() { - request("", GET) addHttpRequestParameter("field", field.id) - page.handleRequest(freenetRequest, templateContext) + page.processTemplate(freenetRequest, templateContext) assertThat(templateContext["field"], equalTo(field)) } @Test fun `post request with cancel set redirects to profile edit page`() { - request("", POST) - addHttpRequestParameter("field", field.id) - addHttpRequestParameter("cancel", "true") + setMethod(POST) + addHttpRequestPart("field", field.id) + addHttpRequestPart("cancel", "true") verifyRedirect("editProfile.html#profile-fields") } @Test fun `post request with new name renames field and redirects to profile edit page`() { - request("", POST) - addHttpRequestParameter("field", field.id) - addHttpRequestParameter("name", "New Name") + setMethod(POST) + addHttpRequestPart("field", field.id) + addHttpRequestPart("name", "New Name") verifyRedirect("editProfile.html#profile-fields") { assertThat(field.name, equalTo("New Name")) verify(currentSone).profile = profile @@ -81,9 +72,9 @@ class EditProfileFieldPageTest : WebPageTest() { @Test fun `post request with same name does not modify field and redirects to profile edit page`() { - request("", POST) - addHttpRequestParameter("field", field.id) - addHttpRequestParameter("name", "Name") + setMethod(POST) + addHttpRequestPart("field", field.id) + addHttpRequestPart("name", "Name") verifyRedirect("editProfile.html#profile-fields") { assertThat(field.name, equalTo("Name")) verify(currentSone, never()).profile = profile @@ -92,11 +83,11 @@ class EditProfileFieldPageTest : WebPageTest() { @Test fun `post request with same name as different field sets error condition in template`() { - request("", POST) + setMethod(POST) profile.addField("New Name") - addHttpRequestParameter("field", field.id) - addHttpRequestParameter("name", "New Name") - page.handleRequest(freenetRequest, templateContext) + addHttpRequestPart("field", field.id) + addHttpRequestPart("name", "New Name") + page.processTemplate(freenetRequest, templateContext) assertThat(field.name, equalTo("Name")) verify(currentSone, never()).profile = profile assertThat(templateContext["duplicateFieldName"], equalTo(true))