Hi,
It's not everyone's cup of tea, but I'm a fan of unit testing my controllers
using CFCUnit. Selenium is cool for following a page flow through, but it's
also nice to be able to just focus on one piece of controller logic.
However, to do this, you have to get the controller to actually give control
back so you can check the results.
Here's a couple of little tips for controlling page flow to make testing
easier. These have been posted before, but I was reminded of them by the
thread on controller layout.
1. Never use a raw cflocation. Instead use a UDF:
<cffunction name="relocate" returntype="void" output="true">
<cfargument name="txtLocation" type="string" required="true">
<cfif StructKeyExists(Request, "DebugFlag")>
<cfoutput>Relocate: #arguments.txtLocation#</cfoutput>
<cfelse>
<cflocation url="#arguments.txtLocation#" addtoken="no">
</cfif>
</cffunction>
2. Never directly check for a form post. Again, use a UDF:
<cffunction name="isFormSubmitted" returntype="boolean" output="false">
<cfreturn StructKeyExists(Request, "DebugFlag") OR CGI.request_method is
"POST">
</cffunction>
(This is a simplified version - in practice I use a slightly more complex
one that checks for a form ID and ensures the form fields have been
received).
Jaime Metcher
You are subscribed to cfcdev. To unsubscribe, please follow the instructions at
http://www.cfczone.org/listserv.cfm
CFCDev is supported by:
Katapult Media, Inc.
We are cool code geeks looking for fun projects to rock!
www.katapultmedia.com
An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]