'oar-'.uniqid('', true).'@example.com', 'password' => bcrypt('secret'), 'lang' => 'de', 'm_level' => 1, 'payment_account' => now()->addYear(), ]); } function oarMakeAbo(User $user, string $isFor, int $status, ?string $email = null): UserAbo { return UserAbo::create([ 'user_id' => $user->id, 'member_id' => $user->id, 'shopping_user_id' => 0, 'email' => $email ?? 'oar-abo-'.uniqid('', true).'@example.com', 'is_for' => $isFor, 'payone_userid' => 0, 'clearingtype' => 'cc', 'amount' => 5000, 'active' => $status === 2, 'status' => $status, 'abo_interval' => 5, 'start_date' => now()->subMonths(7), 'last_date' => now()->subMonth(), 'next_date' => now()->addWeek(), 'cancel_date' => in_array($status, [4, 5], true) ? now() : null, ]); } it('blockiert die Abo-Neuanlage nicht mehr durch gekuendigte oder beendete Abos', function (): void { $user = oarMakeUser(); oarMakeAbo($user, 'me', 4); expect(AboHelper::userHasAbo($user))->toBeFalse(); oarMakeAbo($user, 'me', 5); expect(AboHelper::userHasAbo($user))->toBeFalse(); }); it('blockiert die Abo-Neuanlage weiterhin bei laufenden, pausierten oder angehaltenen Abos', function (int $status): void { $user = oarMakeUser(); oarMakeAbo($user, 'me', $status); expect(AboHelper::userHasAbo($user))->toBeTrue(); })->with([ 'laufend (2)' => 2, 'angehalten (3)' => 3, 'pausiert (6)' => 6, ]); it('ignoriert gekuendigte Kundenabos bei memberHasAbo und hasAboByEmail', function (): void { $user = oarMakeUser(); $email = 'kunde-'.uniqid('', true).'@example.com'; oarMakeAbo($user, 'ot', 4, $email); $shoppingUser = new ShoppingUser; $shoppingUser->billing_email = $email; expect(AboHelper::memberHasAbo($shoppingUser))->toBeFalse() ->and(AboHelper::hasAboByEmail($email))->toBeFalse(); oarMakeAbo($user, 'ot', 2, $email); expect(AboHelper::memberHasAbo($shoppingUser))->toBeTrue() ->and(AboHelper::hasAboByEmail($email))->toBeTrue(); }); it('liefert 6 als Standard-Mindestlaufzeit ohne gepflegtes Setting', function (): void { expect((int) AboHelper::getAboMinDuration())->toBe(AboHelper::DEFAULT_ABO_MIN_DURATION); }); it('respektiert ein gepflegtes abo-min-duration Setting inklusive 0', function (): void { Setting::setContentBySlug('abo-min-duration', 3, 'int'); expect((int) AboHelper::getAboMinDuration())->toBe(3); Setting::setContentBySlug('abo-min-duration', 0, 'int'); expect((int) AboHelper::getAboMinDuration())->toBe(0); });