PageRenderTime 53ms CodeModel.GetById 4ms RepoModel.GetById 0ms app.codeStats 1ms

/tests/units/classes/template/parser.php

http://github.com/mageekguy/atoum
PHP | 542 lines | 520 code | 22 blank | 0 comment | 0 complexity | f751098fc57c1df980f2c3f1ecce4dfe MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\template;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\test,
  6. mageekguy\atoum\template
  7. ;
  8. require_once __DIR__ . '/../../runner.php';
  9. class parser extends atoum\test
  10. {
  11. public function test__construct()
  12. {
  13. $this
  14. ->if($parser = new template\parser())
  15. ->then
  16. ->string($parser->getNamespace())->isEqualTo(template\parser::defaultNamespace)
  17. ->object($parser->getAdapter())->isInstanceOf('mageekguy\atoum\adapter')
  18. ->if($parser = new template\parser($namespace = uniqid()))
  19. ->then
  20. ->string($namespace)->isEqualTo($parser->getNamespace())
  21. ->object($parser->getAdapter())->isInstanceOf('mageekguy\atoum\adapter')
  22. ->if($parser = new template\parser($namespace = rand(1, PHP_INT_MAX)))
  23. ->then
  24. ->string($parser->getNamespace())->isEqualTo((string) $namespace)
  25. ->object($parser->getAdapter())->isInstanceOf('mageekguy\atoum\adapter')
  26. ->if($parser = new template\parser($namespace = uniqid(), $adapter = new atoum\test\adapter()))
  27. ->then
  28. ->string($parser->getNamespace())->isEqualTo((string) $namespace)
  29. ->object($parser->getAdapter())->isIdenticalTo($adapter)
  30. ;
  31. }
  32. public function testSetNamespace()
  33. {
  34. $this
  35. ->if($parser = new template\parser())
  36. ->then
  37. ->object($parser->setNamespace($namespace = uniqid()))->isIdenticalTo($parser)
  38. ->string($parser->getNamespace())->isEqualTo($namespace)
  39. ->object($parser->setNamespace($namespace = rand(1, PHP_INT_MAX)))->isIdenticalTo($parser)
  40. ->string($parser->getNamespace())->isEqualTo((string) $namespace)
  41. ;
  42. }
  43. public function testSetAdapter()
  44. {
  45. $this
  46. ->if($parser = new template\parser())
  47. ->then
  48. ->object($parser->setAdapter($adapter = new atoum\test\adapter()))->isIdenticalTo($parser)
  49. ->object($parser->getAdapter())->isIdenticalTo($adapter)
  50. ;
  51. }
  52. public function testCheckString()
  53. {
  54. $this->define->parserException = '\mageekguy\atoum\tests\units\asserters\template\parser\exception';
  55. $this
  56. ->if($parser = new template\parser())
  57. ->then
  58. ->object($parser->checkString(uniqid()))->isIdenticalTo($parser)
  59. ->object($parser->checkString('<' . uniqid() . ':' . uniqid() . ' />'))->isIdenticalTo($parser)
  60. ->if($tag = uniqid())
  61. ->then
  62. ->object($parser->checkString('<'))->isIdenticalTo($parser)
  63. ->object($parser->checkString('<' . template\parser::defaultNamespace))->isIdenticalTo($parser)
  64. ->object($parser->checkString('<' . template\parser::defaultNamespace . ':'))->isIdenticalTo($parser)
  65. ->object($parser->checkString('<' . template\parser::defaultNamespace . ':' . $tag))->isIdenticalTo($parser)
  66. ->object($parser->checkString('<' . template\parser::defaultNamespace . ':' . $tag . '/>'))->isIdenticalTo($parser)
  67. ->parserException(function() use ($parser, $tag) {
  68. $parser->checkString('<' . template\parser::defaultNamespace . ':' . $tag . ' id="" />');
  69. }
  70. )
  71. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  72. ->isInstanceOf('mageekguy\atoum\template\parser\exception')
  73. ->hasMessage('Id must not be empty')
  74. ->hasErrorLine(1)
  75. ->hasErrorOffset(1)
  76. ->object($parser->checkString('<' . template\parser::defaultNamespace . ':' . $tag . ' id="' . uniqid() . '" />'))->isIdenticalTo($parser)
  77. ->object($parser->checkString('<' . template\parser::defaultNamespace . ':' . $tag . '></' . template\parser::defaultNamespace . ':' . $tag . '>'))->isIdenticalTo($parser)
  78. ->object($parser->checkString('<' . template\parser::defaultNamespace . ':' . $tag . ' ' . "\t" . ' ></' . template\parser::defaultNamespace . ':' . $tag . '>'))->isIdenticalTo($parser)
  79. ->object($parser->checkString('<' . template\parser::defaultNamespace . ':' . $tag . '></' . template\parser::defaultNamespace . ':' . $tag . ' ' . "\t" . ' >'))->isIdenticalTo($parser)
  80. ->if($tagWithId = '<' . template\parser::defaultNamespace . ':' . $tag . ' id="' . ($id = uniqid()) . '" />')
  81. ->then
  82. ->parserException(function() use ($parser, $tagWithId) {
  83. $parser->checkString($tagWithId . $tagWithId);
  84. }
  85. )
  86. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  87. ->isInstanceOf('mageekguy\atoum\template\parser\exception')
  88. ->hasMessage('Id \'' . $id . '\' is already defined in line 1 at offset 1')
  89. ->hasErrorLine(1)
  90. ->hasErrorOffset(41)
  91. ->if($tagWithInvalidAttribute = '<' . template\parser::defaultNamespace . ':' . $tag . ' foo="bar" />')
  92. ->then
  93. ->parserException(function() use ($parser, $tagWithInvalidAttribute) {
  94. $parser->checkString($tagWithInvalidAttribute);
  95. }
  96. )
  97. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  98. ->isInstanceOf('mageekguy\atoum\template\parser\exception')
  99. ->hasMessage('Attribute \'foo\' is unknown')
  100. ->hasErrorLine(1)
  101. ->hasErrorOffset(1)
  102. ->if($firstTag = '<' . template\parser::defaultNamespace . ':' . $tag . '>')
  103. ->then
  104. ->parserException(function() use ($parser, $firstTag) {
  105. $parser->checkString($firstTag);
  106. }
  107. )
  108. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  109. ->isInstanceOf('mageekguy\atoum\template\parser\exception')
  110. ->hasMessage('Tag \'' . $tag . '\' must be closed')
  111. ->hasErrorLine(1)
  112. ->hasErrorOffset(strlen($firstTag) + 1)
  113. ->if($firstTag = '<' . template\parser::defaultNamespace . ':' . $tag . '>')
  114. ->and($eols = str_repeat("\n", rand(1, 10)))
  115. ->then
  116. ->parserException(function() use ($parser, $firstTag, $eols) {
  117. $parser->checkString($eols . $firstTag);
  118. }
  119. )
  120. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  121. ->isInstanceOf('mageekguy\atoum\template\parser\exception')
  122. ->hasMessage('Tag \'' . $tag . '\' must be closed')
  123. ->hasErrorLine(strlen($eols) + 1)
  124. ->hasErrorOffset(strlen($firstTag) + 1)
  125. ->if($spaces = str_repeat(' ', rand(1, 10)))
  126. ->then
  127. ->parserException(function() use ($parser, $firstTag, $eols, $spaces) {
  128. $parser->checkString($eols . $spaces . $firstTag);
  129. }
  130. )
  131. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  132. ->isInstanceOf('mageekguy\atoum\template\parser\exception')
  133. ->hasMessage('Tag \'' . $tag . '\' must be closed')
  134. ->hasErrorLine(strlen($eols) + 1)
  135. ->hasErrorOffset(strlen($firstTag) + strlen($spaces) + 1)
  136. ->if($firstTag = '<' . template\parser::defaultNamespace . ':' . $tag . '>')
  137. ->and($secondTag = '</' . template\parser::defaultNamespace . ':' . ($notOpenTag = uniqid()) . ' ' . "\t" . ' >')
  138. ->then
  139. ->parserException(function() use ($parser, $firstTag, $secondTag) {
  140. $parser->checkString($firstTag . $secondTag);
  141. }
  142. )
  143. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  144. ->isInstanceOf('mageekguy\atoum\template\parser\exception')
  145. ->hasMessage('Tag \'' . $notOpenTag . '\' is not open')
  146. ->hasErrorLine(1)
  147. ->hasErrorOffset(strlen($firstTag) + 1)
  148. ->parserException(function() use ($parser, $firstTag, $secondTag, $eols) {
  149. $parser->checkString($eols . $firstTag . $secondTag);
  150. }
  151. )
  152. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  153. ->isInstanceOf('mageekguy\atoum\template\parser\exception')
  154. ->hasMessage('Tag \'' . $notOpenTag . '\' is not open')
  155. ->hasErrorLine(strlen($eols) + 1)
  156. ->hasErrorOffset(strlen($firstTag) + 1)
  157. ->parserException(function() use ($parser, $firstTag, $secondTag, $eols, $spaces) {
  158. $parser->checkString($eols . $spaces . $firstTag . $secondTag);
  159. }
  160. )
  161. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  162. ->isInstanceOf('mageekguy\atoum\template\parser\exception')
  163. ->hasMessage('Tag \'' . $notOpenTag . '\' is not open')
  164. ->hasErrorLine(strlen($eols) + 1)
  165. ->hasErrorOffset(strlen($firstTag) + strlen($spaces) + 1)
  166. ;
  167. }
  168. public function testCheckFile()
  169. {
  170. $this->define->parserException = '\mageekguy\atoum\tests\units\asserters\template\parser\exception';
  171. $this
  172. ->if($parser = new template\parser(null, $adapter = new test\adapter()))
  173. ->and($adapter->file_get_contents = false)
  174. ->then
  175. ->exception(function() use ($parser, & $path) {
  176. $parser->checkFile($path = uniqid());
  177. }
  178. )
  179. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  180. ->hasMessage('Unable to get contents from file \'' . $path . '\'')
  181. ->if($adapter->file_get_contents = '<' . uniqid() . ':' . uniqid() . ' />')
  182. ->then
  183. ->object($parser->checkFile(uniqid()))->isIdenticalTo($parser)
  184. ->if($adapter->file_get_contents = '<')
  185. ->then
  186. ->object($parser->checkFile(uniqid()))->isIdenticalTo($parser)
  187. ->if($adapter->file_get_contents = '<' . template\parser::defaultNamespace)
  188. ->then
  189. ->object($parser->checkFile(uniqid()))->isIdenticalTo($parser)
  190. ->if($adapter->file_get_contents = '<' . template\parser::defaultNamespace . ':')
  191. ->then
  192. ->object($parser->checkFile(uniqid()))->isIdenticalTo($parser)
  193. ->if($adapter->file_get_contents = '<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()))
  194. ->then
  195. ->object($parser->checkFile(uniqid()))->isIdenticalTo($parser)
  196. ->if($adapter->file_get_contents = '<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . '/>')
  197. ->then
  198. ->object($parser->checkFile(uniqid()))->isIdenticalTo($parser)
  199. ->if($adapter->file_get_contents = '<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . ' id="" />')
  200. ->then
  201. ->parserException(function() use ($parser, $tag) {
  202. $parser->checkFile(uniqid());
  203. }
  204. )
  205. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  206. ->isInstanceOf('mageekguy\atoum\template\parser\exception')
  207. ->hasMessage('Id must not be empty')
  208. ->hasErrorLine(1)
  209. ->hasErrorOffset(1)
  210. ->if($adapter->file_get_contents = '<' . template\parser::defaultNamespace . ':' . $tag . ' id="' . uniqid() . '" />')
  211. ->then
  212. ->object($parser->checkFile(uniqid()))->isIdenticalTo($parser)
  213. ->if($adapter->file_get_contents = '<' . template\parser::defaultNamespace . ':' . $tag . '></' . template\parser::defaultNamespace . ':' . $tag . '>')
  214. ->then
  215. ->object($parser->checkFile(uniqid()))->isIdenticalTo($parser)
  216. ->if($adapter->file_get_contents = '<' . template\parser::defaultNamespace . ':' . $tag . ' ' . "\t" . ' ></' . template\parser::defaultNamespace . ':' . $tag . '>')
  217. ->then
  218. ->object($parser->checkFile(uniqid()))->isIdenticalTo($parser)
  219. ->if($adapter->file_get_contents = '<' . template\parser::defaultNamespace . ':' . $tag . '></' . template\parser::defaultNamespace . ':' . $tag . ' ' . "\t" . ' >')
  220. ->then
  221. ->object($parser->checkFile(uniqid()))->isIdenticalTo($parser)
  222. ->if($tagWithId = '<' . template\parser::defaultNamespace . ':' . $tag . ' id="' . ($id = uniqid()) . '" />')
  223. ->and($adapter->file_get_contents = $tagWithId . $tagWithId)
  224. ->then
  225. ->parserException(function() use ($parser, $tagWithId) {
  226. $parser->checkFile(uniqid());
  227. }
  228. )
  229. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  230. ->isInstanceOf('mageekguy\atoum\template\parser\exception')
  231. ->hasMessage('Id \'' . $id . '\' is already defined in line 1 at offset 1')
  232. ->hasErrorLine(1)
  233. ->hasErrorOffset(41)
  234. ->if($adapter->file_get_contents = '<' . template\parser::defaultNamespace . ':' . $tag . ' foo="bar" />')
  235. ->then
  236. ->parserException(function() use ($parser) {
  237. $parser->checkFile(uniqid());
  238. }
  239. )
  240. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  241. ->isInstanceOf('mageekguy\atoum\template\parser\exception')
  242. ->hasMessage('Attribute \'foo\' is unknown')
  243. ->hasErrorLine(1)
  244. ->hasErrorOffset(1)
  245. ->if($adapter->file_get_contents = $firstTag = '<' . template\parser::defaultNamespace . ':' . $tag . '>')
  246. ->then
  247. ->parserException(function() use ($parser) {
  248. $parser->checkFile(uniqid());
  249. }
  250. )
  251. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  252. ->isInstanceOf('mageekguy\atoum\template\parser\exception')
  253. ->hasMessage('Tag \'' . $tag . '\' must be closed')
  254. ->hasErrorLine(1)
  255. ->hasErrorOffset(strlen($firstTag) + 1)
  256. ->if($adapter->file_get_contents = ($eols = str_repeat("\n", rand(1, 10))) . ($firstTag = '<' . template\parser::defaultNamespace . ':' . $tag . '>'))
  257. ->then
  258. ->parserException(function() use ($parser) {
  259. $parser->checkFile(uniqid());
  260. }
  261. )
  262. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  263. ->isInstanceOf('mageekguy\atoum\template\parser\exception')
  264. ->hasMessage('Tag \'' . $tag . '\' must be closed')
  265. ->hasErrorLine(strlen($eols) + 1)
  266. ->hasErrorOffset(strlen($firstTag) + 1)
  267. ->if($adapter->file_get_contents = ($eols = str_repeat("\n", rand(1, 10))) . ($spaces = str_repeat(' ', rand(1, 10))) . ($firstTag = '<' . template\parser::defaultNamespace . ':' . $tag . '>'))
  268. ->then
  269. ->parserException(function() use ($parser) {
  270. $parser->checkFile(uniqid());
  271. }
  272. )
  273. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  274. ->isInstanceOf('mageekguy\atoum\template\parser\exception')
  275. ->hasMessage('Tag \'' . $tag . '\' must be closed')
  276. ->hasErrorLine(strlen($eols) + 1)
  277. ->hasErrorOffset(strlen($firstTag) + strlen($spaces) + 1)
  278. ->if($firstTag = '<' . template\parser::defaultNamespace . ':' . $tag . '>')
  279. ->and($secondTag = '</' . template\parser::defaultNamespace . ':' . ($notOpenTag = uniqid()) . ' ' . "\t" . ' >')
  280. ->and($adapter->file_get_contents = $firstTag . $secondTag)
  281. ->then
  282. ->parserException(function() use ($parser) {
  283. $parser->checkFile(uniqid());
  284. }
  285. )
  286. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  287. ->isInstanceOf('mageekguy\atoum\template\parser\exception')
  288. ->hasMessage('Tag \'' . $notOpenTag . '\' is not open')
  289. ->hasErrorLine(1)
  290. ->hasErrorOffset(strlen($firstTag) + 1)
  291. ->if($adapter->file_get_contents = $eols . $firstTag . $secondTag)
  292. ->then
  293. ->parserException(function() use ($parser) {
  294. $parser->checkFile(uniqid());
  295. }
  296. )
  297. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  298. ->isInstanceOf('mageekguy\atoum\template\parser\exception')
  299. ->hasMessage('Tag \'' . $notOpenTag . '\' is not open')
  300. ->hasErrorLine(strlen($eols) + 1)
  301. ->hasErrorOffset(strlen($firstTag) + 1)
  302. ->if($adapter->file_get_contents = $eols . $spaces . $firstTag . $secondTag)
  303. ->then
  304. ->parserException(function() use ($parser, $firstTag, $secondTag, $eols, $spaces) {
  305. $parser->checkFile($eols . $spaces . $firstTag . $secondTag);
  306. }
  307. )
  308. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  309. ->isInstanceOf('mageekguy\atoum\template\parser\exception')
  310. ->hasMessage('Tag \'' . $notOpenTag . '\' is not open')
  311. ->hasErrorLine(strlen($eols) + 1)
  312. ->hasErrorOffset(strlen($firstTag) + strlen($spaces) + 1)
  313. ;
  314. }
  315. public function testParseString()
  316. {
  317. $this
  318. ->if($parser = new template\parser())
  319. ->then
  320. ->object($root = $parser->parseString(''))->isInstanceOf('mageekguy\atoum\template')
  321. ->array($root->getChildren())->isEmpty()
  322. ->object($root = $parser->parseString($string = uniqid()))->isInstanceOf('mageekguy\atoum\template')
  323. ->array($root->getChildren())->hasSize(1)
  324. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\data')
  325. ->string($root->getChild(0)->getData())->isEqualTo($string)
  326. ->object($root = $parser->parseString($string = uniqid() . "\n" . uniqid() . "\n"))->isInstanceOf('mageekguy\atoum\template')
  327. ->array($root->getChildren())->hasSize(1)
  328. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\data')
  329. ->string($root->getChild(0)->getData())->isEqualTo($string)
  330. ->object($root = $parser->parseString('<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . ' />'))->isInstanceOf('mageekguy\atoum\template')
  331. ->array($root->getChildren())->hasSize(1)
  332. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\tag')
  333. ->string($root->getChild(0)->getTag())->isEqualTo($tag)
  334. ->variable($root->getChild(0)->getId())->isNull()
  335. ->string($root->getChild(0)->getData())->isEmpty()
  336. ->integer($root->getChild(0)->getLine())->isEqualTo(1)
  337. ->integer($root->getChild(0)->getOffset())->isEqualTo(1)
  338. ->object($root = $parser->parseString('<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . '/>'))->isInstanceOf('mageekguy\atoum\template')
  339. ->array($root->getChildren())->hasSize(1)
  340. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\tag')
  341. ->string($root->getChild(0)->getTag())->isEqualTo($tag)
  342. ->variable($root->getChild(0)->getId())->isNull()
  343. ->string($root->getChild(0)->getData())->isEmpty()
  344. ->integer($root->getChild(0)->getLine())->isEqualTo(1)
  345. ->integer($root->getChild(0)->getOffset())->isEqualTo(1)
  346. ->object($root = $parser->parseString('<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . ' id="' . ($id = uniqid()) . '" />'))->isInstanceOf('mageekguy\atoum\template')
  347. ->array($root->getChildren())->hasSize(1)
  348. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\tag')
  349. ->string($root->getChild(0)->getTag())->isEqualTo($tag)
  350. ->string($root->getChild(0)->getId())->isEqualTo($id)
  351. ->string($root->getChild(0)->getData())->isEmpty()
  352. ->integer($root->getChild(0)->getLine())->isEqualTo(1)
  353. ->integer($root->getChild(0)->getOffset())->isEqualTo(1)
  354. ->object($root = $parser->parseString('<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . ' id="' . ($id = uniqid()) . '"/>'))->isInstanceOf('mageekguy\atoum\template')
  355. ->array($root->getChildren())->hasSize(1)
  356. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\tag')
  357. ->string($root->getChild(0)->getTag())->isEqualTo($tag)
  358. ->string($root->getChild(0)->getId())->isEqualTo($id)
  359. ->string($root->getChild(0)->getData())->isEmpty()
  360. ->integer($root->getChild(0)->getLine())->isEqualTo(1)
  361. ->integer($root->getChild(0)->getOffset())->isEqualTo(1)
  362. ->object($root = $parser->parseString('<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . '>' . ($data = uniqid()) . '</' . template\parser::defaultNamespace . ':' . $tag . '>'))->isInstanceOf('mageekguy\atoum\template')
  363. ->array($root->getChildren())->hasSize(1)
  364. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\tag')
  365. ->string($root->getChild(0)->getTag())->isEqualTo($tag)
  366. ->variable($root->getChild(0)->getId())->isNull()
  367. ->string($root->getChild(0)->getData())->isEmpty()
  368. ->integer($root->getChild(0)->getLine())->isEqualTo(1)
  369. ->integer($root->getChild(0)->getOffset())->isEqualTo(1)
  370. ->object($root = $parser->parseString(($string1 = uniqid()) . '<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . '>' . ($data = uniqid()) . '</' . template\parser::defaultNamespace . ':' . $tag . '>' . ($string2 = uniqid())))->isInstanceOf('mageekguy\atoum\template')
  371. ->array($root->getChildren())->hasSize(3)
  372. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\data')
  373. ->string($root->getChild(0)->getData())->isEqualTo($string1)
  374. ->object($root->getChild(1))->isInstanceOf('mageekguy\atoum\template\tag')
  375. ->variable($root->getChild(1)->getId())->isNull()
  376. ->string($root->getChild(1)->getData())->isEmpty()
  377. ->integer($root->getChild(1)->getLine())->isEqualTo(1)
  378. ->integer($root->getChild(1)->getOffset())->isEqualTo(strlen($string1) + 1)
  379. ->object($root->getChild(2))->isInstanceOf('mageekguy\atoum\template\data')
  380. ->string($root->getChild(2)->getData())->isEqualTo($string2)
  381. ->object($root = $parser->parseString(($string1 = uniqid()) . '<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . ' id="' . ($id = uniqid()) . '">' . ($data = uniqid()) . '</' . template\parser::defaultNamespace . ':' . $tag . '>' . ($string2 = uniqid())))->isInstanceOf('mageekguy\atoum\template')
  382. ->array($root->getChildren())->hasSize(3)
  383. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\data')
  384. ->string($root->getChild(0)->getData())->isEqualTo($string1)
  385. ->object($root->getChild(1))->isInstanceOf('mageekguy\atoum\template\tag')
  386. ->string($root->getChild(1)->getId())->isEqualTo($id)
  387. ->string($root->getChild(1)->getData())->isEmpty()
  388. ->integer($root->getChild(1)->getLine())->isEqualTo(1)
  389. ->integer($root->getChild(1)->getOffset())->isEqualTo(strlen($string1) + 1)
  390. ->object($root->getChild(2))->isInstanceOf('mageekguy\atoum\template\data')
  391. ->string($root->getChild(2)->getData())->isEqualTo($string2)
  392. ->object($root = $parser->parseString(($string = str_repeat("\n", 6)) . '<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . '/>'))
  393. ->array($root->getChildren())->hasSize(2)
  394. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\data')
  395. ->string($root->getChild(0)->getData())->isEqualTo($string)
  396. ->object($root->getChild(1))->isInstanceOf('mageekguy\atoum\template\tag')
  397. ->variable($root->getChild(1)->getId())->isNull()
  398. ->string($root->getChild(1)->getData())->isEmpty()
  399. ->integer($root->getChild(1)->getLine())->isEqualTo(7)
  400. ->integer($root->getChild(1)->getOffset())->isEqualTo(1)
  401. ;
  402. }
  403. public function testParseFile()
  404. {
  405. $this
  406. ->if($parser = new template\parser(null, $adapter = new test\adapter()))
  407. ->and($adapter->file_get_contents = false)
  408. ->then
  409. ->exception(function() use ($parser, & $path) {
  410. $parser->parseFile($path = uniqid());
  411. }
  412. )
  413. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  414. ->hasMessage('Unable to get contents from file \'' . $path . '\'')
  415. ->if($adapter->file_get_contents = '')
  416. ->then
  417. ->object($root = $parser->parseFile(uniqid()))->isInstanceOf('mageekguy\atoum\template')
  418. ->array($root->getChildren())->isEmpty()
  419. ->if($adapter->file_get_contents = $string = uniqid())
  420. ->then
  421. ->object($root = $parser->parseFile(uniqid()))->isInstanceOf('mageekguy\atoum\template')
  422. ->array($root->getChildren())->hasSize(1)
  423. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\data')
  424. ->string($root->getChild(0)->getData())->isEqualTo($string)
  425. ->if($adapter->file_get_contents = $string = uniqid() . "\n" . uniqid() . "\n")
  426. ->then
  427. ->object($root = $parser->parseFile(uniqid()))->isInstanceOf('mageekguy\atoum\template')
  428. ->array($root->getChildren())->hasSize(1)
  429. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\data')
  430. ->string($root->getChild(0)->getData())->isEqualTo($string)
  431. ->if($adapter->file_get_contents = '<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . ' />')
  432. ->then
  433. ->object($root = $parser->parseFile(uniqid()))->isInstanceOf('mageekguy\atoum\template')
  434. ->array($root->getChildren())->hasSize(1)
  435. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\tag')
  436. ->string($root->getChild(0)->getTag())->isEqualTo($tag)
  437. ->variable($root->getChild(0)->getId())->isNull()
  438. ->string($root->getChild(0)->getData())->isEmpty()
  439. ->integer($root->getChild(0)->getLine())->isEqualTo(1)
  440. ->integer($root->getChild(0)->getOffset())->isEqualTo(1)
  441. ->if($adapter->file_get_contents = '<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . '/>')
  442. ->then
  443. ->object($root = $parser->parseFile(uniqid()))->isInstanceOf('mageekguy\atoum\template')
  444. ->array($root->getChildren())->hasSize(1)
  445. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\tag')
  446. ->string($root->getChild(0)->getTag())->isEqualTo($tag)
  447. ->variable($root->getChild(0)->getId())->isNull()
  448. ->string($root->getChild(0)->getData())->isEmpty()
  449. ->integer($root->getChild(0)->getLine())->isEqualTo(1)
  450. ->integer($root->getChild(0)->getOffset())->isEqualTo(1)
  451. ->if($adapter->file_get_contents = '<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . ' id="' . ($id = uniqid()) . '" />')
  452. ->then
  453. ->object($root = $parser->parseFile(uniqid()))->isInstanceOf('mageekguy\atoum\template')
  454. ->array($root->getChildren())->hasSize(1)
  455. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\tag')
  456. ->string($root->getChild(0)->getTag())->isEqualTo($tag)
  457. ->string($root->getChild(0)->getId())->isEqualTo($id)
  458. ->string($root->getChild(0)->getData())->isEmpty()
  459. ->integer($root->getChild(0)->getLine())->isEqualTo(1)
  460. ->integer($root->getChild(0)->getOffset())->isEqualTo(1)
  461. ->if($adapter->file_get_contents = '<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . ' id="' . ($id = uniqid()) . '"/>')
  462. ->then
  463. ->object($root = $parser->parseFile(uniqid()))->isInstanceOf('mageekguy\atoum\template')
  464. ->array($root->getChildren())->hasSize(1)
  465. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\tag')
  466. ->string($root->getChild(0)->getTag())->isEqualTo($tag)
  467. ->string($root->getChild(0)->getId())->isEqualTo($id)
  468. ->string($root->getChild(0)->getData())->isEmpty()
  469. ->integer($root->getChild(0)->getLine())->isEqualTo(1)
  470. ->integer($root->getChild(0)->getOffset())->isEqualTo(1)
  471. ->if($adapter->file_get_contents = '<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . '>' . ($data = uniqid()) . '</' . template\parser::defaultNamespace . ':' . $tag . '>')
  472. ->then
  473. ->object($root = $parser->parseFile(uniqid()))->isInstanceOf('mageekguy\atoum\template')
  474. ->array($root->getChildren())->hasSize(1)
  475. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\tag')
  476. ->string($root->getChild(0)->getTag())->isEqualTo($tag)
  477. ->variable($root->getChild(0)->getId())->isNull()
  478. ->string($root->getChild(0)->getData())->isEmpty()
  479. ->integer($root->getChild(0)->getLine())->isEqualTo(1)
  480. ->integer($root->getChild(0)->getOffset())->isEqualTo(1)
  481. ->if($adapter->file_get_contents = ($string1 = uniqid()) . '<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . '>' . ($data = uniqid()) . '</' . template\parser::defaultNamespace . ':' . $tag . '>' . ($string2 = uniqid()))
  482. ->then
  483. ->object($root = $parser->parseFile(uniqid()))->isInstanceOf('mageekguy\atoum\template')
  484. ->array($root->getChildren())->hasSize(3)
  485. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\data')
  486. ->string($root->getChild(0)->getData())->isEqualTo($string1)
  487. ->object($root->getChild(1))->isInstanceOf('mageekguy\atoum\template\tag')
  488. ->variable($root->getChild(1)->getId())->isNull()
  489. ->string($root->getChild(1)->getData())->isEmpty()
  490. ->integer($root->getChild(1)->getLine())->isEqualTo(1)
  491. ->integer($root->getChild(1)->getOffset())->isEqualTo(strlen($string1) + 1)
  492. ->object($root->getChild(2))->isInstanceOf('mageekguy\atoum\template\data')
  493. ->string($root->getChild(2)->getData())->isEqualTo($string2)
  494. ->if($adapter->file_get_contents = ($string1 = uniqid()) . '<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . ' id="' . ($id = uniqid()) . '">' . ($data = uniqid()) . '</' . template\parser::defaultNamespace . ':' . $tag . '>' . ($string2 = uniqid()))
  495. ->then
  496. ->object($root = $parser->parseFile(uniqid()))->isInstanceOf('mageekguy\atoum\template')
  497. ->array($root->getChildren())->hasSize(3)
  498. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\data')
  499. ->string($root->getChild(0)->getData())->isEqualTo($string1)
  500. ->object($root->getChild(1))->isInstanceOf('mageekguy\atoum\template\tag')
  501. ->string($root->getChild(1)->getId())->isEqualTo($id)
  502. ->string($root->getChild(1)->getData())->isEmpty()
  503. ->integer($root->getChild(1)->getLine())->isEqualTo(1)
  504. ->integer($root->getChild(1)->getOffset())->isEqualTo(strlen($string1) + 1)
  505. ->object($root->getChild(2))->isInstanceOf('mageekguy\atoum\template\data')
  506. ->string($root->getChild(2)->getData())->isEqualTo($string2)
  507. ->if($adapter->file_get_contents = ($string = str_repeat("\n", 6)) . '<' . template\parser::defaultNamespace . ':' . ($tag = uniqid()) . '/>')
  508. ->then
  509. ->object($root = $parser->parseFile(uniqid()))
  510. ->array($root->getChildren())->hasSize(2)
  511. ->object($root->getChild(0))->isInstanceOf('mageekguy\atoum\template\data')
  512. ->string($root->getChild(0)->getData())->isEqualTo($string)
  513. ->object($root->getChild(1))->isInstanceOf('mageekguy\atoum\template\tag')
  514. ->variable($root->getChild(1)->getId())->isNull()
  515. ->string($root->getChild(1)->getData())->isEmpty()
  516. ->integer($root->getChild(1)->getLine())->isEqualTo(7)
  517. ->integer($root->getChild(1)->getOffset())->isEqualTo(1)
  518. ;
  519. }
  520. }