Blame view

mobile/source/ext/phptal/tests/OverloadingTest.php 1.34 KB
a1684257   Administrator   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  <?php
  /**
   * PHPTAL templating engine
   *
   * PHP Version 5
   *
   * @category HTML
   * @package  PHPTAL
   * @author   Laurent Bedubourg <lbedubourg@motion-twin.com>
   * @author   Kornel LesiƄski <kornel@aardvarkmedia.co.uk>
   * @license  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
   * @version  SVN: $Id: OverloadingTest.php 605 2009-05-03 02:50:26Z kornel $
   * @link     http://phptal.org/
   */
  
  class OverloadTestClass
  {
      public $vars = array('foo'=>'bar', 'baz'=>'biz');
  
      public function __set( $name, $value )
      {
          $this->vars[$name] = $value;
      }
  
      public function __get( $name )
      {
          if (array_key_exists($name, $this->vars)) {
              return $this->vars[$name];
          }
          return null;
      }
  
      public function __isset( $key )
      {
          return isset($this->$key) || array_key_exists($key, $this->vars);
      }
  
      public function __call( $func, $args )
      {
          return "$func()=".join(',', $args);
      }
  }
  
  
  require_once dirname(__FILE__)."/config.php";
  
  class OverloadingTest extends PHPTAL_TestCase
  {
      function test()
      {
          $tpl = $this->newPHPTAL('input/overloading-01.html');
          $tpl->object = new OverloadTestClass();
          $res = trim_string($tpl->execute());
          $exp = trim_file('output/overloading-01.html');
          $this->assertEquals($exp, $res);
      }
  }