|
27 | 27 | test('fortify route tenancy bootstrapper updates fortify config correctly', function() { |
28 | 28 | config(['tenancy.bootstrappers' => [FortifyRouteBootstrapper::class]]); |
29 | 29 |
|
30 | | - // Config used when FortifyRouteBootstrapper::$passQueryParameter is true (default) |
| 30 | + // Config used for generating Fortify route URLs |
| 31 | + // when FortifyRouteBootstrapper::$passQueryParameter is true (default) |
31 | 32 | config([ |
32 | 33 | // Parameter name (RequestDataTenantResolver::queryParameterName()) |
33 | 34 | 'tenancy.identification.resolvers.' . RequestDataTenantResolver::class . '.query_parameter' => 'team_query', |
34 | 35 | // Parameter value (RequestDataTenantResolver::payloadValue()) |
35 | 36 | 'tenancy.identification.resolvers.' . RequestDataTenantResolver::class . '.tenant_model_column' => 'company', |
36 | 37 | ]); |
37 | 38 |
|
38 | | - // Config used when FortifyRouteBootstrapper::$passQueryParameter is false |
| 39 | + // Config used for generating Fortify route URLs |
| 40 | + // when FortifyRouteBootstrapper::$passQueryParameter is false |
39 | 41 | config([ |
40 | 42 | // Parameter name (PathTenantResolver::tenantParameterName()) |
41 | 43 | 'tenancy.identification.resolvers.' . PathTenantResolver::class . '.tenant_parameter_name' => 'team_path', |
|
51 | 53 |
|
52 | 54 | FortifyRouteBootstrapper::$fortifyHome = $homeRouteName; |
53 | 55 | FortifyRouteBootstrapper::$fortifyRedirectMap['login'] = $welcomeRouteName; |
54 | | - FortifyRouteBootstrapper::$passTenantParameter = true; |
55 | 56 |
|
56 | 57 | expect(config('fortify.home'))->toBe($originalFortifyHome); |
57 | 58 | expect(config('fortify.redirects'))->toBe($originalFortifyRedirects); |
58 | 59 |
|
59 | 60 | $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 |
62 | 63 | ]); |
63 | 64 |
|
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 |
65 | 67 | // - tenant parameter is 'team_query' |
66 | | - // - parameter value is the tenant's company |
| 68 | + // - parameter value is the tenant's company ('Acme') |
67 | 69 | FortifyRouteBootstrapper::$passQueryParameter = true; |
68 | 70 |
|
69 | 71 | tenancy()->initialize($tenant); |
| 72 | + |
70 | 73 | expect(config('fortify.home'))->toBe('http://localhost/home?team_query=Acme'); |
71 | 74 | expect(config('fortify.redirects'))->toEqual(['login' => 'http://localhost/welcome?team_query=Acme']); |
72 | 75 |
|
| 76 | + // The bootstrapper restores the original Fortify config when ending tenancy |
73 | 77 | tenancy()->end(); |
| 78 | + |
74 | 79 | expect(config('fortify.home'))->toBe($originalFortifyHome); |
75 | 80 | expect(config('fortify.redirects'))->toBe($originalFortifyRedirects); |
76 | 81 |
|
77 | | - // PathTenantResolver config used |
| 82 | + // When $passQueryParameter is false, use the PathTenantResolver config |
78 | 83 | // - tenant parameter is 'team_path' |
79 | | - // - parameter value is the tenant's name |
| 84 | + // - parameter value is the tenant's name ('Foo') |
80 | 85 | FortifyRouteBootstrapper::$passQueryParameter = false; |
81 | 86 |
|
82 | 87 | tenancy()->initialize($tenant); |
| 88 | + |
83 | 89 | expect(config('fortify.home'))->toBe('http://localhost/home?team_path=Foo'); |
84 | 90 | expect(config('fortify.redirects'))->toEqual(['login' => 'http://localhost/welcome?team_path=Foo']); |
85 | 91 |
|
86 | 92 | tenancy()->end(); |
87 | | - expect(config('fortify.home'))->toBe($originalFortifyHome); |
88 | | - expect(config('fortify.redirects'))->toBe($originalFortifyRedirects); |
89 | 93 |
|
| 94 | + // The bootstrapper can override the home and redirects config without the tenant parameter being passed |
90 | 95 | FortifyRouteBootstrapper::$passTenantParameter = false; |
| 96 | + |
91 | 97 | tenancy()->initialize($tenant); |
92 | | - expect(config('fortify.home'))->toBe('http://localhost/home'); |
93 | | - expect(config('fortify.redirects'))->toEqual(['login' => 'http://localhost/welcome']); |
94 | 98 |
|
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); |
98 | 103 | }); |
0 commit comments