Changeset 380

Show
Ignore:
Timestamp:
03/09/07 23:59:56 (2 years ago)
Author:
laurentj
Message:

improvement on the unittest class : ability to display difference between two string; added new classes for futur unit test case on jtpl compiler

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build/manifests/testapp.mn

    r372 r380  
    6565  testevents.listener.php 
    6666  utcreateurls.class.php 
     67  utjtplexpr.class.php 
    6768  utparseurls.class.php 
    6869  utselectoract.class.php 
     
    9394  urlsig.classic.php 
    9495  dao.classic.php 
     96  tpl.classic.php 
    9597 
    9698cd testapp/var 
  • trunk/lib/jelix/tpl/jTplCompiler.class.php

    r367 r380  
    4444       T_PROTECTED, T_RETURN, T_STATIC, T_SWITCH, T_THROW, T_TRY, T_USE, T_VAR, T_WHILE); 
    4545 
    46     private $_allowedInVar; 
    47     private $_allowedInExpr; 
    48     private $_allowedAssign; 
    49     private $_allowedInForeach; 
     46    protected $_allowedInVar; 
     47    protected $_allowedInExpr; 
     48    protected $_allowedAssign; 
     49    protected $_allowedInForeach; 
    5050 
    5151    private $_pluginPath=array(); 
     
    231231    * @return string the corresponding php instruction 
    232232    */ 
    233     private function _parseVariable($expr){ 
     233    protected function _parseVariable($expr){ 
    234234        $tok = explode('|',$expr); 
    235235        $res = $this->_parseFinal(array_shift($tok),$this->_allowedInVar); 
     
    271271     * @return string the corresponding php instructions 
    272272     */ 
    273     private function _parseFunction($name,$args){ 
     273    protected function _parseFunction($name,$args){ 
    274274        $res=''; 
    275275        switch($name) { 
     
    383383     * @return array|string 
    384384     */ 
    385     private function _parseFinal($string, $allowed=array(), $exceptchar=array(';'), $splitArgIntoArray=false){ 
     385    protected function _parseFinal($string, $allowed=array(), $exceptchar=array(';'), $splitArgIntoArray=false){ 
    386386        $tokens = token_get_all('<?php '.$string.'?>'); 
    387387 
     
    474474    } 
    475475 
    476     private function _parseMeta($args, $fct=''){ 
     476    protected function _parseMeta($args, $fct=''){ 
    477477        if(preg_match("/^(\w+)\s+(.*)$/",$args,$m)){ 
    478478            $argfct=$this->_parseFinal($m[2],$this->_allowedInExpr); 
     
    493493     * @return string the path of the plugin, or '' if not found 
    494494     */ 
    495     private function _getPlugin($type, $name){ 
     495    protected function _getPlugin($type, $name){ 
    496496#if JTPL_STANDALONE 
    497497        $treq = 'html'; 
  • trunk/testapp/modules/unittest/classes/jhtmlrespreporter.class.php

    r318 r380  
    33* @package    testapp 
    44* @subpackage unittest 
    5 * @version    $Id$ 
    65* @author     Jouanneau Laurent 
    76* @contributor 
    8 * @copyright  2005-2006 Jouanneau laurent 
     7* @copyright  2005-2007 Jouanneau laurent 
    98* @link        http://www.jelix.org 
    109* @licence    GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 
     
    1312 
    1413require_once(LIB_PATH.'/simpletest/reporter.php'); 
     14require_once(LIB_PATH.'diff/diffhtml.php'); 
    1515 
    1616class jHtmlRespReporter extends SimpleReporter { 
     
    6262   function paintException($message) { 
    6363      parent::paintException($message); 
    64       $str=  "<span class=\"fail\">Exception</span>: "; 
     64      $str=  "<span class=\"exception\">Exception</span>: "; 
    6565      $breadcrumb = $this->getTestList(); 
    6666      array_shift($breadcrumb); 
     
    8888   } 
    8989 
     90   function paintDiff($stringA, $stringB){ 
     91        $diff = new Diff(explode("\n",$stringA),explode("\n",$stringB)); 
     92        if($diff->isEmpty()) { 
     93            $this->_response->body->append('MAIN','<p>Erreur diff : bizarre, aucune diff�nce d\'apr�la difflib...</p>'); 
     94        }else{ 
     95            $fmt = new HtmlUnifiedDiffFormatter(); 
     96            $this->_response->body->append('MAIN',$fmt->format($diff)); 
     97        } 
     98   } 
     99 
    90100   function _htmlEntities($message) { 
    91101      global $gJConfig; 
  • trunk/testapp/modules/unittest/classes/junittestcase.class.php

    r372 r380  
    33* @package     testapp 
    44* @subpackage  unittest 
    5 * @version     $Id$ 
    65* @author      Jouanneau Laurent 
    76* @contributor 
    8 * @copyright   2006 Jouanneau laurent 
     7* @copyright   2006-2007 Jouanneau laurent 
    98* @link        http://www.jelix.org 
    109* @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 
     
    1312class jUnitTestCase extends UnitTestCase { 
    1413 
     14    /** 
     15    *    show difference between two strings 
     16    *    @param string $stringA  the first string 
     17    *    @param string $stringB  the second string 
     18    *    @param string $message        Message to send. 
     19    *    @access public 
     20    */ 
     21    function diff($stringA, $stringB, $message='') { 
     22        if (! isset($this->_reporter)) { 
     23            trigger_error('Can only show diff within test methods'); 
     24        } 
     25        if($message != '') 
     26            $this->_reporter->paintMessage($message); 
     27        $this->_reporter->paintDiff($stringA, $stringB); 
     28    } 
     29 
     30    function assertEqualOrDiff($first, $second, $message = "%s"){ 
     31        $ret = $this->assertEqual($first, $second, $message); 
     32        if(!$ret && is_string($first) && is_string($second)) 
     33            $this->diff($first, $second); 
     34        return $ret; 
     35    } 
    1536 
    1637    function assertComplexIdentical($value, $file, $errormessage=''){ 
  • trunk/testapp/modules/unittest/classes/unittestservice.class.php

    r371 r380  
    7777      $test->run(new jHtmlRespReporter($this->_rep)); 
    7878   } 
     79 
     80   function jtplExprTest(){ 
     81      $test = jClasses::create("utjtplexpr"); 
     82      $test->run(new jHtmlRespReporter($this->_rep)); 
     83   } 
    7984} 
    8085?> 
  • trunk/testapp/modules/unittest/templates/menu.tpl

    r371 r380  
    77<ul> 
    88    <li><a href="{jurl 'unittest~testselectoract'}">selecteurs d'action</a></li> <!--?module=unittest&amp;action=testselectoract--> 
     9    <li><a href="?module=unittest&amp;action=testlocaleprop">lecture .properties</a></li> 
     10 
     11{if $isurlsig} 
     12<li>test urls : 
     13<a href="{jurl 'unittest~urlsig_url1',array('annee'=>'2006','mois'=>'10','id'=>'01')}">url1</a> 
     14<a href="{jurl 'unittest~urlsig_url9',array('annee'=>'2006','mois'=>'10','id'=>'09')}">url9</a> 
     15<a href="{jurl 'unittest~urlsig_url10',array('annee'=>'2006','mois'=>'10','id'=>'10')}">url10</a> 
     16<a href="{jurl 'unittest~urlsig_url3',array('rubrique'=>'voiture','id_art'=>'54','article'=>'dodge viper')}">url3</a> 
     17<a href="{jurl 'unittest~urlsig_url2',array('annee'=>'2005','mois'=>'7')}">url2</a> 
     18<a href="{jurl 'unittest~urlsig_url4',array('first'=>'premier parametre','second'=>'toto le rigolo')}">url4</a> 
     19</li>{/if} 
    920</ul> 
     21 
    1022<h3>jEvent</h3> 
    1123<ul> 
     
    1931</ul> 
    2032 
    21 <h3>jLocale</h3> 
     33<h3>jTpl</h3> 
    2234<ul> 
    23     <li><a href="?module=unittest&amp;action=testlocaleprop">Tester la lecture des properties</a></li> 
     35    <li><a href="?module=unittest&amp;action=tpl_parseExpression">expressions</a></li> 
    2436</ul> 
    2537 
    26 {if $isurlsig} 
    27 <p>test urls : 
    28 <a href="{jurl 'unittest~urlsig_url1',array('annee'=>'2006','mois'=>'10','id'=>'01')}">url1</a> 
    29 <a href="{jurl 'unittest~urlsig_url9',array('annee'=>'2006','mois'=>'10','id'=>'09')}">url9</a> 
    30 <a href="{jurl 'unittest~urlsig_url10',array('annee'=>'2006','mois'=>'10','id'=>'10')}">url10</a> 
    31 <a href="{jurl 'unittest~urlsig_url3',array('rubrique'=>'voiture','id_art'=>'54','article'=>'dodge viper')}">url3</a> 
    32 <a href="{jurl 'unittest~urlsig_url2',array('annee'=>'2005','mois'=>'7')}">url2</a> 
    33 <a href="{jurl 'unittest~urlsig_url4',array('first'=>'premier parametre','second'=>'toto le rigolo')}">url4</a> 
    34 </p>{/if} 
    3538<h3>jDao</h3> 
    3639<ul> 
  • trunk/testapp/www/design/screen.css

    r127 r380  
    6868} 
    6969 
     70div.exception { margin-top:4px; margin-bottom:4px; 
     71    background-color: #ff9186; 
     72    border: 1px solid red; } 
    7073 
     74div.exception strong {color: red;} 
     75div.exception p { font-size:0.9em; } 
    7176 
    72  
     77.diff { background: white; border: 1px solid black; } 
     78.diff .block { background: #ccc; padding-left: 1em; } 
     79.diff .context { background: white; border: none; } 
     80.diff .block tt { font-weight: normal;  font-family: monospace;  color: black; 
     81        margin-left: 0;  border: none; } 
     82.diff del, .diff ins {  font-weight: bold; text-decoration: none; } 
     83.diff .original, .diff .deleted, 
     84.diff .final, .diff .added {  background: white; } 
     85.diff .original, .diff .deleted {  background: #fcc;  border: none; } 
     86.diff .final, .diff .added {  background: #cfc; border: none; } 
     87.diff del { background: #f99; } 
     88.diff ins { background: #9f9; } 
    7389 
    7490 
Download in other formats: Unified Diff Zip Archive