| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144 |
- <?php
- declare(strict_types=1);
- namespace App\Tests\Unit\Service\Organization;
- use App\ApiResources\Organization\OrganizationCreationRequest;
- use App\ApiResources\Organization\OrganizationDeletionRequest;
- 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;
- use App\Entity\Network\Network;
- use App\Entity\Network\NetworkOrganization;
- use App\Entity\Organization\Organization;
- use App\Entity\Organization\OrganizationAddressPostal;
- use App\Entity\Organization\Parameters;
- 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;
- use App\Enum\Organization\AddressPostalOrganizationTypeEnum;
- use App\Enum\Organization\LegalEnum;
- 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;
- use App\Repository\Person\PersonRepository;
- use App\Service\ApiLegacy\ApiLegacyRequestService;
- use App\Service\Dolibarr\DolibarrApiService;
- use App\Service\Organization\OrganizationFactory;
- use App\Service\Organization\Utils as OrganizationUtils;
- use App\Service\Typo3\BindFileService;
- use App\Service\Typo3\SubdomainService;
- use App\Service\Typo3\Typo3Service;
- use App\Service\Utils\DatesUtils;
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\ORM\EntityManagerInterface;
- use libphonenumber\PhoneNumber;
- use libphonenumber\PhoneNumberUtil;
- use PHPUnit\Framework\MockObject\MockObject;
- use PHPUnit\Framework\TestCase;
- use Psr\Log\LoggerInterface;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Contracts\HttpClient\ResponseInterface;
- class TestableOrganizationFactory extends OrganizationFactory
- {
- public function setPhoneNumberUtil(PhoneNumberUtil $phoneNumberUtil): void
- {
- $this->phoneNumberUtil = $phoneNumberUtil;
- }
- public function interruptIfOrganizationExists(OrganizationCreationRequest $organizationCreationRequest): void
- {
- parent::interruptIfOrganizationExists($organizationCreationRequest);
- }
- public function validateSubdomain(string $subdomainValue): void
- {
- parent::validateSubdomain($subdomainValue);
- }
- public function makeOrganizationWithRelations(
- OrganizationCreationRequest $organizationCreationRequest,
- ): Organization {
- return parent::makeOrganizationWithRelations($organizationCreationRequest);
- }
- public function makeOrganization(OrganizationCreationRequest $organizationCreationRequest): Organization
- {
- return parent::makeOrganization($organizationCreationRequest);
- }
- public function makeParameters(OrganizationCreationRequest $organizationCreationRequest): Parameters
- {
- return parent::makeParameters($organizationCreationRequest);
- }
- public function makeSettings(OrganizationCreationRequest $organizationCreationRequest): Settings
- {
- return parent::makeSettings($organizationCreationRequest);
- }
- public function makePostalAddress(OrganizationCreationRequest $organizationCreationRequest): OrganizationAddressPostal
- {
- return parent::makePostalAddress($organizationCreationRequest);
- }
- public function makeContactPoint(OrganizationCreationRequest $organizationCreationRequest): ContactPoint
- {
- return parent::makeContactPoint($organizationCreationRequest);
- }
- public function makeNetworkOrganization(OrganizationCreationRequest $organizationCreationRequest): NetworkOrganization
- {
- return parent::makeNetworkOrganization($organizationCreationRequest);
- }
- public function makeAdminAccess(OrganizationCreationRequest $organizationCreationRequest): Access
- {
- return parent::makeAdminAccess($organizationCreationRequest);
- }
- public function makeCycles(): array
- {
- return parent::makeCycles();
- }
- public function makeAccess(int|OrganizationMemberCreationRequest $creationRequestData, FunctionEnum $function, \DateTime $creationDate, ?int $authorId): Access
- {
- return parent::makeAccess($creationRequestData, $function, $creationDate, $authorId);
- }
- public function makePersonPostalAddress(OrganizationMemberCreationRequest $organizationMemberCreationRequest, \DateTime $creationDate, ?int $authorId): PersonAddressPostal
- {
- return parent::makePersonPostalAddress($organizationMemberCreationRequest, $creationDate, $authorId);
- }
- public function makePersonContactPoint(OrganizationMemberCreationRequest $organizationMemberCreationRequest, \DateTime $creationDate, ?int $authorId): ContactPoint
- {
- return parent::makePersonContactPoint($organizationMemberCreationRequest, $creationDate, $authorId);
- }
- public function makeSubdomain(OrganizationCreationRequest $organizationCreationRequest): Subdomain
- {
- return parent::makeSubdomain($organizationCreationRequest);
- }
- public function createTypo3Website(Organization $organization): ?int
- {
- return parent::createTypo3Website($organization);
- }
- public function updateAdminassosDb(Organization $organization): void
- {
- parent::updateAdminassosDb($organization);
- }
- public function normalizeIdentificationField(string $value): string
- {
- return parent::normalizeIdentificationField($value);
- }
- public function deleteOrganizationAccesses(Organization $organization): void
- {
- parent::deleteOrganizationAccesses($organization);
- }
- public function deleteTypo3Website(Organization $organization): void
- {
- parent::deleteTypo3Website($organization);
- }
- public function switchDolibarrSocietyToProspect(Organization $organization): void
- {
- parent::switchDolibarrSocietyToProspect($organization);
- }
- public function deleteOrganizationFiles(Organization $organization): void
- {
- parent::deleteOrganizationFiles($organization);
- }
- public function deleteDirectoriesV1(Organization $organization): void
- {
- parent::deleteDirectoriesV1($organization);
- }
- public function deleteDirectories59(Organization $organization): void
- {
- parent::deleteDirectories59($organization);
- }
- }
- class OrganizationFactoryTest extends TestCase
- {
- private readonly MockObject|SubdomainService $subdomainService;
- private readonly MockObject|OrganizationRepository $organizationRepository;
- private readonly MockObject|CountryRepository $countryRepository;
- private readonly MockObject|OrganizationUtils $organizationUtils;
- private readonly MockObject|Typo3Service $typo3Service;
- private readonly MockObject|DolibarrApiService $dolibarrApiService;
- private readonly MockObject|EntityManagerInterface $entityManager;
- private readonly MockObject|PersonRepository $personRepository;
- private readonly MockObject|BindFileService $bindFileService;
- private readonly MockObject|LoggerInterface $logger;
- private readonly MockObject|OrganizationIdentificationRepository $organizationIdentificationRepository;
- private readonly MockObject|ApiLegacyRequestService $apiLegacyRequestService;
- private readonly MockObject|PhoneNumberUtil $phoneNumberUtil;
- private readonly MockObject|FunctionTypeRepository $functionTypeRepository;
- public function setUp(): void
- {
- $this->subdomainService = $this->getMockBuilder(SubdomainService::class)->disableOriginalConstructor()->getMock();
- $this->organizationRepository = $this->getMockBuilder(OrganizationRepository::class)->disableOriginalConstructor()->getMock();
- $this->countryRepository = $this->getMockBuilder(CountryRepository::class)->disableOriginalConstructor()->getMock();
- $this->organizationUtils = $this->getMockBuilder(OrganizationUtils::class)->disableOriginalConstructor()->getMock();
- $this->typo3Service = $this->getMockBuilder(Typo3Service::class)->disableOriginalConstructor()->getMock();
- $this->dolibarrApiService = $this->getMockBuilder(DolibarrApiService::class)->disableOriginalConstructor()->getMock();
- $this->entityManager = $this->getMockBuilder(EntityManagerInterface::class)->disableOriginalConstructor()->getMock();
- $this->personRepository = $this->getMockBuilder(PersonRepository::class)->disableOriginalConstructor()->getMock();
- $this->bindFileService = $this->getMockBuilder(BindFileService::class)->disableOriginalConstructor()->getMock();
- $this->logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
- $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
- {
- DatesUtils::clearFakeDatetime();
- }
- private function getOrganizationFactoryMockFor(string $methodName): TestableOrganizationFactory|MockObject
- {
- $organizationFactory = $this
- ->getMockBuilder(TestableOrganizationFactory::class)
- ->setConstructorArgs(
- [
- $this->subdomainService,
- $this->organizationRepository,
- $this->countryRepository,
- $this->organizationUtils,
- $this->typo3Service,
- $this->dolibarrApiService,
- $this->entityManager,
- $this->personRepository,
- $this->bindFileService,
- $this->organizationIdentificationRepository,
- $this->apiLegacyRequestService,
- $this->functionTypeRepository,
- ])
- ->setMethodsExcept(['setLoggerInterface', 'setPhoneNumberUtil', $methodName])
- ->getMock();
- $organizationFactory->setLoggerInterface($this->logger);
- $organizationFactory->setPhoneNumberUtil($this->phoneNumberUtil);
- return $organizationFactory;
- }
- public function testCreate(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('create');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getName')->willReturn('foo');
- $organizationCreationRequest->method('getSubdomain')->willReturn('subdomain');
- $organizationCreationRequest->method('isClient')->willReturn(false);
- $organizationCreationRequest->method('getCreateWebsite')->willReturn(true);
- $this->entityManager->expects(self::once())->method('beginTransaction');
- $organizationFactory->expects(self::once())->method('interruptIfOrganizationExists');
- $organizationFactory->expects(self::once())->method('validateSubdomain')->with('subdomain');
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organizationFactory
- ->expects(self::once())
- ->method('makeOrganizationWithRelations')
- ->with($organizationCreationRequest)
- ->willReturn($organization);
- $this->entityManager->expects(self::once())->method('persist')->with($organization);
- $this->entityManager->expects(self::once())->method('flush');
- $this->entityManager->expects(self::once())->method('commit');
- $this->dolibarrApiService
- ->expects(self::once())
- ->method('createSociety')
- ->with($organization, false)
- ->willReturn(456);
- $this->bindFileService
- ->expects(self::once())
- ->method('registerSubdomain')
- ->with('subdomain');
- $organizationFactory
- ->expects(self::once())
- ->method('createTypo3Website')
- ->with($organization)
- ->willReturn(789);
- $this->logger
- ->method('info')
- ->withConsecutive(
- ["Start the creation of a new organization named 'foo'"],
- ["Subdomain is valid and available : 'subdomain'"],
- ['Organization created with all its relations'],
- ['Organization persisted in the DB'],
- ['New dolibarr structure created (uid : 456)'],
- ['Subdomain registered'],
- ['Typo3 website created (root uid: 789)'],
- ['Adminassos db updated']
- );
- $organizationCreationRequest
- ->expects(self::once())
- ->method('setStatus')
- ->with(OrganizationCreationRequest::STATUS_OK);
- $result = $organizationFactory->create($organizationCreationRequest);
- $this->assertEquals(
- $organization,
- $result
- );
- }
- public function testCreateWithRollback(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('create');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getName')->willReturn('foo');
- $organizationCreationRequest->method('getSubdomain')->willReturn('subdomain');
- $organizationCreationRequest->method('isClient')->willReturn(false);
- $organizationCreationRequest->method('getCreateWebsite')->willReturn(true);
- $this->entityManager->expects(self::once())->method('beginTransaction');
- $organizationFactory->expects(self::once())->method('interruptIfOrganizationExists');
- $organizationFactory->expects(self::once())->method('validateSubdomain')->with('subdomain');
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organizationFactory
- ->expects(self::once())
- ->method('makeOrganizationWithRelations')
- ->with($organizationCreationRequest)
- ->willReturn($organization);
- $this->entityManager->expects(self::once())->method('persist')->with($organization);
- $this->entityManager->expects(self::once())->method('flush')->willThrowException(new \RuntimeException('some error'));
- $this->entityManager->expects(self::once())->method('rollback');
- $this->dolibarrApiService
- ->expects(self::never())
- ->method('createSociety');
- $this->bindFileService
- ->expects(self::never())
- ->method('registerSubdomain');
- $organizationFactory
- ->expects(self::never())
- ->method('createTypo3Website');
- $this->logger
- ->method('info')
- ->withConsecutive(
- ["Start the creation of a new organization named 'foo'"],
- ["Subdomain is valid and available : 'subdomain'"],
- ['Organization created with all its relations']
- );
- $this->logger
- ->method('critical')
- ->with(
- $this->matchesRegularExpression('/^An error happened, operation cancelled\nRuntimeException: some error.*/')
- );
- $this->expectException(\RuntimeException::class);
- $result = $organizationFactory->create($organizationCreationRequest);
- }
- public function testCreateWithExistingOrganization(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('create');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getName')->willReturn('foo');
- $this->entityManager->expects(self::once())->method('beginTransaction');
- $organizationFactory->expects(self::once())->method('interruptIfOrganizationExists')->willThrowException(new \RuntimeException('An organization named foo already exists'));
- $organizationFactory->expects(self::never())->method('validateSubdomain');
- $organizationFactory
- ->expects(self::never())
- ->method('makeOrganizationWithRelations');
- $this->entityManager->expects(self::never())->method('persist');
- $this->entityManager->expects(self::never())->method('flush');
- $this->entityManager->expects(self::once())->method('rollback');
- $this->dolibarrApiService
- ->expects(self::never())
- ->method('createSociety');
- $this->bindFileService
- ->expects(self::never())
- ->method('registerSubdomain');
- $organizationFactory
- ->expects(self::never())
- ->method('createTypo3Website');
- $this->logger
- ->method('info')
- ->withConsecutive(
- ["Start the creation of a new organization named 'foo'"],
- );
- $this->logger
- ->method('critical')
- ->with(
- $this->matchesRegularExpression("/^An error happened, operation cancelled\nRuntimeException: An organization named foo already exists.*/")
- );
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage('An organization named foo already exists');
- $result = $organizationFactory->create($organizationCreationRequest);
- }
- public function testCreateNoWebsiteAndIsClient(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('create');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getName')->willReturn('foo');
- $organizationCreationRequest->method('getSubdomain')->willReturn('subdomain');
- $organizationCreationRequest->method('isClient')->willReturn(true);
- $organizationCreationRequest->method('getCreateWebsite')->willReturn(false);
- $organizationFactory->expects(self::once())->method('interruptIfOrganizationExists');
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organizationFactory
- ->expects(self::once())
- ->method('makeOrganizationWithRelations')
- ->with($organizationCreationRequest)
- ->willReturn($organization);
- $this->dolibarrApiService
- ->method('createSociety')
- ->with($organization, true)
- ->willReturn(456);
- $organizationFactory
- ->expects(self::never())
- ->method('createTypo3Website');
- $this->logger
- ->expects(self::once())
- ->method('warning')
- ->with('Typo3 website creation was not required');
- $result = $organizationFactory->create($organizationCreationRequest);
- $this->assertEquals(
- $organization,
- $result
- );
- }
- public function testCreateWithErrors(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('create');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getName')->willReturn('foo');
- $organizationCreationRequest->method('getSubdomain')->willReturn('subdomain');
- $organizationCreationRequest->method('isClient')->willReturn(true);
- $organizationCreationRequest->method('getCreateWebsite')->willReturn(true);
- $organizationFactory->expects(self::once())->method('interruptIfOrganizationExists');
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organizationFactory
- ->expects(self::once())
- ->method('makeOrganizationWithRelations')
- ->with($organizationCreationRequest)
- ->willReturn($organization);
- $this->dolibarrApiService
- ->method('createSociety')
- ->with($organization, true)
- ->willThrowException(new \RuntimeException('An error happened'));
- $this->bindFileService
- ->method('registerSubdomain')
- ->with('subdomain')
- ->willThrowException(new \RuntimeException('An error happened'));
- $organizationFactory
- ->method('createTypo3Website')
- ->with($organization)
- ->willThrowException(new \RuntimeException('An error happened'));
- $organizationFactory
- ->method('updateAdminassosDb')
- ->with($organization)
- ->willThrowException(new \RuntimeException('An error happened'));
- $this->logger
- ->expects(self::exactly(4))
- ->method('critical')
- ->willReturnOnConsecutiveCalls([
- 'An error happened while creating the dolibarr society, please proceed manually.',
- 'An error happened while updating the bind file, please proceed manually.',
- 'An error happened while creating the typo3 website, please proceed manually.',
- 'An error happened while updating the adminassos db, please proceed manually.',
- ]);
- $this->logger
- ->expects(self::once())
- ->method('warning')
- ->with('-- Operation ended with errors, check the logs for more information --');
- $organizationCreationRequest
- ->expects(self::once())
- ->method('setStatus')
- ->with(OrganizationCreationRequest::STATUS_OK_WITH_ERRORS);
- $result = $organizationFactory->create($organizationCreationRequest);
- $this->assertEquals(
- $organization,
- $result
- );
- }
- public function testInterruptIfOrganizationExistsNotExisting(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('interruptIfOrganizationExists');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getName')->willReturn('foo');
- $organizationCreationRequest->method('getSiretNumber')->willReturn('');
- $organizationCreationRequest->method('getWaldecNumber')->willReturn('');
- $organizationCreationRequest->method('getIdentifier')->willReturn('');
- $organizationCreationRequest->method('getStreetAddress1')->willReturn('part1');
- $organizationCreationRequest->method('getStreetAddress2')->willReturn('part2');
- $organizationCreationRequest->method('getStreetAddress3')->willReturn('part3');
- $organizationCreationRequest->method('getCity')->willReturn('Paris');
- $organizationCreationRequest->method('getPostalCode')->willReturn('75000');
- $this->organizationIdentificationRepository
- ->expects(self::exactly(2))
- ->method('findOneBy')
- ->willReturn(null);
- $organizationFactory
- ->method('normalizeIdentificationField')
- ->willReturnMap([
- ['foo', 'foo'],
- ['part1 part2 part3', 'part1 part2 part3'],
- ]);
- $organizationFactory->interruptIfOrganizationExists($organizationCreationRequest);
- }
- public function testInterruptIfOrganizationExistsNotExistingNonExistingWithIdentifiers(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('interruptIfOrganizationExists');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getName')->willReturn('foo');
- $organizationCreationRequest->method('getSiretNumber')->willReturn('123456');
- $organizationCreationRequest->method('getWaldecNumber')->willReturn('W123456');
- $organizationCreationRequest->method('getIdentifier')->willReturn('FR000000000000');
- $organizationCreationRequest->method('getStreetAddress1')->willReturn('part1');
- $organizationCreationRequest->method('getStreetAddress2')->willReturn('part2');
- $organizationCreationRequest->method('getStreetAddress3')->willReturn('part3');
- $organizationCreationRequest->method('getCity')->willReturn('Paris');
- $organizationCreationRequest->method('getPostalCode')->willReturn('75000');
- $organizationFactory
- ->method('normalizeIdentificationField')
- ->willReturnMap([
- ['foo', 'foo'],
- ['part1 part2 part3', 'part1 part2 part3'],
- ]);
- $this->organizationIdentificationRepository
- ->expects(self::exactly(5))
- ->method('findOneBy')
- ->willReturnMap([
- [['siretNumber' => '123456'], null, null],
- [['waldecNumber' => 'W123456'], null, null],
- [['identifier' => 'FR000000000000'], null, null],
- [['normalizedName' => 'foo', 'addressCity' => 'Paris'], null, null],
- [['normalizedAddress' => 'part1 part2 part3', 'addressCity' => 'Paris', 'postalCode' => '75000'], null, null],
- ]);
- $organizationFactory->interruptIfOrganizationExists($organizationCreationRequest);
- }
- public function testInterruptIfOrganizationExistsExistingWithSiret(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('interruptIfOrganizationExists');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getName')->willReturn('foo');
- $organizationCreationRequest->method('getSiretNumber')->willReturn('123456');
- $organizationCreationRequest->method('getWaldecNumber')->willReturn('W123456');
- $organizationCreationRequest->method('getIdentifier')->willReturn('FR000000000000');
- $organizationCreationRequest->method('getStreetAddress1')->willReturn('part1');
- $organizationCreationRequest->method('getStreetAddress2')->willReturn('part2');
- $organizationCreationRequest->method('getStreetAddress3')->willReturn('part3');
- $organizationCreationRequest->method('getCity')->willReturn('Paris');
- $organizationCreationRequest->method('getPostalCode')->willReturn('75000');
- $organizationFactory
- ->method('normalizeIdentificationField')
- ->willReturnMap([
- ['foo', 'foo'],
- ['part1 part2 part3', 'part1 part2 part3'],
- ]);
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $this->organizationIdentificationRepository
- ->method('findOneBy')
- ->willReturnMap([
- [['siretNumber' => '123456'], null, $organization],
- [['waldecNumber' => 'W123456'], null, null],
- [['identifier' => 'FR000000000000'], null, null],
- [['normalizedName' => 'foo', 'addressCity' => 'Paris'], null, null],
- [['normalizedAddress' => 'part1 part2 part3', 'addressCity' => 'Paris', 'postalCode' => '75000'], null, null],
- ]);
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage("This siret number is already registered : '123456'");
- $organizationFactory->interruptIfOrganizationExists($organizationCreationRequest);
- }
- public function testInterruptIfOrganizationExistsExistingWithWaldec(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('interruptIfOrganizationExists');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getName')->willReturn('foo');
- $organizationCreationRequest->method('getSiretNumber')->willReturn('123456');
- $organizationCreationRequest->method('getWaldecNumber')->willReturn('W123456');
- $organizationCreationRequest->method('getIdentifier')->willReturn('FR000000000000');
- $organizationCreationRequest->method('getStreetAddress1')->willReturn('part1');
- $organizationCreationRequest->method('getStreetAddress2')->willReturn('part2');
- $organizationCreationRequest->method('getStreetAddress3')->willReturn('part3');
- $organizationCreationRequest->method('getCity')->willReturn('Paris');
- $organizationCreationRequest->method('getPostalCode')->willReturn('75000');
- $organizationFactory
- ->method('normalizeIdentificationField')
- ->willReturnMap([
- ['foo', 'foo'],
- ['part1 part2 part3', 'part1 part2 part3'],
- ]);
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $this->organizationIdentificationRepository
- ->method('findOneBy')
- ->willReturnMap([
- [['siretNumber' => '123456'], null, null],
- [['waldecNumber' => 'W123456'], null, $organization],
- [['identifier' => 'FR000000000000'], null, null],
- [['normalizedName' => 'foo', 'addressCity' => 'Paris'], null, null],
- [['normalizedAddress' => 'part1 part2 part3', 'addressCity' => 'Paris', 'postalCode' => '75000'], null, null],
- ]);
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage("This RNA identifier (waldec number) is already registered : 'W123456'");
- $organizationFactory->interruptIfOrganizationExists($organizationCreationRequest);
- }
- public function testInterruptIfOrganizationExistsExistingWithCMFIdentifier(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('interruptIfOrganizationExists');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getName')->willReturn('foo');
- $organizationCreationRequest->method('getSiretNumber')->willReturn('123456');
- $organizationCreationRequest->method('getWaldecNumber')->willReturn('W123456');
- $organizationCreationRequest->method('getIdentifier')->willReturn('FR000000000000');
- $organizationCreationRequest->method('getStreetAddress1')->willReturn('part1');
- $organizationCreationRequest->method('getStreetAddress2')->willReturn('part2');
- $organizationCreationRequest->method('getStreetAddress3')->willReturn('part3');
- $organizationCreationRequest->method('getCity')->willReturn('Paris');
- $organizationCreationRequest->method('getPostalCode')->willReturn('75000');
- $organizationFactory
- ->method('normalizeIdentificationField')
- ->willReturnMap([
- ['foo', 'foo'],
- ['part1 part2 part3', 'part1 part2 part3'],
- ]);
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $this->organizationIdentificationRepository
- ->method('findOneBy')
- ->willReturnMap([
- [['siretNumber' => '123456'], null, null],
- [['waldecNumber' => 'W123456'], null, null],
- [['identifier' => 'FR000000000000'], null, $organization],
- [['normalizedName' => 'foo', 'addressCity' => 'Paris'], null, null],
- [['normalizedAddress' => 'part1 part2 part3', 'addressCity' => 'Paris', 'postalCode' => '75000'], null, null],
- ]);
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage("This CMF identifier is already registered : 'FR000000000000'");
- $organizationFactory->interruptIfOrganizationExists($organizationCreationRequest);
- }
- public function testInterruptIfOrganizationExistsExistingWithSameNameAndCity(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('interruptIfOrganizationExists');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getName')->willReturn('foo');
- $organizationCreationRequest->method('getSiretNumber')->willReturn('123456');
- $organizationCreationRequest->method('getWaldecNumber')->willReturn('W123456');
- $organizationCreationRequest->method('getIdentifier')->willReturn('FR000000000000');
- $organizationCreationRequest->method('getStreetAddress1')->willReturn('part1');
- $organizationCreationRequest->method('getStreetAddress2')->willReturn('part2');
- $organizationCreationRequest->method('getStreetAddress3')->willReturn('part3');
- $organizationCreationRequest->method('getCity')->willReturn('Paris');
- $organizationCreationRequest->method('getPostalCode')->willReturn('75000');
- $organizationFactory
- ->method('normalizeIdentificationField')
- ->willReturnMap([
- ['foo', 'foo'],
- ['part1 part2 part3', 'part1 part2 part3'],
- ]);
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $this->organizationIdentificationRepository
- ->method('findOneBy')
- ->willReturnMap([
- [['siretNumber' => '123456'], null, null],
- [['waldecNumber' => 'W123456'], null, null],
- [['identifier' => 'FR000000000000'], null, null],
- [['normalizedName' => 'foo', 'addressCity' => 'Paris'], null, $organization],
- [['normalizedAddress' => 'part1 part2 part3', 'addressCity' => 'Paris', 'postalCode' => '75000'], null, null],
- ]);
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage("An organization named 'foo' already exists in Paris");
- $organizationFactory->interruptIfOrganizationExists($organizationCreationRequest);
- }
- public function testInterruptIfOrganizationExistsExistingWithSameAddress(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('interruptIfOrganizationExists');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getName')->willReturn('foo');
- $organizationCreationRequest->method('getSiretNumber')->willReturn('123456');
- $organizationCreationRequest->method('getWaldecNumber')->willReturn('W123456');
- $organizationCreationRequest->method('getIdentifier')->willReturn('FR000000000000');
- $organizationCreationRequest->method('getStreetAddress1')->willReturn('part1');
- $organizationCreationRequest->method('getStreetAddress2')->willReturn('part2');
- $organizationCreationRequest->method('getStreetAddress3')->willReturn('part3');
- $organizationCreationRequest->method('getCity')->willReturn('Paris');
- $organizationCreationRequest->method('getPostalCode')->willReturn('75000');
- $organizationFactory
- ->method('normalizeIdentificationField')
- ->willReturnMap([
- ['foo', 'foo'],
- ['part1 part2 part3', 'part1 part2 part3'],
- ]);
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $this->organizationIdentificationRepository
- ->method('findOneBy')
- ->willReturnMap([
- [['siretNumber' => '123456'], null, null],
- [['waldecNumber' => 'W123456'], null, null],
- [['identifier' => 'FR000000000000'], null, null],
- [['normalizedName' => 'foo', 'addressCity' => 'Paris'], null, null],
- [['normalizedAddress' => 'part1 part2 part3', 'addressCity' => 'Paris', 'postalCode' => '75000'], null, $organization],
- ]);
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage('An organization already exists at this address.');
- $organizationFactory->interruptIfOrganizationExists($organizationCreationRequest);
- }
- public function testValidateSubdomain(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('validateSubdomain');
- $this->subdomainService->expects(self::once())->method('isValidSubdomain')->willReturn(true);
- $this->subdomainService->expects(self::once())->method('isReservedSubdomain')->willReturn(false);
- $this->subdomainService->expects(self::once())->method('isRegistered')->willReturn(false);
- $organizationFactory->validateSubdomain('foo');
- }
- public function testValidateSubdomainIsNotValid(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('validateSubdomain');
- $this->subdomainService->method('isValidSubdomain')->willReturn(false);
- $this->subdomainService->method('isReservedSubdomain')->willReturn(false);
- $this->subdomainService->method('isRegistered')->willReturn(false);
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage('Not a valid subdomain : foo');
- $organizationFactory->validateSubdomain('foo');
- }
- public function testValidateSubdomainIsReserved(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('validateSubdomain');
- $this->subdomainService->method('isValidSubdomain')->willReturn(true);
- $this->subdomainService->method('isReservedSubdomain')->willReturn(true);
- $this->subdomainService->method('isRegistered')->willReturn(false);
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage('This subdomain is not available : foo');
- $organizationFactory->validateSubdomain('foo');
- }
- public function testValidateSubdomainIsRegistered(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('validateSubdomain');
- $this->subdomainService->method('isValidSubdomain')->willReturn(true);
- $this->subdomainService->method('isReservedSubdomain')->willReturn(false);
- $this->subdomainService->method('isRegistered')->willReturn(true);
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage('This subdomain is already registered : foo');
- $organizationFactory->validateSubdomain('foo');
- }
- 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
- $organizationFactory
- ->expects(self::once())
- ->method('makeOrganization')
- ->with($organizationCreationRequest)
- ->willReturn($organization);
- // Création des Parameters
- $parameters = $this->getMockBuilder(Parameters::class)->getMock();
- $organizationFactory
- ->expects(self::once())
- ->method('makeParameters')
- ->with($organizationCreationRequest)
- ->willReturn($parameters);
- $organization->expects(self::once())->method('setParameters')->with($parameters);
- // Création des Settings
- $settings = $this->getMockBuilder(Settings::class)->getMock();
- $organizationFactory
- ->expects(self::once())
- ->method('makeSettings')
- ->with($organizationCreationRequest)
- ->willReturn($settings);
- $organization->expects(self::once())->method('setSettings')->with($settings);
- // Création de l'adresse postale
- $organizationAddressPostal = $this->getMockBuilder(OrganizationAddressPostal::class)->getMock();
- $organizationFactory
- ->expects(self::once())
- ->method('makePostalAddress')
- ->with($organizationCreationRequest)
- ->willReturn($organizationAddressPostal);
- $organization->expects(self::once())->method('addOrganizationAddressPostal')->with($organizationAddressPostal);
- // Création du point de contact
- $contactPoint = $this->getMockBuilder(ContactPoint::class)->getMock();
- $organizationFactory
- ->expects(self::once())
- ->method('makeContactPoint')
- ->with($organizationCreationRequest)
- ->willReturn($contactPoint);
- $organization->expects(self::once())->method('addContactPoint')->with($contactPoint);
- // Rattachement au réseau
- $networkOrganization = $this->getMockBuilder(NetworkOrganization::class)->getMock();
- $organizationFactory
- ->expects(self::once())
- ->method('makeNetworkOrganization')
- ->with($organizationCreationRequest)
- ->willReturn($networkOrganization);
- $organization->expects(self::once())->method('addNetworkOrganization')->with($networkOrganization);
- // Créé l'admin
- $adminAccess = $this->getMockBuilder(Access::class)->getMock();
- $organizationFactory
- ->expects(self::once())
- ->method('makeAdminAccess')
- ->with($organizationCreationRequest)
- ->willReturn($adminAccess);
- // Le `$organization->expects(...)->method('addAccess')` est implémenté plus loin,
- // après la création du président et du directeur.
- // Création des cycles
- $cycle1 = $this->getMockBuilder(Cycle::class)->getMock();
- $cycle2 = $this->getMockBuilder(Cycle::class)->getMock();
- $cycle3 = $this->getMockBuilder(Cycle::class)->getMock();
- $organizationFactory
- ->expects(self::once())
- ->method('makeCycles')
- ->willReturn([$cycle1, $cycle2, $cycle3]);
- $organization->expects(self::exactly(3))->method('addCycle')->withConsecutive([$cycle1], [$cycle2], [$cycle3]);
- // Création du président et du directeur
- $organizationMemberCreationRequest1 = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getPresident')->willReturn($organizationMemberCreationRequest1);
- $organizationMemberCreationRequest2 = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getDirector')->willReturn($organizationMemberCreationRequest2);
- $access1 = $this->getMockBuilder(Access::class)->getMock();
- $access2 = $this->getMockBuilder(Access::class)->getMock();
- $organizationFactory
- ->expects(self::exactly(2))
- ->method('makeAccess')
- ->willReturnMap([
- [$organizationMemberCreationRequest1, FunctionEnum::PRESIDENT, $creationDate, 1, $access1],
- [$organizationMemberCreationRequest2, FunctionEnum::DIRECTOR, $creationDate, 1, $access2],
- ]);
- $organization
- ->expects(self::exactly(3))
- ->method('addAccess')
- ->withConsecutive([$adminAccess], [$access1], [$access2]);
- // Création du sous-domaine
- $subdomain = $this->getMockBuilder(Subdomain::class)->getMock();
- $organizationFactory
- ->expects(self::once())
- ->method('makeSubdomain')
- ->with($organizationCreationRequest)
- ->willReturn($subdomain);
- $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);
- $this->assertEquals(
- $result,
- $organization
- );
- }
- public function testMakeOrganizationWithRelationsNoPresidentNoDirector(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makeOrganizationWithRelations');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- // Création de l'organisation
- $organizationFactory
- ->expects(self::once())
- ->method('makeOrganization')
- ->with($organizationCreationRequest)
- ->willReturn($organization);
- $organizationCreationRequest->method('getPresident')->willReturn(null);
- $organizationCreationRequest->method('getDirector')->willReturn(null);
- // Un seul appel, pour l'adminAccess
- $organization
- ->expects(self::once())
- ->method('addAccess');
- $organizationFactory->makeOrganizationWithRelations($organizationCreationRequest);
- }
- public function testMakeOrganization()
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makeOrganization');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getName')->willReturn('My Organization');
- $organizationCreationRequest->method('getLegalStatus')->willReturn(LegalEnum::ASSOCIATION_LAW_1901);
- $organizationCreationRequest->method('getPrincipalType')->willReturn(PrincipalTypeEnum::ARTISTIC_EDUCATION_ONLY);
- $organization = $organizationFactory->makeOrganization($organizationCreationRequest);
- $this->assertEquals(
- 'My Organization',
- $organization->getName()
- );
- $this->assertEquals(
- LegalEnum::ASSOCIATION_LAW_1901,
- $organization->getLegalStatus()
- );
- $this->assertEquals(
- PrincipalTypeEnum::ARTISTIC_EDUCATION_ONLY,
- $organization->getPrincipalType()
- );
- }
- public function testMakeParameters(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makeParameters');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $parameters = $organizationFactory->makeParameters($organizationCreationRequest);
- $this->assertInstanceOf(Parameters::class, $parameters);
- }
- public function testMakeSettings(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makeSettings');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getProduct')->willReturn(SettingsProductEnum::ARTIST_PREMIUM);
- $settings = $organizationFactory->makeSettings($organizationCreationRequest);
- $this->assertEquals(
- SettingsProductEnum::ARTIST_PREMIUM,
- $settings->getProduct()
- );
- }
- public function testMakePostalAddress(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makePostalAddress');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getStreetAddress1')->willReturn('address1');
- $organizationCreationRequest->method('getStreetAddress2')->willReturn('address2');
- $organizationCreationRequest->method('getStreetAddress3')->willReturn('address3');
- $organizationCreationRequest->method('getPostalCode')->willReturn('00000');
- $organizationCreationRequest->method('getCity')->willReturn('city');
- $organizationCreationRequest->method('getCountryId')->willReturn(1);
- $country = $this->getMockBuilder(Country::class)->getMock();
- $this->countryRepository->expects(self::once())->method('find')->with(1)->willReturn($country);
- $organizationAddressPostal = $organizationFactory->makePostalAddress($organizationCreationRequest);
- $this->assertEquals(
- AddressPostalOrganizationTypeEnum::ADDRESS_HEAD_OFFICE,
- $organizationAddressPostal->getType()
- );
- $addressPostal = $organizationAddressPostal->getAddressPostal();
- $this->assertEquals(
- 'address1',
- $addressPostal->getStreetAddress()
- );
- $this->assertEquals(
- 'address2',
- $addressPostal->getStreetAddressSecond()
- );
- $this->assertEquals(
- 'address3',
- $addressPostal->getStreetAddressThird()
- );
- $this->assertEquals(
- '00000',
- $addressPostal->getPostalCode()
- );
- $this->assertEquals(
- 'city',
- $addressPostal->getAddressCity()
- );
- $this->assertEquals(
- $country,
- $addressPostal->getAddressCountry()
- );
- }
- public function testMakePostalAddressUnexistingCountry(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makePostalAddress');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getCountryId')->willReturn(1);
- $this->countryRepository->expects(self::once())->method('find')->with(1)->willReturn(null);
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage('No country found for id 1');
- $organizationFactory->makePostalAddress($organizationCreationRequest);
- }
- public function testMakeContactPoint(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makeContactPoint');
- $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);
- $contactPoint = $organizationFactory->makeContactPoint($organizationCreationRequest);
- $this->assertEquals(
- 'contact@domain.net',
- $contactPoint->getEmail()
- );
- $this->assertEquals(
- $phoneNumber,
- $contactPoint->getTelphone()
- );
- }
- 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
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makeNetworkOrganization');
- DatesUtils::setFakeDatetime('2024-01-01');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getParentId')->willReturn(123);
- $parent = $this->getMockBuilder(Organization::class)->getMock();
- $settings = $this->getMockBuilder(Settings::class)->getMock();
- $settings->method('getProduct')->willReturn(SettingsProductEnum::MANAGER);
- $parent->method('getSettings')->willReturn($settings);
- $this->organizationRepository->expects(self::once())->method('find')->with(123)->willReturn($parent);
- $network = $this->getMockBuilder(Network::class)->getMock();
- $networkOrganization = $this->getMockBuilder(NetworkOrganization::class)->getMock();
- $networkOrganization->method('getNetwork')->willReturn($network);
- $this->organizationUtils
- ->expects(self::once())
- ->method('getActiveNetworkOrganization')
- ->with($parent)
- ->willReturn($networkOrganization);
- $networkOrganization = $organizationFactory->makeNetworkOrganization($organizationCreationRequest);
- $this->assertEquals(
- $parent,
- $networkOrganization->getParent()
- );
- $this->assertEquals(
- $network,
- $networkOrganization->getNetwork()
- );
- $this->assertEquals(
- '2024-01-01',
- $networkOrganization->getStartDate()->format('Y-m-d')
- );
- }
- public function testMakeNetworkOrganizationMissingParent(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makeNetworkOrganization');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getParentId')->willReturn(123);
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage('No parent organization found for id 123');
- $this->organizationRepository->expects(self::once())->method('find')->with(123)->willReturn(null);
- $organizationFactory->makeNetworkOrganization($organizationCreationRequest);
- }
- public function testMakeNetworkOrganizationParentIsNotManager(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makeNetworkOrganization');
- DatesUtils::setFakeDatetime('2024-01-01');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getParentId')->willReturn(123);
- $parent = $this->getMockBuilder(Organization::class)->getMock();
- $settings = $this->getMockBuilder(Settings::class)->getMock();
- $settings->method('getProduct')->willReturn(SettingsProductEnum::SCHOOL);
- $parent->method('getSettings')->willReturn($settings);
- $this->organizationRepository->expects(self::once())->method('find')->with(123)->willReturn($parent);
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage("Parent organization must have the product 'manager' (actual product: 'school')");
- $organizationFactory->makeNetworkOrganization($organizationCreationRequest);
- }
- public function testMakeNetworkOrganizationMissingNetwork(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makeNetworkOrganization');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getParentId')->willReturn(123);
- $parent = $this->getMockBuilder(Organization::class)->getMock();
- $settings = $this->getMockBuilder(Settings::class)->getMock();
- $settings->method('getProduct')->willReturn(SettingsProductEnum::MANAGER);
- $parent->method('getSettings')->willReturn($settings);
- $this->organizationRepository->expects(self::once())->method('find')->with(123)->willReturn($parent);
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage('No network found for parent 123');
- $this->organizationRepository->expects(self::once())->method('find')->with(123)->willReturn($parent);
- $organizationFactory->makeNetworkOrganization($organizationCreationRequest);
- }
- public function testMakeNetworkOrganizationIsCMFInvalidIdentifier(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makeNetworkOrganization');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getParentId')->willReturn(123);
- $organizationCreationRequest->method('getIdentifier')->willReturn('invalid');
- $parent = $this->getMockBuilder(Organization::class)->getMock();
- $settings = $this->getMockBuilder(Settings::class)->getMock();
- $settings->method('getProduct')->willReturn(SettingsProductEnum::MANAGER);
- $parent->method('getSettings')->willReturn($settings);
- $this->organizationRepository->method('find')->with(123)->willReturn($parent);
- $network = $this->getMockBuilder(Network::class)->getMock();
- $network->method('getId')->willReturn(NetworkEnum::CMF->value);
- $networkOrganization = $this->getMockBuilder(NetworkOrganization::class)->getMock();
- $networkOrganization->method('getNetwork')->willReturn($network);
- $this->organizationUtils
- ->method('getActiveNetworkOrganization')
- ->with($parent)
- ->willReturn($networkOrganization);
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage('CMF identifier is missing or invalid.');
- $organizationFactory->makeNetworkOrganization($organizationCreationRequest);
- }
- public function testMakeNetworkOrganizationIsNotCMFInvalidIdentifier(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makeNetworkOrganization');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getParentId')->willReturn(123);
- $organizationCreationRequest->method('getIdentifier')->willReturn('invalid');
- $parent = $this->getMockBuilder(Organization::class)->getMock();
- $settings = $this->getMockBuilder(Settings::class)->getMock();
- $settings->method('getProduct')->willReturn(SettingsProductEnum::MANAGER);
- $parent->method('getSettings')->willReturn($settings);
- $this->organizationRepository->method('find')->with(123)->willReturn($parent);
- $network = $this->getMockBuilder(Network::class)->getMock();
- $network->method('getId')->willReturn(NetworkEnum::OUTOFNET->value);
- $networkOrganization = $this->getMockBuilder(NetworkOrganization::class)->getMock();
- $networkOrganization->method('getNetwork')->willReturn($network);
- $this->organizationUtils
- ->method('getActiveNetworkOrganization')
- ->with($parent)
- ->willReturn($networkOrganization);
- $result = $organizationFactory->makeNetworkOrganization($organizationCreationRequest);
- $this->assertEquals(
- $network,
- $result->getNetwork()
- );
- }
- public function testMakeAdminAccess(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makeAdminAccess');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getSubdomain')->willReturn('foo');
- $adminAccess = $organizationFactory->makeAdminAccess($organizationCreationRequest);
- $this->assertTrue(
- $adminAccess->getAdminAccess()
- );
- $this->assertEquals(
- 'adminfoo',
- $adminAccess->getPerson()->getUsername()
- );
- $this->assertEquals(
- 32,
- strlen($adminAccess->getPerson()->getPassword())
- );
- }
- public function testMakeCycles(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makeCycles');
- $cycles = $organizationFactory->makeCycles();
- $cyclesExpectedData = [
- ['Cycle initiation', 10, CycleEnum::INITIATION_CYCLE],
- ['Cycle 1', 20, CycleEnum::CYCLE_1],
- ['Cycle 2', 30, CycleEnum::CYCLE_2],
- ['Cycle 3', 40, CycleEnum::CYCLE_3],
- ['Cycle 4', 50, CycleEnum::CYCLE_4],
- ['Hors cycle', 60, CycleEnum::OUT_CYCLE],
- ];
- $i = 0;
- foreach ($cycles as $cycle) {
- $this->assertEquals(
- $cyclesExpectedData[$i][0],
- $cycle->getLabel()
- );
- $this->assertEquals(
- $cyclesExpectedData[$i][1],
- $cycle->getOrder()
- );
- $this->assertEquals(
- $cyclesExpectedData[$i][2],
- $cycle->getCycleEnum()
- );
- $this->assertFalse(
- $cycle->getIsSystem()
- );
- ++$i;
- }
- }
- public function testMakeAccessNewPerson(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makeAccess');
- $organizationMemberCreationRequest = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
- $organizationMemberCreationRequest->method('getUsername')->willReturn('bob');
- $organizationMemberCreationRequest->method('getName')->willReturn('Bob');
- $organizationMemberCreationRequest->method('getGivenName')->willReturn('bOBBy');
- $organizationMemberCreationRequest->method('getGender')->willReturn(GenderEnum::MISTER);
- $this->personRepository
- ->method('findOneBy')
- ->with(['username' => 'bob'], null)
- ->willReturn(null);
- $personAddressPostal = $this->getMockBuilder(PersonAddressPostal::class)->getMock();
- $organizationFactory
- ->expects(self::once())
- ->method('makePersonPostalAddress')
- ->with($organizationMemberCreationRequest)
- ->willReturn($personAddressPostal);
- $contactPoint = $this->getMockBuilder(ContactPoint::class)->getMock();
- $organizationFactory
- ->expects(self::once())
- ->method('makePersonContactPoint')
- ->with($organizationMemberCreationRequest)
- ->willReturn($contactPoint);
- $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(
- 'bob',
- $access->getPerson()->getUsername()
- );
- $this->assertTrue(
- strlen($access->getPerson()->getPassword()) === 32
- );
- $this->assertEquals(
- 'Bob',
- $access->getPerson()->getName()
- );
- $this->assertEquals(
- 'Bobby',
- $access->getPerson()->getGivenName()
- );
- $this->assertEquals(
- [$personAddressPostal],
- $access->getPerson()->getPersonAddressPostal()->toArray()
- );
- $this->assertEquals(
- [$contactPoint],
- $access->getPerson()->getContactPoints()->toArray()
- );
- $this->assertEquals(
- $functionType,
- $access->getOrganizationFunction()->first()->getFunctionType()
- );
- $this->assertEquals(
- $creationDate,
- $access->getOrganizationFunction()->first()->getStartDate()
- );
- }
- public function testMakeAccessNewPersonUsernameAlreadyInUse(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makeAccess');
- $organizationMemberCreationRequest = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
- $organizationMemberCreationRequest->method('getUsername')->willReturn('bob');
- $organizationMemberCreationRequest->method('getName')->willReturn('Bob');
- $organizationMemberCreationRequest->method('getGivenName')->willReturn('bOBBy');
- $organizationMemberCreationRequest->method('getGender')->willReturn(GenderEnum::MISTER);
- $person = $this->getMockBuilder(Person::class)->getMock();
- $this->personRepository
- ->method('findOneBy')
- ->with(['username' => 'bob'], null)
- ->willReturn($person);
- $organizationFactory
- ->expects(self::never())
- ->method('makePersonPostalAddress');
- $organizationFactory
- ->expects(self::never())
- ->method('makePersonContactPoint');
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage('Username already in use : bob');
- $creationDate = $this->getMockBuilder(\DateTime::class)->getMock();
- $organizationFactory->makeAccess(
- $organizationMemberCreationRequest,
- FunctionEnum::ADHERENT,
- $creationDate,
- 1
- );
- }
- public function testMakeAccessExistingPerson(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makeAccess');
- $person = $this->getMockBuilder(Person::class)->getMock();
- $this->personRepository
- ->expects(self::once())
- ->method('find')
- ->with(123)
- ->willReturn($person);
- $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()
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makePersonPostalAddress');
- $organizationMemberCreationRequest = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
- $organizationMemberCreationRequest->method('getStreetAddress1')->willReturn('Aaa');
- $organizationMemberCreationRequest->method('getStreetAddress2')->willReturn('Bbb');
- $organizationMemberCreationRequest->method('getStreetAddress3')->willReturn(null);
- $organizationMemberCreationRequest->method('getPostalCode')->willReturn('00000');
- $organizationMemberCreationRequest->method('getCity')->willReturn('city');
- $organizationMemberCreationRequest->method('getCountryId')->willReturn(123);
- $country = $this->getMockBuilder(Country::class)->getMock();
- $this->countryRepository
- ->expects(self::once())
- ->method('find')
- ->with(123)
- ->willReturn($country);
- $creationDate = $this->getMockBuilder(\DateTime::class)->getMock();
- $personPostalAddress = $organizationFactory->makePersonPostalAddress(
- $organizationMemberCreationRequest,
- $creationDate,
- 1
- );
- $this->assertEquals(
- AddressPostalPersonTypeEnum::ADDRESS_PRINCIPAL,
- $personPostalAddress->getType()
- );
- $postalAddress = $personPostalAddress->getAddressPostal();
- $this->assertEquals('Aaa', $postalAddress->getStreetAddress());
- $this->assertEquals('Bbb', $postalAddress->getStreetAddressSecond());
- $this->assertEquals(null, $postalAddress->getStreetAddressThird());
- $this->assertEquals('00000', $postalAddress->getPostalCode());
- $this->assertEquals('city', $postalAddress->getAddressCity());
- $this->assertEquals($country, $postalAddress->getAddressCountry());
- }
- public function testMakeAccessContactPoint(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makePersonContactPoint');
- $organizationMemberCreationRequest = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
- $organizationMemberCreationRequest->method('getPhone')->willReturn('+33102030405');
- $organizationMemberCreationRequest->method('getEmail')->willReturn('email@domain.com');
- $organizationMemberCreationRequest->method('getMobile')->willReturn('+33607080910');
- $this->phoneNumberUtil
- ->expects(self::exactly(2))
- ->method('isPossibleNumber')
- ->willReturnMap([
- ['+33102030405', null, true],
- ['+33607080910', 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],
- ]);
- $creationDate = $this->getMockBuilder(\DateTime::class)->getMock();
- $contactPoint = $organizationFactory->makePersonContactPoint(
- $organizationMemberCreationRequest,
- $creationDate,
- 1
- );
- $this->assertEquals(
- ContactPointTypeEnum::PRINCIPAL,
- $contactPoint->getContactType()
- );
- $this->assertEquals(
- 'email@domain.com',
- $contactPoint->getEmail()
- );
- $this->assertEquals(
- $phoneNumber,
- $contactPoint->getTelphone()
- );
- $this->assertEquals(
- $mobilePhoneNumber,
- $contactPoint->getMobilPhone()
- );
- }
- public function testMakeAccessContactPointInvalidPhone(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makePersonContactPoint');
- $organizationMemberCreationRequest = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
- $organizationMemberCreationRequest->method('getUsername')->willReturn('bob');
- $organizationMemberCreationRequest->method('getPhone')->willReturn('invalid');
- $organizationMemberCreationRequest->method('getEmail')->willReturn('email@domain.com');
- $organizationMemberCreationRequest->method('getMobile')->willReturn('+33607080910');
- $this->phoneNumberUtil
- ->expects(self::once())
- ->method('isPossibleNumber')
- ->with('invalid')
- ->willReturn(false);
- $this->phoneNumberUtil
- ->expects(self::never())
- ->method('parse');
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage('Phone number is invalid or missing (person: bob)');
- $creationDate = $this->getMockBuilder(\DateTime::class)->getMock();
- $organizationFactory->makePersonContactPoint(
- $organizationMemberCreationRequest,
- $creationDate,
- 1
- );
- }
- public function testMakeAccessContactPointInvalidMobilePhone(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makePersonContactPoint');
- $organizationMemberCreationRequest = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
- $organizationMemberCreationRequest->method('getUsername')->willReturn('bob');
- $organizationMemberCreationRequest->method('getPhone')->willReturn('+33102030405');
- $organizationMemberCreationRequest->method('getEmail')->willReturn('email@domain.com');
- $organizationMemberCreationRequest->method('getMobile')->willReturn('invalid');
- $this->phoneNumberUtil
- ->expects(self::exactly(2))
- ->method('isPossibleNumber')
- ->willReturnMap([
- ['+33102030405', null, true],
- ['invalid', null, false],
- ]);
- $this->phoneNumberUtil
- ->expects(self::never())
- ->method('parse');
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage('Mobile phone number is invalid (person: bob)');
- $creationDate = $this->getMockBuilder(\DateTime::class)->getMock();
- $organizationFactory->makePersonContactPoint(
- $organizationMemberCreationRequest,
- $creationDate,
- 1
- );
- }
- public function testMakePersonContactPointNoMobile(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makePersonContactPoint');
- $organizationMemberCreationRequest = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
- $organizationMemberCreationRequest->method('getPhone')->willReturn('+33102030405');
- $organizationMemberCreationRequest->method('getMobile')->willReturn(null);
- $this->phoneNumberUtil
- ->expects(self::once())
- ->method('isPossibleNumber')
- ->with('+33102030405')
- ->willReturn(true);
- $creationDate = $this->getMockBuilder(\DateTime::class)->getMock();
- $contactPoint = $organizationFactory->makePersonContactPoint(
- $organizationMemberCreationRequest,
- $creationDate,
- 1
- );
- $this->assertEquals(
- null,
- $contactPoint->getMobilPhone()
- );
- }
- public function testMakeSubdomain(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('makeSubdomain');
- $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
- $organizationCreationRequest->method('getSubdomain')->willReturn('subdomain');
- $subdomain = $organizationFactory->makeSubdomain($organizationCreationRequest);
- $this->assertEquals(
- 'subdomain',
- $subdomain->getSubdomain()
- );
- $this->assertTrue(
- $subdomain->isActive()
- );
- }
- public function testCreateTypo3Website(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('createTypo3Website');
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getId')->willReturn(123);
- $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock();
- $response->method('getStatusCode')->willReturn(Response::HTTP_OK);
- $response->method('getContent')->willReturn('{"root_uid": 456}');
- $this->typo3Service->expects(self::once())->method('createSite')->with(123)->willReturn($response);
- $organization->expects(self::once())->method('setCmsId')->with(456);
- $this->entityManager->expects(self::once())->method('persist')->with($organization);
- $this->entityManager->expects(self::once())->method('flush');
- $result = $organizationFactory->createTypo3Website($organization);
- $this->assertEquals(
- 456,
- $result
- );
- }
- public function testCreateTypo3WebsiteWithError(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('createTypo3Website');
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getId')->willReturn(123);
- $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock();
- $response->method('getStatusCode')->willReturn(Response::HTTP_FORBIDDEN);
- $response->method('getContent')->willReturn('');
- $this->typo3Service->expects(self::once())->method('createSite')->with(123)->willReturn($response);
- $this->logger
- ->expects(self::once())
- ->method('critical')
- ->with('/!\ A critical error happened while creating the Typo3 website');
- $result = $organizationFactory->createTypo3Website($organization);
- $this->assertNull($result);
- }
- public function testCreateTypo3WebsiteWithInvalidResponse(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('createTypo3Website');
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getId')->willReturn(123);
- $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock();
- $response->method('getStatusCode')->willReturn(Response::HTTP_OK);
- $response->method('getContent')->willReturn('<html lang="fr">Login page</html>');
- $this->typo3Service->expects(self::once())->method('createSite')->with(123)->willReturn($response);
- $this->logger
- ->expects(self::once())
- ->method('critical')
- ->with('/!\ A critical error happened while creating the Typo3 website');
- $result = $organizationFactory->createTypo3Website($organization);
- $this->assertNull($result);
- }
- public function testUpdateAdminassosDb(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('updateAdminassosDb');
- $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock();
- $response->method('getStatusCode')->willReturn(Response::HTTP_OK);
- $this->apiLegacyRequestService
- ->expects(self::once())
- ->method('post')
- ->with('/_internal/secure/organization/creation-event', ['organizationId' => 123])
- ->willReturn($response);
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getId')->willReturn(123);
- $organizationFactory->updateAdminassosDb($organization);
- }
- public function testUpdateAdminassosDbError(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('updateAdminassosDb');
- $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock();
- $response->method('getStatusCode')->willReturn(Response::HTTP_BAD_REQUEST);
- $response->method('getContent')->willReturn('some error');
- $this->apiLegacyRequestService
- ->expects(self::once())
- ->method('post')
- ->with('/_internal/secure/organization/creation-event', ['organizationId' => 123])
- ->willReturn($response);
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getId')->willReturn(123);
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage('An error happened while updating the adminassos database: some error');
- $organizationFactory->updateAdminassosDb($organization);
- }
- public function testNormalizeIdentificationField(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('normalizeIdentificationField');
- $this->assertEquals(
- 'c+est+une+phrase+normalisee+',
- $organizationFactory->normalizeIdentificationField("C'est une phrase normalisée.")
- );
- }
- public function testDelete(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('delete');
- $organizationDeletionRequest = $this->getMockBuilder(OrganizationDeletionRequest::class)->getMock();
- $organizationDeletionRequest->method('getOrganizationId')->willReturn(123);
- $parameters = $this->getMockBuilder(Parameters::class)->getMock();
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getId')->willReturn(123);
- $organization->method('getParameters')->willReturn($parameters);
- $this->organizationRepository
- ->expects(self::once())
- ->method('find')
- ->with(123)
- ->willReturn($organization);
- $this->entityManager->expects(self::once())->method('beginTransaction');
- $this->entityManager->expects(self::once())->method('flush');
- $this->entityManager->expects(self::once())->method('commit');
- $this->entityManager->expects(self::never())->method('rollback');
- $organizationFactory->expects(self::once())->method('deleteOrganizationAccesses')->with($organization);
- $this->entityManager->expects(self::exactly(2))->method('remove')->withConsecutive(
- [$parameters],
- [$organization]
- );
- $organizationFactory->expects(self::once())->method('deleteTypo3Website')->with($organization);
- $organizationFactory->expects(self::once())->method('switchDolibarrSocietyToProspect')->with($organization);
- $organizationFactory->expects(self::once())->method('deleteOrganizationFiles')->with($organization);
- $organizationFactory->expects(self::once())->method('deleteDirectoriesV1')->with($organization);
- $organizationFactory->expects(self::once())->method('deleteDirectories59')->with($organization);
- $organizationDeletionRequest
- ->expects(self::once())
- ->method('setStatus')
- ->with(OrganizationDeletionRequest::STATUS_OK);
- $result = $organizationFactory->delete($organizationDeletionRequest);
- $this->assertEquals(
- $organizationDeletionRequest,
- $result
- );
- }
- public function testDeleteWithRollback(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('delete');
- $organizationDeletionRequest = $this->getMockBuilder(OrganizationDeletionRequest::class)->getMock();
- $organizationDeletionRequest->method('getOrganizationId')->willReturn(123);
- $parameters = $this->getMockBuilder(Parameters::class)->getMock();
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getParameters')->willReturn($parameters);
- $this->organizationRepository
- ->expects(self::once())
- ->method('find')
- ->with(123)
- ->willReturn($organization);
- $this->entityManager->expects(self::once())->method('beginTransaction');
- $this->entityManager->expects(self::never())->method('flush');
- $this->entityManager->expects(self::never())->method('commit');
- $this->entityManager->expects(self::once())->method('rollback');
- $organizationFactory->expects(self::once())->method('deleteOrganizationAccesses')->with($organization);
- $this->entityManager->method('remove')->willThrowException(new \Exception('some error'));
- $organizationFactory->expects(self::never())->method('deleteTypo3Website');
- $organizationFactory->expects(self::never())->method('switchDolibarrSocietyToProspect');
- $organizationFactory->expects(self::never())->method('deleteOrganizationFiles');
- $organizationFactory->expects(self::never())->method('deleteDirectoriesV1');
- $organizationFactory->expects(self::never())->method('deleteDirectories59');
- $organizationDeletionRequest
- ->expects(self::never())
- ->method('setStatus');
- $this->logger
- ->expects(self::once())
- ->method('critical')
- ->with($this->callback(function ($arg) {
- return is_string($arg) && str_contains($arg, 'An error happened, operation cancelled') && str_contains($arg, 'some error');
- }));
- $this->expectException(\Exception::class);
- $organizationFactory->delete($organizationDeletionRequest);
- }
- public function testDeleteWithNonBlockingErrors(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('delete');
- $organizationDeletionRequest = $this->getMockBuilder(OrganizationDeletionRequest::class)->getMock();
- $organizationDeletionRequest->method('getOrganizationId')->willReturn(123);
- $parameters = $this->getMockBuilder(Parameters::class)->getMock();
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getId')->willReturn(123);
- $organization->method('getParameters')->willReturn($parameters);
- $this->organizationRepository
- ->expects(self::once())
- ->method('find')
- ->with(123)
- ->willReturn($organization);
- $this->entityManager->expects(self::once())->method('beginTransaction');
- $this->entityManager->expects(self::once())->method('flush');
- $this->entityManager->expects(self::once())->method('commit');
- $this->entityManager->expects(self::never())->method('rollback');
- $organizationFactory->expects(self::once())->method('deleteOrganizationAccesses')->with($organization);
- $this->entityManager->expects(self::exactly(2))->method('remove')->withConsecutive(
- [$parameters],
- [$organization]
- );
- $organizationFactory->expects(self::once())->method('deleteTypo3Website')->willThrowException(new \Exception('some error'));
- $organizationFactory->expects(self::once())->method('switchDolibarrSocietyToProspect')->willThrowException(new \Exception('some error'));
- $organizationFactory->expects(self::once())->method('deleteOrganizationFiles')->willThrowException(new \Exception('some error'));
- $organizationFactory->expects(self::once())->method('deleteDirectoriesV1')->willThrowException(new \Exception('some error'));
- $organizationFactory->expects(self::once())->method('deleteDirectories59')->willThrowException(new \Exception('some error'));
- $organizationDeletionRequest
- ->expects(self::once())
- ->method('setStatus')
- ->with(OrganizationDeletionRequest::STATUS_OK_WITH_ERRORS);
- $this->logger
- ->expects(self::exactly(5))
- ->method('critical')
- ->withConsecutive(
- ['An error happened while deleting the Typo3 website, please proceed manually.'],
- ['An error happened while updating the Dolibarr society, please proceed manually.'],
- ['An error happened while deleting the local directories, please proceed manually.'],
- ['An error happened while deleting the V1 directories, please proceed manually.'],
- ['An error happened while deleting the 5.9 directories, please proceed manually.'],
- );
- $result = $organizationFactory->delete($organizationDeletionRequest);
- $this->assertEquals(
- $organizationDeletionRequest,
- $result
- );
- }
- public function testDeleteOrganizationAccesses(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('deleteOrganizationAccesses');
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $access1 = $this->getMockBuilder(Access::class)->getMock();
- $access2 = $this->getMockBuilder(Access::class)->getMock();
- $access_other = $this->getMockBuilder(Access::class)->getMock();
- $person1 = $this->getMockBuilder(Person::class)->getMock();
- $person1->method('getAccesses')->willReturn(new ArrayCollection([$access1]));
- $access1->method('getPerson')->willReturn($person1);
- $person2 = $this->getMockBuilder(Person::class)->getMock();
- $person2->method('getAccesses')->willReturn(new ArrayCollection([$access2, $access_other]));
- $access2->method('getPerson')->willReturn($person2);
- $organization->method('getAccesses')->willReturn(new ArrayCollection([$access1, $access2]));
- $this->entityManager
- ->expects(self::exactly(3))
- ->method('remove')
- ->withConsecutive(
- [$person1],
- [$access1],
- [$access2],
- );
- $organizationFactory->deleteOrganizationAccesses($organization);
- }
- public function testSwitchDolibarrSocietyToProspect(): void
- {
- $organizationFactory = $this->getOrganizationFactoryMockFor('switchDolibarrSocietyToProspect');
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getId')->willReturn(123);
- $this->dolibarrApiService
- ->expects(self::once())
- ->method('switchSocietyToProspect')
- ->with(123);
- $organizationFactory->switchDolibarrSocietyToProspect($organization);
- }
- }
|