[ Index ]

PHP Cross Reference of Web Application Component Toolkit

title

Body

[close]

/tests/cases/template/tags/list/ -> list.test.php (source)

   1  <?php
   2  /**
   3   * @package WACT_TESTS
   4   * @version $Id: list.test.php,v 1.13 2004/11/12 21:25:19 jeffmoore Exp $
   5   */
   6  require_once WACT_ROOT . 'template/template.inc.php';
   7  
   8  require_once  'decorators.inc.php';
   9  
  10  /**
  11  * @package WACT_TESTS
  12  */
  13  class CoreListTagTestCase extends UnitTestCase {
  14      function CoreListTagTestCase($name = 'CoreListTagTestCase') {
  15          $this->UnitTestCase($name);
  16      }
  17  
  18  	function setUp() {
  19          $this->FoundingFathers =
  20              array(  array('First' => 'George', 'Last' => 'Washington'),
  21                      array('First' => 'Alexander', 'Last' => 'Hamilton'),
  22                      array('First' => 'Benjamin', 'Last' => 'Franklin'));
  23          $this->Numbers = 
  24              array(  array('BaseNumber' => 2),
  25                      array('BaseNumber' => 4),
  26                      array('BaseNumber' => 6));
  27      }
  28  
  29      function tearDown() {
  30          unset($this->FoundingFathers);
  31          ClearTestingTemplates();
  32      }
  33  
  34      function testList() {
  35          $Template = '<list:LIST id="test"><list:ITEM>';
  36          $Template .= '{$First}' . "\n";
  37          $Template .= '</list:ITEM></list:LIST>';
  38          RegisterTestingTemplate('/tags/core/list/list.html', $Template);        
  39  
  40          $Page =& new Template('/tags/core/list/list.html');
  41          $list =& $Page->getChild('test');
  42          $list->registerDataSet(new ArrayDataSet($this->FoundingFathers));
  43          $output = $Page->capture();
  44          $this->assertEqual($output, "George\nAlexander\nBenjamin\n");
  45      }
  46  
  47      function testListSeparator() {
  48          $Template = '<list:LIST id="test"><list:ITEM>';
  49          $Template .= '{$First}';
  50          $Template .= "<list:SEPARATOR>\n</list:SEPARATOR>";
  51          $Template .= '</list:ITEM></list:LIST>';
  52          RegisterTestingTemplate('/tags/core/list/separator.html', $Template);        
  53  
  54          $Page =& new Template('/tags/core/list/separator.html');
  55          $list =& $Page->getChild('test');
  56          $list->registerDataSet(new ArrayDataSet($this->FoundingFathers));
  57          $output = $Page->capture();
  58          $this->assertEqual($output, "George\nAlexander\nBenjamin");
  59      }
  60  
  61      function testListDefault() {
  62          $Template = '<list:LIST id="test"><list:ITEM>';
  63          $Template .= '{$First}' . "\n";
  64          $Template .= '</list:ITEM>';
  65          $Template .= '<list:default>default</list:default>';
  66          $Template .= '</list:LIST>';
  67          RegisterTestingTemplate('/tags/core/list/default.html', $Template);        
  68  
  69          $Page =& new Template('/tags/core/list/default.html');
  70          $list =& $Page->getChild('test');
  71          $list->registerDataSet(new ArrayDataSet($this->FoundingFathers));
  72          $output = $Page->capture();
  73          $this->assertEqual($output, "George\nAlexander\nBenjamin\n");
  74      }
  75  
  76      function testListDefaultWithNoData() {
  77          $Template = '<list:LIST id="test"><list:ITEM>';
  78          $Template .= '{$First}' . "\n";
  79          $Template .= '</list:ITEM>';
  80          $Template .= '<list:default>default</list:default>';
  81          $Template .= '</list:LIST>';
  82          RegisterTestingTemplate('/tags/core/list/default-empty.html', $Template);        
  83  
  84          $Page =& new Template('/tags/core/list/default-empty.html');
  85          $list =& $Page->getChild('test');
  86          $list->registerDataSet(new ArrayDataSet(array()));
  87          $output = $Page->capture();
  88          $this->assertEqual($output, "default");
  89      }
  90  
  91      function testListRowNumber() {
  92          $Template = '<list:LIST id="test"><list:ITEM>';
  93          $Template .= '{$ListRowNumber}:{$First}' . "\n";
  94          $Template .= '</list:ITEM></list:LIST>';
  95          RegisterTestingTemplate('/tags/core/list/list-rownumber.html', $Template);        
  96  
  97          $Page =& new Template('/tags/core/list/list-rownumber.html');
  98          $list =& $Page->getChild('test');
  99          $list->registerDataSet(new ArrayDataSet($this->FoundingFathers));
 100          $output = $Page->capture();
 101          $this->assertEqual($output, "1:George\n2:Alexander\n3:Benjamin\n");
 102      }
 103  
 104      function testListRowOdd() {
 105          $Template = '<list:LIST id="test"><list:ITEM>';
 106          $Template .= '<core:optional for="ListRowOdd">odd</core:optional>';
 107          $Template .= '<core:default for="ListRowOdd">even</core:default>';
 108          $Template .= ':{$First}' . "\n";
 109          $Template .= '</list:ITEM></list:LIST>';
 110          RegisterTestingTemplate('/tags/core/list/list-rowodd.html', $Template);        
 111  
 112          $Page =& new Template('/tags/core/list/list-rowodd.html');
 113          $list =& $Page->getChild('test');
 114          $list->registerDataSet(new ArrayDataSet($this->FoundingFathers));
 115          $output = $Page->capture();
 116          $this->assertEqual($output, "odd:George\neven:Alexander\nodd:Benjamin\n");
 117      }
 118  
 119      function testListRowEven() {
 120          $Template = '<list:LIST id="test"><list:ITEM>';
 121          $Template .= '<core:optional for="ListRowEven">even</core:optional>';
 122          $Template .= '<core:default for="ListRowEven">odd</core:default>';
 123          $Template .= ':{$First}' . "\n";
 124          $Template .= '</list:ITEM></list:LIST>';
 125          RegisterTestingTemplate('/tags/core/list/list-roweven.html', $Template);        
 126  
 127          $Page =& new Template('/tags/core/list/list-roweven.html');
 128          $list =& $Page->getChild('test');
 129          $list->registerDataSet(new ArrayDataSet($this->FoundingFathers));
 130          $output = $Page->capture();
 131          $this->assertEqual($output, "odd:George\neven:Alexander\nodd:Benjamin\n");
 132      }
 133  
 134      function testListParity() {
 135          $Template = '<list:LIST id="test"><list:ITEM>';
 136          $Template .= '{$Parity}:{$First}' . "\n";
 137          $Template .= '</list:ITEM></list:LIST>';
 138          RegisterTestingTemplate('/tags/core/list/list-parity.html', $Template);        
 139  
 140          $Page =& new Template('/tags/core/list/list-parity.html');
 141          $list =& $Page->getChild('test');
 142          $list->registerDataSet(new ArrayDataSet($this->FoundingFathers));
 143          $output = $Page->capture();
 144          $this->assertEqual($output, "odd:George\neven:Alexander\nodd:Benjamin\n");
 145      }
 146  
 147      function testListFrom() {
 148          $Template = '<list:LIST from="test"><list:ITEM>';
 149          $Template .= '{$First}' . "\n";
 150          $Template .= '</list:ITEM></list:LIST>';
 151          RegisterTestingTemplate('/tags/core/list/listfrom.html', $Template);        
 152  
 153          $Page =& new Template('/tags/core/list/listfrom.html');
 154          $Page->set('test', new ArrayDataSet($this->FoundingFathers)); 
 155          $output = $Page->capture();
 156          $this->assertEqual($output, "George\nAlexander\nBenjamin\n");
 157      }
 158  
 159  	function testNestedListOuterIdInnerFrom() {
 160          $Template = '<list:LIST id="test"><list:ITEM>';
 161          $Template .= '{$First}:';
 162          $Template .= '<list:LIST from="sub"><list:ITEM>';
 163          $Template .= '{$subvar1} ';
 164          $Template .= "</list:ITEM>\n</list:LIST>";
 165          $Template .= '</list:ITEM></list:LIST>';
 166          RegisterTestingTemplate('/tags/core/list/nested-id-from.html', $Template);
 167          
 168          $Page =& new Template('/tags/core/list/nested-id-from.html');
 169          $list =& $Page->getChild('test');
 170          $list->registerDataSet(new NestedDataSetDecorator(new ArrayDataSet($this->FoundingFathers)));
 171          $output = $Page->capture();
 172          $this->assertEqual($output, "George:value1 value3 value5 \nAlexander:value1 value3 value5 \nBenjamin:value1 value3 value5 \n");
 173      }
 174  
 175  	function testNestedListOuterFromInnerFrom() {
 176          $Template = '<list:LIST from="test"><list:ITEM>';
 177          $Template .= '{$First}:';
 178          $Template .= '<list:LIST from="sub"><list:ITEM>';
 179          $Template .= '{$subvar1} ';
 180          $Template .= "</list:ITEM>\n</list:LIST>";
 181          $Template .= '</list:ITEM></list:LIST>';
 182          RegisterTestingTemplate('/tags/core/list/nested-from-from.html', $Template);
 183          
 184          $Page =& new Template('/tags/core/list/nested-from-from.html');
 185          $Page->set('test',new NestedDataSetDecorator(new ArrayDataSet($this->FoundingFathers))); 
 186          $output = $Page->capture();
 187          $this->assertEqual($output, "George:value1 value3 value5 \nAlexander:value1 value3 value5 \nBenjamin:value1 value3 value5 \n");
 188      }
 189  
 190  	function testNestedListOuterIdInnerId() {
 191          $Template = '<list:LIST id="test"><list:ITEM>';
 192          $Template .= '{$BaseNumber}:';
 193          $Template .= '<list:LIST id="sub"><list:ITEM>';
 194          $Template .= '{$Num} ';
 195          $Template .= "</list:ITEM>\n</list:LIST>";
 196          $Template .= '</list:ITEM></list:LIST>';
 197          RegisterTestingTemplate('/tags/core/list/nested-id-id.html', $Template);
 198          
 199          $Page =& new Template('/tags/core/list/nested-id-id.html');
 200          $NumberList =& new ArrayDataSet($this->Numbers);
 201          $Page->setChildDataSource('test', $NumberList);
 202          $Page->setChildDataSource('sub', new InnerDataSource($NumberList));
 203          $output = $Page->capture();
 204          $this->assertEqual($output, "2:2 4 8 \n4:4 16 64 \n6:6 36 216 \n");
 205      }
 206  
 207  	function testScriptInList() {
 208          $template = '<list:list id="script_test" from="data"><script type="text/javascript">'
 209                      .'<list:item>alert("{$msg}");</list:item>'
 210                      .'</script></list:list>';
 211          RegisterTestingTemplate('/tags/core/list/script-in-list.html', $template);
 212          
 213          $Page =& new Template('/tags/core/list/script-in-list.html');
 214          $testSource =& new ArrayDataSet(array(
 215                   array('msg' => 1)
 216                  ,array('msg' => 2)
 217                  ,array('msg' => 3)
 218                  ));
 219          $Page->set('data', $testSource);
 220          
 221          $output = $Page->capture();
 222          $this->assertWantedPattern('/alert.*1.*alert.*2.*alert.*3/iU', $output, 'Bug 1000806-Failed to iterated over the list [%s]');
 223          $this->assertNoUnwantedPattern('/list/i', $output, 'Bug 1000806-Output contains the word list [%s]');
 224          $this->assertNoUnwantedPattern('/item/i', $output, 'Bug 1000806-Output contains the word item [%s]');
 225      }
 226  
 227  
 228  	function testScriptInListWorkAround() {
 229          $template = '{$startscript|raw}<list:list id="script_test" from="data">'
 230                      .'<list:item>alert("{$msg}");</list:item>'
 231                      .'</list:list>{$endscript|raw}';
 232          RegisterTestingTemplate('/tags/core/list/script-in-list2.html', $template);
 233          
 234          $Page =& new Template('/tags/core/list/script-in-list2.html');
 235          $testSource =& new ArrayDataSet(array(
 236                   array('msg' => 1)
 237                  ,array('msg' => 2)
 238                  ,array('msg' => 3)
 239                  ));
 240          $Page->set('data', $testSource);
 241          $Page->set('startscript',  '<script type="text/javascript">');
 242          $Page->set('endscript',  '</script>');
 243          
 244          $output = $Page->capture();
 245          $this->assertWantedPattern('/alert.*1.*alert.*2.*alert.*3/iU', $output, 'Bug 1000806-Failed to iterated over the list [%s]');
 246          $this->assertNoUnwantedPattern('/list/i', $output, 'Bug 1000806-Output contains the word list [%s]');
 247          $this->assertNoUnwantedPattern('/item/i', $output, 'Bug 1000806-Output contains the word item [%s]');
 248      }
 249      /*
 250      Does not work under PHP 4 because a copy is made during the set('test').
 251      This test should pass under PHP 5.
 252      function testNestedListOuterFromInnerId() {
 253          $Template = '<list:LIST from="test"><list:ITEM>';
 254          $Template .= '{$BaseNumber}:';
 255          $Template .= '<list:LIST id="sub"><list:ITEM>';
 256          $Template .= '{$Num} ';
 257          $Template .= "</list:ITEM>\n</list:LIST>";
 258          $Template .= '</list:ITEM></list:LIST>';
 259          RegisterTestingTemplate('/tags/core/list/nested-from-id.html', $Template);
 260          
 261          $Page =& new Template('/tags/core/list/nested-from-id.html');
 262          
 263          $NumberList =& new ArrayDataSet($this->Numbers);
 264          $Page->set('test', $NumberList);
 265          $Page->setChildDataSource('sub', new InnerDataSource($NumberList));
 266          
 267          $output = $Page->capture();
 268          $this->assertEqual($output, "2:2 4 8 \n4:4 16 64 \n6:6 36 216 \n");
 269      }
 270      */
 271  
 272  }
 273  ?>


Generated: Sun Nov 28 19:36:09 2004 Cross-referenced by PHPXref 0.5