Exemplo n.º 1
0
 public function test_should_show_public_dot_404_dot_php()
 {
     $this->setMaximumRedirects(0);
     $this->get(AkConfig::getOption('testing_url') . '/action_pack/public/index.php?ak=invalid');
     $this->assertResponse(404);
     $this->assertText("Exception in InvalidController#index");
 }
Exemplo n.º 2
0
 public function index()
 {
     $this->base_dir = AK_BASE_DIR;
     $this->akelos_dir = AK_FRAMEWORK_DIR;
     $this->tasks_dir = AK_TASKS_DIR;
     $this->has_configuration = file_exists(AkConfig::getDir('config') . DS . 'config.php');
     $this->has_routes = file_exists(AkConfig::getDir('config') . DS . 'routes.php');
     $this->has_database = file_exists(AkConfig::getDir('config') . DS . 'database.yml');
     $this->using_root_path = $this->Request->getPath() == '/';
     $this->new_install = !$this->has_configuration || !$this->has_routes || $this->using_root_path;
     $this->environment = AK_ENVIRONMENT;
     $this->memcached_on = AkMemcache::isServerUp();
     $this->constants = AkDebug::get_constants();
     $this->langs = Ak::langs();
     $this->database_settings = Ak::getSettings('database', false);
     $this->server_user = trim(AK_WIN ? `ECHO %USERNAME%` : `whoami`);
     $this->local_ips = AkConfig::getOption('local_ips', array('localhost', '127.0.0.1', '::1'));
     $paths = array(AK_APP_DIR . DS . 'locales');
     $this->invalid_permissions = array();
     foreach ($paths as $path) {
         if (is_dir($path) && !@file_put_contents($path . DS . '__test_file')) {
             $this->invalid_permissions[] = $path;
         } else {
             @unlink($path . DS . '__test_file');
         }
     }
 }
Exemplo n.º 3
0
 function __construct()
 {
     if (!($this->webserver_enabled = AkConfig::getOption('webserver_enabled', false))) {
         return;
     }
     $this->url = AkConfig::getOption('testing_url') . '/active_resource/public/index.php?ak=http_requests';
     parent::__construct();
 }
Exemplo n.º 4
0
 static function getRegistered()
 {
     // we register a dictionary: mime_type => our_type
     // this is an ordered list, the first entry has top priority
     // say a client accepts different mime_types with the same 'q'uality-factor
     // we then won't just pop his first one, but our best match within this group
     // http://www.iana.org/assignments/media-types/
     $mime_types = AkConfig::getOption('mime_types', array('text/html' => 'html', 'application/xhtml+xml' => 'html', 'application/xml' => 'xml', 'text/xml' => 'xml', 'text/plain' => 'txt', 'text/css' => 'css', 'text/calendar' => 'ics', 'text/csv' => 'csv', 'text/javascript' => 'js', 'application/javascript' => 'js', 'application/x-javascript' => 'js', 'application/json' => 'json', 'text/x-json' => 'json', 'application/jsonrequest' => 'json', 'application/rss+xml' => 'rss', 'application/atom+xml' => 'atom', 'application/x-yaml' => 'yaml', 'text/yaml' => 'yaml', '*/*' => 'html', 'application/x-www-form-urlencoded' => 'html', 'multipart/form-data' => 'html', 'default' => 'html'));
     return $mime_types;
 }
Exemplo n.º 5
0
 public function test_all_session_handlers()
 {
     $cacheHandlers = array('cache_lite' => 1);
     if (!Ak::db() instanceof AkSqliteDbAdapter) {
         $cacheHandlers['akadodbcache'] = 2;
     }
     if (AkConfig::getOption('memcached_enabled', false)) {
         $cacheHandlers['akmemcache'] = 3;
     }
     $unitTests = array('_Test_open', '_Test_read_write', '_Test_destroy', '_Test_gc');
     foreach ($cacheHandlers as $class => $type) {
         foreach ($unitTests as $test) {
             $this->{$test}($type, $class);
         }
     }
 }
Exemplo n.º 6
0
 public function test_all_caches()
 {
     $cacheHandlers = array('cache_lite' => 1, 'akadodbcache' => 2);
     $memcacheEnabled = AkConfig::getOption('memcached_enabled', false);
     AkUnitTestSuite::createTestingDatabaseIfNotAvailable();
     if ($memcacheEnabled) {
         $cacheHandlers['akmemcache'] = 3;
     }
     $unitTests = array('_testInit', '_getAndSaveTests', '_removeTests', '_cleanTests');
     foreach ($cacheHandlers as $class => $type) {
         foreach ($unitTests as $test) {
             unset($this->Cache);
             $this->Cache = new AkCache();
             $this->{$test}($type, $class);
         }
         $this->Cache->clean($this->group);
     }
 }
Exemplo n.º 7
0
 public function init($options)
 {
     // Ak::getLogger('sessions')->info(__METHOD__);
     $this->default_options['secure'] = AK_PROTOCOL == 'https://';
     // 'session.cookie_domain' should be set to empty string for all local domain names,
     // not only for 'localhost' (but should not be empty for local IP addresses)
     if (strstr(AK_HOST, '.') === false) {
         $this->default_options['domain'] = '';
     }
     $this->options = array_merge($this->default_options, AkConfig::getOption('action_controller.session', array()));
     $this->options = array_merge($this->options, $options);
     $this->options['expire_after'] = time() + $this->options['expire_after'];
     $this->ensureSessionKey();
     $this->ensureSecretSecure();
     ini_set('session.use_cookies', '0');
     session_set_save_handler(array($this, 'open'), array($this, 'close'), array($this, 'read'), array($this, 'write'), array($this, 'destroy'), array($this, 'gc'));
     session_start();
     return true;
 }
Exemplo n.º 8
0
 public function test_all_caches()
 {
     $cacheHandlers = array('cache_lite' => 1, 'akadodbcache' => 2);
     $memcacheEnabled = AkConfig::getOption('memcached_enabled', AkMemcache::isServerUp());
     if ($memcacheEnabled) {
         $cacheHandlers['akmemcache'] = 3;
     }
     $unitTests = array('_test_cache_with_string_key', '_test_cache_with_string_key_cached');
     if ($this->controller->_CacheHandler instanceof AkCacheHandler) {
         foreach ($cacheHandlers as $class => $type) {
             $this->controller->_CacheHandler->setCacheStore($type);
             $this->_test_init();
             foreach ($unitTests as $test) {
                 $this->{$test}($class);
             }
         }
     } else {
         $this->fail('CacheHandler is not initialized. Please enable the caching system for the unit-test');
     }
 }
Exemplo n.º 9
0
 public function test_member_when_changed_default_restful_actions_and_path_names_not_specified()
 {
     $controller = 'messages';
     $default_path_names = AkConfig::getOption('resources_path_names', array('add' => 'add', 'edit' => 'edit'));
     AkConfig::setOption('resources_path_names', array('add' => 'nuevo', 'edit' => 'editar'));
     $add_options = array('action' => 'add', 'controller' => $controller);
     $add_path = '/' . $controller . '/nuevo';
     $edit_options = array('action' => 'edit', 'id' => 1, 'controller' => $controller);
     $edit_path = '/' . $controller . '/1/editar';
     $this->useRestfulRoutingMapper($controller);
     $this->assertRestfulRoutesFor($controller, array('path' => $add_path, 'method' => 'get'));
     $this->assertRestfulRoutesFor($controller, array('path' => $edit_path, 'method' => 'get'));
     AkConfig::setOption('resources_path_names', $default_path_names);
 }
Exemplo n.º 10
0
 public function logError($Exception)
 {
     if (!($Logger = Ak::getLogger())) {
         return;
     }
     $message = $Exception->getMessage() . "\n" . $Exception->getTraceAsString();
     $original_faltal_setting = AkConfig::getOption('logger.exit_on_fatal', true);
     $original_display_setting = AkConfig::getOption('logger.display_message', true);
     $original_mail_setting = AkConfig::getOption('logger.send_mails', true);
     AkConfig::setOption('logger.exit_on_fatal', false);
     AkConfig::setOption('logger.display_message', false);
     AkConfig::setOption('logger.send_mails', false);
     $Logger->fatal("\n" . get_class($Exception) . (empty($message) ? '' : ': (' . $message . ")") . "\n  ");
     AkConfig::setOption('logger.exit_on_fatal', $original_faltal_setting);
     AkConfig::setOption('logger.display_message', $original_display_setting);
     AkConfig::setOption('logger.send_mails', $original_mail_setting);
 }
Exemplo n.º 11
0
 public function __construct()
 {
     parent::__construct();
     $this->doc = new DOMDocument();
     $this->doc->loadXML('<testsuite/>');
     $this->root = $this->doc->documentElement;
     $base_path = defined('MAKELOS_BASE_DIR') ? MAKELOS_BASE_DIR : AK_BASE_DIR;
     $file_path = AkConfig::getOption('report_path', $base_path . DS . 'reports' . DS . 'units.xml');
     AkFileSystem::file_put_contents($file_path, "<?xml version=\"1.0\"?>\n", array('base_path' => $base_path));
     $this->_fp = @fopen($file_path, 'a');
 }
Exemplo n.º 12
0
 private function &_getControllerInstance()
 {
     $params = $this->getParams();
     if ($rebase_path = AkConfig::getOption('rebase_path', false)) {
         AkConfig::rebaseApp($rebase_path);
     }
     $module_details = $this->_getModuleDetailsFromParams($params);
     $controller_details = $this->_getControllerDetailsFromParamsAndModuleDetails($params, $module_details);
     $this->_includeModuleSharedController($module_details);
     $this->_includeController($controller_details);
     $this->_ensureControllerClassExists($controller_details);
     $Controller = new $controller_details['class_name'](array('controller' => true));
     $Controller->setModulePath($module_details['path']);
     $this->_linkSessionToController($Controller);
     return $Controller;
 }
Exemplo n.º 13
0
 public function test_should_get_not_get_default_option_if_already_set()
 {
     AkConfig::setOption('valid', 'yes');
     $this->assertEqual(AkConfig::getOption('valid', 'default'), 'yes');
 }
Exemplo n.º 14
0
 public function getActionSeparator()
 {
     return isset($this->action_separator) ? $this->action_separator : AkConfig::getOption('resource_action_separator', '/');
 }
Exemplo n.º 15
0
 public function __construct()
 {
     parent::__construct();
     $this->webserver_enabled = AkConfig::getOption('webserver_enabled', false);
 }
Exemplo n.º 16
0
 public function multiGlob($patterns = array(), $task_path = null)
 {
     $task_paths = empty($task_path) ? AkConfig::getOption('makelos_task_paths', array_merge($this->task_paths, array(dirname(__FILE__) . DS . 'tasks'))) : (array) $task_path;
     $glob_result = array();
     foreach ($patterns as $pattern) {
         foreach ($task_paths as $task_path) {
             $glob_result = array_merge($glob_result, glob($task_path . DS . $pattern));
         }
     }
     array_unique($glob_result);
     return array_diff($glob_result, array(''));
 }
Exemplo n.º 17
0
 /**
  * Use this to translate strings in the scope of your controller
  *
  * @see Ak::t
  */
 public function t($string, $array = null, $controller = null)
 {
     return Ak::t($string, $array, !empty($controller) ? $controller : AkConfig::getOption('locale_namespace', !empty($this->locale_namespace) ? $this->locale_namespace : (defined('AK_DEFAULT_LOCALE_NAMESPACE') ? AK_DEFAULT_LOCALE_NAMESPACE : AkInflector::underscore($this->getControllerName()))));
 }
Exemplo n.º 18
0
 static function checkIfTestingWebserverIsAccesible($options = array())
 {
     if (AkConfig::getOption('webserver_enabled', false)) {
         return;
     }
     if (!AK_WEB_REQUEST && file_exists($options['base_path'] . DS . 'ping.php')) {
         $uuid = Ak::uuid();
         file_put_contents($options['base_path'] . DS . 'akelos_test_ping_uuid.txt', $uuid);
         AkConfig::setOption('webserver_enabled', @file_get_contents(AkConfig::getOption('testing_url') . '/' . basename($options['base_path']) . '/ping.php') == $uuid);
         unlink($options['base_path'] . DS . 'akelos_test_ping_uuid.txt');
     } else {
         AkConfig::setOption('webserver_enabled', false);
     }
 }
Exemplo n.º 19
0
 public function t($string, $array = null, $name_space = null)
 {
     return Ak::t($string, $array, !empty($name_space) ? $name_space : AkConfig::getOption('locale_namespace', !empty($this->locale_namespace) ? $this->locale_namespace : (defined('AK_DEFAULT_LOCALE_NAMESPACE') ? AK_DEFAULT_LOCALE_NAMESPACE : 'helpers')));
 }
Exemplo n.º 20
0
 public function setUp()
 {
     $this->_test_script = AkConfig::getOption('testing_url') . '/action_pack/public/database_sessions.php';
 }
Exemplo n.º 21
0
 private function _getExtraGenerators()
 {
     $result = array();
     if ($generator_paths = AkConfig::getOption('generator_paths', false)) {
         foreach ($generator_paths as $generator_path) {
             $result = array_merge($result, $this->_getGeneratorsInsidePath($generator_path));
         }
     }
     return $result;
 }
Exemplo n.º 22
0
defined('AK_ENVIRONMENT') || define('AK_ENVIRONMENT', 'testing');
defined('AK_BASE_DIR') || define('AK_BASE_DIR', str_replace(DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php', '', substr(AK_TEST_DIR, 0, -5)));
defined('AK_LOG_EVENTS') || define('AK_LOG_EVENTS', true);
defined('DS') || define('DS', DIRECTORY_SEPARATOR);
defined('AK_FRAMEWORK_DIR') || define('AK_FRAMEWORK_DIR', AK_BASE_DIR);
defined('AK_TESTING_NAMESPACE') || define('AK_TESTING_NAMESPACE', 'akelos');
defined('AK_TESTING_URL') || define('AK_TESTING_URL', 'http://akelos.tests');
include_once AK_FRAMEWORK_DIR . DS . 'autoload.php';
if (AK_CLI && !AK_WIN) {
    // will try to set the right mode for tmp folders, git does not kee trac of this for us
    foreach ((array) glob(AK_BASE_DIR . DS . 'tmp' . DS . '*' . DS . '*/') as $__folder) {
        `chmod 777 {$__folder}`;
    }
    unset($__folder);
}
if (!AkConfig::getOption('testing_url', false)) {
    AkConfig::setOption('testing_url', AK_TESTING_URL);
}
AkUnitTestSuite::checkIfTestingWebserverIsAccesible(array('base_path' => AK_TEST_DIR . DS . AK_TESTING_NAMESPACE));
AkUnitTestSuite::createTestingDatabaseIfNotAvailable();
AkUnitTestSuite::ensureTmpDirPermissions();
try {
    ob_start();
    if (!class_exists('BaseActionController')) {
        class BaseActionController extends AkActionController
        {
        }
    }
    if (!class_exists('ApplicationController')) {
        class ApplicationController extends BaseActionController
        {
Exemplo n.º 23
0
Arquivo: user.php Projeto: bermi/admin
 static function getSettingsNamespace()
 {
     return AK_TEST_MODE ? AkConfig::getOption('test_mode_settings_namespace', AK_DEFAULT_ADMIN_SETTINGS) : AK_DEFAULT_ADMIN_SETTINGS;
 }
Exemplo n.º 24
0
 public function handleFatalMessage($error_level, $message, $parameters = array())
 {
     if (AkConfig::getOption('logger.exit_on_fatal', true)) {
         exit(0);
     }
 }
Exemplo n.º 25
0
 public function skip()
 {
     $this->skipIf(!AkConfig::getOption('webserver_enabled', false), '[' . get_class($this) . '] Web server not enabled');
 }
Exemplo n.º 26
0
 /**
  * Alias for translate
  */
 public function t($string, $args = null, $name_space = null)
 {
     $name_space = !empty($name_space) ? $name_space : AkConfig::getOption('locale_namespace', !empty($this->locale_namespace) ? $this->locale_namespace : (defined('AK_DEFAULT_LOCALE_NAMESPACE') && AK_DEFAULT_LOCALE_NAMESPACE != '' ? AK_DEFAULT_LOCALE_NAMESPACE : 'views'));
     return Ak::t($string, $args, $name_space);
 }
Exemplo n.º 27
0
 static function &getLogger($namespace = AK_ENVIRONMENT)
 {
     static $Logger = array();
     if (empty($Logger[$namespace])) {
         $logger_options = AkConfig::getOption($namespace . '_logger_options', array());
         $logger_class = AkConfig::getOption('logger', 'AkLogger');
         $logger_class_for_namespace = AkConfig::getOption($namespace . '_logger', $logger_class);
         if (is_string($logger_class_for_namespace)) {
             $Logger[$namespace] = new $logger_class_for_namespace(array_merge($logger_options, array('namespace' => $namespace)));
         } else {
             $Logger[$namespace] = $logger_class_for_namespace;
         }
     }
     return $Logger[$namespace];
 }
Exemplo n.º 28
0
 public function __construct()
 {
     parent::__construct();
     $this->memcached_enabled = AkConfig::getOption('memcached_enabled', AkMemcache::isServerUp());
 }
Exemplo n.º 29
0
 public function __construct()
 {
     $this->webserver_enabled = AkConfig::getOption('webserver_enabled', false);
     parent::__construct();
     $this->_test_script = AkConfig::getOption('testing_url') . '/action_pack/public/index.php?ak=';
 }
Exemplo n.º 30
0
}
if (isset($options['verbose'])) {
    unset($options['verbose']);
    $options['reporter'] = 'AkelosVerboseTextReporter';
}
if ($db_type = empty($options['db']) ? false : $options['db']) {
    define('AK_DATABASE_SETTINGS_NAMESPACE', $db_type);
    unset($options['db']);
}
$valid_options = array('config', 'base_path', 'namespace', 'TestSuite', 'reporter', 'files', 'on_success', 'on_failure');
$options['files'] = array();
$component = '';
foreach ($options as $k => $v) {
    if (!in_array($k, $valid_options)) {
        if (!is_bool($v)) {
            $v = rtrim($v, DS);
            if (strstr($v, DS)) {
                $options['files'][] = $v . '.php';
            } else {
                $component .= $v . ',';
            }
            unset($options[$k]);
        }
    }
}
if (empty($options['component']) && !empty($component)) {
    $options['component'] = trim($component, ', ');
}
$options = array_diff($options, array(''));
$options['component'] = empty($options['component']) ? AkConfig::getOption('component', file_exists(AK_CONFIG_DIR . DS . 'config.php') ? AkInflector::underscore(AK_APP_NAME) : 'akelos') : $options['component'];
AkUnitTestSuite::runFromOptions($options);