/** * Tear down method. * * @return void */ public function tearDown() { parent::tearDown(); Plugin::unload('TestPlugin'); Plugin::unload('Union/Core'); unset($this->View); }
/** * Check action by path. * * @param string $path * @return bool */ public function hasAction($path) { $action = explode('/', $path); $action = end($action); $details = explode('/', $path, 3); if (count($details) <= 2) { return false; } list($type, $vendor, $ns) = $details; if (Plugin::loaded($vendor) === true) { $vendor = FS::clean($vendor, '/'); $nsDetails = explode('/', $ns); $type = $this->_currentType($type); unset($nsDetails[count($nsDetails) - 1]); $namespace = implode('/', $nsDetails); $namespace = FS::clean(implode('\\', [$vendor, $type, $namespace . $type]), '\\'); return method_exists($namespace, $action); } $details = explode('/', $path, 2); list($type, $vendor) = $details; $type = $this->_currentType($type); $nsDetails = explode('/', FS::clean($vendor, '/')); unset($nsDetails[count($nsDetails) - 1]); $defVendor = Configure::read('App.namespace'); $namespace = implode('/', $nsDetails); $namespace = FS::clean(implode('\\', [$defVendor, $type, $namespace . $type]), '\\'); return method_exists($namespace, $action); }
/** * Setup test data. * * @return void */ public function setUp() { parent::setUp(); $view = new AppView(); $this->Acl = new AclHelper($view); Plugin::load('TestPlugin', ['autoload' => true]); }
/** * Tear down data. * * @return void */ public function tearDown() { parent::tearDown(); Plugin::unload($this->plugin); Cache::drop('permissions'); Cache::drop('permission_roles'); unset($this->Roles, $this->Users, $this->userData); }
/** * Tear down. * * @return void */ public function tearDown() { parent::tearDown(); unset($this->_controller, $this->url, $this->data); Plugin::unload($this->plugin); Plugin::unload('Union/Extensions'); Cache::drop('permissions'); Cache::drop('permission_roles'); Cache::drop('plugins'); }
/** * On setup admin application. * * @return void */ protected function _onSetupAdmin() { $plugins = (array) Plugin::loaded(); foreach ($plugins as $plugin) { $path = Plugin::path($plugin); $navConf = $path . 'config' . DS . self::ADMIN_MENU_FILE_NAME . '.php'; if (file_exists($navConf)) { /** @noinspection PhpIncludeInspection */ require_once $navConf; } } }
/** * Tear down method. * * @return void */ public function tearDown() { parent::tearDown(); Plugin::unload('TestPlugin'); }
/** * @return void */ public function tearDown() { parent::tearDown(); Plugin::unload('Union/Core'); CakeEmail::dropTransport('default'); }
/** * Simple test application. * * @return void */ public function testAppController() { $controller = new AppController(); $this->assertSame('App', $controller->name); $this->assertTrue(Plugin::loaded('TestPlugin')); }
/** * Test composer post autoload dump event. * * @return void */ public function testPostAutoloadDump() { Plugin::load('DebugKit'); if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } if (!defined('TMP')) { define('TMP', sys_get_temp_dir() . DS); } $vendorDir = ROOT . 'vendor'; $webRoot = $vendorDir . '/cakephp/debug_kit/webroot'; $assetsDir = $vendorDir . '/cakephp/debug_kit/assets'; if (!is_dir($webRoot) && is_dir($assetsDir)) { $debugWebroot = new Folder($assetsDir); $debugWebroot->copy($webRoot); $debugWebroot->delete($assetsDir); } $composer = new Composer(); /** @var Config $config */ $config = new Config(); $config->merge(['config' => ['vendor-dir' => $vendorDir]]); $composer->setConfig($config); /** @var IOInterface $io */ $io = $this->getMock('Composer\\IO\\IOInterface'); $event = new Event('postAutoloadDump', $composer, $io); Installer::postAutoloadDump($event); Plugin::unload('DebugKit'); }
}); Request::addDetector('tablet', function ($request) { $detector = new \Detection\MobileDetect(); return $detector->isTablet(); }); // Load union core plugin. Plugin::load('Union/Core', ['bootstrap' => true, 'routes' => true]); Plugin::load('Migrations'); // Load DebugKit plugin. if (Configure::read('debug')) { Plugin::load('DebugKit', ['bootstrap' => true]); } $plugins = ROOT . '/config/plugins.php'; if (file_exists($plugins)) { /** @noinspection PhpIncludeInspection */ $plugins = (include $plugins); if (is_array($plugins)) { \Union\Core\Plugin::loadList($plugins); } } // Connect middleware/dispatcher filters. DispatcherFactory::add('Asset'); DispatcherFactory::add('Routing'); DispatcherFactory::add('ControllerFactory'); /** * Enable default locale format parsing. * This is needed for matching the auto-localized string output of Time() class when parsing dates. */ Type::build('date')->useLocaleParser(); Type::build('datetime')->useLocaleParser(); EventManager::loadListeners();
/** * Test plugin load by list. * * @return void */ public function testLoadList() { $Folder = new Folder(); $pluginsDir = APP_ROOT . 'Plugins' . DS; $TestPlgPath = $pluginsDir . 'PluginTest'; $Folder->create($TestPlgPath, 0777); new File($TestPlgPath . '/config/bootstrap.php', true); new File($TestPlgPath . '/config/routes.php', true); $NoRoutesPlgPath = $pluginsDir . 'NoRoutes'; $Folder->create($NoRoutesPlgPath, 0777); new File($NoRoutesPlgPath . '/config/bootstrap.php', true); $NoBootstrapPlgPath = $pluginsDir . 'NoBootstrap'; $Folder->create($NoBootstrapPlgPath, 0777); new File($NoBootstrapPlgPath . '/config/routes.php', true); $NoConfigPlgPath = $pluginsDir . 'NoConfig'; $Folder->create($NoConfigPlgPath, 0777); Plugin::load('Migrations'); Plugin::loadList(['NoConfig', 'NoRoutes', 'PluginTest', 'Migrations', 'NoBootstrap']); $this->assertTrue(Plugin::loaded('NoBootstrap')); $this->assertTrue(Plugin::loaded('PluginTest')); $this->assertTrue(Plugin::loaded('NoRoutes')); $this->assertTrue(Plugin::loaded('NoConfig')); // Check virtual paths. $this->assertSame(1, count(vPath()->getPaths('NoBootstrap:'))); $this->assertSame(1, count(vPath()->getPaths('PluginTest:'))); $this->assertSame(1, count(vPath()->getPaths('NoRoutes:'))); $this->assertSame(1, count(vPath()->getPaths('NoConfig:'))); $Folder->delete($TestPlgPath); $Folder->delete($NoRoutesPlgPath); $Folder->delete($NoConfigPlgPath); $Folder->delete($NoBootstrapPlgPath); }
<?php /** * UnionCMS Core * * This file is part of the of the simple cms based on CakePHP 3. * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * @package Core * @license MIT * @copyright MIT License http://www.opensource.org/licenses/mit-license.php * @link https://github.com/UnionCMS/Core * @author Sergey Kalistratov <*****@*****.**> */ use Union\Core\Nav; use Union\Core\Plugin; $plugin = 'Union/Core'; Nav::add('sidebar', 'dashboard', ['title' => __d('union', 'Dashboard'), 'weight' => 0, 'icon' => 'dashboard', 'url' => ['plugin' => $plugin, 'controller' => 'Union', 'action' => 'dashboard']]); Nav::add('sidebar', 'system', ['title' => __d('union', 'System'), 'weight' => 1, 'icon' => 'cog', 'children' => ['global-config' => ['title' => __d('union', 'Global config'), 'url' => ['plugin' => 'Union/Extensions', 'controller' => 'Plugins', 'action' => 'config', Plugin::alias($plugin)]]]]);
$folder->create(LOGS, 0777); $folder->create(SESSIONS, 0777); $folder->create(CACHE, 0777); $folder->create(CACHE . 'view', 0777); $folder->create(CACHE . 'models', 0777); date_default_timezone_set('UTC'); mb_internal_encoding('UTF-8'); // Include CakePHP framework. /** @noinspection PhpIncludeInspection */ require_once CAKE_CORE_INCLUDE_PATH . '/config/bootstrap.php'; $path = Path::getInstance(); $path->setRoot(ROOT); $path->set('cache', ASSETS_CACHE); // Load union core plugin. Plugin::load('Union/Core', ['routes' => true, 'bootstrap' => true]); Plugin::load('Search'); // Write union test application config. Configure::write('debug', true); Configure::write('App', ['namespace' => 'TestApp', 'encoding' => 'UTF-8', 'base' => false, 'baseUrl' => env('SCRIPT_NAME'), 'dir' => APP_DIR, 'locale' => 'ru_RU', 'fullBaseUrl' => 'http://localhost', 'paths' => ['plugins' => [APP_ROOT . 'Plugins' . DS], 'templates' => [APP . 'Template' . DS, ROOT . '/vendor/union-cms/core/src/Template/'], 'locales' => [APP . 'Locale' . DS]]]); Configure::write('Acl.database', 'test'); Configure::write('Acl.classname', 'DbAcl'); Configure::write('Session', ['defaults' => 'php']); // Write configure for cache model. Cache::config(['_cake_core_' => ['engine' => 'File', 'prefix' => 'cms_core_', 'serialize' => true], '_cake_model_' => ['engine' => 'File', 'prefix' => 'cms_model_', 'serialize' => true]]); Configure::write('EmailTransport', ['default' => ['className' => 'Mail', 'host' => 'localhost', 'port' => 25, 'timeout' => 30, 'username' => 'user', 'password' => 'secret', 'client' => null, 'tls' => null]]); Configure::write('Email', ['default' => ['transport' => 'default', 'from' => 'you@localhost', 'charset' => 'utf-8', 'headerCharset' => 'utf-8']]); // Ensure default test connection is defined. if (!getenv('db_dsn')) { putenv('db_dsn=sqlite:///:memory:'); } ConnectionManager::config('test', ['url' => getenv('db_dsn')]);
<?php /** * UnionCMS Community * * This file is part of the of the simple cms based on CakePHP 3. * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * @package Community * @license MIT * @copyright MIT License http://www.opensource.org/licenses/mit-license.php * @link https://github.com/UnionCMS/Community * @author Sergey Kalistratov <*****@*****.**> */ use Union\Core\Nav; use Union\Core\Plugin; $plugin = 'Union/Community'; Nav::add('sidebar', 'community', ['title' => __d('community', 'Community'), 'weight' => 50, 'icon' => 'group', 'children' => ['roles' => ['title' => __d('community', 'Groups'), 'weight' => 0, 'url' => ['plugin' => $plugin, 'controller' => 'Roles', 'action' => 'index']], 'users' => ['title' => __d('community', 'Users'), 'weight' => 10, 'url' => ['plugin' => $plugin, 'controller' => 'Users', 'action' => 'index']], 'permissions' => ['title' => __d('community', 'Permissions'), 'weight' => 15, 'url' => ['plugin' => $plugin, 'controller' => 'Acl', 'action' => 'permissions']], 'config' => ['title' => __d('union', 'Configure'), 'weight' => 20, 'url' => ['plugin' => 'Union/Extensions', 'controller' => 'Plugins', 'action' => 'config', Plugin::alias($plugin)]]]]);
/** * Splits a dot syntax plugin name into its plugin and filename. * * @param string $name * @param bool|true $fallback * @return array */ public function pluginSplit($name, $fallback = true) { $plugin = null; list($first, $second) = pluginSplit($name); if (Plugin::loaded($first) === true) { $name = $second; $plugin = $first; } if (isset($this->plugin) && !$plugin && $fallback) { $plugin = $this->plugin; } return [normalizeName($plugin), $name]; }