Gib Website-Bilder aus dem Medienmanager frei, ohne sie zu lizenzieren.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
72130d66c5
commit
13530b8171
18 files changed
+940
-2
No files matched your search
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Entitlement\Grant;
|
||||
use App\Domain\Media\WebsiteIntake;
|
||||
use App\Domain\Media\WebsiteMedia;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
class WebsiteIntakeTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Storage::fake('cms_incoming');
|
||||
Storage::fake('media_derived');
|
||||
Storage::fake('media_public');
|
||||
Storage::fake('media_originals');
|
||||
}
|
||||
|
||||
public function test_an_uploaded_image_becomes_a_released_medium(): void
|
||||
{
|
||||
Storage::disk('cms_incoming')->put('cms/hero.png', $this->pngBytes());
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
|
||||
$element = app(WebsiteIntake::class)->acceptImage(
|
||||
'cms/hero.png',
|
||||
'Lara im Park',
|
||||
'Foto: Lara und Felix',
|
||||
'Lara sitzt auf einer Parkbank',
|
||||
$editor,
|
||||
);
|
||||
|
||||
$element->refresh();
|
||||
$this->assertSame(0, $element->versions()->count());
|
||||
$this->assertSame(0, Grant::query()->count());
|
||||
$this->assertSame('Lara im Park', $element->display_title);
|
||||
$this->assertSame('vorschau/element-'.$element->id.'.jpg', $element->thumbnail_path);
|
||||
$this->assertSame('website/'.$element->id.'/datei.jpg', $element->website_public_path);
|
||||
$this->assertNotNull($element->website_released_at);
|
||||
Storage::disk('cms_incoming')->assertMissing('cms/hero.png');
|
||||
Storage::disk('media_derived')->assertExists($element->thumbnail_path);
|
||||
Storage::disk('media_originals')->assertMissing('cms/hero.png');
|
||||
|
||||
$presentation = app(WebsiteMedia::class)->present($element);
|
||||
$this->assertNotNull($presentation);
|
||||
$this->assertSame($element->id, $presentation->elementId);
|
||||
$this->assertSame('Lara sitzt auf einer Parkbank', $presentation->alt);
|
||||
$this->assertSame('Foto: Lara und Felix', $presentation->credit);
|
||||
$this->assertSame('bild', $presentation->kind);
|
||||
$this->assertStringStartsWith("\xFF\xD8", $this->get($presentation->url)->assertOk()->streamedContent());
|
||||
}
|
||||
|
||||
public function test_a_missing_or_misplaced_file_creates_no_medium(): void
|
||||
{
|
||||
$intake = app(WebsiteIntake::class);
|
||||
Storage::disk('cms_incoming')->put('cms/hero.png', $this->pngBytes());
|
||||
|
||||
try {
|
||||
$intake->acceptImage('cms/hero.png', ' ');
|
||||
$this->fail('Der Titel hätte abgelehnt werden müssen.');
|
||||
} catch (DomainRuleException $exception) {
|
||||
$this->assertSame('Der Titel fehlt.', $exception->getMessage());
|
||||
}
|
||||
|
||||
foreach (['cms/fehlt.png', 'originals/geheim.png', 'cms/../originals/geheim.png', ''] as $path) {
|
||||
try {
|
||||
$intake->acceptImage($path, 'Ohne Datei');
|
||||
$this->fail('Die Datei hätte abgelehnt werden müssen.');
|
||||
} catch (DomainRuleException $exception) {
|
||||
$this->assertSame('Die Bilddatei liegt nicht im Eingang.', $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertSame(0, ContentElement::query()->count());
|
||||
Storage::disk('media_public')->assertMissing('website/1/datei.jpg');
|
||||
}
|
||||
|
||||
public function test_an_unreadable_file_is_kept_but_not_released(): void
|
||||
{
|
||||
Storage::disk('cms_incoming')->put('cms/kaputt.jpg', 'kein bild');
|
||||
|
||||
$element = app(WebsiteIntake::class)->acceptImage('cms/kaputt.jpg', 'Unlesbar', 'Quelle');
|
||||
|
||||
$this->assertNull($element->fresh()->website_released_at);
|
||||
$this->assertNotNull($element->fresh()->thumbnail_error);
|
||||
$this->assertNull(app(WebsiteMedia::class)->present($element));
|
||||
Storage::disk('cms_incoming')->assertExists('cms/kaputt.jpg');
|
||||
Storage::disk('media_public')->assertMissing('website/'.$element->id.'/datei.jpg');
|
||||
}
|
||||
|
||||
private function pngBytes(): string
|
||||
{
|
||||
$image = imagecreatetruecolor(8, 8);
|
||||
ob_start();
|
||||
imagepng($image);
|
||||
$bytes = ob_get_clean();
|
||||
imagedestroy($image);
|
||||
|
||||
return is_string($bytes) ? $bytes : '';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user