User login

Functional tests with the CFWheels testing framework

We're doing some functions tests for cfwheels even though the main docs - http://code.google.com/p/cfwheels/wiki/TestingFramework - have only controller, model, view. Trying to test our showUserText() function alone failed because it was telling me it doesn't know anything about other functions it calls that are in fact core to CFWheels (stripTags, in this case).

Turned out the secret was instantiating a controller and tacking this function (which is in events/functions.cfm so available "everywhere") onto it, loc.controller.showUserText() style.

<cfcomponent extends="wheelsMapping.Test">

  <cffunction name="setup">
    <cfset loc.controller = controller(name="Feed")>
  </cffunction>

  <cffunction name="test_instagram_with_short_url">
    <cfset loc.message = "This message will have an Instagram image embedded that originally had a short URL: http://instagr.am/p/SQeWUcL0UZ/">
    <cfset loc.expected = '<div class="instagram-photo"><a href="http://instagr.am/p/SQeWUcL0UZ"><img src="http://instagr.am/p/SQeWUcL0UZ/media?size=m"></a></div>'>
    <cfset assert("loc.controller.showUserText(loc.message) contains loc.expected")>
  </cffunction>

  <cffunction name="test_instagram_with_long_url">
    <cfset loc.message = "This message will have an Instagram image embedded that originally had a short URL: http://instagram.com/p/SQeWUcL0UZ :-)">
    <cfset loc.expected = '<div class="instagram-photo"><a href="http://instagr.am/p/SQeWUcL0UZ"><img src="http://instagr.am/p/SQeWUcL0UZ/media?size=m"></a></div>'>
    <cfset assert("loc.controller.showUserText(loc.message) contains loc.expected")>
  </cffunction>

</cfcomponent>

Searched words: 
cfwheels function testing

Comments

:)

this is a very slick idea!

Thank you Anthony!

And thank you for all your great work on CFWheels!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.