🔀 Merge “release/v81” into “master”
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / DeleteSonePageTest.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.test.*
4 import net.pterodactylus.sone.web.*
5 import net.pterodactylus.sone.web.page.*
6 import net.pterodactylus.util.web.Method.*
7 import org.hamcrest.MatcherAssert.*
8 import org.hamcrest.Matchers.*
9 import org.junit.*
10 import org.mockito.Mockito.*
11
12 /**
13  * Unit test for [DeleteSonePage].
14  */
15 class DeleteSonePageTest : WebPageTest(::DeleteSonePage) {
16
17         @Test
18         fun `page returns correct path`() {
19                 assertThat(page.path, equalTo("deleteSone.html"))
20         }
21
22         @Test
23         fun `page requires login`() {
24                 assertThat(page.requiresLogin(), equalTo(true))
25         }
26
27         @Test
28         fun `page returns correct title`() {
29                 addTranslation("Page.DeleteSone.Title", "delete sone page")
30                 assertThat(page.getPageTitle(soneRequest), equalTo("delete sone page"))
31         }
32
33         @Test
34         fun `get request does not redirect`() {
35                 page.processTemplate(freenetRequest, templateContext)
36         }
37
38         @Test
39         fun `post request without delete confirmation redirects to index`() {
40                 setMethod(POST)
41                 verifyRedirect("index.html") {
42                         verify(core, never()).deleteSone(any())
43                 }
44         }
45
46         @Test
47         fun `post request with delete confirmation deletes sone and redirects to index`() {
48                 setMethod(POST)
49                 addHttpRequestPart("deleteSone", "true")
50                 verifyRedirect("index.html") {
51                         verify(core).deleteSone(currentSone)
52                 }
53         }
54
55         @Test
56         fun `page can be created by dependency injection`() {
57                 assertThat(baseInjector.getInstance<DeleteSonePage>(), notNullValue())
58         }
59
60         @Test
61         fun `page is annotated with correct menuname`() {
62                 assertThat(page.menuName, equalTo("DeleteSone"))
63         }
64
65         @Test
66         fun `page is annotated with correct template path`() {
67                 assertThat(page.templatePath, equalTo("/templates/deleteSone.html"))
68         }
69
70 }