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

/tests/units/classes/template.php

http://github.com/mageekguy/atoum
PHP | 662 lines | 632 code | 30 blank | 0 comment | 0 complexity | 8fc559ca637f3ac783192c4f677e1246 MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units;
  3. use
  4. mageekguy\atoum
  5. ;
  6. require_once __DIR__ . '/../runner.php';
  7. class template extends atoum\test
  8. {
  9. public function test__construct()
  10. {
  11. $this
  12. ->if($this->newTestedInstance)
  13. ->then
  14. ->string($this->testedInstance->getData())->isEmpty()
  15. ->if($this->newTestedInstance($data = uniqid()))
  16. ->then
  17. ->string($this->testedInstance->getData())->isEqualTo($data)
  18. ;
  19. }
  20. public function test__toString()
  21. {
  22. $this
  23. ->if($this->newTestedInstance)
  24. ->then
  25. ->string($this->testedInstance->getData())->isEmpty()
  26. ->boolean($this->testedInstance->hasChildren())->isFalse()
  27. ->variable($this->testedInstance->getId())->isNull()
  28. ->variable($this->testedInstance->getTag())->isNull()
  29. ->if($this->newTestedInstance($data = uniqid()))
  30. ->then
  31. ->string($this->testedInstance->getData())->isEqualTo($data)
  32. ->boolean($this->testedInstance->hasChildren())->isFalse()
  33. ->variable($this->testedInstance->getId())->isNull()
  34. ->variable($this->testedInstance->getTag())->isNull()
  35. ;
  36. }
  37. public function test__get()
  38. {
  39. $this
  40. ->if($this->newTestedInstance)
  41. ->then
  42. ->object($iterator = $this->testedInstance->{uniqid()})->isInstanceOf('mageekguy\atoum\template\iterator')
  43. ->sizeOf($iterator)->isZero()
  44. ->if($this->testedInstance->addChild($childTag = new atoum\template\tag(uniqid())))
  45. ->then
  46. ->object($iterator = $this->testedInstance->{$childTag->getTag()})->isInstanceOf('mageekguy\atoum\template\iterator')
  47. ->sizeOf($iterator)->isEqualTo(1)
  48. ->object($iterator->current())->isIdenticalTo($childTag)
  49. ->if($this->testedInstance->addChild($otherChildTag = new atoum\template\tag($childTag->getTag())))
  50. ->then
  51. ->object($iterator = $this->testedInstance->{$childTag->getTag()})->isInstanceOf('mageekguy\atoum\template\iterator')
  52. ->sizeOf($iterator)->isEqualTo(2)
  53. ->object($iterator->current())->isIdenticalTo($childTag)
  54. ->object($iterator->next()->current())->isIdenticalTo($otherChildTag)
  55. ->if($this->testedInstance->addChild($anotherChildTag = new atoum\template\tag(uniqid())))
  56. ->then
  57. ->object($iterator = $this->testedInstance->{$childTag->getTag()})->isInstanceOf('mageekguy\atoum\template\iterator')
  58. ->sizeOf($iterator)->isEqualTo(2)
  59. ->object($iterator->current())->isIdenticalTo($childTag)
  60. ->object($iterator->next()->current())->isIdenticalTo($otherChildTag)
  61. ->object($iterator = $this->testedInstance->{$anotherChildTag->getTag()})->isInstanceOf('mageekguy\atoum\template\iterator')
  62. ->sizeOf($iterator)->isEqualTo(1)
  63. ->object($iterator->current())->isIdenticalTo($anotherChildTag)
  64. ->if($childTag->addChild($littleChildTag = new atoum\template\tag($childTag->getTag())))
  65. ->then
  66. ->object($iterator = $this->testedInstance->{$childTag->getTag()})->isInstanceOf('mageekguy\atoum\template\iterator')
  67. ->sizeOf($iterator)->isEqualTo(3)
  68. ->object($iterator->current())->isIdenticalTo($childTag)
  69. ->object($iterator->next()->current())->isIdenticalTo($littleChildTag)
  70. ->object($iterator->next()->current())->isIdenticalTo($otherChildTag)
  71. ->object($iterator = $this->testedInstance->{$anotherChildTag->getTag()})->isInstanceOf('mageekguy\atoum\template\iterator')
  72. ->sizeOf($iterator)->isEqualTo(1)
  73. ->object($iterator->current())->isIdenticalTo($anotherChildTag)
  74. ;
  75. }
  76. public function test__set()
  77. {
  78. $this
  79. ->if(
  80. $this->newTestedInstance,
  81. $this->testedInstance
  82. ->addChild($tag = new atoum\template\tag(uniqid()))
  83. ->{$tag->getTag()} = $data = uniqid()
  84. )
  85. ->then
  86. ->string($tag->getData())->isEqualTo($data)
  87. ->if(
  88. $tag->addChild($childTag = new atoum\template\tag($tag->getTag())),
  89. $this->testedInstance->{$tag->getTag()} = $data
  90. )
  91. ->then
  92. ->string($tag->getData())->isEqualTo($data)
  93. ->string($childTag->getData())->isEqualTo($data)
  94. ->if(
  95. $tag->addChild($otherChildTag = new atoum\template\tag(uniqid())),
  96. $this->testedInstance->{$otherChildTag->getTag()} = $otherData = uniqid()
  97. )
  98. ->then
  99. ->string($tag->getData())->isEqualTo($data)
  100. ->string($childTag->getData())->isEqualTo($data)
  101. ->string($otherChildTag->getData())->isEqualTo($otherData)
  102. ;
  103. }
  104. public function test__isset()
  105. {
  106. $this
  107. ->if($this->newTestedInstance)
  108. ->then
  109. ->boolean(isset($this->testedInstance->{uniqid()}))->isFalse()
  110. ->if($this->testedInstance->addChild($childTag = new atoum\template\tag(uniqid())))
  111. ->then
  112. ->boolean(isset($this->testedInstance->{uniqid()}))->isFalse()
  113. ->boolean(isset($this->testedInstance->{$childTag->getTag()}))->isTrue()
  114. ->if($childTag->addChild($otherChildTag = new atoum\template\tag(uniqid())))
  115. ->then
  116. ->boolean(isset($this->testedInstance->{uniqid()}))->isFalse()
  117. ->boolean(isset($this->testedInstance->{$childTag->getTag()}))->isTrue()
  118. ->boolean(isset($this->testedInstance->{$otherChildTag->getTag()}))->isTrue()
  119. ->if($childTag->addChild($littleChildTag = new atoum\template\tag(uniqid())))
  120. ->then
  121. ->boolean(isset($this->testedInstance->{uniqid()}))->isFalse()
  122. ->boolean(isset($this->testedInstance->{$childTag->getTag()}))->isTrue()
  123. ->boolean(isset($this->testedInstance->{$otherChildTag->getTag()}))->isTrue()
  124. ->boolean(isset($this->testedInstance->{$littleChildTag->getTag()}))->isTrue()
  125. ;
  126. }
  127. public function test__unset()
  128. {
  129. $this
  130. ->if(
  131. $template = $this->newTestedInstance,
  132. $this->testedInstance->addChild($childTag = new atoum\template\tag(uniqid()))
  133. )
  134. ->then
  135. ->boolean(isset($this->testedInstance->{$childTag->getTag()}))->isTrue()
  136. ->string($childTag->getData())->isEmpty()
  137. ->when(function() use ($template, $childTag) {
  138. unset($template->{$childTag->getTag()});
  139. }
  140. )
  141. ->then
  142. ->boolean(isset($this->testedInstance->{$childTag->getTag()}))->isTrue()
  143. ->string($childTag->getData())->isEmpty()
  144. ->if($this->testedInstance->{$childTag->getTag()} = uniqid())
  145. ->then
  146. ->boolean(isset($this->testedInstance->{$childTag->getTag()}))->isTrue()
  147. ->string($childTag->getData())->isNotEmpty()
  148. ->when(function() use ($template, $childTag) {
  149. unset($template->{$childTag->getTag()});
  150. }
  151. )
  152. ->then
  153. ->boolean(isset($this->testedInstance->{$childTag->getTag()}))->isTrue()
  154. ->string($childTag->getData())->isEmpty()
  155. ->if($this->testedInstance->addChild($otherChildTag = new atoum\template\tag(uniqid())))
  156. ->then
  157. ->boolean(isset($this->testedInstance->{$childTag->getTag()}))->isTrue()
  158. ->string($childTag->getData())->isEmpty()
  159. ->boolean(isset($this->testedInstance->{$otherChildTag->getTag()}))->isTrue()
  160. ->string($otherChildTag->getData())->isEmpty()
  161. ->when(function() use ($template, $childTag, $otherChildTag) {
  162. unset($template->{$childTag->getTag()});
  163. unset($template->{$otherChildTag->getTag()});
  164. }
  165. )
  166. ->then
  167. ->boolean(isset($this->testedInstance->{$childTag->getTag()}))->isTrue()
  168. ->string($childTag->getData())->isEmpty()
  169. ->boolean(isset($this->testedInstance->{$otherChildTag->getTag()}))->isTrue()
  170. ->string($otherChildTag->getData())->isEmpty()
  171. ->if(
  172. $this->testedInstance->{$childTag->getTag()} = uniqid(),
  173. $this->testedInstance->{$otherChildTag->getTag()} = uniqid()
  174. )
  175. ->then
  176. ->boolean(isset($this->testedInstance->{$childTag->getTag()}))->isTrue()
  177. ->string($childTag->getData())->isNotEmpty()
  178. ->boolean(isset($this->testedInstance->{$otherChildTag->getTag()}))->isTrue()
  179. ->string($otherChildTag->getData())->isNotEmpty()
  180. ->when(function() use ($template, $childTag) {
  181. unset($template->{$childTag->getTag()});
  182. }
  183. )
  184. ->then
  185. ->boolean(isset($this->testedInstance->{$childTag->getTag()}))->isTrue()
  186. ->string($childTag->getData())->isEmpty()
  187. ->boolean(isset($this->testedInstance->{$otherChildTag->getTag()}))->isTrue()
  188. ->string($otherChildTag->getData())->isNotEmpty()
  189. ->when(function() use ($template, $otherChildTag) {
  190. unset($template->{$otherChildTag->getTag()});
  191. }
  192. )
  193. ->then
  194. ->boolean(isset($this->testedInstance->{$childTag->getTag()}))->isTrue()
  195. ->string($childTag->getData())->isEmpty()
  196. ->boolean(isset($this->testedInstance->{$otherChildTag->getTag()}))->isTrue()
  197. ->string($otherChildTag->getData())->isEmpty()
  198. ->if($childTag->addChild($littleChildTag = new atoum\template\tag(uniqid())))
  199. ->then
  200. ->boolean(isset($this->testedInstance->{$childTag->getTag()}))->isTrue()
  201. ->string($childTag->getData())->isEmpty()
  202. ->boolean(isset($this->testedInstance->{$otherChildTag->getTag()}))->isTrue()
  203. ->string($otherChildTag->getData())->isEmpty()
  204. ->boolean(isset($this->testedInstance->{$littleChildTag->getTag()}))->isTrue()
  205. ->string($littleChildTag->getData())->isEmpty()
  206. ->if(
  207. $this->testedInstance->{$childTag->getTag()} = uniqid(),
  208. $this->testedInstance->{$otherChildTag->getTag()} = uniqid(),
  209. $this->testedInstance->{$littleChildTag->getTag()} = uniqid()
  210. )
  211. ->then
  212. ->boolean(isset($this->testedInstance->{$childTag->getTag()}))->isTrue()
  213. ->string($childTag->getData())->isNotEmpty()
  214. ->boolean(isset($this->testedInstance->{$otherChildTag->getTag()}))->isTrue()
  215. ->string($otherChildTag->getData())->isNotEmpty()
  216. ->boolean(isset($this->testedInstance->{$littleChildTag->getTag()}))->isTrue()
  217. ->string($littleChildTag->getData())->isNotEmpty()
  218. ->when(function() use ($template, $childTag) {
  219. unset($template->{$childTag->getTag()});
  220. }
  221. )
  222. ->then
  223. ->boolean(isset($this->testedInstance->{$childTag->getTag()}))->isTrue()
  224. ->string($childTag->getData())->isEmpty()
  225. ->boolean(isset($this->testedInstance->{$otherChildTag->getTag()}))->isTrue()
  226. ->string($otherChildTag->getData())->isNotEmpty()
  227. ->boolean(isset($this->testedInstance->{$littleChildTag->getTag()}))->isTrue()
  228. ->string($littleChildTag->getData())->isNotEmpty()
  229. ->when(function() use ($template, $otherChildTag) {
  230. unset($template->{$otherChildTag->getTag()});
  231. }
  232. )
  233. ->then
  234. ->boolean(isset($this->testedInstance->{$childTag->getTag()}))->isTrue()
  235. ->string($childTag->getData())->isEmpty()
  236. ->boolean(isset($this->testedInstance->{$otherChildTag->getTag()}))->isTrue()
  237. ->string($otherChildTag->getData())->isEmpty()
  238. ->boolean(isset($this->testedInstance->{$littleChildTag->getTag()}))->isTrue()
  239. ->string($littleChildTag->getData())->isNotEmpty()
  240. ->when(function() use ($template, $littleChildTag) {
  241. unset($template->{$littleChildTag->getTag()});
  242. }
  243. )
  244. ->then
  245. ->boolean(isset($this->testedInstance->{$childTag->getTag()}))->isTrue()
  246. ->string($childTag->getData())->isEmpty()
  247. ->boolean(isset($this->testedInstance->{$otherChildTag->getTag()}))->isTrue()
  248. ->string($otherChildTag->getData())->isEmpty()
  249. ->boolean(isset($this->testedInstance->{$littleChildTag->getTag()}))->isTrue()
  250. ->string($littleChildTag->getData())->isEmpty()
  251. ;
  252. }
  253. public function testGetRoot()
  254. {
  255. $this
  256. ->if($this->newTestedInstance)
  257. ->then
  258. ->object($this->testedInstance->getRoot())->isTestedInstance
  259. ->if($this->testedInstance->addChild($childTemplate = new atoum\template()))
  260. ->then
  261. ->object($this->testedInstance->getRoot())->isTestedInstance
  262. ->object($childTemplate->getRoot())->isTestedInstance
  263. ->if($childTemplate->addChild($littleChildTemplate = new atoum\template()))
  264. ->then
  265. ->object($this->testedInstance->getRoot())->isTestedInstance
  266. ->object($childTemplate->getRoot())->isTestedInstance
  267. ->object($littleChildTemplate->getRoot())->isTestedInstance
  268. ;
  269. }
  270. public function testGetParent()
  271. {
  272. $this
  273. ->if($this->newTestedInstance)
  274. ->then
  275. ->variable($this->testedInstance->getParent())->isNull()
  276. ->if($this->testedInstance->addChild($childTemplate = new atoum\template()))
  277. ->then
  278. ->variable($this->testedInstance->getParent())->isNull()
  279. ->object($childTemplate->getParent())->isTestedInstance
  280. ->if($childTemplate->addChild($littleChildTemplate = new atoum\template()))
  281. ->then
  282. ->variable($this->testedInstance->getParent())->isNull()
  283. ->object($childTemplate->getParent())->isTestedInstance
  284. ->object($littleChildTemplate->getParent())->isIdenticalTo($childTemplate)
  285. ;
  286. }
  287. public function testParentIsSet()
  288. {
  289. $this
  290. ->if($this->newTestedInstance)
  291. ->then
  292. ->boolean($this->testedInstance->parentIsSet())->isFalse()
  293. ->if($childTemplate = new atoum\template())
  294. ->then
  295. ->boolean($this->testedInstance->parentIsSet())->isFalse()
  296. ->boolean($childTemplate->parentIsSet())->isFalse()
  297. ->if($this->testedInstance->addChild($childTemplate))
  298. ->then
  299. ->boolean($this->testedInstance->parentIsSet())->isFalse()
  300. ->boolean($childTemplate->parentIsSet())->isTrue()
  301. ->if($littleChildTemplate = new atoum\template())
  302. ->then
  303. ->boolean($this->testedInstance->parentIsSet())->isFalse()
  304. ->boolean($childTemplate->parentIsSet())->isTrue()
  305. ->boolean($littleChildTemplate->parentIsSet())->isFalse()
  306. ->if($childTemplate->addChild($littleChildTemplate))
  307. ->then
  308. ->boolean($this->testedInstance->parentIsSet())->isFalse()
  309. ->boolean($childTemplate->parentIsSet())->isTrue()
  310. ->boolean($littleChildTemplate->parentIsSet())->isTrue()
  311. ;
  312. }
  313. public function testUnsetParent()
  314. {
  315. $this
  316. ->if($this->newTestedInstance)
  317. ->then
  318. ->boolean($this->testedInstance->parentIsSet())->isFalse()
  319. ->object($this->testedInstance->unsetParent())->isTestedInstance
  320. ->boolean($this->testedInstance->parentIsSet())->isFalse()
  321. ->if($this->testedInstance->addChild($childTemplate = new atoum\template()))
  322. ->then
  323. ->boolean($this->testedInstance->parentIsSet())->isFalse()
  324. ->boolean($childTemplate->parentIsSet())->isTrue()
  325. ->object($this->testedInstance->unsetParent())->isTestedInstance
  326. ->object($childTemplate->unsetParent())->isIdenticalTo($childTemplate)
  327. ->boolean($this->testedInstance->parentIsSet())->isFalse()
  328. ->boolean($childTemplate->parentIsSet())->isFalse()
  329. ;
  330. }
  331. public function testSetParent()
  332. {
  333. $this
  334. ->if($this->newTestedInstance)
  335. ->then
  336. ->boolean($this->testedInstance->parentIsSet())->isFalse()
  337. ->object($this->testedInstance->setParent(new atoum\template()))->isTestedInstance
  338. ->boolean($this->testedInstance->parentIsSet())->isTrue()
  339. ;
  340. }
  341. public function testGetData()
  342. {
  343. $this
  344. ->if($this->newTestedInstance)
  345. ->then
  346. ->string($this->testedInstance->getData())->isEmpty()
  347. ->if($this->newTestedInstance($data = uniqid()))
  348. ->then
  349. ->string($this->testedInstance->getData())->isEqualTo($data)
  350. ->if(
  351. $this->newTestedInstance,
  352. $this->testedInstance->setData($data = uniqid())
  353. )
  354. ->then
  355. ->string($this->testedInstance->getData())->isEqualTo($data)
  356. ->if($this->testedInstance->addChild(new atoum\template($otherData = uniqid())))
  357. ->then
  358. ->string($this->testedInstance->getData())->isEqualTo($data)
  359. ->if($this->testedInstance->build())
  360. ->then
  361. ->string($this->testedInstance->getData())->isEqualTo($data . $otherData)
  362. ;
  363. }
  364. public function testSetData()
  365. {
  366. $this
  367. ->if($this->newTestedInstance)
  368. ->then
  369. ->object($this->testedInstance->setData($data = uniqid()))->isTestedInstance
  370. ->string($this->testedInstance->getData())->isEqualTo($data)
  371. ;
  372. }
  373. public function testAddData()
  374. {
  375. $this
  376. ->if($this->newTestedInstance)
  377. ->then
  378. ->object($this->testedInstance->addData($data = uniqid()))->isTestedInstance
  379. ->string($this->testedInstance->getData())->isEqualTo($data)
  380. ->object($this->testedInstance->addData($data))->isTestedInstance
  381. ->string($this->testedInstance->getData())->isEqualTo($data . $data)
  382. ->object($this->testedInstance->addData($otherData = uniqid()))->isTestedInstance
  383. ->string($this->testedInstance->getData())->isEqualTo($data . $data . $otherData)
  384. ;
  385. }
  386. public function testResetData()
  387. {
  388. $this
  389. ->if($this->newTestedInstance)
  390. ->then
  391. ->string($this->testedInstance->getData())->isEmpty()
  392. ->object($this->testedInstance->resetData())->isTestedInstance
  393. ->string($this->testedInstance->getData())->isEmpty()
  394. ->if($this->newTestedInstance($data = uniqid()))
  395. ->then
  396. ->string($this->testedInstance->getData())->isEqualTo($data)
  397. ->object($this->testedInstance->resetData())->isTestedInstance
  398. ->string($this->testedInstance->getData())->isEmpty()
  399. ;
  400. }
  401. public function testGetId()
  402. {
  403. $this
  404. ->if($this->newTestedInstance)
  405. ->then
  406. ->variable($this->testedInstance->getId())->isNull()
  407. ;
  408. }
  409. public function testIsRoot()
  410. {
  411. $this
  412. ->if($this->newTestedInstance)
  413. ->then
  414. ->boolean($this->testedInstance->isRoot())->isTrue()
  415. ;
  416. }
  417. public function testIsChild()
  418. {
  419. $this
  420. ->if(
  421. $this->newTestedInstance,
  422. $childTemplate = new atoum\template()
  423. )
  424. ->then
  425. ->boolean($this->testedInstance->isChild($childTemplate))->isFalse()
  426. ->if($this->testedInstance->addChild($childTemplate))
  427. ->then
  428. ->boolean($this->testedInstance->isChild($childTemplate))->isTrue()
  429. ;
  430. }
  431. public function testGetTag()
  432. {
  433. $this
  434. ->if($this->newTestedInstance)
  435. ->then
  436. ->variable($this->testedInstance->getTag())->isNull()
  437. ;
  438. }
  439. public function testGetChildren()
  440. {
  441. $this
  442. ->if($this->newTestedInstance)
  443. ->then
  444. ->array($this->testedInstance->getChildren())->isEmpty()
  445. ->if($this->testedInstance->addChild($childTemplate = new atoum\template()))
  446. ->then
  447. ->array($this->testedInstance->getChildren())->isIdenticalTo(array($childTemplate))
  448. ->if($this->testedInstance->addChild($otherChildTemplate = new atoum\template()))
  449. ->then
  450. ->array($this->testedInstance->getChildren())->isIdenticalTo(array($childTemplate, $otherChildTemplate))
  451. ->if($childTemplate->addChild($littleChildTemplate = new atoum\template()))
  452. ->then
  453. ->array($this->testedInstance->getChildren())->isIdenticalTo(array($childTemplate, $otherChildTemplate))
  454. ;
  455. }
  456. public function testAddChild()
  457. {
  458. $this
  459. ->if($this->newTestedInstance)
  460. ->then
  461. ->boolean($this->testedInstance->hasChildren())->isFalse()
  462. ->object($this->testedInstance->addChild($childTemplate = new atoum\template()))->isTestedInstance
  463. ->object($childTemplate->getParent())->isTestedInstance
  464. ->array($this->testedInstance->getChildren())->isIdenticalTo(array($childTemplate))
  465. ->object($this->testedInstance->addChild($childTemplate))->isTestedInstance
  466. ->object($childTemplate->getParent())->isTestedInstance
  467. ->array($this->testedInstance->getChildren())->isIdenticalTo(array($childTemplate))
  468. ->if(
  469. $otherTemplate = new atoum\template(),
  470. $otherTemplate->addChild($otherChildTemplate = new atoum\template())
  471. )
  472. ->then
  473. ->array($otherTemplate->getChildren())->isIdenticalTo(array($otherChildTemplate))
  474. ->object($otherChildTemplate->getParent())->isIdenticalTo($otherTemplate)
  475. ->object($this->testedInstance->addChild($otherChildTemplate))->isTestedInstance
  476. ->array($otherTemplate->getChildren())->isEmpty()
  477. ->object($otherChildTemplate->getParent())->isTestedInstance
  478. ->array($this->testedInstance->getChildren())->isIdenticalTo(array($childTemplate, $otherChildTemplate))
  479. ->if(
  480. $this->newTestedInstance,
  481. $templateWithId = new atoum\template\tag(uniqid()),
  482. $templateWithId->setId($id = uniqid()),
  483. $templateWithSameId = clone $templateWithId
  484. )
  485. ->then
  486. ->boolean($this->testedInstance->hasChildren())->isFalse()
  487. ->object($this->testedInstance->addChild($templateWithId))->isTestedInstance
  488. ->array($this->testedInstance->getChildren())->isIdenticalTo(array($templateWithId))
  489. ->object($this->testedInstance->addChild($templateWithId))->isTestedInstance
  490. ->array($this->testedInstance->getChildren())->isIdenticalTo(array($templateWithId))
  491. ->exception(function($test) use ($templateWithSameId) {
  492. $test->testedInstance->addChild($templateWithSameId);
  493. }
  494. )
  495. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  496. ->hasMessage('Id \'' . $id . '\' is already defined')
  497. ;
  498. }
  499. public function testDeleteChild()
  500. {
  501. $this
  502. ->if(
  503. $this->newTestedInstance,
  504. $this->testedInstance->addChild($childTemplate = new atoum\template())
  505. )
  506. ->then
  507. ->object($childTemplate->getParent())->isTestedInstance
  508. ->array($this->testedInstance->getChildren())->isIdenticalTo(array($childTemplate))
  509. ->object($this->testedInstance->deleteChild($childTemplate))->isTestedInstance
  510. ->variable($childTemplate->getParent())->isNull()
  511. ->array($this->testedInstance->getChildren())->isEmpty()
  512. ;
  513. }
  514. public function testHasChildren()
  515. {
  516. $this
  517. ->if($this->newTestedInstance)
  518. ->then
  519. ->boolean($this->testedInstance->hasChildren())->isFalse()
  520. ->if($this->testedInstance->addChild($childTemplate = new atoum\template()))
  521. ->then
  522. ->boolean($this->testedInstance->hasChildren())->isTrue()
  523. ->if($this->testedInstance->deleteChild($childTemplate))
  524. ->then
  525. ->boolean($this->testedInstance->hasChildren())->isFalse()
  526. ;
  527. }
  528. public function testGetByTag()
  529. {
  530. $this
  531. ->if($this->newTestedInstance)
  532. ->then
  533. ->object($iterator = $this->testedInstance->getByTag(uniqid()))->isInstanceOf('mageekguy\atoum\template\iterator')
  534. ->sizeOf($iterator)->isZero()
  535. ->if($this->testedInstance->addChild($tag = new atoum\template\tag(uniqid())))
  536. ->then
  537. ->object($iterator = $this->testedInstance->getByTag(uniqid()))->isInstanceOf('mageekguy\atoum\template\iterator')
  538. ->sizeOf($iterator)->isZero()
  539. ->object($iterator = $this->testedInstance->getByTag($tag->getTag()))->isInstanceOf('mageekguy\atoum\template\iterator')
  540. ->sizeOf($iterator)->isEqualTo(1)
  541. ->object($iterator->current())->isIdenticalTo($tag)
  542. ->if($this->testedInstance->addChild($otherTag = new atoum\template\tag($tag->getTag())))
  543. ->then
  544. ->object($iterator = $this->testedInstance->getByTag(uniqid()))->isInstanceOf('mageekguy\atoum\template\iterator')
  545. ->sizeOf($iterator)->isZero()
  546. ->object($iterator = $this->testedInstance->getByTag($tag->getTag()))->isInstanceOf('mageekguy\atoum\template\iterator')
  547. ->sizeOf($iterator)->isEqualTo(2)
  548. ->object($iterator->current())->isIdenticalTo($tag)
  549. ->object($iterator->next()->current())->isIdenticalTo($otherTag)
  550. ->if($tag->addChild($childTag = new atoum\template\tag($tag->getTag())))
  551. ->then
  552. ->object($iterator = $this->testedInstance->getByTag(uniqid()))->isInstanceOf('mageekguy\atoum\template\iterator')
  553. ->sizeOf($iterator)->isZero()
  554. ->object($iterator = $this->testedInstance->getByTag($tag->getTag()))->isInstanceOf('mageekguy\atoum\template\iterator')
  555. ->sizeOf($iterator)->isEqualTo(3)
  556. ->object($iterator->current())->isIdenticalTo($tag)
  557. ->object($iterator->next()->current())->isIdenticalTo($childTag)
  558. ->object($iterator->next()->current())->isIdenticalTo($otherTag)
  559. ;
  560. }
  561. public function testGetById()
  562. {
  563. $this
  564. ->if($this->newTestedInstance)
  565. ->then
  566. ->variable($this->testedInstance->getById(uniqid()))->isNull()
  567. ->if(
  568. $tag = new atoum\template\tag(uniqid()),
  569. $this->testedInstance->addChild($tag->setId($id = uniqid()))
  570. )
  571. ->then
  572. ->variable($this->testedInstance->getById(uniqid()))->isNull()
  573. ->object($this->testedInstance->getById($id))->isIdenticalTo($tag)
  574. ->if(
  575. $childTag = new atoum\template\tag(uniqid()),
  576. $tag->addChild($childTag->setId($childId = uniqid()))
  577. )
  578. ->then
  579. ->variable($this->testedInstance->getById(uniqid()))->isNull()
  580. ->object($this->testedInstance->getById($id))->isIdenticalTo($tag)
  581. ->object($tag->getById($id))->isIdenticalTo($tag)
  582. ->object($this->testedInstance->getById($childId))->isIdenticalTo($childTag)
  583. ->object($tag->getById($childId))->isIdenticalTo($childTag)
  584. ->object($childTag->getById($childId))->isIdenticalTo($childTag)
  585. ->variable($childTag->getById($id, false))->isNull()
  586. ;
  587. }
  588. public function testBuild()
  589. {
  590. $this
  591. ->if($this->newTestedInstance)
  592. ->then
  593. ->string($this->testedInstance->getData())->isEmpty()
  594. ->boolean($this->testedInstance->hasChildren())->isFalse()
  595. ->object($this->testedInstance->build())->isTestedInstance
  596. ->string($this->testedInstance->getData())->isEmpty()
  597. ->if($this->newTestedInstance($data = uniqid()))
  598. ->then
  599. ->string($this->testedInstance->getData())->isEqualTo($data)
  600. ->boolean($this->testedInstance->hasChildren())->isFalse()
  601. ->object($this->testedInstance->build())->isTestedInstance
  602. ->string($this->testedInstance->getData())->isEqualTo($data)
  603. ->object($this->testedInstance->build())->isTestedInstance
  604. ->string($this->testedInstance->getData())->isEqualTo($data)
  605. ->if($this->testedInstance->addChild($childTemplate = new atoum\template($childData = uniqid())))
  606. ->then
  607. ->string($this->testedInstance->getData())->isEqualTo($data)
  608. ->string($childTemplate->getData())->isEqualTo($childData)
  609. ->array($this->testedInstance->getChildren())->isIdenticalTo(array($childTemplate))
  610. ->object($this->testedInstance->build())->isTestedInstance
  611. ->string($this->testedInstance->getData())->isEqualTo($data . $childData)
  612. ->string($childTemplate->getData())->isEqualTo($childData)
  613. ->object($this->testedInstance->build())->isTestedInstance
  614. ->string($this->testedInstance->getData())->isEqualTo($data . $childData . $childData)
  615. ;
  616. }
  617. public function testGetChild()
  618. {
  619. $this
  620. ->if($this->newTestedInstance)
  621. ->then
  622. ->variable($this->testedInstance->getChild(0))->isNull()
  623. ->variable($this->testedInstance->getChild(rand(1, PHP_INT_MAX)))->isNull()
  624. ->variable($this->testedInstance->getChild(- rand(1, PHP_INT_MAX)))->isNull()
  625. ->if($this->testedInstance->addChild($childTemplate = new atoum\template()))
  626. ->then
  627. ->variable($this->testedInstance->getChild(0))->isIdenticalTo($childTemplate)
  628. ->variable($this->testedInstance->getChild(rand(1, PHP_INT_MAX)))->isNull()
  629. ->variable($this->testedInstance->getChild(- rand(1, PHP_INT_MAX)))->isNull()
  630. ;
  631. }
  632. }