2014-01-08 21:51:11 +01:00
|
|
|
<?php
|
2014-01-23 17:37:20 +01:00
|
|
|
|
2014-01-08 21:51:11 +01:00
|
|
|
class TestHelper
|
|
|
|
{
|
|
|
|
public static function loginUser()
|
|
|
|
{
|
|
|
|
$authAdapter = Application_Model_Auth::getAuthAdapter();
|
|
|
|
|
2022-03-14 11:15:04 +01:00
|
|
|
// pass to the adapter the submitted username and password
|
2014-01-08 21:51:11 +01:00
|
|
|
$authAdapter->setIdentity('admin')
|
2022-01-23 19:15:55 +01:00
|
|
|
->setCredential('admin');
|
2014-01-08 21:51:11 +01:00
|
|
|
|
|
|
|
$auth = Zend_Auth::getInstance();
|
|
|
|
$result = $auth->authenticate($authAdapter);
|
|
|
|
if ($result->isValid()) {
|
2022-03-14 11:15:04 +01:00
|
|
|
// all info about this user from the login table omit only the password
|
2014-01-08 21:51:11 +01:00
|
|
|
$userInfo = $authAdapter->getResultRowObject(null, 'password');
|
|
|
|
|
2022-03-14 11:15:04 +01:00
|
|
|
// the default storage is a session with namespace Zend_Auth
|
2014-01-08 21:51:11 +01:00
|
|
|
$authStorage = $auth->getStorage();
|
|
|
|
$authStorage->write($userInfo);
|
|
|
|
}
|
|
|
|
}
|
2014-01-23 17:37:20 +01:00
|
|
|
|
|
|
|
public static function getDbZendConfig()
|
|
|
|
{
|
2017-02-20 21:47:53 +01:00
|
|
|
$config = Config::getConfig();
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2014-01-23 17:37:20 +01:00
|
|
|
return new Zend_Config(
|
2021-10-11 16:10:47 +02:00
|
|
|
[
|
2022-02-04 15:03:01 +01:00
|
|
|
'host' => $config['dsn']['host'],
|
|
|
|
'port' => $config['dsn']['port'],
|
2021-10-11 16:10:47 +02:00
|
|
|
'dbname' => $config['dsn']['database'],
|
2017-02-20 21:47:53 +01:00
|
|
|
'username' => $config['dsn']['username'],
|
2021-10-11 16:10:47 +02:00
|
|
|
'password' => $config['dsn']['password'],
|
|
|
|
]
|
2014-01-23 17:37:20 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function installTestDatabase()
|
|
|
|
{
|
2022-03-14 11:15:04 +01:00
|
|
|
// We need to load the config before our app bootstrap runs. The config
|
|
|
|
// is normally
|
2014-01-23 17:37:20 +01:00
|
|
|
$CC_CONFIG = Config::getConfig();
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2022-02-04 15:03:01 +01:00
|
|
|
$dbhost = $CC_CONFIG['dsn']['host'];
|
|
|
|
$dbport = $CC_CONFIG['dsn']['port'];
|
|
|
|
$dbname = $CC_CONFIG['dsn']['database'];
|
2014-01-23 17:37:20 +01:00
|
|
|
$dbuser = $CC_CONFIG['dsn']['username'];
|
|
|
|
$dbpasswd = $CC_CONFIG['dsn']['password'];
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2022-04-18 20:34:38 +02:00
|
|
|
AirtimeInstall::createDatabase();
|
|
|
|
AirtimeInstall::CreateDatabaseTables($dbuser, $dbpasswd, $dbname, $dbhost, $dbport);
|
2014-01-23 17:37:20 +01:00
|
|
|
}
|
2014-01-23 23:04:29 +01:00
|
|
|
|
|
|
|
public static function setupZendBootstrap()
|
|
|
|
{
|
2022-02-04 11:00:41 +01:00
|
|
|
$application = new Zend_Application(APPLICATION_ENV, CONFIG_PATH . '/application.ini');
|
2014-01-23 23:04:29 +01:00
|
|
|
$application->bootstrap();
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2014-01-23 23:04:29 +01:00
|
|
|
return $application;
|
|
|
|
}
|
|
|
|
}
|