Changeset 9076
- Timestamp:
- 12/20/05 16:07:14 (3 years ago)
- Files:
-
- trunk/src/sandbox/mrfc0022/midgard_style_engine.php (modified) (1 diff)
- trunk/src/sandbox/mrfc0022/midgard_style_engine_test.php (modified) (1 diff)
- trunk/src/sandbox/mrfc0022/runtests.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/sandbox/mrfc0022/midgard_style_engine.php
r9075 r9076 126 126 } 127 127 128 class traditional_midgard_style_engine extends standard_midgard_style_engine { 129 130 function traditional_midgard_style_engine(&$context) { 131 $this->standard_midgard_style_engine($context); 132 } 133 134 function compile($element) { 135 $prefix = ""; 136 $variables = array(); 137 $tokens = token_get_all($element); 138 foreach ($tokens as $token) { 139 if (is_array($token) && $token[0] == T_VARIABLE 140 && substr($token[1], 0, 2) != '$_') { 141 $variables[$token[1]] = 1; 142 } 143 } 144 foreach ($variables as $variable => $foo) { 145 $prefix .="global $variable;"; 146 } 147 return $prefix . parent::compile($element); 148 } 149 150 } 151 128 152 ?> trunk/src/sandbox/mrfc0022/midgard_style_engine_test.php
r9075 r9076 90 90 } 91 91 92 class traditional_midgard_style_engine_test extends PHPUnit_TestCase { 93 94 var $engine; 95 96 function traditional_midgard_style_engine_context_test($name) { 97 $this->PHPUnit_TestCase($name); 98 } 99 100 function setUp() { 101 $elements = array( 102 "test" => "<(init)><(print)><(increment)><(print)>", 103 "init" => "<?php \$x = 0; ?>", 104 "print" => "<?php echo \$x; ?>", 105 "increment" => "<?php \$x += 1; ?>" 106 ); 107 $context =& new simple_midgard_style_context($elements); 108 $this->engine =& new traditional_midgard_style_engine($context); 109 } 110 111 function tearDown() { 112 unset($this->engine); 113 } 114 115 function try_render($element) { 116 ob_start(); 117 $this->engine->render($element); 118 return ob_get_clean(); 119 } 120 121 function test_render() { 122 $this->assertEquals("01", $this->try_render("<(test)>")); 123 } 124 125 } 126 92 127 ?> trunk/src/sandbox/mrfc0022/runtests.php
r9071 r9076 29 29 $suite->addTestSuite("chained_midgard_style_context_test"); 30 30 $suite->addTestSuite("standard_midgard_style_engine_test"); 31 $suite->addTestSuite("traditional_midgard_style_engine_test"); 31 32 $result = PHPUnit::run($suite); 32 33
