|
| 1 | +component extends="wheels.WheelsTest" { |
| 2 | + |
| 3 | + function run() { |
| 4 | + |
| 5 | + g = application.wo |
| 6 | + |
| 7 | + describe("Tests that $buildDebugReloadUrl", () => { |
| 8 | + |
| 9 | + // --------------------------------------------------------------- |
| 10 | + // Root installs (webPath = "/") — these expectations are pinned |
| 11 | + // byte-for-byte to the output of the previous inline composition in |
| 12 | + // vendor/wheels/events/onrequestend/debug.cfm (raw cgi.script_name |
| 13 | + // + path_info + query string, then the rewriteFile strip and the |
| 14 | + // reload-param scrub). They must never change. |
| 15 | + // --------------------------------------------------------------- |
| 16 | + |
| 17 | + it("builds the reload URL for a root install with URL rewriting on", () => { |
| 18 | + rv = g.$buildDebugReloadUrl( |
| 19 | + scriptName = "/index.cfm", |
| 20 | + pathInfo = "/posts", |
| 21 | + queryString = "", |
| 22 | + webPath = "/", |
| 23 | + rewriteFile = "index.cfm" |
| 24 | + ) |
| 25 | + |
| 26 | + expect(rv).toBe("/posts?reload=") |
| 27 | + }) |
| 28 | + |
| 29 | + it("preserves the query string on a root install", () => { |
| 30 | + rv = g.$buildDebugReloadUrl( |
| 31 | + scriptName = "/index.cfm", |
| 32 | + pathInfo = "/posts", |
| 33 | + queryString = "page=2&sort=title", |
| 34 | + webPath = "/", |
| 35 | + rewriteFile = "index.cfm" |
| 36 | + ) |
| 37 | + |
| 38 | + expect(rv).toBe("/posts?page=2&sort=title&reload=") |
| 39 | + }) |
| 40 | + |
| 41 | + it("scrubs a leading ?reload= parameter from the query string", () => { |
| 42 | + rv = g.$buildDebugReloadUrl( |
| 43 | + scriptName = "/index.cfm", |
| 44 | + pathInfo = "/posts", |
| 45 | + queryString = "reload=true", |
| 46 | + webPath = "/", |
| 47 | + rewriteFile = "index.cfm" |
| 48 | + ) |
| 49 | + |
| 50 | + expect(rv).toBe("/posts?reload=") |
| 51 | + }) |
| 52 | + |
| 53 | + it("scrubs an &reload=<environment> parameter while keeping the rest of the query string", () => { |
| 54 | + rv = g.$buildDebugReloadUrl( |
| 55 | + scriptName = "/index.cfm", |
| 56 | + pathInfo = "/posts", |
| 57 | + queryString = "page=2&reload=development", |
| 58 | + webPath = "/", |
| 59 | + rewriteFile = "index.cfm" |
| 60 | + ) |
| 61 | + |
| 62 | + expect(rv).toBe("/posts?page=2&reload=") |
| 63 | + }) |
| 64 | + |
| 65 | + it("keeps rewriting-off root installs byte-identical to the previous inline composition", () => { |
| 66 | + // With URL rewriting off, path_info equals script_name (Lucee) so |
| 67 | + // nothing is appended; the rewriteFile strip leaves the bare query. |
| 68 | + rv = g.$buildDebugReloadUrl( |
| 69 | + scriptName = "/index.cfm", |
| 70 | + pathInfo = "/index.cfm", |
| 71 | + queryString = "controller=posts&action=index", |
| 72 | + webPath = "/", |
| 73 | + rewriteFile = "index.cfm" |
| 74 | + ) |
| 75 | + |
| 76 | + expect(rv).toBe("?controller=posts&action=index&reload=") |
| 77 | + }) |
| 78 | + |
| 79 | + it("handles an empty path_info (Adobe engines with rewriting off)", () => { |
| 80 | + rv = g.$buildDebugReloadUrl( |
| 81 | + scriptName = "/index.cfm", |
| 82 | + pathInfo = "", |
| 83 | + queryString = "controller=posts&action=index", |
| 84 | + webPath = "/", |
| 85 | + rewriteFile = "index.cfm" |
| 86 | + ) |
| 87 | + |
| 88 | + expect(rv).toBe("?controller=posts&action=index&reload=") |
| 89 | + }) |
| 90 | + |
| 91 | + // --------------------------------------------------------------- |
| 92 | + // Subfolder (subpath) installs — issue #3344. The base must come |
| 93 | + // from webPath, not raw cgi.script_name, so the emitted link never |
| 94 | + // contains the on-disk /public/ segment or the front controller. |
| 95 | + // --------------------------------------------------------------- |
| 96 | + |
| 97 | + it("honors webPath on a subfolder install (no /public/, no index.cfm)", () => { |
| 98 | + rv = g.$buildDebugReloadUrl( |
| 99 | + scriptName = "/wheelsproject1/public/index.cfm", |
| 100 | + pathInfo = "/posts", |
| 101 | + queryString = "", |
| 102 | + webPath = "/wheelsproject1/", |
| 103 | + rewriteFile = "index.cfm" |
| 104 | + ) |
| 105 | + |
| 106 | + expect(rv).toBe("/wheelsproject1/posts?reload=") |
| 107 | + expect(rv).notToInclude("/public/") |
| 108 | + expect(rv).notToInclude("index.cfm") |
| 109 | + }) |
| 110 | + |
| 111 | + it("honors a nested subpath webPath", () => { |
| 112 | + rv = g.$buildDebugReloadUrl( |
| 113 | + scriptName = "/team/site/public/index.cfm", |
| 114 | + pathInfo = "/posts/1", |
| 115 | + queryString = "page=2", |
| 116 | + webPath = "/team/site/", |
| 117 | + rewriteFile = "index.cfm" |
| 118 | + ) |
| 119 | + |
| 120 | + expect(rv).toBe("/team/site/posts/1?page=2&reload=") |
| 121 | + }) |
| 122 | + |
| 123 | + it("scrubs reload params on a subfolder install", () => { |
| 124 | + rv = g.$buildDebugReloadUrl( |
| 125 | + scriptName = "/wheelsproject1/public/index.cfm", |
| 126 | + pathInfo = "/posts", |
| 127 | + queryString = "reload=true", |
| 128 | + webPath = "/wheelsproject1/", |
| 129 | + rewriteFile = "index.cfm" |
| 130 | + ) |
| 131 | + |
| 132 | + expect(rv).toBe("/wheelsproject1/posts?reload=") |
| 133 | + }) |
| 134 | + |
| 135 | + // --------------------------------------------------------------- |
| 136 | + // Defensive fallbacks (early boot / error paths). |
| 137 | + // --------------------------------------------------------------- |
| 138 | + |
| 139 | + it("falls back to the raw script name when webPath is empty", () => { |
| 140 | + rv = g.$buildDebugReloadUrl( |
| 141 | + scriptName = "/wheelsproject1/public/index.cfm", |
| 142 | + pathInfo = "/posts", |
| 143 | + queryString = "", |
| 144 | + webPath = "", |
| 145 | + rewriteFile = "index.cfm" |
| 146 | + ) |
| 147 | + |
| 148 | + // Exactly what the previous inline composition produced. |
| 149 | + expect(rv).toBe("/wheelsproject1/public/posts?reload=") |
| 150 | + }) |
| 151 | + |
| 152 | + it("skips the rewriteFile strip when rewriteFile is empty", () => { |
| 153 | + rv = g.$buildDebugReloadUrl( |
| 154 | + scriptName = "/index.cfm", |
| 155 | + pathInfo = "/posts", |
| 156 | + queryString = "", |
| 157 | + webPath = "/", |
| 158 | + rewriteFile = "" |
| 159 | + ) |
| 160 | + |
| 161 | + expect(rv).toBe("/index.cfm/posts?reload=") |
| 162 | + }) |
| 163 | + |
| 164 | + it("defaults webPath and rewriteFile from application scope when omitted", () => { |
| 165 | + // The running test app is a root install: webPath "/" and |
| 166 | + // rewriteFile "index.cfm", so this must match the explicit |
| 167 | + // root-install case above. |
| 168 | + rv = g.$buildDebugReloadUrl( |
| 169 | + scriptName = "/index.cfm", |
| 170 | + pathInfo = "/posts", |
| 171 | + queryString = "" |
| 172 | + ) |
| 173 | + |
| 174 | + expect(rv).toBe("/posts?reload=") |
| 175 | + }) |
| 176 | + |
| 177 | + }) |
| 178 | + } |
| 179 | +} |
0 commit comments