【发布时间】:2019-01-14 08:10:35
【问题描述】:
我正在尝试为我在 Lucee 4.5 上运行的 ColdBox 应用程序编写一个单元测试,使用 testbox 为一个包含 cfhtmlhead() 调用的函数。
不幸的是,通常使用该函数附加到 HTML 输出的 <head> 部分的字符串被附加到单元测试的输出中,导致测试失败。
cfhtmlhead() 的输出显然被写入了一个特殊的缓冲区。根据blog post,可以清除该缓冲区。此处显示的示例函数如下所示:
function clearHeaderBuffer() {
local.out = getPageContext().getOut();
while (getMetaData(local.out).getName() is "coldfusion.runtime.NeoBodyContent") {
local.out = local.out.getEnclosingWriter();
}
local.method = local.out.getClass().getDeclaredMethod("initHeaderBuffer", arrayNew(1));
local.method.setAccessible(true);
local.method.invoke(local.out, arrayNew(1));
}
虽然这篇博文是为 Adobe ColdFusion 编写的,但它在 Lucee 中的工作方式显然不同。
通过转储local.out,我看到该对象有一个方法resetHTMLHead()。但是调用该方法似乎也不起作用(即使相关的getHTMLHead() 方法从cfhtmlhead() 调用输出字符串)。
那么,如何在 Lucee 中重置头缓冲区?
【问题讨论】:
标签: testbox unit-testing cfml lucee testbox