X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FEditProfilePageTest.kt;h=0fb6cca8302554ec15d463be41ab4b0f854a270a;hp=333d9852905c3e648fe3f00d270dec22a43a1ee7;hb=9acbc5bdec4ccb752e0856a501568b0bb6161579;hpb=6b2461a58af4530997197ad3b17749f79c4d297a diff --git a/src/test/kotlin/net/pterodactylus/sone/web/EditProfilePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/EditProfilePageTest.kt index 333d985..0fb6cca 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/EditProfilePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/EditProfilePageTest.kt @@ -26,6 +26,8 @@ class EditProfilePageTest : WebPageTest() { private val firstField = profile.addField("First Field") private val secondField = profile.addField("Second Field") + override fun getPage() = page + @Before fun setupProfile() { val avatar = mock() @@ -73,10 +75,7 @@ class EditProfilePageTest : WebPageTest() { request("", POST) addHttpRequestParameter("save-profile", "true") addHttpRequestParameter(fieldName, newValue.toString()) - expectedException.expect(WebTestUtils.redirectsTo("editProfile.html")) - try { - page.handleRequest(freenetRequest, templateContext) - } finally { + verifyRedirect("editProfile.html") { verify(core).touchConfiguration() assertThat(fieldAccessor(), equalTo(expectedValue)) } @@ -125,7 +124,7 @@ class EditProfilePageTest : WebPageTest() { fun `post request with field value saves profile and redirects back to profile edit page`() { val field = profile.addField("name") field.value = "old" - verifySingleFieldCanBeChanged("field-${field.id}", "new") { profile.getFieldByName("name").value } + verifySingleFieldCanBeChanged("field-${field.id}", "new") { profile.getFieldByName("name")!!.value } } @Test @@ -133,7 +132,7 @@ class EditProfilePageTest : WebPageTest() { val field = profile.addField("name") field.value = "old" addHttpRequestHeader("Host", "www.te.st") - verifySingleFieldCanBeChanged("field-${field.id}", "http://www.te.st/KSK@GPL.txt", "KSK@GPL.txt") { profile.getFieldByName("name").value } + verifySingleFieldCanBeChanged("field-${field.id}", "http://www.te.st/KSK@GPL.txt", "KSK@GPL.txt") { profile.getFieldByName("name")!!.value } } @Test @@ -153,10 +152,7 @@ class EditProfilePageTest : WebPageTest() { request("", POST) addHttpRequestParameter("add-field", "true") addHttpRequestParameter("field-name", "new-field") - expectedException.expect(WebTestUtils.redirectsTo("editProfile.html#profile-fields")) - try { - page.handleRequest(freenetRequest, templateContext) - } finally { + verifyRedirect("editProfile.html#profile-fields") { assertThat(profile.getFieldByName("new-field"), notNullValue()) verify(currentSone).profile = profile verify(core).touchConfiguration() @@ -167,39 +163,31 @@ class EditProfilePageTest : WebPageTest() { fun `deleting a field redirects to delete field page`() { request("", POST) addHttpRequestParameter("delete-field-${firstField.id}", "true") - expectedException.expect(WebTestUtils.redirectsTo("deleteProfileField.html?field=${firstField.id}")) - page.handleRequest(freenetRequest, templateContext) + verifyRedirect("deleteProfileField.html?field=${firstField.id}") } @Test fun `moving a field up moves the field up and redirects to the edit profile page`() { request("", POST) addHttpRequestParameter("move-up-field-${secondField.id}", "true") - expectedException.expect(WebTestUtils.redirectsTo("editProfile.html#profile-fields")) - try { - page.handleRequest(freenetRequest, templateContext) - } finally { + verifyRedirect("editProfile.html#profile-fields") { assertThat(profile.fields, contains(secondField, firstField)) verify(currentSone).profile = profile } } - + @Test fun `moving an invalid field up redirects to the invalid page`() { request("", POST) addHttpRequestParameter("move-up-field-foo", "true") - expectedException.expect(WebTestUtils.redirectsTo("invalid.html")) - page.handleRequest(freenetRequest, templateContext) + verifyRedirect("invalid.html") } @Test fun `moving a field down moves the field down and redirects to the edit profile page`() { request("", POST) addHttpRequestParameter("move-down-field-${firstField.id}", "true") - expectedException.expect(WebTestUtils.redirectsTo("editProfile.html#profile-fields")) - try { - page.handleRequest(freenetRequest, templateContext) - } finally { + verifyRedirect("editProfile.html#profile-fields") { assertThat(profile.fields, contains(secondField, firstField)) verify(currentSone).profile = profile } @@ -209,16 +197,14 @@ class EditProfilePageTest : WebPageTest() { fun `moving an invalid field down redirects to the invalid page`() { request("", POST) addHttpRequestParameter("move-down-field-foo", "true") - expectedException.expect(WebTestUtils.redirectsTo("invalid.html")) - page.handleRequest(freenetRequest, templateContext) + verifyRedirect("invalid.html") } @Test fun `editing a field redirects to the edit profile page`() { request("", POST) addHttpRequestParameter("edit-field-${firstField.id}", "true") - expectedException.expect(WebTestUtils.redirectsTo("editProfileField.html?field=${firstField.id}")) - page.handleRequest(freenetRequest, templateContext) + verifyRedirect("editProfileField.html?field=${firstField.id}") } }