04a2034975
- storefront 全站改为极简黑白配色:直角、细线分隔、卡片 hover 浅底、深色模式(跟随系统+手动切换) - 抽出 storefront/partials/card 复用卡片 - 一并提交此前暂存的客户端注册 API、站点设置、后台页面与测试 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
95 lines
2.9 KiB
PHP
95 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Category;
|
|
use App\Models\Package;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\File;
|
|
use Tests\TestCase;
|
|
|
|
class WebAdminPackageDeletionTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_admin_can_delete_package_and_related_data(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$package = Package::query()->create([
|
|
'type' => 'plugin',
|
|
'slug' => 'DeleteMe',
|
|
'name' => 'Delete Me',
|
|
'summary' => '',
|
|
'description' => '',
|
|
'author' => '',
|
|
'homepage' => '',
|
|
'icon_url' => '',
|
|
'license' => '',
|
|
'status' => 'published',
|
|
'is_featured' => false,
|
|
'sort_order' => 0,
|
|
'download_count' => 0,
|
|
'latest_version' => '1.0.0',
|
|
]);
|
|
|
|
$category = Category::query()->create([
|
|
'type' => 'plugin',
|
|
'slug' => 'utility',
|
|
'name' => 'Utility',
|
|
'description' => '',
|
|
'sort_order' => 0,
|
|
]);
|
|
|
|
$package->categories()->attach($category->id);
|
|
|
|
$version = $package->versions()->create([
|
|
'version' => '1.0.0',
|
|
'changelog' => '',
|
|
'typecho_min' => '1.2.0',
|
|
'typecho_max' => '',
|
|
'php_min' => '8.0',
|
|
'php_max' => '',
|
|
'php_extensions' => '[]',
|
|
'package_url' => 'https://cdn.example.com/DeleteMe-1.0.0.zip',
|
|
'package_size' => 1234,
|
|
'sha256' => str_repeat('b', 64),
|
|
'is_stable' => true,
|
|
'is_latest' => true,
|
|
'download_count' => 0,
|
|
'published_at' => now(),
|
|
]);
|
|
|
|
$screenshot = $package->screenshots()->create([
|
|
'image_url' => 'https://cdn.example.com/DeleteMe-home.webp',
|
|
'caption' => 'Home',
|
|
'sort_order' => 1,
|
|
]);
|
|
|
|
$packageDir = storage_path('app/packages/plugin/DeleteMe');
|
|
File::ensureDirectoryExists($packageDir);
|
|
File::put($packageDir . '/1.0.0.zip', 'demo');
|
|
|
|
$this->actingAs($user)
|
|
->delete('/admin/packages/plugin/DeleteMe')
|
|
->assertRedirect('/admin/packages?type=plugin')
|
|
->assertSessionHas('success', '扩展已删除:Delete Me');
|
|
|
|
$this->assertDatabaseMissing('store_packages', [
|
|
'id' => $package->id,
|
|
]);
|
|
$this->assertDatabaseMissing('store_versions', [
|
|
'id' => $version->id,
|
|
]);
|
|
$this->assertDatabaseMissing('store_screenshots', [
|
|
'id' => $screenshot->id,
|
|
]);
|
|
$this->assertDatabaseMissing('store_package_categories', [
|
|
'package_id' => $package->id,
|
|
'category_id' => $category->id,
|
|
]);
|
|
$this->assertFalse(File::isDirectory($packageDir));
|
|
}
|
|
}
|