home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / Sigma_cache_testcase.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  2.9 KB  |  110 lines

  1. <?php
  2.  
  3. /**
  4.  * Unit tests for HTML_Template_Sigma package.
  5.  * 
  6.  * @author Alexey Borzov <avb@php.net>
  7.  * 
  8.  * $Id: Sigma_cache_testcase.php,v 1.2 2003/04/22 19:01:04 avb Exp $
  9.  */
  10.  
  11. require_once 'Sigma_api_testcase.php';
  12.  
  13. class Sigma_cache_TestCase extends Sigma_api_TestCase
  14. {
  15.     function Sigma_cache_TestCase($name)
  16.     {
  17.         $this->Sigma_api_TestCase($name);
  18.     }
  19.  
  20.     function setUp()
  21.     {
  22.         global $Sigma_cache_dir;
  23.  
  24.         $className = 'HTML_Template_' . $GLOBALS['IT_class'];
  25.         $this->tpl =& new $className('./templates', $Sigma_cache_dir);
  26.     }
  27.  
  28.     function _removeCachedFiles($filename)
  29.     {
  30.         if (!is_array($filename)) {
  31.             $filename = array($filename);
  32.         }
  33.         foreach ($filename as $file) {
  34.             $cachedName = $this->tpl->_cachedName($file);
  35.             if (@file_exists($cachedName)) {
  36.                 @unlink($cachedName);
  37.             }
  38.         }
  39.     }
  40.  
  41.     function assertCacheExists($filename)
  42.     {
  43.         if (!is_array($filename)) {
  44.             $filename = array($filename);
  45.         }
  46.         foreach ($filename as $file) {
  47.             $cachedName = $this->tpl->_cachedName($file);
  48.             if (!@file_exists($cachedName)) {
  49.                 $this->assertTrue(false, "File '$file' is not cached");
  50.             }
  51.         }
  52.     }
  53.  
  54.     function testLoadTemplatefile()
  55.     {
  56.         if (!$this->_methodExists('_isCached')) {
  57.             return;
  58.         }
  59.         $this->_removeCachedFiles('loadtemplatefile.html');
  60.         parent::testLoadTemplateFile();
  61.         $this->assertCacheExists('loadtemplatefile.html');
  62.         parent::testLoadTemplateFile();
  63.     }
  64.  
  65.     function testAddBlockfile()
  66.     {
  67.         if (!$this->_methodExists('_isCached')) {
  68.             return;
  69.         }
  70.         $this->_removeCachedFiles(array('blocks.html', 'addblock.html'));
  71.         parent::testAddBlockfile();
  72.         $this->assertCacheExists(array('blocks.html', 'addblock.html'));
  73.         parent::testAddBlockfile();
  74.     }
  75.  
  76.     function testReplaceBlockFile()
  77.     {
  78.         if (!$this->_methodExists('_isCached')) {
  79.             return;
  80.         }
  81.         $this->_removeCachedFiles(array('blocks.html', 'replaceblock.html'));
  82.         parent::testReplaceBlockfile();
  83.         $this->assertCacheExists(array('blocks.html', 'replaceblock.html'));
  84.         parent::testReplaceBlockfile();
  85.     }
  86.  
  87.     function testInclude()
  88.     {
  89.         if (!$this->_methodExists('_isCached')) {
  90.             return;
  91.         }
  92.         $this->_removeCachedFiles(array('include.html', '__include.html'));
  93.         parent::testInclude();
  94.         $this->assertCacheExists(array('include.html', '__include.html'));
  95.         parent::testInclude();
  96.     }
  97.  
  98.     function testCallback()
  99.     {
  100.         if (!$this->_methodExists('_isCached')) {
  101.             return;
  102.         }
  103.         $this->_removeCachedFiles('callback.html');
  104.         parent::testCallback();
  105.         $this->assertCacheExists('callback.html');
  106.         parent::testCallback();
  107.     }
  108. }
  109. ?>
  110.