[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/wact/tests/cases/filters/ -> clip_filter.test.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  
  10  require_once('limb/wact/tests/cases/WactTemplateTestCase.class.php');
  11  
  12  class WactTemplateClipFilterTestCase extends WactTemplateTestCase
  13  {
  14    function testSimpleClipVar()
  15    {
  16      $template = '{$val|clip:5}';
  17  
  18      $this->registerTestingTemplate('/template/filter/clip/clipvar.html', $template);
  19      $page = $this->initTemplate('/template/filter/clip/clipvar.html');
  20      $page->set('val', 'abcdefgh');
  21  
  22      $output = $page->capture();
  23      $this->assertEqual($output, 'abcde');
  24    }
  25  
  26    function testSimpleClipLiteral()
  27    {
  28      $template = '<core:set str="abcdefgh" />{$str|clip:5}';
  29  
  30      $this->registerTestingTemplate('/template/filter/clip/clipstr.html', $template);
  31      $page = $this->initTemplate('/template/filter/clip/clipstr.html');
  32  
  33      $output = $page->capture();
  34      $this->assertEqual($output, 'abcde');
  35    }
  36  
  37    function testSimpleClipVarStart()
  38    {
  39      $template = '{$val|clip:5,2}';
  40  
  41      $this->registerTestingTemplate('/template/filter/clip/clipvarstart.html', $template);
  42      $page = $this->initTemplate('/template/filter/clip/clipvarstart.html');
  43      $page->set('val','abcdefgh');
  44  
  45      $output = $page->capture();
  46      $this->assertEqual($output, 'cdefg');
  47    }
  48  
  49    function testSimpleClipLiteralStart()
  50    {
  51      $template = '<core:set str="abcdefgh" />{$str|clip:5,2}';
  52  
  53      $this->registerTestingTemplate('/template/filter/clip/clipstrstart.html', $template);
  54      $page = $this->initTemplate('/template/filter/clip/clipstrstart.html');
  55  
  56      $output = $page->capture();
  57      $this->assertEqual($output, 'cdefg');
  58    }
  59  
  60    function testSimpleClipVarSuffix()
  61    {
  62      $template = '{$val|clip:5,0,"..."} {$val|clip:12,0,"..."}';
  63  
  64      $this->registerTestingTemplate('/template/filter/clip/clipvarsuf.html', $template);
  65      $page = $this->initTemplate('/template/filter/clip/clipvarsuf.html');
  66      $page->set('val','abcdefgh');
  67  
  68      $output = $page->capture();
  69      $this->assertEqual($output, 'abcde... abcdefgh');
  70    }
  71  
  72    function testSimpleClipLiteralSuffix()
  73    {
  74      $template = '<core:set str="abcdefgh" />{$str|clip:5,0,"..."} {$str|clip:12,0,"..."}';
  75  
  76      $this->registerTestingTemplate('/template/filter/clip/clipstrsuf.html', $template);
  77      $page = $this->initTemplate('/template/filter/clip/clipstrsuf.html');
  78  
  79      $output = $page->capture();
  80      $this->assertEqual($output, 'abcde... abcdefgh');
  81    }
  82  
  83    function testSimpleClipLiteralLenVarSuffix()
  84    {
  85      $template = '<core:set str="abcdefgh" />{$str|clip:len,0,"..."} {$str|clip:len2,0,"..."}';
  86  
  87      $this->registerTestingTemplate('/template/filter/clip/clipstrsuflenvar.html', $template);
  88      $page = $this->initTemplate('/template/filter/clip/clipstrsuflenvar.html');
  89      $page->set('len', 5);
  90      $page->set('len2', 12);
  91  
  92      $output = $page->capture();
  93      $this->assertEqual($output, 'abcde... abcdefgh');
  94    }
  95  
  96    function testLongStringWordBoundary()
  97    {
  98      $template = '{$val|clip:35,0,"...","n"} {$val|clip:35,0,"...","y"}';
  99  
 100      $this->registerTestingTemplate('/template/filter/clip/clipvarwordbound.html', $template);
 101      $page = $this->initTemplate('/template/filter/clip/clipvarwordbound.html');
 102      $page->set('val','Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In auctor sem vitae ante.');
 103  
 104      $output = $page->capture();
 105      $this->assertEqual($output, 'Lorem ipsum dolor sit amet, consect... Lorem ipsum dolor sit amet, consectetuer...');
 106    }
 107  
 108    function testLongLiteralStringWordBoundary()
 109    {
 110      $template = '<core:set str="Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In auctor sem vitae ante." />'
 111          .'{$str|clip:35,0,"...","No"} {$str|clip:35,0,"...","Yes"}';
 112  
 113      $this->registerTestingTemplate('/template/filter/clip/clipstrwordbound.html', $template);
 114      $page = $this->initTemplate('/template/filter/clip/clipstrwordbound.html');
 115  
 116      $output = $page->capture();
 117      $this->assertEqual($output, 'Lorem ipsum dolor sit amet, consect... Lorem ipsum dolor sit amet, consectetuer...');
 118    }
 119  
 120    function testOneAttributeDoubleQuoteVar()
 121    {
 122      $template = '<img src="img.gif" alt="{$val|clip:5,0,"..."}"/>';
 123  
 124      $this->registerTestingTemplate('/template/filter/clip/testoneattributedoublequote.html', $template);
 125  
 126      try {
 127        $page = $this->initTemplate('/template/filter/clip/testoneattributedoublequote.html');
 128        $this->assertTrue(false);
 129      }
 130      catch (WactException $e)
 131      {
 132        $this->assertWantedPattern('/Invalid tag attribute syntax/', $e->getMessage());
 133      }
 134    }
 135  
 136    function testOneAttributeSingleQuoteVar()
 137    {
 138      $template = '<img src=\'img.gif\' alt=\'{$val|clip:5,0,\'...\'}\'/>';
 139  
 140      $this->registerTestingTemplate('/template/filter/clip/testoneattributesinglequote.html',$template);
 141      try
 142      {
 143        $page = $this->initTemplate('/template/filter/clip/testoneattributesinglequote.html');
 144        $this->assertTrue(false);
 145      }
 146      catch (WactException $e)
 147      {
 148        $this->assertWantedPattern('/Invalid tag attribute syntax/', $e->getMessage());
 149      }
 150    }
 151  
 152    function testOneAttributeMixedQuote1Var()
 153    {
 154      $template = '<img src="img.gif" alt="{$val|clip:5,0,\'...\'}"/>';
 155  
 156      $this->registerTestingTemplate('/template/filter/clip/testoneattributemixedquote1.html',$template);
 157      $page = $this->initTemplate('/template/filter/clip/testoneattributemixedquote1.html');
 158      $page->set('val','abcdefgh');
 159  
 160      $output = $page->capture();
 161      $this->assertEqual($output, '<img src="img.gif" alt="abcde..." />');
 162    }
 163  
 164    function testOneAttributeMixedQuote2Var()
 165    {
 166      $template = '<img src=\'img.gif\' alt=\'{'.'$val|clip:5,0,"..."}\'/>';
 167  
 168      $this->registerTestingTemplate('/template/filter/clip/testoneattributemixedquote2.html',$template);
 169      $page = $this->initTemplate('/template/filter/clip/testoneattributemixedquote2.html');
 170      $page->set('val','abcdefgh');
 171  
 172      $output = $page->capture();
 173      $this->assertEqual($output, '<img src="img.gif" alt=\'abcde...\' />');
 174    }
 175  
 176    function testTwoAttributeDoubleQuoteVar()
 177    {
 178      $template = '<img src="img.gif" alt="{$val|clip:5,0,"..."}" title="{$val|clip:5,0,"..."}"/>';
 179  
 180      $this->registerTestingTemplate('/template/filter/clip/testtwoattributedoublequote.html',$template);
 181      try
 182      {
 183        $page = $this->initTemplate('/template/filter/clip/testtwoattributedoublequote.html');
 184        $this->assertTrue(false);
 185      }
 186      catch(WactException $e)
 187      {
 188        $this->assertWantedPattern('/Invalid tag attribute syntax/', $e->getMessage());
 189      }
 190    }
 191  
 192    function testTwoAttributeMixedQuote1Var()
 193    {
 194      $template = '<img src="img.gif" alt="{$val|clip:5,0,\'...\'}" title="{$val|clip:5,0,\'...\'}"/>';
 195  
 196      $this->registerTestingTemplate('/template/filter/clip/testtwoattributemixedquote1.html',$template);
 197      $page = $this->initTemplate('/template/filter/clip/testtwoattributemixedquote1.html');
 198      $page->set('val','abcdefgh');
 199  
 200      $output = $page->capture();
 201      $this->assertEqual($output, '<img src="img.gif" alt="abcde..." title="abcde..." />');
 202    }
 203  
 204    function testTwoAttributeMixedQuote2Var()
 205    {
 206      $template = '<img src=\'img.gif\' alt=\'{'.'$val|clip:5,0,"..."}\' title=\''.'{$val|clip:5,0,"..."}\'/>';
 207  
 208      $this->registerTestingTemplate('/template/filter/clip/testtwoattributemixedquote2.html',$template);
 209      $page = $this->initTemplate('/template/filter/clip/testtwoattributemixedquote2.html');
 210      $page->set('val','abcdefgh');
 211  
 212      $output = $page->capture();
 213      $this->assertEqual($output, '<img src="img.gif" alt=\'abcde...\' title=\'abcde...\' />');
 214    }
 215  }
 216  ?>


Generated: Mon Dec 1 03:56:46 2008 Cross-referenced by PHPXref 0.7