我正在为 HippoCMS 的组件编写单元测试,但是我无法解决如何伪造 Repository 对象来模拟 persistFormMap 数据。
我遵循了基本的 HST-2 表单建议来实际检索请求数据(http://www.onehippo.org/library/concepts/component-development/hst-2-forms.html),但是我没有找到模拟/伪造 getWritableSession 的 Repository 部分(从 persistFormMap() 调用)以放入假组件管理器的简单方法。
public static Session getWritableSession() throws RepositoryException {
if (HstServices.isAvailable()) {
Credentials defaultCredentials = HstServices.getComponentManager().getComponent(Credentials.class.getName() + ".writable");
Repository repository = HstServices.getComponentManager().getComponent(Repository.class.getName());
Session session = null;
if (repository != null) {
if (defaultCredentials != null) {
session = repository.login(defaultCredentials);
} else {
session = repository.login();
}
}
return session;
}
有没有办法在没有persistFormMap() 的情况下获取提交的数据?或者一种正确伪造 repo 的方法(希望不是我在文档中简单查看过的东西)。