/** * @expectedException \Skully\Exceptions\InvalidConfigException * This is exactly the reason why you do not want singleton in your apps. * Imagine if Application::construct() calls for Application's static instance. * Somewhere in the code config for this object might have been created which makes * the object valid. In that case there is no way to test if * Exception can be called when class uses Singleton pattern. */ public function testApplicationWithoutConfigMustThrowError() { // This is the old code. With this code it is not possible to test Exceptions. // $app = Application::construct(Config::construct()); $app = new Application(new Config()); $app->getRouter(); }
public function testSmartyInstall() { $config = new Config(); $config->setProtectedFromArray(array('publicDir' => 'public/', 'caching' => 1, 'theme' => 'default', 'basePath' => realpath(__DIR__ . DIRECTORY_SEPARATOR . 'App') . DIRECTORY_SEPARATOR, 'baseUrl' => 'http://localhost/skully/', 'languages' => array('en' => array('value' => 'english', 'code' => 'en')), 'urlRules' => array('' => 'home/index', 'admin' => 'admin/home/index'), 'namespace' => 'App')); if (!file_exists(realpath(__DIR__ . '/App/App/smarty/plugins'))) { mkdir('./App/App/smarty/plugins'); } if (!file_exists(realpath(__DIR__ . '/App/App/smarty/cache'))) { mkdir('./App/App/smarty/cache'); } if (!file_exists(realpath(__DIR__ . '/App/App/smarty/configs'))) { mkdir('./App/App/smarty/configs'); } $app = new Application($config); $smarty = $app->getTemplateEngine()->getEngine(); $errors = array(); $smarty->testInstall($errors); echo "smarty errors: "; print_r($errors); $this->assertTrue(count($errors) <= 2); }
/** * @param string $basePath Application's base path ending with DIRECTORY_SEPARATOR * @param string $theme * @param \Skully\Application $app * @param array $additionalPluginsDir * @param int $caching */ public function __construct($basePath, $theme = 'default', $app = null, $additionalPluginsDir = array(), $caching = 1) { $appName = $app->getAppName(); $this->app = $app; $this->smarty = new \Smarty(); $this->smarty->caching = $caching; $this->caching = $caching; $this->smarty->setCompileDir($basePath . implode(DIRECTORY_SEPARATOR, array($appName, 'smarty', 'templates_c')) . DIRECTORY_SEPARATOR); $this->smarty->setConfigDir($basePath . implode(DIRECTORY_SEPARATOR, array($appName, 'smarty', 'configs')) . DIRECTORY_SEPARATOR); $this->smarty->setCacheDir($basePath . implode(DIRECTORY_SEPARATOR, array($appName, 'smarty', 'cache'))); $dirs = $this->app->getTheme()->getDirs(); foreach ($dirs as $key => $dir) { if ($key == 'main' || $key == 'default') { $this->addTemplateDir($dir . DIRECTORY_SEPARATOR . $appName . DIRECTORY_SEPARATOR . 'views', $key); } else { $this->addTemplateDir($dir . DIRECTORY_SEPARATOR . 'views', $key); } } $plugins = array_merge($additionalPluginsDir, array($this->app->getRealpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'App' . DIRECTORY_SEPARATOR . 'smarty' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR, $this->app->getRealpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'Library' . DIRECTORY_SEPARATOR . 'Smarty' . DIRECTORY_SEPARATOR . 'libs' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR)); $this->setPluginsDir($plugins); }
/** * @return \Skully\Core\Theme\ThemeInterface * @throw \Skully\Exceptions\InvalidConfigException */ public function getTheme() { /** @var \SkullyAwsS3\S3ConfigTrait $config */ $config = $this->getConfigObject(); if ($config->isAmazonS3Enabled()) { if (empty($this->theme)) { /** @var \SkullyAwsS3\S3ApplicationTrait $this */ $this->prepareS3Theme(); } return $this->theme; } else { return parent::getTheme(); } }
protected function setDefaultAssign() { $this->showSetMessages(); if (!$this->app->configIsEmpty('localTest')) { $this->app->getTemplateEngine()->assign(array('localTest' => $this->app->config('localTest'))); } $this->app->getTemplateEngine()->assign(array('isLogin' => false, 'baseUrl' => $this->app->config('baseUrl'), 'themeUrl' => $this->app->getTheme()->getPublicBaseUrl(), 'xmlLang' => $this->app->getXmlLang(), 'language' => $this->app->getLanguage(), 'clientConfig' => $this->app->clientConfig(), 'isAjax' => $this->app->isAjax(), 'params' => $this->params, '_path' => array('route' => $this->getControllerPath(), 'action' => $this->getCurrentAction()))); $this->setAdditionalAssign(); }
public function testRunAction() { $controller = $this->app->getControllerFromRawUrl('home/something'); }
public function getObject($path) { $s3config = $this->app->config('amazonS3'); $result = $this->client->getObject(array('Bucket' => $s3config['bucket'], 'Key' => S3Helpers::key($this->app->config('publicDir'), $path))); return $result; }
/** * @param ConfigInterface $config * @throws InvalidConfigException */ public function __construct(ConfigInterface $config) { parent::__construct($config); $this->mergeSettingsToConfig(); }
public function testIsAjax() { $this->assertFalse($this->app->isAjax()); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'xmlhttprequest'; $this->assertTrue($this->app->isAjax()); }
protected function setupTheme() { parent::setupTheme(); $this->addAdminTemplateDir(); }