1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-06-20 22:04:02 +00:00
tenancy/tests
lukinovec dfb0e1ad66
TenancyUrlGenerator: override toRoute(), refactor (#1439)
This PR adds the `toRoute()` method override to `TenancyUrlGenerator`.
`toRoute()` now attempts to find a tenant equivalent of the passed route
(= a route with the same name as the passed one, but with the tenant
prefix) and generates URL for the tenant route. This behavior can be
bypassed using the bypass parameter, like with the `route()` method
override `TenancyUrlGenerator` had until now.

The primary reason for adding this is that Livewire v4 no longer uses
the `route()` helper (which automatically prefixes the passed route name
because of the override in `TenancyUrlGenerator`) in
`Livewire::getUpdateUri()`. Now, it uses `toRoute()`
(544aa3dfb8 (diff-e7609f8b0a60bde5a85067803d4e2f08f235c7cee9225a51ea67a85ff9a1d694R52)),
which didn't automatically swap the route for its 'tenant.'-prefixed
equivalent in tenant context (until now). So for the Livewire
integration to work with path identification, we need to override
`toRoute()` as described.

The `temporarySignedRoute()` override got removed because
`temporarySignedRoute()` calls `route()` under the hood, there's no need
to specifically override `temporarySignedRoute()`.

> Note: Browsing old convos, it seems like the `temporarySignedRoute()`
override was needed to make Livewire file uploads work with path
identification, but it's not needed anymore. TenancyUrlGenerator had
some changes since then, and now, I can't see the _exact_ reason why we
needed the override (`temporarySignedRoute()` uses `route()` under the
hood, so the only thing that should really matter is overriding
`route()`/`toRoute()`). It was likely a leftover from some older
implementation.

The `route()` override got simplified. Since `route()` uses `toRoute()`
under the hood, the `route()` override only has to have the prefixing
logic. The rest is delegated to `toRoute()`.

> Note: Even though we override `toRoute()` now which `route()` uses for
generating the URLs, we still need to override `route()` for its
`$this->routes->getByName($name)` call to receive the prefixed name. For
example, if `route()` wasn't overridden, and we only had one route:
`tenant.foo` (no central `foo` route), and we'd call `route('foo')`,
we'd get an exception saying that route "foo" wasn't found, even if
automatic route name prefixing was enabled and `toRoute()` was
overridden. With the `route()` override, `route('foo')` acts as if we
passed 'tenant.foo' instead of 'foo'.

Comments in TenancyUrlGenerator and UrlGeneratorBootstrapper got updated
to be more accurate. All _intentionally_ affected methods are listed in
TenancyUrlGenerator's docblock.

---------

Co-authored-by: Samuel Stancl <samuel@archte.ch>
2026-06-06 14:52:37 -07:00
..
Bootstrappers TenancyUrlGenerator: override toRoute(), refactor (#1439) 2026-06-06 14:52:37 -07:00
Etc [MINOR BC BREAK] Syncing: PivotWithRelation -> PivotWithCentralResource 2025-11-26 05:52:55 +01:00
Features Add TenantConfigBootstrapper, deprecate Feature implementation 2025-09-26 13:49:15 +02:00
RLS [4.x] Fix dropRLSPolicies() (#1413) 2025-11-08 00:52:08 +01:00
ActionTest.php resolve minor todos 2025-08-18 15:05:17 +02:00
AutomaticModeTest.php [4.x] Add Tenancy::reinitialize() method (#1449) 2026-04-08 19:21:43 +02:00
BroadcastingTest.php [4.x] Laravel 12 support (#1321) 2025-02-25 16:26:18 +01:00
CachedTenantResolverTest.php [4.x] Support database cache store tenancy (#1290) (resolve #852) 2025-08-08 00:54:01 +02:00
CloneActionTest.php Cloning: improve type annotations, add cloneRoutes() for convenience 2025-11-10 02:16:57 +01:00
CombinedDomainAndSubdomainIdentificationTest.php [4.x] Laravel 12 support (#1321) 2025-02-25 16:26:18 +01:00
CommandsTest.php [4.x] Use --database in tenants:migrate as the template connection (#1386) 2025-08-25 15:57:15 +02:00
DatabaseCacheBootstrapperTest.php [4.x] Support database cache store tenancy (#1290) (resolve #852) 2025-08-08 00:54:01 +02:00
DatabasePreparationTest.php Skip DB deletion when create_database=false, add ignoreFailures (#1394) 2026-05-01 21:57:19 +02:00
DatabaseUsersTest.php [4.x] Laravel 12 support (#1321) 2025-02-25 16:26:18 +01:00
DeleteDomainsJobTest.php Resolve test to-dos (#45) 2024-04-18 00:22:03 +02:00
DomainTest.php [4.x] Laravel 12 support (#1321) 2025-02-25 16:26:18 +01:00
EarlyIdentificationTest.php Correct DomainTenantResolver::isSubdomain() check (#1425) 2026-05-11 14:26:06 +02:00
EventListenerTest.php [4.x] Laravel 12 support (#1321) 2025-02-25 16:26:18 +01:00
GlobalCacheTest.php [4.x] Support database cache store tenancy (#1290) (resolve #852) 2025-08-08 00:54:01 +02:00
InitializedBootstrappersTest.php [4.x] Only revert initialized bootstrappers (#1385) 2025-08-05 11:12:25 +02:00
MailTest.php [4.x] Laravel 12 support (#1321) 2025-02-25 16:26:18 +01:00
MaintenanceModeTest.php Fix #1404: support universal routes in CheckTenantForMaintenanceMode 2025-10-14 17:22:35 +02:00
ManualModeTest.php [4.x] Laravel 12 support (#1321) 2025-02-25 16:26:18 +01:00
OriginHeaderIdentificationTest.php fix origin identification: parse hostname when full URL is used 2025-07-14 21:44:12 +02:00
PathIdentificationTest.php [4.x] Test that route model binding works correctly with path identification (#1360) 2025-06-02 19:05:17 +02:00
PendingTenantsTest.php [MINOR BC] Create pending tenants with pending_since, improve --with-pending (#1458) 2026-06-05 15:36:57 -07:00
Pest.php [4.x] Support database cache store tenancy (#1290) (resolve #852) 2025-08-08 00:54:01 +02:00
PreventAccessFromUnwantedDomainsTest.php [4.x] Laravel 12 support (#1321) 2025-02-25 16:26:18 +01:00
QueueTest.php [4.x] Laravel 12 support (#1321) 2025-02-25 16:26:18 +01:00
RequestDataIdentificationTest.php [4.x] Resolve testing todos (#1361) 2025-08-03 23:21:03 +02:00
ResourceSyncingTest.php Syncing: support morph maps in TriggerSyncingEvents 2025-12-12 03:43:52 +01:00
RouteMiddlewareTest.php Instead of assigning $innerMiddleware during group MW unpacking, merge it (#1371) 2025-07-01 17:23:13 +02:00
RunForMultipleTest.php [4.x] Fix 1267: early return in runForMultiple if an empty array is passed (#1286) 2025-02-14 08:19:02 +01:00
ScopeSessionsTest.php [4.x] Make ScopeSessions usable on universal routes (#1342) 2025-04-04 03:15:37 +02:00
SessionSeparationTest.php [4.x] Laravel 13 support (#1443) 2026-03-18 19:17:28 +01:00
SingleDatabaseTenancyTest.php [4.x] Laravel 12 support (#1321) 2025-02-25 16:26:18 +01:00
SingleDomainTenantTest.php [4.x] Laravel 12 support (#1321) 2025-02-25 16:26:18 +01:00
SubdomainTest.php Correct DomainTenantResolver::isSubdomain() check (#1425) 2026-05-11 14:26:06 +02:00
TenantAssetTest.php Remove TestCase::randomString() 2025-08-25 17:43:45 +02:00
TenantAwareCommandTest.php [4.x] Laravel 12 support (#1321) 2025-02-25 16:26:18 +01:00
TenantDatabaseManagerTest.php PHP 8.5 support 2025-10-20 01:44:24 +02:00
TenantModelTest.php Add UUIDv7Generator 2025-11-04 15:45:48 +01:00
TenantUserImpersonationTest.php [MINOR BC] UserImpersonation: store auth guard in session, add $logout param to stopImpersonating() (#1437) 2026-06-05 14:15:19 -07:00
TestCase.php PHP 8.5 support 2025-10-20 01:44:24 +02:00
UniversalRouteTest.php [4.x] Laravel 12 support (#1321) 2025-02-25 16:26:18 +01:00