1 package net.pterodactylus.sone.web
3 import net.pterodactylus.sone.test.whenever
4 import net.pterodactylus.sone.web.WebTestUtils.redirectsTo
5 import org.hamcrest.MatcherAssert.assertThat
6 import org.hamcrest.Matchers.equalTo
8 import org.mockito.Mockito.verify
11 * Unit test for [LogoutPage].
13 class LogoutPageTest : WebPageTest() {
15 private val page = LogoutPage(template, webInterface)
18 fun `page unsets current sone and redirects to index`() {
19 expectedException.expect(redirectsTo("index.html"))
21 page.handleRequest(freenetRequest, templateContext)
23 verify(webInterface).setCurrentSone(toadletContext, null)
28 fun `page is not enabled if sone requires full access and request does not have full access`() {
29 core.preferences.isRequireFullAccess = true
30 assertThat(page.isEnabled(toadletContext), equalTo(false))
34 fun `page is disabled if no sone is logged in`() {
36 assertThat(page.isEnabled(toadletContext), equalTo(false))
40 fun `page is disabled if sone is logged in but there is only one sone`() {
41 whenever(core.localSones).thenReturn(listOf(currentSone))
42 assertThat(page.isEnabled(toadletContext), equalTo(false))
46 fun `page is enabled if sone is logged in and there is more than one sone`() {
47 whenever(core.localSones).thenReturn(listOf(currentSone, currentSone))
48 assertThat(page.isEnabled(toadletContext), equalTo(true))
52 fun `page is enabled if full access is required and present and sone is logged in and there is more than one sone`() {
53 core.preferences.isRequireFullAccess = true
54 whenever(toadletContext.isAllowedFullAccess).thenReturn(true)
55 whenever(core.localSones).thenReturn(listOf(currentSone, currentSone))
56 assertThat(page.isEnabled(toadletContext), equalTo(true))