[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/wact/tests/cases/component/form/ -> WactFormElementComponentTest.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  
  10  require_once 'limb/wact/src/components/form/form.inc.php';
  11  
  12  class WactFormElementComponentTest extends WactTemplateTestCase
  13  {
  14    protected $element;
  15    protected $form;
  16  
  17    function setUp()
  18    {
  19      parent :: setUp();
  20  
  21      $this->form = new WactFormComponent('test_form');
  22      $this->element = new WactFormElementComponent('my_element');
  23      $this->form->addChild($this->element);
  24    }
  25  
  26    function testGetNameReturnsIdIsNoNameAttribute()
  27    {
  28      $this->assertEqual($this->element->getName(), 'my_element');
  29    }
  30  
  31    function testGetNameReturnsNameAttributeIfExists()
  32    {
  33      $this->element->setAttribute('name', 'custom_name');
  34      $this->assertEqual($this->element->getName(), 'custom_name');
  35    }
  36  
  37    function testGetValueFromForm()
  38    {
  39      $this->form->set('my_element', 'whatever');
  40      $this->assertEqual($this->element->getValue(), 'whatever');
  41    }
  42  
  43    function testGetGivenValueOverridesFormValue()
  44    {
  45      $this->form->set('my_element', 'whatever');
  46      $this->element->setGivenValue('other value');
  47      $this->assertEqual($this->element->getValue(), 'other value');
  48    }
  49  
  50    function testGetDisplayName()
  51    {
  52      $form_element = new WactFormElementComponent('my_id');
  53      $this->assertEqual($form_element->getDisplayName(),'');
  54  
  55      $form_element = new WactFormElementComponent('my_id');
  56      $form_element->displayname = 'a';
  57      $form_element->setAttribute('title','b');
  58      $form_element->setAttribute('alt','c');
  59      $form_element->setAttribute('name','d');
  60      $this->assertEqual($form_element->getDisplayName(),'a');
  61  
  62      $form_element = new WactFormElementComponent('my_id');
  63      $form_element->setAttribute('title','b');
  64      $form_element->setAttribute('alt','c');
  65      $form_element->setAttribute('name','d');
  66      $this->assertEqual($form_element->getDisplayName(),'b');
  67  
  68      $form_element = new WactFormElementComponent('my_id');
  69      $form_element->setAttribute('alt','c');
  70      $form_element->setAttribute('name','d');
  71      $this->assertEqual($form_element->getDisplayName(),'c');
  72  
  73      $form_element = new WactFormElementComponent('my_id');
  74      $form_element->setAttribute('name','foo_Bar');
  75      $this->assertEqual($form_element->getDisplayName(),'foo Bar');
  76    }
  77  
  78    function testHasErrorsNone()
  79    {
  80      $form_element = new WactFormElementComponent('my_id');
  81      $this->assertFalse($form_element->hasErrors());
  82    }
  83  
  84    function testHasErrors()
  85    {
  86      $form_element = new WactFormElementComponent('my_id');
  87      $form_element->errorclass = 'ErrorClass';
  88      $form_element->errorstyle = 'ErrorStyle';
  89  
  90      $form_element->setError();
  91  
  92      $this->assertTrue($form_element->hasErrors());
  93      $this->assertEqual($form_element->getAttribute('class'),'ErrorClass');
  94      $this->assertEqual($form_element->getAttribute('style'),'ErrorStyle');
  95    }
  96  }
  97  ?>


Generated: Thu Jan 8 04:06:23 2009 Cross-referenced by PHPXref 0.7