1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.test.*
4 import net.pterodactylus.sone.web.*
5 import net.pterodactylus.sone.web.page.*
6 import org.hamcrest.MatcherAssert.*
7 import org.hamcrest.Matchers.*
9 import org.mockito.Mockito.*
12 * Unit test for [LogoutPage].
14 class LogoutPageTest : WebPageTest(::LogoutPage) {
17 fun `page returns correct path`() {
18 assertThat(page.path, equalTo("logout.html"))
22 fun `page requires login`() {
23 assertThat(page.requiresLogin(), equalTo(true))
27 fun `page returns correct title`() {
28 addTranslation("Page.Logout.Title", "logout page title")
29 assertThat(page.getPageTitle(soneRequest), equalTo("logout page title"))
33 fun `page unsets current sone and redirects to index`() {
34 verifyRedirect("index.html") {
35 verify(webInterface).setCurrentSone(toadletContext, null)
40 fun `page is not enabled if sone requires full access and request does not have full access`() {
41 core.preferences.newRequireFullAccess = true
42 assertThat(page.isEnabled(toadletContext), equalTo(false))
46 fun `page is disabled if no sone is logged in`() {
48 assertThat(page.isEnabled(toadletContext), equalTo(false))
52 fun `page is disabled if sone is logged in but there is only one sone`() {
53 whenever(core.localSones).thenReturn(listOf(currentSone))
54 assertThat(page.isEnabled(toadletContext), equalTo(false))
58 fun `page is enabled if sone is logged in and there is more than one sone`() {
59 whenever(core.localSones).thenReturn(listOf(currentSone, currentSone))
60 assertThat(page.isEnabled(toadletContext), equalTo(true))
64 fun `page is enabled if full access is required and present and sone is logged in and there is more than one sone`() {
65 core.preferences.newRequireFullAccess = true
66 whenever(toadletContext.isAllowedFullAccess).thenReturn(true)
67 whenever(core.localSones).thenReturn(listOf(currentSone, currentSone))
68 assertThat(page.isEnabled(toadletContext), equalTo(true))
72 fun `page can be created by dependency injection`() {
73 assertThat(baseInjector.getInstance<LogoutPage>(), notNullValue())
77 fun `page is annotated with correct menuname`() {
78 assertThat(page.menuName, equalTo("Logout"))