CI Feature / test (push) Failing after 3m16s
Die Produktseite ist die Seite des Artikels (/shop/{id}), den die Option als einzige
Position verkauft, oder die Paketseite. Sie wird nicht mehr einem Programm zugeordnet.
Ein Kauf braucht genau eine Position und einen Preis, sonst lässt er sich nicht aktivieren.
Module und Programme werden dadurch nicht öffentlich (Karten und /programme unverändert).
Tests: Die Tests, die eine Programmseite als Produktseite voraussetzten, prüfen jetzt die
Artikelseite; die Zuordnung „eigene Paketseite oder Programmseite“ entfällt (ADR-52).
Ein Altbestandstest sichert die Programmseite für Angebote mit mehreren Positionen.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
193 lines
8.7 KiB
PHP
193 lines
8.7 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Domain\Catalog\ArticleService;
|
|
use App\Domain\Catalog\BundleService;
|
|
use App\Domain\Catalog\CompositionDisplayRelease;
|
|
use App\Domain\Catalog\CompositionVersion;
|
|
use App\Domain\Catalog\ContentService;
|
|
use App\Domain\Catalog\EditorialContentKind;
|
|
use App\Domain\Catalog\LicenceScope;
|
|
use App\Domain\Catalog\LicenseArticle;
|
|
use App\Domain\Catalog\Offer;
|
|
use App\Domain\Catalog\OfferService;
|
|
use App\Domain\Catalog\RightsProfileVersion;
|
|
use App\Domain\Identity\AccountStatus;
|
|
use App\Domain\Identity\Membership;
|
|
use App\Domain\Identity\Party;
|
|
use App\Domain\Identity\PartyType;
|
|
use App\Domain\Identity\RegisterAccount;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* Testdaten für den Testkauf (Etappe 1): zwei Programme mit Film und Begleitmaterial, ein Starterpaket, die
|
|
* Lizenzoptionen für Privatpersonen und für einen Verein, ein Testverein mit bestellberechtigtem Konto und drei
|
|
* Testkonten. Nur für Entwicklung und die Testinstanz; in Produktion läuft der Seeder nicht.
|
|
* Mehrfach ausführbar: Vorhandenes bleibt unverändert.
|
|
*/
|
|
class ShopDemoSeeder extends Seeder
|
|
{
|
|
/** Nur für automatisierte Tests. Außerhalb von Tests gilt LUF_DEMO_PASSWORD oder ein zufälliges Passwort. */
|
|
public const PASSWORD = 'testkauf-passwort-1';
|
|
|
|
private ?string $password = null;
|
|
|
|
public function run(): void
|
|
{
|
|
if (app()->isProduction() || LicenseArticle::query()->where('code', 'shop-konflikte')->exists()) {
|
|
return;
|
|
}
|
|
|
|
$content = app(ContentService::class);
|
|
$articles = app(ArticleService::class);
|
|
$bundles = app(BundleService::class);
|
|
$offers = app(OfferService::class);
|
|
$this->password = app()->runningUnitTests()
|
|
? self::PASSWORD
|
|
: (getenv('LUF_DEMO_PASSWORD') ?: Str::random(24));
|
|
$editor = $this->account('Demo Redaktion', 'shop-demo-redaktion@example.test');
|
|
|
|
[$konflikteVersion, $konflikteArticle] = $this->program(
|
|
$content, $articles, $editor, 'shop-konflikte', 'Konflikte im Training',
|
|
'Wie Trainerinnen und Trainer Konflikte in der Gruppe ruhig und klar begleiten.',
|
|
'Ein Film, ein Arbeitsblatt und eine Anleitung für sechs Trainingseinheiten.',
|
|
'Konflikte erkennen, benennen und gemeinsam lösen.',
|
|
);
|
|
[$grenzenVersion, $grenzenArticle] = $this->program(
|
|
$content, $articles, $editor, 'shop-grenzen', 'Grenzen setzen im Verein',
|
|
'Sicher auftreten, Grenzen vermitteln und Kinder stärken.',
|
|
'Film und Begleitmaterial für einen Übungsabend zu Grenzen und Respekt.',
|
|
'Grenzen verständlich vermitteln.',
|
|
);
|
|
[$starterVersion, $starterArticle] = $this->program(
|
|
$content, $articles, $editor, 'shop-starter', 'Starterpaket für neue Trainer',
|
|
'Das Einstiegspaket mit beiden Programmen und einer Einführung für neue Trainerinnen und Trainer.',
|
|
'Zusätzlich zu beiden Programmen enthält das Paket eine Einführung ins Konzept.',
|
|
'Das Konzept kennenlernen.',
|
|
);
|
|
|
|
$privat = $offers->createRightsProfile('Privatlizenz ehrenamtlich', 'ehrenamtlich', [
|
|
'film' => ['streamen', 'laden'],
|
|
'pdf' => ['ansehen', 'laden'],
|
|
]);
|
|
$verein = $offers->createRightsProfile('Vereinslizenz institutionell', 'institutionell', [
|
|
'film' => ['streamen', 'laden'],
|
|
'pdf' => ['ansehen', 'laden'],
|
|
]);
|
|
|
|
$this->offer($offers, 'Konflikte im Training: Privatlizenz', 'Privatlizenz', $konflikteVersion, [$konflikteArticle, $privat], 4900, 'person', LicenceScope::SINGLE, 1);
|
|
$this->offer($offers, 'Konflikte im Training: Vereinslizenz', 'Mehrfachlizenz für Vereine', $konflikteVersion, [$konflikteArticle, $verein], 14900, 'organisation', LicenceScope::MULTI, 5);
|
|
$this->offer($offers, 'Grenzen setzen: Privatlizenz', 'Privatlizenz', $grenzenVersion, [$grenzenArticle, $privat], 2900, 'person', LicenceScope::SINGLE, 1);
|
|
|
|
$bundle = $bundles->create('Starterpaket');
|
|
$starter = $bundles->publish($bundle, [$konflikteArticle->fresh(), $grenzenArticle->fresh(), $starterArticle->fresh()]);
|
|
$paket = $offers->create('Starterpaket: Privatlizenz');
|
|
$offers->activate($paket, [['target' => $starter, 'rights' => $privat]], ['grant_kind' => 'kauf', 'price_cents' => 5900, 'holder_kind' => 'person', 'licence_scope' => LicenceScope::SINGLE, 'trainer_count' => 1]);
|
|
$offers->setOptionLabel($paket, 'Starterpaket (zwei Programme und Einführung)');
|
|
|
|
$tina = $this->account('Tina Trainerin', 'tina.trainerin@example.test');
|
|
$vera = $this->account('Vera Vorstand', 'vera.vorstand@example.test');
|
|
$max = $this->account('Max Mitglied', 'max.mitglied@example.test');
|
|
$club = Party::query()->firstOrCreate(
|
|
['type' => PartyType::Organisation, 'display_name' => 'Testverein Musterstadt e. V.'],
|
|
);
|
|
Membership::query()->firstOrCreate(['user_id' => $vera->id, 'party_id' => $club->id], ['role' => 'org_admin', 'may_order' => true]);
|
|
Membership::query()->firstOrCreate(['user_id' => $max->id, 'party_id' => $club->id], ['role' => 'mitglied', 'may_order' => false]);
|
|
unset($tina);
|
|
|
|
if (! app()->runningUnitTests()) {
|
|
$this->command?->info('Testkonten angelegt (tina.trainerin, vera.vorstand, max.mitglied und shop-demo-redaktion bei example.test). Passwort: '.($this->password));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Zwei Dateien (Film, Begleitmaterial) als Platzhalter im Speicher, ein Programm als Komposition mit
|
|
* Anzeigefreigabe und ein Lizenzartikel dazu.
|
|
*
|
|
* @return array{0: CompositionVersion, 1: LicenseArticle}
|
|
*/
|
|
private function program(
|
|
ContentService $content,
|
|
ArticleService $articles,
|
|
User $editor,
|
|
string $code,
|
|
string $title,
|
|
string $teaser,
|
|
string $summary,
|
|
string $goal,
|
|
): array {
|
|
$disk = Storage::disk('media_derived');
|
|
$disk->put('inhalte/'.$code.'/film.mp4', 'Platzhalter für den Film '.$title);
|
|
$disk->put('inhalte/'.$code.'/begleitmaterial.pdf', "%PDF-1.4\n% Platzhalter für das Begleitmaterial ".$title."\n%%EOF\n");
|
|
|
|
$film = $content->publishElementVersion(
|
|
$content->createElement('film', 'film', 'Film '.$title),
|
|
null,
|
|
['file' => 'inhalte/'.$code.'/film.mp4'],
|
|
);
|
|
$sheet = $content->publishElementVersion(
|
|
$content->createElement('pdf', 'pdf', 'Begleitmaterial '.$title),
|
|
null,
|
|
['file' => 'inhalte/'.$code.'/begleitmaterial.pdf'],
|
|
);
|
|
$composition = $content->createComposition($title);
|
|
$composition->editorial_content_kind_id = EditorialContentKind::query()->where('slug', 'programm')->value('id');
|
|
$composition->display_title = $title;
|
|
$composition->teaser = $teaser;
|
|
$composition->summary = $summary;
|
|
$composition->save();
|
|
$version = $content->publishComposition(
|
|
$composition,
|
|
[['role' => 'Film', 'target' => $film], ['role' => 'Begleitmaterial', 'target' => $sheet]],
|
|
null,
|
|
null,
|
|
['learning_goal' => $goal],
|
|
);
|
|
app(CompositionDisplayRelease::class)->release($version, $editor);
|
|
|
|
$article = $articles->create($code, 'Testkauf');
|
|
$article->working_title = $title;
|
|
$article->display_title = $title;
|
|
$article->save();
|
|
$articles->publishRelease($article, $version, 'Programm für den Testkauf.');
|
|
|
|
return [$version, $article->fresh()];
|
|
}
|
|
|
|
/**
|
|
* @param array{0: LicenseArticle, 1: RightsProfileVersion} $line
|
|
*/
|
|
private function offer(OfferService $offers, string $name, string $label, CompositionVersion $version, array $line, int $cents, string $holder, ?string $scope = null, ?int $trainers = null): Offer
|
|
{
|
|
$offer = $offers->create($name);
|
|
$offers->activate($offer, [['target' => $line[0], 'rights' => $line[1]]], [
|
|
'grant_kind' => 'kauf',
|
|
'price_cents' => $cents,
|
|
'holder_kind' => $holder,
|
|
'licence_scope' => $scope,
|
|
'trainer_count' => $trainers,
|
|
]);
|
|
$offers->setOptionLabel($offer, $label);
|
|
|
|
return $offer;
|
|
}
|
|
|
|
private function account(string $name, string $email): User
|
|
{
|
|
$existing = User::query()->where('email', $email)->first();
|
|
|
|
if ($existing !== null) {
|
|
return $existing;
|
|
}
|
|
|
|
$user = app(RegisterAccount::class)->register($name, $email, (string) $this->password, true);
|
|
$user->forceFill(['email_verified_at' => now(), 'status' => AccountStatus::Aktiv])->save();
|
|
|
|
return $user;
|
|
}
|
|
}
|