['onticket.adminapp.tickets', 'current', false], 'old code' => ['adminapp.tickets', 'current', true], 'another tenant' => ['adminapp.tickets', 'other', false], 'unrelated menu' => ['adminapp.ventas', 'current', false], ]; } #[DataProvider('menuAssignments')] public function test_ticket_menu_requires_an_association_with_the_authenticated_tenant(string $menuCode, string $assignedTenant, bool $allowed): void { Schema::create('tenants', function (Blueprint $table): void { $table->id(); $table->string('codigo'); }); Schema::create('menues', function (Blueprint $table): void { $table->id(); $table->string('code'); }); Schema::create('tenants_menues', function (Blueprint $table): void { $table->string('tenant_code'); $table->string('menu_code'); }); DB::table('tenants')->insert(['codigo' => 'current']); DB::table('menues')->insert(['code' => $menuCode]); DB::table('tenants_menues')->insert(['tenant_code' => $assignedTenant, 'menu_code' => $menuCode]); $user = new User(['tenant_codigo' => 'current']); $request = Request::create('/api/v1/adminapp/tenant/tickets'); $request->setUserResolver(fn () => $user); if (! $allowed) { $this->expectException(HttpException::class); $this->expectExceptionCode(0); } try { $response = (new EnsureTenantHasMenu)->handle($request, fn () => response('allowed'), 'adminapp.tickets'); $this->assertSame('allowed', $response->getContent()); } catch (HttpException $exception) { $this->assertSame(404, $exception->getStatusCode()); throw $exception; } } public function test_all_ticket_routes_and_filter_form_use_the_updated_menu_codes(): void { foreach ([ 'adminapp.tickets.index', 'adminapp.tickets.cancel', 'adminapp.tickets.calculate-refund', 'adminapp.tickets.refund', 'adminapp.tickets.pdf', 'adminapp.tickets.excel', 'adminapp.forms.tickets-filter', ] as $name) { $route = Route::getRoutes()->getByName($name); $this->assertNotNull($route); $this->assertContains('tenant.menu:adminapp.tickets', $route->gatherMiddleware()); } } }