|
|
@@ -9,34 +9,6 @@ use Illuminate\Support\Str;
|
|
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
|
|
-/**
|
|
|
- * 建一个句子,返回模型
|
|
|
- */
|
|
|
-function makeSentence(string $channelUid, int $book, int $para, int $wordStart, string $content): Sentence
|
|
|
-{
|
|
|
- $sentence = new Sentence;
|
|
|
- $sentence->forceFill([
|
|
|
- // sentences.id 不是自增列,必须显式给值
|
|
|
- 'id' => random_int(1, PHP_INT_MAX),
|
|
|
- 'uid' => (string) Str::uuid(),
|
|
|
- 'book_id' => $book,
|
|
|
- 'paragraph' => $para,
|
|
|
- 'word_start' => $wordStart,
|
|
|
- 'word_end' => $wordStart,
|
|
|
- 'channel_uid' => $channelUid,
|
|
|
- 'editor_uid' => (string) Str::uuid(),
|
|
|
- 'content' => $content,
|
|
|
- 'content_type' => 'markdown',
|
|
|
- 'strlen' => mb_strlen($content),
|
|
|
- 'status' => 30,
|
|
|
- 'create_time' => time() * 1000,
|
|
|
- 'modify_time' => time() * 1000,
|
|
|
- 'language' => 'zh-Hans',
|
|
|
- ])->save();
|
|
|
-
|
|
|
- return $sentence;
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
* 建测试用的 channel 和句子:book 9001 的第 1 段两句,第 2 段一句。返回 channel uid
|
|
|
*/
|
|
|
@@ -52,7 +24,7 @@ function makeParagraphFixture(): string
|
|
|
|
|
|
it('renders every sentence of a paragraph wrapped in divs', function () {
|
|
|
$channel = makeParagraphFixture();
|
|
|
- $data = $this->getJson("/api/v2/tipitaka-content-para/9001-1?channel={$channel}")
|
|
|
+ $data = $this->getJson("/api/v3/tipitaka-read-para/9001-1?channel={$channel}")
|
|
|
->assertOk()
|
|
|
->json('data');
|
|
|
|
|
|
@@ -80,7 +52,7 @@ it('wraps a chapter title paragraph in a heading', function () {
|
|
|
'uid' => (string) Str::uuid(),
|
|
|
])->save();
|
|
|
|
|
|
- $display = $this->getJson("/api/v2/tipitaka-content-para/9001-1?channel={$channel}")
|
|
|
+ $display = $this->getJson("/api/v3/tipitaka-read-para/9001-1?channel={$channel}")
|
|
|
->assertOk()
|
|
|
->json('data.display');
|
|
|
|
|
|
@@ -89,19 +61,19 @@ it('wraps a chapter title paragraph in a heading', function () {
|
|
|
|
|
|
it('can output only the sentences or both', function () {
|
|
|
$channel = makeParagraphFixture();
|
|
|
- $sentences = $this->getJson("/api/v2/tipitaka-content-para/9001-1?channel={$channel}&view=sentences")
|
|
|
+ $sentences = $this->getJson("/api/v3/tipitaka-read-para/9001-1?channel={$channel}&view=sentences")
|
|
|
->assertOk()
|
|
|
->json('data');
|
|
|
expect($sentences)->not->toHaveKey('display');
|
|
|
expect($sentences['sentences'])->toHaveCount(2);
|
|
|
expect($sentences['sentences'][0])->toHaveKeys(['sid', 'html']);
|
|
|
|
|
|
- $all = $this->getJson("/api/v2/tipitaka-content-para/9001-1?channel={$channel}&view=all")
|
|
|
+ $all = $this->getJson("/api/v3/tipitaka-read-para/9001-1?channel={$channel}&view=all")
|
|
|
->assertOk()
|
|
|
->json('data');
|
|
|
expect($all)->toHaveKeys(['para', 'display', 'sentences']);
|
|
|
|
|
|
- $items = $this->getJson("/api/v2/tipitaka-content-para?book=9001¶=1&channel={$channel}&view=sentences")
|
|
|
+ $items = $this->getJson("/api/v3/tipitaka-read-para?book=9001¶=1&channel={$channel}&view=sentences")
|
|
|
->assertOk()
|
|
|
->json('data.items');
|
|
|
expect($items[0])->not->toHaveKey('display');
|
|
|
@@ -110,7 +82,7 @@ it('can output only the sentences or both', function () {
|
|
|
|
|
|
it('lists the paragraphs of a range and skips empty ones', function () {
|
|
|
$channel = makeParagraphFixture();
|
|
|
- $items = $this->getJson("/api/v2/tipitaka-content-para?book=9001¶=1&to=3&channel={$channel}")
|
|
|
+ $items = $this->getJson("/api/v3/tipitaka-read-para?book=9001¶=1&to=3&channel={$channel}")
|
|
|
->assertOk()
|
|
|
->json('data.items');
|
|
|
|
|
|
@@ -119,7 +91,7 @@ it('lists the paragraphs of a range and skips empty ones', function () {
|
|
|
|
|
|
it('outputs one line per sentence for non html formats', function () {
|
|
|
$channel = makeParagraphFixture();
|
|
|
- $display = $this->getJson("/api/v2/tipitaka-content-para/9001-1?channel={$channel}&format=text")
|
|
|
+ $display = $this->getJson("/api/v3/tipitaka-read-para/9001-1?channel={$channel}&format=text")
|
|
|
->assertOk()
|
|
|
->json('data.display');
|
|
|
|
|
|
@@ -128,17 +100,17 @@ it('outputs one line per sentence for non html formats', function () {
|
|
|
|
|
|
it('rejects an invalid id or channel', function () {
|
|
|
$channel = makeParagraphFixture();
|
|
|
- $this->getJson("/api/v2/tipitaka-content-para/bad-id?channel={$channel}")
|
|
|
+ $this->getJson("/api/v3/tipitaka-read-para/bad-id?channel={$channel}")
|
|
|
->assertJsonPath('ok', false);
|
|
|
- $this->getJson('/api/v2/tipitaka-content-para/9001-1?channel=not-a-uuid')
|
|
|
+ $this->getJson('/api/v3/tipitaka-read-para/9001-1?channel=not-a-uuid')
|
|
|
->assertJsonPath('ok', false);
|
|
|
- $this->getJson("/api/v2/tipitaka-content-para/9001-9?channel={$channel}")
|
|
|
+ $this->getJson("/api/v3/tipitaka-read-para/9001-9?channel={$channel}")
|
|
|
->assertJsonPath('ok', false);
|
|
|
});
|
|
|
|
|
|
it('caches the paragraph and drops the cache when a sentence changes', function () {
|
|
|
$channel = makeParagraphFixture();
|
|
|
- $url = "/api/v2/tipitaka-content-para/9001-1?channel={$channel}";
|
|
|
+ $url = "/api/v3/tipitaka-read-para/9001-1?channel={$channel}";
|
|
|
$this->getJson($url)->assertOk();
|
|
|
|
|
|
$tag = PaliContentService::paragraphCacheTag(9001, 1, $channel);
|
|
|
@@ -155,7 +127,7 @@ it('caches the paragraph and drops the cache when a sentence changes', function
|
|
|
|
|
|
it('drops the cache when a sentence is added or deleted', function () {
|
|
|
$channel = makeParagraphFixture();
|
|
|
- $url = "/api/v2/tipitaka-content-para/9001-1?channel={$channel}";
|
|
|
+ $url = "/api/v3/tipitaka-read-para/9001-1?channel={$channel}";
|
|
|
$this->getJson($url)->assertOk();
|
|
|
|
|
|
makeSentence($channel, 9001, 1, 3, 'third sentence');
|