1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 14:14:04 +00:00

Improve early identification tests (#66)

* Separate route-level domain identification test from path/request to improve readability WIP

* Get rid of confusing datasets in route-level identifcation tests

* Clean up updated tests

* Simplify early id tests

* Reduce dataset duplication

* Improve test readability, fix false positive,  polish details

* Separate early ID test from defaulting test (WIP)

* Finish improving and correcting the early identification/default route mode tests

* Make flag/default mode usage more clear by improving the docblock in DealsWithRouteContexts

* Fix PHPUnit deprecation warnings

* code review

* code review

---------

Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
lukinovec 2024-12-20 03:42:23 +01:00 committed by GitHub
parent 48b916e182
commit cb0d7e2902
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 248 additions and 147 deletions

View file

@ -22,18 +22,32 @@ use Stancl\Tenancy\Enums\RouteMode;
trait DealsWithRouteContexts
{
/**
* Get route's middleware context (tenant, central or universal).
* The context is determined by the route's middleware.
* Get the middleware context of a route (tenant, central, or universal).
*
* If the route has the 'universal' middleware, the context is universal,
* and the route is accessible from both contexts.
*
* The universal flag has the highest priority.
*
* If the route has the 'central' middleware, the context is central.
* If the route has the 'tenant' middleware, or any tenancy identification middleware, the context is tenant.
* If you want a universal route to be accessible from the tenant context,
* you still have to provide an identification middleware either using
* route-level middleware or in the global middleware stack.
*
* If the route doesn't have any of the mentioned middleware,
* If the 'tenant' group has identification middleware, you can use it in
* combination with the 'universal' flag, the route will still be universal.
*
* If the route has the 'tenant' middleware, or any tenancy identification
* middleware, the context is tenant (assuming the route doesn't also have
* the 'universal' flag).
*
* If the route has the 'central' middleware, the context is central.
*
* If the route doesn't have any of the mentioned flags/middleware,
* the context is determined by the `tenancy.default_route_mode` config.
*
* If the default route mode is tenant, all unflagged routes will be tenant by default,
* but they will still have to have an identification midddleware (route-level
* or global) to be accessible. Same applies for universal default route mode.
*/
public static function getRouteMode(Route $route): RouteMode
{