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