-
-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathMockRequestContext.cfc
More file actions
59 lines (55 loc) · 1.65 KB
/
MockRequestContext.cfc
File metadata and controls
59 lines (55 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
* A mock request context used for integration testing via TestBox
*/
component
extends ="coldbox.system.web.context.RequestContext"
serializable=false
accessors ="true"
{
/**
* Set an HTTP Header
*
* return RequestContext
*
* @statusCode.hint the status code
* @name.hint The header name
* @value.hint The header value
* @charset.hint The charset to use, defaults to UTF-8
*/
function setHTTPHeader( statusCode, statusText = "", name, value = "" ){
// status code?
if ( !isNull( arguments.statusCode ) ) {
setStatusCode( arguments.statusCode );
}
// Name Exists
else if ( structKeyExists( arguments, "name" ) ) {
var headers = getValue( "cbox_headers", {} );
headers[ lCase( arguments.name ) ] = arguments.value;
// Keep variables.responseHeaders in sync so getResponseHeaders() works in tests
variables.responseHeaders[ arguments.name ] = arguments.value;
setValue( "cbox_headers", headers );
} else {
throw(
message = "Invalid header arguments",
detail = "Pass in either a statusCode or name argument",
type = "RequestContext.InvalidHTTPHeaderParameters"
);
}
return this;
}
/**
* Set the request timeout for the request. In mock mode, we set it as a property
* and we ignore the setting
*
* @seconds The number of seconds as a time limit
*
* @return MockRequestContext
*/
MockRequestContext function setRequestTimeout( required numeric seconds ){
variables.requestTimeout = arguments.seconds;
return this;
}
}