Esempio n. 1
0
File: view.php Progetto: summea/mi
 public function display($param = '', $layout = '', $flash = '', $debug = '')
 {
     // prevent cache for form fields, etc.
     header("Cache-Control: no-store, no-cache, must-revalidate");
     header("Cache-Control: post-check=0, pre-check=0", false);
     # a bit of a hack FIXME
     // make certain config variables easier to use in views
     $BASE_URL = Configure::read('BASE_URL');
     if ($layout) {
         // if we have a specified layout
         if (file_exists(Configure::read('BASE_DIR') . '/app/views/' . $this->controller . '/' . $this->action . '.mhtml')) {
             ob_start();
             // start buffer
             include_once Configure::read('BASE_DIR') . '/app/views/' . $this->controller . '/' . $this->action . '.mhtml';
             $html = ob_get_contents();
             // pass the output to a variable
             ob_end_clean();
             // end buffer
             $content_for_layout = $debug . $flash . $html;
             try {
                 if (file_exists(Configure::read('BASE_DIR') . '/app/views/layouts/' . $layout . '.mhtml')) {
                     include Configure::read('BASE_DIR') . '/app/views/layouts/' . $layout . '.mhtml';
                 } else {
                     throw new Exception('There is no view for this layout! (' . $layout . ')');
                 }
             } catch (Exception $e) {
                 myExceptionHandler($e);
             }
         }
         try {
             if (!file_exists(Configure::read('BASE_DIR') . '/app/views/' . $this->controller . '/' . $this->action . '.mhtml')) {
                 throw new Exception($this->controller . '\' class could not be found');
             }
         } catch (Exception $e) {
             myExceptionHandler($e);
         }
     } else {
         // no specified layout, just show the view
         try {
             if (file_exists(Configure::read('BASE_DIR') . '/app/views/' . $this->controller . '/' . $this->action . '.mhtml')) {
                 include Configure::read('BASE_DIR') . '/app/views/' . $this->controller . '/' . $this->action . '.mhtml';
             } else {
                 throw new Exception('There is no view for this controller\'s
                                     action! (' . $this->controller . ' > ' . $this->action . ')');
             }
         } catch (Exception $e) {
             myExceptionHandler($e);
         }
     }
 }
Esempio n. 2
0
function __autoload($class)
{
    $class = strtolower($class);
    if (class_exists($class, false) || interface_exists($class, false)) {
        return;
    }
    try {
        @(require_once $LIB_DIR . $class . '.php');
        if (!class_exists($class, false)) {
            throw new Exception('Class ' . $class . ' not found');
        }
    } catch (Exception $e) {
        myExceptionHandler($e);
    }
}
 public static function main()
 {
     global $isLocal;
     // check number of arguments
     $isLocal = !isset($_SERVER['HTTP_USER_AGENT']);
     $arguments = array('listGroups' => FALSE, 'loader' => NULL, 'useDefaultConfiguration' => TRUE);
     $loader = NULL;
     $startPos = 1;
     $canCountTest = true;
     global $config_file;
     if ($isLocal && $_SERVER['argv'][1] == "-config" || !$isLocal && strcmp($config_file, "") != 0 && strcmp($config_file, "/*config_xml*/") != 0) {
         // check if configuration specified
         $canCountTest = false;
         $path = $isLocal ? $_SERVER['argv'][2] : $config_file;
         //$_GET["config_xml"];
         $arguments['configuration'] = $path;
         $startPos = 3;
         $configuration = PHPUnit_Util_Configuration::getInstance($path);
         $phpunit = $configuration->getPHPUnitConfiguration();
         if (isset($phpunit['testSuiteLoaderClass'])) {
             if (isset($phpunit['testSuiteLoaderFile'])) {
                 $file = $phpunit['testSuiteLoaderFile'];
             } else {
                 $file = '';
             }
             $command = new PHPUnit_TextUI_Command();
             $loader = $command->handleLoader($phpunit['testSuiteLoaderClass'], $file);
             $arguments['loader'] = $loader;
         }
         $configuration->handlePHPConfiguration();
         $phpunitConfiguration = $configuration->getPHPUnitConfiguration();
         if (isset($phpunitConfiguration['bootstrap'])) {
             PHPUnit_Util_Fileloader::load($phpunitConfiguration['bootstrap']);
         }
         $browsers = $configuration->getSeleniumBrowserConfiguration();
         if (!empty($browsers)) {
             require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
             PHPUnit_Extensions_SeleniumTestCase::$browsers = $browsers;
         }
     }
     if ($isLocal && $_SERVER['argv'][$startPos] == "-group" || !$isLocal && isset($_GET["groups"])) {
         $arguments['groups'] = explode(',', $isLocal ? $_SERVER['argv'][$startPos + 1] : $_GET["groups"]);
         $startPos += 2;
     }
     if ($isLocal && $_SERVER['argv'][$startPos] == "-exclude-group" || !$isLocal && isset($_GET["exclude_groups"])) {
         $arguments['excludeGroups'] = explode(',', $isLocal ? $_SERVER['argv'][$startPos + 1] : $_GET["exclude_groups"]);
         $startPos += 2;
     }
     $check = $isLocal ? $_SERVER['argv'][$startPos] : $_GET["mode"];
     if ($check == "c") {
         $suiteClassName = $isLocal ? $_SERVER['argv'][$startPos + 1] : $_GET["class"];
         $suiteClassFile = $isLocal ? $_SERVER['argv'][$startPos + 2] : $_GET["file"];
         try {
             // $testClass = ();
             if ($loader == NULL) {
                 $loader = new PHPUnit_Runner_StandardTestSuiteLoader();
             }
             $testClass = $loader->load($suiteClassName, $suiteClassFile, FALSE);
         } catch (Exception $e) {
             myExceptionHandler($e);
             return;
         }
         try {
             // if class is a suite
             $suiteMethod = $testClass->getMethod('suite');
             if ($suiteMethod->isAbstract() || !$suiteMethod->isPublic() || !$suiteMethod->isStatic()) {
                 return;
             }
             try {
                 // ?? suite does not have testName argument
                 $test = $suiteMethod->invoke(NULL, $testClass->getName());
                 $test->setName($suiteClassName);
                 if ($canCountTest) {
                     print traceCommand("testCount", "count", (string) sizeof($test));
                 }
                 self::runTest($test, $suiteClassFile, $arguments);
             } catch (ReflectionException $e) {
                 myExceptionHandler($e);
                 return;
             }
         } catch (ReflectionException $e) {
             $test = new PHPUnit_Framework_TestSuite($testClass);
             if ($canCountTest) {
                 print traceCommand("testCount", "count", (string) sizeof($test));
             }
             self::runTest($test, $suiteClassFile, $arguments);
         }
     } else {
         if ($check == "d") {
             // if run directory
             // in remote case we put this script in the test directory
             $suiteDirName = $isLocal ? $_SERVER['argv'][$startPos + 1] : dirname(__FILE__);
             if (is_dir($suiteDirName) && !is_file($suiteDirName . '.php')) {
                 $testCollector = new PHPUnit_Runner_IncludePathTestCollector(array($suiteDirName));
                 // $test = new PHPUnit_Framework_TestSuite($suiteDirName);
                 $filenames = $testCollector->collectTests();
                 $number = 0;
                 $alltests = array();
                 foreach ($filenames as $filename) {
                     $tests = self::collectTestsFromFile($filename);
                     foreach ($tests as $currenttest) {
                         $number += sizeof($currenttest);
                         $alltests[] = $currenttest;
                         $alltests[] = $filename;
                     }
                 }
                 if ($canCountTest) {
                     print traceCommand("testCount", "count", (string) $number);
                 }
                 for ($i = 0; $i < count($alltests); $i += 2) {
                     self::runTest($alltests[$i], $alltests[$i + 1], $arguments);
                 }
                 return;
             }
         } else {
             if ($check == 'f') {
                 // if run all in file
                 $filename = $isLocal ? $_SERVER['argv'][$startPos + 1] : $_GET["file"];
                 $tests = self::collectTestsFromFile($filename);
                 $test = new PHPUnit_Framework_TestSuite();
                 $number = 0;
                 foreach ($tests as $currenttest) {
                     if ($tests) {
                         $test->addTest($currenttest);
                         $number += sizeof($currenttest);
                     }
                 }
                 if ($canCountTest) {
                     print traceCommand("testCount", "count", $number);
                 }
                 foreach ($tests as $currentTest) {
                     self::runTest($currentTest, $filename, $arguments);
                 }
                 return;
             } else {
                 if ($check == 'm') {
                     $suiteMethodName = $isLocal ? $_SERVER['argv'][$startPos + 1] : $_GET["method"];
                     $suiteClassName = $isLocal ? $_SERVER['argv'][$startPos + 2] : $_GET["class"];
                     $suiteClassFile = $isLocal ? $_SERVER['argv'][$startPos + 3] : $_GET["file"];
                     try {
                         $testClass = new PHPUnit_Runner_StandardTestSuiteLoader();
                         $testClass = $testClass->load($suiteClassName, $suiteClassFile, FALSE);
                     } catch (Exception $e) {
                         myExceptionHandler($e);
                         return;
                     }
                     try {
                         // if class is a suite
                         $suiteMethod = $testClass->getMethod($suiteMethodName);
                         if ($suiteMethodName == 'suite') {
                             if ($suiteMethod->isAbstract() || !$suiteMethod->isPublic() || !$suiteMethod->isStatic()) {
                                 return;
                             }
                             try {
                                 $test = $suiteMethod->invoke(NULL, $testClass->getName());
                                 $test->setName($suiteClassName);
                                 if ($canCountTest) {
                                     print traceCommand("testCount", "count", (string) sizeof($test));
                                 }
                                 self::runTest($test, $suiteClassFile, $arguments);
                             } catch (ReflectionException $e) {
                                 myExceptionHandler($e);
                                 return;
                             }
                         } else {
                             $test = PHPUnit_Framework_TestSuite::createTest($testClass, $suiteMethodName);
                             $testSuite = new PHPUnit_Framework_TestSuite();
                             $testSuite->addTest($test);
                             $testSuite->setName($suiteClassName);
                             if ($canCountTest) {
                                 print traceCommand("testCount", "count", (string) sizeof($test));
                             }
                             self::runTest($testSuite, $suiteClassFile, $arguments);
                         }
                     } catch (ReflectionException $e) {
                         myExceptionHandler($e);
                         return;
                     }
                 } else {
                     if ($check == 'x') {
                         $testSuite = $configuration->getTestSuiteConfiguration();
                         self::runTest($testSuite, "", $arguments);
                     }
                 }
             }
         }
     }
 }
Esempio n. 4
0
File: model.php Progetto: summea/mi
 public function destroy($id)
 {
     try {
         if (empty($id)) {
             throw new Exception('No id to destroy!');
         } else {
             $db = Model::openDBConnection();
             if (isset($id)) {
                 // DELETE QUERY
                 $query = sprintf("delete from %s where id=%d", $this->useTable, $id);
             }
             $query = $this->execute($query);
             return $return_this;
         }
     } catch (Exception $e) {
         myExceptionHandler($e);
     }
 }