11_tipitaka_chapters.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. use \WikipaliApi\Api\TipitakaChaptersApi;
  3. /*
  4. * 章节标题:GET /v3/tipitaka-chapters
  5. *
  6. * 只读、无写操作。用长部《大般涅槃经》(book 94 para 287)——CST 三藏的坐标在各服务器上相同。
  7. * 容错打分的各档、译名可见性、layer 过滤由 api-v13 的 TipitakaChapterV3Test 覆盖。
  8. */
  9. test('GET /v3/tipitaka-chapters?q=(不带变音符号、拼错)→ 200,找到大般涅槃经', function () {
  10. $res = request(fn () => api(TipitakaChaptersApi::class)
  11. ->getApiV3TipitakaChaptersWithHttpInfo(1, 5, 'mahaparinibanasuta', null, null, 'mula'));
  12. assert_status(200, $res, 'tipitaka-chapters q');
  13. $top = $res['body']['data'][0] ?? null;
  14. if (! $top) {
  15. fail('tipitaka-chapters:拼错的经名应能找到');
  16. }
  17. assert_eq(94, $top['book'] ?? null, 'book');
  18. assert_eq(287, $top['para'] ?? null, 'para');
  19. assert_eq('mula', $top['layer'] ?? null, 'layer');
  20. foreach (['title', 'translations', 'paragraphs', 'chars', 'path', 'score'] as $key) {
  21. assert_has_key($key, $top, 'tipitaka-chapters 行');
  22. }
  23. });
  24. test('GET /v3/tipitaka-chapters?book=&para= → 200,按经文顺序列出这一章下面的标题', function () {
  25. $res = raw('GET', '/v3/tipitaka-chapters', ['book' => 94, 'para' => 287, 'per_page' => 1000]);
  26. assert_status(200, $res, 'tipitaka-chapters book');
  27. $paras = array_column($res['body']['data'] ?? [], 'para');
  28. assert_eq(287, $paras[0] ?? null, '第一条是这一章自己');
  29. $sorted = $paras;
  30. sort($sorted);
  31. assert_eq($sorted, $paras, '按段号升序');
  32. if (! in_array(585, $paras, true)) {
  33. fail('tipitaka-chapters:应包含小节 94:585(Tathāgatapacchimavācā)');
  34. }
  35. });
  36. test('GET /v3/tipitaka-chapters(q 与 book 都不给)→ 422', function () {
  37. $res = raw('GET', '/v3/tipitaka-chapters');
  38. assert_status(422, $res, '无条件');
  39. });