Add feature tests for shop functionality and organization purchases
- 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:
1 parent
6c8bbee363
commit
4e0760db1e
106 files changed
+4068
-76
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user