2 * Tests for the FormatTagLib.
4 * @author Graeme Rocher
7 * Created: Jul 25, 2007
12 package org
.codehaus
.groovy
.grails
.web
.taglib
14 class FormatTagLibTests
extends AbstractGrailsTagTests
{
16 void testFormatDate() {
17 def calender
= new GregorianCalendar(1980,1,3)
18 def template
= '<g:formatDate format="yyyy-MM-dd" date="${date}"/>'
19 assertOutputEquals("1980-02-03", template
, [date
:calender
.getTime()])
22 void testFormatDateNullDate() {
23 def template
= '<g:formatDate format="yyyy-MM-dd" date="${date}"/>'
24 assertOutputEquals("", template
, [date
:null])
27 void testFormatDateCurrentDate() {
28 def template
= '<g:formatDate format="yyyy-MM-dd"/>'
29 def output
= applyTemplate(template
)
30 assertTrue(output
==~
/\d{4}-\d{2}-\d{2}/)
33 void testFormatNumber() {
34 def template
= '<g:formatNumber number="${myNumber}" format="\\$###,##0"/>'
35 assertOutputEquals('$10', template
, [myNumber
:10])
38 void testFormatNumberNullNumber() {
39 def template
= '<g:formatNumber number="${myNumber}"/>'
40 assertOutputEquals("", template
, [myNumber
:null])
43 void testFormatNumberNoNumber() {
46 applyTemplate('<g:formatNumber/>')
47 fail('Expecting a GrailsTagException')
49 catch(org
.codehaus
.groovy
.grails
.web
.taglib
.exceptions
.GrailsTagException e
)
55 void testFormatDateFromBundle() {
56 def calender
= new GregorianCalendar(1980,1,3)
57 def template
= '<g:formatDate formatName="format.date" date="${date}"/>'
58 messageSource
.addMessage("format.date", request
.locale
, "yyyy-MM-dd")
60 assertOutputEquals("1980-02-03", template
, [date
:calender
.getTime()])
63 void testFormatNumberFromBundle() {
64 def template
= '<g:formatNumber number="${myNumber}" formatName="format.number" />'
65 messageSource
.addMessage("format.number", request
.locale
, '\$###,##0')
66 assertOutputEquals('$10', template
, [myNumber
:10])
70 def template
= '<g:encodeAs codec="HTML">Coheed & Cambria</g:encodeAs>'
72 assertOutputEquals('Coheed & Cambria', template
, [:])