PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/units/classes/template/iterator.php

http://github.com/mageekguy/atoum
PHP | 214 lines | 199 code | 15 blank | 0 comment | 0 complexity | 4969c79ab54e390bba5210bf5a5815f3 MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\template;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\template
  6. ;
  7. require_once __DIR__ . '/../../runner.php';
  8. class iterator extends atoum\test
  9. {
  10. public function testClass()
  11. {
  12. $this
  13. ->testedClass
  14. ->hasInterface('Countable')
  15. ->hasInterface('Iterator')
  16. ;
  17. }
  18. public function test__get()
  19. {
  20. $this
  21. ->if($iterator = new template\iterator())
  22. ->then
  23. ->object($innerIterator = $iterator->{uniqid()})->isInstanceOf('mageekguy\atoum\template\iterator')
  24. ->sizeOf($innerIterator)->isZero()
  25. ->if($template = new atoum\template())
  26. ->and($template->addChild($tag = new template\tag(uniqid())))
  27. ->and($iterator->addTag($tag->getTag(), $template))
  28. ->and($tag->addChild($childTag = new template\tag($tag->getTag())))
  29. ->then
  30. ->object($innerIterator = $iterator->{uniqid()})->isInstanceOf('mageekguy\atoum\template\iterator')
  31. ->sizeOf($innerIterator)->isZero()
  32. ->object($innerIterator = $iterator->{$childTag->getTag()})->isInstanceOf('mageekguy\atoum\template\iterator')
  33. ->sizeOf($innerIterator)->isEqualTo(1)
  34. ->if($childTag->addChild($littleChildTag = new template\tag(uniqid())))
  35. ->then
  36. ->object($innerIterator = $iterator->{uniqid()})->isInstanceOf('mageekguy\atoum\template\iterator')
  37. ->sizeOf($innerIterator)->isZero()
  38. ->object($innerIterator = $iterator->{$childTag->getTag()})->isInstanceOf('mageekguy\atoum\template\iterator')
  39. ->sizeOf($innerIterator)->isEqualTo(1)
  40. ->object($innerIterator = $iterator->{$childTag->getTag()}->{$littleChildTag->getTag()})->isInstanceOf('mageekguy\atoum\template\iterator')
  41. ->sizeOf($innerIterator)->isEqualTo(1)
  42. ;
  43. }
  44. public function test__set()
  45. {
  46. $this
  47. ->if($iterator = new template\iterator())
  48. ->and($template = new atoum\template())
  49. ->and($template->addChild($tag = new template\tag(uniqid())))
  50. ->and($tag->addChild($childTag = new template\tag(uniqid())))
  51. ->and($iterator->addTag($tag->getTag(), $template))
  52. ->and($iterator->{$childTag->getTag()} = $data = uniqid())
  53. ->then
  54. ->string($childTag->getData())->isEqualTo($data)
  55. ->object($iterator->__set($childTag->getTag(), $data = uniqid()))->isIdenticalTo($iterator)
  56. ->string($childTag->getData())->isEqualTo($data)
  57. ;
  58. }
  59. public function test__unset()
  60. {
  61. $this
  62. ->if($iterator = new template\iterator())
  63. ->and($template = new atoum\template())
  64. ->and($template->addChild($tag = new template\tag(uniqid())))
  65. ->and($tag->addChild($childTag = new template\tag(uniqid())))
  66. ->and($iterator->addTag($tag->getTag(), $template))
  67. ->and($iterator->{$childTag->getTag()} = $data = uniqid())
  68. ->then
  69. ->string($childTag->getData())->isNotEmpty()
  70. ;
  71. unset($iterator->{$childTag->getTag()});
  72. $this
  73. ->string($childTag->getData())->isEmpty()
  74. ->if($iterator->{$childTag->getTag()} = uniqid())
  75. ->then
  76. ->string($childTag->getData())->isNotEmpty()
  77. ->object($iterator->__unset($childTag->getTag()))->isIdenticalTo($iterator)
  78. ->string($childTag->getData())->isEmpty()
  79. ;
  80. }
  81. public function test__call()
  82. {
  83. $this
  84. ->if($iterator = new template\iterator())
  85. ->and($template = new atoum\template())
  86. ->and($template->addChild($tag = new \mock\mageekguy\atoum\template\tag(uniqid())))
  87. ->and($tag->getMockController()->build = function() {})
  88. ->and($iterator->addTag($tag->getTag(), $template))
  89. ->then
  90. ->object($iterator->build())->isIdenticalTo($iterator)
  91. ->mock($tag)->call('build')->withArguments(array())->once()
  92. ->object($iterator->build($tags = array(uniqid() => uniqid())))->isIdenticalTo($iterator)
  93. ->mock($tag)->call('build')->withArguments($tags)->once()
  94. ;
  95. }
  96. public function testAddTemplate()
  97. {
  98. $this
  99. ->if($iterator = new template\iterator())
  100. ->and($template = new atoum\template())
  101. ->then
  102. ->object($iterator->addTag(uniqid(), $template))->isIdenticalTo($iterator)
  103. ->sizeOf($iterator)->isZero()
  104. ->if($template->addChild($tag = new template\tag(uniqid())))
  105. ->then
  106. ->object($iterator->addTag(uniqid(), $template))->isIdenticalTo($iterator)
  107. ->sizeOf($iterator)->isZero()
  108. ->object($iterator->addTag($tag->getTag(), $template))->isIdenticalTo($iterator)
  109. ->sizeOf($iterator)->isEqualTo(1)
  110. ->if($tag->addChild($childTag = new template\tag($tag->getTag())))
  111. ->and($iterator = new template\iterator())
  112. ->then
  113. ->object($iterator->addTag(uniqid(), $template))->isIdenticalTo($iterator)
  114. ->sizeOf($iterator)->isZero()
  115. ->object($iterator->addTag($tag->getTag(), $template))->isIdenticalTo($iterator)
  116. ->sizeOf($iterator)->isEqualTo(2)
  117. ;
  118. }
  119. public function testValid()
  120. {
  121. $this
  122. ->if($iterator = new template\iterator())
  123. ->then
  124. ->boolean($iterator->valid())->isFalse()
  125. ->if($template = new atoum\template())
  126. ->and($template->addChild($tag = new template\tag(uniqid())))
  127. ->and($iterator->addTag($tag->getTag(), $template))
  128. ->then
  129. ->boolean($iterator->valid())->isTrue()
  130. ->if($iterator->next())
  131. ->then
  132. ->boolean($iterator->valid())->isFalse()
  133. ;
  134. }
  135. public function testRewind()
  136. {
  137. $this
  138. ->if($iterator = new template\iterator())
  139. ->then
  140. ->object($iterator->rewind())->isIdenticalTo($iterator)
  141. ->if($template = new atoum\template())
  142. ->and($template->addChild($tag = new template\tag(uniqid())))
  143. ->and($template->addChild(new template\tag($tag->getTag())))
  144. ->and($iterator->addTag($tag->getTag(), $template))
  145. ->and($iterator->next())
  146. ->then
  147. ->boolean($iterator->valid())->isTrue()
  148. ->integer($iterator->key())->isEqualTo(1)
  149. ->object($iterator->rewind())->isIdenticalTo($iterator)
  150. ->boolean($iterator->valid())->isTrue()
  151. ->integer($iterator->key())->isZero()
  152. ->if($iterator->next()->next())
  153. ->then
  154. ->boolean($iterator->valid())->isFalse()
  155. ->variable($iterator->key())->isNull()
  156. ->object($iterator->rewind())->isIdenticalTo($iterator)
  157. ->boolean($iterator->valid())->isTrue()
  158. ->integer($iterator->key())->isZero()
  159. ;
  160. }
  161. public function testKey()
  162. {
  163. $this
  164. ->if($iterator = new template\iterator())
  165. ->then
  166. ->boolean($iterator->valid())->isFalse()
  167. ->variable($iterator->key())->isNull()
  168. ->if($template = new atoum\template())
  169. ->and($template->addChild($tag = new template\tag(uniqid())))
  170. ->and($iterator->addTag($tag->getTag(), $template))
  171. ->then
  172. ->boolean($iterator->valid())->isTrue()
  173. ->integer($iterator->key())->isZero()
  174. ->if($iterator->next())
  175. ->then
  176. ->boolean($iterator->valid())->isFalse()
  177. ->variable($iterator->key())->isNull()
  178. ;
  179. }
  180. public function testCurrent()
  181. {
  182. $this
  183. ->if($iterator = new template\iterator())
  184. ->then
  185. ->boolean($iterator->valid())->isFalse()
  186. ->variable($iterator->current())->isNull()
  187. ->if($template = new atoum\template())
  188. ->and($template->addChild($tag = new template\tag(uniqid())))
  189. ->and($iterator->addTag($tag->getTag(), $template))
  190. ->then
  191. ->boolean($iterator->valid())->isTrue()
  192. ->object($iterator->current())->isIdenticalTo($tag)
  193. ->if($iterator->next())
  194. ->then
  195. ->boolean($iterator->valid())->isFalse()
  196. ->variable($iterator->current())->isNull()
  197. ;
  198. }
  199. }