PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/wheels/tests/controller/rendering/specified_layouts.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 184 lines | 146 code | 38 blank | 0 comment | 0 complexity | d42ba522f13b4d5d3385be865cd41938 MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent extends="wheelsMapping.Test">
  2. <cffunction name="setup">
  3. <cfset request.cgi.http_x_requested_with = "">
  4. </cffunction>
  5. <cffunction name="test_using_method">
  6. <cfset loc.args = {template="controller_layout_test"}>
  7. <cfset params = {controller="dummy", action="index"}>
  8. <cfset loc.controller = controller("dummy", params)>
  9. <cfset loc.controller.controller_layout_test = controller_layout_test>
  10. <cfset loc.controller.usesLayout(argumentCollection=loc.args)>
  11. <cfset loc.e = "index_layout">
  12. <cfset loc.r = loc.controller.$useLayout("index")>
  13. <cfset assert('loc.e eq loc.r')>
  14. <cfset loc.e = "show_layout">
  15. <cfset loc.r = loc.controller.$useLayout("show")>
  16. <cfset assert('loc.e eq loc.r')>
  17. <cfset loc.e = "true">
  18. <cfset loc.r = loc.controller.$useLayout("list")>
  19. <cfset assert('loc.e eq loc.r')>
  20. <cfset loc.args.usedefault = false>
  21. <cfset loc.controller.usesLayout(argumentCollection=loc.args)>
  22. <cfset loc.e = "false">
  23. <cfset loc.r = loc.controller.$useLayout("list")>
  24. <cfset assert('loc.e eq loc.r')>
  25. </cffunction>
  26. <cffunction name="test_ajax_request_with_no_layout_specified_should_fallback_to_template">
  27. <cfset request.cgi.http_x_requested_with = "XMLHTTPRequest">
  28. <cfset loc.args = {template="controller_layout_test"}>
  29. <cfset params = {controller="dummy", action="index"}>
  30. <cfset loc.controller = controller("dummy", params)>
  31. <cfset loc.controller.controller_layout_test = controller_layout_test>
  32. <cfset loc.controller.usesLayout(argumentCollection=loc.args)>
  33. <cfset loc.e = "index_layout">
  34. <cfset loc.r = loc.controller.$useLayout("index")>
  35. <cfset assert('loc.e eq loc.r')>
  36. </cffunction>
  37. <cffunction name="test_using_method_ajax">
  38. <cfset request.cgi.http_x_requested_with = "XMLHTTPRequest">
  39. <cfset loc.args = {template="controller_layout_test", ajax="controller_layout_test_ajax"}>
  40. <cfset params = {controller="dummy", action="index"}>
  41. <cfset loc.controller = controller("dummy", params)>
  42. <cfset loc.controller.controller_layout_test = controller_layout_test>
  43. <cfset loc.controller.controller_layout_test_ajax = controller_layout_test_ajax>
  44. <cfset loc.controller.usesLayout(argumentCollection=loc.args)>
  45. <cfset loc.e = "index_layout_ajax">
  46. <cfset loc.r = loc.controller.$useLayout("index")>
  47. <cfset assert('loc.e eq loc.r')>
  48. <cfset loc.e = "show_layout_ajax">
  49. <cfset loc.r = loc.controller.$useLayout("show")>
  50. <cfset assert('loc.e eq loc.r')>
  51. <cfset loc.e = "true">
  52. <cfset loc.r = loc.controller.$useLayout("list")>
  53. <cfset assert('loc.e eq loc.r')>
  54. <cfset loc.args.usedefault = false>
  55. <cfset loc.controller.usesLayout(argumentCollection=loc.args)>
  56. <cfset loc.e = "false">
  57. <cfset loc.r = loc.controller.$useLayout("list")>
  58. <cfset assert('loc.e eq loc.r')>
  59. </cffunction>
  60. <cffunction name="test_should_respect_exceptions">
  61. <cfset loc.args = {template="mylayout", except="index"}>
  62. <cfset params = {controller="dummy", action="index"}>
  63. <cfset loc.controller = controller("dummy", params)>
  64. <cfset loc.controller.usesLayout(argumentCollection=loc.args)>
  65. <cfset loc.e = "mylayout">
  66. <cfset loc.r = loc.controller.$useLayout("show")>
  67. <cfset assert('loc.e eq loc.r')>
  68. <cfset loc.e = "true">
  69. <cfset loc.r = loc.controller.$useLayout("index")>
  70. <cfset assert('loc.e eq loc.r')>
  71. <cfset loc.args.usedefault = false>
  72. <cfset loc.controller.usesLayout(argumentCollection=loc.args)>
  73. <cfset loc.e = "false">
  74. <cfset loc.r = loc.controller.$useLayout("index")>
  75. <cfset assert('loc.e eq loc.r')>
  76. </cffunction>
  77. <cffunction name="test_should_respect_exceptions_ajax">
  78. <cfset request.cgi.http_x_requested_with = "XMLHTTPRequest">
  79. <cfset loc.args = {template="mylayout", ajax="mylayout_ajax", except="index"}>
  80. <cfset params = {controller="dummy", action="index"}>
  81. <cfset loc.controller = controller("dummy", params)>
  82. <cfset loc.controller.usesLayout(argumentCollection=loc.args)>
  83. <cfset loc.e = "mylayout_ajax">
  84. <cfset loc.r = loc.controller.$useLayout("show")>
  85. <cfset assert('loc.e eq loc.r')>
  86. <cfset loc.e = "true">
  87. <cfset loc.r = loc.controller.$useLayout("index")>
  88. <cfset assert('loc.e eq loc.r')>
  89. <cfset loc.args.usedefault = false>
  90. <cfset loc.controller.usesLayout(argumentCollection=loc.args)>
  91. <cfset loc.e = "false">
  92. <cfset loc.r = loc.controller.$useLayout("index")>
  93. <cfset assert('loc.e eq loc.r')>
  94. </cffunction>
  95. <cffunction name="test_should_respect_only">
  96. <cfset loc.args = {template="mylayout", only="index"}>
  97. <cfset params = {controller="dummy", action="index"}>
  98. <cfset loc.controller = controller("dummy", params)>
  99. <cfset loc.controller.usesLayout(argumentCollection=loc.args)>
  100. <cfset loc.e = "true">
  101. <cfset loc.r = loc.controller.$useLayout("show")>
  102. <cfset assert('loc.e eq loc.r')>
  103. <cfset loc.e = "mylayout">
  104. <cfset loc.r = loc.controller.$useLayout("index")>
  105. <cfset assert('loc.e eq loc.r')>
  106. <cfset loc.args.usedefault = false>
  107. <cfset loc.controller.usesLayout(argumentCollection=loc.args)>
  108. <cfset loc.e = "false">
  109. <cfset loc.r = loc.controller.$useLayout("show")>
  110. <cfset assert('loc.e eq loc.r')>
  111. </cffunction>
  112. <cffunction name="test_should_respect_only_ajax">
  113. <cfset request.cgi.http_x_requested_with = "XMLHTTPRequest">
  114. <cfset loc.args = {template="mylayout", ajax="mylayout_ajax", only="index"}>
  115. <cfset params = {controller="dummy", action="index"}>
  116. <cfset loc.controller = controller("dummy", params)>
  117. <cfset loc.controller.usesLayout(argumentCollection=loc.args)>
  118. <cfset loc.e = "true">
  119. <cfset loc.r = loc.controller.$useLayout("show")>
  120. <cfset assert('loc.e eq loc.r')>
  121. <cfset loc.e = "mylayout_ajax">
  122. <cfset loc.r = loc.controller.$useLayout("index")>
  123. <cfset assert('loc.e eq loc.r')>
  124. <cfset loc.args.usedefault = false>
  125. <cfset loc.controller.usesLayout(argumentCollection=loc.args)>
  126. <cfset loc.e = "false">
  127. <cfset loc.r = loc.controller.$useLayout("show")>
  128. <cfset assert('loc.e eq loc.r')>
  129. </cffunction>
  130. <cffunction name="controller_layout_test">
  131. <cfif arguments.action eq "index">
  132. <cfreturn "index_layout">
  133. </cfif>
  134. <cfif arguments.action eq "show">
  135. <cfreturn "show_layout">
  136. </cfif>
  137. </cffunction>
  138. <cffunction name="controller_layout_test_ajax">
  139. <cfif arguments.action eq "index">
  140. <cfreturn "index_layout_ajax">
  141. </cfif>
  142. <cfif arguments.action eq "show">
  143. <cfreturn "show_layout_ajax">
  144. </cfif>
  145. </cffunction>
  146. </cfcomponent>