Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SIWECOS
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cUriBuilderMR
  • ModRewrite
  • ModRewrite_ContentController
  • ModRewrite_ContentExpertController
  • ModRewrite_ContentTestController
  • ModRewrite_ControllerAbstract
  • ModRewriteBase
  • ModRewriteController
  • ModRewriteDebugger
  • ModRewriteTest
  • ModRewriteUrlStack
  • ModRewriteUrlUtil

Functions

  • mr_arrayValue
  • mr_buildGeneratedCode
  • mr_buildNewUrl
  • mr_conCopyArtLang
  • mr_conMoveArticles
  • mr_conSaveArticle
  • mr_conSyncArticle
  • mr_debugOutput
  • mr_getConfiguration
  • mr_getConfigurationFilePath
  • mr_getRequest
  • mr_header
  • mr_i18n
  • mr_loadConfiguration
  • mr_queryAndNextRecord
  • mr_removeMultipleChars
  • mr_requestCleanup
  • mr_runFrontendController
  • mr_setClientLanguageId
  • mr_setConfiguration
  • mr_strCopyCategory
  • mr_strMovedownCategory
  • mr_strMoveSubtree
  • mr_strMoveUpCategory
  • mr_strNewCategory
  • mr_strNewTree
  • mr_strRenameCategory
  • mr_strSyncCategory
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * AMR test controller
  4:  *
  5:  * @package     Plugin
  6:  * @subpackage  ModRewrite
  7:  * @id          $Id$:
  8:  * @author      Murat Purc <murat@purc.de>
  9:  * @copyright   four for business AG <www.4fb.de>
 10:  * @license     http://www.contenido.org/license/LIZENZ.txt
 11:  * @link        http://www.4fb.de
 12:  * @link        http://www.contenido.org
 13:  */
 14: 
 15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 16: 
 17: /**
 18:  * Content controller to run tests.
 19:  *
 20:  * @author      Murat Purc <murat@purc.de>
 21:  * @package     Plugin
 22:  * @subpackage  ModRewrite
 23:  */
 24: class ModRewrite_ContentTestController extends ModRewrite_ControllerAbstract {
 25: 
 26:     /**
 27:      * Number of max items to process
 28:      * @var  int
 29:      */
 30:     protected $_iMaxItems = 0;
 31: 
 32:     /**
 33:      * Initializer method, sets some view variables
 34:      */
 35:     public function init() {
 36:         $this->_oView->content = '';
 37:         $this->_oView->form_idart_chk = ($this->_getParam('idart')) ? ' checked="checked"' : '';
 38:         $this->_oView->form_idcat_chk = ($this->_getParam('idcat')) ? ' checked="checked"' : '';
 39:         $this->_oView->form_idcatart_chk = ($this->_getParam('idcatart')) ? ' checked="checked"' : '';
 40:         $this->_oView->form_idartlang_chk = ($this->_getParam('idartlang')) ? ' checked="checked"' : '';
 41:         $this->_oView->form_maxitems = (int) $this->_getParam('maxitems', 200);
 42:         $this->_iMaxItems = $this->_oView->form_maxitems;
 43:     }
 44: 
 45:     /**
 46:      * Index action
 47:      */
 48:     public function indexAction() {
 49:         $this->_oView->content = '';
 50:     }
 51: 
 52:     /**
 53:      * Test action
 54:      *
 55:      * @throws cDbException
 56:      * @throws cException
 57:      * @throws cInvalidArgumentException
 58:      */
 59:     public function testAction() {
 60:         $this->_oView->content = '';
 61: 
 62:         // Array for testcases
 63:         $aTests = array();
 64: 
 65:         // Instance of mr test
 66:         $oMRTest = new ModRewriteTest($this->_iMaxItems);
 67: 
 68:         $startTime = getmicrotime();
 69: 
 70:         // Fetch complete CONTENIDO page structure
 71:         $aStruct = $oMRTest->fetchFullStructure();
 72:         ModRewriteDebugger::add($aStruct, 'mr_test.php $aStruct');
 73: 
 74:         // Loop through the structure and compose testcases
 75:         foreach ($aStruct as $idcat => $aCat) {
 76:             // category
 77:             $aTests[] = array(
 78:                 'url' => $oMRTest->composeURL($aCat, 'c'),
 79:                 'level' => $aCat['level'],
 80:                 'name' => $aCat['name']
 81:             );
 82: 
 83:             foreach ($aCat['articles'] as $idart => $aArt) {
 84:                 // articles
 85:                 $aTests[] = array(
 86:                     'url' => $oMRTest->composeURL($aArt, 'a'),
 87:                     'level' => $aCat['level'],
 88:                     'name' => $aCat['name'] . ' :: ' . $aArt['title']
 89:                 );
 90:             }
 91:         }
 92: 
 93:         // compose content
 94:         $this->_oView->content = '<pre>';
 95: 
 96:         $oMRUrlStack = ModRewriteUrlStack::getInstance();
 97: 
 98:         // first loop to add urls to mr url stack
 99:         foreach ($aTests as $p => $v) {
100:             $oMRUrlStack->add($v['url']);
101:         }
102: 
103:         $successCounter = 0;
104:         $failCounter = 0;
105: 
106:         // second loop to do the rest
107:         foreach ($aTests as $p => $v) {
108:             $url = mr_buildNewUrl($v['url']);
109:             $arr = $oMRTest->resolveUrl($url);
110:             $error = '';
111:             $resUrl = $oMRTest->getResolvedUrl();
112:             $color = 'green';
113: 
114:             if ($url !== $resUrl) {
115:                 if ($oMRTest->getRoutingFoundState()) {
116:                     $successCounter++;
117:                     $resUrl = 'route to -&gt; ' . $resUrl;
118:                 } else {
119:                     $color = 'red';
120:                     $failCounter++;
121:                 }
122:             } else {
123:                 $successCounter++;
124:             }
125: 
126:             // @todo: translate
127:             if (isset($arr['error'])) {
128:                 switch ($arr['error']) {
129:                     case ModRewriteController::ERROR_CLIENT:
130:                         $error = 'client';
131:                         break;
132:                     case ModRewriteController::ERROR_LANGUAGE:
133:                         $error = 'language';
134:                         break;
135:                     case ModRewriteController::ERROR_CATEGORY:
136:                         $error = 'category';
137:                         break;
138:                     case ModRewriteController::ERROR_ARTICLE:
139:                         $error = 'article';
140:                         break;
141:                     case ModRewriteController::ERROR_POST_VALIDATION:
142:                         $error = 'validation';
143:                         break;
144:                 }
145:             }
146: 
147:             $pref = str_repeat('    ', $v['level']);
148: 
149:             // render resolve information for current item
150:             $itemTpl = $this->_oView->lng_result_item_tpl;
151:             $itemTpl = str_replace('{pref}', $pref, $itemTpl);
152:             $itemTpl = str_replace('{name}', $v['name'], $itemTpl);
153:             $itemTpl = str_replace('{url_in}', $v['url'], $itemTpl);
154:             $itemTpl = str_replace('{url_out}', $url, $itemTpl);
155:             $itemTpl = str_replace('{color}', $color, $itemTpl);
156:             $itemTpl = str_replace('{url_res}', $resUrl, $itemTpl);
157:             $itemTpl = str_replace('{err}', $error, $itemTpl);
158:             $itemTpl = str_replace('{data}', $oMRTest->getReadableResolvedData($arr), $itemTpl);
159: 
160:             $this->_oView->content .= "\n" . $itemTpl . "\n";
161:         }
162:         $this->_oView->content .= '</pre>';
163: 
164:         $totalTime = sprintf('%.4f', (getmicrotime() - $startTime));
165: 
166:         // render information about current test
167:         $msg = $this->_oView->lng_result_message_tpl;
168:         $msg = str_replace('{time}', $totalTime, $msg);
169:         $msg = str_replace('{num_urls}', ($successCounter + $failCounter), $msg);
170:         $msg = str_replace('{num_success}', $successCounter, $msg);
171:         $msg = str_replace('{num_fail}', $failCounter, $msg);
172: 
173:         $this->_oView->content = $msg . $this->_oView->content;
174:     }
175: 
176: }
177: 
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0