| 1 | <!----------------------------------------------------------------------- |
|---|
| 2 | ******************************************************************************** |
|---|
| 3 | Copyright 2005-2007 ColdBox Framework by Luis Majano and Ortus Solutions, Corp |
|---|
| 4 | www.coldboxframework.com | www.luismajano.com | www.ortussolutions.com |
|---|
| 5 | ******************************************************************************** |
|---|
| 6 | |
|---|
| 7 | Author : Luis Majano |
|---|
| 8 | Date : 9/3/2007 |
|---|
| 9 | Description : |
|---|
| 10 | Request service Test |
|---|
| 11 | -----------------------------------------------------------------------> |
|---|
| 12 | <cfcomponent name="requestserviceTest" extends="coldbox.system.testing.BaseTestCase" output="false"> |
|---|
| 13 | |
|---|
| 14 | <cffunction name="setUp" returntype="void" access="public" output="false"> |
|---|
| 15 | <cfscript> |
|---|
| 16 | //Setup ColdBox Mappings For this Test |
|---|
| 17 | setAppMapping("/coldbox/testharness"); |
|---|
| 18 | setConfigMapping(ExpandPath(instance.AppMapping & "/config/coldbox.xml.cfm")); |
|---|
| 19 | //Call the super setup method to setup the app. |
|---|
| 20 | super.setup(); |
|---|
| 21 | </cfscript> |
|---|
| 22 | </cffunction> |
|---|
| 23 | |
|---|
| 24 | <cffunction name="testRequestCapturesWithNoDecoration" access="public" returntype="void" output="false"> |
|---|
| 25 | <cfscript> |
|---|
| 26 | var originalSetting = getcontroller().getSetting("RequestContextDecorator"); |
|---|
| 27 | |
|---|
| 28 | getcontroller().setSetting("RequestContextDecorator",""); |
|---|
| 29 | testRequestCaptures(); |
|---|
| 30 | getcontroller().setSetting("RequestContextDecorator",originalSetting); |
|---|
| 31 | |
|---|
| 32 | </cfscript> |
|---|
| 33 | </cffunction> |
|---|
| 34 | |
|---|
| 35 | <cffunction name="testRequestCaptures" access="public" returntype="void" output="false"> |
|---|
| 36 | <cfscript> |
|---|
| 37 | var service = getController().getRequestService(); |
|---|
| 38 | var context = ""; |
|---|
| 39 | var persistStruct = structnew(); |
|---|
| 40 | var today = now(); |
|---|
| 41 | var SessionStorage = getController().getPlugin("SessionStorage"); |
|---|
| 42 | |
|---|
| 43 | /* Fill up the flash storage */ |
|---|
| 44 | SessionStorage.setVar('_coldbox_persistStruct', structnew()); |
|---|
| 45 | persistStruct = SessionStorage.getVar('_coldbox_persistStruct'); |
|---|
| 46 | persistStruct.flashvariable = today; |
|---|
| 47 | |
|---|
| 48 | /* Setup test variables */ |
|---|
| 49 | form.name = 'luis majano'; |
|---|
| 50 | form.event = "ehGeneral.dspHome,movies.list"; |
|---|
| 51 | |
|---|
| 52 | url.name = "pio majano"; |
|---|
| 53 | url.today = today; |
|---|
| 54 | |
|---|
| 55 | /* Catpure the request */ |
|---|
| 56 | context = service.requestCapture(); |
|---|
| 57 | |
|---|
| 58 | debug(context.getCollection()); |
|---|
| 59 | |
|---|
| 60 | /* Tests */ |
|---|
| 61 | AssertTrue( isObject(context), "Context Creation"); |
|---|
| 62 | AssertTrue(today eq context.getValue('flashvariable') , "Flash variable creation"); |
|---|
| 63 | AssertTrue(url.today eq context.getValue('today') , "URL Append"); |
|---|
| 64 | AssertTrue(form.name eq context.getValue('name'), "Name test and precedence"); |
|---|
| 65 | AssertTrue(context.valueExists('event'), "Multi-Event Test"); |
|---|
| 66 | </cfscript> |
|---|
| 67 | </cffunction> |
|---|
| 68 | |
|---|
| 69 | <cffunction name="testDebugModesRequestCaptures" access="public" returntype="void" output="false"> |
|---|
| 70 | <cfscript> |
|---|
| 71 | var service = getController().getRequestService(); |
|---|
| 72 | var context = ""; |
|---|
| 73 | |
|---|
| 74 | /* Setup test variables */ |
|---|
| 75 | url.debugmode = true; |
|---|
| 76 | url.debugpass = "invalid"; |
|---|
| 77 | |
|---|
| 78 | /* Catpure the request */ |
|---|
| 79 | context = service.requestCapture(); |
|---|
| 80 | |
|---|
| 81 | /* Set debugmode to false to tests */ |
|---|
| 82 | getcontroller().getDebuggerService().setDebugMode(false); |
|---|
| 83 | |
|---|
| 84 | /* Tests */ |
|---|
| 85 | AssertFalse(getcontroller().getDebuggerService().getDebugMode(), "Debug Mode test invalid password"); |
|---|
| 86 | |
|---|
| 87 | /* Now test with right password. */ |
|---|
| 88 | structClear(url); |
|---|
| 89 | structClear(request); |
|---|
| 90 | url.debugmode = true; |
|---|
| 91 | url.debugpass = "coldbox"; |
|---|
| 92 | getController().setSetting('debugPassword',"coldbox"); |
|---|
| 93 | |
|---|
| 94 | /* Catpure the request */ |
|---|
| 95 | context = service.requestCapture(); |
|---|
| 96 | |
|---|
| 97 | /* Tests */ |
|---|
| 98 | AssertTrue(getcontroller().getDebuggerService().getDebugMode(), "Debug Mode test good password: #getcontroller().getDebuggerService().getDebugMode()#"); |
|---|
| 99 | </cfscript> |
|---|
| 100 | </cffunction> |
|---|
| 101 | |
|---|
| 102 | <cffunction name="testDefaultEvent" access="public" returntype="void" output="false"> |
|---|
| 103 | <cfscript> |
|---|
| 104 | var service = getController().getRequestService(); |
|---|
| 105 | var context = ""; |
|---|
| 106 | |
|---|
| 107 | /* Setup test variables */ |
|---|
| 108 | url.event = "default"; |
|---|
| 109 | |
|---|
| 110 | /* Catpure the request */ |
|---|
| 111 | context = service.requestCapture(); |
|---|
| 112 | |
|---|
| 113 | /* Tests */ |
|---|
| 114 | AssertTrue( isObject(context), "Context Creation"); |
|---|
| 115 | AssertTrue( url.event neq context.getCurrentEvent(), "Event mismatch"); |
|---|
| 116 | AssertEquals( context.getCurrentEvent(), url.event & "." & getController().getSetting("EventAction",1) ); |
|---|
| 117 | </cfscript> |
|---|
| 118 | </cffunction> |
|---|
| 119 | |
|---|
| 120 | <cffunction name="testContextGetterSetters" access="public" returntype="Void" output="false" > |
|---|
| 121 | <cfscript> |
|---|
| 122 | var service = getController().getRequestService(); |
|---|
| 123 | var context = ""; |
|---|
| 124 | |
|---|
| 125 | context = service.getContext(); |
|---|
| 126 | AssertTrue( isObject(context), "Context Create"); |
|---|
| 127 | |
|---|
| 128 | structDelete(request, "cb_requestContext"); |
|---|
| 129 | assertFalse( service.contextExists() , "Context exists"); |
|---|
| 130 | |
|---|
| 131 | service.setContext(context); |
|---|
| 132 | assertTrue( structKeyExists(request,"cb_requestContext") ,"setter in request"); |
|---|
| 133 | |
|---|
| 134 | </cfscript> |
|---|
| 135 | </cffunction> |
|---|
| 136 | |
|---|
| 137 | <cffunction name="tearDown" access="public" returntype="Void" hint="teardown" output="false" > |
|---|
| 138 | <cfscript> |
|---|
| 139 | structClear(cookie); |
|---|
| 140 | </cfscript> |
|---|
| 141 | </cffunction> |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | </cfcomponent> |
|---|