Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed #1385

Thanks to Thomas Rotter -> new argument for renderView(),renderExternalView(), event.setView() -> cacheProvider so you can override the default 'template' cache provider and choose your own.
  • Loading branch information...
commit 054d416950ca578d56973ecd6de4b823179ea2eb 1 parent 84ba479
@lmajano lmajano authored
View
57 system/plugins/Renderer.cfc
@@ -73,26 +73,28 @@ Description :
<cffunction name="renderView" access="Public" hint="Renders the current view." output="false" returntype="Any">
<!--- ************************************************************* --->
<cfargument name="view" required="false" type="any" default="" hint="If not passed in, the value in the currentView in the current RequestContext will be used">
- <cfargument name="cache" required="false" type="any" default="false" hint="True if you want to cache the view">
- <cfargument name="cacheTimeout" required="false" type="any" default="" hint="The cache timeout for the view contents">
- <cfargument name="cacheLastAccessTimeout" required="false" type="any" default="" hint="The last access timeout for the view contents">
+ <cfargument name="cache" required="false" type="any" default="false" hint="Cache the rendered view or not">
+ <cfargument name="cacheTimeout" required="false" type="any" default="" hint="The cache timeout for the rendered view">
+ <cfargument name="cacheLastAccessTimeout" required="false" type="any" default="" hint="The last access timeout for the rendered view">
<cfargument name="cacheSuffix" required="false" type="any" default="" hint="Add a cache suffix to the view cache entry. Great for multi-domain caching or i18n caching."/>
+ <cfargument name="cacheProvider" required="false" type="any" default="template" hint="The cache provider you want to use for storing the rendered view. By default we use the 'template' cache provider">
<cfargument name="module" required="false" type="any" default="" hint="Explicitly render a view from this module by passing the module name"/>
<cfargument name="args" required="false" type="any" default="#event.getCurrentViewArgs()#" hint="An optional set of arguments that will be available to this layouts/view rendering ONLY"/>
<cfargument name="collection" required="false" type="any" hint="A collection to use by this Renderer to render the view as many times as the items in the collection (Array or Query)" colddoc:generic="collection"/>
<cfargument name="collectionAs" required="false" type="any" default="" hint="The name of the collection variable in the partial rendering. If not passed, we will use the name of the view by convention"/>
<cfargument name="collectionStartRow" required="false" type="any" default="1" hint="The start row to limit the collection rendering with" colddoc:generic="numeric"/>
<cfargument name="collectionMaxRows" required="false" type="any" default="0" hint="The max rows to iterate over the collection rendering with" colddoc:generic="numeric"/>
- <cfargument name="collectionDelim" required="false" type="any" default="" hint="A string to delimit the collection renderings by"/>
+ <cfargument name="collectionDelim" required="false" type="any" default="" hint="A string to delimit the collection renderings by"/>
<cfargument name="prepostExempt" required="false" type="any" default="false" hint="If true, pre/post view interceptors will not be fired. By default they do fire" colddoc:generic="boolean">
<!--- ************************************************************* --->
<cfscript>
- var viewCacheKey = "";
- var viewCacheEntry = "";
- var timerHash = 0;
- var iData = arguments;
- var explicitModule = false;
- var viewLocations = "";
+ var viewCacheKey = "";
+ var viewCacheEntry = "";
+ var viewCacheProvider = instance.templateCache;
+ var timerHash = 0;
+ var iData = arguments;
+ var explicitModule = false;
+ var viewLocations = "";
// If no incoming explicit module call, default the value to the one in the request context for convenience
if( NOT len(arguments.module) ){
@@ -140,14 +142,19 @@ Description :
arguments.cacheTimeout = viewCacheEntry.timeout;
arguments.cacheLastAccessTimeout = viewCacheEntry.lastAccessTimeout;
arguments.cacheSuffix = viewCacheEntry.cacheSuffix;
+ arguments.cacheProvider = viewCacheEntry.cacheProvider;
}
// Prepare caching key
viewCacheKey = instance.templateCache.VIEW_CACHEKEY_PREFIX & arguments.module & ":" & arguments.view & arguments.cacheSuffix;
// Are we caching?
if (arguments.cache){
+ // Which provider you want to use?
+ if( arguments.cacheProvider neq "template" ){
+ viewCacheProvider = cacheBox.getCache( arguments.cacheProvider );
+ }
// Try to get from cache
- timerHash = instance.debuggerService.timerStart("rendering Cached View [#arguments.view#.cfm]");
- iData.renderedView = instance.templateCache.get( viewCacheKey );
+ timerHash = instance.debuggerService.timerStart("rendering Cached View [#arguments.view#.cfm] from '#arguments.cacheProvider# provider'");
+ iData.renderedView = viewCacheProvider.get( viewCacheKey );
// Verify it existed
if( structKeyExists(iData, "renderedView") ){
instance.debuggerService.timerEnd( timerHash );
@@ -179,7 +186,7 @@ Description :
// Are we caching view
if ( arguments.cache ){
- instance.templateCache.set(viewCacheKey,iData.renderedView,arguments.cacheTimeout,arguments.cacheLastAccessTimeout);
+ viewCacheProvider.set(viewCacheKey, iData.renderedView, arguments.cacheTimeout, arguments.cacheLastAccessTimeout);
}
// Return view content
@@ -333,25 +340,29 @@ Description :
<!--- Render an external View --->
<cffunction name="renderExternalView" access="Public" hint="Renders an external view." output="false" returntype="Any">
<!--- ************************************************************* --->
- <cfargument name="view" required="true" type="string" hint="The full path to the view. This can be an expanded path or relative. Include extension.">
+ <cfargument name="view" required="true" type="any" hint="The full path to the view. This can be an expanded path or relative. Include extension.">
<cfargument name="cache" required="false" type="boolean" default="false" hint="True if you want to cache the view.">
- <cfargument name="cacheTimeout" required="false" type="string" default="" hint="The cache timeout">
- <cfargument name="cacheLastAccessTimeout" required="false" type="string" default="" hint="The last access timeout">
- <cfargument name="cacheSuffix" required="false" type="string" default="" hint="Add a cache suffix to the view cache entry. Great for multi-domain caching or i18n caching."/>
+ <cfargument name="cacheTimeout" required="false" type="any" default="" hint="The cache timeout">
+ <cfargument name="cacheLastAccessTimeout" required="false" type="any" default="" hint="The last access timeout">
+ <cfargument name="cacheSuffix" required="false" type="any" default="" hint="Add a cache suffix to the view cache entry. Great for multi-domain caching or i18n caching."/>
+ <cfargument name="cacheProvider" required="false" type="any" default="template" hint="The cache provider you want to use for storing the rendered view. By default we use the 'template' cache provider">
<cfargument name="args" required="false" type="any" default="#event.getCurrentViewArgs()#" hint="An optional set of arguments that will be available to this layouts/view rendering ONLY"/>
<!--- ************************************************************* --->
<cfscript>
var cbox_renderedView = "";
// Cache Entries
- var cbox_cacheKey = "";
- var cbox_cacheEntry = "";
- var viewLocations = "";
+ var cbox_cacheKey = "";
+ var cbox_cacheEntry = "";
+ var cbox_cacheProvider = instance.templateCache;
+ var viewLocations = "";
// Setup the cache key
cbox_cacheKey = instance.templateCache.VIEW_CACHEKEY_PREFIX & "external-" & arguments.view & arguments.cacheSuffix;
+ // Setup the cache provider
+ if( arguments.cacheProvider neq "template" ){ cbox_cacheProvider = cacheBox.getCache( arguments.cacheProvider ); }
// Try to get from cache
- cbox_timerHash = instance.debuggerService.timerStart("rendering Cached External View [#arguments.view#.cfm]");
- cbox_renderedView = instance.templateCache.get(cbox_cacheKey);
+ cbox_timerHash = instance.debuggerService.timerStart("rendering Cached External View [#arguments.view#.cfm] from '#arguments.cacheProvider#' provider");
+ cbox_renderedView = cbox_cacheProvider.get(cbox_cacheKey);
if( isDefined("cbox_renderedView") ){
instance.debuggerService.timerEnd( cbox_timerHash );
return cbox_renderedView;
@@ -365,7 +376,7 @@ Description :
instance.debuggerService.timerEnd(cbox_timerHash);
// Are we caching it
if( arguments.cache ){
- instance.templateCache.set(cbox_cacheKey,cbox_renderedView,arguments.cacheTimeout,arguments.cacheLastAccessTimeout);
+ cbox_cacheProvider.set(cbox_cacheKey, cbox_renderedView, arguments.cacheTimeout, arguments.cacheLastAccessTimeout);
}
return cbox_renderedView;
</cfscript>
View
28 system/web/context/RequestContext.cfc
@@ -214,14 +214,15 @@ Description :
<cffunction name="setView" access="public" returntype="any" hint="I Set the view to render in this request. Private Request Collection Name: currentView, currentLayout" output="false">
<!--- ************************************************************* --->
- <cfargument name="view" required="false" type="string" hint="The name of the view to set. If a layout has been defined it will assign it, else if will assign the default layout. No extension please">
+ <cfargument name="view" required="false" type="any" hint="The name of the view to set. If a layout has been defined it will assign it, else if will assign the default layout. No extension please">
<cfargument name="nolayout" required="false" type="boolean" default="false" hint="Boolean flag, wether the view sent in will be using a layout or not. Default is false. Uses a pre set layout or the default layout.">
- <cfargument name="cache" required="false" type="boolean" default="false" hint="True if you want to cache the view.">
- <cfargument name="cacheTimeout" required="false" type="string" default="" hint="The cache timeout">
- <cfargument name="cacheLastAccessTimeout" required="false" type="string" default="" hint="The last access timeout">
- <cfargument name="cacheSuffix" required="false" type="string" default="" hint="Add a cache suffix to the view cache entry. Great for multi-domain caching or i18n caching."/>
- <cfargument name="layout" required="false" type="string" hint="You can override the rendering layout of this setView() call if you want to. Else it defaults to implicit resolution or another override.">
- <cfargument name="module" required="false" type="string" default="" hint="Is the view from a module or not"/>
+ <cfargument name="cache" required="false" type="boolean" default="false" hint="True if you want to cache the rendered view.">
+ <cfargument name="cacheTimeout" required="false" type="any" default="" hint="The cache timeout">
+ <cfargument name="cacheLastAccessTimeout" required="false" type="any" default="" hint="The last access timeout">
+ <cfargument name="cacheSuffix" required="false" type="any" default="" hint="Add a cache suffix to the view cache entry. Great for multi-domain caching or i18n caching."/>
+ <cfargument name="cacheProvider" required="false" type="any" default="template" hint="The cache provider you want to use for storing the rendered view. By default we use the 'template' cache provider">
+ <cfargument name="layout" required="false" type="any" hint="You can override the rendering layout of this setView() call if you want to. Else it defaults to implicit resolution or another override.">
+ <cfargument name="module" required="false" type="any" default="" hint="Is the view from a module or not"/>
<cfargument name="args" required="false" type="struct" default="#structNew()#" hint="An optional set of arguments that will be available when the view is rendered"/>
<!--- ************************************************************* --->
<cfscript>
@@ -276,12 +277,11 @@ Description :
removeValue('currentLayout',true);
}
- //Do we need to cache the view
+ // Do we need to cache the view
if( arguments.cache ){
- //prepare the cache keys
+ // prepare the cache keys
cacheEntry.view = arguments.view;
-
- //arg cleanup
+ // Argument cleanup
if ( not isNumeric(arguments.cacheTimeout) )
cacheEntry.Timeout = "";
else
@@ -290,8 +290,10 @@ Description :
cacheEntry.LastAccessTimeout = "";
else
cacheEntry.LastAccessTimeout = arguments.cacheLastAccessTimeout;
- //cache suffix
- cacheEntry.cacheSuffix = arguments.cacheSuffix;
+ // Cache Suffix
+ cacheEntry.cacheSuffix = arguments.cacheSuffix;
+ // Cache Provider
+ cacheEntry.cacheProvider = arguments.cacheProvider;
//Save the view cache entry
setViewCacheableEntry(cacheEntry);
View
18 testing/cases/plugins/RendererTest.cfc
@@ -24,6 +24,15 @@ Description :
assertEquals( results, results2 );
}
+ function testRenderViewWithCacheProviders(){
+ var r = getController().getPlugin("Renderer");
+ results = r.renderView(view="navigation",cache=true,cacheTimeout="5", cacheProvider="default");
+ debug( results );
+ results2 = r.renderView(view="navigation",cache=true,cacheTimeout="5", cacheProvider="default");
+ assertEquals( results, results2 );
+ assertTrue( getCacheBox().getCache("default").lookup("cbox_view-:navigation") );
+ }
+
function testRenderExternalView(){
var r = getController().getPlugin("Renderer");
results = r.renderExternalView("/coldbox/testing/testviews/externalview");
@@ -37,6 +46,15 @@ Description :
assertEquals( results, results2 );
}
+ function testRenderExternalViewWithCachingProviders(){
+ var r = getController().getPlugin("Renderer");
+ results = r.renderExternalView(view="/coldbox/testing/testviews/externalview", cache="true", cacheTimeout="5", cacheProvider="default");
+ results2 = r.renderExternalView(view="/coldbox/testing/testviews/externalview", cache="true", cacheTimeout="5", cacheProvider="default");
+ assertEquals( results, results2 );
+ debug( getCacheBox().getCache("default").getKeys() );
+ assertTrue( getCacheBox().getCache("default").lookup("cbox_view-external-/coldbox/testing/testviews/externalView") );
+ }
+
</cfscript>
</cfcomponent>
View
310 testing/cases/web/context/requestcontextTest.cfc
@@ -3,7 +3,7 @@
<cffunction name="setUp" returntype="void" access="public" output="false">
<cfscript>
oRC = createObject("component","coldbox.system.web.context.RequestContext");
-
+
/* Properties */
props.DefaultLayout = "Main.cfm";
props.DefaultView = "";
@@ -18,20 +18,20 @@
mapping = "/coldbox/testharness"
}
};
-
+
/* Init it */
oRC.init(props);
</cfscript>
</cffunction>
-
+
<cffunction name="getRequestContext" access="private" returntype="any" hint="" output="false" >
<cfreturn oRC>
</cffunction>
-
+
<cffunction name="testgetCollection" returntype="void" access="Public" output="false">
<cfscript>
var event = getRequestContext();
-
+
assertTrue( isStruct(event.getCollection()) );
</cfscript>
</cffunction>
@@ -40,10 +40,10 @@
<cfscript>
var event = getRequestContext();
var test = {today=now()};
-
+
event.collectionAppend(test);
event.clearCollection();
-
+
AssertEquals( structnew(), event.getCollection() );
</cfscript>
</cffunction>
@@ -55,10 +55,10 @@
var event = getRequestContext();
var test = structnew();
test.today = now();
-
+
event.clearCollection();
event.collectionAppend(test);
-
+
AssertEquals( test, event.getCollection() );
</cfscript>
</cffunction>
@@ -70,10 +70,10 @@
var event = getRequestContext();
var test = structnew();
test.today = now();
-
+
event.clearCollection();
event.collectionAppend(test);
-
+
AssertEquals( 1, event.getSize() );
</cfscript>
</cffunction>
@@ -85,14 +85,14 @@
var event = getRequestContext();
var test = structnew();
test.today = now();
-
+
event.clearCollection();
event.collectionAppend(test);
-
+
assertEquals( test.today , event.getValue("today") );
-
+
assertEquals( "null", event.getValue("invalidVar", "null") );
-
+
</cfscript>
</cffunction>
@@ -103,13 +103,13 @@
var event = getRequestContext();
var test = structnew();
test.today = now();
-
+
event.clearCollection();
-
+
event.setValue("test", test.today);
-
+
assertEquals(test.today, event.getValue("test") );
-
+
</cfscript>
</cffunction>
@@ -120,15 +120,15 @@
var event = getRequestContext();
var test = structnew();
test.today = now();
-
+
event.clearCollection();
-
+
event.setValue("test", test.today);
assertEquals(test.today, event.getValue("test") );
-
+
event.removeValue("test");
assertEquals( false, event.getValue("test", false) );
-
+
</cfscript>
</cffunction>
@@ -139,15 +139,15 @@
var event = getRequestContext();
var test = structnew();
test.today = now();
-
+
event.clearCollection();
-
+
event.setValue("test", test.today);
assertTrue( event.valueExists("test") );
-
+
event.removeValue("test");
assertFalse( event.valueExists("test") );
-
+
</cfscript>
</cffunction>
@@ -158,15 +158,15 @@
var event = getRequestContext();
var test = structnew();
test.today = now();
-
+
event.clearCollection();
-
+
AssertFalse( event.valueExists("test") );
-
+
event.paramValue("test", test.today);
-
+
assertTrue( event.valueExists("test") );
-
+
</cfscript>
</cffunction>
@@ -176,30 +176,40 @@
<cfscript>
var event = getRequestContext();
var view = "vwHome";
-
+
event.clearCollection();
-
+
event.setView(view);
assertEquals( view, event.getCurrentView() );
-
+
event.clearCollection();
-
+
event.setView(view, true);
assertEquals(view, event.getCurrentView() );
assertEquals('', event.getCurrentLayout() );
-
+
+ // set view with caching
+ event.setView(view="home", cache="True", cacheProvider="luis", cacheTimeout="20", cacheLastAccessTimeout="1", cacheSuffix="test");
+ r = event.getViewCacheableEntry();
+ //debug( r );
+
+ assertEquals( "home", r.view );
+ assertEquals( "20", r.timeout );
+ assertEquals( "1", r.lastAccessTimeout );
+ assertEquals( "test", r.cacheSuffix );
+ assertEquals( "luis", r.cacheProvider );
</cfscript>
</cffunction>
-
+
<!--- ************************************************************* --->
-
+
<cffunction name="testCurrentLayout" access="public" returntype="void" output="false">
<cfscript>
var event = getRequestContext();
var layout = "layout.pdf";
-
+
event.clearCollection();
-
+
event.setLayout(layout);
assertEquals( layout & ".cfm", event.getCurrentLayout() );
</cfscript>
@@ -211,270 +221,270 @@
<cfscript>
var event = getRequestContext();
var defaultEvent = "ehTest.doSomething";
-
+
event.setValue("event", defaultEvent);
-
+
assertEquals( defaultEvent, event.getCurrentEvent() );
assertEquals( "ehTest", event.getCurrentHandler() );
assertEquals( "doSomething", event.getCurrentAction() );
-
+
defaultEvent = "blog.content.doSomething";
-
+
event.setValue("event", defaultEvent);
-
+
assertEquals( defaultEvent, event.getCurrentEvent() );
assertEquals( "content", event.getCurrentHandler() );
assertEquals( "doSomething", event.getCurrentAction() );
-
+
defaultEvent = "blog.content.security.doSomething";
-
+
event.setValue("event", defaultEvent);
-
+
assertEquals( defaultEvent, event.getCurrentEvent() );
assertEquals( "security", event.getCurrentHandler() );
assertEquals( "doSomething", event.getCurrentAction() );
-
+
</cfscript>
</cffunction>
-
+
<!--- ************************************************************* --->
-
+
<cffunction name="testoverrideEvent" access="Public" output="false" returntype="void">
<cfscript>
var event = getRequestContext();
var newEvent = "pio.yea";
-
+
event.clearCollection();
event.setValue("event","blog.dspEntries");
event.overrideEvent(newEvent);
-
+
assertEquals( newEvent , event.getCurrentEvent() );
</cfscript>
</cffunction>
<!--- ************************************************************* --->
-
+
<cffunction name="testshowdebugpanel" access="public" returntype="void">
<cfscript>
var event = getRequestContext();
-
+
event.showDebugPanel(true);
AssertTrue( event.getDebugPanelFlag() );
-
+
event.showDebugPanel(false);
AssertFalse( event.getDebugPanelFlag() );
-
+
</cfscript>
</cffunction>
-
+
<!--- ************************************************************* --->
-
+
<cffunction name="testProxyRequest" access="public" returntype="void" >
<cfscript>
var event = getRequestContext();
-
+
AssertFalse( event.isProxyRequest() );
-
+
event.setProxyRequest();
AssertTrue( event.isProxyRequest() );
</cfscript>
</cffunction>
-
+
<!--- ************************************************************* --->
-
+
<cffunction name="testNoRender" access="public" returntype="void">
<cfscript>
var event = getRequestContext();
-
+
event.NoRender(remove=true);
AssertFalse( event.isNoRender() );
-
+
event.NoRender(remove=false);
AssertTrue( event.isNoRender() );
-
+
</cfscript>
</cffunction>
-
+
<!--- ************************************************************* --->
-
+
<cffunction name="testgetEventName" access="public" returntype="void" output="false">
<cfscript>
var event = getRequestContext();
var test = props.eventName;
assertEquals( test, event.getEventName() );
-
+
</cfscript>
</cffunction>
-
+
<!--- ************************************************************* --->
-
+
<cffunction name="testgetSelf" access="public" output="false" returntype="void">
<cfscript>
var event = getRequestContext();
var test = props.eventname;
assertEquals( "index.cfm?#test#=", event.getSelf() );
-
+
</cfscript>
</cffunction>
-
+
<!--- ************************************************************* --->
-
+
<cffunction name="testEventCacheableEntry" access="public" output="false" returntype="void">
<cfscript>
var event = getRequestContext();
var centry = structnew();
-
+
AssertFalse( event.isEventCacheable(), "event cacheable");
-
+
centry.cacheable = true;
centry.test = true;
-
+
event.setEventCacheableEntry(centry);
AssertTrue( event.isEventCacheable(), "event cacheable 2");
AssertEquals(centry, event.getEventCacheableEntry() );
-
+
</cfscript>
</cffunction>
-
+
<!--- ************************************************************* --->
-
+
<cffunction name="testViewCacheableEntry" access="public" output="false" returntype="void">
<cfscript>
var event = getRequestContext();
var centry = structnew();
-
+
AssertFalse( event.isViewCacheable(), "view cacheable");
-
+
centry.cacheable = true;
centry.test = true;
-
+
event.setViewCacheableEntry(centry);
AssertTrue( event.isViewCacheable(), "view cacheable 2");
AssertEquals(centry, event.getViewCacheableEntry() );
-
+
</cfscript>
</cffunction>
-
+
<!--- ************************************************************* --->
-
+
<cffunction name="testRoutedStruct" access="public" output="false" returntype="void">
<cfscript>
var event = getRequestContext();
var routedStruct = structnew();
-
+
routedStruct.page = "aboutus";
routedStruct.day = "13";
-
+
event.setRoutedStruct(routedStruct);
-
+
AssertEquals(event.getRoutedStruct(),routedStruct);
-
+
</cfscript>
</cffunction>
-
+
<cffunction name="testSES" access="public" output="false" returntype="void">
<cfscript>
var event = getRequestContext();
base = "http://www.luismajano.com/index.cfm";
-
+
event.setsesBaseURL(base);
assertEquals( event.getsesBaseURL(), base );
-
+
event.setisSES(true);
assertEquals( event.isSES(), true );
-
-
+
+
</cfscript>
</cffunction>
-
+
<cffunction name="testBuildLink" access="public" output="false" returntype="void">
<cfscript>
var event = getRequestContext();
base = "http://www.luismajano.com/index.cfm";
basessl = "https://www.luismajano.com/index.cfm";
-
+
/* simple setup */
event.setisSES(false);
testurl = event.buildLink('general.index');
AssertEquals(testurl, "index.cfm?event=general.index" );
-
+
/* simple qs */
event.setisSES(false);
testurl = event.buildLink(linkTo='general.index',queryString="page=2");
AssertEquals(testurl, "index.cfm?event=general.index&page=2" );
-
+
/* empty qs */
event.setisSES(false);
testurl = event.buildLink(linkTo='general.index',queryString="");
AssertEquals(testurl, "index.cfm?event=general.index" );
-
+
/* ses test */
event.setisSES(true);
event.setsesBaseURL(base);
testurl = event.buildLink('general/index');
AssertEquals(testurl, base & "/general/index" );
-
+
/* query string transformation */
event.setisSES(true);
event.setsesBaseURL(base);
testurl = event.buildLink(linkTo='general/index',queryString="page=2&test=4");
AssertEquals(testurl, base & "/general/index/page/2/test/4" );
-
+
/* ssl test */
event.setisSES(true);
event.setsesBaseURL(base);
testurl = event.buildLink(linkto='general/index',ssl=true);
- AssertEquals(testurl, basessl & "/general/index" );
-
+ AssertEquals(testurl, basessl & "/general/index" );
+
/* translate */
event.setisSES(true);
event.setsesBaseURL(base);
testurl = event.buildLink(linkto='general.index',translate=false);
- AssertEquals(testurl, base & "/general.index" );
-
+ AssertEquals(testurl, base & "/general.index" );
+
</cfscript>
</cffunction>
-
+
<cffunction name="testRenderData" access="public" output="false" returntype="void">
<cfscript>
var event = getRequestContext();
-
+
AssertEquals( event.getRenderData(), structnew());
-
+
// Test JSON
- event.renderData(type='JSON',data="[1,2,3,4]");
+ event.renderData(type='JSON',data="[1,2,3,4]");
rd = event.getRenderData();
assertEquals( rd.contenttype, "application/json");
assertEquals( rd.type, "json");
assertEquals( rd.jsonQueryFormat, "query");
assertEquals( rd.statusCode, "200");
assertEquals( rd.statusText, "");
-
-
- event.renderData(type='JSON',data="[1,2,3,4]",jsonQueryFormat="array",jsonCase="upper");
+
+
+ event.renderData(type='JSON',data="[1,2,3,4]",jsonQueryFormat="array",jsonCase="upper");
rd = event.getRenderData();
assertEquals( rd.jsonQueryFormat, "array");
-
+
//JSONP
event.renderData(type='JSONP',data="[1,2,3,4]",jsonCallback="testCallback");
rd = event.getRenderData();
assertEquals( rd.type, "jsonp");
assertEquals( rd.jsonCallback, 'testCallback');
-
- // Test WDDX
+
+ // Test WDDX
event.renderData(type="WDDX",data=arrayNew(1));
rd = event.getRenderData();
assertEquals( rd.contenttype, "text/xml");
assertEquals( rd.type, "wddx");
-
+
// Test PLAIN
event.renderData(data="Hello");
rd = event.getRenderData();
assertEquals( rd.type, "html");
assertEquals( rd.contenttype, "text/html");
-
+
// Test XML
event.renderData(data=structnew(),type="xml");
rd = event.getRenderData();
@@ -482,96 +492,96 @@
assertEquals( rd.contenttype, "text/xml");
assertEquals( rd.xmlListDelimiter, ",");
assertEquals( rd.xmlColumnList, "");
-
+
// Test contenttype
event.renderData(data="Hello",contentType="application/ms-excel");
rd = event.getRenderData();
assertEquals( rd.type, "html");
assertEquals( rd.contenttype, "application/ms-excel");
-
+
// Test StatusCodes
event.renderData(data="hello",statusCode="400",statusText="Invalid Call!");
rd = event.getRenderData();
assertEquals( rd.statusCode, "400");
assertEquals( rd.statusText, "Invalid Call!");
-
+
</cfscript>
</cffunction>
-
+
<cffunction name="testNoExecution">
<cfscript>
var event = getRequestContext();
-
+
assertFalse( event.isNoExecution() );
event.noExecution();
assertTrue( event.isNoExecution() );
-
+
</cfscript>
</cffunction>
-
+
<cffunction name="testCurrentModule" access="public" returntype="void" output="false">
<cfscript>
var event = getRequestContext();
-
+
event.setValue("event","myModule:test.home");
-
+
//debug(event.getCurrentEVent());
assertEquals("myModule", event.getCurrentModule());
-
+
event.setValue("event","test.home");
assertEquals("", event.getCurrentModule());
-
+
</cfscript>
</cffunction>
-
-
+
+
<cffunction name="testModuleRoot" access="public" returntype="void" output="false">
<cfscript>
var event = getRequestContext();
-
-
+
+
//debug(event.getCurrentEVent());
assertEquals("", event.getmoduleRoot());
event.setValue("event","test1:test.home");
assertEquals(props.modules.test1.mapping, event.getmoduleRoot());
-
-
+
+
</cfscript>
</cffunction>
-
-
+
+
<cffunction name="testsetHTTPHeader" access="public" returntype="void" output="false">
<cfscript>
var event = getRequestContext();
-
+
event.setHTTPHeader(statusCode="200",statusText="Hello");
-
+
event.setHTTPHeader(name="expires",value="#now()#");
</cfscript>
</cffunction>
-
+
<cffunction name="testGetHTTPConetnt" access="public" returntype="void" output="false">
<cfscript>
var event = getRequestContext();
-
+
test = event.getHTTPContent();
-
+
assertTrue( isSimpleValue(test) );
-
+
</cfscript>
</cffunction>
-
+
<cffunction name="testNoLayout" access="public" returntype="void" output="false">
<cfscript>
var event = getRequestContext();
-
+
event.noLayout().setView("test");
-
+
//debug( event.getCollection(private=true) );
assertEquals( true, event.getValue("layoutOverride",false,true) );
-
+
</cfscript>
</cffunction>
-
-
+
+
</cfcomponent>
Please sign in to comment.
Something went wrong with that request. Please try again.