import net.pterodactylus.sone.main.SonePlugin
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
-import net.pterodactylus.sone.web.pages.SoneTemplatePage
import net.pterodactylus.sone.web.page.FreenetRequest
import net.pterodactylus.util.notify.Notification
import net.pterodactylus.util.template.TemplateContext
import net.pterodactylus.util.version.Version
-import net.pterodactylus.util.web.Method.GET
import org.hamcrest.Matcher
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.anyOf
/**
* Unit test for [SoneTemplatePage].
*/
-class SoneTemplatePageTest : WebPageTest() {
-
- private val preferences by lazy { core.preferences!! }
- private val page = object : SoneTemplatePage("path.html", template, webInterface, true) {}
+class SoneTemplatePageTest: WebPageTest2({ template, webInterface -> object : SoneTemplatePage("path.html", template, webInterface, true) {}}) {
@Test
fun `current sone is retrieved from web interface`() {
@Test
fun `retrieving current sone without creation is forwarded to web interface`() {
mock<Sone>().let {
- whenever(webInterface.getCurrentSoneWithoutCreatingSession(toadletContext)).thenReturn(it)
- assertThat(page.getCurrentSoneWithoutCreatingSession(toadletContext), equalTo(it))
+ whenever(webInterface.getCurrentSone(toadletContext, false)).thenReturn(it)
+ assertThat(page.getCurrentSone(toadletContext, false), equalTo(it))
}
}
@Test
fun `redirect does happen if sone is not logged in`() {
unsetCurrentSone()
- request("index.html", GET)
+ request("index.html")
assertThat(page.getRedirectTarget(freenetRequest), equalTo("login.html?target=index.html"))
}
@Test
fun `redirect does happen with parameters encoded correctly if sone is not logged in`() {
unsetCurrentSone()
- request("index.html", GET)
+ request("index.html")
addHttpRequestParameter("foo", "b=r")
addHttpRequestParameter("baz", "q&o")
assertThat(page.getRedirectTarget(freenetRequest), anyOf(