| [ Index ] |
PHP Cross Reference of Web Application Component Toolkit |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package WACT_TESTS 4 * @version $Id: compilercomponent.test.php,v 1.15 2004/11/12 21:25:14 jeffmoore Exp $ 5 */ 6 require_once WACT_ROOT . 'common.inc.php'; 7 require_once WACT_ROOT . 'template/template.inc.php'; 8 require_once WACT_ROOT . 'template/compiler/templatecompiler.inc.php'; 9 10 /** 11 * @package WACT_TESTS 12 */ 13 if ( !class_exists('NullWrappingComponent') ) { 14 class NullWrappingComponent { 15 function generateWrapperPrefix(){} 16 function generateWrapperPostfix(){} 17 } 18 } 19 20 /** 21 * Generate Mocks 22 */ 23 Mock::Generate('CompilerComponent', 'MockCompilerComponent'); 24 Mock::Generate('DataSpace', 'MockDataSpace'); 25 Mock::Generate('CodeWriter', 'MockCodeWriter'); 26 Mock::Generate('NullWrappingComponent', 'MockNullWrappingComponent'); 27 /** 28 * @package WACT_TESTS 29 */ 30 if ( !class_exists('CompilerComponentTestCase')) { 31 class CompilerComponentTestCase extends UnitTestCase { 32 function CompilerComponentTestCase($name = 'CompilerComponent test cases') { 33 $this->UnitTestCase($name); 34 } 35 function setUp() { 36 $this->component = & new CompilerComponent(); 37 } 38 function tearDown() { 39 unset ( $this->component ); 40 } 41 function testGetClientId() { 42 $this->component->setAttribute('id', 'TestId'); 43 $this->assertEqual($this->component->getClientId(), 'TestId'); 44 } 45 function testGetClientIdUnset() { 46 $this->assertNull($this->component->getClientId()); 47 } 48 function testGetServerId() { 49 $this->component->setAttribute('id', 'TestId'); 50 $this->assertEqual($this->component->getServerId(), 'TestId'); 51 } 52 function testGetServerIdAttribute() { 53 $this->component->ServerId = 'Test'; 54 $this->assertEqual($this->component->getServerId(), 'Test'); 55 } 56 function testGetServerIdGenerated() { 57 $id = $this->component->getServerId(); 58 $this->assertEqual($this->component->getServerId(), $id); 59 } 60 function testFindChild() { 61 $mock = & new MockCompilerComponent($this); 62 $mock->setReturnValue('getServerId', 'Test'); 63 $this->component->addChild($mock); 64 $this->assertIsA($this->component->findChild('Test'), 'MockCompilerComponent'); 65 } 66 function testFindChildNotFound() { 67 $this->assertFalse($this->component->findChild('Test')); 68 } 69 function testFindChildByClass() { 70 $mock = & new MockCompilerComponent($this); 71 $this->component->addChild($mock); 72 $this->assertIsA($this->component->findChildByClass('MockCompilerComponent'), 'MockCompilerComponent'); 73 } 74 function testFindChildByClassNotFound() { 75 $this->assertFalse($this->component->findChildByClass('MockCompilerComponent')); 76 } 77 function testFindParentByChilld() { 78 $parent = & new CompilerComponent(); 79 $parent->addChild($this->component); 80 $this->assertIsA($this->component->findParentByClass('CompilerComponent'), 'CompilerComponent'); 81 } 82 function testFindParentByClassNotFound() { 83 $this->assertFalse($this->component->findParentByClass('Test')); 84 } 85 function testRemoveChild() { 86 $mock = & new MockCompilerComponent($this); 87 $mock->setReturnValue('getServerId', 'Test'); 88 $this->component->addChild($mock); 89 $this->assertIsA($this->component->removeChild('Test'), 'MockCompilerComponent'); 90 } 91 function testPrepare() { 92 $child = &new MockCompilerComponent($this); 93 $this->component->addChild($child); 94 $child->expectCallCount('prepare', 1); 95 $this->component->prepare(); 96 $child->tally(); 97 } 98 function testPreParse() { 99 $this->assertEqual($this->component->preParse(), PARSER_REQUIRE_PARSING); 100 } 101 function testGetDataSource() { 102 $parent = &new MockCompilerComponent($this); 103 $mockds = & new MockDataSpace($this); 104 $parent->setReturnValue('getDataSource', $mockds); 105 $this->component->parent = & $parent; 106 $this->assertIsA($this->component->getDataSource(), 'MockDataSpace'); 107 } 108 function testGetParentDataSource() { 109 $parent = &new MockCompilerComponent($this); 110 $mockds = & new MockDataSpace($this); 111 $testparent = & new MockCompilerComponent($this); 112 $testparent->expectCallCount('getDataSource', 1); 113 $mockds->parent = & $testparent; 114 $parent->setReturnValue('getDataSource', $mockds); 115 $this->component->parent = & $parent; 116 } 117 function testGetRootDataSource() { 118 $parent =&new MockCompilerComponent($this); 119 $parent->parent = NULL; 120 $this->component->parent = $parent; 121 $this->assertIsA($this->component->getRootDataSource(), 'MockCompilerComponent'); 122 } 123 function testgetDataSourceRefCode() { 124 $parent = &new MockCompilerComponent($this); 125 $parent->setReturnValue('getDataSourceRefCode', 'Test'); 126 $this->component->parent = & $parent; 127 $this->assertEqual($this->component->getDataSourceRefCode(), 'Test'); 128 } 129 function testGenerateConstructor() { 130 $code = & new MockCodeWriter($this); 131 $child = & new MockCompilerComponent($this); 132 $child->expectCallCount('generateConstructor', 1); 133 $this->component->addChild($child); 134 $this->component->generateConstructor($code); 135 $child->tally(); 136 } 137 function testGenerateContents() { 138 $code = & new MockCodeWriter($this); 139 $child = & new MockCompilerComponent($this); 140 $child->expectCallCount('generate', 1); 141 $this->component->addChild($child); 142 $this->component->generateContents($code); 143 $child->tally(); 144 } 145 function testPreGenerate() { 146 $code = & new MockCodeWriter($this); 147 $wrapper = & new MockNullWrappingComponent($this); 148 $wrapper->expectCallCount('generateWrapperPrefix', 1); 149 $this->component->registerWrapper($wrapper); 150 $this->component->preGenerate($code); 151 $wrapper->tally(); 152 } 153 function testPostGenerate() { 154 $code = & new MockCodeWriter($this); 155 $wrapper = & new MockNullWrappingComponent($this); 156 $wrapper->expectCallCount('generateWrapperPostfix', 1); 157 $this->component->registerWrapper($wrapper); 158 $this->component->postGenerate($code); 159 $wrapper->tally(); 160 } 161 function testGenerate(){ 162 $code = & new MockCodeWriter($this); 163 $child = & new MockCompilerComponent($this); 164 $child->expectCallCount('generate', 1); 165 $this->component->addChild($child); 166 $wrapper = & new MockNullWrappingComponent($this); 167 $wrapper->expectCallCount('generateWrapperPrefix', 1); 168 $wrapper->expectCallCount('generateWrapperPostfix', 1); 169 $this->component->registerWrapper($wrapper); 170 $this->component->generate($code); 171 $child->tally(); 172 } 173 function testGetAttribute() { 174 $this->component->setAttribute('foo', 'bar'); 175 $this->assertEqual($this->component->getAttribute('foo'), 'bar'); 176 $this->assertEqual($this->component->getAttribute('FOO'), 'bar'); 177 } 178 function testGetAttributeUnset() { 179 $this->assertNull($this->component->getAttribute('foo')); 180 } 181 function testHasAttribute() { 182 $this->component->setAttribute('foo', 'bar'); 183 $this->component->setAttribute('tricky', NULL); 184 $this->assertTrue( $this->component->hasAttribute('foo')); 185 $this->assertTrue( $this->component->hasAttribute('tricky')); 186 $this->assertFalse( $this->component->hasAttribute('missing')); 187 $this->assertTrue( $this->component->hasAttribute('FOO')); 188 $this->assertTrue( $this->component->hasAttribute('TRICKY')); 189 $this->assertFalse( $this->component->hasAttribute('MISSING')); 190 } 191 function testDuplicateAttribute() { 192 // Once set, attributes at compile time are immutable. 193 $this->component->setAttribute('SAME', 'value 1'); 194 $this->component->setAttribute('same', 'value 2'); 195 $this->assertError(); 196 $this->swallowErrors(); 197 } 198 function testRemoveAttribute() { 199 $this->component->setAttribute('foo', 'bar'); 200 $this->component->setAttribute('untouched', 'value'); 201 $this->assertTrue( $this->component->hasAttribute('foo')); 202 $this->component->removeAttribute('FOO'); 203 $this->assertFalse( $this->component->hasAttribute('foo')); 204 } 205 function testBooleanAttribute() { 206 //true cases 207 $this->component->setAttribute('A', NULL); 208 $this->component->setAttribute('B', 'True'); 209 $this->component->setAttribute('C', 'Something'); 210 //false cases 211 $this->component->setAttribute('D', 'False'); 212 $this->component->setAttribute('F', 'n'); 213 $this->component->setAttribute('G', 'No'); 214 $this->component->setAttribute('H', 'none'); 215 $this->component->setAttribute('I', '0'); 216 //assertions 217 $this->assertTrue( $this->component->getBoolAttribute('A')); 218 $this->assertTrue( $this->component->getBoolAttribute('B')); 219 $this->assertTrue( $this->component->getBoolAttribute('C')); 220 $this->assertFalse( $this->component->getBoolAttribute('D')); 221 $this->assertFalse( $this->component->getBoolAttribute('E')); 222 $this->assertFalse( $this->component->getBoolAttribute('F')); 223 $this->assertFalse( $this->component->getBoolAttribute('G')); 224 $this->assertFalse( $this->component->getBoolAttribute('H')); 225 $this->assertFalse( $this->component->getBoolAttribute('I')); 226 } 227 function testAddChildAttribute() { 228 $attrib =& new AttributeNode('Foo', 'bar'); 229 $this->component->addChildAttribute($attrib); 230 $this->assertEqual($this->component->getAttribute('FOO'), 'bar'); 231 } 232 function testGetAttributesAsArray() { 233 $this->component->setAttribute('foo', 'bar'); 234 $this->component->setAttribute('tricky', NULL); 235 $this->assertIdentical( 236 $this->component->getAttributesAsArray(array('tricky')), 237 array('foo' => 'bar')); 238 } 239 } 240 } 241 ?>
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 |