KodocTest.php 5.7 KB

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