1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.test.whenever
4 import net.pterodactylus.sone.web.pages.LogoutPage
5 import net.pterodactylus.sone.web.pages.WebPageTest
6 import org.hamcrest.MatcherAssert.assertThat
7 import org.hamcrest.Matchers.equalTo
9 import org.mockito.Mockito.verify
12 * Unit test for [LogoutPage].
14 class LogoutPageTest : WebPageTest() {
16 private val page = LogoutPage(template, webInterface)
18 override fun getPage() = page
21 fun `page unsets current sone and redirects to index`() {
22 verifyRedirect("index.html") {
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))