OrganizationFactoryTest.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Tests\Unit\Service\Organization;
  4. use App\ApiResources\Organization\OrganizationCreationRequest;
  5. use App\ApiResources\Organization\OrganizationMemberCreationRequest;
  6. use App\Entity\Access\Access;
  7. use App\Entity\Core\AddressPostal;
  8. use App\Entity\Core\ContactPoint;
  9. use App\Entity\Core\Country;
  10. use App\Entity\Education\Cycle;
  11. use App\Entity\Network\Network;
  12. use App\Entity\Network\NetworkOrganization;
  13. use App\Entity\Organization\Organization;
  14. use App\Entity\Organization\OrganizationAddressPostal;
  15. use App\Entity\Organization\Parameters;
  16. use App\Entity\Organization\Settings;
  17. use App\Entity\Organization\Subdomain;
  18. use App\Entity\Person\Person;
  19. use App\Entity\Person\PersonAddressPostal;
  20. use App\Enum\Core\ContactPointTypeEnum;
  21. use App\Enum\Education\CycleEnum;
  22. use App\Enum\Organization\AddressPostalOrganizationTypeEnum;
  23. use App\Enum\Organization\LegalEnum;
  24. use App\Enum\Organization\PrincipalTypeEnum;
  25. use App\Enum\Organization\SettingsProductEnum;
  26. use App\Enum\Person\AddressPostalPersonTypeEnum;
  27. use App\Enum\Person\GenderEnum;
  28. use App\Repository\Core\CountryRepository;
  29. use App\Repository\Organization\OrganizationRepository;
  30. use App\Repository\Person\PersonRepository;
  31. use App\Service\Dolibarr\DolibarrApiService;
  32. use App\Service\Organization\OrganizationFactory;
  33. use App\Service\Organization\Utils as OrganizationUtils;
  34. use App\Service\Typo3\BindFileService;
  35. use App\Service\Typo3\SubdomainService;
  36. use App\Service\Typo3\Typo3Service;
  37. use App\Service\Utils\DatesUtils;
  38. use Doctrine\ORM\EntityManagerInterface;
  39. use PHPUnit\Framework\MockObject\MockObject;
  40. use PHPUnit\Framework\TestCase;
  41. use Psr\Log\LoggerInterface;
  42. use Symfony\Component\HttpFoundation\Response;
  43. use Symfony\Contracts\HttpClient\ResponseInterface;
  44. class TestableOrganizationFactory extends OrganizationFactory {
  45. public function isExistingOrganization(OrganizationCreationRequest $organizationCreationRequest): bool
  46. {
  47. return parent::isExistingOrganization($organizationCreationRequest);
  48. }
  49. public function validateSubdomain(string $subdomainValue): void
  50. {
  51. parent::validateSubdomain($subdomainValue);
  52. }
  53. public function makeOrganizationWithRelations(
  54. OrganizationCreationRequest $organizationCreationRequest
  55. ): Organization {
  56. return parent::makeOrganizationWithRelations($organizationCreationRequest);
  57. }
  58. public function makeOrganization(OrganizationCreationRequest $organizationCreationRequest): Organization {
  59. return parent::makeOrganization($organizationCreationRequest);
  60. }
  61. public function makeParameters(OrganizationCreationRequest $organizationCreationRequest): Parameters {
  62. return parent::makeParameters($organizationCreationRequest);
  63. }
  64. public function makeSettings(OrganizationCreationRequest $organizationCreationRequest): Settings {
  65. return parent::makeSettings($organizationCreationRequest);
  66. }
  67. public function makePostalAddress(OrganizationCreationRequest $organizationCreationRequest): OrganizationAddressPostal {
  68. return parent::makePostalAddress($organizationCreationRequest);
  69. }
  70. public function makeContactPoint(OrganizationCreationRequest $organizationCreationRequest): ContactPoint {
  71. return parent::makeContactPoint($organizationCreationRequest);
  72. }
  73. public function makeNetworkOrganization(OrganizationCreationRequest $organizationCreationRequest): NetworkOrganization {
  74. return parent::makeNetworkOrganization($organizationCreationRequest);
  75. }
  76. public function makeAdminAccess(OrganizationCreationRequest $organizationCreationRequest): Access {
  77. return parent::makeAdminAccess($organizationCreationRequest);
  78. }
  79. public function makeCycles(): array {
  80. return parent::makeCycles();
  81. }
  82. public function makeAccess(int|OrganizationMemberCreationRequest $creationRequestData): Access {
  83. return parent::makeAccess($creationRequestData);
  84. }
  85. public function makePersonPostalAddress(OrganizationMemberCreationRequest $organizationMemberCreationRequest): PersonAddressPostal {
  86. return parent::makePersonPostalAddress($organizationMemberCreationRequest);
  87. }
  88. public function makePersonContactPoint(OrganizationMemberCreationRequest $organizationMemberCreationRequest): ContactPoint {
  89. return parent::makePersonContactPoint($organizationMemberCreationRequest);
  90. }
  91. public function makeSubdomain(OrganizationCreationRequest $organizationCreationRequest): Subdomain {
  92. return parent::makeSubdomain($organizationCreationRequest);
  93. }
  94. public function createTypo3Website(Organization $organization): ?int {
  95. return parent::createTypo3Website($organization);
  96. }
  97. }
  98. class OrganizationFactoryTest extends TestCase
  99. {
  100. private readonly MockObject | SubdomainService $subdomainService;
  101. private readonly MockObject | OrganizationRepository $organizationRepository;
  102. private readonly MockObject | CountryRepository $countryRepository;
  103. private readonly MockObject | OrganizationUtils $organizationUtils;
  104. private readonly MockObject | Typo3Service $typo3Service;
  105. private readonly MockObject | DolibarrApiService $dolibarrApiService;
  106. private readonly MockObject | EntityManagerInterface $entityManager;
  107. private readonly MockObject | PersonRepository $personRepository;
  108. private readonly MockObject | BindFileService $bindFileService;
  109. private readonly MockObject | LoggerInterface $logger;
  110. public function setUp(): void
  111. {
  112. $this->subdomainService = $this->getMockBuilder(SubdomainService::class)->disableOriginalConstructor()->getMock();
  113. $this->organizationRepository = $this->getMockBuilder(OrganizationRepository::class)->disableOriginalConstructor()->getMock();
  114. $this->countryRepository = $this->getMockBuilder(CountryRepository::class)->disableOriginalConstructor()->getMock();
  115. $this->organizationUtils = $this->getMockBuilder(OrganizationUtils::class)->disableOriginalConstructor()->getMock();
  116. $this->typo3Service = $this->getMockBuilder(Typo3Service::class)->disableOriginalConstructor()->getMock();
  117. $this->dolibarrApiService = $this->getMockBuilder(DolibarrApiService::class)->disableOriginalConstructor()->getMock();
  118. $this->entityManager = $this->getMockBuilder(EntityManagerInterface::class)->disableOriginalConstructor()->getMock();
  119. $this->personRepository = $this->getMockBuilder(PersonRepository::class)->disableOriginalConstructor()->getMock();
  120. $this->bindFileService = $this->getMockBuilder(BindFileService::class)->disableOriginalConstructor()->getMock();
  121. $this->logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
  122. }
  123. public function tearDown(): void
  124. {
  125. DatesUtils::clearFakeDatetime();
  126. }
  127. private function getOrganizationFactoryMockFor(string $methodName): TestableOrganizationFactory | MockObject
  128. {
  129. $organizationFactory = $this
  130. ->getMockBuilder(TestableOrganizationFactory::class)
  131. ->setConstructorArgs(
  132. [
  133. $this->subdomainService,
  134. $this->organizationRepository,
  135. $this->countryRepository,
  136. $this->organizationUtils,
  137. $this->typo3Service,
  138. $this->dolibarrApiService,
  139. $this->entityManager,
  140. $this->personRepository,
  141. $this->bindFileService
  142. ])
  143. ->setMethodsExcept(['setLoggerInterface', $methodName])
  144. ->getMock();
  145. $organizationFactory->setLoggerInterface($this->logger);
  146. return $organizationFactory;
  147. }
  148. public function testCreate(): void {
  149. $organizationFactory = $this->getOrganizationFactoryMockFor('create');
  150. $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
  151. $organizationCreationRequest->method('getName')->willReturn('foo');
  152. $organizationCreationRequest->method('getSubdomain')->willReturn('subdomain');
  153. $organizationCreationRequest->method('isClient')->willReturn(false);
  154. $organizationCreationRequest->method('getCreateWebsite')->willReturn(true);
  155. $this->entityManager->expects(self::once())->method('beginTransaction');
  156. $organizationFactory->expects(self::once())->method('isExistingOrganization')->willReturn(false);
  157. $organizationFactory->expects(self::once())->method('validateSubdomain')->with('subdomain');
  158. $organization = $this->getMockBuilder(Organization::class)->getMock();
  159. $organizationFactory
  160. ->expects(self::once())
  161. ->method('makeOrganizationWithRelations')
  162. ->with($organizationCreationRequest)
  163. ->willReturn($organization);
  164. $this->entityManager->expects(self::once())->method('persist')->with($organization);
  165. $this->entityManager->expects(self::once())->method('flush');
  166. $this->entityManager->expects(self::once())->method('commit');
  167. $this->dolibarrApiService
  168. ->expects(self::once())
  169. ->method('createSociety')
  170. ->with($organization, false)
  171. ->willReturn(456);
  172. $this->bindFileService
  173. ->expects(self::once())
  174. ->method('registerSubdomain')
  175. ->with('subdomain');
  176. $organizationFactory
  177. ->expects(self::once())
  178. ->method('createTypo3Website')
  179. ->with($organization);
  180. $this->logger
  181. ->method('info')
  182. ->withConsecutive(
  183. ["Start the creation of a new organization named 'foo'"],
  184. ["Subdomain is valid and available : 'subdomain'"],
  185. ["Organization created with all its relations"],
  186. ["New dolibarr structure created (uid : 456)"],
  187. ["Organization persisted in the DB"],
  188. ["Subdomain registered"],
  189. );
  190. $result = $organizationFactory->create($organizationCreationRequest);
  191. $this->assertEquals(
  192. $organization,
  193. $result
  194. );
  195. }
  196. public function testCreateWithRollback(): void {
  197. $organizationFactory = $this->getOrganizationFactoryMockFor('create');
  198. $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
  199. $organizationCreationRequest->method('getName')->willReturn('foo');
  200. $organizationCreationRequest->method('getSubdomain')->willReturn('subdomain');
  201. $organizationCreationRequest->method('isClient')->willReturn(false);
  202. $organizationCreationRequest->method('getCreateWebsite')->willReturn(true);
  203. $this->entityManager->expects(self::once())->method('beginTransaction');
  204. $organizationFactory->expects(self::once())->method('isExistingOrganization')->willReturn(false);
  205. $organizationFactory->expects(self::once())->method('validateSubdomain')->with('subdomain');
  206. $organization = $this->getMockBuilder(Organization::class)->getMock();
  207. $organizationFactory
  208. ->expects(self::once())
  209. ->method('makeOrganizationWithRelations')
  210. ->with($organizationCreationRequest)
  211. ->willReturn($organization);
  212. $this->entityManager->expects(self::once())->method('persist')->with($organization);
  213. $this->entityManager->expects(self::once())->method('flush')->willThrowException(new \RuntimeException('some error'));
  214. $this->entityManager->expects(self::once())->method('rollback');
  215. $this->dolibarrApiService
  216. ->expects(self::never())
  217. ->method('createSociety');
  218. $this->bindFileService
  219. ->expects(self::never())
  220. ->method('registerSubdomain');
  221. $organizationFactory
  222. ->expects(self::never())
  223. ->method('createTypo3Website');
  224. $this->logger
  225. ->method('info')
  226. ->withConsecutive(
  227. ["Start the creation of a new organization named 'foo'"],
  228. ["Subdomain is valid and available : 'subdomain'"],
  229. ["Organization created with all its relations"]
  230. );
  231. $this->logger
  232. ->method('critical')
  233. ->with(
  234. $this->matchesRegularExpression('/^An error happened, operation cancelled\nRuntimeException: some error.*/')
  235. );
  236. $this->expectException(\RuntimeException::class);
  237. $result = $organizationFactory->create($organizationCreationRequest);
  238. }
  239. public function testCreateWithExistingOrganization(): void {
  240. $organizationFactory = $this->getOrganizationFactoryMockFor('create');
  241. $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
  242. $organizationCreationRequest->method('getName')->willReturn('foo');
  243. $this->entityManager->expects(self::once())->method('beginTransaction');
  244. $organizationFactory->expects(self::once())->method('isExistingOrganization')->willReturn(true);
  245. $organizationFactory->expects(self::never())->method('validateSubdomain');
  246. $organizationFactory
  247. ->expects(self::never())
  248. ->method('makeOrganizationWithRelations');
  249. $this->entityManager->expects(self::never())->method('persist');
  250. $this->entityManager->expects(self::never())->method('flush');
  251. $this->entityManager->expects(self::once())->method('rollback');
  252. $this->dolibarrApiService
  253. ->expects(self::never())
  254. ->method('createSociety');
  255. $this->bindFileService
  256. ->expects(self::never())
  257. ->method('registerSubdomain');
  258. $organizationFactory
  259. ->expects(self::never())
  260. ->method('createTypo3Website');
  261. $this->logger
  262. ->method('info')
  263. ->withConsecutive(
  264. ["Start the creation of a new organization named 'foo'"],
  265. );
  266. $this->logger
  267. ->method('critical')
  268. ->with(
  269. $this->matchesRegularExpression("/^An error happened, operation cancelled\nRuntimeException: An organization named foo already exists.*/")
  270. );
  271. $this->expectException(\RuntimeException::class);
  272. $this->expectExceptionMessage("An organization named foo already exists");
  273. $result = $organizationFactory->create($organizationCreationRequest);
  274. }
  275. public function testCreateNoWebsiteAndIsClient(): void {
  276. $organizationFactory = $this->getOrganizationFactoryMockFor('create');
  277. $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
  278. $organizationCreationRequest->method('getName')->willReturn('foo');
  279. $organizationCreationRequest->method('getSubdomain')->willReturn('subdomain');
  280. $organizationCreationRequest->method('isClient')->willReturn(true);
  281. $organizationCreationRequest->method('getCreateWebsite')->willReturn(false);
  282. $organizationFactory->method('isExistingOrganization')->willReturn(false);
  283. $organization = $this->getMockBuilder(Organization::class)->getMock();
  284. $organizationFactory
  285. ->expects(self::once())
  286. ->method('makeOrganizationWithRelations')
  287. ->with($organizationCreationRequest)
  288. ->willReturn($organization);
  289. $this->dolibarrApiService
  290. ->method('createSociety')
  291. ->with($organization, true)
  292. ->willReturn(456);
  293. $organizationFactory
  294. ->expects(self::never())
  295. ->method('createTypo3Website');
  296. $this->logger
  297. ->expects(self::once())
  298. ->method('warning')
  299. ->with("Typo3 website creation was not required");
  300. $result = $organizationFactory->create($organizationCreationRequest);
  301. $this->assertEquals(
  302. $organization,
  303. $result
  304. );
  305. }
  306. public function testIsExistingOrganization(): void
  307. {
  308. $organizationFactory = $this->getOrganizationFactoryMockFor('isExistingOrganization');
  309. $organizationCreationRequest1 = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
  310. $organizationCreationRequest1->method('getName')->willReturn('foo');
  311. $organizationCreationRequest2 = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
  312. $organizationCreationRequest2->method('getName')->willReturn('bar');
  313. $this->organizationRepository->method('count')->willReturnMap([
  314. [['name' => 'foo'], 1],
  315. [['name' => 'bar'], 0],
  316. ]);
  317. $this->assertTrue($organizationFactory->isExistingOrganization($organizationCreationRequest1));
  318. $this->assertFalse($organizationFactory->isExistingOrganization($organizationCreationRequest2));
  319. }
  320. public function testValidateSubdomain(): void {
  321. $organizationFactory = $this->getOrganizationFactoryMockFor('validateSubdomain');
  322. $this->subdomainService->expects(self::once())->method('isValidSubdomain')->willReturn(true);
  323. $this->subdomainService->expects(self::once())->method('isReservedSubdomain')->willReturn(false);
  324. $this->subdomainService->expects(self::once())->method('isRegistered')->willReturn(false);
  325. $organizationFactory->validateSubdomain('foo');
  326. }
  327. public function testValidateSubdomainIsNotValid(): void {
  328. $organizationFactory = $this->getOrganizationFactoryMockFor('validateSubdomain');
  329. $this->subdomainService->method('isValidSubdomain')->willReturn(false);
  330. $this->subdomainService->method('isReservedSubdomain')->willReturn(false);
  331. $this->subdomainService->method('isRegistered')->willReturn(false);
  332. $this->expectException(\RuntimeException::class);
  333. $this->expectExceptionMessage("Not a valid subdomain : foo");
  334. $organizationFactory->validateSubdomain('foo');
  335. }
  336. public function testValidateSubdomainIsReserved(): void {
  337. $organizationFactory = $this->getOrganizationFactoryMockFor('validateSubdomain');
  338. $this->subdomainService->method('isValidSubdomain')->willReturn(true);
  339. $this->subdomainService->method('isReservedSubdomain')->willReturn(true);
  340. $this->subdomainService->method('isRegistered')->willReturn(false);
  341. $this->expectException(\RuntimeException::class);
  342. $this->expectExceptionMessage("This subdomain is not available : foo");
  343. $organizationFactory->validateSubdomain('foo');
  344. }
  345. public function testValidateSubdomainIsRegistered(): void {
  346. $organizationFactory = $this->getOrganizationFactoryMockFor('validateSubdomain');
  347. $this->subdomainService->method('isValidSubdomain')->willReturn(true);
  348. $this->subdomainService->method('isReservedSubdomain')->willReturn(false);
  349. $this->subdomainService->method('isRegistered')->willReturn(true);
  350. $this->expectException(\RuntimeException::class);
  351. $this->expectExceptionMessage("This subdomain is already registered : foo");
  352. $organizationFactory->validateSubdomain('foo');
  353. }
  354. public function testMakeOrganizationWithRelations()
  355. {
  356. $organizationFactory = $this->getOrganizationFactoryMockFor('makeOrganizationWithRelations');
  357. $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
  358. $organization = $this->getMockBuilder(Organization::class)->getMock();
  359. // Création de l'organisation
  360. $organizationFactory
  361. ->expects(self::once())
  362. ->method('makeOrganization')
  363. ->with($organizationCreationRequest)
  364. ->willReturn($organization);
  365. // Création des Parameters
  366. $parameters = $this->getMockBuilder(Parameters::class)->getMock();
  367. $organizationFactory
  368. ->expects(self::once())
  369. ->method('makeParameters')
  370. ->with($organizationCreationRequest)
  371. ->willReturn($parameters);
  372. $organization->expects(self::once())->method('setParameters')->with($parameters);
  373. // Création des Settings
  374. $settings = $this->getMockBuilder(Settings::class)->getMock();
  375. $organizationFactory
  376. ->expects(self::once())
  377. ->method('makeSettings')
  378. ->with($organizationCreationRequest)
  379. ->willReturn($settings);
  380. $organization->expects(self::once())->method('setSettings')->with($settings);
  381. // Création de l'adresse postale
  382. $organizationAddressPostal = $this->getMockBuilder(OrganizationAddressPostal::class)->getMock();
  383. $organizationFactory
  384. ->expects(self::once())
  385. ->method('makePostalAddress')
  386. ->with($organizationCreationRequest)
  387. ->willReturn($organizationAddressPostal);
  388. $organization->expects(self::once())->method('addOrganizationAddressPostal')->with($organizationAddressPostal);
  389. // Création du point de contact
  390. $contactPoint = $this->getMockBuilder(ContactPoint::class)->getMock();
  391. $organizationFactory
  392. ->expects(self::once())
  393. ->method('makeContactPoint')
  394. ->with($organizationCreationRequest)
  395. ->willReturn($contactPoint);
  396. $organization->expects(self::once())->method('addContactPoint')->with($contactPoint);
  397. // Rattachement au réseau
  398. $networkOrganization = $this->getMockBuilder(NetworkOrganization::class)->getMock();
  399. $organizationFactory
  400. ->expects(self::once())
  401. ->method('makeNetworkOrganization')
  402. ->with($organizationCreationRequest)
  403. ->willReturn($networkOrganization);
  404. $organization->expects(self::once())->method('addNetworkOrganization')->with($networkOrganization);
  405. // Créé l'admin
  406. $adminAccess = $this->getMockBuilder(Access::class)->getMock();
  407. $organizationFactory
  408. ->expects(self::once())
  409. ->method('makeAdminAccess')
  410. ->with($organizationCreationRequest)
  411. ->willReturn($adminAccess);
  412. // Le `$organization->expects(...)->method('addAccess')` est implémenté plus loin,
  413. // après la création du président et du directeur
  414. // Création des cycles
  415. $cycle1 = $this->getMockBuilder(Cycle::class)->getMock();
  416. $cycle2 = $this->getMockBuilder(Cycle::class)->getMock();
  417. $cycle3 = $this->getMockBuilder(Cycle::class)->getMock();
  418. $organizationFactory
  419. ->expects(self::once())
  420. ->method('makeCycles')
  421. ->willReturn([$cycle1, $cycle2, $cycle3]);
  422. $organization->expects(self::exactly(3))->method('addCycle')->withConsecutive([$cycle1], [$cycle2], [$cycle3]);
  423. // Création du président et du directeur
  424. $organizationMemberCreationRequest1 = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
  425. $organizationCreationRequest->method('getPresident')->willReturn($organizationMemberCreationRequest1);
  426. $organizationMemberCreationRequest2 = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
  427. $organizationCreationRequest->method('getDirector')->willReturn($organizationMemberCreationRequest2);
  428. $access1 = $this->getMockBuilder(Access::class)->getMock();
  429. $access2 = $this->getMockBuilder(Access::class)->getMock();
  430. $organizationFactory
  431. ->expects(self::exactly(2))
  432. ->method('makeAccess')
  433. ->willReturnMap([
  434. [$organizationMemberCreationRequest1, $access1],
  435. [$organizationMemberCreationRequest2, $access2]
  436. ]);
  437. $organization
  438. ->expects(self::exactly(3))
  439. ->method('addAccess')
  440. ->withConsecutive([$adminAccess], [$access1], [$access2]);
  441. // Création du sous-domaine
  442. $subdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  443. $organizationFactory
  444. ->expects(self::once())
  445. ->method('makeSubdomain')
  446. ->with($organizationCreationRequest)
  447. ->willReturn($subdomain);
  448. $subdomain->expects(self::once())->method('setOrganization')->with($organization);
  449. // Enregistrement du sous domaine dans Parameters (retrocompatibilité v1)
  450. $organization->method('getParameters')->willReturn($parameters);
  451. $organizationCreationRequest->method('getSubdomain')->willReturn('foo');
  452. $parameters->expects(self::once())->method('setSubDomain')->with('foo');
  453. $parameters->expects(self::once())->method('setOtherWebsite')->with('https://foo.opentalent.fr');
  454. $this->entityManager->expects(self::once())->method('persist')->with($parameters);
  455. $result = $organizationFactory->makeOrganizationWithRelations($organizationCreationRequest);
  456. $this->assertEquals(
  457. $result,
  458. $organization
  459. );
  460. }
  461. public function testMakeOrganizationWithRelationsNoPresidentNoDirector() {
  462. $organizationFactory = $this->getOrganizationFactoryMockFor('makeOrganizationWithRelations');
  463. $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
  464. $organization = $this->getMockBuilder(Organization::class)->getMock();
  465. // Création de l'organisation
  466. $organizationFactory
  467. ->expects(self::once())
  468. ->method('makeOrganization')
  469. ->with($organizationCreationRequest)
  470. ->willReturn($organization);
  471. $organizationCreationRequest->method('getPresident')->willReturn(null);
  472. $organizationCreationRequest->method('getDirector')->willReturn(null);
  473. // Un seul appel, pour l'adminAccess
  474. $organization
  475. ->expects(self::once())
  476. ->method('addAccess');
  477. $organizationFactory->makeOrganizationWithRelations($organizationCreationRequest);
  478. }
  479. public function testMakeOrganization()
  480. {
  481. $organizationFactory = $this->getOrganizationFactoryMockFor('makeOrganization');
  482. $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
  483. $organizationCreationRequest->method('getName')->willReturn('My Organization');
  484. $organizationCreationRequest->method('getLegalStatus')->willReturn(LegalEnum::ASSOCIATION_LAW_1901);
  485. $organizationCreationRequest->method('getPrincipalType')->willReturn(PrincipalTypeEnum::ARTISTIC_EDUCATION_ONLY);
  486. $this->entityManager->expects(self::once())->method('persist')->with($this->isInstanceOf(Organization::class));
  487. $organization = $organizationFactory->makeOrganization($organizationCreationRequest);
  488. $this->assertEquals(
  489. 'My Organization',
  490. $organization->getName()
  491. );
  492. $this->assertEquals(
  493. LegalEnum::ASSOCIATION_LAW_1901,
  494. $organization->getLegalStatus()
  495. );
  496. $this->assertEquals(
  497. PrincipalTypeEnum::ARTISTIC_EDUCATION_ONLY,
  498. $organization->getPrincipalType()
  499. );
  500. }
  501. public function testMakeParameters(): void
  502. {
  503. $organizationFactory = $this->getOrganizationFactoryMockFor('makeParameters');
  504. $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
  505. $this->entityManager->expects(self::once())->method('persist')->with($this->isInstanceOf(Parameters::class));
  506. $parameters = $organizationFactory->makeParameters($organizationCreationRequest);
  507. $this->assertInstanceOf(Parameters::class, $parameters);
  508. }
  509. public function testMakeSettings(): void
  510. {
  511. $organizationFactory = $this->getOrganizationFactoryMockFor('makeSettings');
  512. $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
  513. $organizationCreationRequest->method('getProduct')->willReturn(SettingsProductEnum::ARTIST_PREMIUM);
  514. $this->entityManager->expects(self::once())->method('persist')->with($this->isInstanceOf(Settings::class));
  515. $settings = $organizationFactory->makeSettings($organizationCreationRequest);
  516. $this->assertEquals(
  517. SettingsProductEnum::ARTIST_PREMIUM,
  518. $settings->getProduct()
  519. );
  520. }
  521. public function testMakePostalAddress(): void
  522. {
  523. $organizationFactory = $this->getOrganizationFactoryMockFor('makePostalAddress');
  524. $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
  525. $organizationCreationRequest->method('getStreetAddress1')->willReturn('address1');
  526. $organizationCreationRequest->method('getStreetAddress2')->willReturn('address2');
  527. $organizationCreationRequest->method('getStreetAddress3')->willReturn('address3');
  528. $organizationCreationRequest->method('getPostalCode')->willReturn('00000');
  529. $organizationCreationRequest->method('getCity')->willReturn('city');
  530. $organizationCreationRequest->method('getCountryId')->willReturn(1);
  531. $country = $this->getMockBuilder(Country::class)->getMock();
  532. $this->countryRepository->expects(self::once())->method('find')->with(1)->willReturn($country);
  533. $this
  534. ->entityManager
  535. ->expects(self::exactly(2))
  536. ->method('persist')
  537. ->withConsecutive(
  538. [$this->isInstanceOf(AddressPostal::class)],
  539. [$this->isInstanceOf(OrganizationAddressPostal::class)]
  540. );
  541. $organizationAddressPostal = $organizationFactory->makePostalAddress($organizationCreationRequest);
  542. $this->assertEquals(
  543. AddressPostalOrganizationTypeEnum::ADDRESS_HEAD_OFFICE,
  544. $organizationAddressPostal->getType()
  545. );
  546. $addressPostal = $organizationAddressPostal->getAddressPostal();
  547. $this->assertEquals(
  548. 'address1',
  549. $addressPostal->getStreetAddress()
  550. );
  551. $this->assertEquals(
  552. 'address2',
  553. $addressPostal->getStreetAddressSecond()
  554. );
  555. $this->assertEquals(
  556. 'address3',
  557. $addressPostal->getStreetAddressThird()
  558. );
  559. $this->assertEquals(
  560. '00000',
  561. $addressPostal->getPostalCode()
  562. );
  563. $this->assertEquals(
  564. 'city',
  565. $addressPostal->getAddressCity()
  566. );
  567. $this->assertEquals(
  568. $country,
  569. $addressPostal->getAddressCountry()
  570. );
  571. }
  572. public function testMakeContactPoint(): void
  573. {
  574. $organizationFactory = $this->getOrganizationFactoryMockFor('makeContactPoint');
  575. $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
  576. $organizationCreationRequest->method('getPhoneNumber')->willReturn('+33102030405');
  577. $organizationCreationRequest->method('getEmail')->willReturn('contact@domain.net');
  578. $this->entityManager->expects(self::once())->method('persist')->with($this->isInstanceOf(ContactPoint::class));
  579. $contactPoint = $organizationFactory->makeContactPoint($organizationCreationRequest);
  580. $this->assertEquals(
  581. 'contact@domain.net',
  582. $contactPoint->getEmail()
  583. );
  584. $this->assertEquals(
  585. '33',
  586. $contactPoint->getTelphone()->getCountryCode()
  587. );
  588. $this->assertEquals(
  589. '102030405',
  590. $contactPoint->getTelphone()->getNationalNumber()
  591. );
  592. }
  593. public function testMakeNetworkOrganization(): void {
  594. $organizationFactory = $this->getOrganizationFactoryMockFor('makeNetworkOrganization');
  595. DatesUtils::setFakeDatetime('2024-01-01');
  596. $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
  597. $organizationCreationRequest->method('getParentId')->willReturn(123);
  598. $this->entityManager->expects(self::once())->method('persist')->with($this->isInstanceOf(NetworkOrganization::class));
  599. $parent = $this->getMockBuilder(Organization::class)->getMock();
  600. $this->organizationRepository->expects(self::once())->method('find')->with(123)->willReturn($parent);
  601. $network = $this->getMockBuilder(Network::class)->getMock();
  602. $networkOrganization = $this->getMockBuilder(NetworkOrganization::class)->getMock();
  603. $networkOrganization->method('getNetwork')->willReturn($network);
  604. $this->organizationUtils
  605. ->expects(self::once())
  606. ->method('getActiveNetworkOrganization')
  607. ->with($parent)
  608. ->willReturn($networkOrganization);
  609. $networkOrganization = $organizationFactory->makeNetworkOrganization($organizationCreationRequest);
  610. $this->assertEquals(
  611. $parent,
  612. $networkOrganization->getParent()
  613. );
  614. $this->assertEquals(
  615. $network,
  616. $networkOrganization->getNetwork()
  617. );
  618. $this->assertEquals(
  619. '2024-01-01',
  620. $networkOrganization->getStartDate()->format('Y-m-d')
  621. );
  622. }
  623. public function testMakeNetworkOrganizationMissingParent(): void {
  624. $organizationFactory = $this->getOrganizationFactoryMockFor('makeNetworkOrganization');
  625. $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
  626. $organizationCreationRequest->method('getParentId')->willReturn(123);
  627. $this->expectException(\RuntimeException::class);
  628. $this->expectExceptionMessage('No parent organization found for id 123');
  629. $this->organizationRepository->expects(self::once())->method('find')->with(123)->willReturn(null);
  630. $organizationFactory->makeNetworkOrganization($organizationCreationRequest);
  631. }
  632. public function testMakeNetworkOrganizationMissingNetwork(): void {
  633. $organizationFactory = $this->getOrganizationFactoryMockFor('makeNetworkOrganization');
  634. $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
  635. $organizationCreationRequest->method('getParentId')->willReturn(123);
  636. $parent = $this->getMockBuilder(Organization::class)->getMock();
  637. $this->organizationRepository->expects(self::once())->method('find')->with(123)->willReturn($parent);
  638. $this->organizationUtils
  639. ->expects(self::once())
  640. ->method('getActiveNetworkOrganization')
  641. ->with($parent)
  642. ->willReturn(null);
  643. $this->expectException(\RuntimeException::class);
  644. $this->expectExceptionMessage('No network found for parent 123');
  645. $this->organizationRepository->expects(self::once())->method('find')->with(123)->willReturn($parent);
  646. $organizationFactory->makeNetworkOrganization($organizationCreationRequest);
  647. }
  648. public function testMakeAdminAccess()
  649. {
  650. $organizationFactory = $this->getOrganizationFactoryMockFor('makeAdminAccess');
  651. $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
  652. $organizationCreationRequest->method('getSubdomain')->willReturn('foo');
  653. $this
  654. ->entityManager
  655. ->expects(self::exactly(2))
  656. ->method('persist')
  657. ->withConsecutive(
  658. [$this->isInstanceOf(Person::class)],
  659. [$this->isInstanceOf(Access::class)]
  660. );
  661. $adminAccess = $organizationFactory->makeAdminAccess($organizationCreationRequest);
  662. $this->assertTrue(
  663. $adminAccess->getAdminAccess()
  664. );
  665. $this->assertEquals(
  666. 'adminfoo',
  667. $adminAccess->getPerson()->getUsername()
  668. );
  669. $this->assertEquals(
  670. 32,
  671. strlen($adminAccess->getPerson()->getPassword())
  672. );
  673. }
  674. public function testMakeCycles(): void
  675. {
  676. $organizationFactory = $this->getOrganizationFactoryMockFor('makeCycles');
  677. $cycles = $organizationFactory->makeCycles();
  678. $cyclesExpectedData = [
  679. ['Cycle initiation', 10, CycleEnum::INITIATION_CYCLE],
  680. ['Cycle 1', 20, CycleEnum::CYCLE_1],
  681. ['Cycle 2', 30, CycleEnum::CYCLE_2],
  682. ['Cycle 3', 40, CycleEnum::CYCLE_3],
  683. ['Cycle 4', 50, CycleEnum::CYCLE_4],
  684. ['Hors cycle', 60, CycleEnum::OUT_CYCLE],
  685. ];
  686. $i = 0;
  687. foreach ($cycles as $cycle) {
  688. $this->assertEquals(
  689. $cyclesExpectedData[$i][0],
  690. $cycle->getLabel()
  691. );
  692. $this->assertEquals(
  693. $cyclesExpectedData[$i][1],
  694. $cycle->getOrder()
  695. );
  696. $this->assertEquals(
  697. $cyclesExpectedData[$i][2],
  698. $cycle->getCycleEnum()
  699. );
  700. $this->assertFalse(
  701. $cycle->getIsSystem()
  702. );
  703. $i++;
  704. }
  705. }
  706. public function testMakeAccessNewPerson(): void
  707. {
  708. $organizationFactory = $this->getOrganizationFactoryMockFor('makeAccess');
  709. $organizationMemberCreationRequest = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
  710. $organizationMemberCreationRequest->method('getUsername')->willReturn('bob');
  711. $organizationMemberCreationRequest->method('getName')->willReturn('Bob');
  712. $organizationMemberCreationRequest->method('getGivenName')->willReturn('bOBBy');
  713. $organizationMemberCreationRequest->method('getGender')->willReturn(GenderEnum::MISTER);
  714. $personAddressPostal = $this->getMockBuilder(PersonAddressPostal::class)->getMock();
  715. $organizationFactory
  716. ->expects(self::once())
  717. ->method('makePersonPostalAddress')
  718. ->with($organizationMemberCreationRequest)
  719. ->willReturn($personAddressPostal);
  720. $contactPoint = $this->getMockBuilder(ContactPoint::class)->getMock();
  721. $organizationFactory
  722. ->expects(self::once())
  723. ->method('makePersonContactPoint')
  724. ->with($organizationMemberCreationRequest)
  725. ->willReturn($contactPoint);
  726. $this->entityManager
  727. ->expects(self::exactly(2))
  728. ->method('persist')
  729. ->withConsecutive(
  730. [$this->isInstanceOf(Person::class)],
  731. [$this->isInstanceOf(Access::class)]
  732. );
  733. $access = $organizationFactory->makeAccess($organizationMemberCreationRequest);
  734. $this->assertInstanceOf(Access::class, $access);
  735. $this->assertEquals(
  736. 'bob',
  737. $access->getPerson()->getUsername()
  738. );
  739. $this->assertTrue(
  740. strlen($access->getPerson()->getPassword()) === 32
  741. );
  742. $this->assertEquals(
  743. 'Bob',
  744. $access->getPerson()->getName()
  745. );
  746. $this->assertEquals(
  747. 'Bobby',
  748. $access->getPerson()->getGivenName()
  749. );
  750. $this->assertEquals(
  751. [$personAddressPostal],
  752. $access->getPerson()->getPersonAddressPostal()->toArray()
  753. );
  754. $this->assertEquals(
  755. [$contactPoint],
  756. $access->getPerson()->getContactPoints()->toArray()
  757. );
  758. }
  759. public function testMakeAccessExistingPerson(): void
  760. {
  761. $organizationFactory = $this->getOrganizationFactoryMockFor('makeAccess');
  762. $person = $this->getMockBuilder(Person::class)->getMock();
  763. $this->personRepository
  764. ->expects(self::once())
  765. ->method('find')
  766. ->with(123)
  767. ->willReturn($person);
  768. $this->entityManager
  769. ->expects(self::once())
  770. ->method('persist')
  771. ->with($this->isInstanceOf(Access::class));
  772. $access = $organizationFactory->makeAccess(123);
  773. $this->assertInstanceOf(Access::class, $access);
  774. $this->assertEquals(
  775. $person,
  776. $access->getPerson()
  777. );
  778. }
  779. public function testMakeAccessPostalAddress()
  780. {
  781. $organizationFactory = $this->getOrganizationFactoryMockFor('makePersonPostalAddress');
  782. $organizationMemberCreationRequest = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
  783. $organizationMemberCreationRequest->method('getStreetAddress1')->willReturn('Aaa');
  784. $organizationMemberCreationRequest->method('getStreetAddress2')->willReturn('Bbb');
  785. $organizationMemberCreationRequest->method('getStreetAddress3')->willReturn(null);
  786. $organizationMemberCreationRequest->method('getPostalCode')->willReturn('00000');
  787. $organizationMemberCreationRequest->method('getCity')->willReturn('city');
  788. $organizationMemberCreationRequest->method('getCountryId')->willReturn(123);
  789. $country = $this->getMockBuilder(Country::class)->getMock();
  790. $this->countryRepository
  791. ->expects(self::once())
  792. ->method('find')
  793. ->with(123)
  794. ->willReturn($country);
  795. $this->entityManager
  796. ->expects(self::exactly(2))
  797. ->method('persist')
  798. ->withConsecutive(
  799. [$this->isInstanceOf(AddressPostal::class)],
  800. [$this->isInstanceOf(PersonAddressPostal::class)]
  801. );
  802. $personPostalAddress = $organizationFactory->makePersonPostalAddress($organizationMemberCreationRequest);
  803. $this->assertEquals(
  804. AddressPostalPersonTypeEnum::ADDRESS_PRINCIPAL,
  805. $personPostalAddress->getType()
  806. );
  807. $postalAddress = $personPostalAddress->getAddressPostal();
  808. $this->assertEquals('Aaa', $postalAddress->getStreetAddress());
  809. $this->assertEquals('Bbb', $postalAddress->getStreetAddressSecond());
  810. $this->assertEquals(null, $postalAddress->getStreetAddressThird());
  811. $this->assertEquals('00000', $postalAddress->getPostalCode());
  812. $this->assertEquals('city', $postalAddress->getAddressCity());
  813. $this->assertEquals($country, $postalAddress->getAddressCountry());
  814. }
  815. public function testMakeAccessContactPoint(): void
  816. {
  817. $organizationFactory = $this->getOrganizationFactoryMockFor('makePersonContactPoint');
  818. $organizationMemberCreationRequest = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
  819. $organizationMemberCreationRequest->method('getPhone')->willReturn('+33102030405');
  820. $organizationMemberCreationRequest->method('getEmail')->willReturn('email@domain.com');
  821. $organizationMemberCreationRequest->method('getMobile')->willReturn('+33607080910');
  822. $this->entityManager
  823. ->expects(self::once())
  824. ->method('persist')
  825. ->with($this->isInstanceOf(ContactPoint::class));
  826. $contactPoint = $organizationFactory->makePersonContactPoint($organizationMemberCreationRequest);
  827. $this->assertEquals(
  828. ContactPointTypeEnum::PRINCIPAL,
  829. $contactPoint->getContactType()
  830. );
  831. $this->assertEquals(
  832. '33',
  833. $contactPoint->getTelphone()->getCountryCode()
  834. );
  835. $this->assertEquals(
  836. '102030405',
  837. $contactPoint->getTelphone()->getNationalNumber()
  838. );
  839. $this->assertEquals(
  840. '33',
  841. $contactPoint->getMobilPhone()->getCountryCode()
  842. );
  843. $this->assertEquals(
  844. '607080910',
  845. $contactPoint->getMobilPhone()->getNationalNumber()
  846. );
  847. $this->assertEquals(
  848. 'email@domain.com',
  849. $contactPoint->getEmail()
  850. );
  851. }
  852. public function testMakePersonContactPointNoMobile(): void {
  853. $organizationFactory = $this->getOrganizationFactoryMockFor('makePersonContactPoint');
  854. $organizationMemberCreationRequest = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
  855. $organizationMemberCreationRequest->method('getPhone')->willReturn('+33102030405');
  856. $organizationMemberCreationRequest->method('getMobile')->willReturn(null);
  857. $contactPoint = $organizationFactory->makePersonContactPoint($organizationMemberCreationRequest);
  858. $this->assertEquals(
  859. null,
  860. $contactPoint->getMobilPhone()
  861. );
  862. }
  863. public function testMakeSubdomain(): void
  864. {
  865. $organizationFactory = $this->getOrganizationFactoryMockFor('makeSubdomain');
  866. $organizationCreationRequest = $this->getMockBuilder(OrganizationCreationRequest::class)->getMock();
  867. $organizationCreationRequest->method('getSubdomain')->willReturn('subdomain');
  868. $this->entityManager
  869. ->expects(self::once())
  870. ->method('persist')
  871. ->with($this->isInstanceOf(Subdomain::class));
  872. $subdomain = $organizationFactory->makeSubdomain($organizationCreationRequest);
  873. $this->assertEquals(
  874. 'subdomain',
  875. $subdomain->getSubdomain()
  876. );
  877. $this->assertTrue(
  878. $subdomain->isActive()
  879. );
  880. }
  881. public function testCreateTypo3Website(): void {
  882. $organizationFactory = $this->getOrganizationFactoryMockFor('createTypo3Website');
  883. $organization = $this->getMockBuilder(Organization::class)->getMock();
  884. $organization->method('getId')->willReturn(123);
  885. $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock();
  886. $response->method('getStatusCode')->willReturn(Response::HTTP_OK);
  887. $response->method('getContent')->willReturn('456');
  888. $this->typo3Service->expects(self::once())->method('createSite')->with(123)->willReturn($response);
  889. $organization->expects(self::once())->method('setCmsId')->with(456);
  890. $this->entityManager->expects(self::once())->method('persist')->with($organization);
  891. $this->entityManager->expects(self::once())->method('flush');
  892. $result = $organizationFactory->createTypo3Website($organization);
  893. $this->assertEquals(
  894. 456,
  895. $result
  896. );
  897. }
  898. public function testCreateTypo3WebsiteWithError(): void {
  899. $organizationFactory = $this->getOrganizationFactoryMockFor('createTypo3Website');
  900. $organization = $this->getMockBuilder(Organization::class)->getMock();
  901. $organization->method('getId')->willReturn(123);
  902. $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock();
  903. $response->method('getStatusCode')->willReturn(Response::HTTP_FORBIDDEN);
  904. $response->method('getContent')->willReturn('');
  905. $this->typo3Service->expects(self::once())->method('createSite')->with(123)->willReturn($response);
  906. $this->logger
  907. ->expects(self::once())
  908. ->method('critical')
  909. ->with('/!\ A critical error happened while creating the Typo3 website');
  910. $result = $organizationFactory->createTypo3Website($organization);
  911. $this->assertNull($result);
  912. }
  913. public function testCreateTypo3WebsiteWithInvalidResponse(): void {
  914. $organizationFactory = $this->getOrganizationFactoryMockFor('createTypo3Website');
  915. $organization = $this->getMockBuilder(Organization::class)->getMock();
  916. $organization->method('getId')->willReturn(123);
  917. $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock();
  918. $response->method('getStatusCode')->willReturn(Response::HTTP_OK);
  919. $response->method('getContent')->willReturn('<html lang="fr">Login page</html>');
  920. $this->typo3Service->expects(self::once())->method('createSite')->with(123)->willReturn($response);
  921. $this->logger
  922. ->expects(self::once())
  923. ->method('critical')
  924. ->with('/!\ A critical error happened while creating the Typo3 website');
  925. $result = $organizationFactory->createTypo3Website($organization);
  926. $this->assertNull($result);
  927. }
  928. }