Add feature tests for shop functionality and organization purchases
Deploy Test / test (push) Successful in 1m38s
Deploy Test / deploy (push) Successful in 31s

- Implement OfferOptionAdminTest to validate offer option management, including price display, activation, and cancellation.
- Create OrganizationPurchaseTest to ensure correct handling of organization purchases, including access control and order processing.
- Add ShopProductPageTest to verify shop product listings, search functionality, and product page details.
- Introduce BuildsShop trait for seeding test data related to shop functionality.
- Implement MoneyTest to validate money parsing and formatting, ensuring correct handling of euro amounts.
This commit is contained in:
Lars committed 2026-11-21 12:06:24 +01:00
1 parent 6c8bbee363
commit 4e0760db1e
106 files changed
+4068 -76

No files matched your search

@@ -0,0 +1,82 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
/**
* Etappe 1 (Testkauf): nur ergänzend, keine Daten werden gelöscht oder umbenannt.
*
* - Ein Angebot (Lizenzoption) kann auf die Komposition zeigen, deren öffentliche Seite die Produktseite ist
* (`offers.composition_id`). Angebote derselben Komposition bilden die Angebotsgruppe (Alternativen).
* - Mitgliedschaft eines Kontos in einer Organisation mit Bestellberechtigung (Domänenmodell 04, MEMBERSHIP).
* - Der Erwerb hält das auslösende Konto, die Bestellung Gesamtsumme und Währung, die Position Inhaber, Währung,
* Steuerklasse und Vergabeart als Kopie. `orders.party_id` ist der Lizenzinhaber, `orders.user_id` das handelnde Konto.
*/
return new class extends Migration
{
public function up(): void
{
Schema::table('offers', function (Blueprint $table) {
$table->foreignId('composition_id')->nullable()->constrained('compositions')->nullOnDelete();
$table->string('option_label')->nullable();
});
Schema::create('memberships', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->foreignId('party_id')->constrained()->restrictOnDelete();
$table->string('role')->default('mitglied');
$table->boolean('may_order')->default(false);
$table->date('valid_from')->nullable();
$table->date('valid_until')->nullable();
$table->timestamps();
$table->unique(['user_id', 'party_id']);
});
Schema::table('acquisitions', function (Blueprint $table) {
$table->foreignId('acting_user_id')->nullable()->constrained('users')->nullOnDelete();
});
Schema::table('orders', function (Blueprint $table) {
$table->unsignedInteger('total_cents')->nullable();
$table->string('currency', 3)->default('EUR');
});
Schema::table('order_lines', function (Blueprint $table) {
$table->string('currency', 3)->default('EUR');
$table->string('tax_class')->nullable();
$table->string('grant_kind')->nullable();
$table->foreignId('holder_party_id')->nullable()->constrained('parties')->restrictOnDelete();
});
// Bestehende Bestellungen: Summe und Inhaber der Position aus den vorhandenen Angaben.
foreach (DB::table('orders')->get() as $order) {
DB::table('orders')->where('id', $order->id)->update([
'total_cents' => (int) DB::table('order_lines')->where('order_id', $order->id)->sum('price_cents'),
]);
DB::table('order_lines')->where('order_id', $order->id)->update(['holder_party_id' => $order->party_id]);
}
}
public function down(): void
{
Schema::table('order_lines', function (Blueprint $table) {
$table->dropConstrainedForeignId('holder_party_id');
$table->dropColumn(['currency', 'tax_class', 'grant_kind']);
});
Schema::table('orders', function (Blueprint $table) {
$table->dropColumn(['total_cents', 'currency']);
});
Schema::table('acquisitions', function (Blueprint $table) {
$table->dropConstrainedForeignId('acting_user_id');
});
Schema::dropIfExists('memberships');
Schema::table('offers', function (Blueprint $table) {
$table->dropConstrainedForeignId('composition_id');
$table->dropColumn('option_label');
});
}
};
+189
View File
@@ -0,0 +1,189 @@
<?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\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');
$this->offer($offers, 'Konflikte im Training: Vereinslizenz', 'Mehrfachlizenz für Vereine', $konflikteVersion, [$konflikteArticle, $verein], 14900, 'organisation');
$this->offer($offers, 'Grenzen setzen: Privatlizenz', 'Privatlizenz', $grenzenVersion, [$grenzenArticle, $privat], 2900, 'person');
$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']);
$offers->assignProduct($paket, $starterVersion->composition_id, '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): Offer
{
$offer = $offers->create($name);
$offers->activate($offer, [['target' => $line[0], 'rights' => $line[1]]], [
'grant_kind' => 'kauf',
'price_cents' => $cents,
'holder_kind' => $holder,
]);
$offers->assignProduct($offer, $version->composition_id, $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;
}
}