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

svn at limb-project.com svn at limb-project.com
Wed Dec 5 17:12:29 MSK 2007


Author: serega
Date: 2007-12-05 17:12:29 +0300 (Wed, 05 Dec 2007)
New Revision: 6585
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6585

Added:
   3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormFieldWidgetTest.class.php
Modified:
   3.x/trunk/limb/macro/src/compiler/lmbMacroTag.class.php
   3.x/trunk/limb/macro/src/tags/form/lmbMacroCheckableInputWidget.class.php
   3.x/trunk/limb/macro/src/tags/form/lmbMacroFormElementTag.class.php
   3.x/trunk/limb/macro/src/tags/form/lmbMacroFormFieldWidget.class.php
   3.x/trunk/limb/macro/src/tags/form/lmbMacroSelectWidget.class.php
   3.x/trunk/limb/macro/src/tags/form/lmbMacroTextAreaWidget.class.php
   3.x/trunk/limb/macro/tests/cases/compiler/lmbMacroTagTest.class.php
   3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormWidgetTagTest.class.php
Log:
-- lmbMacroTag :: getRuntimeId() now uses non dynamic "id" attribute value only. For dynamic "id" unique runtime_id will be generated
-- lmbMacroFormElementTag now set "style" and "class" attributes with values from "error_style" and "error_class" attribute if element is in error state.
-- "error_style" and "error_class" added to non rendering attributes list

Modified: 3.x/trunk/limb/macro/src/compiler/lmbMacroTag.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/compiler/lmbMacroTag.class.php	2007-12-05 13:56:11 UTC (rev 6584)
+++ 3.x/trunk/limb/macro/src/compiler/lmbMacroTag.class.php	2007-12-05 14:12:29 UTC (rev 6585)
@@ -48,8 +48,8 @@
     if($this->node_id)
       return $this->node_id;
 
-    if($id = $this->get('id'))
-      $this->node_id = $id;
+    if($this->hasConstant('id'))
+      $this->node_id = $this->get('id');
     else
       $this->node_id = self :: generateNewId();
 

Modified: 3.x/trunk/limb/macro/src/tags/form/lmbMacroCheckableInputWidget.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/form/lmbMacroCheckableInputWidget.class.php	2007-12-05 13:56:11 UTC (rev 6584)
+++ 3.x/trunk/limb/macro/src/tags/form/lmbMacroCheckableInputWidget.class.php	2007-12-05 14:12:29 UTC (rev 6585)
@@ -16,7 +16,7 @@
  */
 class lmbMacroCheckableInputWidget extends lmbMacroFormFieldWidget
 {
-  protected $skip_render = array('checked_value');
+  protected $skip_render = array('checked_value', 'error_class', 'error_style');
   
   function getName()
   {

Modified: 3.x/trunk/limb/macro/src/tags/form/lmbMacroFormElementTag.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/form/lmbMacroFormElementTag.class.php	2007-12-05 13:56:11 UTC (rev 6584)
+++ 3.x/trunk/limb/macro/src/tags/form/lmbMacroFormElementTag.class.php	2007-12-05 14:12:29 UTC (rev 6585)
@@ -18,7 +18,10 @@
   {
     parent :: _generateWidget($code_writer);
     if($form_tag = $this->findParentByClass('lmbMacroFormTag'))
+    {
       $code_writer->writePHP("{$this->getRuntimeVar()}->setForm({$form_tag->getRuntimeVar()});\n");
+      //$code_writer->writePHP("{$form_tag->getRuntimeVar()}->addChild({$this->getRuntimeVar()});\n");
+    }
   }  
 }
 

Modified: 3.x/trunk/limb/macro/src/tags/form/lmbMacroFormFieldWidget.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/form/lmbMacroFormFieldWidget.class.php	2007-12-05 13:56:11 UTC (rev 6584)
+++ 3.x/trunk/limb/macro/src/tags/form/lmbMacroFormFieldWidget.class.php	2007-12-05 14:12:29 UTC (rev 6585)
@@ -20,9 +20,15 @@
 {
   protected $has_errors = false;
   protected $form;
+  protected $skip_render = array('error_class', 'error_style');
   
   function getDisplayName()
   {
+    if($this->hasAttribute('title'))
+      return $this->getAttribute('title');
+    if($this->hasAttribute('alt'))
+      return $this->getAttribute('alt');
+    
     return $this->runtime_id;
   }
   
@@ -34,6 +40,14 @@
   function setErrorState($has_errors = true)
   {
     $this->has_errors = $has_errors;
+    
+    if($has_errors)
+    {
+      if($this->hasAttribute('error_class')) 
+        $this->setAttribute('class', $this->getAttribute('error_class'));
+      if($this->hasAttribute('error_style')) 
+       $this->setAttribute('style', $this->getAttribute('error_style'));
+    }
   }
   
   function hasErrors()

Modified: 3.x/trunk/limb/macro/src/tags/form/lmbMacroSelectWidget.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/form/lmbMacroSelectWidget.class.php	2007-12-05 13:56:11 UTC (rev 6584)
+++ 3.x/trunk/limb/macro/src/tags/form/lmbMacroSelectWidget.class.php	2007-12-05 14:12:29 UTC (rev 6585)
@@ -17,7 +17,7 @@
 {
   protected $options = array();
 
-  protected $skip_render = array('value', 'options', 'value_field');
+  protected $skip_render = array('value', 'options', 'value_field', 'error_class', 'error_style');
 
   function setOptions($options)
   {

Modified: 3.x/trunk/limb/macro/src/tags/form/lmbMacroTextAreaWidget.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/form/lmbMacroTextAreaWidget.class.php	2007-12-05 13:56:11 UTC (rev 6584)
+++ 3.x/trunk/limb/macro/src/tags/form/lmbMacroTextAreaWidget.class.php	2007-12-05 14:12:29 UTC (rev 6585)
@@ -16,6 +16,6 @@
  */
 class lmbMacroTextAreaWidget extends lmbMacroFormFieldWidget
 {
-  protected $skip_render = array('value');
+  protected $skip_render = array('value', 'error_class', 'error_style');
 }
 

Modified: 3.x/trunk/limb/macro/tests/cases/compiler/lmbMacroTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/compiler/lmbMacroTagTest.class.php	2007-12-05 13:56:11 UTC (rev 6584)
+++ 3.x/trunk/limb/macro/tests/cases/compiler/lmbMacroTagTest.class.php	2007-12-05 14:12:29 UTC (rev 6585)
@@ -132,6 +132,12 @@
     $this->assertEqual($this->node->getNodeId(), 'my_tag');
   }
 
+  function testGetNodeId_DontUseDynamicIdAttribute()
+  {
+    $this->node->set('id', '$my_tag');
+    $this->assertNotEqual($this->node->getNodeId(), '$my_tag');
+  }
+  
   function testGenerate()
   {
     $code_writer = new MockMacroCodeWriter();

Added: 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormFieldWidgetTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormFieldWidgetTest.class.php	                        (rev 0)
+++ 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormFieldWidgetTest.class.php	2007-12-05 14:12:29 UTC (rev 6585)
@@ -0,0 +1,62 @@
+<?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 lmbMacroFormFieldWidgetTest extends lmbBaseMacroTest
+{
+  function testGetValue_FromValueAttribute()
+  {
+    $form = new lmbMacroFormWidget('my_id');
+    $widget = new lmbMacroFormFieldWidget('any_field');
+    $widget->setAttribute('value', 10);
+    $widget->setForm($form);
+    
+    $this->assertEqual($widget->getValue(), 10);
+  }
+
+  function testGetValue_FromFormDatasource()
+  {
+    $form = new lmbMacroFormWidget('my_id');
+    $form->setDatasource(array('any_field' => 10));
+    $widget = new lmbMacroFormFieldWidget('any_field');
+    $widget->setForm($form);
+    
+    $this->assertEqual($widget->getValue(), 10);
+  }
+
+  function testGetDisplayName_ReturnIdByDefault()
+  {
+    $widget = new lmbMacroFormFieldWidget('any_field');
+    $this->assertEqual($widget->getDisplayname(), 'any_field');
+  }
+
+  function testGetDisplayName_ReturnTitleAttribute()
+  {
+    $widget = new lmbMacroFormFieldWidget('any_field');
+    $widget->setAttribute('title', 'My Field');
+    $this->assertEqual($widget->getDisplayname(), 'My Field');
+  }
+
+  function testGetDisplayName_ReturnAltAttribute()
+  {
+    $widget = new lmbMacroFormFieldWidget('any_field');
+    $widget->setAttribute('alt', 'My Super Field');
+    $this->assertEqual($widget->getDisplayname(), 'My Super Field');
+  }
+  
+  function testSetErrorState_SetErrorStateClassAndStyle()
+  {
+    $widget = new lmbMacroFormFieldWidget('any_field');
+    $widget->setAttribute('error_style', 'my_error_style');
+    $widget->setAttribute('error_class', 'my_error_class');
+    $widget->setErrorState(true);
+    
+    $this->assertEqual($widget->getAttribute('class'), 'my_error_class');
+    $this->assertEqual($widget->getAttribute('style'), 'my_error_style');
+  }
+}

Modified: 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormWidgetTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormWidgetTagTest.class.php	2007-12-05 13:56:11 UTC (rev 6584)
+++ 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroFormWidgetTagTest.class.php	2007-12-05 14:12:29 UTC (rev 6585)
@@ -17,7 +17,7 @@
     $form->addChild($field1);
     $form->addChild($field2);
     
-    $this->assertEqual($form->getChild('Input3'), $field2);
+    $this->assertReference($form->getChild('Input3'), $field2);
     $this->assertNull($form->getChild('NoSuchInput'));
   }
   
@@ -37,8 +37,8 @@
     $form->addChild($label1);
     $form->addChild($label2);
     
-    $this->assertEqual($form->getLabelFor('Input3'), $label2);
-    $this->assertEqual($form->getLabelFor('Input1'), $label1);
+    $this->assertReference($form->getLabelFor('Input3'), $label2);
+    $this->assertReference($form->getLabelFor('Input1'), $label1);
     $this->assertNull($form->getLabelFor('NoSuchInput'));
   }
   



More information about the limb-svn mailing list