return sonePlugin.core();
}
- /**
- * Returns the template context factory of the web interface.
- *
- * @return The template context factory
- */
- public TemplateContextFactory getTemplateContextFactory() {
- return templateContextFactory;
- }
-
@Nullable
@Override
public Sone getCurrentSone(@Nonnull ToadletContext toadletContext) {
pageToadletRegistry.addPage(new GetImagePage(this));
pageToadletRegistry.addPage(new GetTranslationAjaxPage(this));
pageToadletRegistry.addPage(new GetStatusAjaxPage(this, elementLoader, newElements, timeTextConverter, l10nFilter, TimeZone.getDefault()));
- pageToadletRegistry.addPage(new GetNotificationsAjaxPage(this));
+ pageToadletRegistry.addPage(new GetNotificationsAjaxPage(this, templateContextFactory));
pageToadletRegistry.addPage(new DismissNotificationAjaxPage(this));
pageToadletRegistry.addPage(new CreatePostAjaxPage(this));
pageToadletRegistry.addPage(new CreateReplyAjaxPage(this));
- pageToadletRegistry.addPage(new GetReplyAjaxPage(this, replyTemplate));
- pageToadletRegistry.addPage(new GetPostAjaxPage(this, postTemplate));
+ pageToadletRegistry.addPage(new GetReplyAjaxPage(this, templateContextFactory, replyTemplate));
+ pageToadletRegistry.addPage(new GetPostAjaxPage(this, templateContextFactory, postTemplate));
pageToadletRegistry.addPage(new GetLinkedElementAjaxPage(this, elementLoader, linkedElementRenderFilter));
pageToadletRegistry.addPage(new GetTimesAjaxPage(this, timeTextConverter, l10nFilter, TimeZone.getDefault()));
pageToadletRegistry.addPage(new MarkAsKnownAjaxPage(this));
import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.notify.Notification
import net.pterodactylus.util.notify.TemplateNotification
+import net.pterodactylus.util.template.TemplateContextFactory
import java.io.StringWriter
import javax.inject.Inject
* AJAX handler to return all current notifications.
*/
@ToadletPath("getNotifications.ajax")
-class GetNotificationsAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) {
+class GetNotificationsAjaxPage @Inject constructor(webInterface: WebInterface, private val templateContextFactory: TemplateContextFactory) : JsonPage(webInterface) {
override val needsFormPassword = false
override val requiresLogin = false
)
private fun TemplateNotification.render(currentSone: Sone?, freenetRequest: FreenetRequest) = StringWriter().use {
- val mergedTemplateContext = webInterface.templateContextFactory.createTemplateContext()
+ val mergedTemplateContext = templateContextFactory.createTemplateContext()
.mergeContext(templateContext)
.apply {
this["core"] = core
import net.pterodactylus.sone.web.WebInterface
import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
+import net.pterodactylus.util.template.TemplateContextFactory
import javax.inject.Inject
/**
* This AJAX handler retrieves information and rendered representation of a [Post].
*/
@ToadletPath("getPost.ajax")
-class GetPostAjaxPage @Inject constructor(webInterface: WebInterface, private val postTemplate: Template) : LoggedInJsonPage(webInterface) {
+class GetPostAjaxPage @Inject constructor(webInterface: WebInterface, private val templateContextFactory: TemplateContextFactory, private val postTemplate: Template) : LoggedInJsonPage(webInterface) {
override val needsFormPassword = false
} ?: createErrorJsonObject("invalid-post-id")
private fun Post.render(currentSone: Sone, request: FreenetRequest) =
- webInterface.templateContextFactory.createTemplateContext().apply {
+ templateContextFactory.createTemplateContext().apply {
set("core", core)
set("request", request)
set("post", this@render)
import net.pterodactylus.sone.web.WebInterface
import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
+import net.pterodactylus.util.template.TemplateContextFactory
import javax.inject.Inject
/**
* This AJAX page returns the details of a reply.
*/
@ToadletPath("getReply.ajax")
-class GetReplyAjaxPage @Inject constructor(webInterface: WebInterface, private val template: Template) : LoggedInJsonPage(webInterface) {
+class GetReplyAjaxPage @Inject constructor(webInterface: WebInterface, val templateContextFactory: TemplateContextFactory, private val template: Template) : LoggedInJsonPage(webInterface) {
override val needsFormPassword = false
).toList().toTypedArray())
private fun PostReply.render(currentSone: Sone, request: FreenetRequest) =
- webInterface.templateContextFactory.createTemplateContext().apply {
+ templateContextFactory.createTemplateContext().apply {
set("core", core)
set("request", request)
set("reply", this@render)
/**
* Unit test for [GetNotificationsAjaxPage].
*/
-class GetNotificationsAjaxPageTest : JsonPageTest("getNotifications.ajax", requiresLogin = false, needsFormPassword = false, pageSupplier = ::GetNotificationsAjaxPage) {
+class GetNotificationsAjaxPageTest : JsonPageTest("getNotifications.ajax", requiresLogin = false, needsFormPassword = false) {
+
+ override val page: JsonPage by lazy { GetNotificationsAjaxPage(webInterface, TemplateContextFactory()) }
private val testNotifications = listOf(
createNotification("n1", 2000, "t1", 5000, true),
@Test
fun `template notifications are rendered correctly`() {
- whenever(webInterface.templateContextFactory).thenReturn(TemplateContextFactory())
whenever(updateChecker.hasLatestVersion()).thenReturn(true)
whenever(updateChecker.latestEdition).thenReturn(999)
whenever(updateChecker.latestVersion).thenReturn(Version(0, 1, 2))
import net.pterodactylus.sone.utils.asTemplate
import net.pterodactylus.sone.web.baseInjector
import net.pterodactylus.util.template.ReflectionAccessor
+import net.pterodactylus.util.template.TemplateContextFactory
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.hamcrest.Matchers.notNullValue
/**
* Unit test for [GetPostAjaxPage].
*/
-class GetPostAjaxPageTest : JsonPageTest("getPost.ajax", needsFormPassword = false,
- pageSupplier = { webInterface ->
- GetPostAjaxPage(webInterface, "<%core>\n<%request>\n<%post.text>\n<%currentSone>\n<%localSones>".asTemplate())
- }) {
+class GetPostAjaxPageTest : JsonPageTest("getPost.ajax", needsFormPassword = false) {
+
+ private val templateContextFactory = TemplateContextFactory().apply {
+ addAccessor(Any::class.java, ReflectionAccessor())
+ }
+ override val page: JsonPage by lazy { GetPostAjaxPage(webInterface, templateContextFactory, "<%core>\n<%request>\n<%post.text>\n<%currentSone>\n<%localSones>".asTemplate()) }
@Test
fun `request with missing post results in invalid-post-id`() {
whenever(recipientId).thenReturn("recipient-id".asOptional())
whenever(text).thenReturn("post text")
}
- webInterface.templateContextFactory.addAccessor(Any::class.java, ReflectionAccessor())
addPost(post)
addRequestParameter("post", "post-id")
assertThatJsonIsSuccessful()
import net.pterodactylus.sone.utils.asTemplate
import net.pterodactylus.sone.web.baseInjector
import net.pterodactylus.util.template.ReflectionAccessor
+import net.pterodactylus.util.template.TemplateContextFactory
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.hamcrest.Matchers.notNullValue
/**
* Unit test for [GetReplyAjaxPage].
*/
-class GetReplyAjaxPageTest : JsonPageTest("getReply.ajax", needsFormPassword = false,
- pageSupplier = { webInterface ->
- GetReplyAjaxPage(webInterface, "<%core>\n<%request>\n<%reply.text>\n<%currentSone>".asTemplate())
- }) {
+class GetReplyAjaxPageTest : JsonPageTest("getReply.ajax", needsFormPassword = false) {
+
+ private val templateContextFactory = TemplateContextFactory().apply {
+ addAccessor(Any::class.java, ReflectionAccessor())
+ }
+ override val page: JsonPage by lazy { GetReplyAjaxPage(webInterface, templateContextFactory, "<%core>\n<%request>\n<%reply.text>\n<%currentSone>".asTemplate()) }
@Test
fun `request without reply id results in invalid-reply-id`() {
whenever(time).thenReturn(1000)
whenever(text).thenReturn("reply text")
}
- webInterface.templateContextFactory.addAccessor(Any::class.java, ReflectionAccessor())
addReply(reply)
addRequestParameter("reply", "reply-id")
assertThatJsonIsSuccessful()
}
init {
- whenever(webInterface.templateContextFactory).thenReturn(TemplateContextFactory())
whenever(webInterface.getCurrentSone(ArgumentMatchers.eq(toadletContext))).thenReturn(currentSone)
whenever(webInterface.core).thenReturn(core)
whenever(webInterface.formPassword).then { formPassword }