🔥 Remove templates from FreenetTemplatePages
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / WebPageTest.kt
index 4f72902..20e6cb6 100644 (file)
@@ -1,7 +1,7 @@
 package net.pterodactylus.sone.web.pages
 
 import com.google.common.eventbus.EventBus
-import freenet.clients.http.ToadletContext
+import freenet.clients.http.*
 import freenet.support.SimpleReadOnlyArrayBucket
 import freenet.support.api.HTTPRequest
 import freenet.support.api.HTTPUploadedFile
@@ -13,6 +13,7 @@ import net.pterodactylus.sone.data.PostReply
 import net.pterodactylus.sone.data.Sone
 import net.pterodactylus.sone.data.TemporaryImage
 import net.pterodactylus.sone.freenet.wot.OwnIdentity
+import net.pterodactylus.sone.main.*
 import net.pterodactylus.sone.test.deepMock
 import net.pterodactylus.sone.test.get
 import net.pterodactylus.sone.test.mock
@@ -20,10 +21,9 @@ import net.pterodactylus.sone.test.whenever
 import net.pterodactylus.sone.utils.asList
 import net.pterodactylus.sone.utils.asOptional
 import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
 import net.pterodactylus.sone.web.page.FreenetTemplatePage.RedirectException
 import net.pterodactylus.util.notify.Notification
-import net.pterodactylus.util.template.Template
 import net.pterodactylus.util.template.TemplateContext
 import net.pterodactylus.util.web.Method
 import net.pterodactylus.util.web.Method.GET
@@ -42,19 +42,28 @@ import kotlin.text.Charsets.UTF_8
 /**
  * Base class for web page tests.
  */
-open class WebPageTest(pageSupplier: (Template, WebInterface) -> SoneTemplatePage = { _, _ -> mock() }) {
+open class WebPageTest(pageSupplier: (WebInterface, Loaders, TemplateRenderer) -> SoneTemplatePage = { _, _, _ -> mock() }) {
 
        val currentSone = mock<Sone>()
-       val template = mock<Template>()
+       val loaders = mock<Loaders>()
+       val templateRenderer = mock<TemplateRenderer>()
        val webInterface = deepMock<WebInterface>()
        val core = webInterface.core
        val eventBus = mock<EventBus>()
        val preferences = Preferences(eventBus)
        val l10n = webInterface.l10n!!
+       val sessionManager = mock<SessionManager>()
+
+       val page by lazy { pageSupplier(webInterface, loaders, templateRenderer) }
 
-       val page by lazy { pageSupplier(template, webInterface) }
        val httpRequest = mock<HTTPRequest>()
        val freenetRequest = mock<FreenetRequest>()
+       init {
+               whenever(freenetRequest.l10n).thenReturn(l10n)
+               whenever(freenetRequest.sessionManager).thenReturn(sessionManager)
+               whenever(freenetRequest.uri).thenReturn(mock())
+       }
+       val soneRequest by lazy { freenetRequest.toSoneRequest(core, webInterface) }
        val templateContext = TemplateContext()
        val toadletContext = deepMock<ToadletContext>()
        val responseContent = ByteArrayOutputStream()
@@ -102,6 +111,7 @@ open class WebPageTest(pageSupplier: (Template, WebInterface) -> SoneTemplatePag
        }
 
        private fun setupWebInterface() {
+               whenever(webInterface.sessionManager).thenReturn(sessionManager)
                whenever(webInterface.getCurrentSoneCreatingSession(eq(toadletContext))).thenReturn(currentSone)
                whenever(webInterface.getCurrentSone(eq(toadletContext), anyBoolean())).thenReturn(currentSone)
                whenever(webInterface.getCurrentSoneWithoutCreatingSession(eq(toadletContext))).thenReturn(currentSone)