Skip to content

Commit da30e1e

Browse files
committed
Clarify Fortify bootstrapper test
1 parent cabf665 commit da30e1e

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

tests/Bootstrappers/FortifyRouteBootstrapperTest.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@
2727
test('fortify route tenancy bootstrapper updates fortify config correctly', function() {
2828
config(['tenancy.bootstrappers' => [FortifyRouteBootstrapper::class]]);
2929

30-
// Config used when FortifyRouteBootstrapper::$passQueryParameter is true (default)
30+
// Config used for generating Fortify route URLs
31+
// when FortifyRouteBootstrapper::$passQueryParameter is true (default)
3132
config([
3233
// Parameter name (RequestDataTenantResolver::queryParameterName())
3334
'tenancy.identification.resolvers.' . RequestDataTenantResolver::class . '.query_parameter' => 'team_query',
3435
// Parameter value (RequestDataTenantResolver::payloadValue())
3536
'tenancy.identification.resolvers.' . RequestDataTenantResolver::class . '.tenant_model_column' => 'company',
3637
]);
3738

38-
// Config used when FortifyRouteBootstrapper::$passQueryParameter is false
39+
// Config used for generating Fortify route URLs
40+
// when FortifyRouteBootstrapper::$passQueryParameter is false
3941
config([
4042
// Parameter name (PathTenantResolver::tenantParameterName())
4143
'tenancy.identification.resolvers.' . PathTenantResolver::class . '.tenant_parameter_name' => 'team_path',
@@ -51,48 +53,51 @@
5153

5254
FortifyRouteBootstrapper::$fortifyHome = $homeRouteName;
5355
FortifyRouteBootstrapper::$fortifyRedirectMap['login'] = $welcomeRouteName;
54-
FortifyRouteBootstrapper::$passTenantParameter = true;
5556

5657
expect(config('fortify.home'))->toBe($originalFortifyHome);
5758
expect(config('fortify.redirects'))->toBe($originalFortifyRedirects);
5859

5960
$tenant = Tenant::create([
60-
'name' => 'Foo', // Tenant parameter value for path identification
61-
'company' => 'Acme', // Tenant parameter value for query string identification
61+
'company' => 'Acme', // Tenant parameter value $passQueryParameter is true
62+
'name' => 'Foo', // Tenant parameter value when $passQueryParameter is false
6263
]);
6364

64-
// RequestDataTenantResolver config used
65+
// The bootstrapper overrides the URLs in the Fortify config correctly (the URLs have the correct tenant parameter + parameter value)
66+
// When $passQueryParameter is true, use the RequestDataTenantResolver config
6567
// - tenant parameter is 'team_query'
66-
// - parameter value is the tenant's company
68+
// - parameter value is the tenant's company ('Acme')
6769
FortifyRouteBootstrapper::$passQueryParameter = true;
6870

6971
tenancy()->initialize($tenant);
72+
7073
expect(config('fortify.home'))->toBe('http://localhost/home?team_query=Acme');
7174
expect(config('fortify.redirects'))->toEqual(['login' => 'http://localhost/welcome?team_query=Acme']);
7275

76+
// The bootstrapper restores the original Fortify config when ending tenancy
7377
tenancy()->end();
78+
7479
expect(config('fortify.home'))->toBe($originalFortifyHome);
7580
expect(config('fortify.redirects'))->toBe($originalFortifyRedirects);
7681

77-
// PathTenantResolver config used
82+
// When $passQueryParameter is false, use the PathTenantResolver config
7883
// - tenant parameter is 'team_path'
79-
// - parameter value is the tenant's name
84+
// - parameter value is the tenant's name ('Foo')
8085
FortifyRouteBootstrapper::$passQueryParameter = false;
8186

8287
tenancy()->initialize($tenant);
88+
8389
expect(config('fortify.home'))->toBe('http://localhost/home?team_path=Foo');
8490
expect(config('fortify.redirects'))->toEqual(['login' => 'http://localhost/welcome?team_path=Foo']);
8591

8692
tenancy()->end();
87-
expect(config('fortify.home'))->toBe($originalFortifyHome);
88-
expect(config('fortify.redirects'))->toBe($originalFortifyRedirects);
8993

94+
// The bootstrapper can override the home and redirects config without the tenant parameter being passed
9095
FortifyRouteBootstrapper::$passTenantParameter = false;
96+
9197
tenancy()->initialize($tenant);
92-
expect(config('fortify.home'))->toBe('http://localhost/home');
93-
expect(config('fortify.redirects'))->toEqual(['login' => 'http://localhost/welcome']);
9498

95-
tenancy()->end();
96-
expect(config('fortify.home'))->toBe($originalFortifyHome);
97-
expect(config('fortify.redirects'))->toBe($originalFortifyRedirects);
99+
expect(config('fortify.home'))->toBe('http://localhost/home')
100+
->not()->toBe($originalFortifyHome);
101+
expect(config('fortify.redirects'))->toEqual(['login' => 'http://localhost/welcome'])
102+
->not()->toBe($originalFortifyRedirects);
98103
});

0 commit comments

Comments
 (0)