function testLogin($service = 'http://localhost:3000', $application_name = 'test_client', $user_agent = 'test_client/0.1', $verify_peer = false, $api_key = '01234-56789-01234-56789-01234-56789-01234-56789')
{
    /*
     * Initialise the Workbooks API object
     */
    $service_params = array('application_name' => $application_name, 'user_agent' => $user_agent, 'logger_callback' => array('WorkbooksApi', 'logAllToStdout'), 'connect_timeout' => 120, 'request_timeout' => 120, 'verify_peer' => $verify_peer);
    if (isset($service)) {
        $service_params['service'] = $service;
    }
    $workbooks = new WorkbooksApi($service_params);
    /*
     * Connect to the service and login
     */
    $login_params = array('api_key' => $api_key);
    $workbooks->log('login commences', __FILE__, 'debug');
    $login = $workbooks->login($login_params);
    if ($login['http_status'] != WorkbooksApi::HTTP_STATUS_OK) {
        $workbooks->log('Login failed.', $login, 'error');
        exit($exit_error);
    }
    /*
     * We now have a valid logged-in session.
     */
    $workbooks->log('login complete', __FILE__, 'info');
    return $workbooks;
}
function testLogin($service = 'http://localhost:3000', $application_name = 'test_client', $user_agent = 'test_client/0.1', $verify_peer = false, $username = '******', $password = '******')
{
    /*
     * Initialise the Workbooks API object
     */
    $service_params = array('application_name' => $application_name, 'user_agent' => $user_agent, 'logger_callback' => array('WorkbooksApi', 'logAllToStdout'), 'connect_timeout' => 120, 'request_timeout' => 120, 'verify_peer' => $verify_peer);
    if (isset($service)) {
        $service_params['service'] = $service;
    }
    $workbooks = new WorkbooksApi($service_params);
    /*
     * Connect to the service and login
     */
    $login_params = array('username' => $username, 'password' => $password);
    # If there is a database env variable use it to login
    if (getenv('DATABASE_ID')) {
        $login_params['logical_database_id'] = getenv('DATABASE_ID');
    }
    $workbooks->log('login commences', __FILE__, 'debug');
    $login = $workbooks->login($login_params);
    if ($login['http_status'] == WorkbooksApi::HTTP_STATUS_FORBIDDEN && $login['response']['failure_reason'] == 'no_database_selection_made') {
        //$workbooks->log('Database selection required', $login, 'error');
        /*
         * Multiple databases are available, and we must choose one. 
         * A good UI might remember the previously-selected database or use $databases to present a list of databases for the user to choose from. 
         */
        $default_database_id = $login['response']['default_database_id'];
        $databases = $login['response']['databases'];
        /*
         * For this test script we simply select the one which was the default when the user last logged in to the Workbooks user interface. This 
         * would not be correct for most API clients since the user's choice on any particular session should not necessarily change their choice 
         * for all of their API clients.
         */
        $login = $workbooks->login(array_merge($login_params, array('logical_database_id' => $default_database_id)));
    }
    if ($login['http_status'] != WorkbooksApi::HTTP_STATUS_OK) {
        $workbooks->log('Login failed.', $login, 'error');
        exit($exit_error);
    }
    /*
     * We now have a valid logged-in session.
     */
    $workbooks->log('login complete', __FILE__, 'info');
    return $workbooks;
}