| 1 | <cfcomponent name="requestcontextTest" extends="coldbox.system.testing.BaseTestCase" output="false"> |
|---|
| 2 | |
|---|
| 3 | <cffunction name="setUp" returntype="void" access="public" output="false"> |
|---|
| 4 | <cfscript> |
|---|
| 5 | oRC = createObject("component","coldbox.system.beans.RequestContext"); |
|---|
| 6 | |
|---|
| 7 | /* Properties */ |
|---|
| 8 | props.DefaultLayout = "Main.cfm"; |
|---|
| 9 | props.DefaultView = ""; |
|---|
| 10 | props.FolderLayouts = structnew(); |
|---|
| 11 | props.ViewLayouts = structnew(); |
|---|
| 12 | props.EventName = "event"; |
|---|
| 13 | props.isSES = false; |
|---|
| 14 | props.sesBaseURL = "http://jfetmac/applications/coldbox/testharness/index.cfm"; |
|---|
| 15 | |
|---|
| 16 | /* Init it */ |
|---|
| 17 | oRC.init(structnew(),structnew(),props); |
|---|
| 18 | </cfscript> |
|---|
| 19 | </cffunction> |
|---|
| 20 | <cffunction name="getRequestContext" access="private" returntype="any" hint="" output="false" > |
|---|
| 21 | <cfreturn oRC> |
|---|
| 22 | </cffunction> |
|---|
| 23 | |
|---|
| 24 | <cffunction name="testgetCollection" returntype="void" access="Public" output="false"> |
|---|
| 25 | <cfscript> |
|---|
| 26 | var event = getRequestContext(); |
|---|
| 27 | |
|---|
| 28 | assertTrue( isStruct(event.getCollection()) ); |
|---|
| 29 | </cfscript> |
|---|
| 30 | </cffunction> |
|---|
| 31 | |
|---|
| 32 | <!--- ************************************************************* ---> |
|---|
| 33 | |
|---|
| 34 | <cffunction name="testsetCollection" access="public" returntype="void" output="false"> |
|---|
| 35 | <cfscript> |
|---|
| 36 | var event = getRequestContext(); |
|---|
| 37 | var test = {name='luis',test=now()}; |
|---|
| 38 | |
|---|
| 39 | event.setCollection(test); |
|---|
| 40 | |
|---|
| 41 | AssertEquals( test, event.getCollection() ); |
|---|
| 42 | </cfscript> |
|---|
| 43 | </cffunction> |
|---|
| 44 | |
|---|
| 45 | <!--- ************************************************************* ---> |
|---|
| 46 | |
|---|
| 47 | <cffunction name="testclearCollection" access="public" returntype="void" output="false"> |
|---|
| 48 | <cfscript> |
|---|
| 49 | var event = getRequestContext(); |
|---|
| 50 | var test = structnew(); |
|---|
| 51 | test.today = now(); |
|---|
| 52 | |
|---|
| 53 | event.setCollection(test); |
|---|
| 54 | event.clearCollection(); |
|---|
| 55 | |
|---|
| 56 | AssertEquals( structnew(), event.getCollection() ); |
|---|
| 57 | </cfscript> |
|---|
| 58 | </cffunction> |
|---|
| 59 | |
|---|
| 60 | <!--- ************************************************************* ---> |
|---|
| 61 | |
|---|
| 62 | <cffunction name="testcollectionAppend" access="public" returntype="void" output="false"> |
|---|
| 63 | <cfscript> |
|---|
| 64 | var event = getRequestContext(); |
|---|
| 65 | var test = structnew(); |
|---|
| 66 | test.today = now(); |
|---|
| 67 | |
|---|
| 68 | event.clearCollection(); |
|---|
| 69 | event.collectionAppend(test); |
|---|
| 70 | |
|---|
| 71 | AssertEquals( test, event.getCollection() ); |
|---|
| 72 | </cfscript> |
|---|
| 73 | </cffunction> |
|---|
| 74 | |
|---|
| 75 | <!--- ************************************************************* ---> |
|---|
| 76 | |
|---|
| 77 | <cffunction name="testgetSize" access="public" returntype="void" output="false"> |
|---|
| 78 | <cfscript> |
|---|
| 79 | var event = getRequestContext(); |
|---|
| 80 | var test = structnew(); |
|---|
| 81 | test.today = now(); |
|---|
| 82 | |
|---|
| 83 | event.clearCollection(); |
|---|
| 84 | event.collectionAppend(test); |
|---|
| 85 | |
|---|
| 86 | AssertEquals( 1, event.getSize() ); |
|---|
| 87 | </cfscript> |
|---|
| 88 | </cffunction> |
|---|
| 89 | |
|---|
| 90 | <!--- ************************************************************* ---> |
|---|
| 91 | |
|---|
| 92 | <cffunction name="testgetValue" returntype="void" access="Public" output="false"> |
|---|
| 93 | <cfscript> |
|---|
| 94 | var event = getRequestContext(); |
|---|
| 95 | var test = structnew(); |
|---|
| 96 | test.today = now(); |
|---|
| 97 | |
|---|
| 98 | event.clearCollection(); |
|---|
| 99 | event.collectionAppend(test); |
|---|
| 100 | |
|---|
| 101 | assertEquals( test.today , event.getValue("today") ); |
|---|
| 102 | |
|---|
| 103 | assertEquals( "null", event.getValue("invalidVar", "null") ); |
|---|
| 104 | |
|---|
| 105 | assertTrue( isArray(event.getValue("invalidVar", "[array]") ) ); |
|---|
| 106 | |
|---|
| 107 | assertTrue( isQuery ( event.getValue("invalidVar", "[query]") )) ; |
|---|
| 108 | |
|---|
| 109 | assertTrue( isStruct( event.getValue("invalidVar", "[struct]") ) ); |
|---|
| 110 | |
|---|
| 111 | </cfscript> |
|---|
| 112 | </cffunction> |
|---|
| 113 | |
|---|
| 114 | <!--- ************************************************************* ---> |
|---|
| 115 | |
|---|
| 116 | <cffunction name="testsetValue" access="Public" output="false" returntype="void"> |
|---|
| 117 | <cfscript> |
|---|
| 118 | var event = getRequestContext(); |
|---|
| 119 | var test = structnew(); |
|---|
| 120 | test.today = now(); |
|---|
| 121 | |
|---|
| 122 | event.clearCollection(); |
|---|
| 123 | |
|---|
| 124 | event.setValue("test", test.today); |
|---|
| 125 | |
|---|
| 126 | assertEquals(test.today, event.getValue("test") ); |
|---|
| 127 | |
|---|
| 128 | </cfscript> |
|---|
| 129 | </cffunction> |
|---|
| 130 | |
|---|
| 131 | <!--- ************************************************************* ---> |
|---|
| 132 | |
|---|
| 133 | <cffunction name="testremoveValue" access="Public" output="false" returntype="void"> |
|---|
| 134 | <cfscript> |
|---|
| 135 | var event = getRequestContext(); |
|---|
| 136 | var test = structnew(); |
|---|
| 137 | test.today = now(); |
|---|
| 138 | |
|---|
| 139 | event.clearCollection(); |
|---|
| 140 | |
|---|
| 141 | event.setValue("test", test.today); |
|---|
| 142 | assertEquals(test.today, event.getValue("test") ); |
|---|
| 143 | |
|---|
| 144 | event.removeValue("test"); |
|---|
| 145 | assertEquals( false, event.getValue("test", false) ); |
|---|
| 146 | |
|---|
| 147 | </cfscript> |
|---|
| 148 | </cffunction> |
|---|
| 149 | |
|---|
| 150 | <!--- ************************************************************* ---> |
|---|
| 151 | |
|---|
| 152 | <cffunction name="testvalueExists" returntype="void" access="Public" output="false"> |
|---|
| 153 | <cfscript> |
|---|
| 154 | var event = getRequestContext(); |
|---|
| 155 | var test = structnew(); |
|---|
| 156 | test.today = now(); |
|---|
| 157 | |
|---|
| 158 | event.clearCollection(); |
|---|
| 159 | |
|---|
| 160 | event.setValue("test", test.today); |
|---|
| 161 | assertTrue( event.valueExists("test") ); |
|---|
| 162 | |
|---|
| 163 | event.removeValue("test"); |
|---|
| 164 | assertFalse( event.valueExists("test") ); |
|---|
| 165 | |
|---|
| 166 | </cfscript> |
|---|
| 167 | </cffunction> |
|---|
| 168 | |
|---|
| 169 | <!--- ************************************************************* ---> |
|---|
| 170 | |
|---|
| 171 | <cffunction name="testparamValue" returntype="void" access="Public" output="false"> |
|---|
| 172 | <cfscript> |
|---|
| 173 | var event = getRequestContext(); |
|---|
| 174 | var test = structnew(); |
|---|
| 175 | test.today = now(); |
|---|
| 176 | |
|---|
| 177 | event.clearCollection(); |
|---|
| 178 | |
|---|
| 179 | AssertFalse( event.valueExists("test") ); |
|---|
| 180 | |
|---|
| 181 | event.paramValue("test", test.today); |
|---|
| 182 | |
|---|
| 183 | assertTrue( event.valueExists("test") ); |
|---|
| 184 | |
|---|
| 185 | </cfscript> |
|---|
| 186 | </cffunction> |
|---|
| 187 | |
|---|
| 188 | <!--- ************************************************************* ---> |
|---|
| 189 | |
|---|
| 190 | <cffunction name="testCurrentView" access="public" returntype="void" output="false"> |
|---|
| 191 | <cfscript> |
|---|
| 192 | var event = getRequestContext(); |
|---|
| 193 | var view = "vwHome"; |
|---|
| 194 | |
|---|
| 195 | event.clearCollection(); |
|---|
| 196 | |
|---|
| 197 | event.setView(view); |
|---|
| 198 | assertEquals( view, event.getCurrentView() ); |
|---|
| 199 | |
|---|
| 200 | event.clearCollection(); |
|---|
| 201 | |
|---|
| 202 | event.setView(view, true); |
|---|
| 203 | assertEquals( view, event.getCurrentView() ); |
|---|
| 204 | assertEquals( '', event.getCurrentLayout() ); |
|---|
| 205 | |
|---|
| 206 | </cfscript> |
|---|
| 207 | </cffunction> |
|---|
| 208 | |
|---|
| 209 | <!--- ************************************************************* ---> |
|---|
| 210 | |
|---|
| 211 | <cffunction name="testCurrentLayout" access="public" returntype="void" output="false"> |
|---|
| 212 | <cfscript> |
|---|
| 213 | var event = getRequestContext(); |
|---|
| 214 | var layout = "layout.pdf"; |
|---|
| 215 | |
|---|
| 216 | event.clearCollection(); |
|---|
| 217 | |
|---|
| 218 | event.setLayout(layout); |
|---|
| 219 | assertEquals( layout & ".cfm", event.getCurrentLayout() ); |
|---|
| 220 | </cfscript> |
|---|
| 221 | </cffunction> |
|---|
| 222 | |
|---|
| 223 | <!--- ************************************************************* ---> |
|---|
| 224 | |
|---|
| 225 | <cffunction name="testgetCurrentEventHandlerAction" access="public"returntype="void" output="false"> |
|---|
| 226 | <cfscript> |
|---|
| 227 | var event = getRequestContext(); |
|---|
| 228 | var defaultEvent = "ehTest.doSomething"; |
|---|
| 229 | |
|---|
| 230 | event.setValue("event", defaultEvent); |
|---|
| 231 | |
|---|
| 232 | assertEquals( defaultEvent, event.getCurrentEvent() ); |
|---|
| 233 | assertEquals( "ehTest", event.getCurrentHandler() ); |
|---|
| 234 | assertEquals( "doSomething", event.getCurrentAction() ); |
|---|
| 235 | |
|---|
| 236 | defaultEvent = "blog.content.doSomething"; |
|---|
| 237 | |
|---|
| 238 | event.setValue("event", defaultEvent); |
|---|
| 239 | |
|---|
| 240 | assertEquals( defaultEvent, event.getCurrentEvent() ); |
|---|
| 241 | assertEquals( "content", event.getCurrentHandler() ); |
|---|
| 242 | assertEquals( "doSomething", event.getCurrentAction() ); |
|---|
| 243 | |
|---|
| 244 | defaultEvent = "blog.content.security.doSomething"; |
|---|
| 245 | |
|---|
| 246 | event.setValue("event", defaultEvent); |
|---|
| 247 | |
|---|
| 248 | assertEquals( defaultEvent, event.getCurrentEvent() ); |
|---|
| 249 | assertEquals( "security", event.getCurrentHandler() ); |
|---|
| 250 | assertEquals( "doSomething", event.getCurrentAction() ); |
|---|
| 251 | |
|---|
| 252 | </cfscript> |
|---|
| 253 | </cffunction> |
|---|
| 254 | |
|---|
| 255 | <!--- ************************************************************* ---> |
|---|
| 256 | |
|---|
| 257 | <cffunction name="testoverrideEvent" access="Public" output="false" returntype="void"> |
|---|
| 258 | <cfscript> |
|---|
| 259 | var event = getRequestContext(); |
|---|
| 260 | var newEvent = "pio.yea"; |
|---|
| 261 | |
|---|
| 262 | event.clearCollection(); |
|---|
| 263 | event.setValue("event","blog.dspEntries"); |
|---|
| 264 | event.overrideEvent(newEvent); |
|---|
| 265 | |
|---|
| 266 | assertEquals( newEvent , event.getCurrentEvent() ); |
|---|
| 267 | </cfscript> |
|---|
| 268 | </cffunction> |
|---|
| 269 | |
|---|
| 270 | <!--- ************************************************************* ---> |
|---|
| 271 | |
|---|
| 272 | <cffunction name="testshowdebugpanel" access="public" returntype="void"> |
|---|
| 273 | <cfscript> |
|---|
| 274 | var event = getRequestContext(); |
|---|
| 275 | |
|---|
| 276 | event.showDebugPanel(true); |
|---|
| 277 | AssertTrue( event.getDebugPanelFlag() ); |
|---|
| 278 | |
|---|
| 279 | event.showDebugPanel(false); |
|---|
| 280 | AssertFalse( event.getDebugPanelFlag() ); |
|---|
| 281 | |
|---|
| 282 | </cfscript> |
|---|
| 283 | </cffunction> |
|---|
| 284 | |
|---|
| 285 | <!--- ************************************************************* ---> |
|---|
| 286 | |
|---|
| 287 | <cffunction name="testProxyRequest" access="public" returntype="void" > |
|---|
| 288 | <cfscript> |
|---|
| 289 | var event = getRequestContext(); |
|---|
| 290 | |
|---|
| 291 | AssertFalse( event.isProxyRequest() ); |
|---|
| 292 | |
|---|
| 293 | event.setProxyRequest(); |
|---|
| 294 | AssertTrue( event.isProxyRequest() ); |
|---|
| 295 | </cfscript> |
|---|
| 296 | </cffunction> |
|---|
| 297 | |
|---|
| 298 | <!--- ************************************************************* ---> |
|---|
| 299 | |
|---|
| 300 | <cffunction name="testNoRender" access="public" returntype="void"> |
|---|
| 301 | <cfscript> |
|---|
| 302 | var event = getRequestContext(); |
|---|
| 303 | |
|---|
| 304 | event.NoRender(remove=true); |
|---|
| 305 | AssertFalse( event.isNoRender() ); |
|---|
| 306 | |
|---|
| 307 | event.NoRender(remove=false); |
|---|
| 308 | AssertTrue( event.isNoRender() ); |
|---|
| 309 | |
|---|
| 310 | </cfscript> |
|---|
| 311 | </cffunction> |
|---|
| 312 | |
|---|
| 313 | <!--- ************************************************************* ---> |
|---|
| 314 | |
|---|
| 315 | <cffunction name="testgetEventName" access="public" returntype="void" output="false"> |
|---|
| 316 | <cfscript> |
|---|
| 317 | var event = getRequestContext(); |
|---|
| 318 | var test = props.eventName; |
|---|
| 319 | |
|---|
| 320 | assertEquals( test, event.getEventName() ); |
|---|
| 321 | |
|---|
| 322 | </cfscript> |
|---|
| 323 | </cffunction> |
|---|
| 324 | |
|---|
| 325 | <!--- ************************************************************* ---> |
|---|
| 326 | |
|---|
| 327 | <cffunction name="testgetSelf" access="public" output="false" returntype="void"> |
|---|
| 328 | <cfscript> |
|---|
| 329 | var event = getRequestContext(); |
|---|
| 330 | var test = props.eventname; |
|---|
| 331 | |
|---|
| 332 | assertEquals( "index.cfm?#test#=", event.getSelf() ); |
|---|
| 333 | |
|---|
| 334 | </cfscript> |
|---|
| 335 | </cffunction> |
|---|
| 336 | |
|---|
| 337 | <!--- ************************************************************* ---> |
|---|
| 338 | |
|---|
| 339 | <cffunction name="testEventCacheableEntry" access="public" output="false" returntype="void"> |
|---|
| 340 | <cfscript> |
|---|
| 341 | var event = getRequestContext(); |
|---|
| 342 | var centry = structnew(); |
|---|
| 343 | |
|---|
| 344 | AssertFalse( event.isEventCacheable(), "event cacheable"); |
|---|
| 345 | |
|---|
| 346 | centry.cacheable = true; |
|---|
| 347 | centry.test = true; |
|---|
| 348 | |
|---|
| 349 | event.setEventCacheableEntry(centry); |
|---|
| 350 | AssertTrue( event.isEventCacheable(), "event cacheable 2"); |
|---|
| 351 | AssertEquals(centry, event.getEventCacheableEntry() ); |
|---|
| 352 | |
|---|
| 353 | </cfscript> |
|---|
| 354 | </cffunction> |
|---|
| 355 | |
|---|
| 356 | <!--- ************************************************************* ---> |
|---|
| 357 | |
|---|
| 358 | <cffunction name="testViewCacheableEntry" access="public" output="false" returntype="void"> |
|---|
| 359 | <cfscript> |
|---|
| 360 | var event = getRequestContext(); |
|---|
| 361 | var centry = structnew(); |
|---|
| 362 | |
|---|
| 363 | AssertFalse( event.isViewCacheable(), "view cacheable"); |
|---|
| 364 | |
|---|
| 365 | centry.cacheable = true; |
|---|
| 366 | centry.test = true; |
|---|
| 367 | |
|---|
| 368 | event.setViewCacheableEntry(centry); |
|---|
| 369 | AssertTrue( event.isViewCacheable(), "view cacheable 2"); |
|---|
| 370 | AssertEquals(centry, event.getViewCacheableEntry() ); |
|---|
| 371 | |
|---|
| 372 | </cfscript> |
|---|
| 373 | </cffunction> |
|---|
| 374 | |
|---|
| 375 | <!--- ************************************************************* ---> |
|---|
| 376 | |
|---|
| 377 | <cffunction name="testRoutedStruct" access="public" output="false" returntype="void"> |
|---|
| 378 | <cfscript> |
|---|
| 379 | var event = getRequestContext(); |
|---|
| 380 | var routedStruct = structnew(); |
|---|
| 381 | |
|---|
| 382 | routedStruct.page = "aboutus"; |
|---|
| 383 | routedStruct.day = "13"; |
|---|
| 384 | |
|---|
| 385 | event.setRoutedStruct(routedStruct); |
|---|
| 386 | |
|---|
| 387 | AssertEquals(event.getRoutedStruct(),routedStruct); |
|---|
| 388 | |
|---|
| 389 | </cfscript> |
|---|
| 390 | </cffunction> |
|---|
| 391 | |
|---|
| 392 | <cffunction name="testSES" access="public" output="false" returntype="void"> |
|---|
| 393 | <cfscript> |
|---|
| 394 | var event = getRequestContext(); |
|---|
| 395 | base = "http://www.luismajano.com/index.cfm"; |
|---|
| 396 | |
|---|
| 397 | event.setsesBaseURL(base); |
|---|
| 398 | assertEquals( event.getsesBaseURL(), base ); |
|---|
| 399 | |
|---|
| 400 | event.setisSES(true); |
|---|
| 401 | assertEquals( event.isSES(), true ); |
|---|
| 402 | |
|---|
| 403 | |
|---|
| 404 | </cfscript> |
|---|
| 405 | </cffunction> |
|---|
| 406 | |
|---|
| 407 | <cffunction name="testBuildLink" access="public" output="false" returntype="void"> |
|---|
| 408 | <cfscript> |
|---|
| 409 | var event = getRequestContext(); |
|---|
| 410 | base = "http://www.luismajano.com/index.cfm"; |
|---|
| 411 | basessl = "https://www.luismajano.com/index.cfm"; |
|---|
| 412 | |
|---|
| 413 | event.setisSES(false); |
|---|
| 414 | testurl = event.buildLink('general.index'); |
|---|
| 415 | AssertEquals(testurl, "index.cfm?event=general.index" ); |
|---|
| 416 | |
|---|
| 417 | event.setisSES(true); |
|---|
| 418 | event.setsesBaseURL(base); |
|---|
| 419 | testurl = event.buildLink('general/index'); |
|---|
| 420 | AssertEquals(testurl, base & "/general/index" ); |
|---|
| 421 | |
|---|
| 422 | event.setisSES(true); |
|---|
| 423 | event.setsesBaseURL(base); |
|---|
| 424 | testurl = event.buildLink(linkto='general/index',ssl=true); |
|---|
| 425 | AssertEquals(testurl, basessl & "/general/index" ); |
|---|
| 426 | |
|---|
| 427 | </cfscript> |
|---|
| 428 | </cffunction> |
|---|
| 429 | |
|---|
| 430 | <cffunction name="testRenderData" access="public" output="false" returntype="void"> |
|---|
| 431 | <cfscript> |
|---|
| 432 | var event = getRequestContext(); |
|---|
| 433 | |
|---|
| 434 | AssertEquals( event.getRenderData(), structnew()); |
|---|
| 435 | |
|---|
| 436 | event.renderData('JSON',"[1,2,3,4]"); |
|---|
| 437 | |
|---|
| 438 | test = structnew(); |
|---|
| 439 | test.type = "JSON"; |
|---|
| 440 | test.data = "[1,2,3,4]"; |
|---|
| 441 | test.contenttype="text/plain"; |
|---|
| 442 | |
|---|
| 443 | AssertEquals( event.getRenderData(), test); |
|---|
| 444 | |
|---|
| 445 | </cfscript> |
|---|
| 446 | </cffunction> |
|---|
| 447 | |
|---|
| 448 | |
|---|
| 449 | </cfcomponent> |
|---|