Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions system/testing/mock/web/context/MockRequestContext.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ component
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
Comment thread
lmajano marked this conversation as resolved.
Outdated
variables.responseHeaders[ arguments.name ] = arguments.value;
setValue( "cbox_headers", headers );
} else {
throw(
Expand Down
19 changes: 19 additions & 0 deletions tests/specs/web/context/RequestContextTest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,25 @@ component extends="coldbox.system.testing.BaseModelTest" {
event.setHTTPHeader( name = "expires", value = "#now()#" );
}

function testMockRequestContextPopulatesResponseHeaders(){
// MockRequestContext.setHTTPHeader() should populate variables.responseHeaders
// so that getResponseHeaders() works correctly in integration tests
var mockEvent = getMockBox().createMock( "coldbox.system.testing.mock.web.context.MockRequestContext" );
mockEvent.init( properties = props, controller = mockController );

// Set custom headers
mockEvent.setHTTPHeader( name = "x-custom-header", value = "test-value" );
mockEvent.setHTTPHeader( name = "cached-data", value = "false" );

// getResponseHeaders() should return the headers that were set
var headers = mockEvent.getResponseHeaders();

expect( headers ).toHaveKey( "x-custom-header" );
expect( headers[ "x-custom-header" ] ).toBe( "test-value" );
expect( headers ).toHaveKey( "cached-data" );
expect( headers[ "cached-data" ] ).toBe( "false" );
}
Comment thread
lmajano marked this conversation as resolved.
Outdated

function testGetHTTPContent(){
var event = getRequestContext();
test = event.getHTTPContent();
Expand Down
Loading