Ergaenze Stammdaten, Suche, Dimensionen, Abdeckung und Ausgabenachweis
Deploy Test / test (push) Successful in 17s
Deploy Test / deploy (push) Successful in 25s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-16 08:24:23 +01:00
1 parent 7b54c38623
commit 5e763d15ec
23 files changed
+661 -5

No files matched your search

+2
View File
@@ -10,6 +10,8 @@ class Composition extends Model
{
protected $fillable = [
'designation',
'display_title',
'summary',
'kind',
'editorial_content_kind_id',
'archived_at',
+2
View File
@@ -13,7 +13,9 @@ class ContentElement extends Model
'kind',
'output_class',
'working_title',
'display_title',
'description',
'summary',
'editorial_content_kind_id',
'archived_at',
];
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace App\Domain\Catalog;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class EditorialDimension extends Model
{
protected $fillable = ['slug', 'label'];
public function values(): HasMany
{
return $this->hasMany(EditorialDimensionValue::class);
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\Domain\Catalog;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class EditorialDimensionValue extends Model
{
protected $fillable = ['editorial_dimension_id', 'slug', 'label'];
public function dimension(): BelongsTo
{
return $this->belongsTo(EditorialDimension::class, 'editorial_dimension_id');
}
}
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace App\Domain\Catalog;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class IdentityChange extends Model
{
protected $fillable = [
'subject_type',
'subject_id',
'field',
'before',
'after',
'actor_id',
'occurred_at',
];
protected function casts(): array
{
return [
'occurred_at' => 'datetime',
];
}
public function actor(): BelongsTo
{
return $this->belongsTo(User::class, 'actor_id');
}
}
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace App\Domain\Catalog;
use Illuminate\Database\Eloquent\Model;
class IdentityDimension
{
public function assign(Model $subject, EditorialDimensionValue $value, string $origin = 'direkt'): void
{
if (! in_array($origin, ['direkt', 'abgeleitet'], true)) {
throw new DomainRuleException('Die Herkunft einer Zuordnung ist direkt oder abgeleitet.');
}
IdentityDimensionValue::query()->updateOrCreate(
[
'subject_type' => $subject->getMorphClass(),
'subject_id' => $subject->getKey(),
'editorial_dimension_value_id' => $value->id,
],
['origin' => $origin],
);
}
/**
* @param list<int> $valueIds
*/
public function matches(Model $subject, array $valueIds): bool
{
if ($valueIds === []) {
return true;
}
$assigned = IdentityDimensionValue::query()
->where('subject_type', $subject->getMorphClass())
->where('subject_id', $subject->getKey())
->pluck('editorial_dimension_value_id')
->all();
$wanted = EditorialDimensionValue::query()->whereIn('id', $valueIds)->get()->groupBy('editorial_dimension_id');
if ($wanted->isEmpty()) {
return false;
}
foreach ($wanted as $group) {
$ids = $group->pluck('id')->all();
if (array_intersect($ids, $assigned) === []) {
return false;
}
}
return true;
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Domain\Catalog;
use Illuminate\Database\Eloquent\Model;
class IdentityDimensionValue extends Model
{
protected $fillable = [
'subject_type',
'subject_id',
'editorial_dimension_value_id',
'origin',
];
}
+39
View File
@@ -0,0 +1,39 @@
<?php
namespace App\Domain\Catalog;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
class IdentityProfile
{
/**
* @param array<string, mixed> $fields
*/
public function fill(Model $subject, array $fields, ?User $actor = null): void
{
foreach ($fields as $field => $value) {
$next = is_string($value) ? trim($value) : $value;
$next = $next === '' ? null : $next;
$before = $subject->getAttribute($field);
$before = $before === '' ? null : $before;
if ($before === $next) {
continue;
}
$subject->setAttribute($field, $next);
IdentityChange::query()->create([
'subject_type' => $subject->getMorphClass(),
'subject_id' => $subject->getKey(),
'field' => $field,
'before' => $before,
'after' => $next,
'actor_id' => $actor?->id,
'occurred_at' => now(),
]);
}
$subject->save();
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
namespace App\Domain\Catalog;
class OfferCoverage
{
public function __construct(private readonly ContentResolver $resolver) {}
/**
* @param list<LicenseArticle> $articles
* @return list<string>
*/
public function missingLeaves(CompositionVersion $version, array $articles): array
{
$covered = [];
foreach ($articles as $article) {
$release = $article->currentRelease;
if ($release === null) {
continue;
}
foreach ($release->contents()->pluck('content_element_version_id') as $id) {
$covered[(int) $id] = true;
}
}
$missing = [];
foreach ($this->resolver->expand($version) as $row) {
if (! isset($covered[$row['version_id']])) {
$missing[] = $row['path'];
}
}
return $missing;
}
}
+29
View File
@@ -89,6 +89,7 @@ public function activate(Offer $offer, array $lines, array $attributes = []): Of
$this->assertAttributes($attributes);
$scope = $this->scopeFor($lines);
$this->assertCoverage($lines, $attributes);
return DB::transaction(function () use ($offer, $lines, $attributes, $scope): OfferVersion {
$offer = Offer::query()->lockForUpdate()->findOrFail($offer->id);
@@ -171,6 +172,34 @@ private function assertAttributes(array $attributes): void
* @param list<array{target: LicenseArticle|BundleVersion, rights: RightsProfileVersion}> $lines
* @return list<array{license_article_id: int, rights_profile_version_id: int}>
*/
/**
* @param list<array{target: LicenseArticle|BundleVersion, rights: RightsProfileVersion}> $lines
* @param array<string, mixed> $attributes
*/
private function assertCoverage(array $lines, array $attributes): void
{
$versionId = $attributes['composition_version_id'] ?? null;
if ($versionId === null) {
return;
}
$version = CompositionVersion::query()->findOrFail($versionId);
$articles = [];
foreach ($lines as $line) {
if ($line['target'] instanceof LicenseArticle) {
$articles[] = $line['target'];
}
}
$missing = app(OfferCoverage::class)->missingLeaves($version, $articles);
if ($missing !== []) {
throw new DomainRuleException('Das Angebot deckt nicht alle Blätter: '.implode(', ', $missing));
}
}
private function scopeFor(array $lines): array
{
$scope = [];
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace App\Domain\Entitlement;
use Illuminate\Database\Eloquent\Model;
class MediaDelivery extends Model
{
protected $fillable = [
'grant_id',
'license_article_id',
'article_release_id',
'content_element_version_id',
'action',
'format',
'delivered_at',
];
protected function casts(): array
{
return [
'delivered_at' => 'datetime',
];
}
}
@@ -11,6 +11,7 @@
use App\Domain\Catalog\ContentVersionStatus;
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Catalog\EditorialContentKind;
use App\Domain\Catalog\IdentityProfile;
use App\Filament\Resources\Combinations\CombinationResource;
use App\Filament\Resources\Courses\CourseResource;
use App\Filament\Resources\Exercises\ExerciseResource;
@@ -22,6 +23,7 @@
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\EditRecord;
@@ -44,6 +46,9 @@ public function form(Schema $schema): Schema
{
return $schema->columns(1)->components([
TextInput::make('designation')->label('Bezeichnung')->required(),
TextInput::make('display_title')->label('Anzeigetitel')
->helperText('Erscheint in der Bibliothek. Leer lässt die Bezeichnung stehen.'),
Textarea::make('summary')->label('Kurzbeschreibung')->rows(3),
Select::make('kind')->label('Art')->options(CompositionKind::options())->required()
->helperText('Übung, Kurs und fachliche Kombination sind verschiedene Zusammenstellungen. Die Art lässt sich hier ändern.'),
Select::make('editorial_content_kind_id')
@@ -153,6 +158,8 @@ protected function mutateFormDataBeforeFill(array $data): array
return [
'designation' => $composition->designation,
'display_title' => $composition->display_title,
'summary' => $composition->summary,
'kind' => $kind instanceof CompositionKind ? $kind->value : $kind,
'editorial_content_kind_id' => $composition->editorial_content_kind_id,
'members' => $members,
@@ -169,6 +176,10 @@ protected function handleRecordUpdate(Model $record, array $data): Model
try {
$kind = CompositionKind::from($data['kind']);
$record->designation = trim((string) $data['designation']);
app(IdentityProfile::class)->fill($record, [
'display_title' => $data['display_title'] ?? null,
'summary' => $data['summary'] ?? null,
], auth()->user());
$record->kind = $kind;
$record->editorial_content_kind_id = filled($data['editorial_content_kind_id'] ?? null)
? (int) $data['editorial_content_kind_id']
@@ -6,6 +6,7 @@
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Catalog\EditorialContentKind;
use App\Domain\Catalog\IdentityProfile;
use App\Domain\Catalog\Pillar;
use App\Domain\Catalog\PillarService;
use App\Filament\Resources\ContentElements\ContentElementResource;
@@ -47,6 +48,9 @@ public function form(Schema $schema): Schema
return new HtmlString('<a href="'.e($url).'">Medium und Fassungen ansehen</a>');
}),
TextInput::make('working_title')->label('Arbeitstitel')->required(),
TextInput::make('display_title')->label('Anzeigetitel')
->helperText('Erscheint in der Bibliothek. Leer lässt den Arbeitstitel stehen. Speichern legt keine Fassung an.'),
Textarea::make('summary')->label('Kurzbeschreibung')->rows(3),
Textarea::make('description')->label('Beschreibung')->rows(4)
->helperText('Gilt für das Medium, nicht für eine einzelne Fassung.'),
Select::make('editorial_content_kind_id')
@@ -121,7 +125,9 @@ protected function mutateFormDataBeforeFill(array $data): array
{
return [
'working_title' => $this->getRecord()->working_title,
'display_title' => $this->getRecord()->display_title,
'description' => $this->getRecord()->description,
'summary' => $this->getRecord()->summary,
'pillars' => $this->getRecord()->pillars()->pluck('pillars.id')->all(),
];
}
@@ -134,6 +140,10 @@ protected function handleRecordUpdate(Model $record, array $data): Model
/** @var ContentElement $record */
try {
app(ContentService::class)->describe($record, (string) $data['working_title'], $data['description'] ?? null);
app(IdentityProfile::class)->fill($record, [
'display_title' => $data['display_title'] ?? null,
'summary' => $data['summary'] ?? null,
], auth()->user());
app(PillarService::class)->assign($record, array_map(intval(...), $data['pillars'] ?? []));
} catch (DomainRuleException $exception) {
Notification::make()->title($exception->getMessage())->danger()->send();
@@ -5,10 +5,12 @@
use App\Domain\Catalog\ArticleRelease;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\ContentElementVersion;
use App\Domain\Catalog\IdentityDimension;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Entitlement\DecideAccess;
use App\Domain\Entitlement\Grant;
use App\Domain\Entitlement\GrantStatus;
use App\Domain\Entitlement\MediaDelivery;
use App\Http\Controllers\Controller;
use App\Http\CourseOutline;
use App\Http\LibraryCatalog;
@@ -22,7 +24,42 @@ class LibraryController extends Controller
{
public function index(Request $request): View
{
return view('member.library', app(LibraryCatalog::class)->index($request->user()));
$catalog = app(LibraryCatalog::class)->index($request->user());
$query = trim((string) $request->query('q', ''));
$dimensionIds = array_values(array_filter(array_map(intval(...), (array) $request->query('dimension', []))));
$dimensions = app(IdentityDimension::class);
if ($query !== '') {
$catalog['programs'] = array_values(array_filter(
$catalog['programs'],
fn (array $card): bool => $this->matches($card, $query),
));
$catalog['materials'] = array_values(array_filter(
$catalog['materials'],
fn (array $card): bool => $this->matches($card, $query),
));
}
if ($dimensionIds !== []) {
$catalog['programs'] = array_values(array_filter(
$catalog['programs'],
fn (array $card): bool => $dimensions->matches($card['composition'], $dimensionIds),
));
$catalog['materials'] = array_values(array_filter(
$catalog['materials'],
function (array $card) use ($dimensions, $dimensionIds): bool {
$release = $card['article']->currentRelease;
$subject = $release?->rootCompositionVersion?->composition
?? $release?->rootElementVersion?->element
?? $card['article'];
return $dimensions->matches($subject, $dimensionIds);
},
));
}
return view('member.library', [...$catalog, 'query' => $query]);
}
public function program(Request $request, Composition $composition): View
@@ -104,6 +141,18 @@ public function media(
$decision = app(DecideAccess::class)($request->user(), $article, $release, $version, $action);
abort_unless($decision->allowed, 403, $decision->reason);
if ($decision->grant !== null) {
MediaDelivery::query()->create([
'grant_id' => $decision->grant->id,
'license_article_id' => $article->id,
'article_release_id' => $release->id,
'content_element_version_id' => $version->id,
'action' => $action,
'format' => 'bestand',
'delivered_at' => now(),
]);
}
$version->loadMissing('element');
$file = $version->metadata['file'] ?? null;
@@ -122,6 +171,16 @@ public function media(
]);
}
/**
* @param array<string, mixed> $card
*/
private function matches(array $card, string $query): bool
{
$haystack = mb_strtolower(($card['title'] ?? '').' '.($card['summary'] ?? ''));
return str_contains($haystack, mb_strtolower($query));
}
private function grantQuery(Request $request)
{
return Grant::query()
+7 -2
View File
@@ -20,8 +20,13 @@ public function title(LicenseArticle $article): string
'rootElementVersion.element',
]);
return $release->rootCompositionVersion?->composition?->designation
?? $release->rootElementVersion?->element?->working_title
$composition = $release->rootCompositionVersion?->composition;
$element = $release->rootElementVersion?->element;
return (filled($composition?->display_title) ? $composition->display_title : null)
?? $composition?->designation
?? (filled($element?->display_title) ? $element->display_title : null)
?? $element?->working_title
?? $release->classification_note
?? $article->code;
}
+4 -2
View File
@@ -41,7 +41,8 @@ public function index(User $user): array
$programs[$composition->id] = [
'composition' => $composition,
'version' => $version,
'title' => $composition->designation,
'title' => filled($composition->display_title) ? $composition->display_title : $composition->designation,
'summary' => $composition->summary,
'kind' => $composition->editorialContentKind?->label
?? ($composition->kind?->label()),
];
@@ -72,7 +73,8 @@ public function program(User $user, Composition $composition): array
return [
'composition' => $composition,
'title' => $composition->designation,
'title' => filled($composition->display_title) ? $composition->display_title : $composition->designation,
'summary' => $composition->summary,
'kind' => $composition->editorialContentKind?->label
?? ($composition->kind?->label()),
'nodes' => array_map(
@@ -0,0 +1,45 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('content_elements', function (Blueprint $table) {
$table->string('display_title')->nullable()->after('working_title');
$table->text('summary')->nullable()->after('description');
});
Schema::table('compositions', function (Blueprint $table) {
$table->string('display_title')->nullable()->after('designation');
$table->text('summary')->nullable()->after('display_title');
});
Schema::create('identity_changes', function (Blueprint $table) {
$table->id();
$table->string('subject_type');
$table->unsignedBigInteger('subject_id');
$table->string('field');
$table->text('before')->nullable();
$table->text('after')->nullable();
$table->foreignId('actor_id')->nullable()->constrained('users')->nullOnDelete();
$table->timestamp('occurred_at');
$table->timestamps();
$table->index(['subject_type', 'subject_id']);
});
}
public function down(): void
{
Schema::dropIfExists('identity_changes');
Schema::table('compositions', function (Blueprint $table) {
$table->dropColumn(['display_title', 'summary']);
});
Schema::table('content_elements', function (Blueprint $table) {
$table->dropColumn(['display_title', 'summary']);
});
}
};
@@ -0,0 +1,75 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('editorial_dimensions', function (Blueprint $table) {
$table->id();
$table->string('slug')->unique();
$table->string('label');
$table->timestamps();
});
Schema::create('editorial_dimension_values', function (Blueprint $table) {
$table->id();
$table->foreignId('editorial_dimension_id')->constrained()->cascadeOnDelete();
$table->string('slug');
$table->string('label');
$table->timestamps();
$table->unique(['editorial_dimension_id', 'slug']);
});
Schema::create('identity_dimension_values', function (Blueprint $table) {
$table->id();
$table->string('subject_type');
$table->unsignedBigInteger('subject_id');
$table->foreignId('editorial_dimension_value_id')->constrained()->cascadeOnDelete();
$table->string('origin');
$table->timestamps();
$table->unique(['subject_type', 'subject_id', 'editorial_dimension_value_id'], 'identity_dimension_unique');
});
$now = now();
$dimensionId = DB::table('editorial_dimensions')->insertGetId([
'slug' => 'saeule',
'label' => 'Fachliche Säule',
'created_at' => $now,
'updated_at' => $now,
]);
foreach (DB::table('pillars')->orderBy('id')->get() as $pillar) {
$slug = 'pfeiler-'.$pillar->id;
$valueId = DB::table('editorial_dimension_values')->insertGetId([
'editorial_dimension_id' => $dimensionId,
'slug' => $slug,
'label' => $pillar->name,
'created_at' => $now,
'updated_at' => $now,
]);
foreach (DB::table('content_element_pillar')->where('pillar_id', $pillar->id)->get() as $link) {
DB::table('identity_dimension_values')->insert([
'subject_type' => 'App\\Domain\\Catalog\\ContentElement',
'subject_id' => $link->content_element_id,
'editorial_dimension_value_id' => $valueId,
'origin' => 'direkt',
'created_at' => $now,
'updated_at' => $now,
]);
}
}
}
public function down(): void
{
Schema::dropIfExists('identity_dimension_values');
Schema::dropIfExists('editorial_dimension_values');
Schema::dropIfExists('editorial_dimensions');
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('media_deliveries', function (Blueprint $table) {
$table->id();
$table->foreignId('grant_id')->constrained()->restrictOnDelete();
$table->foreignId('license_article_id')->constrained()->restrictOnDelete();
$table->foreignId('article_release_id')->constrained()->restrictOnDelete();
$table->foreignId('content_element_version_id')->constrained()->restrictOnDelete();
$table->string('action');
$table->string('format');
$table->timestamp('delivered_at');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('media_deliveries');
}
};
+8
View File
@@ -5,6 +5,14 @@
@section('content')
@include('member.partials.nav')
<h1>Bibliothek</h1>
<form method="get" action="{{ route('member.library') }}">
<label for="q">Suche</label>
<input id="q" name="q" type="search" value="{{ $query ?? '' }}">
<button class="button" type="submit">Suchen</button>
@if (filled($query ?? null))
<a href="{{ route('member.library') }}">Zurücksetzen</a>
@endif
</form>
<p class="lede">Programme zeigen den Aufbau. Einzelne Materialien stehen darunter, solange sie zu keinem freigegebenen Programm gehören.</p>
@if ($programs === [] && $materials === [])
<div class="empty">
+3
View File
@@ -9,5 +9,8 @@
@if ($kind)
<p>{{ $kind }}</p>
@endif
@if (filled($summary ?? null))
<p class="lede">{{ $summary }}</p>
@endif
@include('member.partials.structure', ['nodes' => $nodes])
@endsection
@@ -0,0 +1,90 @@
<?php
namespace Tests\Feature;
use App\Domain\Catalog\ArticleService;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Catalog\EditorialDimension;
use App\Domain\Catalog\EditorialDimensionValue;
use App\Domain\Catalog\IdentityDimension;
use App\Domain\Catalog\OfferService;
use App\Domain\Entitlement\GrantIssuer;
use App\Domain\Entitlement\MediaDelivery;
use App\Http\SignedLink;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class CatalogFollowThroughTest extends TestCase
{
use RefreshDatabase;
public function test_an_uncovered_program_cannot_be_activated(): void
{
$content = app(ContentService::class);
$film = $content->publishElementVersion($content->createElement('film', 'film', 'Film'), null, ['file' => 'inhalte/a.mp4']);
$sheet = $content->publishElementVersion($content->createElement('text', 'document', 'Blatt'), 'Text');
$program = $content->publishComposition($content->createComposition('Programm'), [
['role' => 'Film', 'target' => $film],
['role' => 'Blatt', 'target' => $sheet],
]);
$articles = app(ArticleService::class);
$filmArticle = $articles->create('nur-film');
$articles->publishRelease($filmArticle, $film, 'Nur der Film.');
$offers = app(OfferService::class);
$rights = $offers->createRightsProfile('Film', 'ehrenamtlich', ['film' => ['streamen']]);
$this->expectException(DomainRuleException::class);
$offers->activate($offers->create('Lückenhaft'), [
['target' => $filmArticle->fresh(), 'rights' => $rights],
], [
'grant_kind' => 'kauf',
'price_cents' => 100,
'composition_version_id' => $program->id,
]);
}
public function test_a_dimension_filters_the_library_and_a_delivery_is_recorded(): void
{
Storage::fake('media_derived');
Storage::disk('media_derived')->put('inhalte/demo.txt', 'text');
$content = app(ContentService::class);
$version = $content->publishElementVersion(
$content->createElement('text', 'text', 'Filterblatt'),
null,
['file' => 'inhalte/demo.txt'],
);
$dimension = EditorialDimension::query()->create(['slug' => 'alter', 'label' => 'Alter']);
$value = EditorialDimensionValue::query()->create([
'editorial_dimension_id' => $dimension->id,
'slug' => 'grundschule',
'label' => 'Grundschule',
]);
app(IdentityDimension::class)->assign($version->element, $value);
$articles = app(ArticleService::class);
$article = $articles->create('filter');
$release = $articles->publishRelease($article, $version, 'Eigenständig.');
$offers = app(OfferService::class);
$rights = $offers->createRightsProfile('Lesen', 'ehrenamtlich', ['text' => ['ansehen']]);
$offer = $offers->create('Filterangebot');
$offers->activate($offer, [['target' => $article->fresh(), 'rights' => $rights]], ['grant_kind' => 'auf_abruf']);
$member = User::factory()->create();
app(GrantIssuer::class)->claim($member, $offer);
$this->actingAs($member)->get(route('member.library', ['dimension' => [$value->id]]))->assertOk()->assertSee('Filterblatt');
$this->actingAs($member)->get(route('member.library', ['dimension' => [999]]))->assertOk()->assertDontSee('Filterblatt');
$url = SignedLink::temporary('member.media', now()->addMinutes(5), [
'article' => $article->id,
'release' => $release->id,
'version' => $version->id,
'action' => 'ansehen',
'reader' => $member->id,
]);
$this->actingAs($member)->get($url)->assertOk();
$this->assertSame(1, MediaDelivery::query()->count());
$this->assertSame('ansehen', MediaDelivery::query()->first()->action);
}
}
+51
View File
@@ -0,0 +1,51 @@
<?php
namespace Tests\Feature;
use App\Domain\Catalog\ArticleService;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\IdentityChange;
use App\Domain\Catalog\IdentityProfile;
use App\Domain\Catalog\OfferService;
use App\Domain\Entitlement\GrantIssuer;
use App\Http\CourseOutline;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class IdentityProfileTest extends TestCase
{
use RefreshDatabase;
public function test_display_fields_change_the_library_without_a_new_version(): void
{
$content = app(ContentService::class);
$version = $content->publishElementVersion($content->createElement('text', 'text', 'Arbeitstitel'), 'Text');
$element = $version->element;
$article = app(ArticleService::class)->create('stamm');
app(ArticleService::class)->publishRelease($article, $version, 'Eigenständig.');
$offers = app(OfferService::class);
$rights = $offers->createRightsProfile('Lesen', 'ehrenamtlich', ['text' => ['ansehen']]);
$offer = $offers->create('Stammangebot');
$offers->activate($offer, [['target' => $article->fresh(), 'rights' => $rights]], ['grant_kind' => 'auf_abruf']);
$member = User::factory()->create();
app(GrantIssuer::class)->claim($member, $offer);
$versions = $element->versions()->count();
$releases = $article->releases()->count();
app(IdentityProfile::class)->fill($element, [
'display_title' => 'Sichtbarer Titel',
'summary' => 'Kurz für die Bibliothek',
], $member);
$this->assertSame($versions, $element->fresh()->versions()->count());
$this->assertSame($releases, $article->fresh()->releases()->count());
$this->assertSame('Sichtbarer Titel', app(CourseOutline::class)->title($article->fresh()));
$change = IdentityChange::query()->where('field', 'display_title')->first();
$this->assertSame($member->id, $change->actor_id);
$this->assertNotNull($change->occurred_at);
$this->actingAs($member)->get(route('member.library', ['q' => 'Sichtbarer']))->assertOk()->assertSee('Sichtbarer Titel');
$this->actingAs($member)->get(route('member.library', ['q' => 'kommt-nicht-vor']))->assertOk()->assertDontSee('Sichtbarer Titel');
}
}