NodeTest.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Server
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once 'Zend/Server/Reflection/Node.php';
  23. require_once 'PHPUnit/Framework/TestCase.php';
  24. require_once 'PHPUnit/Framework/IncompleteTestError.php';
  25. /**
  26. * Test case for Zend_Server_Reflection_Node
  27. *
  28. * @category Zend
  29. * @package Zend_Server
  30. * @subpackage UnitTests
  31. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. * @group Zend_Server
  34. */
  35. class Zend_Server_Reflection_NodeTest extends PHPUnit_Framework_TestCase
  36. {
  37. /**
  38. * __construct() test
  39. */
  40. public function test__construct()
  41. {
  42. $node = new Zend_Server_Reflection_Node('string');
  43. $this->assertTrue($node instanceof Zend_Server_Reflection_Node);
  44. $this->assertEquals('string', $node->getValue());
  45. $this->assertTrue(null === $node->getParent());
  46. $children = $node->getChildren();
  47. $this->assertTrue(empty($children));
  48. $child = new Zend_Server_Reflection_Node('array', $node);
  49. $this->assertTrue($child instanceof Zend_Server_Reflection_Node);
  50. $this->assertEquals('array', $child->getValue());
  51. $this->assertTrue($node === $child->getParent());
  52. $children = $child->getChildren();
  53. $this->assertTrue(empty($children));
  54. $children = $node->getChildren();
  55. $this->assertTrue($child === $children[0]);
  56. }
  57. /**
  58. * setParent() test
  59. */
  60. public function testSetParent()
  61. {
  62. $parent = new Zend_Server_Reflection_Node('string');
  63. $child = new Zend_Server_Reflection_Node('array');
  64. $child->setParent($parent);
  65. $this->assertTrue($parent === $child->getParent());
  66. }
  67. /**
  68. * createChild() test
  69. */
  70. public function testCreateChild()
  71. {
  72. $parent = new Zend_Server_Reflection_Node('string');
  73. $child = $parent->createChild('array');
  74. $this->assertTrue($child instanceof Zend_Server_Reflection_Node);
  75. $this->assertTrue($parent === $child->getParent());
  76. $children = $parent->getChildren();
  77. $this->assertTrue($child === $children[0]);
  78. }
  79. /**
  80. * attachChild() test
  81. */
  82. public function testAttachChild()
  83. {
  84. $parent = new Zend_Server_Reflection_Node('string');
  85. $child = new Zend_Server_Reflection_Node('array');
  86. $parent->attachChild($child);
  87. $this->assertTrue($parent === $child->getParent());
  88. $children = $parent->getChildren();
  89. $this->assertTrue($child === $children[0]);
  90. }
  91. /**
  92. * getChildren() test
  93. */
  94. public function testGetChildren()
  95. {
  96. $parent = new Zend_Server_Reflection_Node('string');
  97. $child = $parent->createChild('array');
  98. $children = $parent->getChildren();
  99. $types = array();
  100. foreach ($children as $c) {
  101. $types[] = $c->getValue();
  102. }
  103. $this->assertTrue(is_array($children));
  104. $this->assertEquals(1, count($children), var_export($types, 1));
  105. $this->assertTrue($child === $children[0]);
  106. }
  107. /**
  108. * hasChildren() test
  109. */
  110. public function testHasChildren()
  111. {
  112. $parent = new Zend_Server_Reflection_Node('string');
  113. $this->assertFalse($parent->hasChildren());
  114. $parent->createChild('array');
  115. $this->assertTrue($parent->hasChildren());
  116. }
  117. /**
  118. * getParent() test
  119. */
  120. public function testGetParent()
  121. {
  122. $parent = new Zend_Server_Reflection_Node('string');
  123. $child = $parent->createChild('array');
  124. $this->assertTrue(null === $parent->getParent());
  125. $this->assertTrue($parent === $child->getParent());
  126. }
  127. /**
  128. * getValue() test
  129. */
  130. public function testGetValue()
  131. {
  132. $parent = new Zend_Server_Reflection_Node('string');
  133. $this->assertEquals('string', $parent->getValue());
  134. }
  135. /**
  136. * setValue() test
  137. */
  138. public function testSetValue()
  139. {
  140. $parent = new Zend_Server_Reflection_Node('string');
  141. $this->assertEquals('string', $parent->getValue());
  142. $parent->setValue('array');
  143. $this->assertEquals('array', $parent->getValue());
  144. }
  145. /**
  146. * getEndPoints() test
  147. */
  148. public function testGetEndPoints()
  149. {
  150. $root = new Zend_Server_Reflection_Node('root');
  151. $child1 = $root->createChild('child1');
  152. $child2 = $root->createChild('child2');
  153. $child1grand1 = $child1->createChild(null);
  154. $child1grand2 = $child1->createChild('child1grand2');
  155. $child2grand1 = $child2->createChild('child2grand1');
  156. $child2grand2 = $child2->createChild('child2grand2');
  157. $child2grand2great1 = $child2grand2->createChild(null);
  158. $child2grand2great2 = $child2grand2->createChild('child2grand2great2');
  159. $endPoints = $root->getEndPoints();
  160. $endPointsArray = array();
  161. foreach ($endPoints as $endPoint) {
  162. $endPointsArray[] = $endPoint->getValue();
  163. }
  164. $test = array(
  165. 'child1',
  166. 'child1grand2',
  167. 'child2grand1',
  168. 'child2grand2',
  169. 'child2grand2great2'
  170. );
  171. $this->assertTrue($test === $endPointsArray, 'Test was [' . var_export($test, 1) . ']; endPoints were [' . var_export($endPointsArray, 1) . ']');
  172. }
  173. }