MarkupTemplateDataTest.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <?php
  2. use App\Models\Article;
  3. use App\Models\BookTitle;
  4. use App\Models\Channel;
  5. use App\Models\DhammaTerm;
  6. use App\Models\Discussion;
  7. use App\Models\PaliText;
  8. use App\Services\Markup\Format;
  9. use App\Services\Markup\MarkupService;
  10. use App\Services\Markup\RenderOptions;
  11. use Illuminate\Foundation\Testing\RefreshDatabase;
  12. use Illuminate\Support\Facades\DB;
  13. use Illuminate\Support\Str;
  14. uses(RefreshDatabase::class);
  15. /**
  16. * App\Services\Markup 里要查库的模板:术语、句子、quote、ql、qa、Tpl、g、ref,以及批量取数、逐段对读、嵌套层数。
  17. */
  18. function markupDataTree(string $source, array $options = []): array
  19. {
  20. return json_decode(json_encode(app(MarkupService::class)->render($source, new RenderOptions(...$options))), true);
  21. }
  22. function markupDataRender(string $source, Format $format, array $options = []): string
  23. {
  24. return app(MarkupService::class)->render($source, new RenderOptions(...array_merge($options, ['format' => $format])));
  25. }
  26. function makeMarkupTerm(array $attrs): DhammaTerm
  27. {
  28. $term = new DhammaTerm;
  29. $term->forceFill(array_merge([
  30. 'id' => random_int(1, PHP_INT_MAX),
  31. 'guid' => (string) Str::uuid(),
  32. 'word_en' => $attrs['word'],
  33. 'meaning' => '',
  34. 'language' => 'zh-Hans',
  35. 'editor_id' => 0,
  36. 'create_time' => time() * 1000,
  37. 'modify_time' => time() * 1000,
  38. ], $attrs))->save();
  39. return $term;
  40. }
  41. /**
  42. * root 名下的系统 channel。
  43. */
  44. function makeSystemChannel(string $name, string $type = 'translation', string $lang = 'en'): string
  45. {
  46. $uid = makeChannel(config('mint.admin.root_uuid'), $name);
  47. Channel::where('uid', $uid)->update(['type' => $type, 'lang' => $lang]);
  48. return $uid;
  49. }
  50. beforeEach(function () {
  51. $this->owner = makeStudio('markup-owner');
  52. $this->channel = makeChannel($this->owner, 'markup channel');
  53. });
  54. describe('term', function () {
  55. it('finds the channel own term', function () {
  56. makeMarkupTerm(['word' => 'dhamma', 'meaning' => '法', 'other_meaning' => '正法', 'channal' => $this->channel, 'owner' => $this->owner]);
  57. $tree = markupDataTree('[[dhamma]]', ['channels' => [$this->channel]]);
  58. expect($tree[0]['props'])->toMatchArray([
  59. 'word' => 'dhamma',
  60. 'meaning' => '法',
  61. 'meaning2' => '正法',
  62. 'channel' => $this->channel,
  63. 'parentChannelId' => $this->channel,
  64. 'parentStudioId' => $this->owner,
  65. ]);
  66. expect($tree[0]['children'])->toBe([['type' => 'text', 'value' => '法(dhamma)']]);
  67. });
  68. it('falls back to the studio term in the same language before the language family', function () {
  69. makeMarkupTerm(['word' => 'sati', 'meaning' => '念-繁', 'language' => 'zh-Hant', 'owner' => $this->owner]);
  70. makeMarkupTerm(['word' => 'sati', 'meaning' => '念', 'language' => 'zh-Hans', 'owner' => $this->owner]);
  71. makeMarkupTerm(['word' => 'sati', 'meaning' => 'mindfulness', 'language' => 'en', 'owner' => $this->owner]);
  72. expect(markupDataTree('[[sati]]', ['channels' => [$this->channel]])[0]['props']['meaning'])->toBe('念');
  73. });
  74. it('falls back to the community term channel', function () {
  75. $community = makeSystemChannel('_community_term_zh-hans_');
  76. makeMarkupTerm(['word' => 'kusala', 'meaning' => '善', 'channal' => $community, 'owner' => config('mint.admin.root_uuid')]);
  77. $props = markupDataTree('{{term|kusala}}', ['channels' => [$this->channel]])[0]['props'];
  78. expect($props)->toMatchArray(['meaning' => '善', 'isCommunity' => true]);
  79. // HTML 带上社区标记,library 百科页据此着绿色(与 v6 术语组件一致)
  80. expect(markupDataRender('{{term|kusala}}', Format::Html, ['channels' => [$this->channel]]))
  81. ->toContain('class="term-ref term_community"');
  82. });
  83. it('filters by tag with word@tag and overrides the label with word#text', function () {
  84. makeMarkupTerm(['word' => 'sutta', 'meaning' => '经', 'tag' => 'a', 'channal' => $this->channel, 'owner' => $this->owner]);
  85. makeMarkupTerm(['word' => 'sutta', 'meaning' => '契经', 'tag' => 'b', 'channal' => $this->channel, 'owner' => $this->owner]);
  86. expect(markupDataTree('[[sutta@b]]', ['channels' => [$this->channel]])[0]['props']['meaning'])->toBe('契经');
  87. expect(markupDataTree('[[sutta@a#经文]]', ['channels' => [$this->channel]])[0]['props']['meaning'])->toBe('经文');
  88. });
  89. it('leaves the term note out of the tree but renders it, with its own templates, in markdown', function () {
  90. makeMarkupTerm(['word' => 'magga', 'meaning' => '道', 'note' => '见 [[nibbāna]]', 'channal' => $this->channel, 'owner' => $this->owner]);
  91. makeMarkupTerm(['word' => 'nibbāna', 'meaning' => '涅槃', 'channal' => $this->channel, 'owner' => $this->owner]);
  92. // 前端术语组件自己取词条详情,note 不随正文下发
  93. expect(markupDataTree('[[magga]]', ['channels' => [$this->channel]])[0]['props'])->not->toHaveKey('note');
  94. expect(markupDataRender('[[magga]]', Format::Markdown, ['channels' => [$this->channel], 'footnote' => true]))
  95. ->toBe("道(magga)[^1]\n\n[^1]: 见 涅槃(nibbāna)");
  96. });
  97. it('expands term notes only one level deep', function () {
  98. makeMarkupTerm(['word' => 'a', 'meaning' => '甲', 'note' => '甲注 [[b]]', 'channal' => $this->channel, 'owner' => $this->owner]);
  99. makeMarkupTerm(['word' => 'b', 'meaning' => '乙', 'note' => '乙注 [[c]]', 'channal' => $this->channel, 'owner' => $this->owner]);
  100. makeMarkupTerm(['word' => 'c', 'meaning' => '丙', 'channal' => $this->channel, 'owner' => $this->owner]);
  101. // 甲的 note 里的乙只出译名,不再展开乙注(否则词条互相引用会成倍膨胀)
  102. expect(markupDataRender('[[a]]', Format::Markdown, ['channels' => [$this->channel], 'footnote' => true]))
  103. ->toBe("甲(a)[^1]\n\n[^1]: 甲注 乙(b)");
  104. });
  105. it('renders terms per format', function () {
  106. makeMarkupTerm(['word' => 'dhamma', 'meaning' => '法', 'note' => '注', 'channal' => $this->channel, 'owner' => $this->owner]);
  107. $options = ['channels' => [$this->channel]];
  108. expect(markupDataRender('[[dhamma]]', Format::Text, $options))->toBe('法');
  109. expect(markupDataRender('[[dhamma]]', Format::Html, $options))
  110. ->toMatch('/^<span><span class="term-ref" data-id="[0-9a-f-]{36}" data-term="dhamma">法<\/span><\/span>$/');
  111. expect(markupDataRender('[[dhamma]]与[[dhamma]]', Format::Markdown, $options + ['footnote' => true]))
  112. ->toBe("法(dhamma)[^1]与法\n\n[^1]: 注");
  113. });
  114. it('looks up all terms of a document with a constant number of queries', function () {
  115. $words = [];
  116. foreach (range(1, 30) as $i) {
  117. makeMarkupTerm(['word' => "w{$i}", 'meaning' => "义{$i}", 'channal' => $this->channel, 'owner' => $this->owner]);
  118. $words[] = "[[w{$i}]]";
  119. }
  120. makeSystemChannel('_community_term_zh-hans_');
  121. DB::enableQueryLog();
  122. $tree = markupDataTree(implode(' ', $words), ['channels' => [$this->channel]]);
  123. $queries = count(DB::getQueryLog());
  124. DB::disableQueryLog();
  125. expect(collect($tree)->where('type', 'tpl')->pluck('props.meaning')->all())->toHaveCount(30)->toContain('义30');
  126. // channel、本 channel 术语、studio 术语、社区 channel、社区术语
  127. expect($queries)->toBeLessThanOrEqual(6);
  128. });
  129. });
  130. describe('sent', function () {
  131. beforeEach(function () {
  132. $this->pali = makeSystemChannel('_System_Pali_VRI_', 'original', 'pi');
  133. makeSentence($this->pali, 999, 1, 1, '<span>Evaṃ me sutaṃ</span>');
  134. makeSentence($this->channel, 999, 1, 1, '如是我闻[[dhamma]]');
  135. makeMarkupTerm(['word' => 'dhamma', 'meaning' => '法', 'channal' => $this->channel, 'owner' => $this->owner]);
  136. });
  137. it('renders origin and translation bodies with the row channel', function () {
  138. $props = markupDataTree('{{999-1-1-1}}', ['channels' => [$this->channel]])[0]['props'];
  139. // 只给渲染要用的:坐标在 id 里,原文 / 译文已分组(不给 channel.type),没有义注就不给 commentaries
  140. expect(array_keys($props))->toBe(['id', 'show', 'origin', 'translation']);
  141. expect($props)->toMatchArray(['id' => '999-1-1-1', 'show' => 'both']);
  142. expect($props['origin'][0]['channel'])->toBe(['id' => $this->pali, 'name' => '_System_Pali_VRI_', 'lang' => 'pi']);
  143. expect(array_keys($props['origin'][0]))->toBe(['id', 'channel', 'body']);
  144. expect($props['origin'][0]['body'][0])->toMatchArray(['type' => 'el', 'tag' => 'span']);
  145. expect($props['translation'][0]['body'][1]['name'])->toBe('term');
  146. expect($props['translation'][0]['body'][1]['props']['meaning'])->toBe('法');
  147. expect($props['translation'][0])->not->toHaveKey('content');
  148. });
  149. it('includes the source content in edit mode', function () {
  150. $wbw = makeSystemChannel('_System_Wbw_VRI_', 'wbw', 'pi');
  151. makeSentence($wbw, 999, 1, 1, 'wbw text');
  152. $tree = markupDataTree('{{999-1-1-1}}', ['channels' => [$this->channel], 'mode' => 'edit']);
  153. expect($tree[0]['name'])->toBe('sentedit');
  154. expect($tree[0]['props']['translation'][0]['content'])->toBe('如是我闻[[dhamma]]');
  155. expect($tree[0]['props']['translation'][0]['contentType'])->toBe('markdown');
  156. expect($tree[0]['props']['origin'][0]['channel']['id'])->toBe($wbw);
  157. });
  158. it('reads a single channel with id@channel', function () {
  159. $other = makeChannel($this->owner, 'other');
  160. makeSentence($other, 999, 1, 1, '另一译');
  161. $props = markupDataTree("{{999-1-1-1@{$other}}}", ['channels' => [$this->channel]])[0]['props'];
  162. expect(array_column(array_column($props['translation'], 'channel'), 'id'))->toBe([$other]);
  163. });
  164. it('renders sentences per format and honours text=', function () {
  165. $options = ['channels' => [$this->channel]];
  166. expect(markupDataRender('{{999-1-1-1}}', Format::Html, $options))
  167. ->toBe('<span><span class="sentence"><span class="origin"><span><span>Evaṃ me sutaṃ</span></span></span>'
  168. .'<span class="translation"><span>如是我闻<span class="term-ref" data-id="'
  169. .DhammaTerm::where('word', 'dhamma')->value('guid').'" data-term="dhamma">法</span></span></span></span></span>');
  170. expect(markupDataRender('{{sent|id=999-1-1-1|text=translation}}', Format::Text, $options))->toBe('如是我闻法');
  171. expect(markupDataRender('{{999-1-1-1}}', Format::Simple, $options))->toBe('Evaṃ me sutaṃ如是我闻法');
  172. expect(markupDataRender('{{999-1-1-1}}', Format::Markdown, $options + ['origin' => false]))->toBe('如是我闻法(dhamma)');
  173. });
  174. it('renders a markdown-e2 sentence with code instead of notes', function () {
  175. DB::table('sentences')->where('channel_uid', $this->channel)->update(['content' => '用 `code`', 'content_type' => 'markdown-e2']);
  176. $body = markupDataTree('{{999-1-1-1}}', ['channels' => [$this->channel]])[0]['props']['translation'][0]['body'];
  177. expect($body[1])->toMatchArray(['type' => 'el', 'tag' => 'code']);
  178. });
  179. it('renders sentences inside raw html blocks', function () {
  180. $tree = markupDataTree("<nt>\n{{999-1-1-1}}\n</nt>", ['channels' => [$this->channel]]);
  181. expect($tree[0]['attrs']['data-tag'])->toBe('nt');
  182. $sent = collect($tree[0]['children'])->firstWhere('type', 'tpl');
  183. expect($sent['props']['translation'][0]['body'][0]['value'])->toBe('如是我闻');
  184. });
  185. it('duplicates sentence-only paragraphs in paragraph mode', function () {
  186. $tree = markupDataTree("{{999-1-1-1}}\n\n正文", ['channels' => [$this->channel], 'paragraph' => true]);
  187. expect(array_column($tree, 'tag'))->toBe(['p', 'p', 'p']);
  188. expect($tree[0]['children'][0]['props']['show'])->toBe('origin');
  189. expect($tree[1]['children'][0]['props']['show'])->toBe('translation');
  190. });
  191. it('loads all sentences of a document in one query', function () {
  192. foreach (range(2, 20) as $start) {
  193. makeSentence($this->channel, 999, 1, $start, "句{$start}");
  194. }
  195. $source = implode('', array_map(fn ($start) => "{{999-1-{$start}-{$start}}}", range(1, 20)));
  196. DB::enableQueryLog();
  197. markupDataTree($source, ['channels' => [$this->channel]]);
  198. $sentenceQueries = collect(DB::getQueryLog())->filter(fn ($q) => str_contains($q['query'], 'from "sentences"'))->count();
  199. DB::disableQueryLog();
  200. expect($sentenceQueries)->toBe(1);
  201. });
  202. it('stops nesting content that refers to itself', function () {
  203. DB::table('sentences')->where('channel_uid', $this->channel)->update(['content' => '自引{{999-1-1-1}}']);
  204. $tree = markupDataTree('{{999-1-1-1}}', ['channels' => [$this->channel]]);
  205. $json = json_encode($tree, JSON_UNESCAPED_UNICODE);
  206. // 文章 → 句子正文 → 句子正文,第 3 层不再展开
  207. expect(substr_count($json, '自引'))->toBe(2);
  208. expect($json)->toContain('"body":null');
  209. });
  210. it('lists referenced books with ref', function () {
  211. BookTitle::forceCreate(['book' => 999, 'paragraph' => 0, 'title' => 'dīghanikāya', 'sn' => 1]);
  212. $props = markupDataTree("{{999-1-1-1}}\n\n{{ref}}", ['channels' => [$this->channel]])[1]['children'][0]['props'];
  213. expect($props['pali'])->toBe([['sn' => 1, 'title' => 'dīghanikāya', 'copyright' => 'CSCD V4 VRI 2008']]);
  214. expect(markupDataRender("{{999-1-1-1}}\n\n{{ref}}", Format::Markdown, ['channels' => [$this->channel]]))
  215. ->toEndWith("[1] **Dīghanikāya** CSCD V4 VRI 2008\n\n");
  216. });
  217. });
  218. describe('templates reading other tables', function () {
  219. it('renders quote with the paragraph toc', function () {
  220. (new PaliText)->forceFill([
  221. 'book' => 9001, 'paragraph' => 3, 'level' => 2, 'class' => '', 'toc' => 'Brahmajālasutta',
  222. 'text' => '', 'html' => '', 'path' => json_encode([['title' => 'dīgha']]), 'uid' => (string) Str::uuid(),
  223. ])->save();
  224. expect(markupDataTree('{{quote|9001-3}}', ['channels' => [$this->channel]])[0]['props'])
  225. ->toBe(['paraId' => '9001-3', 'pali' => 'Brahmajālasutta']);
  226. expect(markupDataRender('{{quote|9001-3}}', Format::Text))->toBe('Brahmajālasutta');
  227. expect(markupDataRender('{{quote|9001-404}}', Format::Text))->toBe('9001-404');
  228. });
  229. it('renders qa with the discussion title', function () {
  230. $qa = Discussion::forceCreate([
  231. 'res_type' => 'sentence', 'res_id' => (string) Str::uuid(), 'type' => 'qa',
  232. 'title' => '为什么?', 'content' => 'body', 'editor_uid' => $this->owner,
  233. ]);
  234. $props = markupDataTree("{{qa|{$qa->id}}}")[0]['props'];
  235. expect($props)->toBe(['id' => $qa->id, 'title' => '为什么?', 'resType' => 'sentence']);
  236. });
  237. it('renders Tpl articles with mustache params', function () {
  238. (new Article)->forceFill([
  239. 'id' => random_int(1, PHP_INT_MAX), 'uid' => (string) Str::uuid(), 'title' => 'Tpl:greet',
  240. 'content' => 'Hello **{{1}}** from {{place}}', 'owner' => $this->owner, 'owner_id' => 0, 'editor_id' => 0,
  241. 'create_time' => time() * 1000, 'modify_time' => time() * 1000,
  242. ])->save();
  243. $tree = markupDataTree('{{Tpl:greet|Ānanda|place=Sāvatthī}}');
  244. expect($tree[0])->toMatchArray(['name' => 'tpl', 'props' => ['name' => 'Tpl:greet']]);
  245. expect($tree[0]['children'][1])->toMatchArray(['tag' => 'strong']);
  246. expect(markupDataRender('{{Tpl:greet|Ānanda|place=Sāvatthī}}', Format::Text))->toBe('Hello Ānanda from Sāvatthī');
  247. expect(markupDataTree('{{Tpl:missing}}')[0]['children'])->toBe([]);
  248. });
  249. it('renders grammar lookups from the system grammar channel', function () {
  250. $grammar = makeSystemChannel('_System_Grammar_Term_en_');
  251. makeMarkupTerm(['word' => 'nom', 'meaning' => 'nominative', 'channal' => $grammar, 'owner' => config('mint.admin.root_uuid')]);
  252. $props = markupDataTree('{{g|nom}}', ['channels' => [$this->channel]])[0]['props'];
  253. expect($props['word'])->toBe('nom');
  254. expect($props['term'])->toMatchArray(['meaning' => 'nominative', 'channel' => $grammar]);
  255. });
  256. it('renders quote-link with a localized book name', function () {
  257. makeMarkupTerm(['word' => 'dīghanikāya', 'meaning' => '长部', 'tag' => ':quote:', 'channal' => $this->channel, 'owner' => $this->owner]);
  258. $tree = markupDataTree('{{ql|type=m|bookname=dīghanikāya|volume=1|page=23}}', ['channels' => [$this->channel]]);
  259. expect($tree[0]['name'])->toBe('quote-link');
  260. expect($tree[0]['props'])->toMatchArray(['type' => 'm', 'bookName' => 'dīghanikāya', 'volume' => 1, 'page' => '23']);
  261. expect($tree[0]['props'])->not->toHaveKey('bookNameLocal');
  262. expect($tree[0]['props']['term']['meaning'])->toBe('长部');
  263. expect(markupDataRender('{{ql|type=m|bookname=dīghanikāya|volume=1|page=23}}', Format::Text, ['channels' => [$this->channel]]))
  264. ->toBe('长部 1.23');
  265. });
  266. it('renders nissaya with the channel language', function () {
  267. Channel::where('uid', $this->channel)->update(['lang' => 'my']);
  268. expect(markupDataTree('{{nissaya|evaṃ|ဤသို့}}', ['channels' => [$this->channel]])[0]['props'])->toBe(['pali' => 'evaṃ', 'meaning' => ['ဤသို့']]);
  269. expect(markupDataRender('{{nissaya|evaṃ|ဤသို့}}', Format::Html, ['channels' => [$this->channel]]))
  270. ->toBe('<span><span lang="pi-Mymr">evaṃ</span>၊ <span lang="my">ဤသို့</span></span>');
  271. });
  272. });
  273. describe('ref', function () {
  274. beforeEach(function () {
  275. // book 998 收了两部作品:第 1 段起是 first work,第 10 段起是 second work;book 997 一部
  276. BookTitle::forceCreate(['book' => 998, 'paragraph' => 1, 'title' => 'first work', 'sn' => 1]);
  277. BookTitle::forceCreate(['book' => 998, 'paragraph' => 10, 'title' => 'second work', 'sn' => 2]);
  278. BookTitle::forceCreate(['book' => 997, 'paragraph' => 1, 'title' => 'third work', 'sn' => 3]);
  279. });
  280. $titles = function (array $tree): array {
  281. $find = function (array $nodes) use (&$find): ?array {
  282. foreach ($nodes as $node) {
  283. if (($node['name'] ?? null) === 'reference') {
  284. return $node;
  285. }
  286. if (($found = $find($node['children'] ?? [])) !== null) {
  287. return $found;
  288. }
  289. }
  290. return null;
  291. };
  292. return array_column($find($tree)['props']['pali'] ?? [], 'title');
  293. };
  294. it('collects references from para, quote, ql with book and para, and chapter articles', function () use ($titles) {
  295. $source = '{{para|id=998-12|title=t}} {{quote|997-3}} {{ql|type=m|book=998|para=2}} '
  296. .'{{article|type=chapter|book=998|paragraphs=15}} {{ql|type=m|bookname=x|volume=1|page=2}}{{ref}}';
  297. expect($titles(markupDataTree($source)))->toBe(['second work', 'third work', 'first work']);
  298. });
  299. it('collects references from chapter, by id or by book and para', function () use ($titles) {
  300. expect($titles(markupDataTree('{{chapter|998-12}} {{chapter|book=997|para=3}}{{ref}}')))
  301. ->toBe(['second work', 'third work']);
  302. expect($titles(markupDataTree('{{chapter|title=t}}{{ref}}')))->toBe([]);
  303. });
  304. it('picks the nearest title, counting a reference to the first paragraph of a work', function () use ($titles) {
  305. expect($titles(markupDataTree('{{para|id=998-10}}{{ref}}')))->toBe(['second work']);
  306. expect($titles(markupDataTree('{{para|id=998-9}}{{ref}}')))->toBe(['first work']);
  307. expect($titles(markupDataTree('{{para|id=998-0}}{{ref}}')))->toBe([]);
  308. });
  309. it('lists every reference wherever {{ref}} is placed', function () use ($titles) {
  310. expect($titles(markupDataTree("{{ref}}\n\n{{para|id=997-5}}\n\n{{998-12-1-2}}")))->toBe(['third work', 'second work']);
  311. });
  312. it('gives the list its own title, like {{toc}}', function () {
  313. $ref = fn (string $source) => collect(markupDataTree($source))->firstWhere('name', 'reference')
  314. ?? collect(markupDataTree($source))->pluck('children')->flatten(1)->firstWhere('name', 'reference');
  315. expect($ref('{{para|id=997-5}}{{ref}}')['props'])->toMatchArray(['title' => '参考文献']);
  316. expect($ref('{{para|id=997-5}}{{ref|title=引用书目}}')['props']['title'])->toBe('引用书目');
  317. expect($ref('{{para|id=997-5}}{{ref|title=}}')['props'])->not->toHaveKey('title');
  318. // 紧跟在手写的「## 参考文献」后面:不再显示第二个标题
  319. expect($ref("{{para|id=997-5}}\n\n## 参考文献\n\n{{ref}}")['props'])->not->toHaveKey('title');
  320. // 没有引用:整块不输出,也没有标题
  321. expect($ref('{{ref}}')['props'])->toBe(['pali' => []]);
  322. expect(markupDataRender('{{ref}}', Format::Html))->toBe('');
  323. });
  324. it('renders the title in html, text and markdown', function () {
  325. expect(markupDataRender('{{para|id=997-5}}{{ref}}', Format::Text))->toBe("参考文献\n[1] Third work CSCD V4 VRI 2008\n");
  326. expect(markupDataRender('{{para|id=997-5}}{{ref}}', Format::Markdown))->toBe("参考文献\n\n[1] **Third work** CSCD V4 VRI 2008\n\n");
  327. // html 的具体结构由页面决定(百科页另有写法),这里只看标题与条目都在、标题在前
  328. expect(markupDataRender('{{para|id=997-5}}{{ref}}', Format::Html))
  329. ->toMatch('/参考文献.*\[1\] Third work CSCD V4 VRI 2008/s');
  330. });
  331. it('counts references inside template parameters such as footnotes, once per title', function () use ($titles) {
  332. expect($titles(markupDataTree('{{n|见 {{quote|998-3}}}} {{para|id=998-4}} {{ref}}')))->toBe(['first work']);
  333. });
  334. });