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