[ Index ]

PHP Cross Reference of Web Application Component Toolkit

title

Body

[close]

/tests/cases/template/compiler/ -> attributenode.test.php (source)

   1  <?php
   2  /**
   3  * @package WACT_TESTS
   4  * @version $Id: attributenode.test.php,v 1.6 2004/07/21 09:12:15 harryf Exp $
   5  */
   6  /**
   7  * Includes
   8  */
   9  require_once WACT_ROOT . 'template/compiler/templatecompiler.inc.php';
  10  
  11  Mock::Generate('CodeWriter', 'MockCodeWriter');
  12  Mock::Generate('CompilerComponent', 'MockCompilerComponent');
  13  Mock::Generate('Expression', 'MockExpression');
  14  Mock::Generate('AttributeExpression', 'MockAttributeExpression');
  15  Mock::Generate('AttributeNode', 'MockAttributeNode');
  16  
  17  Mock::generatePartial(
  18          'AttributeExpression',
  19          'AttributeExpressionPartialMock',
  20          array('createExpression'));
  21  
  22  /**
  23  * @package WACT_TESTS
  24  */
  25  class AttributeNodeTestCase extends UnitTestCase {
  26  	function AttributeNodeTestCase($name = 'AttributeNode test cases') {
  27          parent::UnitTestCase($name);
  28      }
  29  	function setUp() {
  30          $this->attribute = & new AttributeNode('test', 'value');
  31      }
  32  	function tearDown() {
  33          unset ( $this->attribute );
  34          parent::tearDown();
  35      }
  36      
  37  	function testIsConstant() {
  38          $this->assertTrue($this->attribute->isConstant());
  39      }
  40      
  41  	function testGetValue() {
  42          $this->assertEqual($this->attribute->getValue(), 'value');
  43      }
  44  
  45  	function testGetValueNull() {
  46          $Attribute = & new AttributeNode('test', NULL);
  47          $this->assertIdentical($Attribute->getValue(), NULL);
  48      }
  49      
  50  	function testGenerateFragment() {
  51          // BAD TEST: see bug #896626
  52          $MockCode = & new MockCodeWriter($this);
  53          $MockCode->expectArguments('writeHTML', array('value'));
  54          $this->attribute->generateFragment($MockCode);
  55      }
  56      
  57  	function testGenerate() {
  58          // BAD TEST: see bug #896626
  59          $MockCode = & new MockCodeWriter($this);
  60          $MockCode->expectArgumentsAt(0, 'writeHTML', array(' test'));
  61          $MockCode->expectArgumentsAt(1, 'writeHTML', array('="'));
  62          $MockCode->expectArgumentsAt(2, 'writeHTML', array('value'));
  63          $MockCode->expectArgumentsAt(3, 'writeHTML', array('"'));
  64          $this->attribute->generate($MockCode);
  65      }
  66  
  67  	function testGenerateExpression() {
  68          // BAD TEST: see bug #896626
  69          $MockCode = & new MockCodeWriter($this);
  70          $MockCode->expectArguments('writePHPLiteral', array('value'));
  71          $this->attribute->generatePreStatement($MockCode);
  72          $this->attribute->generateExpression($MockCode);
  73          $this->attribute->generatePostStatement($MockCode);
  74      }
  75  
  76  }
  77  
  78  
  79  class AttributeExpressionTestCase extends UnitTestCase {
  80  	function AttributeExpressionTestCase($name = 'AttributeExpression test cases') {
  81          parent::UnitTestCase($name);
  82      }
  83  	function setUp() {
  84  
  85          $this->expression =& new MockExpression($this);
  86  
  87          $this->attribute = &new AttributeExpressionPartialMock($this);
  88          $this->attribute->setReturnReference('createExpression', $this->expression);
  89          $this->attribute->expectOnce('createExpression');
  90          $this->attribute->AttributeExpression('test', 'hello', new MockCompilerComponent($this));
  91      }
  92  	function tearDown() {
  93          unset ( $this->attribute );
  94          parent::tearDown();
  95      }
  96      
  97  	function testIsConstant() {
  98          $this->expression->setReturnValue('IsConstant', TRUE);
  99          $this->expression->expectOnce('IsConstant');
 100          $this->assertTrue($this->attribute->isConstant());
 101      }
 102  
 103  	function testGetValue() {
 104          $this->expression->setReturnValue('getValue', 'hello');
 105          $this->expression->expectOnce('getValue');
 106          $this->assertEqual($this->attribute->getValue(), 'hello');
 107      }
 108  
 109  
 110  	function testGenerateConstantFragment() {
 111          $this->expression->setReturnValue('IsConstant', TRUE);
 112          $this->expression->expectOnce('IsConstant');
 113          $this->expression->setReturnValue('getValue', 'hello');
 114          $this->expression->expectOnce('getValue');
 115  
 116          $MockCode = & new MockCodeWriter($this);
 117          $MockCode->expectArguments('writeHTML', array('hello'));
 118          $this->attribute->generateFragment($MockCode);
 119      }
 120  
 121  	function testGenerateFragment() {
 122          $this->expression->setReturnValue('IsConstant', FALSE);
 123          $this->expression->expectOnce('IsConstant');
 124          $this->expression->setReturnValue('getValue', 'hello');
 125          $this->expression->expectOnce('generatePreStatement');
 126          $this->expression->expectOnce('generateExpression');
 127          $this->expression->expectOnce('generatePostStatement');
 128  
 129          $MockCode = & new MockCodeWriter($this);
 130          $MockCode->expectArgumentsAt(0, 'writePHP', array('echo htmlspecialchars('));
 131          $MockCode->expectArgumentsAt(1, 'writePHP', array(', ENT_QUOTES);'));
 132          $this->attribute->generateFragment($MockCode);
 133      }
 134  
 135  	function testGenerate() {
 136          $this->expression->setReturnValue('IsConstant', FALSE);
 137          $this->expression->expectOnce('IsConstant');
 138          $this->expression->setReturnValue('getValue', 'hello');
 139          $this->expression->expectOnce('generatePreStatement');
 140          $this->expression->expectOnce('generateExpression');
 141          $this->expression->expectOnce('generatePostStatement');
 142  
 143          $MockCode = & new MockCodeWriter($this);
 144          $MockCode->expectArgumentsAt(0, 'writeHTML', array(' test'));
 145          $MockCode->expectArgumentsAt(1, 'writeHTML', array('="'));
 146          $MockCode->expectArgumentsAt(2, 'writeHTML', array('"'));
 147          $MockCode->expectArgumentsAt(0, 'writePHP', array('echo htmlspecialchars('));
 148          $MockCode->expectArgumentsAt(1, 'writePHP', array(', ENT_QUOTES);'));
 149          $this->attribute->generate($MockCode);
 150      }
 151  
 152  	function testGenerateExpression() {
 153  
 154          $MockCode = & new MockCodeWriter($this);
 155          $MockCode->expectArguments('writePHPLiteral', array('value'));
 156          $this->attribute->generatePreStatement($MockCode);
 157          $this->attribute->generateExpression($MockCode);
 158          $this->attribute->generatePostStatement($MockCode);
 159      }
 160  
 161  }
 162  
 163  class CompoundAttributeTestCase extends UnitTestCase {
 164  	function CompoundAttributeTestCase($name = 'CompoundAttribute test cases') {
 165          parent::UnitTestCase($name);
 166      }
 167  
 168  	function setUp() {
 169          $this->literal =& new MockAttributeNode($this);
 170          $this->expression =& new MockAttributeExpression($this);
 171          $this->attribute =& new CompoundAttribute('test');
 172          $this->attribute->addAttributeFragment($this->literal);
 173          $this->attribute->addAttributeFragment($this->expression);
 174      }
 175  
 176  	function tearDown() {
 177          $this->literal->tally();
 178          $this->expression->tally();
 179          unset($this->literal);
 180          unset($this->expression);
 181          parent::tearDown();
 182      }
 183  
 184  	function testIsConstantAllTrue() {
 185          $this->literal->setReturnValue('IsConstant', TRUE);
 186          $this->literal->expectOnce('IsConstant');
 187          $this->expression->setReturnValue('IsConstant', TRUE);
 188          $this->expression->expectOnce('IsConstant');
 189          $this->assertTrue($this->attribute->isConstant());
 190      }
 191  
 192  	function testIsConstantAllFalse() {
 193          $this->literal->setReturnValue('IsConstant', FALSE);
 194          $this->literal->expectOnce('IsConstant');
 195          $this->expression->setReturnValue('IsConstant', FALSE);
 196          $this->expression->expectNever('IsConstant');
 197          $this->assertFalse($this->attribute->isConstant());
 198      }
 199  
 200  	function testIsConstantMixed() {
 201          $this->literal->setReturnValue('IsConstant', TRUE);
 202          $this->literal->expectOnce('IsConstant');
 203          $this->expression->setReturnValue('IsConstant', FALSE);
 204          $this->expression->expectOnce('IsConstant');
 205          $this->assertFalse($this->attribute->isConstant());
 206      }
 207  
 208  	function testGetValue() {
 209          $this->literal->setReturnValue('getValue', 'Hur');
 210          $this->literal->expectOnce('getValue');
 211          $this->expression->setReturnValue('getValue', 'rah');
 212          $this->expression->expectOnce('getValue');
 213          $this->assertEqual($this->attribute->getValue(), 'Hurrah');
 214      }
 215  
 216  	function testGenerate() {
 217          $this->literal->expectOnce('generateFragment');
 218          $this->expression->expectOnce('generateFragment');
 219          $MockCode = & new MockCodeWriter($this);
 220          $this->attribute->generate($MockCode);
 221      }
 222  
 223      function testGenerateExpression() {
 224          $this->literal->expectOnce('generatePreStatement');
 225          $this->literal->expectOnce('generateExpression');
 226          $this->literal->expectOnce('generatePostStatement');
 227          $this->expression->expectOnce('generatePreStatement');
 228          $this->expression->expectOnce('generateExpression');
 229          $this->expression->expectOnce('generatePostStatement');
 230          $MockCode = & new MockCodeWriter($this);
 231          $MockCode->expectArgumentsAt(0, 'writePHP', array('('));
 232          $MockCode->expectArgumentsAt(1, 'writePHP', array(''));
 233          $MockCode->expectArgumentsAt(2, 'writePHP', array('.'));
 234          $MockCode->expectArgumentsAt(3, 'writePHP', array(')'));
 235          $this->attribute->generatePreStatement($MockCode);
 236          $this->attribute->generateExpression($MockCode);
 237          $this->attribute->generatePostStatement($MockCode);
 238      }
 239  
 240  	function testPrepare() {
 241          $this->literal->expectOnce('prepare');
 242          $this->expression->expectOnce('prepare');
 243          $MockCode = & new MockCodeWriter($this);
 244          $this->attribute->prepare($MockCode);
 245      }
 246      
 247  }
 248  
 249  ?>


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