1 package net.pterodactylus.sone.web
3 import net.pterodactylus.sone.test.whenever
4 import org.hamcrest.MatcherAssert.assertThat
5 import org.hamcrest.Matchers.equalTo
7 import org.mockito.Mockito.verify
10 * Unit test for [LogoutPage].
12 class LogoutPageTest : WebPageTest() {
14 private val page = LogoutPage(template, webInterface)
16 override fun getPage() = page
19 fun `page unsets current sone and redirects to index`() {
20 verifyRedirect("index.html") {
21 verify(webInterface).setCurrentSone(toadletContext, null)
26 fun `page is not enabled if sone requires full access and request does not have full access`() {
27 core.preferences.isRequireFullAccess = true
28 assertThat(page.isEnabled(toadletContext), equalTo(false))
32 fun `page is disabled if no sone is logged in`() {
34 assertThat(page.isEnabled(toadletContext), equalTo(false))
38 fun `page is disabled if sone is logged in but there is only one sone`() {
39 whenever(core.localSones).thenReturn(listOf(currentSone))
40 assertThat(page.isEnabled(toadletContext), equalTo(false))
44 fun `page is enabled if sone is logged in and there is more than one sone`() {
45 whenever(core.localSones).thenReturn(listOf(currentSone, currentSone))
46 assertThat(page.isEnabled(toadletContext), equalTo(true))
50 fun `page is enabled if full access is required and present and sone is logged in and there is more than one sone`() {
51 core.preferences.isRequireFullAccess = true
52 whenever(toadletContext.isAllowedFullAccess).thenReturn(true)
53 whenever(core.localSones).thenReturn(listOf(currentSone, currentSone))
54 assertThat(page.isEnabled(toadletContext), equalTo(true))