hooks in config/services.php/.env.example, and updated wizard steps/controllers to store session payloads, attach packages, and surface localized success/error states. - Retooled payment handling for both Stripe and PayPal, adding richer status management in CheckoutController/ PayPalController, fallback flows in the wizard’s PaymentStep.tsx, and fresh feature tests for intent creation, webhooks, and the wizard CTA. - Introduced a consent-aware Matomo analytics stack: new consent context, cookie-banner UI, useAnalytics/ useCtaExperiment hooks, and MatomoTracker component, then instrumented marketing pages (Home, Packages, Checkout) with localized copy and experiment tracking. - Polished package presentation across marketing UIs by centralizing formatting in PresentsPackages, surfacing localized description tables/placeholders, tuning badges/layouts, and syncing guest/marketing translations. - Expanded docs & reference material (docs/prp/*, TODOs, public gallery overview) and added a Playwright smoke test for the hero CTA while reconciling outstanding checklist items.
104 lines
3.7 KiB
PHP
104 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Package;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Laravel\Socialite\Contracts\Factory as SocialiteFactory;
|
|
use Laravel\Socialite\Contracts\Provider as SocialiteProvider;
|
|
use Laravel\Socialite\Contracts\User as SocialiteUserContract;
|
|
use Mockery;
|
|
use Tests\TestCase;
|
|
|
|
class CheckoutGoogleControllerTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
Mockery::close();
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function test_redirect_persists_package_context_and_delegates_to_google(): void
|
|
{
|
|
$package = Package::factory()->create();
|
|
|
|
$provider = Mockery::mock(SocialiteProvider::class);
|
|
$provider->shouldReceive('scopes')->andReturnSelf();
|
|
$provider->shouldReceive('with')->andReturnSelf();
|
|
$provider->shouldReceive('redirect')->once()->andReturn(redirect('/google/auth'));
|
|
|
|
$this->mock(SocialiteFactory::class, function ($mock) use ($provider) {
|
|
$mock->shouldReceive('driver')->with('google')->andReturn($provider);
|
|
});
|
|
|
|
$response = $this->get('/checkout/auth/google?package_id=' . $package->id . '&locale=de');
|
|
|
|
$response->assertRedirect('/google/auth');
|
|
$this->assertSame($package->id, session('checkout_google_payload.package_id'));
|
|
}
|
|
|
|
public function test_callback_creates_user_and_logs_in(): void
|
|
{
|
|
$package = Package::factory()->create(['price' => 0]);
|
|
|
|
$googleUser = Mockery::mock(SocialiteUserContract::class);
|
|
$googleUser->shouldReceive('getEmail')->andReturn('checkout-google@example.com');
|
|
$googleUser->shouldReceive('getName')->andReturn('Checkout Google');
|
|
|
|
$provider = Mockery::mock(SocialiteProvider::class);
|
|
$provider->shouldReceive('user')->andReturn($googleUser);
|
|
|
|
$this->mock(SocialiteFactory::class, function ($mock) use ($provider) {
|
|
$mock->shouldReceive('driver')->with('google')->andReturn($provider);
|
|
});
|
|
|
|
$response = $this
|
|
->withSession([
|
|
'checkout_google_payload' => ['package_id' => $package->id, 'locale' => 'de'],
|
|
])
|
|
->get('/checkout/auth/google/callback');
|
|
|
|
$response->assertRedirect(route('purchase.wizard', ['package' => $package->id]));
|
|
|
|
$this->assertAuthenticated();
|
|
|
|
$user = auth()->user();
|
|
$this->assertSame('checkout-google@example.com', $user->email);
|
|
$this->assertTrue($user->pending_purchase);
|
|
$this->assertNotNull($user->tenant);
|
|
$this->assertDatabaseHas('tenant_packages', [
|
|
'tenant_id' => $user->tenant_id,
|
|
'package_id' => $package->id,
|
|
]);
|
|
}
|
|
|
|
public function test_callback_with_missing_email_flashes_error(): void
|
|
{
|
|
$package = Package::factory()->create();
|
|
|
|
$googleUser = Mockery::mock(SocialiteUserContract::class);
|
|
$googleUser->shouldReceive('getEmail')->andReturn(null);
|
|
$googleUser->shouldReceive('getName')->andReturn('No Email');
|
|
|
|
$provider = Mockery::mock(SocialiteProvider::class);
|
|
$provider->shouldReceive('user')->andReturn($googleUser);
|
|
|
|
$this->mock(SocialiteFactory::class, function ($mock) use ($provider) {
|
|
$mock->shouldReceive('driver')->with('google')->andReturn($provider);
|
|
});
|
|
|
|
$response = $this
|
|
->withSession([
|
|
'checkout_google_payload' => ['package_id' => $package->id, 'locale' => 'en'],
|
|
])
|
|
->get('/checkout/auth/google/callback');
|
|
|
|
$response->assertRedirect(route('purchase.wizard', ['package' => $package->id]));
|
|
$response->assertSessionHas('checkout_google_error');
|
|
$this->assertGuest();
|
|
}
|
|
}
|