From 633e348ac4eb12ae650037d0f3364acff7a68f48 Mon Sep 17 00:00:00 2001 From: David Levin Date: Wed, 25 Feb 2026 20:31:35 -0800 Subject: [PATCH 1/3] Fix: getResponseHeaders() returns empty struct after setup() MockRequestContext.getResponseHeaders() always returns an empty struct {} in integration tests, even after calling setHTTPHeader() with named headers. This causes test assertions on response headers to fail unexpectedly when setup() is called between tests. --- .../mock/web/context/MockRequestContext.cfc | 2 ++ .../specs/web/context/RequestContextTest.cfc | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/system/testing/mock/web/context/MockRequestContext.cfc b/system/testing/mock/web/context/MockRequestContext.cfc index 9ce3ba013..4d450bf96 100644 --- a/system/testing/mock/web/context/MockRequestContext.cfc +++ b/system/testing/mock/web/context/MockRequestContext.cfc @@ -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 + variables.responseHeaders[ arguments.name ] = arguments.value; setValue( "cbox_headers", headers ); } else { throw( diff --git a/tests/specs/web/context/RequestContextTest.cfc b/tests/specs/web/context/RequestContextTest.cfc index 5d30c36e0..f3541afcd 100755 --- a/tests/specs/web/context/RequestContextTest.cfc +++ b/tests/specs/web/context/RequestContextTest.cfc @@ -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" ); + } + function testGetHTTPContent(){ var event = getRequestContext(); test = event.getHTTPContent(); From a48ead9bc7f42226edeb893f66c5293d0921ac57 Mon Sep 17 00:00:00 2001 From: Luis Majano Date: Thu, 19 Mar 2026 11:30:24 +0100 Subject: [PATCH 2/3] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- system/testing/mock/web/context/MockRequestContext.cfc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/testing/mock/web/context/MockRequestContext.cfc b/system/testing/mock/web/context/MockRequestContext.cfc index 4d450bf96..8b0bb0d2f 100644 --- a/system/testing/mock/web/context/MockRequestContext.cfc +++ b/system/testing/mock/web/context/MockRequestContext.cfc @@ -29,7 +29,7 @@ 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 + // Keep variables.responseHeaders in sync so getResponseHeaders() works in tests variables.responseHeaders[ arguments.name ] = arguments.value; setValue( "cbox_headers", headers ); } else { From 45ae01e05535ed6a4f058629683ad902a5776c74 Mon Sep 17 00:00:00 2001 From: Luis Majano Date: Thu, 19 Mar 2026 11:30:55 +0100 Subject: [PATCH 3/3] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../specs/web/context/RequestContextTest.cfc | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/specs/web/context/RequestContextTest.cfc b/tests/specs/web/context/RequestContextTest.cfc index f3541afcd..0b9e4bf9b 100755 --- a/tests/specs/web/context/RequestContextTest.cfc +++ b/tests/specs/web/context/RequestContextTest.cfc @@ -591,24 +591,24 @@ 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" ); - } + 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" ); + } function testGetHTTPContent(){ var event = getRequestContext();