[limb-svn] r6764 - in 3.x/trunk/limb/macro: src/compiler src/tags/form tests/cases/tags/form
svn at limb-project.com
svn at limb-project.com
Thu Jan 31 12:56:25 MSK 2008
Author: serega
Date: 2008-01-31 12:56:25 +0300 (Thu, 31 Jan 2008)
New Revision: 6764
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6764
Added:
3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormElementTagTest.class.php
3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormWidgetTest.class.php
Removed:
3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormWidgetTagTest.class.php
Modified:
3.x/trunk/limb/macro/src/compiler/lmbMacroRuntimeWidgetTag.class.php
3.x/trunk/limb/macro/src/tags/form/lmbMacroFormElementTag.class.php
Log:
-- lmbMacroRuntimeWidgetTag :: $runtime_var attribute added to cache runtime_var value
-- lmbMacroFormElementTag :: getRuntimeVar() added that provide uniqueness of runtime_var of form elements
Modified: 3.x/trunk/limb/macro/src/compiler/lmbMacroRuntimeWidgetTag.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/compiler/lmbMacroRuntimeWidgetTag.class.php 2008-01-31 08:31:15 UTC (rev 6763)
+++ 3.x/trunk/limb/macro/src/compiler/lmbMacroRuntimeWidgetTag.class.php 2008-01-31 09:56:25 UTC (rev 6764)
@@ -15,6 +15,7 @@
{
protected $widget_include_file;
protected $widget_class_name;
+ protected $runtime_var;
function preParse($compiler)
{
@@ -29,7 +30,10 @@
function getRuntimeVar()
{
- return '$this->' . $this->tag . '_' . $this->getRuntimeId();
+ if($this->runtime_var)
+ return $this->runtime_var;
+ $this->runtime_var = '$this->' . $this->tag . '_' . $this->getRuntimeId();
+ return $this->runtime_var;
}
function getRuntimeId()
Modified: 3.x/trunk/limb/macro/src/tags/form/lmbMacroFormElementTag.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/form/lmbMacroFormElementTag.class.php 2008-01-31 08:31:15 UTC (rev 6763)
+++ 3.x/trunk/limb/macro/src/tags/form/lmbMacroFormElementTag.class.php 2008-01-31 09:56:25 UTC (rev 6764)
@@ -23,5 +23,14 @@
$code_writer->writeToInit("{$form_tag->getRuntimeVar()}->addChild({$this->getRuntimeVar()});\n");
}
}
+
+ function getRuntimeVar()
+ {
+ if($this->runtime_var)
+ return $this->runtime_var;
+
+ $this->runtime_var = '$this->' . $this->tag . '_' . self :: generateNewRuntimeId();
+ return $this->runtime_var;
+ }
}
Added: 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormElementTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormElementTagTest.class.php (rev 0)
+++ 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormElementTagTest.class.php 2008-01-31 09:56:25 UTC (rev 6764)
@@ -0,0 +1,26 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+class lmbMacroFormElementTagTest extends lmbBaseMacroTest
+{
+ function testCheckWhatWidgetVarsAreEniqueForWidgetsWithSameIds()
+ {
+ $template = '{{form name="my_form1" from="$#form1_data"}}{{input type="text" name="my_input"}}{{/form}}'.
+ '{{form name="my_form2" from="$#form2_data"}}{{input type="text" name="my_input"}}{{/form}}';
+
+ $page = $this->_createMacroTemplate($template, 'tpl.html');
+ $page->set('form1_data', array('my_input' => 100));
+ $page->set('form2_data', array('my_input' => 200));
+
+ $out = $page->render();
+ $expected = '<form name="my_form1"><input type="text" name="my_input" value="100" /></form>'.
+ '<form name="my_form2"><input type="text" name="my_input" value="200" /></form>';
+ $this->assertEqual($out, $expected);
+ }
+}
Deleted: 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormWidgetTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormWidgetTagTest.class.php 2008-01-31 08:31:15 UTC (rev 6763)
+++ 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormWidgetTagTest.class.php 2008-01-31 09:56:25 UTC (rev 6764)
@@ -1,123 +0,0 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-
-class lmbMacroFormWidgetTest extends lmbBaseMacroTest
-{
- function testAddAndGetChild()
- {
- $form = new lmbMacroFormWidget('my_id');
- $field1 = new lmbMacroFormElementWidget('Input1');
- $field2 = new lmbMacroFormElementWidget('Input3');
- $form->addChild($field1);
- $form->addChild($field2);
-
- $this->assertReference($form->getChild('Input3'), $field2);
- $this->assertNull($form->getChild('NoSuchInput'));
- }
-
- function testGetLabelFor()
- {
- $form = new lmbMacroFormWidget('my_id');
- $field1 = new lmbMacroFormElementWidget('Input1');
- $label1 = new lmbMacroFormLabelWidget('Label1');
- $label1->setAttribute('for', 'Input1');
-
- $field2 = new lmbMacroFormElementWidget('Input3');
- $label2 = new lmbMacroFormLabelWidget('Label3');
- $label2->setAttribute('for', 'Input3');
-
- $form->addChild($field1);
- $form->addChild($field2);
- $form->addChild($label1);
- $form->addChild($label2);
-
- $this->assertReference($form->getLabelFor('Input3'), $label2);
- $this->assertReference($form->getLabelFor('Input1'), $label1);
- $this->assertNull($form->getLabelFor('NoSuchInput'));
- }
-
- function testSetErrorsNotifyFieldsAboutErrors()
- {
- $error_list = new lmbMacroFormErrorList();
- $error_fields = array('x'=>'Input1', 'z'=>'Input3');
- $error_list->addError('message', $error_fields);
-
- $form = new lmbMacroFormWidget('my_id');
- $field1 = new lmbMacroFormElementWidget('Input1');
- $field2 = new lmbMacroFormElementWidget('Input3');
- $form->addChild($field1);
- $form->addChild($field2);
-
- $form->setErrorList($error_list);
-
- $this->assertTrue($field1->hasErrors());
- $this->assertTrue($field2->hasErrors());
- }
-
- function testSetErrorsConvertErrorsToErrorList()
- {
- $error_fields = array('x'=>'Input1', 'z'=>'Input3');
- $errors = array(array('message' => 'My message', 'fields' => $error_fields, 'values' => array(10, 20)));
-
- $form = new lmbMacroFormWidget('my_id');
- $form->setErrorList($errors);
-
- $error_list = $form->getErrorList();
- $this->assertIsA($error_list, 'lmbMacroFormErrorList');
- $this->assertEqual(count($error_list), 1);
- }
-
- function testSetErrorsNotifyFieldsAndLabelsAboutErrors()
- {
- $error_list = new lmbMacroFormErrorList();
- $error_list->addError('message', array('x'=>'Input1'));
-
- $form = new lmbMacroFormWidget('my_id');
- $field1 = new lmbMacroFormElementWidget('Input1');
- $label1 = new lmbMacroFormLabelWidget('Label1');
- $label1->setAttribute('for', 'Input1');
-
- $field2 = new lmbMacroFormElementWidget('Input3');
- $label2 = new lmbMacroFormLabelWidget('Label3');
- $label2->setAttribute('for', 'Input3');
-
- $form->addChild($field1);
- $form->addChild($field2);
- $form->addChild($label1);
- $form->addChild($label2);
-
- $form->setErrorList($error_list);
-
- $this->assertTrue($field1->hasErrors());
- $this->assertFalse($field2->hasErrors());
- $this->assertTrue($label1->hasErrors());
- $this->assertFalse($label2->hasErrors());
- }
-
- function testGetFieldErrorsForField()
- {
- $error_list = new lmbMacroFormErrorList();
- $error_list->addError('message1', array('x'=>'Input1'));
- $error_list->addError('message2', array('x'=>'Input1', 'z'=>'Input2'));
-
- $form = new lmbMacroFormWidget('my_id');
- $form->setErrorList($error_list);
-
- $errors = $form->getErrorsListForFields();
- $this->assertEqual(sizeof($errors), 3);
-
- $errors = $form->getErrorsListForFields('Input1');
-
- $this->assertEqual($errors[0]['message'], 'message1');
- $this->assertEqual($errors[1]['message'], 'message2');
-
- $errors = $form->getErrorsListForFields('Input2');
- $this->assertEqual($errors[0]['message'], 'message2');
- }
-}
Copied: 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormWidgetTest.class.php (from rev 6761, 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormWidgetTagTest.class.php)
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormWidgetTest.class.php (rev 0)
+++ 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormWidgetTest.class.php 2008-01-31 09:56:25 UTC (rev 6764)
@@ -0,0 +1,123 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+class lmbMacroFormWidgetTest extends lmbBaseMacroTest
+{
+ function testAddAndGetChild()
+ {
+ $form = new lmbMacroFormWidget('my_id');
+ $field1 = new lmbMacroFormElementWidget('Input1');
+ $field2 = new lmbMacroFormElementWidget('Input3');
+ $form->addChild($field1);
+ $form->addChild($field2);
+
+ $this->assertReference($form->getChild('Input3'), $field2);
+ $this->assertNull($form->getChild('NoSuchInput'));
+ }
+
+ function testGetLabelFor()
+ {
+ $form = new lmbMacroFormWidget('my_id');
+ $field1 = new lmbMacroFormElementWidget('Input1');
+ $label1 = new lmbMacroFormLabelWidget('Label1');
+ $label1->setAttribute('for', 'Input1');
+
+ $field2 = new lmbMacroFormElementWidget('Input3');
+ $label2 = new lmbMacroFormLabelWidget('Label3');
+ $label2->setAttribute('for', 'Input3');
+
+ $form->addChild($field1);
+ $form->addChild($field2);
+ $form->addChild($label1);
+ $form->addChild($label2);
+
+ $this->assertReference($form->getLabelFor('Input3'), $label2);
+ $this->assertReference($form->getLabelFor('Input1'), $label1);
+ $this->assertNull($form->getLabelFor('NoSuchInput'));
+ }
+
+ function testSetErrorsNotifyFieldsAboutErrors()
+ {
+ $error_list = new lmbMacroFormErrorList();
+ $error_fields = array('x'=>'Input1', 'z'=>'Input3');
+ $error_list->addError('message', $error_fields);
+
+ $form = new lmbMacroFormWidget('my_id');
+ $field1 = new lmbMacroFormElementWidget('Input1');
+ $field2 = new lmbMacroFormElementWidget('Input3');
+ $form->addChild($field1);
+ $form->addChild($field2);
+
+ $form->setErrorList($error_list);
+
+ $this->assertTrue($field1->hasErrors());
+ $this->assertTrue($field2->hasErrors());
+ }
+
+ function testSetErrorsConvertErrorsToErrorList()
+ {
+ $error_fields = array('x'=>'Input1', 'z'=>'Input3');
+ $errors = array(array('message' => 'My message', 'fields' => $error_fields, 'values' => array(10, 20)));
+
+ $form = new lmbMacroFormWidget('my_id');
+ $form->setErrorList($errors);
+
+ $error_list = $form->getErrorList();
+ $this->assertIsA($error_list, 'lmbMacroFormErrorList');
+ $this->assertEqual(count($error_list), 1);
+ }
+
+ function testSetErrorsNotifyFieldsAndLabelsAboutErrors()
+ {
+ $error_list = new lmbMacroFormErrorList();
+ $error_list->addError('message', array('x'=>'Input1'));
+
+ $form = new lmbMacroFormWidget('my_id');
+ $field1 = new lmbMacroFormElementWidget('Input1');
+ $label1 = new lmbMacroFormLabelWidget('Label1');
+ $label1->setAttribute('for', 'Input1');
+
+ $field2 = new lmbMacroFormElementWidget('Input3');
+ $label2 = new lmbMacroFormLabelWidget('Label3');
+ $label2->setAttribute('for', 'Input3');
+
+ $form->addChild($field1);
+ $form->addChild($field2);
+ $form->addChild($label1);
+ $form->addChild($label2);
+
+ $form->setErrorList($error_list);
+
+ $this->assertTrue($field1->hasErrors());
+ $this->assertFalse($field2->hasErrors());
+ $this->assertTrue($label1->hasErrors());
+ $this->assertFalse($label2->hasErrors());
+ }
+
+ function testGetFieldErrorsForField()
+ {
+ $error_list = new lmbMacroFormErrorList();
+ $error_list->addError('message1', array('x'=>'Input1'));
+ $error_list->addError('message2', array('x'=>'Input1', 'z'=>'Input2'));
+
+ $form = new lmbMacroFormWidget('my_id');
+ $form->setErrorList($error_list);
+
+ $errors = $form->getErrorsListForFields();
+ $this->assertEqual(sizeof($errors), 3);
+
+ $errors = $form->getErrorsListForFields('Input1');
+
+ $this->assertEqual($errors[0]['message'], 'message1');
+ $this->assertEqual($errors[1]['message'], 'message2');
+
+ $errors = $form->getErrorsListForFields('Input2');
+ $this->assertEqual($errors[0]['message'], 'message2');
+ }
+}
More information about the limb-svn
mailing list