[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/wact/tests/cases/tags/form/ -> WactSelectOptionsSourceTagTest.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  class WactSelectOptionsSourceTagTest extends WactTemplateTestCase
  11  {
  12    function testTargetNotFound()
  13    {
  14      $template = '<core:DATASOURCE id="data">' .
  15                  '<select:OPTIONS_SOURCE target="select" from="source"/>' .
  16                  '</core:DATASOURCE>';
  17  
  18      $this->registerTestingTemplate('/tags/form/select_options_source/error.html', $template);
  19  
  20      try
  21      {
  22        $page = $this->initTemplate('/tags/form/select_options_source/error.html');
  23        $this->assertTrue(false);
  24      }
  25      catch(WactException $e)
  26      {
  27        $this->assertWantedPattern('/Could not find component/', $e->getMessage());
  28      }
  29    }
  30  
  31    function testTargetIsNotSupported()
  32    {
  33      $template = '<core:DATASOURCE id="data">' .
  34                  '<select:OPTIONS_SOURCE target="select" from="source"/>' .
  35                  '<core:DATASOURCE id="select"></core:DATASOURCE>' .
  36                  '</core:DATASOURCE>';
  37  
  38      $this->registerTestingTemplate('/tags/form/select_options_source/not_supported.html', $template);
  39  
  40      try
  41      {
  42        $page = $this->initTemplate('/tags/form/select_options_source/not_supported.html');
  43        $this->assertTrue(false);
  44      }
  45      catch(WactException $e)
  46      {
  47        $this->assertWantedPattern('/Select tag not found/', $e->getMessage());
  48      }
  49    }
  50  
  51    function testTakeOptionsFrom()
  52    {
  53      $template = '<core:DATASOURCE id="data">' .
  54                  '<select:OPTIONS_SOURCE target="select" from="{$^source}"/>' .
  55                  '<form runat="server">' .
  56                  '<select id="select" name="select"></select>' .
  57                  '</form>' .
  58                  '</core:DATASOURCE>';
  59  
  60      $this->registerTestingTemplate('/tags/form/select_options_source/from.html', $template);
  61  
  62      $page = $this->initTemplate('/tags/form/select_options_source/from.html');
  63  
  64      $data = $page->getChild('data');
  65      $data->set('source', $options = array('4' => 'red', '5' => 'blue'));
  66  
  67      $this->assertEqual($page->capture(),
  68                         '<form>'.
  69                         '<select id="select" name="select"><option value="4">red</option><option value="5">blue</option></select>'.
  70                         '</form>');
  71    }
  72  
  73    function testOptionsViaRegisterDataSet()
  74    {
  75      $template = '<select:OPTIONS_SOURCE id="source" target="select"/>' .
  76                  '<form runat="server">' .
  77                  '<select id="select" name="select"></select>' .
  78                  '</form>';
  79  
  80      $this->registerTestingTemplate('/tags/form/select_options_source/register_dataset.html', $template);
  81  
  82      $page = $this->initTemplate('/tags/form/select_options_source/register_dataset.html');
  83  
  84      $data = $page->getChild('source');
  85  
  86      $data->registerDataSet($options = array(array('4' => 'red'), array('5' => 'blue')));
  87  
  88      $this->assertEqual($page->capture(),
  89                         '<form>'.
  90                         '<select id="select" name="select"><option value="4">red</option><option value="5">blue</option></select>'.
  91                         '</form>');
  92    }
  93  
  94    function testOptionsUseNameAndId()
  95    {
  96      $template = '<select:OPTIONS_SOURCE id="source" target="select" use_as_name="name" use_as_id="id"/>' .
  97                  '<form runat="server">' .
  98                  '<select id="select" name="select"></select>' .
  99                  '</form>';
 100  
 101      $this->registerTestingTemplate('/tags/form/select_options_source/use_name_and_id.html', $template);
 102  
 103      $page = $this->initTemplate('/tags/form/select_options_source/use_name_and_id.html');
 104  
 105      $data = $page->getChild('source');
 106  
 107      $data->registerDataSet($options = array(array('id' => '4', 'name' => 'red'),
 108                                              array('id' => '5', 'name' => 'blue')));
 109  
 110      $this->assertEqual($page->capture(),
 111                         '<form>'.
 112                         '<select id="select" name="select"><option value="4">red</option><option value="5">blue</option></select>'.
 113                         '</form>');
 114    }
 115  
 116    function testSeveralTargets()
 117    {
 118      $template = '<select:OPTIONS_SOURCE id="source" target="select1,select2" use_as_name="name" use_as_id="id"/>' .
 119                  '<form runat="server">' .
 120                  '<select id="select1" name="select1"></select>' .
 121                  '<select id="select2" name="select2"></select>' .
 122                  '</form>';
 123  
 124      $this->registerTestingTemplate('/tags/form/select_options_source/several_targets.html', $template);
 125  
 126      $page = $this->initTemplate('/tags/form/select_options_source/several_targets.html');
 127  
 128      $data = $page->getChild('source');
 129  
 130      $data->registerDataSet($options = array(array('id' => '4', 'name' => 'red'),
 131                                              array('id' => '5', 'name' => 'blue')));
 132  
 133      $this->assertEqual($page->capture(),
 134                         '<form>'.
 135                         '<select id="select1" name="select1"><option value="4">red</option><option value="5">blue</option></select>'.
 136                         '<select id="select2" name="select2"><option value="4">red</option><option value="5">blue</option></select>'.
 137                         '</form>');
 138    }
 139  
 140    function testWithDefaultOption()
 141    {
 142      $template = '<select:OPTIONS_SOURCE id="source" target="select" use_as_name="name" use_as_id="id" default_value="-1" default_name="Select something"/>' .
 143                  '<form runat="server">' .
 144                  '<select id="select" name="select"></select>' .
 145                  '</form>';
 146  
 147      $this->registerTestingTemplate('/tags/form/select_options_source/with_default.html', $template);
 148  
 149      $page = $this->initTemplate('/tags/form/select_options_source/with_default.html');
 150  
 151      $data = $page->getChild('source');
 152  
 153      $data->registerDataSet($options = array(array('id' => '4', 'name' => 'red'),
 154                                              array('id' => '5', 'name' => 'blue')));
 155  
 156      $this->assertEqual($page->capture(),
 157                         '<form>'.
 158                         '<select id="select" name="select"><option value="-1">Select something</option><option value="4">red</option><option value="5">blue</option></select>'.
 159                         '</form>');
 160    }
 161  
 162    function testOptionsViaRegisterDatasourceAndDefaultOption()
 163    {
 164      $template = '<select:OPTIONS_SOURCE id="source" target="select" default_value="0" default_name="select"/>' .
 165                  '<form runat="server">' .
 166                  '<select id="select" name="select"></select>' .
 167                  '</form>';
 168  
 169      $this->registerTestingTemplate('/tags/form/select_options_source/register_datasource_and_default_option.html', $template);
 170  
 171      $page = $this->initTemplate('/tags/form/select_options_source/register_datasource_and_default_option.html');
 172  
 173      $data = $page->getChild('source');
 174  
 175      $data->registerDatasource($options = array('4' => 'red', '5' => 'blue'));
 176  
 177      $this->assertEqual($page->capture(),
 178                         '<form>'.
 179                         '<select id="select" name="select"><option value="" selected="true">select</option><option value="4">red</option><option value="5">blue</option></select>'.
 180                         '</form>');
 181    }
 182  
 183  }
 184  ?>


Generated: Mon Dec 1 03:56:46 2008 Cross-referenced by PHPXref 0.7