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

/tests/units/classes/template/data.php

http://github.com/mageekguy/atoum
PHP | 231 lines | 209 code | 22 blank | 0 comment | 0 complexity | 7e8995b8353971d493ee0c67fe5af2d7 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 data extends atoum\test
  9. {
  10. public function test__construct()
  11. {
  12. $this
  13. ->if($data = new template\data())
  14. ->then
  15. ->string($data->getData())->isEmpty()
  16. ->variable($data->getTag())->isNull()
  17. ->variable($data->getId())->isNull()
  18. ->array($data->getChildren())->isEmpty()
  19. ->if($data = new template\data($string = uniqid()))
  20. ->then
  21. ->string($data->getData())->isEqualTo($string)
  22. ->variable($data->getTag())->isNull()
  23. ->variable($data->getId())->isNull()
  24. ->array($data->getChildren())->isEmpty()
  25. ;
  26. }
  27. public function test__toString()
  28. {
  29. $this
  30. ->if($data = new template\data())
  31. ->then
  32. ->castToString($data)->isEmpty()
  33. ->if($data = new template\data($string = uniqid()))
  34. ->then
  35. ->castToString($data)->isEqualTo($string)
  36. ;
  37. }
  38. public function testGetData()
  39. {
  40. $this
  41. ->if($data = new template\data())
  42. ->then
  43. ->string($data->getData())->isEmpty()
  44. ->if($data = new template\data($string = uniqid()))
  45. ->then
  46. ->string($data->getData())->isEqualTo($string)
  47. ;
  48. }
  49. public function testSetData()
  50. {
  51. $this
  52. ->if($data = new template\data())
  53. ->then
  54. ->object($data->setData($string = uniqid()))->isIdenticalTo($data)
  55. ->string($data->getData())->isEqualTo($string)
  56. ;
  57. }
  58. public function testAddData()
  59. {
  60. $this
  61. ->if($string = uniqid())
  62. ->and($data = new template\data())
  63. ->then
  64. ->object($data->addData($string = uniqid()))->isIdenticalTo($data)
  65. ->string($data->getData())->isEqualTo($string)
  66. ->object($data->addData($string))->isIdenticalTo($data)
  67. ->string($data->getData())->isEqualTo($string . $string)
  68. ->object($data->addData($otherString = uniqid()))->isIdenticalTo($data)
  69. ->string($data->getData())->isEqualTo($string . $string . $otherString)
  70. ;
  71. }
  72. public function testSetParent()
  73. {
  74. $this
  75. ->if($data = new template\data())
  76. ->then
  77. ->object($data->setParent($tag = new template\tag(uniqid())))->isIdenticalTo($data)
  78. ->object($data->getParent())->isIdenticalTo($tag)
  79. ->object($tag->getChild(0))->isIdenticalTo($data)
  80. ;
  81. }
  82. public function testGetParent()
  83. {
  84. $this
  85. ->if($data = new template\data())
  86. ->then
  87. ->variable($data->getParent())->isNull()
  88. ->if($data->setParent($tag = new template\tag(uniqid())))
  89. ->then
  90. ->object($data->getParent())->isIdenticalTo($tag)
  91. ;
  92. }
  93. public function testParentIsSet()
  94. {
  95. $this
  96. ->if($data = new template\data())
  97. ->then
  98. ->boolean($data->parentIsSet())->isFalse()
  99. ->if($data->setParent($tag = new template\tag(uniqid())))
  100. ->then
  101. ->boolean($data->parentIsSet())->isTrue()
  102. ;
  103. }
  104. public function testUnsetParent()
  105. {
  106. $this
  107. ->if($data = new template\data())
  108. ->then
  109. ->object($data->unsetParent())->isIdenticalTo($data)
  110. ->boolean($data->parentIsSet())->isFalse()
  111. ->if($data->setParent($tag = new template\tag(uniqid())))
  112. ->then
  113. ->object($data->unsetParent())->isIdenticalTo($data)
  114. ->boolean($data->parentIsSet())->isFalse()
  115. ;
  116. }
  117. public function testHasChildren()
  118. {
  119. $this
  120. ->if($data = new template\data())
  121. ->then
  122. ->boolean($data->hasChildren())->isFalse()
  123. ;
  124. }
  125. public function testGetChildren()
  126. {
  127. $this
  128. ->if($data = new template\data())
  129. ->then
  130. ->array($data->getChildren())->isEmpty()
  131. ;
  132. }
  133. public function testGetChild()
  134. {
  135. $this
  136. ->if($data = new template\data())
  137. ->then
  138. ->variable($data->getChild(0))->isNull()
  139. ->variable($data->getChild(rand(1, PHP_INT_MAX)))->isNull()
  140. ;
  141. }
  142. public function testGetById()
  143. {
  144. $this
  145. ->if($data = new template\data())
  146. ->then
  147. ->variable($data->getById(uniqid()))->isNull()
  148. ;
  149. }
  150. public function testGetByTag()
  151. {
  152. $this
  153. ->if($data = new template\data())
  154. ->then
  155. ->array($data->getByTag(uniqid()))->isEmpty()
  156. ;
  157. }
  158. public function testGetId()
  159. {
  160. $this
  161. ->if($data = new template\data())
  162. ->then
  163. ->variable($data->getId())->isNull()
  164. ;
  165. }
  166. public function testGetTag()
  167. {
  168. $this
  169. ->if($data = new template\data())
  170. ->then
  171. ->variable($data->getTag())->isNull()
  172. ;
  173. }
  174. public function testResetData()
  175. {
  176. $this
  177. ->if($data = new template\data())
  178. ->then
  179. ->object($data->resetData())->isIdenticalTo($data)
  180. ->string($data->getData())->isEmpty()
  181. ->if($data = new template\data($string = uniqid()))
  182. ->then
  183. ->object($data->resetData())->isIdenticalTo($data)
  184. ->string($data->getData())->isEmpty()
  185. ;
  186. }
  187. public function testIsRoot()
  188. {
  189. $this
  190. ->if($data = new template\data())
  191. ->then
  192. ->boolean($data->isRoot())->isTrue()
  193. ->if($data->setParent(new template\tag(uniqid())))
  194. ->then
  195. ->boolean($data->isRoot())->isFalse()
  196. ;
  197. }
  198. public function testBuild()
  199. {
  200. $this
  201. ->if($data = new template\data())
  202. ->then
  203. ->object($data->build())->isIdenticalTo($data)
  204. ->if($data = new template\data(uniqid()))
  205. ->then
  206. ->object($data->build())->isIdenticalTo($data)
  207. ;
  208. }
  209. }