DescriptionTest.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. /**
  3. * phpDocumentor Description Test
  4. *
  5. * PHP Version 5.3
  6. *
  7. * @author Vasil Rangelov <boen.robot@gmail.com>
  8. * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
  9. * @license http://www.opensource.org/licenses/mit-license.php MIT
  10. * @link http://phpdoc.org
  11. */
  12. namespace Barryvdh\Reflection\DocBlock;
  13. /**
  14. * Test class for \Barryvdh\Reflection\DocBlock\Description
  15. *
  16. * @author Vasil Rangelov <boen.robot@gmail.com>
  17. * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
  18. * @license http://www.opensource.org/licenses/mit-license.php MIT
  19. * @link http://phpdoc.org
  20. */
  21. class DescriptionTest extends \PHPUnit_Framework_TestCase
  22. {
  23. public function testConstruct()
  24. {
  25. $fixture = <<<LONGDESC
  26. This is text for a description.
  27. LONGDESC;
  28. $object = new Description($fixture);
  29. $this->assertSame($fixture, $object->getContents());
  30. $parsedContents = $object->getParsedContents();
  31. $this->assertCount(1, $parsedContents);
  32. $this->assertSame($fixture, $parsedContents[0]);
  33. }
  34. public function testInlineTagParsing()
  35. {
  36. $fixture = <<<LONGDESC
  37. This is text for a {@link http://phpdoc.org/ description} that uses inline
  38. tags.
  39. LONGDESC;
  40. $object = new Description($fixture);
  41. $this->assertSame($fixture, $object->getContents());
  42. $parsedContents = $object->getParsedContents();
  43. $this->assertCount(3, $parsedContents);
  44. $this->assertSame('This is text for a ', $parsedContents[0]);
  45. $this->assertInstanceOf(
  46. __NAMESPACE__ . '\Tag\LinkTag',
  47. $parsedContents[1]
  48. );
  49. $this->assertSame(
  50. ' that uses inline
  51. tags.',
  52. $parsedContents[2]
  53. );
  54. }
  55. public function testInlineTagAtStartParsing()
  56. {
  57. $fixture = <<<LONGDESC
  58. {@link http://phpdoc.org/ This} is text for a description that uses inline
  59. tags.
  60. LONGDESC;
  61. $object = new Description($fixture);
  62. $this->assertSame($fixture, $object->getContents());
  63. $parsedContents = $object->getParsedContents();
  64. $this->assertCount(3, $parsedContents);
  65. $this->assertSame('', $parsedContents[0]);
  66. $this->assertInstanceOf(
  67. __NAMESPACE__ . '\Tag\LinkTag',
  68. $parsedContents[1]
  69. );
  70. $this->assertSame(
  71. ' is text for a description that uses inline
  72. tags.',
  73. $parsedContents[2]
  74. );
  75. }
  76. public function testNestedInlineTagParsing()
  77. {
  78. $fixture = <<<LONGDESC
  79. This is text for a description with {@internal inline tag with
  80. {@link http://phpdoc.org another inline tag} in it}.
  81. LONGDESC;
  82. $object = new Description($fixture);
  83. $this->assertSame($fixture, $object->getContents());
  84. $parsedContents = $object->getParsedContents();
  85. $this->assertCount(3, $parsedContents);
  86. $this->assertSame(
  87. 'This is text for a description with ',
  88. $parsedContents[0]
  89. );
  90. $this->assertInstanceOf(
  91. __NAMESPACE__ . '\Tag',
  92. $parsedContents[1]
  93. );
  94. $this->assertSame('.', $parsedContents[2]);
  95. $parsedDescription = $parsedContents[1]->getParsedDescription();
  96. $this->assertCount(3, $parsedDescription);
  97. $this->assertSame("inline tag with\n", $parsedDescription[0]);
  98. $this->assertInstanceOf(
  99. __NAMESPACE__ . '\Tag\LinkTag',
  100. $parsedDescription[1]
  101. );
  102. $this->assertSame(' in it', $parsedDescription[2]);
  103. }
  104. public function testLiteralOpeningDelimiter()
  105. {
  106. $fixture = <<<LONGDESC
  107. This is text for a description containing { that is literal.
  108. LONGDESC;
  109. $object = new Description($fixture);
  110. $this->assertSame($fixture, $object->getContents());
  111. $parsedContents = $object->getParsedContents();
  112. $this->assertCount(1, $parsedContents);
  113. $this->assertSame($fixture, $parsedContents[0]);
  114. }
  115. public function testNestedLiteralOpeningDelimiter()
  116. {
  117. $fixture = <<<LONGDESC
  118. This is text for a description containing {@internal inline tag that has { that
  119. is literal}.
  120. LONGDESC;
  121. $object = new Description($fixture);
  122. $this->assertSame($fixture, $object->getContents());
  123. $parsedContents = $object->getParsedContents();
  124. $this->assertCount(3, $parsedContents);
  125. $this->assertSame(
  126. 'This is text for a description containing ',
  127. $parsedContents[0]
  128. );
  129. $this->assertInstanceOf(
  130. __NAMESPACE__ . '\Tag',
  131. $parsedContents[1]
  132. );
  133. $this->assertSame('.', $parsedContents[2]);
  134. $this->assertSame(
  135. array('inline tag that has { that
  136. is literal'),
  137. $parsedContents[1]->getParsedDescription()
  138. );
  139. }
  140. public function testLiteralClosingDelimiter()
  141. {
  142. $fixture = <<<LONGDESC
  143. This is text for a description with {} that is not a tag.
  144. LONGDESC;
  145. $object = new Description($fixture);
  146. $this->assertSame($fixture, $object->getContents());
  147. $parsedContents = $object->getParsedContents();
  148. $this->assertCount(1, $parsedContents);
  149. $this->assertSame(
  150. 'This is text for a description with } that is not a tag.',
  151. $parsedContents[0]
  152. );
  153. }
  154. public function testNestedLiteralClosingDelimiter()
  155. {
  156. $fixture = <<<LONGDESC
  157. This is text for a description with {@internal inline tag with {} that is not an
  158. inline tag}.
  159. LONGDESC;
  160. $object = new Description($fixture);
  161. $this->assertSame($fixture, $object->getContents());
  162. $parsedContents = $object->getParsedContents();
  163. $this->assertCount(3, $parsedContents);
  164. $this->assertSame(
  165. 'This is text for a description with ',
  166. $parsedContents[0]
  167. );
  168. $this->assertInstanceOf(
  169. __NAMESPACE__ . '\Tag',
  170. $parsedContents[1]
  171. );
  172. $this->assertSame('.', $parsedContents[2]);
  173. $this->assertSame(
  174. array('inline tag with } that is not an
  175. inline tag'),
  176. $parsedContents[1]->getParsedDescription()
  177. );
  178. }
  179. public function testInlineTagEscapingSequence()
  180. {
  181. $fixture = <<<LONGDESC
  182. This is text for a description with literal {{@}link}.
  183. LONGDESC;
  184. $object = new Description($fixture);
  185. $this->assertSame($fixture, $object->getContents());
  186. $parsedContents = $object->getParsedContents();
  187. $this->assertCount(1, $parsedContents);
  188. $this->assertSame(
  189. 'This is text for a description with literal {@link}.',
  190. $parsedContents[0]
  191. );
  192. }
  193. public function testNestedInlineTagEscapingSequence()
  194. {
  195. $fixture = <<<LONGDESC
  196. This is text for a description with an {@internal inline tag with literal
  197. {{@}link{} in it}.
  198. LONGDESC;
  199. $object = new Description($fixture);
  200. $this->assertSame($fixture, $object->getContents());
  201. $parsedContents = $object->getParsedContents();
  202. $this->assertCount(3, $parsedContents);
  203. $this->assertSame(
  204. 'This is text for a description with an ',
  205. $parsedContents[0]
  206. );
  207. $this->assertInstanceOf(
  208. __NAMESPACE__ . '\Tag',
  209. $parsedContents[1]
  210. );
  211. $this->assertSame('.', $parsedContents[2]);
  212. $this->assertSame(
  213. array('inline tag with literal
  214. {@link} in it'),
  215. $parsedContents[1]->getParsedDescription()
  216. );
  217. }
  218. }