Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #268 from hdiv/master

RequestDataValueProcessor interface support
  • Loading branch information...
commit d1a42f26e8519c20dec6b056904ee7e85e5821cf 2 parents 5de560f + 26ab642
@graemerocher graemerocher authored
View
20 grails-plugin-controllers/src/main/groovy/org/codehaus/groovy/grails/web/metaclass/ChainMethod.groovy
@@ -22,6 +22,12 @@ import org.codehaus.groovy.grails.web.mapping.UrlCreator
import org.codehaus.groovy.grails.web.mapping.UrlMappingsHolder
import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest
import org.springframework.web.context.request.RequestContextHolder
+import org.springframework.web.servlet.support.RequestDataValueProcessor
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
* Implementation of the chain() method for controllers.
@@ -31,6 +37,8 @@ import org.springframework.web.context.request.RequestContextHolder
*/
class ChainMethod {
+ private static final Log LOG = LogFactory.getLog(RedirectDynamicMethod.class);
+
static invoke(target, Map args = [:]) {
def controller = args.controller ?: GrailsNameUtils.getLogicalPropertyName(
target.class.name, ControllerArtefactHandler.TYPE)
@@ -74,7 +82,17 @@ class ChainMethod {
UrlCreator creator = mappings.getReverseMapping(controller, action, plugin, params)
def response = webRequest.getCurrentResponse()
- def url = response.encodeRedirectURL(creator.createURL(controller, action, plugin, params, 'utf-8'))
+ def url = creator.createURL(controller, action, plugin, params, 'utf-8')
+
+ if(appCtx.containsBean("requestDataValueProcessor")) {
+ RequestDataValueProcessor valueProcessor = appCtx.getBean("requestDataValueProcessor")
+ if(valueProcessor != null) {
+ HttpServletRequest request = webRequest.getCurrentRequest()
+ url = response.encodeRedirectURL(valueProcessor.processUrl(request,url))
+ }
+ } else {
+ url = response.encodeRedirectURL(url)
+ }
response.sendRedirect url
}
}
View
29 ...s-plugin-controllers/src/main/groovy/org/codehaus/groovy/grails/web/metaclass/RedirectDynamicMethod.java
@@ -33,6 +33,7 @@
import org.springframework.context.ApplicationContext;
import org.springframework.validation.Errors;
import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.servlet.support.RequestDataValueProcessor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -65,6 +66,7 @@
private boolean useJessionId = false;
private Collection<RedirectEventListener> redirectListeners;
private LinkGenerator linkGenerator;
+ private RequestDataValueProcessor requestDataValueProcessor = null;
/**
*/
@@ -146,6 +148,7 @@ public Object invoke(Object target, String methodName, Object[] arguments) {
// which includes the contextPath
argMap.put(LinkGenerator.ATTRIBUTE_CONTEXT_PATH, BLANK);
return redirectResponse(requestLinkGenerator.getServerBaseURL(), requestLinkGenerator.link(argMap), request, response, permanent);
+
}
private LinkGenerator getLinkGenerator(GrailsWebRequest webRequest) {
@@ -170,8 +173,8 @@ private Object redirectResponse(String serverBaseURL, String actualUri, HttpServ
if (LOG.isDebugEnabled()) {
LOG.debug("Executing redirect with response ["+response+"]");
}
-
- String absoluteURL = actualUri.contains("://") ? actualUri : serverBaseURL + actualUri;
+ String processedActualUri = processedUrl(actualUri, request);
+ String absoluteURL = processedActualUri.contains("://") ? processedActualUri : serverBaseURL + processedActualUri;
String redirectUrl = useJessionId ? response.encodeRedirectURL(absoluteURL) : absoluteURL;
int status = permanent ? HttpServletResponse.SC_MOVED_PERMANENTLY : HttpServletResponse.SC_MOVED_TEMPORARILY;
@@ -184,7 +187,7 @@ private Object redirectResponse(String serverBaseURL, String actualUri, HttpServ
}
}
- request.setAttribute(GRAILS_REDIRECT_ISSUED, actualUri);
+ request.setAttribute(GRAILS_REDIRECT_ISSUED, processedActualUri);
return null;
}
@@ -204,4 +207,24 @@ else if (actionRef instanceof Closure) {
}
return actionName;
}
+
+
+ /**
+ * getter to obtain RequestDataValueProcessor from
+ */
+ private void initRequestDataValueProcessor() {
+ GrailsWebRequest webRequest = (GrailsWebRequest)RequestContextHolder.currentRequestAttributes();
+ ApplicationContext applicationContext = webRequest.getApplicationContext();
+ if (requestDataValueProcessor == null && applicationContext.containsBean("requestDataValueProcessor")){
+ requestDataValueProcessor = applicationContext.getBean("requestDataValueProcessor",RequestDataValueProcessor.class);
+ }
+ }
+ private String processedUrl(String link, HttpServletRequest request) {
+ initRequestDataValueProcessor();
+ String currentLink = link;
+ if(requestDataValueProcessor != null) {
+ currentLink = requestDataValueProcessor.processUrl(request,link);
+ }
+ return currentLink;
+ }
}
View
35 grails-plugin-gsp/src/main/groovy/org/codehaus/groovy/grails/plugins/web/taglib/ApplicationTagLib.groovy
@@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ApplicationContext
import org.springframework.context.ApplicationContextAware
import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest
+import org.springframework.web.servlet.support.RequestDataValueProcessor
/**
* The base application tag library for Grails many of which take inspiration from Rails helpers (thanks guys! :)
@@ -58,6 +59,8 @@ class ApplicationTagLib implements ApplicationContextAware, InitializingBean, Gr
boolean useJsessionId = false
boolean hasResourceProcessor = false
+ def requestDataValueProcessor = null
+
void afterPropertiesSet() {
def config = applicationContext.getBean(GrailsApplication.APPLICATION_ID).config
if (config.grails.views.enable.jsessionid instanceof Boolean) {
@@ -158,7 +161,9 @@ class ApplicationTagLib implements ApplicationContextAware, InitializingBean, Gr
}
// Use resources plugin if present, but only if file is specified - resources require files
// But users often need to link to a folder just using dir
- return ((hasResourceProcessor && attrs.file) ? r.resource(attrs) : linkGenerator.resource(attrs))
+ def url = ((hasResourceProcessor && attrs.file) ? r.resource(attrs) : linkGenerator.resource(attrs));
+
+ return url?processedUrl("${url}",request):url;
}
/**
@@ -175,11 +180,12 @@ class ApplicationTagLib implements ApplicationContextAware, InitializingBean, Gr
if (hasResourceProcessor) {
return r.img(attrs)
} else {
- def uri = attrs.uri ?: resource(attrs)
+ def uri = attrs.uri ?processedUrl(attrs.uri,request): resource(attrs)
def excludes = ['dir', 'uri', 'file', 'plugin']
def attrsAsString = attrsToString(attrs.findAll { !(it.key in excludes) })
- return "<img src=\"${uri.encodeAsHTML()}\"${attrsAsString} />"
+ def imgSrc = uri.encodeAsHTML()
+ return "<img src=\"${imgSrc}\"${attrsAsString} />"
}
}
@@ -322,7 +328,7 @@ class ApplicationTagLib implements ApplicationContextAware, InitializingBean, Gr
// Allow attrs to overwrite any constants
attrs.each { typeInfo.remove(it.key) }
- out << writer(uri, typeInfo, attrs)
+ out << writer(processedUrl(uri,request), typeInfo, attrs)
out << "\r\n"
}
@@ -365,6 +371,7 @@ class ApplicationTagLib implements ApplicationContextAware, InitializingBean, Gr
urlAttrs.params = params
}
def generatedLink = linkGenerator.link(attrs, request.characterEncoding)
+ generatedLink = processedUrl(generatedLink,request);
if (useJsessionId) {
return response.encodeURL(generatedLink)
@@ -435,4 +442,24 @@ class ApplicationTagLib implements ApplicationContextAware, InitializingBean, Gr
}
return Metadata.current[attrs.name]
}
+
+ /**
+ * getter to obtain RequestDataValueProcessor from
+ */
+ private initRequestDataValueProcessor() {
+ if (requestDataValueProcessor == null && grailsAttributes.getApplicationContext().containsBean("requestDataValueProcessor")){
+ requestDataValueProcessor = grailsAttributes.getApplicationContext().getBean("requestDataValueProcessor")
+ }
+ }
+ Closure processedUrl = { link,request ->
+ if(!link) {
+ throwTagError('processedUrl missing required attribute ["link"]')
+ }
+ initRequestDataValueProcessor();
+ def currentLink = link;
+ if(requestDataValueProcessor != null) {
+ currentLink = requestDataValueProcessor.processUrl(request,link);
+ }
+ return currentLink;
+ }
}
View
129 grails-plugin-gsp/src/main/groovy/org/codehaus/groovy/grails/plugins/web/taglib/FormTagLib.groovy
@@ -27,6 +27,7 @@ import org.springframework.beans.SimpleTypeConverter
import org.springframework.context.MessageSourceResolvable
import org.springframework.http.HttpMethod
import org.springframework.web.servlet.support.RequestContextUtils as RCU
+import org.springframework.web.servlet.support.RequestDataValueProcessor
/**
* Tags for working with form controls.
@@ -40,6 +41,8 @@ class FormTagLib {
'XAF', 'NZD', 'MAD', 'DKK', 'GBP', 'CHF',
'XPF', 'ILS', 'ROL', 'TRL']
+ def requestDataValueProcessor = null;
+
/**
* Creates a new text field.
*
@@ -117,6 +120,9 @@ class FormTagLib {
def fieldImpl(out, attrs) {
resolveAttributes(attrs)
+
+ attrs.value = processFormFieldValueIfNecessary(attrs.name, attrs.value, attrs.type);
+
out << "<input type=\"${attrs.remove('type')}\" "
outputAttributes(attrs, out, true)
out << "/>"
@@ -161,14 +167,22 @@ class FormTagLib {
if (checked instanceof String) checked = Boolean.valueOf(checked)
if (value == null) value = false
-
- out << "<input type=\"hidden\" name=\"_${name}\" /><input type=\"checkbox\" name=\"${name}\" "
+ def hiddenValue = "";
+
+ value = processFormFieldValueIfNecessary(name, value,"checkbox")
+ hiddenValue = processFormFieldValueIfNecessary("_${name}", hiddenValue, "hidden")
+
+ out << "<input type=\"hidden\" name=\"_${name}\"";
+ if(hiddenValue != "") {
+ out << " value=\"${hiddenValue}\"";
+ }
+ out << " /><input type=\"checkbox\" name=\"${name}\" "
if (checkedAttributeWasSpecified) {
if (checked) {
out << 'checked="checked" '
}
}
- else if (value) {
+ else if (value && value != "") {
out << 'checked="checked" '
}
@@ -209,9 +223,14 @@ class FormTagLib {
attrs.remove 'escapeHtml'
}
+ // Add textarea field to requestDataValueProcessor
+ def content = (escapeHtml ? value.encodeAsHTML() : value)
+ if(attrs.name) {
+ content = processFormFieldValueIfNecessary(attrs.name,content,"textarea" )
+ }
out << "<textarea "
outputAttributes(attrs, out, true)
- out << ">" << (escapeHtml ? value.encodeAsHTML() : value) << "</textarea>"
+ out << ">" << content << "</textarea>"
}
/**
@@ -323,7 +342,15 @@ class FormTagLib {
def linkAttrs = attrs.subMap(LinkGenerator.LINK_ATTRIBUTES)
writer << "<form action=\""
- writer << createLink(linkAttrs)
+
+ // Call RequestDataValueProcessor to modify url if necessary
+ def link = createLink(linkAttrs)
+ def requestDataValueProcessor = getRequestDataValueProcessor()
+ if (requestDataValueProcessor != null) {
+ link= requestDataValueProcessor.processAction(request,link)
+ }
+
+ writer << link
writer << "\" "
// if URL is not nul remove attributes
@@ -372,11 +399,27 @@ class FormTagLib {
// output the body
writer << body()
+ //Write RequestDataValueProcessor hidden fields if necessary
+ if (requestDataValueProcessor != null){
+ def hiddenFields = requestDataValueProcessor.getExtraHiddenFields(request)
+ writeHiddenFields(hiddenFields)
+ }
// close tag
writer << "</form>"
}
/**
+ * Method to generate hidden inputs
+ */
+ private writeHiddenFields(hiddenFields) {
+ def writer = getOut()
+ if(hiddenFields != null) {
+ hiddenFields.each() { key, value -> writer << "<input type=\"hidden\" name=\"${key}\" value=\"${value}\" />\n"
+ }
+ }
+ }
+
+ /**
* Creates a submit button that submits to an action in the controller specified by the form action.<br/>
* The name of the action attribute is translated into the action name, for example "Edit" becomes
* "_action_edit" or "List People" becomes "_action_listPeople".<br/>
@@ -407,6 +450,8 @@ class FormTagLib {
// add action and value
def value = attrs.remove('value')
def action = attrs.remove('action') ?: value
+ // Change value if necessary in requestDataValueProcessor
+ value = processFormFieldValueIfNecessary("_action_${action}",value,"submit")
booleanToAttribute(attrs, 'disabled')
out << "<input type=\"submit\" name=\"_action_${action}\" value=\"${value}\" "
@@ -443,6 +488,8 @@ class FormTagLib {
// add action and value
def value = attrs.remove('value')
def action = attrs.remove('action') ?: value
+ //Change this button to use requestDataValueProcessor
+ value = processFormFieldValueIfNecessary("_action_${action}","${value}","image")
booleanToAttribute(attrs, 'disabled')
out << "<input type=\"image\" name=\"_action_${action}\" value=\"${value}\" "
@@ -450,6 +497,7 @@ class FormTagLib {
// add image src
def src = attrs.remove('src')
if (src) {
+ src = processedUrl(src,request)
out << "src=\"${src}\" "
}
@@ -578,7 +626,9 @@ class FormTagLib {
booleanToAttribute(attrs, 'disabled')
booleanToAttribute(attrs, 'readonly')
- out.println "<input type=\"hidden\" name=\"${name}\" value=\"date.struct\" />"
+ // Change this hidden to use requestDataValueProcessor
+ def dateStructValue = processFormFieldValueIfNecessary("${name}","date.struct","hidden")
+ out.println "<input type=\"hidden\" name=\"${name}\" value=\"${dateStructValue}\" />"
// create day select
if (precision >= PRECISION_RANKINGS["day"]) {
@@ -597,7 +647,9 @@ class FormTagLib {
}
for (i in 1..31) {
- out.println "<option value=\"${i}\"${i == day ? ' selected="selected"' : ''}>${i}</option>"
+ // Change this option to use requestDataValueProcessor
+ def dayIndex = processFormFieldValueIfNecessary("${name}_day","${i}","option")
+ out.println "<option value=\"${dayIndex}\"${i == day ? ' selected="selected"' : ''}>${i}</option>"
}
out.println '</select>'
}
@@ -621,6 +673,7 @@ class FormTagLib {
dfs.months.eachWithIndex {m, i ->
if (m) {
def monthIndex = i + 1
+ monthIndex = processFormFieldValueIfNecessary("${name}_month","${monthIndex}","option")
out.println "<option value=\"${monthIndex}\"${i == month ? ' selected="selected"' : ''}>$m</option>"
}
}
@@ -644,7 +697,9 @@ class FormTagLib {
}
for (i in years) {
- out.println "<option value=\"${i}\"${i == year ? ' selected="selected"' : ''}>${i}</option>"
+ // Change this year option to use requestDataValueProcessor
+ def yearIndex = processFormFieldValueIfNecessary("${name}_year","${i}","option")
+ out.println "<option value=\"${yearIndex}\"${i == year ? ' selected="selected"' : ''}>${i}</option>"
}
out.println '</select>'
}
@@ -668,6 +723,8 @@ class FormTagLib {
for (i in 0..23) {
def h = '' + i
if (i < 10) h = '0' + h
+ // This option add hour to requestDataValueProcessor
+ h = processFormFieldValueIfNecessary("${name}_hour","${h}","option")
out.println "<option value=\"${h}\"${i == hour ? ' selected="selected"' : ''}>$h</option>"
}
out.println '</select> :'
@@ -697,6 +754,7 @@ class FormTagLib {
for (i in 0..59) {
def m = '' + i
if (i < 10) m = '0' + m
+ m = processFormFieldValueIfNecessary("${name}_minute","${m}","option")
out.println "<option value=\"${m}\"${i == minute ? ' selected="selected"' : ''}>$m</option>"
}
out.println '</select>'
@@ -853,14 +911,17 @@ class FormTagLib {
writer.println()
}
+
+ def requestDataValueProcessor = getRequestDataValueProcessor()
// create options from list
if (from) {
from.eachWithIndex {el, i ->
def keyValue = null
writer << '<option '
if (keys) {
- keyValue = keys[i]
- writeValueAndCheckIfSelected(keyValue, value, writer)
+ keyValue = keys[i];
+
+ writeValueAndCheckIfSelected(attrs.name, keyValue, value, writer)
}
else if (optionKey) {
def keyValueObject = null
@@ -875,11 +936,11 @@ class FormTagLib {
keyValue = el[optionKey]
keyValueObject = el
}
- writeValueAndCheckIfSelected(keyValue, value, writer, keyValueObject)
+ writeValueAndCheckIfSelected(attrs.name, keyValue, value, writer, keyValueObject)
}
else {
keyValue = el
- writeValueAndCheckIfSelected(keyValue, value, writer)
+ writeValueAndCheckIfSelected(attrs.name, keyValue, value, writer)
}
writer << '>'
if (optionValue) {
@@ -922,11 +983,11 @@ class FormTagLib {
writer << '</select>'
}
- private writeValueAndCheckIfSelected(keyValue, value, writer) {
- writeValueAndCheckIfSelected(keyValue, value, writer, null)
+ private writeValueAndCheckIfSelected(selectName, keyValue, value, writer) {
+ writeValueAndCheckIfSelected(selectName, keyValue, value, writer, null)
}
- private writeValueAndCheckIfSelected(keyValue, value, writer, el) {
+ private writeValueAndCheckIfSelected(selectName, keyValue, value, writer, el) {
boolean selected = false
def keyClass = keyValue?.getClass()
@@ -955,6 +1016,7 @@ class FormTagLib {
// ignore
}
}
+ keyValue = processFormFieldValueIfNecessary(selectName, "${keyValue}","option")
writer << "value=\"${keyValue}\" "
if (selected) {
writer << 'selected="selected" '
@@ -980,6 +1042,7 @@ class FormTagLib {
booleanToAttribute(attrs, 'readonly')
def checked = attrs.remove('checked') ? true : false
+ value = processFormFieldValueIfNecessary(name, "${value?.toString()?.encodeAsHTML()}","radio")
out << "<input type=\"radio\" name=\"${name}\"${ checked ? ' checked="checked" ' : ' '}value=\"${value?.toString()?.encodeAsHTML()}\" "
if (!attrs.containsKey('id')) {
out << """id="${name}" """
@@ -1015,7 +1078,9 @@ class FormTagLib {
if (value?.toString().equals(val.toString())) {
it.radio << 'checked="checked" '
}
- it.radio << "value=\"${val.toString().encodeAsHTML()}\" "
+ // Generate
+ def processedVal = processFormFieldValueIfNecessary(name, val.toString().encodeAsHTML(), "radio");
+ it.radio << "value=\"${processedVal}\" "
// process remaining attributes
outputAttributes(attrs, it.radio)
@@ -1027,4 +1092,36 @@ class FormTagLib {
out.println()
}
}
+
+ /**
+ * getter to obtain RequestDataValueProcessor from
+ */
+ private getRequestDataValueProcessor() {
+ if (requestDataValueProcessor == null && grailsAttributes.getApplicationContext().containsBean("requestDataValueProcessor")){
+ requestDataValueProcessor = grailsAttributes.getApplicationContext().getBean("requestDataValueProcessor")
+ }
+ return requestDataValueProcessor;
+ }
+
+ private processFormFieldValueIfNecessary(name, value, type) {
+ def requestDataValueProcessor = getRequestDataValueProcessor();
+ def processedValue = value;
+ if(requestDataValueProcessor != null) {
+ processedValue = requestDataValueProcessor.processFormFieldValue(request, name, "${value}", type);
+ }
+ return processedValue;
+ }
+
+ Closure processedUrl = { link,request ->
+ if(!link) {
+ throwTagError('processedUrl missing required attribute ["link"]')
+ }
+ requestDataValueProcessor = getRequestDataValueProcessor()
+ def currentLink = link;
+ if(requestDataValueProcessor != null) {
+ currentLink = requestDataValueProcessor.processUrl(request,link);
+ }
+ return currentLink;
+ }
+
}
View
40 grails-test-suite-base/src/main/groovy/grails/util/MockRequestDataValueProcessor.java
@@ -0,0 +1,40 @@
+package grails.util;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
+import java.util.HashMap;
+
+public class MockRequestDataValueProcessor implements org.springframework.web.servlet.support.RequestDataValueProcessor {
+ public Map<String,String> getExtraHiddenFields(HttpServletRequest request) {
+ Map<String,String> extraHiddenFields = new HashMap<String,String>();
+ extraHiddenFields.put("requestDataValueProcessorHiddenName","hiddenValue");
+ return extraHiddenFields;
+ }
+ public String processAction(HttpServletRequest request, String action) {
+ String resultAction = action;
+ if(action.indexOf("requestDataValueProcessorParamName=paramValue")>-1) {
+ resultAction = resultAction.replace("?requestDataValueProcessorParamName=paramValue&","?");
+ resultAction = resultAction.replace("?requestDataValueProcessorParamName=paramValue","");
+ resultAction = resultAction.replace("&requestDataValueProcessorParamName=paramValue","");
+ }
+ return resultAction;
+ }
+ public String processFormFieldValue(HttpServletRequest request, String name, String value, String type) {
+ return value+"_PROCESSED_";
+ }
+ public String processUrl(HttpServletRequest request, String url) {
+ String resultUrl = url;
+ String toAppend = null;
+ if(resultUrl.indexOf("?")>-1) {
+ toAppend = "&requestDataValueProcessorParamName=paramValue";
+ } else {
+ toAppend = "?requestDataValueProcessorParamName=paramValue";
+ }
+ if(resultUrl.indexOf("#") > -1) {
+ resultUrl = resultUrl.replace("#",toAppend+"#");
+ } else {
+ resultUrl = resultUrl + toAppend;
+ }
+ return resultUrl;
+ }
+}
View
40 grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/web/metaclass/ChainMethodTests.groovy
@@ -4,11 +4,27 @@ import org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerTests
import org.codehaus.groovy.grails.web.servlet.GrailsFlashScope
import grails.util.MockHttpServletResponse
+import grails.util.MockRequestDataValueProcessor
+
+import org.codehaus.groovy.grails.support.MockApplicationContext
+import org.springframework.web.servlet.support.RequestDataValueProcessor
+
+
/**
* @author Graeme Rocher
* @since 1.0
*/
-class ChainMethodTests extends AbstractGrailsControllerTests{
+class ChainMethodTests extends AbstractGrailsControllerTests {
+
+ void registerRequestDataValueProcessor() {
+ RequestDataValueProcessor requestDataValueProcessor = new MockRequestDataValueProcessor();
+ MockApplicationContext applicationContext = (MockApplicationContext)ctx;
+ applicationContext.registerMockBean("requestDataValueProcessor",requestDataValueProcessor);
+ }
+ void unRegisterRequestDataValueProcessor() {
+ MockApplicationContext applicationContext = (MockApplicationContext)ctx;
+ applicationContext.registerMockBean("requestDataValueProcessor",null);
+ }
protected void onSetUp() {
gcl.parseClass('''
@@ -56,6 +72,28 @@ class TestChainBook {
assertEquals '/testChain/create', response.redirectedUrl
}
+ void testChainMethodWithModelAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def domainClass = ga.getDomainClass("TestChainBook").clazz
+ domainClass.metaClass.save = { false }
+ def controller = ga.getControllerClass("TestChainController").newInstance()
+
+ controller.save()
+
+ def flash = controller.flash
+
+ assert flash.chainModel.book
+
+ def id = System.identityHashCode(flash.chainModel.book)
+
+ assert flash.chainModel[GrailsFlashScope.ERRORS_PREFIX+id]
+
+ org.springframework.mock.web.MockHttpServletResponse response = controller.response
+
+ assertEquals '/testChain/create?requestDataValueProcessorParamName=paramValue', response.redirectedUrl
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testChainMethodWithId() {
def controller = ga.getControllerClass("TestChainController").newInstance()
controller.testId()
View
128 ...ls-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/web/servlet/mvc/RedirectMethodTests.groovy
@@ -5,6 +5,10 @@ import org.codehaus.groovy.grails.web.servlet.HttpHeaders
import org.codehaus.groovy.grails.web.servlet.mvc.exceptions.CannotRedirectException
import org.springframework.beans.MutablePropertyValues
+import grails.util.MockRequestDataValueProcessor
+import org.codehaus.groovy.grails.support.MockApplicationContext
+import org.springframework.web.servlet.support.RequestDataValueProcessor
+
/**
* Tests the behaviour of the redirect method.
*
@@ -13,6 +17,16 @@ import org.springframework.beans.MutablePropertyValues
*/
class RedirectMethodTests extends AbstractGrailsControllerTests {
+ void registerRequestDataValueProcessor() {
+ RequestDataValueProcessor requestDataValueProcessor = new MockRequestDataValueProcessor();
+ MockApplicationContext applicationContext = (MockApplicationContext)ctx;
+ applicationContext.registerMockBean("requestDataValueProcessor",requestDataValueProcessor);
+ }
+ void unRegisterRequestDataValueProcessor() {
+ MockApplicationContext applicationContext = (MockApplicationContext)ctx;
+ applicationContext.registerMockBean("requestDataValueProcessor",null);
+ }
+
protected void onSetUp() {
gcl.parseClass('''
class UrlMappings {
@@ -44,6 +58,16 @@ class UrlMappings {
assertEquals "/redirect/toAction", response.redirectedUrl
}
+ void testRedirectToDefaultActionOfAnotherControllerWithRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def c = new NewsSignupController()
+ webRequest.controllerName = 'newsSignup'
+ c.redirectToDefaultAction.call()
+ assertEquals "/redirect/toAction?requestDataValueProcessorParamName=paramValue", response.redirectedUrl
+ this.unRegisterRequestDataValueProcessor()
+ }
+
+
void testRedirectEventListeners() {
def fired = false
def callable = { fired = true }
@@ -95,6 +119,15 @@ class UrlMappings {
assertEquals "/", response.redirectedUrl
}
+ void testRedirectToRootWtihRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def c = new RedirectController()
+ webRequest.controllerName = 'redirect'
+ c.toRoot.call()
+ assertEquals "/?requestDataValueProcessorParamName=paramValue", response.redirectedUrl
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testRedirectToAbsoluteURL() {
def c = new RedirectController()
webRequest.controllerName = 'redirect'
@@ -110,6 +143,15 @@ class UrlMappings {
assertEquals "/test/foo#frag", response.redirectedUrl
}
+ void testRedirectWithFragmentAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def c = new RedirectController()
+ webRequest.controllerName = 'redirect'
+ c.toControllerAndActionWithFragment.call()
+ assertEquals "/test/foo?requestDataValueProcessorParamName=paramValue#frag", response.redirectedUrl
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testRedirectInControllerWithOneLetterClassName() {
def c = new AController()
webRequest.controllerName = 'a'
@@ -117,12 +159,29 @@ class UrlMappings {
assertEquals "/a/list", response.redirectedUrl
}
+ void testRedirectInControllerWithOneLetterClassNameAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def c = new AController()
+ webRequest.controllerName = 'a'
+ c.index.call()
+ assertEquals "/a/list?requestDataValueProcessorParamName=paramValue", response.redirectedUrl
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testRedirectInControllerWithAllUpperCaseClassName() {
def c = new ABCController()
webRequest.controllerName = 'ABC'
c.index.call()
assertEquals "/ABC/list", response.redirectedUrl
}
+ void testRedirectInControllerWithAllUpperCaseClassNameAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def c = new ABCController()
+ webRequest.controllerName = 'ABC'
+ c.index.call()
+ assertEquals "/ABC/list?requestDataValueProcessorParamName=paramValue", response.redirectedUrl
+ this.unRegisterRequestDataValueProcessor()
+ }
void testRedirectToAction() {
def c = new RedirectController()
@@ -131,6 +190,15 @@ class UrlMappings {
assertEquals "/redirect/foo", response.redirectedUrl
}
+ void testRedirectToActionWithRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def c = new RedirectController()
+ webRequest.controllerName = 'redirect'
+ c.toAction.call()
+ assertEquals "/redirect/foo?requestDataValueProcessorParamName=paramValue", response.redirectedUrl
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testRedirectToActionWithGstring() {
def c = new RedirectController()
webRequest.controllerName = 'redirect'
@@ -145,6 +213,15 @@ class UrlMappings {
assertEquals "/test", response.redirectedUrl
}
+ void testRedirectToControllerWithRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def c = new RedirectController()
+ webRequest.controllerName = 'redirect'
+ c.toController.call()
+ assertEquals "/test?requestDataValueProcessorParamName=paramValue", response.redirectedUrl
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testRedirectToControllerAndAction() {
def c = new RedirectController()
webRequest.controllerName = 'redirect'
@@ -159,6 +236,15 @@ class UrlMappings {
assertEquals "/test/foo?one=two&two=three", response.redirectedUrl
}
+ void testRedirectToControllerWithParamsAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def c = new RedirectController()
+ webRequest.controllerName = 'redirect'
+ c.toControllerWithParams.call()
+ assertEquals "/test/foo?one=two&two=three&requestDataValueProcessorParamName=paramValue", response.redirectedUrl
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testRedirectToControllerWithDuplicateParams() {
def c = new RedirectController()
webRequest.controllerName = 'redirect'
@@ -166,6 +252,15 @@ class UrlMappings {
assertEquals "/test/foo?one=two&one=three", response.redirectedUrl
}
+ void testRedirectToControllerWithDuplicateParamsAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def c = new RedirectController()
+ webRequest.controllerName = 'redirect'
+ c.toControllerWithDuplicateParams.call()
+ assertEquals "/test/foo?one=two&one=three&requestDataValueProcessorParamName=paramValue", response.redirectedUrl
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testRedirectToControllerWithDuplicateArrayParams() {
def c = new RedirectController()
webRequest.controllerName = 'redirect'
@@ -173,6 +268,15 @@ class UrlMappings {
assertEquals "/test/foo?one=two&one=three", response.redirectedUrl
}
+ void testRedirectToControllerWithDuplicateArrayParamsAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def c = new RedirectController()
+ webRequest.controllerName = 'redirect'
+ c.toControllerWithDuplicateArrayParams.call()
+ assertEquals "/test/foo?one=two&one=three&requestDataValueProcessorParamName=paramValue", response.redirectedUrl
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testRedirectToActionWithMapping() {
def c = new NewsSignupController()
c = new NewsSignupController()
@@ -181,6 +285,16 @@ class UrlMappings {
assertEquals "/little-brown-bottle/thankyou", response.redirectedUrl
}
+ void testRedirectToActionWithMappingAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def c = new NewsSignupController()
+ c = new NewsSignupController()
+ webRequest.controllerName = 'newsSignup'
+ c.testNoController.call()
+ assertEquals "/little-brown-bottle/thankyou?requestDataValueProcessorParamName=paramValue", response.redirectedUrl
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testPermanentRedirect() {
def c = new RedirectController()
webRequest.controllerName = 'redirect'
@@ -192,6 +306,20 @@ class UrlMappings {
assertEquals 301, response.status
}
+ void testPermanentRedirectAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def c = new RedirectController()
+ webRequest.controllerName = 'redirect'
+ webRequest.currentRequest.serverPort = 8080
+ c.toActionPermanent.call()
+
+ // location header should be absolute
+ assertEquals "http://localhost:8080/redirect/foo?requestDataValueProcessorParamName=paramValue", response.getHeader(HttpHeaders.LOCATION)
+ assertEquals 301, response.status
+ this.unRegisterRequestDataValueProcessor()
+ }
+
+
}
class TestRedirectListener implements RedirectEventListener {
View
419 grails-test-suite-web/src/test/groovy/org/codehaus/groovy/grails/web/taglib/ApplicationTagLibTests.groovy
@@ -1,6 +1,7 @@
package org.codehaus.groovy.grails.web.taglib
import grails.util.GrailsUtil
+import grails.util.MockRequestDataValueProcessor;
import javax.servlet.http.Cookie
@@ -9,16 +10,36 @@ import org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib
import org.codehaus.groovy.grails.web.pages.GroovyPageBinding
import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes
import org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException
+import org.springframework.web.servlet.support.RequestDataValueProcessor
import org.springframework.mock.web.MockHttpServletResponse
+import org.codehaus.groovy.grails.support.MockApplicationContext
class ApplicationTagLibTests extends AbstractGrailsTagTests {
+ void registerRequestDataValueProcessor() {
+ RequestDataValueProcessor requestDataValueProcessor = new MockRequestDataValueProcessor();
+ MockApplicationContext applicationContext = (MockApplicationContext)ctx;
+ applicationContext.registerMockBean("requestDataValueProcessor",requestDataValueProcessor);
+ }
+ void unRegisterRequestDataValueProcessor() {
+ MockApplicationContext applicationContext = (MockApplicationContext)ctx;
+ applicationContext.registerMockBean("requestDataValueProcessor",null);
+ }
+
void testResourceTagWithPluginAttribute() {
request.contextPath = '/test'
def template = '${resource(file:"images/foo.jpg", plugin:"controllers")}'
assertOutputEquals "/test/plugins/controllers-${GrailsUtil.getGrailsVersion()}/images/foo.jpg", template
}
+ void testResourceTagWithPluginAttributeAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ request.contextPath = '/test'
+ def template = '${resource(file:"images/foo.jpg", plugin:"controllers")}'
+ assertOutputEquals "/test/plugins/controllers-${GrailsUtil.getGrailsVersion()}/images/foo.jpg?requestDataValueProcessorParamName=paramValue", template
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testResourceTagWithImplicitPlugin() {
def template = '${resource(file:"images/foo.jpg")}'
@@ -26,6 +47,16 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals "/plugin/one/images/foo.jpg", template
}
+ void testResourceTagWithImplicitPluginAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+
+ def template = '${resource(file:"images/foo.jpg")}'
+
+ request.setAttribute(GrailsApplicationAttributes.PAGE_SCOPE, new GroovyPageBinding("/plugin/one"))
+ assertOutputEquals "/plugin/one/images/foo.jpg?requestDataValueProcessorParamName=paramValue", template
+ this.unRegisterRequestDataValueProcessor();
+ }
+
void testResourceTagWithContextPathAttribute() {
request.contextPath = '/test'
def template = '${resource(file:"images/foo.jpg", contextPath:"/foo")}'
@@ -35,12 +66,31 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals "/foo/images/foo.jpg", template
}
+ void testResourceTagWithContextPathAttributeAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ request.contextPath = '/test'
+ def template = '${resource(file:"images/foo.jpg", contextPath:"/foo")}'
+ assertOutputEquals "/foo/images/foo.jpg?requestDataValueProcessorParamName=paramValue", template
+
+ request.setAttribute(GrailsApplicationAttributes.PAGE_SCOPE, new GroovyPageBinding("/plugin/one"))
+ assertOutputEquals "/foo/images/foo.jpg?requestDataValueProcessorParamName=paramValue", template
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testResourceTagWithPluginAttributeAndNone() {
request.contextPath = '/test'
def template = '${resource(file:"images/foo.jpg", plugin:"none")}'
assertOutputEquals "/test/images/foo.jpg", template
}
+ void testResourceTagWithPluginAttributeAndNoneAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ request.contextPath = '/test'
+ def template = '${resource(file:"images/foo.jpg", plugin:"none")}'
+ assertOutputEquals "/test/images/foo.jpg?requestDataValueProcessorParamName=paramValue", template
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testResourceTag() {
request.contextPath = '/test'
def template = '${resource(file:"images/foo.jpg")}'
@@ -50,12 +100,32 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals '/test/images/foo.jpg', template
}
+ void testResourceTagAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ request.contextPath = '/test'
+ def template = '${resource(file:"images/foo.jpg")}'
+ assertOutputEquals '/test/images/foo.jpg?requestDataValueProcessorParamName=paramValue', template
+
+ template = '${resource(dir:"images",file:"foo.jpg")}'
+ assertOutputEquals '/test/images/foo.jpg?requestDataValueProcessorParamName=paramValue', template
+ this.unRegisterRequestDataValueProcessor()
+ }
+
+
void testResourceTagDirOnly() {
request.contextPath = '/test'
def template = '${resource(dir:"jquery")}'
assertOutputEquals '/test/jquery', template
}
+ void testResourceTagDirOnlyAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ request.contextPath = '/test'
+ def template = '${resource(dir:"jquery")}'
+ assertOutputEquals '/test/jquery?requestDataValueProcessorParamName=paramValue', template
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testUseJessionIdWithCreateLink() {
def response = new JsessionIdMockHttpServletResponse()
ApplicationTagLib.metaClass.getResponse = {-> response}
@@ -73,6 +143,25 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals "/foo/test", template
}
+ void testUseJessionIdWithCreateLinkAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+
+ def response = new JsessionIdMockHttpServletResponse()
+ ApplicationTagLib.metaClass.getResponse = {-> response}
+ def tagLibBean = appCtx.getBean("org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib")
+ ga.config.grails.views.enable.jsessionid=true
+ tagLibBean.afterPropertiesSet()
+ assertTrue(tagLibBean.@useJsessionId)
+
+ def template = '<g:createLink controller="foo" action="test" />'
+ assertOutputEquals "/foo/test?requestDataValueProcessorParamName=paramValue;jsessionid=test", template
+
+ ga.config.grails.views.enable.jsessionid=false
+ tagLibBean.afterPropertiesSet()
+ assertFalse(tagLibBean.@useJsessionId)
+ assertOutputEquals "/foo/test?requestDataValueProcessorParamName=paramValue", template
+ }
+
void testObtainCookieValue() {
def cookie = new Cookie("foo", "bar")
request.cookies = [cookie] as Cookie[]
@@ -105,6 +194,16 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals('<a href="/foo/action?test=test&amp;test2=test2">test</a>', template)
}
+ void testLinkWithMultipleParametersAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+ def template = '<g:link controller="foo" action="action" params="[test: \'test\', test2: \'test2\']">test</g:link>'
+ assertOutputEquals('<a href="/foo/action?test=test&amp;test2=test2&amp;requestDataValueProcessorParamName=paramValue">test</a>', template)
+ // test caching too
+ assertOutputEquals('<a href="/foo/action?test=test&amp;test2=test2&amp;requestDataValueProcessorParamName=paramValue">test</a>', template)
+ this.unRegisterRequestDataValueProcessor()
+
+ }
+
void testLinkWithMultipleCollectionParameters() {
def template = '<g:link controller="foo" action="action" params="[test: [\'test-a\',\'test-b\'], test2: [\'test2-a\',\'test2-b\'] as String[]]">test</g:link>'
assertOutputEquals('<a href="/foo/action?test=test-a&amp;test=test-b&amp;test2=test2-a&amp;test2=test2-b">test</a>', template)
@@ -112,6 +211,15 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals('<a href="/foo/action?test=test-a&amp;test=test-b&amp;test2=test2-a&amp;test2=test2-b">test</a>', template)
}
+ void testLinkWithMultipleCollectionParametersAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def template = '<g:link controller="foo" action="action" params="[test: [\'test-a\',\'test-b\'], test2: [\'test2-a\',\'test2-b\'] as String[]]">test</g:link>'
+ assertOutputEquals('<a href="/foo/action?test=test-a&amp;test=test-b&amp;test2=test2-a&amp;test2=test2-b&amp;requestDataValueProcessorParamName=paramValue">test</a>', template)
+ // test caching too
+ assertOutputEquals('<a href="/foo/action?test=test-a&amp;test=test-b&amp;test2=test2-a&amp;test2=test2-b&amp;requestDataValueProcessorParamName=paramValue">test</a>', template)
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testLinkWithCollectionParameter() {
def template = '<g:link controller="foo" action="action" params="[test: [\'test-a\']]">test</g:link>'
assertOutputEquals('<a href="/foo/action?test=test-a">test</a>', template)
@@ -119,12 +227,29 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals('<a href="/foo/action?test=test-a">test</a>', template)
}
+ void testLinkWithCollectionParameterAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def template = '<g:link controller="foo" action="action" params="[test: [\'test-a\']]">test</g:link>'
+ assertOutputEquals('<a href="/foo/action?test=test-a&amp;requestDataValueProcessorParamName=paramValue">test</a>', template)
+ // test caching too
+ assertOutputEquals('<a href="/foo/action?test=test-a&amp;requestDataValueProcessorParamName=paramValue">test</a>', template)
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testLinkWithCharCollectionParameter() {
def template = '<g:link controller="foo" action="action" params="[letter: [\'a\' as char]]">test</g:link>'
assertOutputEquals('<a href="/foo/action?letter=a">test</a>', template)
// test caching too
assertOutputEquals('<a href="/foo/action?letter=a">test</a>', template)
}
+ void testLinkWithCharCollectionParameterAndRequestDataValueProcessor() {
+ registerRequestDataValueProcessor();
+ def template = '<g:link controller="foo" action="action" params="[letter: [\'a\' as char]]">test</g:link>'
+ assertOutputEquals('<a href="/foo/action?letter=a&amp;requestDataValueProcessorParamName=paramValue">test</a>', template)
+ // test caching too
+ assertOutputEquals('<a href="/foo/action?letter=a&amp;requestDataValueProcessorParamName=paramValue">test</a>', template)
+ this.unRegisterRequestDataValueProcessor()
+ }
void testCreateLinkWithCollectionParameter() {
def template = '<% l=\'a\' %>${g.createLink(controller:"foo", action:"action", params:[letter:[l]])} ${g.createLink(controller:"foo", action:"action", params:[letter:[l]])}'
@@ -133,16 +258,39 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals('/foo/action?letter=a /foo/action?letter=a', template)
}
+ void testCreateLinkWithCollectionParameterAndRequestDataValueProcessor() {
+ registerRequestDataValueProcessor();
+ def template = '<% l=\'a\' %>${g.createLink(controller:"foo", action:"action", params:[letter:[l]])} ${g.createLink(controller:"foo", action:"action", params:[letter:[l]])}'
+ assertOutputEquals('/foo/action?letter=a&requestDataValueProcessorParamName=paramValue /foo/action?letter=a&requestDataValueProcessorParamName=paramValue', template)
+ // test caching too
+ assertOutputEquals('/foo/action?letter=a&requestDataValueProcessorParamName=paramValue /foo/action?letter=a&requestDataValueProcessorParamName=paramValue', template)
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testLikeWithElementId() {
def template = '<g:link elementId="myId" controller="foo" action="list">bar</g:link>'
assertOutputEquals('<a href="/foo/list" id="myId">bar</a>', template)
}
+ void testLikeWithElementIdAndRequestDataValueProcessor() {
+ registerRequestDataValueProcessor();
+ def template = '<g:link elementId="myId" controller="foo" action="list">bar</g:link>'
+ assertOutputEquals('<a href="/foo/list?requestDataValueProcessorParamName=paramValue" id="myId">bar</a>', template)
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testLinkWithMultipleParametersAndElementId() {
def template = '<g:link elementId="myid" controller="foo" action="action" params="[test: \'test\', test2: \'test2\']">test</g:link>'
assertOutputEquals('<a href="/foo/action?test=test&amp;test2=test2" id="myid">test</a>', template)
}
+ void testLinkWithMultipleParametersAndElementIdAndRequestDataValueProcessor() {
+ registerRequestDataValueProcessor();
+ def template = '<g:link elementId="myid" controller="foo" action="action" params="[test: \'test\', test2: \'test2\']">test</g:link>'
+ assertOutputEquals('<a href="/foo/action?test=test&amp;test2=test2&amp;requestDataValueProcessorParamName=paramValue" id="myid">test</a>', template)
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testLinkWithFragment() {
def template = '<g:link controller="foo" action="bar" fragment="test">link</g:link>'
profile("link rendering") {
@@ -150,6 +298,18 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
}
}
+ void testLinkWithFragmentAndRequestDataValueProcessor() {
+ registerRequestDataValueProcessor();
+
+ def template = '<g:link controller="foo" action="bar" fragment="test">link</g:link>'
+ profile("link rendering") {
+ assertOutputEquals('<a href="/foo/bar?requestDataValueProcessorParamName=paramValue#test">link</a>', template)
+ }
+ this.unRegisterRequestDataValueProcessor()
+ }
+
+
+
void testCreateLinkWithFlowExecutionKeyAndEvent() {
request.flowExecutionKey = '12345'
@@ -157,6 +317,17 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals('/foo/bar?execution=12345&_eventId=boo', template)
}
+ void testCreateLinkWithFlowExecutionKeyAndEventAndRequestDataValueProcessor() {
+ registerRequestDataValueProcessor();
+
+ request.flowExecutionKey = '12345'
+
+ def template = '<g:createLink controller="foo" action="bar" event="boo" />'
+ assertOutputEquals('/foo/bar?execution=12345&_eventId=boo&requestDataValueProcessorParamName=paramValue', template)
+
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testLinkWithFlowExecutionKeyAndEvent() {
request.flowExecutionKey = '12345'
@@ -164,6 +335,16 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals('<a href="/foo/bar?execution=12345&amp;_eventId=boo">link</a>', template)
}
+ void testLinkWithFlowExecutionKeyAndEventAndRequestDataValueProcessor() {
+ registerRequestDataValueProcessor();
+
+ request.flowExecutionKey = '12345'
+
+ def template = '<g:link controller="foo" action="bar" event="boo" >link</g:link>'
+ assertOutputEquals('<a href="/foo/bar?execution=12345&amp;_eventId=boo&amp;requestDataValueProcessorParamName=paramValue">link</a>', template)
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testSetTag() {
def template = '<g:set var="one" value="two" />one: ${one}'
assertOutputEquals('one: two', template)
@@ -218,16 +399,42 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals "/images/foo.jpg", template
}
+ void testCreateLinkToWithDirAndLeadingSlashAndRequestDataValueProcessor() {
+ registerRequestDataValueProcessor();
+
+ request.contextPath = "/"
+ def template = '<g:createLinkTo dir="/images" file="foo.jpg" />'
+ assertOutputEquals "/images/foo.jpg?requestDataValueProcessorParamName=paramValue", template
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testCreateLinkToWithDirAndLeadingNoLeadingSlash() {
def template = '<g:createLinkTo dir="images" file="foo.jpg" />'
assertOutputEquals "/images/foo.jpg", template
}
+ void testCreateLinkToWithDirAndLeadingNoLeadingSlashAndRequestDataValueProcessor() {
+ registerRequestDataValueProcessor();
+
+ def template = '<g:createLinkTo dir="images" file="foo.jpg" />'
+ assertOutputEquals "/images/foo.jpg?requestDataValueProcessorParamName=paramValue", template
+ this.unRegisterRequestDataValueProcessor()
+ }
+
+
void testCreateLinkToWithFileAndLeadingSlash() {
def template = '<g:createLinkTo dir="/images" file="/foo.jpg" />'
assertOutputEquals "/images/foo.jpg", template
}
+ void testCreateLinkToWithFileAndLeadingSlashAndRequestDataValueProcessor() {
+ registerRequestDataValueProcessor();
+
+ def template = '<g:createLinkTo dir="/images" file="/foo.jpg" />'
+ assertOutputEquals "/images/foo.jpg?requestDataValueProcessorParamName=paramValue", template
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testCreateLinkTo() {
def template = '<g:resource dir="test" />'
@@ -240,39 +447,99 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals '', template
}
+ void testCreateLinkToWithRequestDataValueProcessor() {
+ registerRequestDataValueProcessor();
+
+ def template = '<g:resource dir="test" />'
+ assertOutputEquals '/test?requestDataValueProcessorParamName=paramValue', template
+
+ template = '<g:resource dir="test" file="file" />'
+ assertOutputEquals '/test/file?requestDataValueProcessorParamName=paramValue', template
+
+ template = '<g:resource dir="" />'
+ assertOutputEquals '', template
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testCreateLinkToFilesInRoot() {
def template = '<g:resource dir="/" file="test.gsp" />'
assertOutputEquals '/test.gsp', template
}
+ void testCreateLinkToFilesInRootWithRequestDataValueProcessor() {
+ registerRequestDataValueProcessor();
+
+ def template = '<g:resource dir="/" file="test.gsp" />'
+ assertOutputEquals '/test.gsp?requestDataValueProcessorParamName=paramValue', template
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testResourceFilesInRootWithContext() {
def template = '<g:resource dir="/" file="test.gsp" />'
request.contextPath = "/foo"
assertOutputEquals '/foo/test.gsp', template
}
+ void testResourceFilesInRootWithContextAndRequestDataValueProcessor() {
+ registerRequestDataValueProcessor();
+
+ def template = '<g:resource dir="/" file="test.gsp" />'
+ request.contextPath = "/foo"
+ assertOutputEquals '/foo/test.gsp?requestDataValueProcessorParamName=paramValue', template
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testCreateLinkWithZeroId() {
def template = '<g:createLink action="testAction" controller="testController" id="${id}" />'
assertOutputEquals '/testController/testAction/0', template, [id:0]
}
+
+ void testCreateLinkWithZeroIdAndRequestDataValueProcessor() {
+ registerRequestDataValueProcessor();
+
+ def template = '<g:createLink action="testAction" controller="testController" id="${id}" />'
+ assertOutputEquals '/testController/testAction/0?requestDataValueProcessorParamName=paramValue', template, [id:0]
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testCreateLinkURLEncoding() {
def template = '<g:createLink action="testAction" controller="testController" params="[name:\'Marc Palmer\']" />'
assertOutputEquals '/testController/testAction?name=Marc+Palmer', template
}
+ void testCreateLinkURLEncodingWithRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+ def template = '<g:createLink action="testAction" controller="testController" params="[name:\'Marc Palmer\']" />'
+ assertOutputEquals '/testController/testAction?name=Marc+Palmer&requestDataValueProcessorParamName=paramValue', template
+ this.unRegisterRequestDataValueProcessor();
+ }
+
void testCreateLinkURLEncodingWithHTMLChars() {
def template = '<g:createLink action="testAction" controller="testController" params="[email:email]" />'
assertOutputEquals '/testController/testAction?email=%3Cmarc%40anyware.co.uk%3E', template, [email:'<marc@anyware.co.uk>']
}
+ void testCreateLinkURLEncodingWithHTMLCharsAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+ def template = '<g:createLink action="testAction" controller="testController" params="[email:email]" />'
+ assertOutputEquals '/testController/testAction?email=%3Cmarc%40anyware.co.uk%3E&requestDataValueProcessorParamName=paramValue', template, [email:'<marc@anyware.co.uk>']
+ this.unRegisterRequestDataValueProcessor();
+ }
+
void testCreateLinkWithBase() {
def template = '<g:createLink base="http://www128.myhost.com:3495" action="testAction" controller="testController" />'
assertOutputEquals 'http://www128.myhost.com:3495/testController/testAction', template
}
- void testCreateLinkWithUseJSessionIdAndContextPapth() {
+ void testCreateLinkWithBaseAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+ def template = '<g:createLink base="http://www128.myhost.com:3495" action="testAction" controller="testController" />'
+ assertOutputEquals 'http://www128.myhost.com:3495/testController/testAction?requestDataValueProcessorParamName=paramValue', template
+ this.unRegisterRequestDataValueProcessor();
+ }
+ void testCreateLinkWithUseJSessionIdAndContextPapth() {
request.contextPath = "/foo"
def taglib = appCtx.getBean(ApplicationTagLib.name)
@@ -281,12 +548,33 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals '/foo/testController/testAction', template
}
+ void testCreateLinkWithUseJSessionIdAndContextPapthAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+ request.contextPath = "/foo"
+ def taglib = appCtx.getBean(ApplicationTagLib.name)
+
+ taglib.useJsessionId = true
+ def template = '<g:createLink action="testAction" controller="testController" />'
+ assertOutputEquals '/foo/testController/testAction?requestDataValueProcessorParamName=paramValue', template
+ this.unRegisterRequestDataValueProcessor();
+ }
+
void testCreateLinkWithContextPath() {
request.contextPath = "/foo"
def template = '<g:createLink action="testAction" controller="testController" />'
assertOutputEquals '/foo/testController/testAction', template
}
+ void testCreateLinkWithContextPathAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+
+ request.contextPath = "/foo"
+ def template = '<g:createLink action="testAction" controller="testController" />'
+ assertOutputEquals '/foo/testController/testAction?requestDataValueProcessorParamName=paramValue', template
+ this.unRegisterRequestDataValueProcessor();
+
+ }
+
void testAbsoluteWithContextPath() {
request.contextPath = "/foo"
def template = '<g:createLink action="testAction" controller="testController" absolute="true" />'
@@ -302,6 +590,25 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals 'http://www.mysite.com/testController/testAction', template
}
+ void testAbsoluteWithContextPathAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+
+ request.contextPath = "/foo"
+ def template = '<g:createLink action="testAction" controller="testController" absolute="true" />'
+
+ def linkGenerator = appCtx.getBean("grailsLinkGenerator")
+ linkGenerator.configuredServerBaseURL="http://www.mysite.com"
+ assertOutputEquals 'http://www.mysite.com/testController/testAction?requestDataValueProcessorParamName=paramValue', template
+
+ template = '<g:createLink action="testAction" controller="testController" absolute="${true}" />'
+
+ linkGenerator = appCtx.getBean("grailsLinkGenerator")
+ linkGenerator.configuredServerBaseURL="http://www.mysite.com"
+ assertOutputEquals 'http://www.mysite.com/testController/testAction?requestDataValueProcessorParamName=paramValue', template
+
+ this.unRegisterRequestDataValueProcessor();
+ }
+
void testAbsoluteFalseWithContextPath() {
request.contextPath = "/foo"
def template = '<g:createLink action="testAction" controller="testController" absolute="false" />'
@@ -317,6 +624,25 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals '/foo/testController/testAction', template
}
+ void testAbsoluteFalseWithContextPathAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+
+ request.contextPath = "/foo"
+ def template = '<g:createLink action="testAction" controller="testController" absolute="false" />'
+
+ def linkGenerator = appCtx.getBean("grailsLinkGenerator")
+ linkGenerator.configuredServerBaseURL="http://www.mysite.com"
+ assertOutputEquals '/foo/testController/testAction?requestDataValueProcessorParamName=paramValue', template
+
+ template = '<g:createLink action="testAction" controller="testController" absolute="${false}" />'
+
+ linkGenerator = appCtx.getBean("grailsLinkGenerator")
+ linkGenerator.configuredServerBaseURL="http://www.mysite.com"
+ assertOutputEquals '/foo/testController/testAction?requestDataValueProcessorParamName=paramValue', template
+
+ this.unRegisterRequestDataValueProcessor();
+ }
+
void testAbsoluteWithContextPathAndNullConfig() {
ConfigurationHolder.config = null
request.contextPath = "/foo"
@@ -328,6 +654,21 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals 'http://localhost:8080/foo/testController/testAction', template
}
+ void testAbsoluteWithContextPathAndNullConfigAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+
+ ConfigurationHolder.config = null
+ request.contextPath = "/foo"
+ request.serverPort = 8080
+ def template = '<g:createLink action="testAction" controller="testController" absolute="true" />'
+ assertOutputEquals 'http://localhost:8080/foo/testController/testAction?requestDataValueProcessorParamName=paramValue', template
+
+ template = '<g:createLink action="testAction" controller="testController" absolute="${true}" />'
+ assertOutputEquals 'http://localhost:8080/foo/testController/testAction?requestDataValueProcessorParamName=paramValue', template
+
+ this.unRegisterRequestDataValueProcessor();
+ }
+
void testAbsoluteFalseWithContextPathAndNullConfig() {
ConfigurationHolder.config = null
request.contextPath = "/foo"
@@ -339,6 +680,21 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals '/foo/testController/testAction', template
}
+ void testAbsoluteFalseWithContextPathAndNullConfigAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+
+ ConfigurationHolder.config = null
+ request.contextPath = "/foo"
+ request.serverPort = 8080
+ def template = '<g:createLink action="testAction" controller="testController" absolute="false" />'
+ assertOutputEquals '/foo/testController/testAction?requestDataValueProcessorParamName=paramValue', template
+
+ template = '<g:createLink action="testAction" controller="testController" absolute="${false}" />'
+ assertOutputEquals '/foo/testController/testAction?requestDataValueProcessorParamName=paramValue', template
+
+ this.unRegisterRequestDataValueProcessor();
+ }
+
/**
* Tests regression of <a href="http://jira.codehaus.org/browse/GRAILS-3368">GRAILS-3368</a>.
* The context path should not be included in the generated link
@@ -349,6 +705,13 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals '/testController/testAction', template
}
+ void testCreateLinkWithNoContextPathAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+ def template = '<g:createLink base="" action="testAction" controller="testController" />'
+ assertOutputEquals '/testController/testAction?requestDataValueProcessorParamName=paramValue', template
+ this.unRegisterRequestDataValueProcessor();
+ }
+
void testCreateLinkWithAbsolute() {
def template = '<g:createLink absolute="true" action="testAction" controller="testController" />'
request.serverPort = 8080
@@ -359,6 +722,19 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals 'http://localhost:8080/testController/testAction', template
}
+ void testCreateLinkWithAbsoluteAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+
+ def template = '<g:createLink absolute="true" action="testAction" controller="testController" />'
+ request.serverPort = 8080
+ assertOutputEquals 'http://localhost:8080/testController/testAction?requestDataValueProcessorParamName=paramValue', template
+
+ template = '<g:createLink absolute="${true}" action="testAction" controller="testController" />'
+ request.serverPort = 8080
+ assertOutputEquals 'http://localhost:8080/testController/testAction?requestDataValueProcessorParamName=paramValue', template
+ this.unRegisterRequestDataValueProcessor();
+ }
+
void testCreateLinkWithAbsoluteFalse() {
def template = '<g:createLink absolute="false" action="testAction" controller="testController" />'
request.serverPort = 8080
@@ -369,6 +745,19 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals '/testController/testAction', template
}
+ void testCreateLinkWithAbsoluteFalseAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+
+ def template = '<g:createLink absolute="false" action="testAction" controller="testController" />'
+ request.serverPort = 8080
+ assertOutputEquals '/testController/testAction?requestDataValueProcessorParamName=paramValue', template
+
+ template = '<g:createLink absolute="${false}" action="testAction" controller="testController" />'
+ request.serverPort = 8080
+ assertOutputEquals '/testController/testAction?requestDataValueProcessorParamName=paramValue', template
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testJoinStrings() {
def template = /<g:join in="['Bruce', 'Adrian', 'Dave', 'Nicko', 'Steve']" delimiter="_"\/>/
assertOutputEquals 'Bruce_Adrian_Dave_Nicko_Steve', template
@@ -405,6 +794,16 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals '<img src="/images/logo.png" width="100" height="200" />', template
}
+ void testImgWithRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def template = '<g:img dir="images" file="logo.png" width="100" height="200"/>'
+ assertOutputEquals '<img src="/images/logo.png?requestDataValueProcessorParamName=paramValue" width="100" height="200" />', template
+
+ template = '<g:img file="logo.png" width="100" height="200"/>'
+ assertOutputEquals '<img src="/images/logo.png?requestDataValueProcessorParamName=paramValue" width="100" height="200" />', template
+ this.unRegisterRequestDataValueProcessor();
+ }
+
void testExternal() {
def template = '<g:external uri="/js/main.js"/>'
assertOutputEquals '<script src="/js/main.js" type="text/javascript"></script>\r\n', template
@@ -418,4 +817,22 @@ class ApplicationTagLibTests extends AbstractGrailsTagTests {
template = '<g:external uri="/images/icons/iphone-icon.png" type="appleicon"/>'
assertOutputEquals '<link href="/images/icons/iphone-icon.png" rel="apple-touch-icon"/>\r\n', template
}
+
+ void testExternalWithRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+
+ def template = '<g:external uri="/js/main.js"/>'
+ assertOutputEquals '<script src="/js/main.js?requestDataValueProcessorParamName=paramValue" type="text/javascript"></script>\r\n', template
+
+ template = '<g:external uri="/css/style.css"/>'
+ assertOutputEquals '<link href="/css/style.css?requestDataValueProcessorParamName=paramValue" type="text/css" rel="stylesheet" media="screen, projector"/>\r\n', template
+
+ template = '<g:external uri="/css/print.css" media="print"/>'
+ assertOutputEquals '<link href="/css/print.css?requestDataValueProcessorParamName=paramValue" type="text/css" rel="stylesheet" media="print"/>\r\n', template
+
+ template = '<g:external uri="/images/icons/iphone-icon.png" type="appleicon"/>'
+ assertOutputEquals '<link href="/images/icons/iphone-icon.png?requestDataValueProcessorParamName=paramValue" rel="apple-touch-icon"/>\r\n', template
+
+ this.unRegisterRequestDataValueProcessor()
+ }
}
View
133 grails-test-suite-web/src/test/groovy/org/codehaus/groovy/grails/web/taglib/FormTagLibTests.groovy
@@ -1,6 +1,10 @@
package org.codehaus.groovy.grails.web.taglib
+import grails.util.MockRequestDataValueProcessor
+
import org.codehaus.groovy.grails.plugins.web.taglib.FormTagLib
+import org.codehaus.groovy.grails.support.MockApplicationContext
+import org.springframework.web.servlet.support.RequestDataValueProcessor
/**
* Tests for the FormTagLib.groovy file which contains tags to help with the l
@@ -10,22 +14,53 @@ import org.codehaus.groovy.grails.plugins.web.taglib.FormTagLib
*/
class FormTagLibTests extends AbstractGrailsTagTests {
+ void registerRequestDataValueProcessor() {
+ RequestDataValueProcessor requestDataValueProcessor = new MockRequestDataValueProcessor();
+ MockApplicationContext applicationContext = (MockApplicationContext)ctx;
+ applicationContext.registerMockBean("requestDataValueProcessor",requestDataValueProcessor);
+ }
+ void unRegisterRequestDataValueProcessor() {
+ MockApplicationContext applicationContext = (MockApplicationContext)ctx;
+ applicationContext.registerMockBean("requestDataValueProcessor",null);
+ }
+
void testFormTagWithAlternativeMethod() {
def template = '<g:form url="/foo/bar" method="delete"></g:form>'
assertOutputEquals('<form action="/foo/bar" method="post" ><input type="hidden" name="_method" value="DELETE" id="_method" /></form>', template)
}
+ void testFormTagWithAlternativeMethodAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def template = '<g:form url="/foo/bar" method="delete"></g:form>'
+ assertOutputEquals('<form action="/foo/bar" method="post" ><input type="hidden" name="_method" value="DELETE_PROCESSED_" id="_method" /><input type="hidden" name="requestDataValueProcessorHiddenName" value="hiddenValue" />\n</form>', template)
+ this.unRegisterRequestDataValueProcessor()
+ }
+
// test for GRAILS-3865
void testHiddenFieldWithZeroValue() {
def template = '<g:hiddenField name="index" value="${0}" />'
assertOutputContains 'value="0"', template
}
+ void testHiddenFieldWithZeroValueAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+ def template = '<g:hiddenField name="index" value="${0}" />'
+ assertOutputContains 'value="0_PROCESSED_"', template
+ this.unRegisterRequestDataValueProcessor();
+ }
void testFormTagWithStringURL() {
def template = '<g:form url="/foo/bar"></g:form>'
assertOutputEquals('<form action="/foo/bar" method="post" ></form>', template)
}
+ void testFormTagWithStringURLAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+
+ def template = '<g:form url="/foo/bar"></g:form>'
+ assertOutputEquals('<form action="/foo/bar" method="post" ><input type="hidden" name="requestDataValueProcessorHiddenName" value="hiddenValue" />\n</form>', template)
+ this.unRegisterRequestDataValueProcessor();
+ }
+
void testFormTagWithTrueUseToken() {
def template = '<g:form url="/foo/bar" useToken="true"></g:form>'
assertOutputContains('<form action="/foo/bar" method="post" >', template)
@@ -38,6 +73,26 @@ class FormTagLibTests extends AbstractGrailsTagTests {
assertOutputContains('<input type="hidden" name="org.codehaus.groovy.grails.SYNCHRONIZER_URI" value="', template)
}
+ void testFormTagWithTrueUseTokenAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor();
+
+ def template = '<g:form url="/foo/bar" useToken="true"></g:form>'
+ assertOutputContains('<form action="/foo/bar" method="post" >', template)
+ assertOutputContains('<input type="hidden" name="org.codehaus.groovy.grails.SYNCHRONIZER_TOKEN" value="', template)
+ assertOutputContains('<input type="hidden" name="org.codehaus.groovy.grails.SYNCHRONIZER_URI" value="', template)
+ assertOutputContains('<input type="hidden" name="requestDataValueProcessorHiddenName" value="hiddenValue" />',template)
+ assertOutputContains('_PROCESSED_',template)
+
+ template = '<g:form url="/foo/bar" useToken="${2 * 3 == 6}"></g:form>'
+ assertOutputContains('<form action="/foo/bar" method="post" >', template)
+ assertOutputContains('<input type="hidden" name="org.codehaus.groovy.grails.SYNCHRONIZER_TOKEN" value="', template)
+ assertOutputContains('<input type="hidden" name="org.codehaus.groovy.grails.SYNCHRONIZER_URI" value="', template)
+ assertOutputContains('<input type="hidden" name="requestDataValueProcessorHiddenName" value="hiddenValue" />',template)
+ assertOutputContains('<input type="hidden" name="requestDataValueProcessorHiddenName" value="hiddenValue" />',template)
+ assertOutputContains('_PROCESSED_',template)
+ this.unRegisterRequestDataValueProcessor();
+ }
+
void testFormTagWithNonTrueUseToken() {
def template = '<g:form url="/foo/bar" useToken="false"></g:form>'
assertOutputContains('<form action="/foo/bar" method="post" >', template)
@@ -63,9 +118,26 @@ class FormTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals('<input type="text" name="testField" value="foo &gt; &quot; &amp; &lt; &#39;" id="testField" />', template, [value:/foo > " & < '/])
}
+ void testTextFieldTagWithRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def template = '<g:textField name="testField" value="1" />'
+ assertOutputEquals('<input type="text" name="testField" value="1_PROCESSED_" id="testField" />', template)
+
+ template = '<g:textField name="testField" value="${value}" />'
+ assertOutputEquals('<input type="text" name="testField" value="foo &gt; &quot; &amp; &lt; &#39;_PROCESSED_" id="testField" />', template, [value:/foo > " & < '/])
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testTextAreaWithBody() {
def template = '<g:textArea name="test">This is content</g:textArea>'
- assertOutputEquals '<textarea name="test" id="test" >This is content</textarea>', template
+ assertOutputEquals '<textarea name="test" id="test" >This is content</textarea>', template
+ }
+
+ void testTextAreaWithBodyAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def template = '<g:textArea name="test">This is content</g:textArea>'
+ assertOutputEquals '<textarea name="test" id="test" >This is content_PROCESSED_</textarea>', template
+ this.unRegisterRequestDataValueProcessor()
}
void testPasswordTag() {
@@ -73,6 +145,13 @@ class FormTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals('<input type="password" name="myPassword" value="foo" id="myPassword" />', template)
}
+ void testPasswordTagWithRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ def template = '<g:passwordField name="myPassword" value="foo"/>'
+ assertOutputEquals('<input type="password" name="myPassword" value="foo_PROCESSED_" id="myPassword" />', template)
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testFormWithURL() {
final StringWriter sw = new StringWriter()
@@ -84,6 +163,19 @@ class FormTagLibTests extends AbstractGrailsTagTests {
}
}
+ void testFormWithURLAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ final StringWriter sw = new StringWriter()
+
+ withTag("form", new PrintWriter(sw)) { tag ->
+ // use sorted map to be able to predict the order in which tag attributes are generated
+ def attributes = new TreeMap([url:[controller:'con', action:'action'], id:'formElementId'])
+ tag.call(attributes, { "" })
+ assertEquals '<form action="/con/action" method="post" id="formElementId" ><input type="hidden" name="requestDataValueProcessorHiddenName" value="hiddenValue" />\n</form>', sw.toString().trim()
+ }
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testActionSubmitWithoutAction() {
final StringWriter sw = new StringWriter()
@@ -95,6 +187,19 @@ class FormTagLibTests extends AbstractGrailsTagTests {
}
}
+ void testActionSubmitWithoutActionAndWithRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ final StringWriter sw = new StringWriter()
+
+ withTag("actionSubmit", new PrintWriter(sw)) { tag ->
+ // use sorted map to be able to predict the order in which tag attributes are generated
+ def attributes = new TreeMap([value:'Edit'])
+ tag.call(attributes)
+ assertEquals '<input type="submit" name="_action_Edit" value="Edit_PROCESSED_" />', sw.toString() // NO TRIM, TEST WS!
+ }
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testActionSubmitWithAction() {
final StringWriter sw = new StringWriter()
@@ -106,6 +211,19 @@ class FormTagLibTests extends AbstractGrailsTagTests {
}
}
+ void testActionSubmitWithActionAndRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ final StringWriter sw = new StringWriter()
+
+ withTag("actionSubmit", new PrintWriter(sw)) { tag ->
+ // use sorted map to be able to predict the order in which tag attributes are generated
+ def attributes = new TreeMap([action:'Edit', value:'Some label for editing'])
+ tag.call(attributes)
+ assertEquals '<input type="submit" name="_action_Edit" value="Some label for editing_PROCESSED_" />', sw.toString() // NO TRIM, TEST WS!
+ }
+ this.unRegisterRequestDataValueProcessor()
+ }
+
/**
* GRAILS-454 - Make sure that the 'name' attribute is ignored.
*/
@@ -142,6 +260,19 @@ class FormTagLibTests extends AbstractGrailsTagTests {
}
}
+ void testActionSubmitImageWithoutActionAndWithRequestDataValueProcessor() {
+ this.registerRequestDataValueProcessor()
+ final StringWriter sw = new StringWriter()
+
+ withTag("actionSubmitImage", new PrintWriter(sw)) { tag ->
+ // use sorted map to be able to predict the order in which tag attributes are generated
+ def attributes = new TreeMap([src:'edit.gif', value:'Edit'])
+ tag.call(attributes)
+ assertEquals '<input type="image" name="_action_Edit" value="Edit_PROCESSED_" src="edit.gif?requestDataValueProcessorParamName=paramValue" />', sw.toString() // NO TRIM, TEST WS!
+ }
+ this.unRegisterRequestDataValueProcessor()
+ }
+
void testActionSubmitImageWithAction() {
final StringWriter sw = new StringWriter()
Please sign in to comment.
Something went wrong with that request. Please try again.