1 package net.pterodactylus.sone.web.pages
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(::LogoutPage) {
15 fun `page returns correct path`() {
16 assertThat(page.path, equalTo("logout.html"))
20 fun `page requires login`() {
21 assertThat(page.requiresLogin(), equalTo(true))
25 fun `page returns correct title`() {
26 addTranslation("Page.Logout.Title", "logout page title")
27 assertThat(page.getPageTitle(freenetRequest), equalTo("logout page title"))
31 fun `page unsets current sone and redirects to index`() {
32 verifyRedirect("index.html") {
33 verify(webInterface).setCurrentSone(toadletContext, null)
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))
44 fun `page is disabled if no sone is logged in`() {
46 assertThat(page.isEnabled(toadletContext), equalTo(false))
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))
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))
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))