KodocTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <?php
  2. /**
  3. * @group kohana
  4. * @group kohana.userguide
  5. *
  6. * @package Kohana/Userguide
  7. * @author Kohana Team
  8. * @copyright (c) Kohana Team
  9. * @license https://koseven.ga/LICENSE.md
  10. */
  11. class Kohana_KodocTest extends Unittest_TestCase
  12. {
  13. public function provider_parse_basic()
  14. {
  15. return [
  16. [
  17. <<<'COMMENT'
  18. /**
  19. * Description
  20. */
  21. COMMENT
  22. ,
  23. ["<p>Description</p>\n", []],
  24. ],
  25. [
  26. <<<'COMMENT'
  27. /**
  28. * Description spanning
  29. * multiple lines
  30. */
  31. COMMENT
  32. ,
  33. ["<p>Description spanning\nmultiple lines</p>\n", []],
  34. ],
  35. [
  36. <<<'COMMENT'
  37. /**
  38. * Description including
  39. *
  40. * a code block
  41. */
  42. COMMENT
  43. ,
  44. ["<p>Description including</p>\n\n<pre><code>a code block\n</code></pre>\n", []],
  45. ],
  46. [
  47. <<<'COMMENT'
  48. /**
  49. * Indented
  50. */
  51. COMMENT
  52. ,
  53. ["<p>Indented</p>\n", []],
  54. ],
  55. [
  56. <<<'COMMENT'
  57. /**
  58. * @tag Content
  59. */
  60. COMMENT
  61. ,
  62. ['', ['tag' => ['Content']]],
  63. ],
  64. [
  65. <<<'COMMENT'
  66. /**
  67. * @tag Multiple
  68. * @tag Tags
  69. */
  70. COMMENT
  71. ,
  72. ['', ['tag' => ['Multiple', 'Tags']]],
  73. ],
  74. [
  75. <<<'COMMENT'
  76. /**
  77. * Description with tag
  78. * @tag Content
  79. */
  80. COMMENT
  81. ,
  82. [
  83. "<p>Description with tag</p>\n",
  84. ['tag' => ['Content']],
  85. ],
  86. ],
  87. [
  88. <<<'COMMENT'
  89. /**
  90. * @trailingspace
  91. */
  92. COMMENT
  93. ,
  94. ['', ['trailingspace' => ['']]],
  95. ],
  96. [
  97. <<<'COMMENT'
  98. /**
  99. * @tag Content that spans
  100. * multiple lines
  101. */
  102. COMMENT
  103. ,
  104. [
  105. '',
  106. ['tag' => ["Content that spans\nmultiple lines"]],
  107. ],
  108. ],
  109. [
  110. <<<'COMMENT'
  111. /**
  112. * @tag Content that spans
  113. * multiple lines indented
  114. */
  115. COMMENT
  116. ,
  117. [
  118. '',
  119. ['tag' => ["Content that spans\n multiple lines indented"]],
  120. ],
  121. ],
  122. ];
  123. }
  124. /**
  125. * @covers Kohana_Kodoc::parse
  126. *
  127. * @dataProvider provider_parse_basic
  128. *
  129. * @param string $comment Argument to the method
  130. * @param array $expected Expected result
  131. */
  132. public function test_parse_basic($comment, $expected)
  133. {
  134. $this->assertSame($expected, Kodoc::parse($comment));
  135. }
  136. public function provider_parse_tags()
  137. {
  138. $route_api = Route::get('docs/api');
  139. return [
  140. [
  141. <<<'COMMENT'
  142. /**
  143. * @access public
  144. */
  145. COMMENT
  146. ,
  147. ['', []],
  148. ],
  149. [
  150. <<<'COMMENT'
  151. /**
  152. * @copyright Some plain text
  153. */
  154. COMMENT
  155. ,
  156. ['', ['copyright' => ['Some plain text']]],
  157. ],
  158. [
  159. <<<'COMMENT'
  160. /**
  161. * @copyright (c) 2008-2017 Kohana Team
  162. */
  163. COMMENT
  164. ,
  165. ['', ['copyright' => ['&copy; 2008-2017 Kohana Team']]],
  166. ],
  167. [
  168. <<<'COMMENT'
  169. /**
  170. * @license Kohana
  171. */
  172. COMMENT
  173. ,
  174. ['', ['license' => ['Kohana']]],
  175. ],
  176. [
  177. <<<'COMMENT'
  178. /**
  179. * @license http://kohanaframework.org/license
  180. */
  181. COMMENT
  182. ,
  183. ['', ['license' => ['<a href="http://kohanaframework.org/license">http://kohanaframework.org/license</a>']]],
  184. ],
  185. [
  186. <<<'COMMENT'
  187. /**
  188. * @link http://kohanaframework.org
  189. */
  190. COMMENT
  191. ,
  192. ['', ['link' => ['<a href="http://kohanaframework.org">http://kohanaframework.org</a>']]],
  193. ],
  194. [
  195. <<<'COMMENT'
  196. /**
  197. * @link http://kohanaframework.org Description
  198. */
  199. COMMENT
  200. ,
  201. ['', ['link' => ['<a href="http://kohanaframework.org">Description</a>']]],
  202. ],
  203. [
  204. <<<'COMMENT'
  205. /**
  206. * @see MyClass
  207. */
  208. COMMENT
  209. ,
  210. [
  211. '',
  212. [
  213. 'see' => [
  214. '<a href="'.URL::site(
  215. $route_api->uri(['class' => 'MyClass'])
  216. ).'">MyClass</a>',
  217. ],
  218. ],
  219. ],
  220. ],
  221. [
  222. <<<'COMMENT'
  223. /**
  224. * @see MyClass::method()
  225. */
  226. COMMENT
  227. ,
  228. [
  229. '',
  230. [
  231. 'see' => [
  232. '<a href="'.URL::site(
  233. $route_api->uri(['class' => 'MyClass']).'#method'
  234. ).'">MyClass::method()</a>',
  235. ],
  236. ],
  237. ],
  238. ],
  239. [
  240. <<<'COMMENT'
  241. /**
  242. * @throws Exception
  243. */
  244. COMMENT
  245. ,
  246. [
  247. '',
  248. [
  249. 'throws' => [
  250. '<a href="'.URL::site(
  251. $route_api->uri(['class' => 'Exception'])
  252. ).'">Exception</a>',
  253. ],
  254. ],
  255. ],
  256. ],
  257. [
  258. <<<'COMMENT'
  259. /**
  260. * @throws Exception During failure
  261. */
  262. COMMENT
  263. ,
  264. [
  265. '',
  266. [
  267. 'throws' => [
  268. '<a href="'.URL::site(
  269. $route_api->uri(['class' => 'Exception'])
  270. ).'">Exception</a> During failure',
  271. ],
  272. ],
  273. ],
  274. ],
  275. [
  276. <<<'COMMENT'
  277. /**
  278. * @uses MyClass
  279. */
  280. COMMENT
  281. ,
  282. [
  283. '',
  284. [
  285. 'uses' => [
  286. '<a href="'.URL::site(
  287. $route_api->uri(['class' => 'MyClass'])
  288. ).'">MyClass</a>',
  289. ],
  290. ],
  291. ],
  292. ],
  293. [
  294. <<<'COMMENT'
  295. /**
  296. * @uses MyClass::method()
  297. */
  298. COMMENT
  299. ,
  300. [
  301. '',
  302. [
  303. 'uses' => [
  304. '<a href="'.URL::site(
  305. $route_api->uri(['class' => 'MyClass']).'#method'
  306. ).'">MyClass::method()</a>',
  307. ],
  308. ],
  309. ],
  310. ],
  311. ];
  312. }
  313. /**
  314. * @covers Kohana_Kodoc::format_tag
  315. * @covers Kohana_Kodoc::parse
  316. *
  317. * @dataProvider provider_parse_tags
  318. *
  319. * @param string $comment Argument to the method
  320. * @param array $expected Expected result
  321. */
  322. public function test_parse_tags($comment, $expected)
  323. {
  324. $this->assertSame($expected, Kodoc::parse($comment));
  325. }
  326. /**
  327. * Provides test data for test_transparent_classes
  328. * @return array
  329. */
  330. public function provider_transparent_classes()
  331. {
  332. return [
  333. // Kohana_Core is a special case
  334. ['Kohana','Kohana_Core',NULL],
  335. ['Controller_Template','Kohana_Controller_Template',NULL],
  336. ['Controller_Template','Kohana_Controller_Template',
  337. ['Kohana_Controller_Template'=>'Kohana_Controller_Template',
  338. 'Controller_Template'=>'Controller_Template']
  339. ],
  340. [FALSE,'Kohana_Controller_Template',
  341. ['Kohana_Controller_Template'=>'Kohana_Controller_Template']],
  342. [FALSE,'Controller_Template',NULL],
  343. ];
  344. }
  345. /**
  346. * Tests Kodoc::is_transparent
  347. *
  348. * Checks that a selection of transparent and non-transparent classes give expected results
  349. *
  350. * @group kohana.userguide.3529-configurable-transparent-classes
  351. * @dataProvider provider_transparent_classes
  352. * @param mixed $expected
  353. * @param string $class
  354. * @param array $classes
  355. */
  356. public function test_transparent_classes($expected, $class, $classes)
  357. {
  358. $result = Kodoc::is_transparent($class, $classes);
  359. $this->assertSame($expected,$result);
  360. }
  361. }