1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.test.*
5 import net.pterodactylus.sone.web.*
6 import net.pterodactylus.sone.web.page.*
7 import net.pterodactylus.util.web.Method.*
8 import org.hamcrest.MatcherAssert.*
9 import org.hamcrest.Matchers.*
11 import org.mockito.Mockito.*
14 * Unit test for [DeleteProfileFieldPage].
16 class DeleteProfileFieldPageTest: WebPageTest(::DeleteProfileFieldPage) {
18 private val profile = Profile(currentSone)
19 private val field = profile.addField("name")
23 whenever(currentSone.profile).thenReturn(profile)
28 fun `page returns correct path`() {
29 assertThat(page.path, equalTo("deleteProfileField.html"))
33 fun `page requires login`() {
34 assertThat(page.requiresLogin(), equalTo(true))
38 fun `get request with invalid field name redirects to invalid page`() {
39 verifyRedirect("invalid.html")
43 fun `post request with invalid field name redirects to invalid page`() {
45 addHttpRequestPart("field", "wrong-id")
46 verifyRedirect("invalid.html")
50 fun `get request with valid field name sets field in template context`() {
51 addHttpRequestParameter("field", field.id)
52 page.processTemplate(freenetRequest, templateContext)
53 assertThat(templateContext["field"], equalTo<Any>(field))
57 fun `post request without confirm redirects to edit profile page`() {
59 addHttpRequestPart("field", field.id)
60 verifyRedirect("editProfile.html#profile-fields") {
61 verify(currentSone, never()).profile = any()
66 fun `post request with confirm removes field and redirects to edit profile page`() {
68 addHttpRequestPart("field", field.id)
69 addHttpRequestPart("confirm", "true")
70 verifyRedirect("editProfile.html#profile-fields") {
71 assertThat(profile.getFieldById(field.id), nullValue())
72 verify(currentSone).profile = profile
77 fun `page can be created by dependency injection`() {
78 assertThat(baseInjector.getInstance<DeleteProfileFieldPage>(), notNullValue())
82 fun `page is annotated with correct template path`() {
83 assertThat(page.templatePath, equalTo("/templates/deleteProfileField.html"))