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() {
14 private val page = LogoutPage(template, webInterface)
16 override fun getPage() = page
19 fun `page returns correct path`() {
20 assertThat(page.path, equalTo("logout.html"))
24 fun `page requires login`() {
25 assertThat(page.requiresLogin(), equalTo(true))
29 fun `page returns correct title`() {
30 addTranslation("Page.Logout.Title", "logout page title")
31 assertThat(page.getPageTitle(freenetRequest), equalTo("logout page title"))
35 fun `page unsets current sone and redirects to index`() {
36 verifyRedirect("index.html") {
37 verify(webInterface).setCurrentSone(toadletContext, null)
42 fun `page is not enabled if sone requires full access and request does not have full access`() {
43 core.preferences.isRequireFullAccess = true
44 assertThat(page.isEnabled(toadletContext), equalTo(false))
48 fun `page is disabled if no sone is logged in`() {
50 assertThat(page.isEnabled(toadletContext), equalTo(false))
54 fun `page is disabled if sone is logged in but there is only one sone`() {
55 whenever(core.localSones).thenReturn(listOf(currentSone))
56 assertThat(page.isEnabled(toadletContext), equalTo(false))
60 fun `page is enabled if sone is logged in and there is more than one sone`() {
61 whenever(core.localSones).thenReturn(listOf(currentSone, currentSone))
62 assertThat(page.isEnabled(toadletContext), equalTo(true))
66 fun `page is enabled if full access is required and present and sone is logged in and there is more than one sone`() {
67 core.preferences.isRequireFullAccess = true
68 whenever(toadletContext.isAllowedFullAccess).thenReturn(true)
69 whenever(core.localSones).thenReturn(listOf(currentSone, currentSone))
70 assertThat(page.isEnabled(toadletContext), equalTo(true))