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