assertTrue(Schema::hasColumn('tenants', 'website_type_code')); $this->assertEqualsCanonicalizing([ 'id', 'codigo', 'nombre', 'created_at', 'updated_at', ], Schema::getColumnListing('website_type')); $this->assertEqualsCanonicalizing([ 'id', 'website_type_code', 'nombre', 'descripcion', 'is_required', 'config_schema', 'created_at', 'updated_at', ], Schema::getColumnListing('website_type_extras')); $this->assertEqualsCanonicalizing([ 'id', 'website_code', 'website_type_extra_id', 'config', 'created_at', 'updated_at', ], Schema::getColumnListing('websites_extras')); } public function test_models_map_the_diagram_relations_and_casts(): void { $type = WebsiteType::query()->create([ 'codigo' => 'store', 'nombre' => 'Tienda', ]); $typeExtra = $type->extras()->create([ 'nombre' => 'WhatsApp', 'descripcion' => 'Configuracion del canal de WhatsApp', 'is_required' => true, 'config_schema' => [ 'type' => 'object', 'required' => ['phone'], ], ]); $tenant = $this->createTenant(); $tenant->websiteType()->associate($type)->save(); $websiteExtra = $tenant->websiteExtras()->create([ 'website_type_extra_id' => $typeExtra->id, 'config' => ['phone' => '+5491112345678'], ]); $this->assertTrue($type->extras()->firstOrFail()->is($typeExtra)); $this->assertSame($type->codigo, $typeExtra->website_type_code); $this->assertTrue($type->tenants()->firstOrFail()->is($tenant)); $this->assertTrue($tenant->websiteType()->firstOrFail()->is($type)); $this->assertSame($type->codigo, $tenant->website_type_code); $this->assertTrue($typeExtra->websiteType()->firstOrFail()->is($type)); $this->assertTrue($typeExtra->websiteExtras()->firstOrFail()->is($websiteExtra)); $this->assertTrue($websiteExtra->website()->firstOrFail()->is($tenant)); $this->assertTrue($websiteExtra->websiteTypeExtra()->firstOrFail()->is($typeExtra)); $this->assertTrue($typeExtra->is_required); $this->assertSame([ 'type' => 'object', 'required' => ['phone'], ], $typeExtra->config_schema); $this->assertSame(['phone' => '+5491112345678'], $websiteExtra->config); } public function test_deleting_a_type_cascades_its_definitions_and_website_values(): void { $type = WebsiteType::query()->create([ 'codigo' => 'store', 'nombre' => 'Tienda', ]); $typeExtra = $type->extras()->create([ 'nombre' => 'WhatsApp', 'descripcion' => 'Configuracion del canal de WhatsApp', 'config_schema' => ['type' => 'object'], ]); $websiteExtra = $this->createTenant()->websiteExtras()->create([ 'website_type_extra_id' => $typeExtra->id, 'config' => ['phone' => '+5491112345678'], ]); $type->delete(); $this->assertDatabaseMissing('website_type_extras', ['id' => $typeExtra->id]); $this->assertDatabaseMissing('websites_extras', ['id' => $websiteExtra->id]); } private function createTenant(): Tenant { return Tenant::query()->create([ 'codigo' => 'acme', 'nombre' => 'Acme', 'dominio' => 'acme.com', 'primary_color' => '#111111', 'secondary_color' => '#222222', 'danger_color' => '#333333', 'success_color' => '#444444', 'header_bg_color' => '#ffffff', 'footer_bg_color' => '#ffffff', 'header_logo_id' => 1, 'footer_logo_id' => 2, ]); } }