Hi Luis,
Sure. Here is the code in my test case:
component extends=‘coldbox.system.testing.BaseInterceptorTest’ interceptor=‘modules.saas.interceptors.security’ {
public void function setUp() {
// Call the super setup method to setup the app.
super.setup();
// Create the security service that we’re going to test.
securityService = getMockBox().createMock(“modules.saas.model.security.securityService”);
// Mock the get model method in the interceptor to return the security service.
Interceptor.$(“getModel”, securityService);
// Mock the required logging behaviour.
// TODO: I don’t like having to mock this, it SHOULD be part of the ColdBox core, speak to Luis about it.
Interceptor.$property(propertyname=‘log’, mock=mockLogger);
MockLogger.$(“info”);
}
public void function testRememberMeSuccess() {
// Mock the return structure for the security service.
local.return = {
issuccess = true,
message = ‘We remembered this user some user.’
};
// Mock that the security service will a sucessful result struct.
securityService.$(‘rememberMeLogin’, local.return);
// Clear the properties for the mock event.
mockRequestContext.clearCollection();
// Call the interceptor with the mock event.
Interceptor.sessionStart(mockRequestContext, ‘’);
}
public void function testRememberMeFailed() {
// Mock the return structure for the security service.
local.return = {
issuccess = false,
message = ‘The user doesnt appear to have a remember me cookie.’
};
// Mock that the security service will a sucessful result struct.
securityService.$(‘rememberMeLogin’, local.return);
// Clear the properties for the mock event.
mockRequestContext.clearCollection();
// Call the interceptor with the mock event.
Interceptor.sessionStart(mockRequestContext, ‘’);
}
}
And here is the code it’s testing.
component extends=“coldbox.system.interceptors.Security” {
public void function configure () {
// Configure the super class.
super.configure();
}
public void function SessionStart() {
// Ask the security service to try and login any remember me cookies.
local.remember_me_login_result = getModel(‘security.SecurityService’).rememberMeLogin();
// Check to see if the login passed or not.
if (local.remember_me_login_result.issuccess) {
// We logged the user in as they’d asked us to remember them.
// Put a log note about this as it’s an invisible action.
log.info(“User Remembered: #local.remember_me_login_result.message#”);
} else {
// We didn’t remember who the user was or log them in automaticaly.
// Put a log note about this as it’s an invisible action.
log.info(“User Not Remembered: #local.remember_me_login_result.message#”);
}
}
}
This, as it stands works just fine, but notice how I have to explicitly mock the ‘log’ property and ‘info’ methods in my setup?
Robert