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 net.pterodactylus.sone.web.page.*
7 import org.hamcrest.MatcherAssert.assertThat
8 import org.hamcrest.Matchers.equalTo
9 import org.hamcrest.Matchers.notNullValue
11 import org.mockito.Mockito.verify
14 * Unit test for [LogoutPage].
16 class LogoutPageTest: WebPageTest(::LogoutPage) {
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(soneRequest), 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.newRequireFullAccess = 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.newRequireFullAccess = true
68 whenever(toadletContext.isAllowedFullAccess).thenReturn(true)
69 whenever(core.localSones).thenReturn(listOf(currentSone, currentSone))
70 assertThat(page.isEnabled(toadletContext), equalTo(true))
74 fun `page can be created by dependency injection`() {
75 assertThat(baseInjector.getInstance<LogoutPage>(), notNullValue())
79 fun `page is annotated with correct menuname`() {
80 assertThat(page.menuName, equalTo("Logout"))