[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/wact/tests/cases/tags/form/ -> WactInputTagTest.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/tests/cases/WactTemplateTestCase.class.php');
  11  
  12  class WactInputTagTest extends WactTemplateTestCase
  13  {
  14    function testInputTypes()
  15    {
  16      $tplStart = '<form runat="server"><input id="test" type="';
  17      $tplEnd = '" runat="server"/></form>';
  18  
  19      $types = array (
  20          'text' => 'WactInputComponent',
  21          'password' => 'WactFormElementComponent',
  22          'checkbox' => 'WactCheckableInputComponent',
  23          'submit' => 'WactFormElementComponent',
  24          'radio' => 'WactCheckableInputComponent',
  25          'reset' => 'WactFormElementComponent',
  26          'file' => 'WactFileInputComponent',
  27          'hidden' => 'WactInputComponent',
  28          'button' => 'WactInputComponent',
  29      );
  30  
  31      foreach ($types as $type => $component )
  32      {
  33        $template = $tplStart.$type.$tplEnd;
  34        $this->registerTestingTemplate('/tags/form/controls/input/'.$type.'.html', $template);
  35        $page =  $this->initTemplate('/tags/form/controls/input/'.$type.'.html');
  36        $Input =  $page->getChild('test');
  37        $this->assertIsA($Input,$component);
  38        $this->default_locator->clearTestingTemplates();
  39      }
  40    }
  41  
  42    function testUnknownType()
  43    {
  44      $template = '<form runat="server"><input id="test" type="unknown" runat="server"/></form>';
  45      $this->registerTestingTemplate('/tags/form/controls/input/unknown.html', $template);
  46      try
  47      {
  48        $page =  $this->initTemplate('/tags/form/controls/input/unknown.html');
  49      }
  50      catch(WactException $e)
  51      {
  52        $this->assertWantedPattern('/Unrecognized type attribute for input tag/', $e->getMessage());
  53      }
  54    }
  55  
  56    function testGetValueFromFormRegadrlessOfValueAttribute()
  57    {
  58      $template ='<form id="testForm" runat="server">'.
  59                  '<input type="text" id="test" name="myInput" value="my_value" runat="server" />'.
  60                 '</form>';
  61      $this->registerTestingTemplate('/tags/form/input/value_from_form.html', $template);
  62  
  63      $page = $this->initTemplate('/tags/form/input/value_from_form.html');
  64  
  65      $form = $page->getChild('testForm');
  66      $form->registerDataSource(array('myInput' => 'foo'));
  67  
  68      $expected = '<form id="testForm">'.
  69                  '<input type="text" id="test" name="myInput" value="foo" />'.
  70                  '</form>';
  71      $this->assertEqual($page->capture(), $expected);
  72    }
  73  
  74    function testUseGivenValueRegardlessOfFormValue()
  75    {
  76      $template ='<form id="testForm" runat="server">'.
  77                 '<input type="text" id="test" name="myInput" runat="server" given_value="{$#bar.var1}" />'.
  78                 '</form>';
  79      $this->registerTestingTemplate('/tags/form/input/use_given_value.html', $template);
  80  
  81      $page = $this->initTemplate('/tags/form/input/use_given_value.html');
  82      $page->set('bar', array('var1' => 'other_value'));
  83  
  84      $form = $page->getChild('testForm');
  85      $form->registerDataSource(array('myInput' => 'foo'));
  86  
  87      $expected = '<form id="testForm">'.
  88                  '<input type="text" id="test" name="myInput" value="other_value" />'.
  89                  '</form>';
  90      $this->assertEqual($page->capture(), $expected);
  91    }
  92  
  93    function testUseGivenValueWithoutForm()
  94    {
  95      $template = '<input type="text" id="test" name="myInput" runat="server" given_value="{$#bar}" />';
  96      $this->registerTestingTemplate('/tags/form/input/use_given_value_without_form.html', $template);
  97  
  98      $page = $this->initTemplate('/tags/form/input/use_given_value_without_form.html');
  99      $page->set('bar', 'other_value');
 100  
 101      $expected = '<input type="text" id="test" name="myInput" value="other_value" />';
 102      $this->assertEqual($page->capture(), $expected);
 103    }
 104  
 105    function testGenerateEmptyValueIfNotValueInForm()
 106    {
 107      $template = '<form id="testForm" runat="server">'.
 108                   '<input type="text" id="test" name="myInput" runat="server"/>'.
 109                  '</form>';
 110      $this->registerTestingTemplate('/tags/form/input/test_novalue.html', $template);
 111  
 112      $page = $this->initTemplate('/tags/form/input/test_novalue.html');
 113  
 114      $expected = '<form id="testForm">'.
 115                  '<input type="text" id="test" name="myInput" value="" />'.
 116                  '</form>';
 117      $this->assertEqual($page->capture(), $expected);
 118    }
 119  
 120    function testAllowToUseDynamicIdAttribute()
 121    {
 122      $template = '<form id="testForm" runat="server">'.
 123                  '<input type="text" id="{$test_value}" name="myInput" runat="server"/>'.
 124                  '</form>';
 125      $this->registerTestingTemplate('/tags/form/input/dynamic_attribute.html', $template);
 126  
 127      $page = $this->initTemplate('/tags/form/input/dynamic_attribute.html');
 128      $page->setChildDatasource('testForm', array('test_value' => 'my_value'));
 129  
 130      $expected = '<form id="testForm">'.
 131                  '<input type="text" name="myInput" value="" id="my_value" />'.
 132                  '</form>';
 133      $this->assertEqual($page->capture(), $expected);
 134    }
 135  }
 136  ?>


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