From 69d5565f58d92736499fe9d3438a46714c968c22 Mon Sep 17 00:00:00 2001 From: Gregory PLANCHAT Date: Tue, 28 Sep 2010 10:13:56 +0200 Subject: [PATCH] Added core/application unit tests Updated module dependency management & loading Signed-off-by: Gregory PLANCHAT --- .gitmodules | 12 + application/One.php | 8 +- .../One/Core/Exception/ConfigurationError.php | 1 - .../Exception/Database/ConnectionError.php | 1 - .../Database/InvalidConnectionName.php | 1 - .../Exception/Database/ResourceNotFound.php | 1 - .../Core/Exception/ImplementationError.php | 1 - .../Exception/InvalidConstructorParams.php | 1 - .../One/Core/Exception/InvalidMethodCall.php | 1 - .../core/One/Core/Exception/Unimplemented.php | 1 - .../code/core/One/Core/Model/Application.php | 359 +++++------------- .../code/core/One/Core/Model/Layout.php | 2 +- .../code/core/One/Core/Model/Session.php | 1 - test/regression/AllTests.php | 17 + test/regression/One/AllTests.php | 17 + test/regression/One/Core/AllTests.php | 18 + test/regression/One/Core/Model/AllTests.php | 17 + .../One/Core/Model/ApplicationTest.php | 210 ++++++++++ test/regression/One/Core/ObjectTest.php | 6 + test/regression/OneTest.php | 23 ++ test/regression/phpunit.bat | 3 +- 21 files changed, 426 insertions(+), 275 deletions(-) create mode 100644 test/regression/AllTests.php create mode 100644 test/regression/One/AllTests.php create mode 100644 test/regression/One/Core/AllTests.php create mode 100644 test/regression/One/Core/Model/AllTests.php create mode 100644 test/regression/One/Core/Model/ApplicationTest.php create mode 100644 test/regression/One/Core/ObjectTest.php create mode 100644 test/regression/OneTest.php diff --git a/.gitmodules b/.gitmodules index 0f99340..e401558 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,15 @@ [submodule "test/externals/libraries/php-file-iterator"] path = test/externals/libraries/php-file-iterator url = git://github.com/sebastianbergmann/php-file-iterator.git +[submodule "test/externals/libraries/php-token-stream"] + path = test/externals/libraries/php-token-stream + url = git://github.com/sebastianbergmann/php-token-stream.git +[submodule "test/externals/libraries/phpunit-mock-objects"] + path = test/externals/libraries/phpunit-mock-objects + url = git://github.com/sebastianbergmann/phpunit-mock-objects.git +[submodule "test/externals/libraries/php-text-template"] + path = test/externals/libraries/php-text-template + url = git://github.com/sebastianbergmann/php-text-template.git +[submodule "test/externals/libraries/php-timer"] + path = test/externals/libraries/php-timer + url = git://github.com/sebastianbergmann/php-timer.git diff --git a/application/One.php b/application/One.php index 1e89308..651d677 100644 --- a/application/One.php +++ b/application/One.php @@ -203,7 +203,6 @@ public static function app() $modulePath = sprintf($pathPattern, $moduleConfig['codePool'], str_replace('_', DS, $moduleName)); self::_registerModule(self::getFrontController(), self::getRouter(), $moduleName, $moduleConfig, $modulePath); } - var_dump(self::getFrontController()->getControllerDirectory()); self::getFrontController()->setDefaultModule('One_Core'); $dispatcher = self::getFrontController()->getDispatcher(); @@ -294,15 +293,14 @@ private static function _inflectClassName($className, $domain) $inflector = new One_Core_Model_Inflector(); } - $domain = str_replace('.', '/', $domain); - $offset = strpos($className, '/'); $module = substr($className, 0, $offset); $class = substr($className, $offset + 1); - self::getConfig("{$domain}/{$module}/rewrite") +// self::getConfig("{$domain}/{$module}/rewrite") - if (($namespace = self::getConfig("{$domain}/{$module}/namespace")) !== null) { + $xmlDomain = str_replace('.', '/', $domain); + if (($namespace = self::getConfig("{$xmlDomain}/{$module}/namespace")) !== null) { return $namespace . '_' . $inflector->filter($class); } diff --git a/application/code/core/One/Core/Exception/ConfigurationError.php b/application/code/core/One/Core/Exception/ConfigurationError.php index bf76e66..37a9677 100644 --- a/application/code/core/One/Core/Exception/ConfigurationError.php +++ b/application/code/core/One/Core/Exception/ConfigurationError.php @@ -28,7 +28,6 @@ * */ -require_once 'Nova/Core/Exception.php'; /** * Invalid method call exception, thrown when : * - a configuration parameter is missing diff --git a/application/code/core/One/Core/Exception/Database/ConnectionError.php b/application/code/core/One/Core/Exception/Database/ConnectionError.php index 4fb529c..f95c073 100644 --- a/application/code/core/One/Core/Exception/Database/ConnectionError.php +++ b/application/code/core/One/Core/Exception/Database/ConnectionError.php @@ -28,7 +28,6 @@ * */ -require_once 'Nova/Core/Exception.php'; /** * Invalid method call exception, thrown when : * - conneciton to the database could not be set up diff --git a/application/code/core/One/Core/Exception/Database/InvalidConnectionName.php b/application/code/core/One/Core/Exception/Database/InvalidConnectionName.php index 45adfdf..7ca6bae 100644 --- a/application/code/core/One/Core/Exception/Database/InvalidConnectionName.php +++ b/application/code/core/One/Core/Exception/Database/InvalidConnectionName.php @@ -28,7 +28,6 @@ * */ -require_once 'Nova/Core/Exception.php'; /** * Invalid method call exception, thrown when : * - supplied conneciton name could not be found by the conneciton pool diff --git a/application/code/core/One/Core/Exception/Database/ResourceNotFound.php b/application/code/core/One/Core/Exception/Database/ResourceNotFound.php index 3804f03..97973e7 100644 --- a/application/code/core/One/Core/Exception/Database/ResourceNotFound.php +++ b/application/code/core/One/Core/Exception/Database/ResourceNotFound.php @@ -28,7 +28,6 @@ * */ -require_once 'Nova/Core/Exception.php'; /** * Invalid method call exception, thrown when : * - Desired database resource is not found diff --git a/application/code/core/One/Core/Exception/ImplementationError.php b/application/code/core/One/Core/Exception/ImplementationError.php index e95bbc5..baa299d 100644 --- a/application/code/core/One/Core/Exception/ImplementationError.php +++ b/application/code/core/One/Core/Exception/ImplementationError.php @@ -28,7 +28,6 @@ * */ -require_once 'Nova/Core/Exception.php'; /** * Invalid implementation, thrown when : * - a class instanciated by Nova object forgeries does not implement the diff --git a/application/code/core/One/Core/Exception/InvalidConstructorParams.php b/application/code/core/One/Core/Exception/InvalidConstructorParams.php index 33dc673..1437b38 100644 --- a/application/code/core/One/Core/Exception/InvalidConstructorParams.php +++ b/application/code/core/One/Core/Exception/InvalidConstructorParams.php @@ -28,7 +28,6 @@ * */ -require_once 'Nova/Core/Exception.php'; /** * Invalid method call exception, thrown when : * - at least one constructor param is missing or is invalid diff --git a/application/code/core/One/Core/Exception/InvalidMethodCall.php b/application/code/core/One/Core/Exception/InvalidMethodCall.php index 33795c1..0aa6658 100644 --- a/application/code/core/One/Core/Exception/InvalidMethodCall.php +++ b/application/code/core/One/Core/Exception/InvalidMethodCall.php @@ -28,7 +28,6 @@ * */ -require_once 'Nova/Core/Exception.php'; /** * Invalid method call exception, thrown when : * - an inexistent method is called diff --git a/application/code/core/One/Core/Exception/Unimplemented.php b/application/code/core/One/Core/Exception/Unimplemented.php index f45e5ae..98085ed 100644 --- a/application/code/core/One/Core/Exception/Unimplemented.php +++ b/application/code/core/One/Core/Exception/Unimplemented.php @@ -28,7 +28,6 @@ * */ -require_once 'Nova/Core/Exception.php'; /** * Unimplemented method/function/algorithm exception, thrown when : * - desired functionality isn't yet impelmented diff --git a/application/code/core/One/Core/Model/Application.php b/application/code/core/One/Core/Model/Application.php index 86bb5dd..d02f60e 100644 --- a/application/code/core/One/Core/Model/Application.php +++ b/application/code/core/One/Core/Model/Application.php @@ -1,299 +1,140 @@ - * All rights reserved. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * NOTICE: - * This file is part of the core development branch, changing its contents will - * make you unable to use the automatic updates manager. Please refer to the - * documentation for further information about customizing XNova. - * - */ -/** - * Applciation manager - * - * - * @uses Zend_Config - * @uses One_Core_Object - * - * @access public - * @author gplanchat - * @category Config - * @package One - * @subpackage One_Core - */ class One_Core_Model_Application - extends One_Core_Object + extends Zend_Application { - private $_config = NULL; - private $_globalConfig = NULL; - private $_websitesConfig = array(); - private $_gamesConfig = array(); - private $_gameViewsConfig = array(); + protected $_websiteId = null; - private $_cacheHandler = NULL; + protected $_activeModules = array(); - protected function _construct() - { - $frontendOptions = array( - 'caching' => !defined('DEBUG') ? true : false, - 'cache_id_prefix' => 'Config', - 'lifetime' => NULL, - 'logging' => defined('DEBUG') ? true : false, - 'write_control' => true, - 'automatic_serialization' => true - ); - - $backendOptions = array( - 'cache_dir' => APPLICATION_PATH . DS . 'cache', - 'file_locking' => true, - 'read_control' => true, - 'read_control_type' => 'adler32', - 'hashed_directory_level' => 0, - 'hashed_directory_umask' => 0700, - 'file_name_prefix' => 'NovaCache', - 'cache_file_umask' => 0600 - ); + protected $_dependencies = array(); - $this->_cacheHandler = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions); - } + const DS = DIRECTORY_SEPARATOR; + const PS = PATH_SEPARATOR; - /** - * @todo - * @return unknown_type - */ - protected function _mergeDatabaseConfig($websiteId = 0, $gameId = 0, $gameViewId = 0) + public function __construct($websiteId, $environment, Zend_Config $globalConfig = null) { - if (!$this->_globalConfig) { - return $this; + $this->_websiteId = $websiteId; + + if ($globalConfig === null) { + $configFile = implode(self::DS, array(APPLICATION_PATH, + 'configs', 'application.xml')); + + require_once 'Zend/Config/Xml.php'; + $config = new Zend_Config_Xml($configFile, $environment, true); + } else if (($environmentConfig = $globalConfig->get($environment)) !== null) { + $configArray = $environmentConfig->toArray(); + $config = new Zend_Config($configArray, true); + + if (isset($configArray['extends'])) { + $sectionName = $configArray['extends']; + while ($sectionName !== null) { + if (!isset($globalConfig->{$sectionName})) { + require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception("Section '$sectionName' cannot be found in $xml"); + } + $tmp = new Zend_Config($globalConfig->{$sectionName}->toArray(), true); + $config = $tmp->merge($config); + $sectionName = $globalConfig->{$sectionName}->extends; + } + } + + unset($config->extends); + } else { + throw new One_Core_Exception_ConfigurationError( + "Environement '{$environment}' not found."); } - } - private function _importGlobalConfig() - { - $config = new Zend_Config_Xml(APPLICATION_PATH . 'config' . DS . 'system.xml', NULL, true); - $config->merge(new Zend_Config_Xml(APPLICATION_PATH . 'config' . DS . 'local.xml', NULL, true)); + $pathPattern = implode(self::DS, array(APPLICATION_PATH, + 'code', '%s', '%s', 'configs', 'module.xml')); - $path = APPLICATION_PATH . 'config' . DS . 'modules'; - $iterator = new RegexIterator(new FilesystemIterator($path, FilesystemIterator::SKIP_DOTS), '#\.xml$#'); - foreach ($iterator as $file) { - $config->merge(new Zend_Config_Xml($file->getPathname(), NULL, true)); + if (($modules = $config->get('modules')) === null) { + throw new One_Core_Exception_ConfigurationError( + "No modules found. A core module should at least be declared."); } - if ($modules = $config->get('modules')) { - foreach ($modules as $moduleName => $moduleConfig) { - $codePool = $moduleConfig->get('codePool'); - if (!$codePool) { - $codePool = 'local'; - } - $configPath = APPLICATION_PATH . 'code' . DS . $codePool . DS . str_replace('_', DS, $moduleName) - . DS . '_config' . DS . 'module.xml'; - $config->merge(new Zend_Config_Xml($configPath, NULL, true)); - } + foreach ($modules as $moduleName => $moduleConfig) { + $this->_addModule($config, $moduleName, $moduleConfig, $pathPattern); } - $config->setReadOnly(); - return $config; - } - /** - * Loads the config files, for various usages - * - * @access private - * @return Zend_Config - */ - public function getConfig($path = NULL) - { - Nova::profilerStart('APPLICATION.CONFIG'); - if (is_null($this->_config)) { - Nova::profilerStart('APPLICATION.CONFIG.LOAD'); - $cacheId = 'General'; + $this->_validateModulesActivation($modules); - if ($rawConfig = $this->_cacheHandler->load($cacheId)) { - Nova::profilerStart('APPLICATION.CONFIG.LOAD.CACHED'); - $this->_config = new Zend_Config($rawConfig); - Nova::profilerStop('APPLICATION.CONFIG.LOAD.CACHED'); - } else { - Nova::profilerStart('APPLICATION.CONFIG.LOAD.UNCACHED'); - $this->_config = $this->_importGlobalConfig(); + $config->setReadOnly(); - $this->_cacheHandler->save($this->_config->toArray(), $cacheId, array('configuration')); - Nova::profilerStop('APPLICATION.CONFIG.LOAD.UNCACHED'); - } - Nova::profilerStop('APPLICATION.CONFIG.LOAD'); - } - Nova::profilerStop('APPLICATION.CONFIG'); + parent::__construct($environment, $config); + } - if (!is_null($path)) { - $pathExploded = explode('.', $path); - if (count($pathExploded)) { - $config = $this->_config; - foreach ($pathExploded as $chunk) { - $config = $config->get($chunk, NULL); - if (is_null($config)) { - return NULL; - } + protected function _validateModulesActivation($modulesConfig) + { + $moduleDependencies = $this->_dependencies; + $sortedModules = array(); + while (!empty($moduleDependencies)) { + $modulesCount = count($moduleDependencies); + foreach ($moduleDependencies as $slaveModule => $dependencies) { + if (!empty($dependencies)) { + continue; } - if ($config instanceof Zend_Config) { - return $config->toArray(); - } else { - return $config; + unset($moduleDependencies[$slaveModule]); + $sortedModules[$slaveModule] = null; + + foreach ($moduleDependencies as $module => $dependencies) { + foreach ($dependencies as $masterModule) { + if (($offset = array_search($slaveModule, $moduleDependencies[$module])) !== false) { + unset($moduleDependencies[$module][$offset]); + } + } } } - return NULL; - } else { - return $this->_config->toArray(); + if ($modulesCount === count($moduleDependencies)) { +// throw new One_Core_Exception_ConfigurationError( +// 'Module topological sort could not be proceeded, the dependency tree may be cyclic'); + break; + } } - } - /** - * Returns the modules configuration - * - * @return Zend_Config - */ - public function getModulesConfig() - { - return $this->getConfig('modules'); + $this->_activeModules = array_keys($sortedModules); } - /** - * Loads global configuration - * - * @return Zend_Config - * @todo - */ - public function getGlobalConfig() + protected function _addModule($config, $moduleName, $moduleConfig, $pathPattern) { - if (is_null($this->_globalConfig)) { - $cacheTag = 'CONFIGURATION_GLOBAL'; - - if ($this->_cacheExists($cacheTag)) { - Nova::profilerStart('APPLICATION.CONFIG.GLOBAL.LOAD.CACHE ' . __METHOD__); - $this->_globalConfig = $this->_loadConfigFromCache($cacheTag); - Nova::profilerStop('APPLICATION.CONFIG.GLOBAL.LOAD.CACHE ' . __METHOD__); - } else { - Nova::profilerStart('APPLICATION.CONFIG.GLOBAL.LOAD ' . __METHOD__); - $config = $this->getConfig(); - $this->_globalConfig = new Zend_Config(array(), true); - $this->_globalConfig->merge(new Zend_Config($config->get('default'), true)); - $this->_globalConfig->merge(new Zend_Config($config->get('global'), true)); + if (!in_array(strtolower($moduleConfig->get('active')), array(1, true, '1', 'true', 'on'))) { + return; + } - $stagesConfig = $config->get('global'); - if ($stagesConfig) { - $this->_globalConfig->merge(new Zend_Config($stagesConfig->get($this->getStage()), true)); + if (($dependencies = $moduleConfig->get('requires')) !== null) { + foreach ($dependencies as $dependency) { + if (!isset($this->_dependencies[$moduleName])) { + $this->_dependencies[$moduleName] = array(); } - - $this->_mergeDatabaseConfig(); - - Nova::profilerStart('APPLICATION.CONFIG.GLOBAL.SAVE.CACHE ' . __METHOD__); - $this->_saveConfigToCache($this->_globalConfig, $cacheTag); - Nova::profilerStop('APPLICATION.CONFIG.GLOBAL.SAVE.CACHE ' . __METHOD__); - $this->_globalConfig->setReadOnly(); - Nova::profilerStop('APPLICATION.CONFIG.GLOBAL.LOAD ' . __METHOD__); + $this->_dependencies[$moduleName][] = $dependency; } + } else { + $this->_dependencies[$moduleName] = array(); } - return $this->_globalConfig; - } - /** - * Loads website configuration - * - * @return Zend_Config - * @todo - */ - public function getWebsiteConfig($websiteId = NULL) - { - if (is_null($websiteId)) { - $websiteId = $this->getWebsiteId(); + if (($codePool = $moduleConfig->get('codePool')) === null) { + $codePool = 'local'; + $moduleConfig->codePool = $codePool; } - if (is_null($this->_websiteConfig)) { - $cacheTag = 'CONFIGURATION_WEBSITE_' . strval($websiteId) . '.cache'; - - if ($this->_cacheExists($cacheFile)) { - Nova::profilerStart("APPLICATION.CONFIG.WEBSITE({$websiteId}).LOAD.CACHE " . __METHOD__); - $this->_websiteConfig = $this->_loadConfigFromCache($cacheTag); - Nova::profilerStop("APPLICATION.CONFIG.GLOBAL.LOAD.CACHE " . __METHOD__); - } else { - Nova::profilerStart("APPLICATION.CONFIG.WEBSITE({$websiteId}).GLOBAL.LOAD " . __METHOD__); - $this->_websiteConfig = $this->getConfig(); - - $stageConfig = $this->_websiteConfig->get($this->getStage()); - if (!is_null($stageConfig)) { - $this->_websiteConfig->merge($stageConfig); - } - - $this->_mergeDatabaseConfig(); - - Nova::profilerStart("APPLICATION.CONFIG.WEBSITE({$websiteId}).GLOBAL.SAVE.CACHE " . __METHOD__); - $this->_saveConfigToCache($this->_websiteConfig, $cacheTag); - Nova::profilerStop("APPLICATION.CONFIG.WEBSITE({$websiteId}).GLOBAL.SAVE.CACHE " . __METHOD__); - $this->_websiteConfig->setReadOnly(); - Nova::profilerStop("APPLICATION.CONFIG.WEBSITE({$websiteId}).GLOBAL.LOAD " . __METHOD__); - } + $path = sprintf($pathPattern, $codePool, str_replace('_', self::DS, $moduleName)); + if (!file_exists($path)) { + $config->get('modules')->get($moduleName)->active = false; + return; } - return $this->_websiteConfig; - } - - /** - * Loads game configuration - * - * @return Zend_Config - * @todo - */ - public function getGameConfig($gameId = NULL) - { - } - - /** - * Loads website view configuration - * - * @return Zend_Config - * @todo - */ - public function getGameViewConfig($gameViewId = NULL) - { - } - /** - * FIXME: PHPDoc - */ - public function getStage() - { - return defined('DEBUG') ? 'debug' : 'production'; - } - - /** - * FIXME: PHPDoc - */ - public function bootstrap() - { - return $this; + $moduleConfig = new Zend_Config_Xml($path); + if (($envConfig = $moduleConfig->get($environment)) !== null) { + $config->merge($envConfig); + } else if (($envConfig = $moduleConfig->get('default')) !== null) { + $config->merge($envConfig); + } else { + $config->merge($moduleConfig); + } } - /** - * FIXME: PHPDoc - */ - public function run() + public function getWebsiteId() { - return $this; + return $this->_websiteId; } -} +} \ No newline at end of file diff --git a/application/code/core/One/Core/Model/Layout.php b/application/code/core/One/Core/Model/Layout.php index e85cc56..561fe53 100644 --- a/application/code/core/One/Core/Model/Layout.php +++ b/application/code/core/One/Core/Model/Layout.php @@ -70,7 +70,7 @@ public static function factory($layoutName) * @param string $layoutName * @return void */ - protected function __construct($filename, $layoutName) + public function __construct($filename, $layoutName) { $config = Nova::getConfig('frontend.design'); $this->_basePath = ROOT_PATH . "/design/{$config['name']}/{$config['template']}"; diff --git a/application/code/core/One/Core/Model/Session.php b/application/code/core/One/Core/Model/Session.php index 2130f13..7de3a05 100644 --- a/application/code/core/One/Core/Model/Session.php +++ b/application/code/core/One/Core/Model/Session.php @@ -27,7 +27,6 @@ * documentation for further information about customizing XNova. * */ -require_once 'Nova/Core/Model/SessionAbstract.php'; /** * Session management class diff --git a/test/regression/AllTests.php b/test/regression/AllTests.php new file mode 100644 index 0000000..f5caeb3 --- /dev/null +++ b/test/regression/AllTests.php @@ -0,0 +1,17 @@ +addTestSuite('OneTest'); + $suite->addTest(One_AllTests::suite()); + + return $suite; + } +} \ No newline at end of file diff --git a/test/regression/One/AllTests.php b/test/regression/One/AllTests.php new file mode 100644 index 0000000..bf4ad2d --- /dev/null +++ b/test/regression/One/AllTests.php @@ -0,0 +1,17 @@ +addTest(One_Core_AllTests::suite()); + + return $suite; + } +} \ No newline at end of file diff --git a/test/regression/One/Core/AllTests.php b/test/regression/One/Core/AllTests.php new file mode 100644 index 0000000..a9f5172 --- /dev/null +++ b/test/regression/One/Core/AllTests.php @@ -0,0 +1,18 @@ +addTestSuite('One_Core_ObjectTest'); + $suite->addTest(One_Core_Model_AllTests::suite()); + + return $suite; + } +} \ No newline at end of file diff --git a/test/regression/One/Core/Model/AllTests.php b/test/regression/One/Core/Model/AllTests.php new file mode 100644 index 0000000..3c49de9 --- /dev/null +++ b/test/regression/One/Core/Model/AllTests.php @@ -0,0 +1,17 @@ +addTestSuite('One_Core_Model_ApplicationTest'); + + return $suite; + } +} \ No newline at end of file diff --git a/test/regression/One/Core/Model/ApplicationTest.php b/test/regression/One/Core/Model/ApplicationTest.php new file mode 100644 index 0000000..022678f --- /dev/null +++ b/test/regression/One/Core/Model/ApplicationTest.php @@ -0,0 +1,210 @@ + array( + 'modules' => array( + 'One_Core' => array( + 'active' => true, + 'codePool' => 'local', + 'route' => array( + 'type' => 'core/router.route', + 'path' => 'core', + 'name' => 'default' + ) + ), + 'One_Foo' => array( + 'active' => false, + 'codePool' => 'local', + 'requires' => array( + 'One_Core' + ), + 'route' => array( + 'type' => 'core/router.route', + 'path' => 'foo', + 'name' => 'module.foo' + ) + ), + 'One_Bar' => array( + 'active' => true, + 'codePool' => 'local', + 'requires' => array( + 'One_Core', + 'One_Foo', + 'One_Baz' + ), + 'route' => array( + 'type' => 'bar/router.route', + 'path' => 'bar', + 'name' => 'module.bar' + ) + ), + 'One_Baz' => array( + 'active' => false, + 'codePool' => 'local', + 'requires' => array( + 'One_Core', + 'One_Foo' + ), + 'route' => array( + 'type' => 'baz/router.route', + 'path' => 'baz', + 'name' => 'module.baz' + ) + ), + 'One_Dummy' => array( + 'active' => false, + 'codePool' => 'local', + 'requires' => array( + 'One_Dumb', + ), + 'route' => array( + 'type' => 'dummy/router.route', + 'path' => 'dummy', + 'name' => 'module.dummy' + ) + ), + 'One_Dumb' => array( + 'active' => false, + 'codePool' => 'local', + 'requires' => array( + 'One_Dummy', + ), + 'route' => array( + 'type' => 'dumb/router.route', + 'path' => 'dumb', + 'name' => 'module.dumb' + ) + ) + ) + ), + 'production' => array( + 'extends' => 'default' + ), + 'test_acyclic_dependencies' => array( + 'extends' => 'production', + 'modules' => array( + 'One_Foo' => array( + 'active' => true + ), + 'One_Baz' => array( + 'active' => true + ) + ), + ), + 'test_cyclic_dependencies' => array( + 'extends' => 'production', + 'modules' => array( + 'One_Dummy' => array( + 'active' => true + ), + 'One_Dumb' => array( + 'active' => true + ) + ) + ) + ); + + public function __construct() + { + } + + public function tearDown() + { + $this->_applicationHandler = null; + $this->_environment = null; + $this->_config = null; + } + + public function setUp() + { + $this->_environment = 'production'; + $this->_config = new Zend_Config($this->_defaultConfg); + $this->_websiteId = 1; + } + + public function initApplication() + { + $this->_applicationHandler = new One_Core_Model_Application( + $this->_websiteId, $this->_environment, $this->_config); + } + + public function testWebsiteId() + { + $this->initApplication(); + + $this->assertAttributeType('int', '_websiteId', $this->_applicationHandler, + 'Website ID was not properly set in the application'); + + $this->assertAttributeEquals($this->_websiteId, '_websiteId', $this->_applicationHandler, + 'Website ID was not properly set in the application'); + } + + public function testEnvironment() + { + $this->initApplication(); + + $this->assertAttributeType('string', '_environment', $this->_applicationHandler, + 'Environment was not properly set in the application'); + + $this->assertAttributeEquals($this->_environment, '_environment', $this->_applicationHandler, + 'Environment was not properly set in the application'); + } + + public function testModuleList() + { + $this->_environment = 'test_acyclic_dependencies'; + $this->initApplication(); + + $activeModules = array( + 'One_Core', + 'One_Foo', + 'One_Baz', + 'One_Bar' + ); + + $this->assertAttributeEquals($activeModules, '_activeModules', + $this->_applicationHandler); + + $this->_environment = 'test_cyclic_dependencies'; + $this->_applicationHandler = null; + $this->initApplication(); + + $activeModules = array( + 'One_Core' + ); + + $this->assertAttributeEquals($activeModules, '_activeModules', + $this->_applicationHandler); + } + + public function testModuleDependencies() + { + $this->_environment = 'test_acyclic_dependencies'; + $this->initApplication(); + + $this->assertAttributeType('array', '_dependencies', $this->_applicationHandler, + 'There is an error in the module dependency management'); + + $dependencies = array( + 'One_Core' => array(), + 'One_Foo' => array('One_Core'), + 'One_Baz' => array('One_Core', 'One_Foo'), + 'One_Bar' => array('One_Core', 'One_Foo', 'One_Baz'), + ); + + $this->assertAttributeEquals($dependencies, '_dependencies', $this->_applicationHandler, + 'There is an error in the module dependency management'); + } +} \ No newline at end of file diff --git a/test/regression/One/Core/ObjectTest.php b/test/regression/One/Core/ObjectTest.php new file mode 100644 index 0000000..a4272d0 --- /dev/null +++ b/test/regression/One/Core/ObjectTest.php @@ -0,0 +1,6 @@ +assertEquals('One_Core_Model_Session', One::loadClass('core/session'), + 'Class inflection fails'); + + $this->assertEquals('One_Core_Model_Setup_Patch', One::loadClass('core/setup.patch', 'model'), + 'Class inflection fails'); + + $this->assertEquals('One_Core_Model_Orm_DataMapper', One::loadClass('core/data-mapper', 'model.orm'), + 'Class inflection fails'); + } +} \ No newline at end of file diff --git a/test/regression/phpunit.bat b/test/regression/phpunit.bat index 91d04de..a366f05 100644 --- a/test/regression/phpunit.bat +++ b/test/regression/phpunit.bat @@ -40,6 +40,7 @@ GOTO RUN :USE_PEAR_PATH set PHPBIN=%PHP_PEAR_PHP_BIN% :RUN -"%PHPBIN%" "D:\php-env\workspace\one-platform\test\externals\libraries\phpunit\phpunit.php" %* +cd D:\php-env\workspace\one-platform\test\regression +"%PHPBIN%" "D:\php-env\workspace\one-platform\test\externals\libraries\phpunit\phpunit.php" AllTests pause