public function indexAction()
 {
     Zend_Registry::set('db', false);
     Kwf_Test_SeparateDb::setDbFromCookie();
     // setzt es nur wenn es das cookie wirklich gibt
     //FnF models setzen damit tests nicht in echte tabellen schreiben
     Kwf_Component_Cache::setInstance(Kwf_Component_Cache::CACHE_BACKEND_FNF);
     Kwf_Component_Cache_Memory::setInstance(new Kwf_Component_Cache_MemoryBlackHole());
     /*
     if (class_exists('APCIterator')) {
         $prefix = Kwf_Cache::getUniquePrefix();
         apc_delete_file(new APCIterator('user', '#^'.$prefix.'#'));
     } else {
         apc_clear_cache('user');
     }
     */
     Kwf_Component_Data_Root::setComponentClass($this->_getParam('root'));
     Zend_Registry::set('testRootComponentClass', $this->_getParam('root'));
     $root = Kwf_Component_Data_Root::getInstance();
     $root->setFilename('kwf/kwctest/' . $this->_getParam('root'));
     $url = $this->_getParam('url');
     $urlParts = explode('/', $url);
     if (is_array($urlParts) && $urlParts[0] == 'media') {
         if (sizeof($urlParts) != 7) {
             throw new Kwf_Exception_NotFound();
         }
         $class = $urlParts[1];
         $id = $urlParts[2];
         $type = $urlParts[3];
         $checksum = $urlParts[4];
         // time() wäre der 5er, wird aber nur wegen browsercache benötigt
         $filename = $urlParts[6];
         if ($checksum != Kwf_Media::getChecksum($class, $id, $type, $filename)) {
             throw new Kwf_Exception_AccessDenied('Access to file not allowed.');
         }
         Kwf_Media_Output::output(Kwf_Media::getOutput($class, $id, $type));
     }
     if ($url == 'kwf/util/kwc/render') {
         if (isset($_REQUEST['url'])) {
             $_REQUEST['url'] = str_replace('/' . $root->filename, '', $_REQUEST['url']);
         }
         Kwf_Util_Component::dispatchRender();
     }
     $domain = 'http://' . Zend_Registry::get('config')->server->domain;
     $data = $root->getPageByUrl($domain . Kwf_Setup::getBaseUrl() . '/' . $url, null);
     if (!$data) {
         throw new Kwf_Exception_NotFound();
     }
     $root->setCurrentPage($data);
     $contentSender = Kwc_Abstract::getSetting($data->componentClass, 'contentSender');
     $contentSender = new $contentSender($data);
     $contentSender->sendContent(true);
     Kwf_Benchmark::shutDown();
     Kwf_Benchmark::output();
     exit;
 }
Exemplo n.º 2
0
 public static function ensureHttp()
 {
     if (php_sapi_name() != 'cli') {
         if (isset($_SERVER['HTTPS']) && $_SERVER['REQUEST_METHOD'] != 'POST' && !Kwf_Session::sessionExists()) {
             $redirect = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
             header('Location: ' . $redirect, true, 302);
             Kwf_Benchmark::shutDown();
             exit;
         }
     }
 }
Exemplo n.º 3
0
 public static function output($file)
 {
     self::outputWithoutShutdown($file);
     Kwf_Benchmark::shutDown();
     exit;
 }
Exemplo n.º 4
0
 public function dispatch(Zend_Controller_Request_Abstract $request = null, Zend_Controller_Response_Abstract $response = null)
 {
     if ($request === null) {
         if (PHP_SAPI == 'cli') {
             $request = new Kwf_Controller_Request_Cli();
         } else {
             $request = new Kwf_Controller_Request_Http();
         }
     }
     if ($response === null) {
         $response = new Kwf_Controller_Response_Http();
     }
     try {
         $ret = parent::dispatch($request, $response);
     } catch (Zend_Controller_Router_Exception $e) {
         if ($e->getCode() == 404) {
             //fired by Zend_Controller_Router_Rewrite::route, transform into proper 404
             throw new Kwf_Exception_NotFound();
         } else {
             throw $e;
         }
     }
     Kwf_Benchmark::shutDown();
     return $ret;
 }
Exemplo n.º 5
0
 public static function dispatchKwc()
 {
     $requestPath = self::getRequestPath();
     if ($requestPath === false) {
         return;
     }
     $fullRequestPath = $requestPath;
     $data = null;
     $baseUrl = Kwf_Setup::getBaseUrl();
     if ($baseUrl) {
         if (substr($requestPath, 0, strlen($baseUrl)) != $baseUrl) {
             throw new Kwf_Exception_NotFound();
         }
         $requestPath = substr($requestPath, strlen($baseUrl));
     }
     $uri = substr($requestPath, 1);
     $i = strpos($uri, '/');
     if ($i) {
         $uri = substr($uri, 0, $i);
     }
     if ($uri == 'robots.txt') {
         Kwf_Util_RobotsTxt::output();
     }
     if ($uri == 'sitemap.xml') {
         $data = Kwf_Component_Data_Root::getInstance()->getPageByUrl('http://' . $_SERVER['HTTP_HOST'] . Kwf_Setup::getBaseUrl() . '/', null);
         Kwf_Component_Sitemap::output($data->getDomainComponent());
     }
     if (!in_array($uri, array('media', 'kwf', 'admin', 'assets', 'vkwf', 'api'))) {
         if (!isset($_SERVER['HTTP_HOST'])) {
             $requestUrl = 'http://' . Kwf_Config::getValue('server.domain') . $fullRequestPath;
         } else {
             $requestUrl = 'http://' . $_SERVER['HTTP_HOST'] . $fullRequestPath;
         }
         Kwf_Trl::getInstance()->setUseUserLanguage(false);
         $root = Kwf_Component_Data_Root::getInstance();
         foreach ($root->getPlugins('Kwf_Component_PluginRoot_Interface_PreDispatch') as $p) {
             $p->preDispatch($requestUrl);
         }
         $acceptLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null;
         $exactMatch = true;
         $data = $root->getPageByUrl($requestUrl, $acceptLanguage, $exactMatch);
         Kwf_Benchmark::checkpoint('getPageByUrl');
         if (!$data) {
             throw new Kwf_Exception_NotFound();
         }
         if (!$exactMatch) {
             if (rawurldecode($data->url) == $fullRequestPath) {
                 throw new Kwf_Exception("getPageByUrl reported this isn't an exact match, but the urls are equal. wtf.");
             }
             $url = $data->url;
             if (!$url) {
                 // e.g. firstChildPageData without child pages
                 throw new Kwf_Exception_NotFound();
             }
             foreach ($root->getPlugins('Kwf_Component_PluginRoot_Interface_PostRender') as $p) {
                 $url = $p->processUrl($url);
             }
             if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING']) {
                 $url .= '?' . $_SERVER['QUERY_STRING'];
             }
             header('Location: ' . $url, true, 301);
             exit;
         }
         $root->setCurrentPage($data);
         Kwf_User_Autologin::processCookies();
         $contentSender = Kwf_Component_Settings::getSetting($data->componentClass, 'contentSender');
         $contentSender = new $contentSender($data);
         $contentSender->sendContent(true);
         Kwf_Benchmark::shutDown();
         //TODO: ein flag oder sowas ähnliches stattdessen verwenden
         if ($data instanceof Kwc_Abstract_Feed_Component || $data instanceof Kwc_Export_Xml_Component || $data instanceof Kwc_Export_Xml_Trl_Component) {
             echo "<!--";
         }
         Kwf_Benchmark::output();
         if ($data instanceof Kwc_Abstract_Feed_Component || $data instanceof Kwc_Export_Xml_Component || $data instanceof Kwc_Export_Xml_Trl_Component) {
             echo "-->";
         }
         exit;
     } else {
         if ($requestPath == '/kwf/util/kwc/render') {
             Kwf_User_Autologin::processCookies();
             Kwf_Util_Component::dispatchRender();
         }
     }
 }
Exemplo n.º 6
0
 public static function handleException($exception)
 {
     if ($exception instanceof Zend_Controller_Exception && $exception->getPrevious()) {
         $exception = $exception->getPrevious();
     }
     if (!$exception instanceof Kwf_Exception_Abstract) {
         $exception = new Kwf_Exception_Other($exception);
     }
     $exception->render();
     Kwf_Benchmark::shutDown();
     Kwf_Benchmark::output();
 }
Exemplo n.º 7
0
 public static function dispatchRender()
 {
     if ((!isset($_REQUEST['url']) || !$_REQUEST["url"]) && (!isset($_REQUEST['componentId']) || !$_REQUEST['componentId']) && (!isset($_REQUEST['dbId']) || !$_REQUEST['dbId'])) {
         throw new Kwf_Exception_NotFound();
     }
     if (isset($_REQUEST['pageUrl'])) {
         foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_PreDispatch') as $plugin) {
             $plugin->preDispatch($_REQUEST['pageUrl']);
         }
     }
     if (isset($_REQUEST['componentId'])) {
         $data = Kwf_Component_Data_Root::getInstance()->getComponentById($_REQUEST['componentId']);
     } else {
         if (isset($_REQUEST['dbId'])) {
             $data = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($_REQUEST['dbId'], array('limit' => 1));
         } else {
             $url = $_REQUEST['url'];
             if (!is_string($url)) {
                 throw new Kwf_Exception_NotFound();
             }
             $parsedUrl = parse_url($url);
             if (isset($parsedUrl['query'])) {
                 foreach (explode('&', $parsedUrl['query']) as $get) {
                     if (!$get) {
                         continue;
                     }
                     $pos = strpos($get, '=');
                     $_GET[substr($get, 0, $pos)] = substr($get, $pos + 1);
                     //ouch
                     $_REQUEST[substr($get, 0, $pos)] = substr($get, $pos + 1);
                     //ouch
                 }
             }
             foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_PreDispatch') as $p) {
                 $p->preDispatch($url);
             }
             $data = Kwf_Component_Data_Root::getInstance()->getPageByUrl($url, null);
         }
     }
     if (!$data) {
         throw new Kwf_Exception_NotFound();
     }
     $contentSender = Kwc_Abstract::getSetting($data->componentClass, 'contentSender');
     $contentSender = new $contentSender($data);
     $content = $contentSender->getContent(false);
     $content['contents'] = $content['content'];
     unset($content['content']);
     if (!isset($content['lifetime'])) {
         $content['lifetime'] = false;
     }
     if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'json') {
         $content['contents'] = json_encode(array('mimeType' => $content['mimeType'], 'content' => $content['contents'], 'assets' => $content['assets']));
         $content['mimeType'] = 'application/json';
     }
     Kwf_Media_Output::output($content);
     Kwf_Benchmark::shutDown();
     exit;
 }
 public function indexAction()
 {
     self::initForTests();
     if (!Kwf_Registry::get('config')->server->domain) {
         throw new Kwf_Exception_Client("Can't run tests; server.domain is not set. Please set in tests/config.local.ini");
     }
     $arguments = array();
     $arguments['colors'] = true;
     $arguments['filter'] = false;
     if ($this->_getParam('filter')) {
         $arguments['filter'] = $this->_getParam('filter');
     }
     $arguments['groups'] = array();
     if ($this->_getParam('group')) {
         $arguments['groups'] = explode(',', $this->_getParam('group'));
     }
     $arguments['excludeGroups'] = array();
     if ($this->_getParam('exclude-group')) {
         $arguments['excludeGroups'] = explode(',', $this->_getParam('exclude-group'));
     }
     $arguments['verbose'] = false;
     if ($this->_getParam('verbose')) {
         $arguments['verbose'] = $this->_getParam('verbose');
     }
     if ($this->_getParam('stop-on-failure')) {
         $arguments['stopOnFailure'] = $this->_getParam('stop-on-failure');
     }
     if ($this->_getParam('log-xml')) {
         $arguments['xmlLogfile'] = $this->_getParam('log-xml');
     }
     if ($this->_getParam('log-pmd')) {
         $arguments['pmdXML'] = $this->_getParam('log-pmd');
     }
     if ($this->_getParam('log-metrics')) {
         $arguments['metricsXML'] = $this->_getParam('log-metrics');
     }
     if ($this->_getParam('coverage-xml')) {
         $arguments['coverageClover'] = $this->_getParam('coverage-xml');
     }
     if ($this->_getParam('retry-on-error')) {
         $arguments['retryOnError'] = $this->_getParam('retry-on-error');
     }
     if ($this->_getParam('coverage')) {
         if (!extension_loaded('tokenizer') || !extension_loaded('xdebug')) {
             throw new Kwf_ClientException('tokenizer and xdebug extensions must be loaded');
         }
         if (!is_string($this->_getParam('coverage'))) {
             $arguments['reportDirectory'] = './report';
         } else {
             $arguments['reportDirectory'] = $this->_getParam('coverage');
         }
     }
     Kwf_Registry::set('testDomain', Kwf_Registry::get('config')->server->domain);
     Kwf_Registry::set('testServerConfig', Kwf_Registry::get('config'));
     if ($this->_getParam('report')) {
         $resultLogger = new Kwf_Test_ResultLogger(true);
         $arguments['listeners'][] = $resultLogger;
     }
     if ($this->_getParam('testdox')) {
         $arguments['printer'] = new PHPUnit_Util_TestDox_ResultPrinter_Text();
         $arguments['noProgress'] = true;
     } else {
         if ($this->_getParam('no-progress')) {
             $arguments['noProgress'] = true;
         }
     }
     if ($this->_getParam('disable-debug')) {
         Kwf_Debug::disable();
     }
     //nur temporär deaktiviert, damit ich selenium-verbindungs-probleme besser debuggen kann
     //         PHPUnit_Util_Filter::setFilter(false);
     $runner = new Kwf_Test_TestRunner();
     $suite = new Kwf_Test_TestSuite();
     Kwf_Model_Abstract::clearInstances();
     $result = $runner->doRun($suite, $arguments);
     if ($this->_getParam('report')) {
         $resultLogger->printResult($result);
         $reportData = array('tests' => $result->count(), 'failures' => $result->failureCount() + $result->errorCount(), 'skipped' => $result->skippedCount(), 'not_implemented' => $result->notImplementedCount(), 'kwf_version' => Kwf_Util_Git::kwf()->getActiveBranch() . ' (' . Kwf_Util_Git::kwf()->revParse('HEAD') . ')');
         if (Kwf_Registry::get('config')->application->id != 'kwf') {
             $reportData['web_version'] = Kwf_Util_Git::web()->getActiveBranch() . ' (' . Kwf_Util_Git::web()->revParse('HEAD') . ')';
         }
         echo "===REPORT===";
         echo serialize($reportData);
         echo "===/REPORT===";
     }
     Kwf_Benchmark::shutDown();
     if ($result->wasSuccessful()) {
         exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
     } else {
         if ($result->errorCount() > 0) {
             exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
         } else {
             exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
         }
     }
     $this->_helper->viewRenderer->setNoRender(true);
 }
Exemplo n.º 9
0
 public static function dispatchRender()
 {
     if ((!isset($_REQUEST['url']) || !$_REQUEST["url"]) && (!isset($_REQUEST['componentId']) || !$_REQUEST['componentId']) && (!isset($_REQUEST['dbId']) || !$_REQUEST['dbId'])) {
         throw new Kwf_Exception_NotFound();
     }
     if (isset($_REQUEST['componentId'])) {
         $data = Kwf_Component_Data_Root::getInstance()->getComponentById($_REQUEST['componentId']);
     } else {
         if (isset($_REQUEST['dbId'])) {
             $data = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($_REQUEST['dbId'], array('limit' => 1));
         } else {
             $url = $_REQUEST['url'];
             if (!is_string($url)) {
                 throw new Kwf_Exception_NotFound();
             }
             $parsedUrl = parse_url($url);
             if (isset($parsedUrl['query'])) {
                 foreach (explode('&', $parsedUrl['query']) as $get) {
                     if (!$get) {
                         continue;
                     }
                     $pos = strpos($get, '=');
                     $_GET[substr($get, 0, $pos)] = substr($get, $pos + 1);
                     //ouch
                     $_REQUEST[substr($get, 0, $pos)] = substr($get, $pos + 1);
                     //ouch
                 }
             }
             $data = Kwf_Component_Data_Root::getInstance()->getPageByUrl($url, null);
         }
     }
     if (!$data) {
         throw new Kwf_Exception_NotFound();
     }
     $contentSender = Kwc_Abstract::getSetting($data->componentClass, 'contentSender');
     $contentSender = new $contentSender($data);
     $contentSender->sendContent(false);
     Kwf_Benchmark::shutDown();
     exit;
 }