1 package net.pterodactylus.sone.web.page
3 import freenet.clients.http.*
4 import freenet.support.*
5 import freenet.support.HTMLNode.*
6 import net.pterodactylus.sone.test.*
7 import net.pterodactylus.sone.test.TestUtil.*
8 import org.hamcrest.MatcherAssert.*
9 import org.hamcrest.Matchers.*
13 class PageMakerInteractionTest {
15 private val toadletContext = deepMock<ToadletContext>()
16 private val pageMaker: PageMaker = toadletContext.pageMaker
17 private val outerNode = HTMLDoctype("html", "-//W3C//DTD XHTML 1.1//EN")
18 private val htmlNode: HTMLNode = outerNode.addChild("html")
19 private val headNode: HTMLNode = htmlNode.addChild("head")
20 private val contentNode: HTMLNode = htmlNode.addChild("body").addChild("div")
21 private val pageNode: PageNode = createObject(PageNode::class.java, arrayOf(HTMLNode::class.java, HTMLNode::class.java, HTMLNode::class.java), outerNode, headNode, contentNode)
24 whenever(pageMaker.getPageNode("page title", toadletContext)).thenReturn(pageNode)
27 private val pageMakerInteractions = PageMakerInteraction(toadletContext, "page title")
30 fun `interactions can add style sheet`() {
31 pageMakerInteractions.addStyleSheet("style.sheet")
32 assertThat(headNode.children.filter { it.name == "link" }.map { it.attributes }, contains(
33 mapOf("rel" to "stylesheet", "href" to "style.sheet", "type" to "text/css", "media" to "screen")
38 fun `link nodes can be added`() {
39 pageMakerInteractions.addLinkNode(mapOf("foo" to "bar"))
40 assertThat(headNode.children.filter { it.name == "link" }.map { it.attributes }, contains(
46 fun `shortcut icon can be added`() {
47 pageMakerInteractions.addShortcutIcon("shortcut.icon")
48 assertThat(headNode.children.filter { it.name == "link" }.map { it.attributes }, contains(
49 mapOf("rel" to "icon", "href" to "shortcut.icon")
54 fun `content can be set`() {
55 pageMakerInteractions.setContent("foo<bar")
56 assertThat(contentNode.generate(), containsString("foo<bar"))
60 fun `whole page can be rendered`() {
61 pageMakerInteractions.setContent("foo<bar")
62 assertThat(pageMakerInteractions.renderPage(), containsString("foo<bar"))
65 private val HTMLNode.name: String get() = firstTag