Skip to content

Commit 386b695

Browse files
committed
Update tests
Updated the tests.cfm file and moved the functions to a new CFC named TestRunner so that adobe wouldn't throw the duplicate routine error
1 parent 7d8118c commit 386b695

2 files changed

Lines changed: 76 additions & 77 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
component {
2+
// Setup the test environment
3+
function setTestboxEnvironment() {
4+
// creating backup for original environment
5+
if (structKeyExists(server, "boxlang")) {
6+
application.$$$wheels = {}
7+
for (local.key in application.wheels) {
8+
if (IsSimpleValue(application.wheels[local.key]) || IsArray(application.wheels[local.key]) || IsStruct(application.wheels[local.key])) {
9+
application.$$$wheels[local.key] = application.wheels[local.key]
10+
}
11+
}
12+
} else {
13+
application.$$$wheels = Duplicate(application.wheels)
14+
}
15+
16+
// load testbox routes
17+
application.wo.$include(template = "/tests/routes.cfm")
18+
application.wo.$setNamedRoutePositions()
19+
20+
local.AssetPath = "/tests/_assets/"
21+
22+
application.wo.set(rewriteFile = "index.cfm")
23+
application.wo.set(controllerPath = local.AssetPath & "controllers")
24+
application.wo.set(viewPath = local.AssetPath & "views")
25+
application.wo.set(modelPath = local.AssetPath & "models")
26+
application.wo.set(wheelsComponentPath = "/wheels")
27+
28+
/* turn off default validations for testing */
29+
application.wheels.automaticValidations = false
30+
application.wheels.assetQueryString = false
31+
application.wheels.assetPaths = false
32+
33+
/* redirections should always delay when testing */
34+
application.wheels.functions.redirectTo.delay = true
35+
36+
/* enable transactions for proper test isolation */
37+
application.wheels.transactionMode = "commit"
38+
39+
/* turn off request query caching */
40+
application.wheels.cacheQueriesDuringRequest = false
41+
42+
// CSRF
43+
application.wheels.csrfCookieName = "_wheels_test_authenticity"
44+
application.wheels.csrfCookieEncryptionAlgorithm = "AES"
45+
application.wheels.csrfCookieEncryptionSecretKey = GenerateSecretKey("AES")
46+
application.wheels.csrfCookieEncryptionEncoding = "Base64"
47+
48+
// Setup CSRF token and cookie. The cookie can always be in place, even when the session-based CSRF storage is being
49+
// tested.
50+
dummyController = application.wo.controller("dummy")
51+
csrfToken = dummyController.$generateCookieAuthenticityToken()
52+
53+
cookie[application.wheels.csrfCookieName] = Encrypt(
54+
SerializeJSON({authenticityToken = csrfToken}),
55+
application.wheels.csrfCookieEncryptionSecretKey,
56+
application.wheels.csrfCookieEncryptionAlgorithm,
57+
application.wheels.csrfCookieEncryptionEncoding
58+
)
59+
if(structKeyExists(url, "db") && listFind("mysql,sqlserver,postgres,h2", url.db)){
60+
application.wheels.dataSourceName = "wheelstestdb_" & url.db;
61+
} else if (application.wheels.coreTestDataSourceName eq "|datasourceName|") {
62+
application.wheels.dataSourceName = "wheelstestdb";
63+
} else {
64+
application.wheels.dataSourceName = application.wheels.coreTestDataSourceName;
65+
}
66+
application.testenv.db = application.wo.$dbinfo(datasource = application.wheels.dataSourceName, type = "version")
67+
68+
local.populate = StructKeyExists(url, "populate") ? url.populate : true
69+
if (local.populate) {
70+
include "/tests/populate.cfm"
71+
}
72+
}
73+
}

templates/base/src/tests/runner.cfm

Lines changed: 3 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@
104104
);
105105
}
106106
107-
setTestboxEnvironment()
107+
// Sets up the test environment
108+
local.testRunner = new tests.TestRunner();
109+
local.testRunner.setTestboxEnvironment()
108110
109111
if (!structKeyExists(url, "format") || url.format eq "html") {
110112
// Determine reporter for HTML format
@@ -256,80 +258,4 @@
256258
type = "App";
257259
include "/wheels/tests_testbox/html.cfm";
258260
}
259-
260-
private function setTestboxEnvironment() {
261-
// creating backup for original environment
262-
if (structKeyExists(server, "boxlang")) {
263-
application.$$$wheels = $duplicateWheelsEnvironment(application.wheels)
264-
} else {
265-
application.$$$wheels = Duplicate(application.wheels)
266-
}
267-
268-
// load testbox routes
269-
application.wo.$include(template = "/tests/routes.cfm")
270-
application.wo.$setNamedRoutePositions()
271-
272-
local.AssetPath = "/tests/_assets/"
273-
274-
application.wo.set(rewriteFile = "index.cfm")
275-
application.wo.set(controllerPath = local.AssetPath & "controllers")
276-
application.wo.set(viewPath = local.AssetPath & "views")
277-
application.wo.set(modelPath = local.AssetPath & "models")
278-
application.wo.set(wheelsComponentPath = "/wheels")
279-
280-
/* turn off default validations for testing */
281-
application.wheels.automaticValidations = false
282-
application.wheels.assetQueryString = false
283-
application.wheels.assetPaths = false
284-
285-
/* redirections should always delay when testing */
286-
application.wheels.functions.redirectTo.delay = true
287-
288-
/* enable transactions for proper test isolation */
289-
application.wheels.transactionMode = "commit"
290-
291-
/* turn off request query caching */
292-
application.wheels.cacheQueriesDuringRequest = false
293-
294-
// CSRF
295-
application.wheels.csrfCookieName = "_wheels_test_authenticity"
296-
application.wheels.csrfCookieEncryptionAlgorithm = "AES"
297-
application.wheels.csrfCookieEncryptionSecretKey = GenerateSecretKey("AES")
298-
application.wheels.csrfCookieEncryptionEncoding = "Base64"
299-
300-
// Setup CSRF token and cookie. The cookie can always be in place, even when the session-based CSRF storage is being
301-
// tested.
302-
dummyController = application.wo.controller("dummy")
303-
csrfToken = dummyController.$generateCookieAuthenticityToken()
304-
305-
cookie[application.wheels.csrfCookieName] = Encrypt(
306-
SerializeJSON({authenticityToken = csrfToken}),
307-
application.wheels.csrfCookieEncryptionSecretKey,
308-
application.wheels.csrfCookieEncryptionAlgorithm,
309-
application.wheels.csrfCookieEncryptionEncoding
310-
)
311-
if(structKeyExists(url, "db") && listFind("mysql,sqlserver,postgres,h2", url.db)){
312-
application.wheels.dataSourceName = "wheelstestdb_" & url.db;
313-
} else if (application.wheels.coreTestDataSourceName eq "|datasourceName|") {
314-
application.wheels.dataSourceName = "wheelstestdb";
315-
} else {
316-
application.wheels.dataSourceName = application.wheels.coreTestDataSourceName;
317-
}
318-
application.testenv.db = application.wo.$dbinfo(datasource = application.wheels.dataSourceName, type = "version")
319-
320-
local.populate = StructKeyExists(url, "populate") ? url.populate : true
321-
if (local.populate) {
322-
include "/tests/populate.cfm"
323-
}
324-
}
325-
326-
private function $duplicateWheelsEnvironment(required struct original) {
327-
local.backup = {}
328-
for (local.key in arguments.original) {
329-
if (IsSimpleValue(arguments.original[local.key]) || IsArray(arguments.original[local.key]) || IsStruct(arguments.original[local.key])) {
330-
local.backup[local.key] = arguments.original[local.key]
331-
}
332-
}
333-
return local.backup
334-
}
335261
</cfscript>

0 commit comments

Comments
 (0)