M7: 全量测试(25 用例)+ README + 部署文档(nginx/systemd/cron)+ theme:publish 命令
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Comment;
|
||||
use App\Models\Post;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Spatie\Tags\Tag;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LegacyRoutesTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->seed();
|
||||
|
||||
$user = User::create(['name' => '作者', 'email' => 'author@test.com', 'password' => bcrypt('x')]);
|
||||
$category = Category::create(['name' => '技术', 'slug' => 'tech']);
|
||||
\Illuminate\Support\Facades\DB::table('posts')->insert([
|
||||
'id' => 12,
|
||||
'user_id' => $user->id,
|
||||
'category_id' => $category->id,
|
||||
'title' => '老文章',
|
||||
'slug' => 'legacy-post',
|
||||
'content' => '内容',
|
||||
'content_format' => 'markdown',
|
||||
'status' => 'published',
|
||||
'published_at' => now(),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
Comment::create(['post_id' => 12, 'author_name' => '访客', 'content' => '好文', 'status' => 'published', 'created_at' => now()]);
|
||||
}
|
||||
|
||||
public function test_rewrite_style_urls_redirect(): void
|
||||
{
|
||||
$this->get('/show-12.html')->assertRedirect('/posts/legacy-post');
|
||||
$this->get('/show-12-1.html')->assertRedirect('/posts/legacy-post');
|
||||
$this->get('/category-1.html')->assertRedirect();
|
||||
$this->get('/archives-'.now()->format('Ymd').'.html')->assertRedirect();
|
||||
$this->get('/tagslist.html')->assertRedirect('/tags');
|
||||
$this->get('/links.shtml')->assertRedirect('/links');
|
||||
$this->get('/login.shtml')->assertRedirect('/login');
|
||||
$this->get('/reg.shtml')->assertRedirect('/register');
|
||||
}
|
||||
|
||||
public function test_query_style_urls_redirect(): void
|
||||
{
|
||||
$this->get('/?action=show&id=12')->assertRedirect('/posts/legacy-post');
|
||||
$this->get('/?action=category&cid=1')->assertRedirect();
|
||||
$this->get('/?action=index&setdate='.now()->format('Ym'))->assertRedirect();
|
||||
$this->get('/?action=search&keyword=laravel')->assertRedirect('/search?q=laravel');
|
||||
$this->get('/?action=links')->assertRedirect('/links');
|
||||
$this->get('/?action=archives')->assertRedirect('/archives');
|
||||
$this->get('/?action=comments')->assertRedirect('/comments');
|
||||
}
|
||||
|
||||
public function test_trackback_endpoints_are_gone(): void
|
||||
{
|
||||
$this->get('/tburl.php')->assertStatus(410);
|
||||
$this->get('/trackback.php')->assertStatus(410);
|
||||
}
|
||||
|
||||
public function test_stable_paths_work(): void
|
||||
{
|
||||
$this->get('/rss.xml')->assertOk();
|
||||
$this->get('/sitemap.xml')->assertOk();
|
||||
$this->get('/robots.txt')->assertOk();
|
||||
}
|
||||
|
||||
public function test_missing_records_return_404(): void
|
||||
{
|
||||
$this->get('/show-99999.html')->assertNotFound();
|
||||
$this->get('/?action=show&id=99999')->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_legacy_tag_id_mapping(): void
|
||||
{
|
||||
$tag = Tag::create(['name' => 'laravel-tag', 'type' => 'post']);
|
||||
Setting::set('legacy_tags', [1 => $tag->id]);
|
||||
|
||||
$this->get('/?action=tags&id=1')->assertRedirect('/tags/laravel-tag');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user