Allow heading tags (h1-h6) in ContentSanitizer so news editor headings render
This commit is contained in:
24
tests/Unit/Enhance/EnhanceProcessorFactoryTest.php
Normal file
24
tests/Unit/Enhance/EnhanceProcessorFactoryTest.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Models\EnhanceJob;
|
||||
use App\Services\Enhance\EnhanceProcessorFactory;
|
||||
use App\Services\Enhance\Processors\ExternalWorkerEnhanceProcessor;
|
||||
use App\Services\Enhance\Processors\StubEnhanceProcessor;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
uses(TestCase::class, RefreshDatabase::class);
|
||||
|
||||
it('returns the stub processor for the stub engine', function (): void {
|
||||
expect(app(EnhanceProcessorFactory::class)->make(EnhanceJob::ENGINE_STUB))->toBeInstanceOf(StubEnhanceProcessor::class);
|
||||
});
|
||||
|
||||
it('returns the external worker processor for the external worker engine', function (): void {
|
||||
expect(app(EnhanceProcessorFactory::class)->make(EnhanceJob::ENGINE_EXTERNAL_WORKER))->toBeInstanceOf(ExternalWorkerEnhanceProcessor::class);
|
||||
});
|
||||
|
||||
it('throws for an unknown enhance processor engine', function (): void {
|
||||
app(EnhanceProcessorFactory::class)->make('unknown-engine');
|
||||
})->throws(RuntimeException::class);
|
||||
63
tests/Unit/Enhance/EnhanceStorageSafetyTest.php
Normal file
63
tests/Unit/Enhance/EnhanceStorageSafetyTest.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
uses(Tests\TestCase::class);
|
||||
|
||||
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
use App\Models\EnhanceJob;
|
||||
use App\Models\User;
|
||||
use App\Services\Enhance\EnhanceStorageService;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
beforeEach(function (): void {
|
||||
config()->set('enhance.disk', 'public');
|
||||
Storage::fake('public');
|
||||
});
|
||||
|
||||
it('allows enhance source output and preview paths', function (): void {
|
||||
$service = app(EnhanceStorageService::class);
|
||||
|
||||
expect($service->isEnhancePath('enhance/sources/1/source.png'))->toBeTrue();
|
||||
expect($service->isEnhancePath('enhance/outputs/1/output.webp'))->toBeTrue();
|
||||
expect($service->isEnhancePath('enhance/previews/1/preview.webp'))->toBeTrue();
|
||||
});
|
||||
|
||||
it('rejects artwork random and null paths safely', function (): void {
|
||||
$service = app(EnhanceStorageService::class);
|
||||
Storage::disk('public')->put('uploads/artworks/original.png', 'unsafe');
|
||||
Storage::disk('public')->put('random/file.txt', 'unsafe');
|
||||
|
||||
expect($service->isEnhancePath('uploads/artworks/original.png'))->toBeFalse();
|
||||
expect($service->isEnhancePath('random/file.txt'))->toBeFalse();
|
||||
expect($service->isEnhancePath(null))->toBeFalse();
|
||||
expect($service->safeDelete('public', 'uploads/artworks/original.png'))->toBeFalse();
|
||||
expect($service->safeDelete('public', 'random/file.txt'))->toBeFalse();
|
||||
expect($service->safeDelete('public', null))->toBeFalse();
|
||||
|
||||
Storage::disk('public')->assertExists('uploads/artworks/original.png');
|
||||
Storage::disk('public')->assertExists('random/file.txt');
|
||||
});
|
||||
|
||||
it('lists known job paths', function (): void {
|
||||
$service = app(EnhanceStorageService::class);
|
||||
$owner = User::factory()->create();
|
||||
|
||||
EnhanceJob::query()->create([
|
||||
'user_id' => $owner->id,
|
||||
'status' => EnhanceJob::STATUS_COMPLETED,
|
||||
'engine' => EnhanceJob::ENGINE_STUB,
|
||||
'mode' => 'standard',
|
||||
'scale' => 2,
|
||||
'source_path' => 'enhance/sources/known/source.png',
|
||||
'output_path' => 'enhance/outputs/known/output.webp',
|
||||
'preview_path' => 'enhance/previews/known/preview.webp',
|
||||
]);
|
||||
|
||||
expect($service->listKnownJobPaths())->toContain(
|
||||
'enhance/sources/known/source.png',
|
||||
'enhance/outputs/known/output.webp',
|
||||
'enhance/previews/known/preview.webp',
|
||||
);
|
||||
});
|
||||
38
tests/Unit/Enhance/EnhanceValidatorTest.php
Normal file
38
tests/Unit/Enhance/EnhanceValidatorTest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Services\Enhance\EnhanceValidator;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Tests\TestCase;
|
||||
|
||||
uses(TestCase::class, RefreshDatabase::class);
|
||||
|
||||
it('validates a supported uploaded image and normalizes options', function (): void {
|
||||
$file = UploadedFile::fake()->image('artwork.png', 1400, 900)->size(768);
|
||||
|
||||
$validated = app(EnhanceValidator::class)->validateUpload($file, [
|
||||
'scale' => 4,
|
||||
'mode' => 'illustration',
|
||||
'engine' => 'stub',
|
||||
]);
|
||||
|
||||
expect($validated['scale'])->toBe(4);
|
||||
expect($validated['mode'])->toBe('illustration');
|
||||
expect($validated['engine'])->toBe('stub');
|
||||
expect($validated['input_width'])->toBe(1400);
|
||||
expect($validated['input_height'])->toBe(900);
|
||||
expect($validated['input_mime'])->toBe('image/png');
|
||||
});
|
||||
|
||||
it('rejects unsupported image formats', function (): void {
|
||||
$file = UploadedFile::fake()->create('vector.svg', 10, 'image/svg+xml');
|
||||
|
||||
app(EnhanceValidator::class)->validateUpload($file, [
|
||||
'scale' => 2,
|
||||
'mode' => 'standard',
|
||||
'engine' => 'stub',
|
||||
]);
|
||||
})->throws(ValidationException::class);
|
||||
Reference in New Issue
Block a user