1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.test.getInstance
4 import net.pterodactylus.sone.test.whenever
5 import net.pterodactylus.sone.web.baseInjector
6 import org.hamcrest.MatcherAssert.assertThat
7 import org.hamcrest.Matchers.equalTo
8 import org.hamcrest.Matchers.notNullValue
10 import org.mockito.Mockito.verify
13 * Unit test for [LogoutPage].
15 class LogoutPageTest: WebPageTest(::LogoutPage) {
18 fun `page returns correct path`() {
19 assertThat(page.path, equalTo("logout.html"))
23 fun `page requires login`() {
24 assertThat(page.requiresLogin(), equalTo(true))
28 fun `page returns correct title`() {
29 addTranslation("Page.Logout.Title", "logout page title")
30 assertThat(page.getPageTitle(freenetRequest), equalTo("logout page title"))
34 fun `page unsets current sone and redirects to index`() {
35 verifyRedirect("index.html") {
36 verify(webInterface).setCurrentSone(toadletContext, null)
41 fun `page is not enabled if sone requires full access and request does not have full access`() {
42 core.preferences.isRequireFullAccess = true
43 assertThat(page.isEnabled(toadletContext), equalTo(false))
47 fun `page is disabled if no sone is logged in`() {
49 assertThat(page.isEnabled(toadletContext), equalTo(false))
53 fun `page is disabled if sone is logged in but there is only one sone`() {
54 whenever(core.localSones).thenReturn(listOf(currentSone))
55 assertThat(page.isEnabled(toadletContext), equalTo(false))
59 fun `page is enabled if sone is logged in and there is more than one sone`() {
60 whenever(core.localSones).thenReturn(listOf(currentSone, currentSone))
61 assertThat(page.isEnabled(toadletContext), equalTo(true))
65 fun `page is enabled if full access is required and present and sone is logged in and there is more than one sone`() {
66 core.preferences.isRequireFullAccess = true
67 whenever(toadletContext.isAllowedFullAccess).thenReturn(true)
68 whenever(core.localSones).thenReturn(listOf(currentSone, currentSone))
69 assertThat(page.isEnabled(toadletContext), equalTo(true))
73 fun `page can be created by dependency injection`() {
74 assertThat(baseInjector.getInstance<LogoutPage>(), notNullValue())