Convert index page test to use new web page test base
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / WebPageTest2.kt
index 9e57539..bf328a7 100644 (file)
@@ -9,6 +9,7 @@ import net.pterodactylus.sone.data.Image
 import net.pterodactylus.sone.data.Post
 import net.pterodactylus.sone.data.PostReply
 import net.pterodactylus.sone.data.Sone
+import net.pterodactylus.sone.freenet.wot.OwnIdentity
 import net.pterodactylus.sone.test.deepMock
 import net.pterodactylus.sone.test.get
 import net.pterodactylus.sone.test.mock
@@ -55,6 +56,7 @@ abstract class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTempla
        private val requestHeaders = mutableMapOf<String, String>()
        private val getRequestParameters = mutableMapOf<String, MutableList<String>>()
        private val postRequestParameters = mutableMapOf<String, ByteArray>()
+       private val ownIdentities = mutableSetOf<OwnIdentity>()
        private val allSones = mutableMapOf<String, Sone>()
        private val localSones = mutableMapOf<String, Sone>()
        private val allPosts = mutableMapOf<String, Post>()
@@ -67,6 +69,7 @@ abstract class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTempla
        @Before
        fun setupCore() {
                whenever(core.preferences).thenReturn(preferences)
+               whenever(core.identityManager.allOwnIdentities).then { ownIdentities }
                whenever(core.sones).then { allSones.values }
                whenever(core.getSone(anyString())).then { allSones[it[0]].asOptional() }
                whenever(core.localSones).then { localSones.values }
@@ -101,6 +104,7 @@ abstract class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTempla
                whenever(httpRequest.getLongParam(anyString(), anyLong())).then { getRequestParameters[it[0]]?.first()?.toLongOrNull() ?: it[1] }
                whenever(httpRequest.getMultipleParam(anyString())).then { getRequestParameters[it[0]]?.toTypedArray() ?: emptyArray<String>() }
                whenever(httpRequest.getMultipleIntParam(anyString())).then { getRequestParameters[it[0]]?.map { it.toIntOrNull() ?: 0 } ?: emptyArray<Int>() }
+               whenever(httpRequest.isPartSet(anyString())).then { it[0] in postRequestParameters }
                whenever(httpRequest.getPartAsStringFailsafe(anyString(), anyInt())).then { postRequestParameters[it[0]]?.decode()?.take(it[1]) ?: "" }
        }
 
@@ -146,6 +150,10 @@ abstract class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTempla
                whenever(webInterface.getCurrentSoneWithoutCreatingSession(eq(toadletContext))).thenReturn(null)
        }
 
+       fun addOwnIdentity(ownIdentity: OwnIdentity) {
+               ownIdentities += ownIdentity
+       }
+
        fun addSone(id: String, sone: Sone) {
                allSones[id] = sone
        }