[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/filter_chain/tests/cases/ -> lmbFilterChainTest.class.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  lmb_require('limb/filter_chain/src/lmbInterceptingFilter.interface.php');
  10  lmb_require('limb/filter_chain/src/lmbFilterChain.class.php');
  11  
  12  class InterceptingFilterStub
  13  {
  14    var $captured = array();
  15    var $run = false;
  16  
  17    function run($fc)
  18    {
  19      $this->run = true;
  20      $this->captured['filter_chain'] = $fc;
  21  
  22      $fc->next();
  23    }
  24  }
  25  
  26  class OutputFilter1
  27  {
  28    function run($fc)
  29    {
  30      echo '<filter1>';
  31      $fc->next();
  32      echo '</filter1>';
  33    }
  34  }
  35  
  36  class OutputFilter2
  37  {
  38    function run($fc)
  39    {
  40      echo '<filter2>';
  41      $fc->next();
  42      echo '</filter2>';
  43    }
  44  }
  45  
  46  class OutputFilter3
  47  {
  48    function run($fc)
  49    {
  50      echo '<filter3>';
  51      $fc->next();
  52      echo '</filter3>';
  53    }
  54  }
  55  
  56  class lmbFilterChainTest extends UnitTestCase
  57  {
  58    var $fc;
  59    function setUp()
  60    {
  61      $this->fc = new lmbFilterChain();
  62    }
  63  
  64    function testProcess()
  65    {
  66      $mock_filter = new InterceptingFilterStub();
  67  
  68      $this->fc->registerFilter($mock_filter);
  69  
  70      $this->assertFalse($mock_filter->run);
  71  
  72      $this->fc->process();
  73  
  74      $this->assertTrue($mock_filter->run);
  75  
  76      $this->assertIsA($mock_filter->captured['filter_chain'], 'lmbFilterChain');
  77    }
  78  
  79    function testProcessProperNesting()
  80    {
  81      $f1 = new OutputFilter1();
  82      $f2 = new OutputFilter2();
  83  
  84      $this->fc->registerFilter($f1);
  85      $this->fc->registerFilter($f2);
  86  
  87      ob_start();
  88  
  89      $this->fc->process();
  90  
  91      $str = ob_get_contents();
  92      ob_end_clean();
  93  
  94      $this->assertEqual($str, '<filter1><filter2></filter2></filter1>');
  95    }
  96  
  97    function testFilterChainAsAFilter()
  98    {
  99      $f1 = new OutputFilter1();
 100      $f2 = new OutputFilter2();
 101  
 102      $fc = new lmbFilterChain();
 103  
 104      $fc1 = new lmbFilterChain();
 105      $fc1->registerFilter($f1);
 106  
 107      $fc2 = new lmbFilterChain();
 108      $fc2->registerFilter($f2);
 109  
 110      $fc->registerFilter($fc1);
 111      $fc->registerFilter($fc2);
 112  
 113      ob_start();
 114  
 115      $fc->process();
 116  
 117      $str = ob_get_contents();
 118      ob_end_clean();
 119  
 120      $this->assertEqual($str, '<filter1></filter1><filter2></filter2>');
 121    }
 122  }
 123  
 124  ?>


Generated: Sat Nov 22 03:48:54 2008 Cross-referenced by PHPXref 0.7