| [ Index ] |
PHP Cross Reference of Web Application Component Toolkit |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package WACT_TESTS 4 * @version $Id: arraydataset.test.php,v 1.11 2004/11/12 21:25:19 jeffmoore Exp $ 5 */ 6 require_once WACT_ROOT . 'util/arraydataset.inc.php'; 7 require_once WACT_ROOT . 'util/emptydataset.inc.php'; 8 9 require_once TEST_CASES . '/util/datasource.inc.php'; 10 11 if ( !class_exists('ADSTestFilter') ) { 12 class ADSTestFilter { 13 function doFilter(&$vars) { 14 foreach ($vars as $key => $val) { 15 $vars[$key] = strrev($vars[$key]); 16 } 17 } 18 } 19 } 20 21 /** 22 * @package WACT_TESTS 23 */ 24 //if ( !class_exists('ArrayDataSetTestCase') ) { 25 class EmptyArrayDataSetTestCase extends DataSourceTestCase { 26 function EmptyArrayDataSetTestCase($name = 'EmptyArrayDataSetTestCase') { 27 $this->DataSourceTestCase($name); 28 } 29 function setUp() { 30 $this->dataspace = new ArrayDataSet(array()); 31 $this->dataspace->reset(); 32 $this->dataspace->next(); 33 } 34 function tearDown() { 35 unset ( $this->dataspace ); 36 parent::tearDown(); 37 } 38 function testIsEmpty() { 39 $this->assertTrue($this->dataspace->isEmpty()); 40 } 41 } 42 43 class ArrayDataSetTestCase extends UnitTestCase { 44 function ArrayDataSetTestCase($name = 'ArrayDataSetTestCase') { 45 $this->UnitTestCase($name); 46 } 47 function setUp() { 48 $array = array( 49 array('size' => 'small', 'color' => 'purple', 'smell' => 'lilac'), 50 array('size' => 'large', 'color' => 'red', 'smell' => 'lavender') 51 ); 52 $this->dataspace = new ArrayDataSet($array); 53 54 // Must call following before values can be accessed. 55 $this->dataspace->reset(); 56 $this->dataspace->next(); 57 } 58 function tearDown() { 59 unset ( $this->dataspace ); 60 } 61 function testSet() { 62 $this->dataspace->set('size', 'tiny'); 63 $this->assertIdentical($this->dataspace->get('size'), 'tiny'); 64 } 65 function testImport() { 66 $array = array('size' => 'medium', 'color' => 'white'); 67 $this->dataspace->import($array); 68 $this->assertIdentical($this->dataspace->get('size'), 'medium'); 69 $this->assertIdentical($this->dataspace->get('color'), 'white'); 70 $this->assertNull($this->dataspace->get('smell')); 71 } 72 function testMerge() { 73 $array = array('size' => 'tiny', 'shape' => 'triangle'); 74 $this->dataspace->merge($array); 75 $this->assertIdentical($this->dataspace->get('size'), 'tiny'); 76 $this->assertIdentical($this->dataspace->get('color'), 'purple'); 77 $this->assertIdentical($this->dataspace->get('smell'), 'lilac'); 78 $this->assertIdentical($this->dataspace->get('shape'), 'triangle'); 79 } 80 function testExportEmpty() { 81 $foo = array(); 82 $this->dataspace->import($foo); 83 $this->assertIdentical($this->dataspace->export(), $foo); 84 } 85 function testImportDataSetAsArray() { 86 // This test case depends on the order of elements in the array 87 // remaining the same in the implemenation of the ArrayDataSet. 88 // While this is probably true, there is no such requirement. 89 $dataset = array ( 90 array('x'=>1,'y'=>2), 91 array('x'=>3,'y'=>4), 92 array('x'=>5,'y'=>6), 93 ); 94 95 $row = array('x'=>1,'y'=>2); 96 $this->dataspace->importDataSetAsArray($dataset); 97 $this->dataspace->reset(); 98 $this->dataspace->next(); 99 $this->assertIdentical($row, $this->dataspace->export()); 100 $this->assertIdentical($dataset, $this->dataspace->getDataSet()); 101 } 102 function testIsEmpty() { 103 $this->assertFalse($this->dataspace->isEmpty()); 104 } 105 function testExport() { 106 $this->dataspace->import(array()); 107 $this->dataspace->set('foo','bar'); 108 $expected = array('foo'=>'bar'); 109 $this->assertIdentical($this->dataspace->export(), $expected); 110 } 111 112 } 113 114 class ArrayDataSetIterationTestCase extends UnitTestCase { 115 function ArrayDataSetIterationTestCase($name = 'ArrayDataSetIterationTestCase') { 116 $this->UnitTestCase($name); 117 } 118 function setUp() { 119 $array = array( 120 array('size' => 'small', 'color' => 'purple', 'smell' => 'lilac'), 121 array('size' => 'large', 'color' => 'red', 'smell' => 'lavender') 122 ); 123 $this->dataspace = new ArrayDataSet($array); 124 $this->dataspace->reset(); 125 } 126 function tearDown() { 127 unset ( $this->dataspace ); 128 } 129 function testListDataSetIteration() { 130 $out_array = array(); 131 while ($this->dataspace->next()) { 132 $out_array[] = $this->dataspace->get('size'); 133 } 134 $test_array=array('small', 'large'); 135 $this->assertIdentical($test_array, $out_array); 136 } 137 function testNextCount() { 138 $count = 0; 139 while ( $this->dataspace->next() ) { 140 $count++; 141 } 142 $this->assertEqual(2, $count); 143 } 144 function testFilter() { 145 $filter =& new MockFilter($this); 146 $filter->expectArgumentsAt(0, 'doFilter', 147 array(array('size' => 'small', 'color' => 'purple', 'smell' => 'lilac'))); 148 $filter->expectArgumentsAt(1, 'doFilter', 149 array(array('size' => 'large', 'color' => 'red', 'smell' => 'lavender'))); 150 $filter->expectCallCount('doFilter', 2); 151 $this->dataspace->registerFilter($filter); 152 while ($this->dataspace->next()) { 153 } 154 $filter->tally(); 155 } 156 function testFilterDoesntChangeValues() { 157 $this->dataspace->registerFilter(new ADSTestFilter()); 158 while ($this->dataspace->next()) { 159 $out_array1[] = $this->dataspace->get('color'); 160 } 161 $this->dataspace->reset(); 162 while ($this->dataspace->next()) { 163 $out_array2[] = $this->dataspace->get('color'); 164 } 165 $this->dataspace->reset(); 166 while ($this->dataspace->next()) { 167 $out_array3[] = $this->dataspace->get('color'); 168 } 169 $this->assertIdentical($out_array1, $out_array2); 170 $this->assertIdentical($out_array2, $out_array3); 171 } 172 //} 173 174 } 175 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Nov 28 19:36:09 2004 | Cross-referenced by PHPXref 0.5 |