🎨 Fix formatting
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / LogoutPageTest.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 org.hamcrest.MatcherAssert.*
7 import org.hamcrest.Matchers.*
8 import org.junit.*
9 import org.mockito.Mockito.*
10
11 /**
12  * Unit test for [LogoutPage].
13  */
14 class LogoutPageTest : WebPageTest(::LogoutPage) {
15
16         @Test
17         fun `page returns correct path`() {
18                 assertThat(page.path, equalTo("logout.html"))
19         }
20
21         @Test
22         fun `page requires login`() {
23                 assertThat(page.requiresLogin(), equalTo(true))
24         }
25
26         @Test
27         fun `page returns correct title`() {
28                 addTranslation("Page.Logout.Title", "logout page title")
29                 assertThat(page.getPageTitle(soneRequest), equalTo("logout page title"))
30         }
31
32         @Test
33         fun `page unsets current sone and redirects to index`() {
34                 verifyRedirect("index.html") {
35                         verify(webInterface).setCurrentSone(toadletContext, null)
36                 }
37         }
38
39         @Test
40         fun `page is not enabled if sone requires full access and request does not have full access`() {
41                 core.preferences.newRequireFullAccess = true
42                 assertThat(page.isEnabled(toadletContext), equalTo(false))
43         }
44
45         @Test
46         fun `page is disabled if no sone is logged in`() {
47                 unsetCurrentSone()
48                 assertThat(page.isEnabled(toadletContext), equalTo(false))
49         }
50
51         @Test
52         fun `page is disabled if sone is logged in but there is only one sone`() {
53                 whenever(core.localSones).thenReturn(listOf(currentSone))
54                 assertThat(page.isEnabled(toadletContext), equalTo(false))
55         }
56
57         @Test
58         fun `page is enabled if sone is logged in and there is more than one sone`() {
59                 whenever(core.localSones).thenReturn(listOf(currentSone, currentSone))
60                 assertThat(page.isEnabled(toadletContext), equalTo(true))
61         }
62
63         @Test
64         fun `page is enabled if full access is required and present and sone is logged in and there is more than one sone`() {
65                 core.preferences.newRequireFullAccess = true
66                 whenever(toadletContext.isAllowedFullAccess).thenReturn(true)
67                 whenever(core.localSones).thenReturn(listOf(currentSone, currentSone))
68                 assertThat(page.isEnabled(toadletContext), equalTo(true))
69         }
70
71         @Test
72         fun `page can be created by dependency injection`() {
73                 assertThat(baseInjector.getInstance<LogoutPage>(), notNullValue())
74         }
75
76         @Test
77         fun `page is annotated with correct menuname`() {
78                 assertThat(page.menuName, equalTo("Logout"))
79         }
80
81 }