Skip to content

Commit

Permalink
Merge branch '2.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Brown committed Sep 12, 2012
2 parents 6e5a465 + 45450f4 commit 22efdbc
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,12 @@ class FormTagLib {
void outputAttributes(attrs, writer, boolean useNameAsIdIfIdDoesNotExist = false) {
attrs.remove('tagName') // Just in case one is left
attrs.each { k, v ->
writer << k
writer << '="'
writer << v.encodeAsHTML()
writer << '" '
if(v != null) {
writer << k
writer << '="'
writer << v.encodeAsHTML()
writer << '" '
}
}
if (useNameAsIdIfIdDoesNotExist) {
outputNameAsIdIfIdDoesNotExist(attrs, writer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,12 @@ abstract class AbstractGrailsTagTests extends GroovyTestCase {

try {
request.setAttribute(RequestConstants.PAGE, page)
request.setAttribute(GrailsPageFilter.GSP_SITEMESH_PAGE, new GSPSitemeshPage())
return applyTemplate(layout, params,null, "/layouts/test_"+System.currentTimeMillis())
}
finally {
request.removeAttribute(RequestConstants.PAGE)
request.removeAttribute(GrailsPageFilter.GSP_SITEMESH_PAGE)
}
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ package org.codehaus.groovy.grails.web.sitemesh

import org.codehaus.groovy.grails.support.MockStringResourceLoader
import org.codehaus.groovy.grails.web.taglib.AbstractGrailsTagTests
import org.springframework.mock.web.MockServletConfig

import com.opensymphony.module.sitemesh.Config
import com.opensymphony.module.sitemesh.Decorator
import com.opensymphony.module.sitemesh.DecoratorMapper
import com.opensymphony.module.sitemesh.factory.BaseFactory

/**
* Tests the sitemesh capturing and rendering tags end-to-end
Expand Down Expand Up @@ -77,6 +83,71 @@ class FullSitemeshLifeCycleTests extends AbstractGrailsTagTests {
''', result
}

static class DummySiteMeshFactory extends BaseFactory {
public DummySiteMeshFactory(Config config) {
super(config)
}

@Override
public void refresh() {
}
}

def configureSitemesh() {
def mockServletConfig = new MockServletConfig()
def siteMeshConfig = new Config(mockServletConfig)
def siteMeshFactory = new DummySiteMeshFactory(siteMeshConfig)
def decorator = {name -> [getPage: {-> "/layout/${name}.gsp".toString()}] as Decorator }
siteMeshFactory.decoratorMapper = [getNamedDecorator: {request, name -> decorator(name)}] as DecoratorMapper
FactoryHolder.factory = siteMeshFactory
}

void testMultipleLevelsOfLayouts() {
def resourceLoader = new MockStringResourceLoader()
resourceLoader.registerMockResource('/layout/dialog.gsp', '''<html>
<head><g:layoutHead /><title>Dialog - <g:layoutTitle /></title></head>
<body onload="${g.pageProperty(name:'body.onload')}"><div id="dialog"><g:layoutBody /></div></body>
</html>''')
resourceLoader.registerMockResource('/layout/base.gsp', '''<html>
<head><g:layoutHead /><title>Base - <g:layoutTitle /></title></head>
<body onload="${g.pageProperty(name:'body.onload')}"><div id="base"><g:layoutBody /></div></body>
</html>''')
appCtx.groovyPageLocator.addResourceLoader resourceLoader

configureSitemesh()

def template = '''
<g:applyLayout name="base"><g:applyLayout name="dialog">
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>This is the title</title></head>
<body onload="test();">body text</body>
</html>
</g:applyLayout></g:applyLayout>
'''
request.setAttribute(GrailsPageFilter.GSP_SITEMESH_PAGE, new GSPSitemeshPage())
assertOutputEquals '''
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Base - Dialog - This is the title</title></head>
<body onload="test();"><div id="base"><div id="dialog">body text</div></div></body>
</html>
''', template

def layout = '''
<html>
<head><title>Decorated <g:layoutTitle default="defaultTitle"/></title><g:layoutHead /></head>
<body><h1>Hello</h1><g:layoutBody /></body>
</html>
'''
def result = applyLayout(layout, template)

assertEquals '''
<html>
<head><title>Decorated Base - Dialog - This is the title</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
<body><h1>Hello</h1><div id="base"><div id="dialog">body text</div></div></body>
</html>
''', result
}

void testParameters() {
def template = '''
<html>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,20 @@ class FormTagLib3Tests extends AbstractGrailsTagTests {
assertEquals 'Tag [select] is missing required attribute [name]', message
}
}

void testSelectTagWithNullAttribute() {
final StringWriter sw = new StringWriter()
final PrintWriter pw = new PrintWriter(sw)

withTag("select", pw) { tag ->
assertNotNull tag
tag([name: 'mySelectTag', from: [], errors: null])
}

println sw.toString()

assertTrue sw.toString().startsWith('<select name="mySelectTag" id="mySelectTag" >')
}

void testDatePickerWithYearsAndRelativeYearsAttribute() {
final StringWriter sw = new StringWriter()
Expand Down

0 comments on commit 22efdbc

Please sign in to comment.