* @version $Id: data_table_tag.test.php,v 1.19 2004/06/24 23:06:49 jeffmoore Exp $ */ require_once WACT_ROOT . 'template/template.inc.php'; require_once WACT_ROOT . 'util/arraydataset.inc.php'; require_once 'list/decorators.inc.php'; class WarnTestCssClassRowFilter { function doFilter(&$DataSpace, &$TblDataSpace, $RowNum) { if ($DataSpace->get('check') == $TblDataSpace->get('field1')) { return 'warn'; } } } class WarnTestCssClassColFilter { var $col; function WarnTestCssClassColFilter($col) { $this->col = $col; } function doFilter(&$DataSpace, &$TblDataSpace, $RowNum) { if ($DataSpace->get('check') == $TblDataSpace->get($this->col)) { return 'warn'; } } } /** * @package WACT_TESTS */ class TemplateDataTableTagTestCase extends UnitTestCase { var $data; function TemplateDataTableTagTestCase($name = 'TemplateDataTableTagTestCase') { $this->UnitTestCase($name); $this->data = array( array('field1' => 'val1', 'field2' => 'val2') ,array('field1' => 'val3', 'field2' => 'val4') ,array('field1' => 'val5', 'field2' => 'val6') ); $this->FoundingFathers = array( array('First' => 'George', 'Last' => 'Washington'), array('First' => 'Alexander', 'Last' => 'Hamilton'), array('First' => 'Benjamin', 'Last' => 'Franklin')); $this->Numbers = array( array('BaseNumber' => 2), array('BaseNumber' => 4), array('BaseNumber' => 6)); } function setUp() { } function tearDown() { } function testEmptyTable() { $Template = ''; RegisterTestingTemplate('/template/tags/dt_empty.html', $Template); $Page =& new Template('/template/tags/dt_empty.html'); $output = $Page->capture(); $this->assertWantedPattern('/^/i', $output); $this->assertWantedPattern('~]+>[\n\t ]*~ims', $output); } function testCommentsInTable() { $Template = 'This is a comment'; RegisterTestingTemplate('/template/tags/dt_rem.html', $Template); $Page =& new Template('/template/tags/dt_rem.html'); $output = $Page->capture(); $this->assertWantedPattern('/^/i', $output); $this->assertWantedPattern('~]+>[\n\t ]*~ims', $output); $this->assertNoUnwantedPattern('/This is a comment/i', $output); } function testAttribsOnTable() { $Template = ''; RegisterTestingTemplate('/template/tags/dt_attrib.html', $Template); $Page =& new Template('/template/tags/dt_attrib.html'); $output = $Page->capture(); $this->assertWantedPattern('/^assertWantedPattern('~]+>[\n\t ]*~ims', $output); $this->assertWantedPattern('/]*\scellpadding="6"[^>]*>/i', $output); $this->assertWantedPattern('/]*\scellspacing="4"[^>]*>/i', $output); $this->assertWantedPattern('/]*\sclass="data"[^>]*>/i', $output); $this->assertNoUnwantedPattern('/]*\sfoo="bogus"[^>]*>/i', $output); } function testDefaultBadNesting() { $Template = 'There is no data to show.'; RegisterTestingTemplate('/template/tags/dt_defbadnest.html', $Template); $Page =& new Template('/template/tags/dt_defbadnest.html'); $output = $Page->capture(); $this->assertErrorPattern('/MISSINGENCLOSURE(?U).*data:default/i'); } function testDefaultNoDataTable() { $Template = 'There is no data to show.'; RegisterTestingTemplate('/template/tags/dt_defnodata.html', $Template); $Page =& new Template('/template/tags/dt_defnodata.html'); $output = $Page->capture(); $this->assertWantedPattern('/^/i', $output); $this->assertWantedPattern('~]+>(?U).*There is no data to show(?U).*~ims', $output); } function testBasicTable() { $Template = ''; RegisterTestingTemplate('/template/tags/dt_basic.html', $Template); $Page =& new Template('/template/tags/dt_basic.html'); $Table =& $Page->GetChild('tab'); $Table->registerDataSet(new ArrayDataSet($this->data)); $output = $Page->capture(); $this->assertWantedPattern('~^]+>(?U).*$~ims', $output); $this->assertWantedPattern('~]*>field1(?U).*]*>field2~ims', $output); $this->assertWantedPattern('~]*>\s*]*>val1\s*]*>val2~ims', $output); $this->assertWantedPattern('~]*>\s*]*>val3\s*]*>val4~ims', $output); } function testBasicFromTable() { $Template = ''; RegisterTestingTemplate('/template/tags/dt_basicfrom.html', $Template); $Page =& new Template('/template/tags/dt_basicfrom.html'); $Page->Set('data', new ArrayDataSet($this->data)); $output = $Page->capture(); $this->assertWantedPattern('~^]+>(?U).*$~ims', $output); $this->assertWantedPattern('~]*>field1(?U).*]*>field2~ims', $output); $this->assertWantedPattern('~]*>\s*]*>val1\s*]*>val2~ims', $output); $this->assertWantedPattern('~]*>\s*]*>val3\s*]*>val4~ims', $output); } function testColumnBadNesting() { $Template = 'There is no data to show.'; RegisterTestingTemplate('/template/tags/dt_colbadnest.html', $Template); $Page =& new Template('/template/tags/dt_colbadnest.html'); $output = $Page->capture(); $this->assertErrorPattern('/MISSINGENCLOSURE(?U).*data:column/i'); $Template = 'There is no data to show.'; RegisterTestingTemplate('/template/tags/dt_col2badnest.html', $Template); $Page =& new Template('/template/tags/dt_col2badnest.html'); $output = $Page->capture(); $this->assertErrorPattern('/MISSINGENCLOSURE(?U).*data:column/i'); } function testColumnControlsOrder() { $Template = ''; RegisterTestingTemplate('/template/tags/dt_colord.html', $Template); $Page =& new Template('/template/tags/dt_colord.html'); $Table =& $Page->GetChild('tab'); $Table->registerDataSet(new ArrayDataSet($this->data)); $output = $Page->capture(); $this->assertWantedPattern('~]*>field2(?U).*]*>field1~ims', $output); $this->assertWantedPattern('~]*>\s*]*>val2\s*]*>val1~ims', $output); $this->assertWantedPattern('~]*>\s*]*>val4\s*]*>val3~ims', $output); } function testColumnCellTemplateOrder() { $Template = '{$field2|uppercase}'; RegisterTestingTemplate('/template/tags/dt_coltpl.html', $Template); $Page =& new Template('/template/tags/dt_coltpl.html'); $Table =& $Page->GetChild('tab'); $Table->registerDataSet(new ArrayDataSet($this->data)); $output = $Page->capture(); $this->assertWantedPattern('~]*>\s*]*>VAL2\s*]*>val1~ms', $output); $this->assertWantedPattern('~]*>\s*]*>VAL4\s*]*>val3~ms', $output); } function testHeaderBadNesting() { $Template = ''; RegisterTestingTemplate('/template/tags/dt_headbadnest.html', $Template); $Page =& new Template('/template/tags/dt_headbadnest.html'); $output = $Page->capture(); $this->assertErrorPattern('/MISSINGENCLOSURE(?U).*data:header/i'); } function testFooterBadNesting() { $Template = ''; RegisterTestingTemplate('/template/tags/dt_footbadnest.html', $Template); $Page =& new Template('/template/tags/dt_footbadnest.html'); $output = $Page->capture(); $this->assertErrorPattern('/MISSINGENCLOSURE(?U).*data:footer/i'); } function testColumnHeaderTemplate() { $Template = '' .'{$#field1_desc|uppercase}' .'{$#field2_desc|uppercase} ({$field2})' .''; RegisterTestingTemplate('/template/tags/dt_headtpl.html', $Template); $Page =& new Template('/template/tags/dt_headtpl.html'); $Page->set('field1_desc', 'field1'); $Page->set('field2_desc', 'f2'); $Page->set('data', new ArrayDataSet($this->data)); $output = $Page->capture(); $this->assertWantedPattern('~]*>FIELD1(?U).*]*>F2\s\(val2\)~ims', $output); } function testColumnAttribHeader() { $Template = '' .'' .'{$#field2_desc|uppercase} ({$field2})' .''; RegisterTestingTemplate('/template/tags/dt_headatttpl.html', $Template); $Page =& new Template('/template/tags/dt_headatttpl.html'); $Page->set('field1_desc', 'field1'); $Page->set('field2_desc', 'f2'); $Page->set('data', new ArrayDataSet($this->data)); $output = $Page->capture(); $this->assertWantedPattern('~]*>FIELD1(?U).*]*>F2\s\(val2\)~ims', $output); } /* I can't seem to get this test to run, I always get an UNRESOLVED_BINDING error function testColumnAttribHeaderProperty() { $Template = '' .'' .''; RegisterTestingTemplate('/template/tags/dt_headattproptpl.html', $Template); $Page =& new Template('/template/tags/dt_headattproptpl.html'); $Page->set('field1_desc', 'Field1'); $Page->set('data', new ArrayDataSet($this->data)); $output = $Page->capture(); $this->assertWantedPattern('~]*>Field1~ms', $output); } */ function testColumnHide() { $Template = '' .'' .''; RegisterTestingTemplate('/template/tags/dt_colhide.html', $Template); $Page =& new Template('/template/tags/dt_colhide.html'); $Page->set('data', new ArrayDataSet($this->data)); $output = $Page->capture(); $this->assertNoUnwantedPattern('~]*>field1~ims', $output); $this->assertNoUnwantedPattern('~]*>val1~ims', $output); } function testColumnAsThTable() { $Template = ''; RegisterTestingTemplate('/template/tags/dt_colashead.html', $Template); $Page =& new Template('/template/tags/dt_colashead.html'); $Page->Set('data', new ArrayDataSet($this->data)); $output = $Page->capture(); $this->assertWantedPattern('~^]+>(?U).*$~ims', $output); $this->assertWantedPattern('~]*>field1(?U).*]*>field2~ims', $output); $this->assertWantedPattern('~]*>\s*]*>val1\s*]*>val2~ims', $output); $this->assertWantedPattern('~]*>\s*]*>val3\s*]*>val4~ims', $output); } function testAutoGenAttrib() { $Template = ''; RegisterTestingTemplate('/template/tags/dt_autogenoff.html', $Template); $Page =& new Template('/template/tags/dt_autogenoff.html'); $Page->set('data', new ArrayDataSet($this->data)); $output = $Page->capture(); $this->assertWantedPattern('~]*>field2~ims', $output); $this->assertWantedPattern('~]*>\s*]*>val2~ims', $output); $this->assertWantedPattern('~]*>\s*]*>val4~ims', $output); $this->assertNoUnwantedPattern('~]*>field1~ims', $output); $this->assertNoUnwantedPattern('~]*>val1~ims', $output); $this->assertNoUnwantedPattern('~]*>val3~ims', $output); } function testTableWideHeader() { $Template = '{$#t} {$field1} wide heading'; RegisterTestingTemplate('/template/tags/dt_tabhead.html', $Template); $Page =& new Template('/template/tags/dt_tabhead.html'); $data = $this->data; foreach ($data as $key => $row) { $data[$key] = array_merge($row, array('another'=>'', 'column'=>'', 'and'=>'', 'one'=>'', 'more' => '')); } $Page->Set('data', new ArrayDataSet($data)); $Page->Set('t', 'Table'); $output = $Page->capture(); $this->assertWantedPattern('~^]+>(?U).*$~ims', $output); $this->assertWantedPattern('~]*>\s*]*>Table val1 wide heading~ims', $output); } function testTableWideFooter() { $Template = 'Copyleft 2004 Procata, Inc.'; RegisterTestingTemplate('/template/tags/dt_tabfoot.html', $Template); $Page =& new Template('/template/tags/dt_tabfoot.html'); $data = $this->data; foreach ($data as $key => $row) { $data[$key] = array_merge($row, array('another'=>'', 'column'=>'', 'and'=>'', 'one'=>'', 'more' => '')); } $Page->Set('data', new ArrayDataSet($data)); $output = $Page->capture(); $this->assertWantedPattern('~^]+>(?U).*$~ims', $output); $this->assertWantedPattern('~]*>\s*]*>Copyleft 2004[^<]*\s*\s*~ims', $output); } function testTableWideFooterTh() { $Template = 'Copyleft 2004 Procata, Inc.'; RegisterTestingTemplate('/template/tags/dt_tabfooth.html', $Template); $Page =& new Template('/template/tags/dt_tabfooth.html'); $data = $this->data; foreach ($data as $key => $row) { $data[$key] = array_merge($row, array('another'=>'', 'column'=>'', 'and'=>'', 'one'=>'', 'more' => '')); } $Page->Set('data', new ArrayDataSet($data)); $output = $Page->capture(); $this->assertWantedPattern('~^]+>(?U).*$~ims', $output); $this->assertWantedPattern('~]*>\s*]*>Copyleft 2004[^<]*\s*\s*~ims', $output); } function testColFooters() { $Template = '' .'f1' .'{$#foot}f3' .''; RegisterTestingTemplate('/template/tags/dt_tabcfoot.html', $Template); $Page =& new Template('/template/tags/dt_tabcfoot.html'); $Page->Set('data', new ArrayDataSet($this->data)); $Page->Set('foot', 'f2'); $output = $Page->capture(); $this->assertWantedPattern('~]*>f1f2~ims', $output); $this->assertWantedPattern('~]*> f3~ims', $output); } function testColFootersBold() { $Template = '' .'f1' .'{$#foot}f3' .''; RegisterTestingTemplate('/template/tags/dt_tabcfootb.html', $Template); $Page =& new Template('/template/tags/dt_tabcfootb.html'); $Page->Set('data', new ArrayDataSet($this->data)); $Page->Set('foot', 'f2'); $output = $Page->capture(); $this->assertWantedPattern('~]*>f1f2~ims', $output); $this->assertWantedPattern('~]*> f3~ims', $output); } function testColGroup() { $Template = '' .'' .' :: {$#grp} :: ' .'' .'' .''; RegisterTestingTemplate('/template/tags/dt_tabgrp.html', $Template); $Page =& new Template('/template/tags/dt_tabgrp.html'); $data = $this->data; foreach ($data as $key => $row) { $data[$key] = array_merge($row, array('another'=>'', 'column'=>'')); } $Page->Set('data', new ArrayDataSet($data)); $Page->Set('grp', 'Group Title'); $output = $Page->capture(); $this->assertWantedPattern('~]*>(?U).*]*>field2]*> :: Group Title :: (?U).*]*>column(?U).*~ims', $output); $this->assertWantedPattern('~]*>(?U).*field1(?U).*another~ims', $output); } function testRowCssClassFilter() { $Template = '' .''; RegisterTestingTemplate('/template/tags/dt_tabrowfil.html', $Template); $Page =& new Template('/template/tags/dt_tabrowfil.html'); $Page->Set('data', new ArrayDataSet($this->data)); $Page->Set('check', 'val3'); $Filter =& new WarnTestCssClassRowFilter; $Table =& $Page->GetChild('tab'); $Table->registerRowCssClassFilter($Filter); $output = $Page->capture(); $this->assertWantedPattern('~]*class="warn"[^>]*>\s*val3~ims', $output); } function testColumnCssClassFilter() { $Template = '' .'' .''; RegisterTestingTemplate('/template/tags/dt_tabcolfil.html', $Template); $Page =& new Template('/template/tags/dt_tabcolfil.html'); $Page->Set('data', new ArrayDataSet($this->data)); $Page->Set('check', 'val4'); $Filter =& new WarnTestCssClassColFilter('field2'); $Column =& $Page->GetChild('f2'); $Column->registerCssClassFilter($Filter); $output = $Page->capture(); $this->assertWantedPattern('~]*>\s*]*class="warn">val4~ims', $output); } function testTableRowAttributes() { $Template = ''; RegisterTestingTemplate('/template/tags/dt_tabrowatt.html', $Template); $Page =& new Template('/template/tags/dt_tabrowatt.html'); $Page->Set('data', new ArrayDataSet($this->data)); $output = $Page->capture(); $attrib_pattern=']*(\sstyle="rs"|\salign="left"|\svalign="top"){3}[^>]*>'; $this->assertWantedPattern('~]*style="ts"[^>]*>(?U).*]*>((?U).*'.$attrib_pattern.'){3}~ims', $output); $this->assertNoUnwantedPattern('~foo="bar"~ims', $output); } function testColumnAttributes() { $Template = '' .'' .'' .''; RegisterTestingTemplate('/template/tags/dt_tabcolatt.html', $Template); $Page =& new Template('/template/tags/dt_tabcolatt.html'); $Page->Set('data', new ArrayDataSet($this->data)); $output = $Page->capture(); $attrib_pattern=']*(\sstyle="f1s"|\salign="right"){2}[^>]*>(?U).*(?U).*]*(\sstyle="f2s"|\salign="center"){2}[^>]*>(?U).*'; $this->assertWantedPattern('~]*style="ts"[^>]*>((?U).*]*>(?U).*'.$attrib_pattern.'){3}~ims', $output); } function testHeaderAttributes() { $Template = '' .'' .'f1' .'' .''; RegisterTestingTemplate('/template/tags/dt_tabheadatt.html', $Template); $Page =& new Template('/template/tags/dt_tabheadatt.html'); $Page->Set('data', new ArrayDataSet($this->data)); $output = $Page->capture(); $this->assertWantedPattern('~]*style="ts"[^>]*>(?U).*]*>(?U).*]*style="width: 250px"[^>]*>((?U).*]*>(?U).*]*style="text-align: center"[^>]*>){3}~ims', $output); } function testSuppressOpen() {} // no function testSuppressClose() {} // no function testAutoRowClass() {} //feature to add wact_header, wact_detail and wact_footer classes to all function testSupressHeadings() {} //no headings show up function testRepeatHeadings() {} //headings show up ever n rows function testNestedListOuterIdInnerFrom() { $Template = ''; $Template .= '{$First}:'; $Template .= ''; $Template .= ''; RegisterTestingTemplate('/tags/data/nested-id-from.html', $Template); $Page =& new Template('/tags/data/nested-id-from.html'); $list =& $Page->getChild('test'); $list->registerDataSet(new NestedDataSetDecorator(new ArrayDataSet($this->FoundingFathers))); $output = $Page->capture(); $this->assertWantedPattern('/^George:.*value1.*value3.*value5.*Alexander:.*value1.*value3.*value5.*Benjamin:.*value1.*value3.*value5.*$/s', $output); } function testNestedListOuterFromInnerFrom() { $Template = ''; $Template .= '{$First}:'; $Template .= ''; $Template .= ''; RegisterTestingTemplate('/tags/data/nested-from-from.html', $Template); $Page =& new Template('/tags/data/nested-from-from.html'); $Page->set('test',new NestedDataSetDecorator(new ArrayDataSet($this->FoundingFathers))); $output = $Page->capture(); $this->assertWantedPattern('/^George:.*value1.*value3.*value5.*Alexander:.*value1.*value3.*value5.*Benjamin:.*value1.*value3.*value5.*$/s', $output); } function testNestedListOuterIdInnerId() { $Template = ''; $Template .= '{$BaseNumber}:'; $Template .= ''; $Template .= ''; RegisterTestingTemplate('/tags/data/nested-id-id.html', $Template); $Page =& new Template('/tags/data/nested-id-id.html'); $NumberList =& new ArrayDataSet($this->Numbers); $Page->setChildDataSource('test', $NumberList); $Page->setChildDataSource('sub', new InnerDataSource($NumberList)); $output = $Page->capture(); $this->assertWantedPattern('/^2:.*2.*4.*8.*4:.*4.*16.*64.*6:.*6.*36.*216.*$/s', $output); } /* Does not work under PHP 4 because a copy is made during the set('test'). This test should pass under PHP 5. function testNestedListOuterFromInnerId() { $Template = ''; $Template .= '{$BaseNumber}:'; $Template .= ''; $Template .= ''; RegisterTestingTemplate('/tags/data/nested-from-id.html', $Template); $Page =& new Template('/tags/data/nested-from-id.html'); $NumberList =& new ArrayDataSet($this->Numbers); $Page->set('test', $NumberList); $Page->setChildDataSource('sub', new InnerDataSource($NumberList)); $output = $Page->capture(); $this->assertWantedPattern('/^2:.*2.*4.*8.*4:.*4.*16.*64.*6:.*6.*36.*216.*$/s', $output); } */ } ?>