2
0

LibraryPageErrorsTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. use App\Models\Article;
  3. use App\Models\Collection;
  4. use Illuminate\Foundation\Testing\RefreshDatabase;
  5. use Illuminate\Support\Str;
  6. /*
  7. * staging 日志(2026-11-19)里两类必然 500 的 web 页面的回归测试:
  8. * - blog 的子页面指向被注释掉的 BlogController 方法 → BadMethodCallException
  9. * - 文集阅读页没给 book.read 视图 book_title → Undefined array key
  10. */
  11. uses(RefreshDatabase::class);
  12. it('answers 404 instead of 500 for blog pages that are not implemented yet', function (string $path) {
  13. makeStudio('blogger');
  14. $this->get("/blog/blogger/{$path}")->assertNotFound();
  15. })->with([
  16. 'categories' => 'categories',
  17. 'archives' => 'archives',
  18. 'archives by year' => 'archives/2024',
  19. 'tag' => 'tag/dukkha',
  20. 'search' => 'search?q=dukkha',
  21. 'post' => 'some-post',
  22. ]);
  23. it('still renders the blog home, whose layout links to those routes by name', function () {
  24. makeStudio('blogger');
  25. $this->get('/blog/blogger')
  26. ->assertSuccessful()
  27. ->assertSee(route('blog.archives', ['user' => 'blogger'], false))
  28. ->assertSee(route('blog.search', ['user' => 'blogger'], false));
  29. });
  30. it('renders an anthology article with the anthology title as the book title', function () {
  31. $owner = makeStudio('editor');
  32. // ArticleResource 渲染时取作者名下第一个译文 channel,没有就报错(v2 代码的另一个问题,不在此修)
  33. makeChannel($owner, 'editor translation');
  34. $articleId = (string) Str::uuid();
  35. $anthologyId = (string) Str::uuid();
  36. $now = time() * 1000;
  37. (new Article)->forceFill([
  38. 'id' => random_int(1, PHP_INT_MAX),
  39. 'uid' => $articleId,
  40. 'title' => '第一单元',
  41. 'content' => '正文',
  42. 'owner' => $owner,
  43. 'owner_id' => 0,
  44. 'editor_id' => 0,
  45. 'status' => 30,
  46. 'create_time' => $now,
  47. 'modify_time' => $now,
  48. ])->save();
  49. (new Collection)->forceFill([
  50. 'id' => random_int(1, PHP_INT_MAX),
  51. 'uid' => $anthologyId,
  52. 'title' => '初级班课本',
  53. 'article_list' => json_encode([['article_id' => $articleId, 'level' => 1, 'title' => '第一单元']]),
  54. 'owner' => $owner,
  55. 'owner_id' => 0,
  56. 'editor_id' => 0,
  57. 'status' => 30,
  58. 'create_time' => $now,
  59. 'modify_time' => $now,
  60. ])->save();
  61. $this->get("/library/anthology/{$anthologyId}/read/{$articleId}")
  62. ->assertSuccessful()
  63. ->assertSee('<h5 class="offcanvas-title">初级班课本</h5>', false);
  64. });