Rewrite continued:
[core.git] / application / tests / class_ApplicationHelper.php
index 5d3c60dc181e9128c43d84e74161d168eb441f7e..6b234b436defa8a230624c09df15676c49ebe1b7 100644 (file)
@@ -1,11 +1,14 @@
 <?php
-// Own namespace
+// Must be this namespace, else the launcher cannot find the class.
 namespace CoreFramework\Helper\Application;
 
 // Import framework stuff
+use CoreFramework\Bootstrap\FrameworkBootstrap;
+use CoreFramework\Configuration\FrameworkConfiguration;
+use CoreFramework\Factory\ObjectFactory;
+use CoreFramework\Loader\ClassLoader;
 use CoreFramework\Manager\ManageableApplication;
 use CoreFramework\Object\BaseFrameworkSystem;
-use CoreFramework\Factory\ObjectFactory;
 use CoreFramework\Registry\Registerable;
 use CoreFramework\Registry\Registry;
 use CoreFramework\Template\CompileableTemplate;
@@ -155,37 +158,54 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica
        }
 
        /**
-        * Launches the test suite
+        * 1) Setups application data
+        *
+        * @return      void
+        */
+       public function setupApplicationData () {
+               // Set all application data
+               $this->setAppName('Unit tests and more');
+               $this->setAppVersion('0.0.0');
+               $this->setAppShortName('tests');
+       }
+
+       /**
+        * 2) Does initial stuff before starting the application
         *
         * @return      void
         */
-       public final function entryPoint () {
-               // Set this application in registry
-               Registry::getRegistry()->addInstance('app', $this);
+       public function initApplication () {
+               // Get config instance
+               $cfg = FrameworkConfiguration::getSelfInstance();
 
-               // Default response is console
-               $response = self::getResponseTypeFromSystem();
-               $responseType = self::getResponseTypeFromSystem();
+               // Initialize output system
+               self::createDebugInstance('ApplicationHelper');
 
-               // Create a new request object
-               $requestInstance = ObjectFactory::createObjectByName(sprintf('CoreFramework\Request\%sRequest', self::convertToClassName($response)));
+               /*
+                * This application needs a database connection then simply call init
+                * method.
+                */
+               FrameworkBootstrap::initDatabaseInstance();
 
-               // Remember request instance here
-               $this->setRequestInstance($requestInstance);
+               // Register core tests
+               ClassLoader::registerTestsPath('framework/main/tests');
 
-               // Do we have another response?
-               if ($requestInstance->isRequestElementSet('request')) {
-                       // Then use it
-                       $response = strtolower($requestInstance->getRequestElement('request'));
-                       $responseType = $response;
-               } // END - if
+               // Register own tests
+               ClassLoader::registerTestsPath('application/tests/tests');
 
-               // ... and a new response object
-               $responseClass = sprintf('CoreFramework\Response\%sResponse', self::convertToClassName($response));
-               $responseInstance = ObjectFactory::createObjectByName($responseClass, array($this));
+               // Scan for them now
+               ClassLoader::scanTestsClasses();
+       }
 
-               // Remember response instance here
-               $this->setResponseInstance($responseInstance);
+       /**
+        * 3) Launches the application
+        *
+        * @return      void
+        */
+       public function launchApplication () {
+               // Get request/response instances
+               $requestInstance  = FrameworkBootstrap::getRequestInstance();
+               $responseInstance = FrameworkBootstrap::getResponseInstance();
 
                // Get the parameter from the request
                $commandName = $requestInstance->getRequestElement('command');
@@ -205,7 +225,7 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica
                        self::convertToClassName(sprintf(
                                '%s_%s_controller_resolver',
                                $this->getAppShortName(),
-                               $responseType
+                               FrameworkBootstrap::getRequestTypeFromSystem()
                        ))
                );
                $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this));
@@ -242,7 +262,7 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica
         * @return      $masterTemplateName             Name of the master template
         */
        public function buildMasterTemplateName () {
-               return 'node_main';
+               return 'tests_main';
        }
 
        /**