/** * @covers User::get_identity */ public function test_get_identity() { if (!empty($_COOKIE['user'])) { unset($_COOKIE['user']); } /** * @var $session Session */ $session = Application::get_class(Session::class); $session->unset_var('user'); $identity = $this->user->get_identity(); self::assertTrue($identity->is_guest()); $mapper = $this->user->get_mapper(); /** * @var $model \User\models\UserModel */ $model = $mapper->find_where(['password' => ['=', '']])->one(); $auth = $this->user->get_auth(); self::assertTrue($auth->login($model->login, $model->password)); $identity = $this->user->get_identity(); self::assertFalse($identity->is_guest()); self::assertTrue($auth->login($model->login, $model->password, true)); $identity = $this->user->get_identity(); self::assertFalse($identity->is_guest()); }
public function __construct() { /** * @var $configuration Configuration */ $configuration = Application::get_class(Configuration::class); $pages = $configuration->pages; $area_routers = $configuration->routers; switch (array_replace_recursive([''], Request::uri_parts())[0]) { case 'admin_panel': $this->routes = $pages['admin_panel']; $this->area_router = Application::get_class($area_routers['admin_panel']); break; case 'rest': $routes = array_merge($pages['site'], $pages['admin_panel']); /** * mix site and admin panel routes with other rest routes to not duplicate url's */ $routes = array_merge(array_combine(array_map(function ($el) { return '/rest/templates' . $el; }, array_keys($routes)), $routes), $pages['rest']); $this->routes = $routes; $this->area_router = Application::get_class($area_routers['rest']); break; case 'action': $this->routes = $pages['action']; $this->area_router = Application::get_class($area_routers['action']); break; default: $this->routes = $pages['site']; $this->area_router = Application::get_class($area_routers['site']); } }
/** * @throws \InvalidArgumentException */ private function set_title() { /** * @var $router Router */ $router = Application::get_class(Router::class); $pageModel = $router->current_page(); if ($pageModel) { $title = $this->titles[$pageModel->name]; if (is_array($title)) { list($class, $method, $prefix) = array_pad($title, 3, ''); try { $reflection_method = new \ReflectionMethod($class, $method); $params = $router->get_route_params(); $params[] = $prefix; if ($reflection_method->isStatic()) { $this->current = call_user_func_array([$class, $method], $params); } else { $this->current = call_user_func_array([Application::get_class($class), $method], $params); } } catch (\Exception $e) { Error::log($e->getMessage()); } } else { $this->current = $title; } } }
public function setUp() { $this->session_obj = \common\classes\Application::get_class(Session::class); if (empty($_COOKIE['pfm_session_id'])) { $_COOKIE['pfm_session_id'] = static::$session_id; } }
private static function init_test_tables() { $adapter = new \common\adapters\MysqlAdapter(''); $sql = ' CREATE TABLE IF NOT EXISTS tests_table ( `id` serial primary key , `field1` varchar(255) not null default "" , `field2` bigint not null default 0 , `field3` enum("val1", "val2", "val3") default "val1" ) '; $adapter->execute($sql); $sql = ' CREATE TABLE IF NOT EXISTS tests_table2 ( `id` serial primary key , `field1` varchar(255) not null default "" , `field2` bigint not null default 0 , `field3` enum("val1", "val2", "val3") default "val1" ) '; $adapter->execute($sql); $roles = [User::credentials_admin, User::credentials_admin, User::credentials_admin, User::credentials_user, User::credentials_user, User::credentials_user, User::credentials_super_admin, User::credentials_super_admin, User::credentials_super_admin]; /** * @var $user User */ $user = Application::get_class(User::class); $mapper = $user->get_mapper(); for ($i = 0; $i < 9; $i++) { $mapper->save(new \User\models\UserModel(['login' => uniqid('test', true), 'credentials' => $roles[$i]])); } }
public function setUp() { /** * @var $user User */ $user = Application::get_class(User::class); $this->mapper = $user->get_mapper(); }
public function route() { /** * @var $router \Tools\routers\ToolsRouter */ $router = \common\classes\Application::get_class(ToolsRouter::class); $router->route(); }
public function add_user() { /** * @var $view TemplateView */ $view = Application::get_class(AddUserView::class); $this->response->blocks['main'] = $view->render(); }
public function __construct() { $this->register_autoload(); $this->mapper = \common\classes\Application::get_class(SessionMapper::class); if ($this->get_id()) { $this->model = $this->mapper->find_by_id($this->get_id()); } }
protected function get_configuration() { /** * @var $configuration Configuration */ $configuration = Application::get_class(Configuration::class); $db_params = $configuration->db_params; return array_merge(['db_type' => 'mysql', 'host' => 'localhost'], $db_params); }
public function get_data() { /** * @var $mapper \Tools\mappers\TemplatesMapper */ $mapper = Application::get_class(TemplatesMapper::class); $templates = $mapper->get_page(); return ['templates_list' => $templates->to_array()]; }
public function __construct() { /** * @var $system \System */ $system = Application::get_class(\System::class); $template = $this->template = $system->template; $compile_dir = $template->get_path() . DS . 'templates_c'; $this->set_compile_dir($compile_dir); }
public function get_data() { /** * @var $user \User */ $user = Application::get_class(\User::class); $mapper = $user->get_mapper(); $identity = $mapper->find_by_id($this->id); return ['user' => $identity->to_array()]; }
/** * @covers Session\mappers\SessionMapper::find_by_id */ public function test_find_by_id() { \common\classes\Application::get_class(Session::class); $this->mapper = \common\classes\Application::get_class(SessionMapper::class); $adapter = $this->mapper->get_adapter(); $id = $adapter->execute('SELECT id from sessions ORDER BY id DESC LIMIT 1')->get_result(); $record = $this->mapper->find_by_id($id); self::assertEquals($id, $record->id); return [[$record]]; }
private function load_db_params(array $configuration) { if (defined('TESTS_ENV')) { $this->db_params = $configuration['db_params']['tests']; } elseif (Application::is_dev()) { $this->db_params = $configuration['db_params']['development']; } else { $this->db_params = $configuration['db_params']['production']; } }
private function init_db() { if (defined('TESTS_ENV') || Application::is_dev()) { $adapter = new \common\adapters\MysqlAdapter(''); $sql = 'SHOW TABLES'; $tables = ['users', 'session', 'templates']; if (count(array_intersect($adapter->execute($sql)->get_arrays(), $tables)) < count($tables)) { $sql = file_get_contents(ROOT_PATH . DS . 'resource' . DS . 'initialize.sql'); $adapter->execute($sql); } } }
/** * @covers common\views\TemplateView::get_lang_vars_base_dir */ public function test_get_lang_vars_base_dir() { /** * @var $system System */ $system = Application::get_class(System::class); /** * @var $template \common\interfaces\Template */ $template = $system->template; self::assertEquals($this->view->get_lang_vars_base_dir(), $template->get_lang_path()); }
public function get_data() { /** * @var $ext \User */ $ext = Application::get_class(\User::class); $user = $ext->get_identity(); $mapper = $ext->get_mapper(); $users = $mapper->get_page($this->page)->to_array(); $is_super_admin = $user->is_super_admin(); $template_dir = $this->get_template_dir($index = 1); return ['users' => $users, 'my_id' => $user->id, 'is_super_admin' => $is_super_admin, 'paging_model' => $mapper->get_paging($this->page)->to_array(), 'base_url' => '/admin_panel/users', 'inclusions' => ['pagination.tpl.html' => file_get_contents($template_dir . DS . 'pagination.tpl.html')]]; }
/** * @covers \User\models\UserModel::is_super_admin */ public function test_is_super_admin() { /** * @var $user User */ $user = Application::get_class('User'); $mapper = $user->get_mapper(); /** * @var $model \User\models\UserModel */ $model = $mapper->find_where(['credentials' => ['=', User::credentials_super_admin]])->one(); self::assertTrue($model->is_super_admin()); }
public static function show_error($message) { /** * @var $system \System */ $system = Application::get_class(\System::class); $smarty = new \Smarty(); $smarty->setTemplateDir($system->get_path() . DS . 'templates'); $smarty->setCompileDir($system->get_path() . DS . 'templates_c'); $error_class = 'error-block'; $params = ['class' => $error_class, 'message' => $message]; $smarty->assign($params); echo $smarty->getTemplate('message.tpl.html'); }
public function is_guest() { if (!empty($_COOKIE['user'])) { return $_COOKIE['user'] != $this->remember_hash; } else { /** * @var $session \Session */ $session = Application::get_class(\Session::class); if ($remember_hash = $session->get_var('user')) { return $remember_hash != $this->remember_hash; } return true; } }
/** * @covers \User\auth\UserAuth::log_out */ public function test_log_out() { /** * @var $user User */ $user = Application::get_class(User::class); $mapper = $user->get_mapper(); $sql = 'select * from users WHERE deleted = 0 AND password = "" ORDER BY id DESC LIMIT 1'; /** * @var $model \User\models\UserModel */ $model = $mapper->find_by_sql($sql)->one(); self::assertTrue($this->auth->login($model->login, $model->password)); self::assertTrue($this->auth->log_out()); self::assertTrue($this->auth->login($model->login, $model->password, true)); self::assertTrue($this->auth->log_out()); self::assertFalse($this->auth->log_out()); }
public function log_out() { if (!empty($_COOKIE['user'])) { unset($_COOKIE['user']); setcookie('user', null, -1, '/'); return true; } else { /** * @var $session \Session */ $session = Application::get_class(\Session::class); if ($session->get_var('user')) { $session->unset_var('user'); return true; } return false; } }
private function check_credentials($value) { /** * @var $ext \User */ $ext = Application::get_class(\User::class); /** * @var $user \User\models\UserModel */ $user = $ext->get_identity(); switch ($value) { case 'super_admin': return $user->is_super_admin(); case 'admin': return $user->is_admin(); default: return false; } }
public static function load_extension_class($name) { $parts = explode('\\', $name); $class_name = strtolower(array_pop($parts)) . '.php'; $extension = reset($parts); if (Application::extension_exists($extension)) { $parts = array_map([StringHelper::class, 'camelcase_to_dash'], $parts); $parts = array_map('strtolower', $parts); $file = 'pfmextension://' . implode(DS, $parts) . DS . $class_name; if (is_file($file)) { require_once $file; return true; } else { return false; } } else { return false; } }
protected function show_result(GetResponse $response) { /** * @var $template Template */ $template = Application::get_class(\Starter::class); $smarty = new \Smarty(); $bundle_file = ROOT_PATH . DS . 'static_builder' . DS . 'bundle.result.json'; $bundle_result = json_decode(file_get_contents($bundle_file), true); $smarty->assign('bundle_result', $bundle_result); if (strpos(Request::uri(), 'admin_panel') !== false) { $smarty->setTemplateDir($template->get_path() . DS . 'templates' . DS . 'admin_panel'); } else { $smarty->setTemplateDir($template->get_path() . DS . 'templates' . DS . 'site'); } $smarty->setCompileDir($template->get_path() . DS . 'templates_c'); $smarty->assign($response->blocks); $smarty->assign('title', new PageTitle()); echo $smarty->getTemplate('index' . DS . 'index.tpl.html'); }
private function show_result() { /** * @var $view ExtensionView */ $view = Application::get_class(LeftMenuView::class); $this->response->blocks['left'] = $view->render(); $view = Application::get_class(TopMenuView::class); $this->response->blocks['top'] = $view->render(); $smarty = new \Smarty(); $bundle_file = ROOT_PATH . DS . 'static_builder' . DS . 'bundle.result.json'; $bundle_result = json_decode(file_get_contents($bundle_file), true); $smarty->assign('bundle_result', $bundle_result); $smarty->assign($this->response->blocks); /** * @var $ext \Tools */ $ext = Application::get_class(\Tools::class); $smarty->setTemplateDir($ext->get_path() . DS . 'templates' . DS . 'index'); $smarty->setCompileDir($ext->get_path() . DS . 'templates_c'); echo $smarty->getTemplate('index.tpl.html'); }
public static function load_extension($name) { $name = basename($name); if (!Application::extension_exists($name)) { return false; } $extension_class = $name; $name = strtolower($name); $extension_file_gz = ROOT_PATH . DS . 'extensions' . DS . "{$name}.tar.gz"; $extension_build_dir = ROOT_PATH . DS . 'build' . DS . $name; if (file_exists($extension_build_dir)) { $check_is_changed = Application::is_dev() || defined('TESTS_ENV'); if ($check_is_changed) { $is_extension_changed = self::is_extension_changed($name) || !self::is_extension_built($name); if ($is_extension_changed) { self::build_extension($name); } } } if (!class_exists($extension_class, false)) { require_once "phar://{$extension_file_gz}/{$name}.php"; } return true; }
<?php require_once realpath(dirname(__DIR__ . '../')) . '/resource/defines.php'; require_once ROOT_PATH . DS . 'common' . DS . 'classes' . DS . 'application.php'; require_once ROOT_PATH . DS . 'lib/Smarty/Smarty.class.php'; require_once ROOT_PATH . DS . 'lib' . DS . 'Validator' . DS . 'autoload.php'; \common\classes\Application::initialize(); \common\classes\Application::start();
public function setUp() { $this->router = Application::get_class(SilentRestRouter::class); }