|
|
@@ -7,6 +7,7 @@ namespace App\Tests\Unit\Service\Organization;
|
|
|
use App\ApiResources\Organization\OrganizationCreationRequest;
|
|
|
use App\ApiResources\Organization\OrganizationMemberCreationRequest;
|
|
|
use App\Entity\Access\Access;
|
|
|
+use App\Entity\Access\FunctionType;
|
|
|
use App\Entity\Core\ContactPoint;
|
|
|
use App\Entity\Core\Country;
|
|
|
use App\Entity\Education\Cycle;
|
|
|
@@ -19,6 +20,7 @@ use App\Entity\Organization\Settings;
|
|
|
use App\Entity\Organization\Subdomain;
|
|
|
use App\Entity\Person\Person;
|
|
|
use App\Entity\Person\PersonAddressPostal;
|
|
|
+use App\Enum\Access\FunctionEnum;
|
|
|
use App\Enum\Core\ContactPointTypeEnum;
|
|
|
use App\Enum\Education\CycleEnum;
|
|
|
use App\Enum\Network\NetworkEnum;
|
|
|
@@ -28,6 +30,7 @@ use App\Enum\Organization\PrincipalTypeEnum;
|
|
|
use App\Enum\Organization\SettingsProductEnum;
|
|
|
use App\Enum\Person\AddressPostalPersonTypeEnum;
|
|
|
use App\Enum\Person\GenderEnum;
|
|
|
+use App\Repository\Access\FunctionTypeRepository;
|
|
|
use App\Repository\Core\CountryRepository;
|
|
|
use App\Repository\Organization\OrganizationIdentificationRepository;
|
|
|
use App\Repository\Organization\OrganizationRepository;
|
|
|
@@ -112,19 +115,19 @@ class TestableOrganizationFactory extends OrganizationFactory
|
|
|
return parent::makeCycles();
|
|
|
}
|
|
|
|
|
|
- public function makeAccess(int|OrganizationMemberCreationRequest $creationRequestData): Access
|
|
|
+ public function makeAccess(int|OrganizationMemberCreationRequest $creationRequestData, FunctionEnum $function, \DateTime $creationDate, int|null $authorId): Access
|
|
|
{
|
|
|
- return parent::makeAccess($creationRequestData);
|
|
|
+ return parent::makeAccess($creationRequestData, $function, $creationDate, $authorId);
|
|
|
}
|
|
|
|
|
|
- public function makePersonPostalAddress(OrganizationMemberCreationRequest $organizationMemberCreationRequest): PersonAddressPostal
|
|
|
+ public function makePersonPostalAddress(OrganizationMemberCreationRequest $organizationMemberCreationRequest, \DateTime $creationDate, int|null $authorId): PersonAddressPostal
|
|
|
{
|
|
|
- return parent::makePersonPostalAddress($organizationMemberCreationRequest);
|
|
|
+ return parent::makePersonPostalAddress($organizationMemberCreationRequest, $creationDate, $authorId);
|
|
|
}
|
|
|
|
|
|
- public function makePersonContactPoint(OrganizationMemberCreationRequest $organizationMemberCreationRequest): ContactPoint
|
|
|
+ public function makePersonContactPoint(OrganizationMemberCreationRequest $organizationMemberCreationRequest, \DateTime $creationDate, int|null $authorId): ContactPoint
|
|
|
{
|
|
|
- return parent::makePersonContactPoint($organizationMemberCreationRequest);
|
|
|
+ return parent::makePersonContactPoint($organizationMemberCreationRequest, $creationDate, $authorId);
|
|
|
}
|
|
|
|
|
|
public function makeSubdomain(OrganizationCreationRequest $organizationCreationRequest): Subdomain
|
|
|
@@ -163,6 +166,7 @@ class OrganizationFactoryTest extends TestCase
|
|
|
private readonly MockObject|OrganizationIdentificationRepository $organizationIdentificationRepository;
|
|
|
private readonly MockObject|ApiLegacyRequestService $apiLegacyRequestService;
|
|
|
private readonly MockObject|PhoneNumberUtil $phoneNumberUtil;
|
|
|
+ private readonly MockObject|FunctionTypeRepository $functionTypeRepository;
|
|
|
|
|
|
public function setUp(): void
|
|
|
{
|
|
|
@@ -179,6 +183,7 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$this->organizationIdentificationRepository = $this->getMockBuilder(OrganizationIdentificationRepository::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->apiLegacyRequestService = $this->getMockBuilder(ApiLegacyRequestService::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->phoneNumberUtil = $this->getMockBuilder(PhoneNumberUtil::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $this->functionTypeRepository = $this->getMockBuilder(FunctionTypeRepository::class)->disableOriginalConstructor()->getMock();
|
|
|
}
|
|
|
|
|
|
public function tearDown(): void
|
|
|
@@ -203,6 +208,7 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$this->bindFileService,
|
|
|
$this->organizationIdentificationRepository,
|
|
|
$this->apiLegacyRequestService,
|
|
|
+ $this->functionTypeRepository
|
|
|
])
|
|
|
->setMethodsExcept(['setLoggerInterface', 'setPhoneNumberUtil', $methodName])
|
|
|
->getMock();
|
|
|
@@ -817,11 +823,16 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$organizationFactory->validateSubdomain('foo');
|
|
|
}
|
|
|
|
|
|
- public function testMakeOrganizationWithRelations()
|
|
|
+ public function testMakeOrganizationWithRelations(): void
|
|
|
{
|
|
|
$organizationFactory = $this->getOrganizationFactoryMockFor('makeOrganizationWithRelations');
|
|
|
|
|
|
+ $creationDate = $this->getMockBuilder(\DateTime::class)->getMock();
|
|
|
+
|
|
|
$organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
|
|
|
+ $organizationCreationRequest->method('getCreationDate')->willReturn($creationDate);
|
|
|
+ $organizationCreationRequest->method('getAuthorId')->willReturn(1);
|
|
|
+
|
|
|
$organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
|
|
|
// Création de l'organisation
|
|
|
@@ -890,7 +901,7 @@ class OrganizationFactoryTest extends TestCase
|
|
|
->willReturn($adminAccess);
|
|
|
|
|
|
// Le `$organization->expects(...)->method('addAccess')` est implémenté plus loin,
|
|
|
- // après la création du président et du directeur
|
|
|
+ // après la création du président et du directeur.
|
|
|
|
|
|
// Création des cycles
|
|
|
$cycle1 = $this->getMockBuilder(Cycle::class)->getMock();
|
|
|
@@ -917,8 +928,8 @@ class OrganizationFactoryTest extends TestCase
|
|
|
->expects(self::exactly(2))
|
|
|
->method('makeAccess')
|
|
|
->willReturnMap([
|
|
|
- [$organizationMemberCreationRequest1, $access1],
|
|
|
- [$organizationMemberCreationRequest2, $access2],
|
|
|
+ [$organizationMemberCreationRequest1, FunctionEnum::PRESIDENT, $creationDate, 1, $access1],
|
|
|
+ [$organizationMemberCreationRequest2, FunctionEnum::DIRECTOR, $creationDate, 1, $access2],
|
|
|
]);
|
|
|
|
|
|
$organization
|
|
|
@@ -951,7 +962,7 @@ class OrganizationFactoryTest extends TestCase
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- public function testMakeOrganizationWithRelationsNoPresidentNoDirector()
|
|
|
+ public function testMakeOrganizationWithRelationsNoPresidentNoDirector(): void
|
|
|
{
|
|
|
$organizationFactory = $this->getOrganizationFactoryMockFor('makeOrganizationWithRelations');
|
|
|
|
|
|
@@ -1417,7 +1428,22 @@ class OrganizationFactoryTest extends TestCase
|
|
|
->with($organizationMemberCreationRequest)
|
|
|
->willReturn($contactPoint);
|
|
|
|
|
|
- $access = $organizationFactory->makeAccess($organizationMemberCreationRequest);
|
|
|
+ $functionType = $this->getMockBuilder(FunctionType::class)->getMock();
|
|
|
+
|
|
|
+ $this->functionTypeRepository
|
|
|
+ ->expects(self::once())
|
|
|
+ ->method('findOneBy')
|
|
|
+ ->with(['mission' => FunctionEnum::ACCOUNTANT])
|
|
|
+ ->willReturn($functionType);
|
|
|
+
|
|
|
+ $creationDate = $this->getMockBuilder(\DateTime::class)->getMock();
|
|
|
+
|
|
|
+ $access = $organizationFactory->makeAccess(
|
|
|
+ $organizationMemberCreationRequest,
|
|
|
+ FunctionEnum::ACCOUNTANT,
|
|
|
+ $creationDate,
|
|
|
+ 1
|
|
|
+ );
|
|
|
|
|
|
$this->assertInstanceOf(Access::class, $access);
|
|
|
$this->assertEquals(
|
|
|
@@ -1443,6 +1469,14 @@ class OrganizationFactoryTest extends TestCase
|
|
|
[$contactPoint],
|
|
|
$access->getPerson()->getContactPoints()->toArray()
|
|
|
);
|
|
|
+ $this->assertEquals(
|
|
|
+ $functionType,
|
|
|
+ $access->getOrganizationFunction()->first()->getFunctionType()
|
|
|
+ );
|
|
|
+ $this->assertEquals(
|
|
|
+ $creationDate,
|
|
|
+ $access->getOrganizationFunction()->first()->getStartDate()
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
public function testMakeAccessNewPersonUsernameAlreadyInUse(): void
|
|
|
@@ -1473,7 +1507,14 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$this->expectException(\RuntimeException::class);
|
|
|
$this->expectExceptionMessage('Username already in use : bob');
|
|
|
|
|
|
- $organizationFactory->makeAccess($organizationMemberCreationRequest);
|
|
|
+ $creationDate = $this->getMockBuilder(\DateTime::class)->getMock();
|
|
|
+
|
|
|
+ $organizationFactory->makeAccess(
|
|
|
+ $organizationMemberCreationRequest,
|
|
|
+ FunctionEnum::ADHERENT,
|
|
|
+ $creationDate,
|
|
|
+ 1
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
public function testMakeAccessExistingPerson(): void
|
|
|
@@ -1488,13 +1529,39 @@ class OrganizationFactoryTest extends TestCase
|
|
|
->with(123)
|
|
|
->willReturn($person);
|
|
|
|
|
|
- $access = $organizationFactory->makeAccess(123);
|
|
|
+ $creationDate = $this->getMockBuilder(\DateTime::class)->getMock();
|
|
|
+
|
|
|
+ $functionType = $this->getMockBuilder(FunctionType::class)->getMock();
|
|
|
+
|
|
|
+ $this->functionTypeRepository
|
|
|
+ ->expects(self::once())
|
|
|
+ ->method('findOneBy')
|
|
|
+ ->with(['mission' => FunctionEnum::ACCOUNTANT])
|
|
|
+ ->willReturn($functionType);
|
|
|
+
|
|
|
+ $creationDate = $this->getMockBuilder(\DateTime::class)->getMock();
|
|
|
+
|
|
|
+ $access = $organizationFactory->makeAccess(
|
|
|
+ 123,
|
|
|
+ FunctionEnum::ACCOUNTANT,
|
|
|
+ $creationDate,
|
|
|
+ 1
|
|
|
+ );
|
|
|
|
|
|
$this->assertInstanceOf(Access::class, $access);
|
|
|
$this->assertEquals(
|
|
|
$person,
|
|
|
$access->getPerson()
|
|
|
);
|
|
|
+
|
|
|
+ $this->assertEquals(
|
|
|
+ $functionType,
|
|
|
+ $access->getOrganizationFunction()->first()->getFunctionType()
|
|
|
+ );
|
|
|
+ $this->assertEquals(
|
|
|
+ $creationDate,
|
|
|
+ $access->getOrganizationFunction()->first()->getStartDate()
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
public function testMakeAccessPostalAddress()
|
|
|
@@ -1517,7 +1584,13 @@ class OrganizationFactoryTest extends TestCase
|
|
|
->with(123)
|
|
|
->willReturn($country);
|
|
|
|
|
|
- $personPostalAddress = $organizationFactory->makePersonPostalAddress($organizationMemberCreationRequest);
|
|
|
+ $creationDate = $this->getMockBuilder(\DateTime::class)->getMock();
|
|
|
+
|
|
|
+ $personPostalAddress = $organizationFactory->makePersonPostalAddress(
|
|
|
+ $organizationMemberCreationRequest,
|
|
|
+ $creationDate,
|
|
|
+ 1
|
|
|
+ );
|
|
|
|
|
|
$this->assertEquals(
|
|
|
AddressPostalPersonTypeEnum::ADDRESS_PRINCIPAL,
|
|
|
@@ -1562,7 +1635,13 @@ class OrganizationFactoryTest extends TestCase
|
|
|
['+33607080910', null, null, false, $mobilePhoneNumber],
|
|
|
]);
|
|
|
|
|
|
- $contactPoint = $organizationFactory->makePersonContactPoint($organizationMemberCreationRequest);
|
|
|
+ $creationDate = $this->getMockBuilder(\DateTime::class)->getMock();
|
|
|
+
|
|
|
+ $contactPoint = $organizationFactory->makePersonContactPoint(
|
|
|
+ $organizationMemberCreationRequest,
|
|
|
+ $creationDate,
|
|
|
+ 1
|
|
|
+ );
|
|
|
|
|
|
$this->assertEquals(
|
|
|
ContactPointTypeEnum::PRINCIPAL,
|
|
|
@@ -1609,7 +1688,13 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$this->expectException(\RuntimeException::class);
|
|
|
$this->expectExceptionMessage('Phone number is invalid or missing (person: bob)');
|
|
|
|
|
|
- $organizationFactory->makePersonContactPoint($organizationMemberCreationRequest);
|
|
|
+ $creationDate = $this->getMockBuilder(\DateTime::class)->getMock();
|
|
|
+
|
|
|
+ $organizationFactory->makePersonContactPoint(
|
|
|
+ $organizationMemberCreationRequest,
|
|
|
+ $creationDate,
|
|
|
+ 1
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
public function testMakeAccessContactPointInvalidMobilePhone(): void
|
|
|
@@ -1638,7 +1723,13 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$this->expectException(\RuntimeException::class);
|
|
|
$this->expectExceptionMessage('Mobile phone number is invalid (person: bob)');
|
|
|
|
|
|
- $organizationFactory->makePersonContactPoint($organizationMemberCreationRequest);
|
|
|
+ $creationDate = $this->getMockBuilder(\DateTime::class)->getMock();
|
|
|
+
|
|
|
+ $organizationFactory->makePersonContactPoint(
|
|
|
+ $organizationMemberCreationRequest,
|
|
|
+ $creationDate,
|
|
|
+ 1
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
public function testMakePersonContactPointNoMobile(): void
|
|
|
@@ -1656,7 +1747,13 @@ class OrganizationFactoryTest extends TestCase
|
|
|
->with('+33102030405')
|
|
|
->willReturn(true);
|
|
|
|
|
|
- $contactPoint = $organizationFactory->makePersonContactPoint($organizationMemberCreationRequest);
|
|
|
+ $creationDate = $this->getMockBuilder(\DateTime::class)->getMock();
|
|
|
+
|
|
|
+ $contactPoint = $organizationFactory->makePersonContactPoint(
|
|
|
+ $organizationMemberCreationRequest,
|
|
|
+ $creationDate,
|
|
|
+ 1
|
|
|
+ );
|
|
|
|
|
|
$this->assertEquals(
|
|
|
null,
|