Vincent преди 1 година
родител
ревизия
7fba570734

+ 1 - 1
src/Entity/Core/File.php

@@ -174,7 +174,7 @@ class File
     /**
      * Serveur sur lequel le fichier est physiquement stocké
      */
-    #[ORM\Column(length: 5, enumType: FileHostEnum::class)]
+    #[ORM\Column(length: 5, enumType: FileHostEnum::class,options: ['default' => FileHostEnum::AP2I])]
     private ?FileHostEnum $host = FileHostEnum::AP2I;
 
     //    #[ORM\Column]

+ 1 - 1
src/Entity/Organization/Parameters.php

@@ -129,7 +129,7 @@ class Parameters
     private bool $bulletinEditWithoutEvaluation = true;
 
     #[ORM\Column(length: 255, nullable: true, enumType: SendToBulletinEnum::class, options: ['default' => SendToBulletinEnum::STUDENTS_AND_THEIR_GUARDIANS])]
-    private ?SendToBulletinEnum $bulletinReceiver = null;
+    private ?SendToBulletinEnum $bulletinReceiver = SendToBulletinEnum::STUDENTS_AND_THEIR_GUARDIANS;
 
     #[ORM\Column(length: 255, nullable: true)]
     private ?string $usernameSMS = null;

+ 0 - 7
src/Entity/Organization/Settings.php

@@ -77,18 +77,11 @@ class Settings
         return $this;
     }
 
-    /**
-     * @return mixed[]|null
-     */
     public function getModules(): ?array
     {
         return $this->modules;
     }
 
-    /**
-     * @param mixed[]|null $modules
-     * @return $this
-     */
     public function setModules(?array $modules): self
     {
         $this->modules = $modules;

+ 0 - 39
src/Service/Export/Encoder/DocXEncoder

@@ -1,39 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace App\Service\Export\Encoder;
-
-use App\Enum\Export\ExportFormatEnum;
-use Phpdocx\Create\CreateDocx;
-
-/**
- * Encode HTML to docx format
- */
-class DocXEncoder implements EncoderInterface
-{
-
-  public function support(string $format): bool
-  {
-    return $format === ExportFormatEnum::DOCX
-  }
-
-  /**
-   * Encode the given HTML content into docX, and
-   * return the encoded content
-   *
-   * @param string $html
-   * @param array<mixed> $options
-   * @return string
-   */
-  public function encode(string $html, array $options = []): string
-  {
-    $docx = new CreateDocx();
-    $docx->addText($html);
-    $tempFile = tempnam(sys_get_temp_dir(), 'docx');
-    $docx->createDocx($tempFile);
-    $docxContent = file_get_contents($tempFile);
-    unlink($tempFile);
-    return $docxContent;
-  }
-}

+ 2 - 0
src/Service/Organization/Utils.php

@@ -48,6 +48,7 @@ class Utils
      * Teste si l'organisation est considérée comme un school == a un produit school standard ou premium
      * @param Organization $organization
      * @return bool
+     * @see UtilsTest::testIsSchool()
      */
     public function isSchool(Organization $organization): bool {
         return $organization->getSettings()->getProduct() === SettingsProductEnum::SCHOOL
@@ -58,6 +59,7 @@ class Utils
      * Teste si l'organisation est considérée comme un school == a un produit artiste standard ou premium
      * @param Organization $organization
      * @return bool
+     * @see UtilsTest::testIsArtist()
      */
     public function isArtist(Organization $organization): bool {
         return $organization->getSettings()->getProduct() === SettingsProductEnum::ARTIST

+ 1 - 0
tests/Unit/Service/Dolibarr/DolibarrSyncServiceTest.php

@@ -69,6 +69,7 @@ class DolibarrSyncServiceTest extends TestCase
     private MockObject | ArrayUtils $arrayUtils;
     private MockObject | TranslatorInterface $translator;
     private MockObject | LoggerInterface $logger;
+    private MockObject | Utils $organizationUtils;
 
     public function setUp(): void {
         $this->organizationRepository = $this->getMockBuilder(OrganizationRepository::class)

+ 107 - 34
tests/Unit/Service/Organization/UtilsTest.php

@@ -28,59 +28,48 @@ class UtilsTest extends TestCase
     {
         $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['isStructure'])->getMock();
 
-        $settings = $this->getMockBuilder(Settings::class)->getMock();
-        $organization = $this->getMockBuilder(Organization::class)->getMock();
-        $organization->method('getSettings')->willReturn($settings);
-
-        // Each cal to 'isStructure' provoke 2 calls on getProduct
-        $settings->method('getProduct')->willReturnOnConsecutiveCalls(
-            SettingsProductEnum::ARTIST,
-            SettingsProductEnum::ARTIST,
-            SettingsProductEnum::ARTIST_PREMIUM,
-            SettingsProductEnum::ARTIST_PREMIUM,
-            SettingsProductEnum::SCHOOL,
-            SettingsProductEnum::SCHOOL,
-            SettingsProductEnum::SCHOOL_PREMIUM,
-            SettingsProductEnum::SCHOOL_PREMIUM,
-            SettingsProductEnum::MANAGER,
-            SettingsProductEnum::MANAGER,
-            SettingsProductEnum::MANAGER_PREMIUM,
-            SettingsProductEnum::MANAGER_PREMIUM,
-        );
-
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST);
         $this->assertTrue($organizationUtils->isStructure($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST_PREMIUM);
         $this->assertTrue($organizationUtils->isStructure($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL);
         $this->assertTrue($organizationUtils->isStructure($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL_PREMIUM);
         $this->assertTrue($organizationUtils->isStructure($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER);
         $this->assertFalse($organizationUtils->isStructure($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER_PREMIUM);
         $this->assertFalse($organizationUtils->isStructure($organization));
     }
 
     /**
-     * @see OrganizationUtils::isStructure()
+     * @see OrganizationUtils::isManager()
      */
     public function testIsManager(): void
     {
         $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['isManager'])->getMock();
 
-        $settings = $this->getMockBuilder(Settings::class)->getMock();
-        $organization = $this->getMockBuilder(Organization::class)->getMock();
-        $organization->method('getSettings')->willReturn($settings);
-
-        $settings->method('getProduct')->willReturnOnConsecutiveCalls(
-            SettingsProductEnum::ARTIST,
-            SettingsProductEnum::ARTIST_PREMIUM,
-            SettingsProductEnum::SCHOOL,
-            SettingsProductEnum::SCHOOL_PREMIUM,
-            SettingsProductEnum::MANAGER,
-            SettingsProductEnum::MANAGER_PREMIUM,
-        );
-
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST);
         $this->assertFalse($organizationUtils->isManager($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST_PREMIUM);
         $this->assertFalse($organizationUtils->isManager($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL);
         $this->assertFalse($organizationUtils->isManager($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL_PREMIUM);
         $this->assertFalse($organizationUtils->isManager($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER);
         $this->assertTrue($organizationUtils->isManager($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER_PREMIUM);
         $this->assertFalse($organizationUtils->isManager($organization));
     }
 
@@ -355,4 +344,88 @@ class UtilsTest extends TestCase
 
         $this->assertEquals(null, $organizationUtils->getOrganizationWebsite($organization));
     }
+
+    /**
+     * @see OrganizationUtils::isSchool()
+     */
+    public function testIsSchool(): void
+    {
+        $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['isSchool'])->getMock();
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST);
+        $this->assertFalse($organizationUtils->isSchool($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST_PREMIUM);
+        $this->assertFalse($organizationUtils->isSchool($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL);
+        $this->assertTrue($organizationUtils->isSchool($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL_PREMIUM);
+        $this->assertTrue($organizationUtils->isSchool($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER);
+        $this->assertFalse($organizationUtils->isSchool($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER_PREMIUM);
+        $this->assertFalse($organizationUtils->isSchool($organization));
+    }
+
+    /**
+     * @see OrganizationUtils::isArtist()
+     */
+    public function testIsArtist(): void
+    {
+        $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['isArtist'])->getMock();
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST);
+        $this->assertTrue($organizationUtils->isArtist($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST_PREMIUM);
+        $this->assertTrue($organizationUtils->isArtist($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL);
+        $this->assertFalse($organizationUtils->isArtist($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL_PREMIUM);
+        $this->assertFalse($organizationUtils->isArtist($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER);
+        $this->assertFalse($organizationUtils->isArtist($organization));
+
+        $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER_PREMIUM);
+        $this->assertFalse($organizationUtils->isArtist($organization));
+    }
+
+    /**
+     * @see OrganizationUtils::hasModule()
+     */
+    public function testHasModule(): void
+    {
+        $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['hasModule'])->getMock();
+
+        $settings = $this->getMockBuilder(Settings::class)->getMock();
+        $settings->method('getModules')->willReturn(['foo', 'bar']);
+
+        $organization = $this->getMockBuilder(Organization::class)->getMock();
+        $organization->method('getSettings')->willReturn($settings);
+
+        $this->assertTrue($organizationUtils->hasModule($organization, 'foo'));
+        $this->assertFalse($organizationUtils->hasModule($organization, 'other'));
+    }
+
+    /**
+     * @param SettingsProductEnum $product
+     * @return Organization
+     */
+    private function createOrganizationWithProductMock(SettingsProductEnum $product): Organization{
+        $settings = $this->getMockBuilder(Settings::class)->getMock();
+        $settings->method('getProduct')->willReturn($product);
+
+        $organization = $this->getMockBuilder(Organization::class)->getMock();
+        $organization->method('getSettings')->willReturn($settings);
+
+        return $organization;
+    }
+
 }