From: David ‘Bombe’ Roden Date: Mon, 28 Nov 2016 19:37:02 +0000 (+0100) Subject: Add unit test for logout page X-Git-Tag: 0.9.7^2~378 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=c922f4176046a911deec47dc71f70b0052703233;p=Sone.git Add unit test for logout page --- diff --git a/src/test/kotlin/net/pterodactylus/sone/web/LogoutPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/LogoutPageTest.kt new file mode 100644 index 0000000..65b75e0 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/LogoutPageTest.kt @@ -0,0 +1,59 @@ +package net.pterodactylus.sone.web + +import net.pterodactylus.sone.test.whenever +import net.pterodactylus.sone.web.WebTestUtils.redirectsTo +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.equalTo +import org.junit.Test +import org.mockito.Mockito.verify + +/** + * Unit test for [LogoutPage]. + */ +class LogoutPageTest : WebPageTest() { + + private val page = LogoutPage(template, webInterface) + + @Test + fun `page unsets current sone and redirects to index`() { + expectedException.expect(redirectsTo("index.html")) + try { + page.handleRequest(freenetRequest, templateContext) + } finally { + verify(webInterface).setCurrentSone(toadletContext, null) + } + } + + @Test + fun `page is not enabled if sone requires full access and request does not have full access`() { + core.preferences.isRequireFullAccess = true + assertThat(page.isEnabled(toadletContext), equalTo(false)) + } + + @Test + fun `page is disabled if no sone is logged in`() { + unsetCurrentSone() + assertThat(page.isEnabled(toadletContext), equalTo(false)) + } + + @Test + fun `page is disabled if sone is logged in but there is only one sone`() { + whenever(core.localSones).thenReturn(listOf(currentSone)) + assertThat(page.isEnabled(toadletContext), equalTo(false)) + } + + @Test + fun `page is enabled if sone is logged in and there is more than one sone`() { + whenever(core.localSones).thenReturn(listOf(currentSone, currentSone)) + assertThat(page.isEnabled(toadletContext), equalTo(true)) + } + + @Test + fun `page is enabled if full access is required and present and sone is logged in and there is more than one sone`() { + core.preferences.isRequireFullAccess = true + whenever(toadletContext.isAllowedFullAccess).thenReturn(true) + whenever(core.localSones).thenReturn(listOf(currentSone, currentSone)) + assertThat(page.isEnabled(toadletContext), equalTo(true)) + } + +}