[limb-svn] r6986 - in 3.x/trunk/limb/macro: src/tags/form tests/cases/tags/form

svn at limb-project.com svn at limb-project.com
Wed May 7 21:49:06 MSD 2008


Author: pachanga
Date: 2008-05-07 21:49:06 +0400 (Wed, 07 May 2008)
New Revision: 6986
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6986

Added:
   3.x/trunk/limb/macro/src/tags/form/form_referer.tag.php
   3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormRefererTagTest.class.php
Log:
-- adding initial version of {{form:referer}}

Added: 3.x/trunk/limb/macro/src/tags/form/form_referer.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/form/form_referer.tag.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/src/tags/form/form_referer.tag.php	2008-05-07 17:49:06 UTC (rev 6986)
@@ -0,0 +1,28 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+/**
+ * @tag form:referer
+ * @forbid_end_tag
+ * @package macro
+ * @version $Id$
+ */
+class lmbMacroFormRefererTag extends lmbMacroTag
+{
+  function _generateContent($code)
+  {
+    $ref = $code->generateVar();
+
+    $code->writePHP($ref . ' = isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "";' . "\n");
+
+    $code->writePHP("if($ref)");
+    $code->writePHP('echo "<input type=\'hidden\' name=\'referer\' value=\'' . $ref . '\'>";');
+  }
+}
+

Added: 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormRefererTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormRefererTagTest.class.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormRefererTagTest.class.php	2008-05-07 17:49:06 UTC (rev 6986)
@@ -0,0 +1,47 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+class lmbMacroFormRefererTagTest extends lmbBaseMacroTest
+{
+  protected $prev_ref;
+
+  function setUp()
+  {
+    $this->prev_ref = isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "";
+  }
+
+  function tearDown()
+  {
+    $_SERVER["HTTP_REFERER"] = $this->prev_ref;
+  }
+
+  function testNoReferer()
+  {
+    $_SERVER["HTTP_REFERER"] = "";
+
+    $template = '{{form name="my_form"}}{{form:referer}}{{/form}}';
+
+    $page = $this->_createMacroTemplate($template, 'tpl.html');
+ 
+    $out = $page->render();
+    $this->assertEqual($out, '<form name="my_form"></form>');
+  }   
+
+  function testReferer()
+  {
+    $_SERVER["HTTP_REFERER"] = "back.html";
+
+    $template = '{{form name="my_form"}}{{form:referer}}{{/form}}';
+
+    $page = $this->_createMacroTemplate($template, 'tpl.html');
+ 
+    $out = $page->render();
+    $this->assertEqual($out, "<form name=\"my_form\"><input type='hidden' name='referer' value='back.html'></form>");
+  }
+}



More information about the limb-svn mailing list