Olivier Massot 3 mesi fa
parent
commit
35c8190692

+ 2 - 3
src/Doctrine/Access/AdditionalExtension/DateTimeConstraintExtensionAdditional.php

@@ -20,10 +20,9 @@ class DateTimeConstraintExtensionAdditional implements AdditionalAccessExtension
 
     public function support(string $name): bool
     {
-        return
+        $request = $this->requestStack->getMainRequest();
 
-                $this->requestStack->getMainRequest()->isMethod('GET')
-        ;
+        return $request->isMethod('GET') && $request->get('_time_constraint', true);
     }
 
     public function addWhere(QueryBuilder $queryBuilder): void

+ 27 - 66
tests/Unit/Service/Organization/OrganizationFactoryTest.php

@@ -970,12 +970,7 @@ class OrganizationFactoryTest extends TestCase
 
         $organization->expects(self::once())->method('addSubdomain')->with($subdomain);
 
-        // Enregistrement du sous domaine dans Parameters (retrocompatibilité v1)
-        $organization->method('getParameters')->willReturn($parameters);
-
         $organizationCreationRequest->method('getSubdomain')->willReturn('foo');
-        $parameters->expects(self::once())->method('setSubDomain')->with('foo');
-        $parameters->expects(self::once())->method('setOtherWebsite')->with('https://foo.opentalent.fr');
 
         $result = $organizationFactory->makeOrganizationWithRelations($organizationCreationRequest);
 
@@ -1142,21 +1137,9 @@ class OrganizationFactoryTest extends TestCase
 
         $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
 
-        $organizationCreationRequest->method('getPhoneNumber')->willReturn('+33102030405');
-        $organizationCreationRequest->method('getEmail')->willReturn('contact@domain.net');
-
-        $this->phoneNumberUtil
-            ->method('isPossibleNumber')
-            ->with('+33102030405')
-            ->willReturn(true);
-
         $phoneNumber = $this->getMockBuilder(PhoneNumber::class)->getMock();
-
-        $this->phoneNumberUtil
-            ->expects(self::once())
-            ->method('parse')
-            ->with('+33102030405')
-            ->willReturn($phoneNumber);
+        $organizationCreationRequest->method('getPhoneNumber')->willReturn($phoneNumber);
+        $organizationCreationRequest->method('getEmail')->willReturn('contact@domain.net');
 
         $contactPoint = $organizationFactory->makeContactPoint($organizationCreationRequest);
 
@@ -1171,31 +1154,6 @@ class OrganizationFactoryTest extends TestCase
         );
     }
 
-    public function testMakeContactPointInvalidPhoneNumber(): void
-    {
-        $organizationFactory = $this->getOrganizationFactoryMockFor('makeContactPoint');
-
-        $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
-
-        $organizationCreationRequest->method('getPhoneNumber')->willReturn('invalid');
-        $organizationCreationRequest->method('getEmail')->willReturn('contact@domain.net');
-
-        $this->phoneNumberUtil
-            ->method('isPossibleNumber')
-            ->with('invalid')
-            ->willReturn(false);
-
-        $phoneNumber = $this->getMockBuilder(PhoneNumber::class)->getMock();
-
-        $this->phoneNumberUtil
-            ->expects(self::never())
-            ->method('parse');
-
-        $this->expectException(\RuntimeException::class);
-        $this->expectExceptionMessage('Phone number is invalid or missing');
-
-        $organizationFactory->makeContactPoint($organizationCreationRequest);
-    }
 
     public function testMakeNetworkOrganization(): void
     {
@@ -1635,28 +1593,24 @@ class OrganizationFactoryTest extends TestCase
 
         $organizationMemberCreationRequest = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
 
-        $organizationMemberCreationRequest->method('getPhone')->willReturn('+33102030405');
+        $phoneNumber = $this->getMockBuilder(PhoneNumber::class)->getMock();
+        $mobilePhoneNumber = $this->getMockBuilder(PhoneNumber::class)->getMock();
+
+        $organizationMemberCreationRequest->method('getPhone')->willReturn($phoneNumber);
         $organizationMemberCreationRequest->method('getEmail')->willReturn('email@domain.com');
-        $organizationMemberCreationRequest->method('getMobile')->willReturn('+33607080910');
+        $organizationMemberCreationRequest->method('getMobile')->willReturn($mobilePhoneNumber);
 
         $this->phoneNumberUtil
             ->expects(self::exactly(2))
             ->method('isPossibleNumber')
             ->willReturnMap([
-                ['+33102030405', null, true],
-                ['+33607080910', null, true],
+                [$phoneNumber, null, true],
+                [$mobilePhoneNumber, null, true],
             ]);
 
-        $phoneNumber = $this->getMockBuilder(PhoneNumber::class)->getMock();
-        $mobilePhoneNumber = $this->getMockBuilder(PhoneNumber::class)->getMock();
-
         $this->phoneNumberUtil
-            ->expects(self::exactly(2))
-            ->method('parse')
-            ->willReturnMap([
-                ['+33102030405', null, null, false, $phoneNumber],
-                ['+33607080910', null, null, false, $mobilePhoneNumber],
-            ]);
+            ->expects(self::never())
+            ->method('parse');
 
         $creationDate = $this->getMockBuilder(\DateTime::class)->getMock();
 
@@ -1693,15 +1647,18 @@ class OrganizationFactoryTest extends TestCase
 
         $organizationMemberCreationRequest = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
 
+        $invalidPhoneNumber = $this->getMockBuilder(PhoneNumber::class)->getMock();
+        $mobilePhoneNumber = $this->getMockBuilder(PhoneNumber::class)->getMock();
+
         $organizationMemberCreationRequest->method('getUsername')->willReturn('bob');
-        $organizationMemberCreationRequest->method('getPhone')->willReturn('invalid');
+        $organizationMemberCreationRequest->method('getPhone')->willReturn($invalidPhoneNumber);
         $organizationMemberCreationRequest->method('getEmail')->willReturn('email@domain.com');
-        $organizationMemberCreationRequest->method('getMobile')->willReturn('+33607080910');
+        $organizationMemberCreationRequest->method('getMobile')->willReturn($mobilePhoneNumber);
 
         $this->phoneNumberUtil
             ->expects(self::once())
             ->method('isPossibleNumber')
-            ->with('invalid')
+            ->with($invalidPhoneNumber)
             ->willReturn(false);
 
         $this->phoneNumberUtil
@@ -1726,17 +1683,20 @@ class OrganizationFactoryTest extends TestCase
 
         $organizationMemberCreationRequest = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
 
+        $phoneNumber = $this->getMockBuilder(PhoneNumber::class)->getMock();
+        $invalidMobilePhoneNumber = $this->getMockBuilder(PhoneNumber::class)->getMock();
+
         $organizationMemberCreationRequest->method('getUsername')->willReturn('bob');
-        $organizationMemberCreationRequest->method('getPhone')->willReturn('+33102030405');
+        $organizationMemberCreationRequest->method('getPhone')->willReturn($phoneNumber);
         $organizationMemberCreationRequest->method('getEmail')->willReturn('email@domain.com');
-        $organizationMemberCreationRequest->method('getMobile')->willReturn('invalid');
+        $organizationMemberCreationRequest->method('getMobile')->willReturn($invalidMobilePhoneNumber);
 
         $this->phoneNumberUtil
             ->expects(self::exactly(2))
             ->method('isPossibleNumber')
             ->willReturnMap([
-                ['+33102030405', null, true],
-                ['invalid', null, false],
+                [$phoneNumber, null, true],
+                [$invalidMobilePhoneNumber, null, false],
             ]);
 
         $this->phoneNumberUtil
@@ -1761,13 +1721,14 @@ class OrganizationFactoryTest extends TestCase
 
         $organizationMemberCreationRequest = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
 
-        $organizationMemberCreationRequest->method('getPhone')->willReturn('+33102030405');
+        $phoneNumber = $this->getMockBuilder(PhoneNumber::class)->getMock();
+        $organizationMemberCreationRequest->method('getPhone')->willReturn($phoneNumber);
         $organizationMemberCreationRequest->method('getMobile')->willReturn(null);
 
         $this->phoneNumberUtil
             ->expects(self::once())
             ->method('isPossibleNumber')
-            ->with('+33102030405')
+            ->with($phoneNumber)
             ->willReturn(true);
 
         $creationDate = $this->getMockBuilder(\DateTime::class)->getMock();

+ 4 - 1
tests/Unit/Service/Organization/TrialTest.php

@@ -13,6 +13,7 @@ use App\Service\Dolibarr\DolibarrUtils;
 use App\Service\Shop\Trial;
 use App\Service\Utils\DatesUtils;
 use Doctrine\ORM\EntityManagerInterface;
+use libphonenumber\PhoneNumber;
 use PHPUnit\Framework\TestCase;
 
 /**
@@ -126,11 +127,13 @@ class TrialTest extends TestCase
         $organization->method('getId')->willReturn(123);
 
         $request = $this->createMock(NewStructureArtistPremiumTrialRequest::class);
+        $phoneNumber = $this->createMock(PhoneNumber::class);
+        $phoneNumber->method('__toString')->willReturn('+33123456789');
         $request->method('getRepresentativeFirstName')->willReturn('John');
         $request->method('getRepresentativeLastName')->willReturn('Doe');
         $request->method('getRepresentativeFunction')->willReturn('Manager');
         $request->method('getRepresentativeEmail')->willReturn('test@example.com');
-        $request->method('getRepresentativePhone')->willReturn('+33123456789');
+        $request->method('getRepresentativePhone')->willReturn($phoneNumber);
 
         $settings
             ->expects(self::once())

+ 4 - 51
tests/Unit/Service/Shop/ShopServiceTest.php

@@ -20,6 +20,7 @@ use App\Service\Shop\ShopService;
 use App\Service\Shop\Trial;
 use App\Service\Utils\DatesUtils;
 use Doctrine\ORM\EntityManagerInterface;
+use libphonenumber\PhoneNumber;
 use libphonenumber\PhoneNumberUtil;
 use PHPUnit\Framework\MockObject\MockObject;
 use PHPUnit\Framework\TestCase;
@@ -508,16 +509,9 @@ class ShopServiceTest extends TestCase
     {
         $shopService = $this->getShopServiceMockFor('validateNewStructureArtistPremiumTrialRequest');
 
-        $phoneNumberUtil = $this
-            ->getMockBuilder(PhoneNumberUtil::class)
-            ->disableOriginalConstructor()
-            ->getMock();
-        $shopService->phoneNumberUtil = $phoneNumberUtil;
-
         $trialRequest = $this
             ->getMockBuilder(NewStructureArtistPremiumTrialRequest::class)
             ->getMock();
-        $trialRequest->method('getRepresentativePhone')->willReturn('+33123456789');
 
         $organizationCreationRequest = $this
             ->getMockBuilder(OrganizationCreationRequest::class)
@@ -528,11 +522,6 @@ class ShopServiceTest extends TestCase
             ->with($trialRequest)
             ->willReturn($organizationCreationRequest);
 
-        $phoneNumberUtil->expects(self::once())
-            ->method('isPossibleNumber')
-            ->with('+33123456789')
-            ->willReturn(true);
-
         $this->organizationFactory->expects(self::once())
             ->method('interruptIfOrganizationExists')
             ->with($organizationCreationRequest);
@@ -549,43 +538,6 @@ class ShopServiceTest extends TestCase
         $shopService->validateNewStructureArtistPremiumTrialRequest($data);
     }
 
-    /**
-     * Test validateNewStructureArtistPremiumTrialRequest method with invalid phone number.
-     */
-    public function testValidateNewStructureArtistPremiumTrialRequestWithInvalidPhoneNumber(): void
-    {
-        $shopService = $this->getShopServiceMockFor('validateNewStructureArtistPremiumTrialRequest');
-
-        $phoneNumberUtil = $this->getMockBuilder(PhoneNumberUtil::class)
-            ->disableOriginalConstructor()
-            ->getMock();
-        $shopService->phoneNumberUtil = $phoneNumberUtil;
-
-        $trialRequest = $this
-            ->getMockBuilder(NewStructureArtistPremiumTrialRequest::class)
-            ->getMock();
-        $trialRequest->method('getRepresentativePhone')->willReturn('invalid-phone');
-
-        // Mock the phoneNumberUtil to return false for isPossibleNumber
-        $phoneNumberUtil->expects(self::once())
-            ->method('isPossibleNumber')
-            ->with('invalid-phone')
-            ->willReturn(false);
-
-        // Convert the trial request to an array for validation
-        $data = [
-            'representativePhone' => 'invalid-phone',
-        ];
-        $this->serializer->expects(self::once())
-            ->method('deserialize')
-            ->with(json_encode($data), NewStructureArtistPremiumTrialRequest::class, 'json')
-            ->willReturn($trialRequest);
-
-        $this->expectException(\RuntimeException::class);
-        $this->expectExceptionMessage('Invalid phone number');
-
-        $shopService->validateNewStructureArtistPremiumTrialRequest($data);
-    }
 
     /**
      * Test createOrganizationCreationRequestFromTrialRequest method with forValidationOnly=false.
@@ -596,12 +548,13 @@ class ShopServiceTest extends TestCase
 
         $trialRequest = $this->getMockBuilder(NewStructureArtistPremiumTrialRequest::class)
             ->getMock();
+        $phoneNumber = $this->createMock(PhoneNumber::class);
         $trialRequest->method('getStructureName')->willReturn('Test Structure');
         $trialRequest->method('getCity')->willReturn('Test City');
         $trialRequest->method('getPostalCode')->willReturn('12345');
         $trialRequest->method('getAddress')->willReturn('Test Address');
         $trialRequest->method('getAddressComplement')->willReturn('Test Address Complement');
-        $trialRequest->method('getRepresentativePhone')->willReturn('+33123456789');
+        $trialRequest->method('getRepresentativePhone')->willReturn($phoneNumber);
         $trialRequest->method('getStructureEmail')->willReturn('structure@example.com');
         $trialRequest->method('getStructureType')->willReturn(PrincipalTypeEnum::ARTISTIC_EDUCATION_ONLY);
         $trialRequest->method('getLegalStatus')->willReturn(LegalEnum::ASSOCIATION_LAW_1901);
@@ -625,7 +578,7 @@ class ShopServiceTest extends TestCase
         $this->assertEquals(PrincipalTypeEnum::ARTISTIC_EDUCATION_ONLY, $result->getPrincipalType());
         $this->assertEquals(LegalEnum::ASSOCIATION_LAW_1901, $result->getLegalStatus());
         $this->assertEquals('123456789', $result->getSiretNumber());
-        $this->assertEquals('+33123456789', $result->getPhoneNumber());
+        $this->assertEquals($phoneNumber, $result->getPhoneNumber());
         $this->assertEquals('test-structure', $result->getSubdomain());
         $this->assertEquals(SettingsProductEnum::FREEMIUM, $result->getProduct());
         $this->assertFalse($result->getCreateWebsite());