From c9ecf8c4d72f2c668fae44fd9dc991965064d07e Mon Sep 17 00:00:00 2001
From: Fabrice Gangler <fabrice.gangler@adullact.org>
Date: Tue, 18 Mar 2025 11:21:41 +0100
Subject: [PATCH] test: add organizations fixture

---
 .../DataFixtures/AppOrganizationFixtures.php  | 85 +++++++++++++++++++
 1 file changed, 85 insertions(+)
 create mode 100644 webapp/src/DataFixtures/AppOrganizationFixtures.php

diff --git a/webapp/src/DataFixtures/AppOrganizationFixtures.php b/webapp/src/DataFixtures/AppOrganizationFixtures.php
new file mode 100644
index 0000000..20518eb
--- /dev/null
+++ b/webapp/src/DataFixtures/AppOrganizationFixtures.php
@@ -0,0 +1,85 @@
+<?php
+
+/*
+ * This file is part of the Comptoir-du-Libre software.
+ * <https://gitlab.adullact.net/Comptoir/comptoir-du-libre>
+ *
+ * Copyright (c) ADULLACT   <https://adullact.org>
+ *               Association des Développeurs et Utilisateurs de Logiciels Libres
+ *               pour les Administrations et les Collectivités Territoriales
+ *
+ * Comptoir-du-Libre is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this software. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>.
+ */
+
+declare(strict_types=1);
+
+namespace App\DataFixtures;
+
+use App\Entity\Organization;
+use App\Entity\OrganizationType;
+use Doctrine\Bundle\FixturesBundle\Fixture;
+use Doctrine\Persistence\ObjectManager;
+
+class AppOrganizationFixtures extends Fixture
+{
+    public const ORGANIZATION_TYPES = [
+        'public_sector', 'no_profit', 'company'
+    ];
+
+    public const ORGANIZATIONS = [
+        [
+            'createdAt' => '2022-06-19 13:31:24',
+            'updatedAt' => '2022-07-25 14:22:05',
+            'type' => 'public_sector',
+            'name' => "Mairie d'Abbeville",
+            'slug' => 'mairie-d-abbeville',
+        ],
+        [
+            'createdAt' => '2023-06-19 13:31:24',
+            'updatedAt' => '2023-07-25 14:22:05',
+            'type' => 'public_sector',
+            'name' => "Ville Montpellier (34)",
+            'slug' => 'ville-montpellier-34',
+            'website' => 'https://www.montpellier.fr',
+            'oldComptoirId' => 17,
+        ],
+    ];
+
+
+    public function load(ObjectManager $manager): void
+    {
+        $organizationTypes = [];
+        foreach (self::ORGANIZATION_TYPES as $type) {
+            $organizationType = new OrganizationType();
+            $organizationType->setName("$type");
+            $manager->persist($organizationType);
+            $manager->flush();
+            $organizationTypes["$type"] = $organizationType;
+        }
+
+        foreach (self::ORGANIZATIONS as $key => $data) {
+            $createdAt = new \DateTimeImmutable($data['createdAt']);
+            $updatedAt = new \DateTimeImmutable($data['updatedAt']);
+            $organization = new Organization();
+            $organization->setName($data['name']);
+            $organization->setSlug($data['slug']);
+            $organization->setCreatedAt($createdAt);
+            $organization->setUpdatedAt($updatedAt);
+            $organization->setType($organizationTypes[$data['type']]);
+            if (isset($data['website'])) {
+                $organization->setWebsite($data['website']);
+            }
+            if (isset($data['oldComptoirId'])) {
+                $organization->setOldComptoirId($data['oldComptoirId']);
+            }
+            $manager->persist($organization);
+            $manager->flush();
+        }
+    }
+}
-- 
GitLab