1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Profile
4 import net.pterodactylus.sone.test.whenever
5 import net.pterodactylus.util.web.Method.POST
6 import org.hamcrest.MatcherAssert.assertThat
7 import org.hamcrest.Matchers.equalTo
8 import org.hamcrest.Matchers.nullValue
9 import org.junit.Before
11 import org.mockito.Mockito.any
12 import org.mockito.Mockito.never
13 import org.mockito.Mockito.verify
16 * Unit test for [DeleteProfileFieldPage].
18 class DeleteProfileFieldPageTest: WebPageTest(::DeleteProfileFieldPage) {
20 private val profile = Profile(currentSone)
21 private val field = profile.addField("name")
25 whenever(currentSone.profile).thenReturn(profile)
30 fun `page returns correct path`() {
31 assertThat(page.path, equalTo("deleteProfileField.html"))
35 fun `page requires login`() {
36 assertThat(page.requiresLogin(), equalTo(true))
40 fun `get request with invalid field name redirects to invalid page`() {
41 verifyRedirect("invalid.html")
45 fun `post request with invalid field name redirects to invalid page`() {
47 addHttpRequestPart("field", "wrong-id")
48 verifyRedirect("invalid.html")
52 fun `get request with valid field name sets field in template context`() {
53 addHttpRequestParameter("field", field.id)
54 page.processTemplate(freenetRequest, templateContext)
55 assertThat(templateContext["field"], equalTo<Any>(field))
59 fun `post request without confirm redirects to edit profile page`() {
61 addHttpRequestPart("field", field.id)
62 verifyRedirect("editProfile.html#profile-fields") {
63 verify(currentSone, never()).profile = any()
68 fun `post request with confirm removes field and redirects to edit profile page`() {
70 addHttpRequestPart("field", field.id)
71 addHttpRequestPart("confirm", "true")
72 verifyRedirect("editProfile.html#profile-fields") {
73 assertThat(profile.getFieldById(field.id), nullValue())
74 verify(currentSone).profile = profile