Allow modifications to the target location within the template.
authorGunnar Wrobel <p@rdus.de>
Fri, 14 Jan 2011 14:18:48 +0000 (15:18 +0100)
committerGunnar Wrobel <p@rdus.de>
Fri, 14 Jan 2011 14:18:48 +0000 (15:18 +0100)
components/lib/Components/Helper/Template/Php.php
components/test/Components/Unit/Components/Helper/TemplatesTest.php
components/test/Components/fixture/templates/rewrite/one [new file with mode: 0644]

index abc8fdc..611239f 100644 (file)
@@ -40,8 +40,10 @@ extends Components_Helper_Template
         foreach ($parameters as $key => $value) {
             ${$key} = $value;
         }
+        $tdir = dirname($this->_target);
+        $target = basename($this->_target);
         ob_start();
         include $this->_source;
-        file_put_contents($this->_target, ob_get_clean());
+        file_put_contents($tdir . DIRECTORY_SEPARATOR . $target, ob_get_clean());
     }
 }
\ No newline at end of file
index d6282a7..769ef8b 100644 (file)
@@ -104,35 +104,6 @@ extends Components_TestCase
         $templates->write(array('1' => new stdClass, '2' => 'Two'));
     }
 
-    public function testPrefix()
-    {
-        $tdir =  $this->getTemporaryDirectory();
-        $templates = new Components_Helper_Templates_Prefix(
-            dirname(__FILE__) . '/../../../fixture/templates',
-            $tdir,
-            'var',
-            'target'
-        );
-        $templates->write(array('1' => 'One', '2' => 'Two'));
-        $this->assertEquals(
-            "One : Two\n",
-            file_get_contents($tdir . DIRECTORY_SEPARATOR . 'target')
-        );
-    }
-
-    /**
-     * @expectedException Components_Exception
-     */
-    public function testMissingPrefixTemplate()
-    {
-        $templates = new Components_Helper_Templates_Prefix(
-            dirname(__FILE__) . '/../../../fixture/templates',
-            $this->getTemporaryDirectory(),
-            'NOSUCHPREFIX',
-            'target'
-        );
-    }
-
     public function testPhp()
     {
         $tdir =  $this->getTemporaryDirectory();
@@ -212,4 +183,19 @@ extends Components_TestCase
             file_get_contents($tdir . DIRECTORY_SEPARATOR . 'two')
         );
     }
+
+    public function testTargetRewrite()
+    {
+        $tdir =  $this->getTemporaryDirectory();
+        $templates = new Components_Helper_Templates_Directory(
+            dirname(__FILE__) . '/../../../fixture/templates/rewrite',
+            $tdir
+        );
+        $templates->write(array('one' => 'One'));
+        $this->assertEquals(
+            "One",
+            file_get_contents($tdir . DIRECTORY_SEPARATOR . 'rewritten')
+        );
+    }
+
 }
\ No newline at end of file
diff --git a/components/test/Components/fixture/templates/rewrite/one b/components/test/Components/fixture/templates/rewrite/one
new file mode 100644 (file)
index 0000000..2215c83
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+
+echo $one;
+
+$target = 'rewritten';