SubdomainServiceTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. <?php
  2. namespace App\Tests\Unit\Service\Typo3;
  3. use App\Entity\Access\Access;
  4. use App\Entity\Organization\Organization;
  5. use App\Entity\Organization\Parameters;
  6. use App\Entity\Organization\Subdomain;
  7. use App\Entity\Person\Person;
  8. use App\Message\Message\Mailer;
  9. use App\Message\Message\Typo3\Typo3Update;
  10. use App\Repository\Access\AccessRepository;
  11. use App\Repository\Organization\SubdomainRepository;
  12. use App\Service\Mailer\Model\SubdomainChangeModel;
  13. use App\Service\Organization\Utils as OrganizationUtils;
  14. use App\Service\Typo3\BindFileService;
  15. use App\Service\Typo3\SubdomainService;
  16. use Doctrine\Common\Collections\ArrayCollection;
  17. use Doctrine\ORM\EntityManagerInterface;
  18. use PHPUnit\Framework\MockObject\MockObject;
  19. use PHPUnit\Framework\TestCase;
  20. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  21. use Symfony\Component\Messenger\Envelope;
  22. use Symfony\Component\Messenger\MessageBusInterface;
  23. class TestableSubdomainService extends SubdomainService
  24. {
  25. public function setOrganizationActiveSubdomain(Subdomain $subdomain): Subdomain
  26. {
  27. return parent::setOrganizationActiveSubdomain($subdomain);
  28. }
  29. public function renameAdminUserToMatchSubdomain(Subdomain $subdomain): void
  30. {
  31. parent::renameAdminUserToMatchSubdomain($subdomain);
  32. }
  33. public function updateTypo3Website($organization): void
  34. {
  35. parent::updateTypo3Website($organization);
  36. }
  37. public function getMailModel(Subdomain $subdomain): SubdomainChangeModel
  38. {
  39. return parent::getMailModel($subdomain);
  40. }
  41. public function sendConfirmationEmail(Subdomain $subdomain): void
  42. {
  43. parent::sendConfirmationEmail($subdomain);
  44. }
  45. }
  46. class SubdomainServiceTest extends TestCase
  47. {
  48. private MockObject|SubdomainRepository $subdomainRepository;
  49. private MockObject|OrganizationUtils $organizationUtils;
  50. private MockObject|BindFileService $bindFileService;
  51. private MockObject|MessageBusInterface $messageBus;
  52. private MockObject|EntityManagerInterface $entityManager;
  53. private MockObject|AccessRepository $accessRepository;
  54. private MockObject|ParameterBagInterface $parameterBag;
  55. public function setUp(): void
  56. {
  57. $this->subdomainRepository = $this->getMockBuilder(SubdomainRepository::class)->disableOriginalConstructor()->getMock();
  58. $this->entityManager = $this->getMockBuilder(EntityManagerInterface::class)->disableOriginalConstructor()->getMock();
  59. $this->messageBus = $this->getMockBuilder(MessageBusInterface::class)->disableOriginalConstructor()->getMock();
  60. $this->organizationUtils = $this->getMockBuilder(OrganizationUtils::class)->disableOriginalConstructor()->getMock();
  61. $this->bindFileService = $this->getMockBuilder(BindFileService::class)->disableOriginalConstructor()->getMock();
  62. $this->accessRepository = $this->getMockBuilder(AccessRepository::class)->disableOriginalConstructor()->getMock();
  63. $this->parameterBag = $this->getMockBuilder(ParameterBagInterface::class)->disableOriginalConstructor()->getMock();
  64. }
  65. private function makeSubdomainServiceMockFor(string $methodName): MockObject|TestableSubdomainService
  66. {
  67. return $this->getMockBuilder(TestableSubdomainService::class)
  68. ->setConstructorArgs([
  69. $this->subdomainRepository,
  70. $this->entityManager,
  71. $this->messageBus,
  72. $this->organizationUtils,
  73. $this->bindFileService,
  74. $this->accessRepository,
  75. $this->parameterBag,
  76. ])
  77. ->setMethodsExcept([$methodName])
  78. ->getMock();
  79. }
  80. public function testGetSubdomain(): void {
  81. $subdomainService = $this->makeSubdomainServiceMockFor('getSubdomain');
  82. $subdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  83. $this->subdomainRepository->method('findOneBy')->with(['subdomain' => 'abc'])->willReturn($subdomain);
  84. $this->assertEquals(
  85. $subdomain,
  86. $subdomainService->getSubdomain('abc')
  87. );
  88. }
  89. /**
  90. * @see SubdomainService::canRegisterNewSubdomain()
  91. */
  92. public function testCanRegisterNewSubdomainTrue(): void
  93. {
  94. $subdomainService = $this->makeSubdomainServiceMockFor('canRegisterNewSubdomain');
  95. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  96. $organization->expects(self::once())->method('getSubdomains')->willReturn(new ArrayCollection([1, 2]));
  97. $this->assertTrue($subdomainService->canRegisterNewSubdomain($organization));
  98. }
  99. /**
  100. * @see SubdomainService::canRegisterNewSubdomain()
  101. */
  102. public function testCanRegisterNewSubdomainFalse(): void
  103. {
  104. $subdomainService = $this->makeSubdomainServiceMockFor('canRegisterNewSubdomain');
  105. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  106. $organization->expects(self::once())->method('getSubdomains')->willReturn(new ArrayCollection([1, 2, 3]));
  107. $this->assertFalse($subdomainService->canRegisterNewSubdomain($organization));
  108. }
  109. /**
  110. * @see SubdomainService::isValidSubdomain()
  111. */
  112. public function testIsValidSubdomain(): void
  113. {
  114. $subdomainService = $this->makeSubdomainServiceMockFor('isValidSubdomain');
  115. $this->assertTrue($subdomainService->isValidSubdomain('abcd'));
  116. $this->assertTrue($subdomainService->isValidSubdomain('abcdefgh'));
  117. $this->assertTrue($subdomainService->isValidSubdomain('abcd-efgh'));
  118. $this->assertTrue($subdomainService->isValidSubdomain('123'));
  119. $this->assertTrue($subdomainService->isValidSubdomain('a'));
  120. $this->assertFalse($subdomainService->isValidSubdomain('_abc'));
  121. $this->assertFalse($subdomainService->isValidSubdomain('abc-'));
  122. $this->assertFalse($subdomainService->isValidSubdomain(str_repeat('abcdef', 20)));
  123. }
  124. public function testIsReservedSubdomain(): void
  125. {
  126. $subdomainService = $this->makeSubdomainServiceMockFor('isReservedSubdomain');
  127. $this->parameterBag
  128. ->method('get')
  129. ->with('opentalent.subdomains')
  130. ->willReturn([
  131. 'reserved' => [
  132. 'abcd',
  133. 'abc\d+',
  134. ],
  135. ]);
  136. $this->assertTrue($subdomainService->isReservedSubdomain('abcd'));
  137. $this->assertTrue($subdomainService->isReservedSubdomain('abc123'));
  138. $this->assertFalse($subdomainService->isReservedSubdomain('abcde'));
  139. $this->assertFalse($subdomainService->isReservedSubdomain('abc'));
  140. $this->assertFalse($subdomainService->isReservedSubdomain('foo'));
  141. }
  142. public function testIsRegisteredSubdomain(): void
  143. {
  144. $subdomainService = $this->makeSubdomainServiceMockFor('isRegistered');
  145. $this->subdomainRepository->method('findBy')->willReturnCallback(function ($args) {
  146. if ($args === ['subdomain' => 'sub']) {
  147. $subdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  148. return [$subdomain];
  149. }
  150. return [];
  151. });
  152. $this->assertTrue($subdomainService->isRegistered('sub'));
  153. $this->assertFalse($subdomainService->isRegistered('foo'));
  154. }
  155. public function testAddNewSubdomain(): void
  156. {
  157. $subdomainService = $this->makeSubdomainServiceMockFor('addNewSubdomain');
  158. $parameters = $this->getMockBuilder(Parameters::class)->disableOriginalConstructor()->getMock();
  159. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  160. $organization->method('getParameters')->willReturn($parameters);
  161. $subdomainService->expects(self::once())->method('isValidSubdomain')->with('sub')->willReturn(true);
  162. $subdomainService->expects(self::once())->method('canRegisterNewSubdomain')->with($organization)->willReturn(true);
  163. $subdomainService->expects(self::once())->method('isReservedSubdomain')->with('sub')->willReturn(false);
  164. $subdomainService->expects(self::once())->method('isRegistered')->with('sub')->willReturn(false);
  165. $this->entityManager->expects(self::once())->method('persist');
  166. $this->entityManager->expects(self::once())->method('flush');
  167. $this->bindFileService->expects(self::once())->method('registerSubdomain')->with('sub');
  168. // Subdomain is not activated by default
  169. $subdomainService->expects(self::never())->method('activateSubdomain');
  170. $subdomain = $subdomainService->addNewSubdomain($organization, 'sub');
  171. $this->assertEquals($subdomain->getOrganization(), $organization);
  172. $this->assertEquals($subdomain->getSubdomain(), 'sub');
  173. $this->assertFalse($subdomain->isActive());
  174. }
  175. public function testAddNewSubdomainInvalid(): void
  176. {
  177. $subdomainService = $this->makeSubdomainServiceMockFor('addNewSubdomain');
  178. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  179. $subdomainService->expects(self::once())->method('isValidSubdomain')->with('_sub')->willReturn(false);
  180. $subdomainService->expects(self::never())->method('canRegisterNewSubdomain')->with($organization)->willReturn(true);
  181. $subdomainService->expects(self::never())->method('isReservedSubdomain')->with($organization)->willReturn(false);
  182. $subdomainService->expects(self::never())->method('isRegistered')->with('sub')->willReturn(false);
  183. $this->entityManager->expects(self::never())->method('persist');
  184. $this->entityManager->expects(self::never())->method('flush');
  185. $this->bindFileService->expects(self::never())->method('registerSubdomain')->with('_sub');
  186. $subdomainService->expects(self::never())->method('activateSubdomain');
  187. $this->expectException(\RuntimeException::class);
  188. $this->expectExceptionMessage('Not a valid subdomain');
  189. $subdomainService->addNewSubdomain($organization, '_sub');
  190. }
  191. public function testAddNewSubdomainMaxReached(): void
  192. {
  193. $subdomainService = $this->makeSubdomainServiceMockFor('addNewSubdomain');
  194. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  195. $subdomainService->expects(self::once())->method('isValidSubdomain')->with('_sub')->willReturn(true);
  196. $subdomainService->expects(self::once())->method('canRegisterNewSubdomain')->with($organization)->willReturn(false);
  197. $subdomainService->expects(self::never())->method('isReservedSubdomain')->with($organization)->willReturn(false);
  198. $subdomainService->expects(self::never())->method('isRegistered')->with('sub')->willReturn(false);
  199. $this->entityManager->expects(self::never())->method('persist');
  200. $this->entityManager->expects(self::never())->method('flush');
  201. $this->bindFileService->expects(self::never())->method('registerSubdomain')->with('_sub');
  202. $subdomainService->expects(self::never())->method('activateSubdomain');
  203. $this->expectException(\RuntimeException::class);
  204. $this->expectExceptionMessage('This organization can not register new subdomains');
  205. $subdomainService->addNewSubdomain($organization, '_sub');
  206. }
  207. public function testAddNewSubdomainIsReserved(): void
  208. {
  209. $subdomainService = $this->makeSubdomainServiceMockFor('addNewSubdomain');
  210. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  211. $subdomainService->expects(self::once())->method('isValidSubdomain')->with('_sub')->willReturn(true);
  212. $subdomainService->expects(self::once())->method('canRegisterNewSubdomain')->with($organization)->willReturn(true);
  213. $subdomainService->expects(self::once())->method('isReservedSubdomain')->with('_sub')->willReturn(true);
  214. $subdomainService->expects(self::never())->method('isRegistered')->with('sub')->willReturn(false);
  215. $this->entityManager->expects(self::never())->method('persist');
  216. $this->entityManager->expects(self::never())->method('flush');
  217. $this->bindFileService->expects(self::never())->method('registerSubdomain')->with('_sub');
  218. $subdomainService->expects(self::never())->method('activateSubdomain');
  219. $this->expectException(\RuntimeException::class);
  220. $this->expectExceptionMessage('This subdomain is not available');
  221. $subdomainService->addNewSubdomain($organization, '_sub');
  222. }
  223. public function testAddNewSubdomainExisting(): void
  224. {
  225. $subdomainService = $this->makeSubdomainServiceMockFor('addNewSubdomain');
  226. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  227. $subdomainService->expects(self::once())->method('isValidSubdomain')->with('sub')->willReturn(true);
  228. $subdomainService->expects(self::once())->method('canRegisterNewSubdomain')->with($organization)->willReturn(true);
  229. $subdomainService->expects(self::once())->method('isReservedSubdomain')->with('sub')->willReturn(false);
  230. $subdomainService->expects(self::once())->method('isRegistered')->with('sub')->willReturn(true);
  231. $this->entityManager->expects(self::never())->method('persist');
  232. $this->entityManager->expects(self::never())->method('flush');
  233. $this->bindFileService->expects(self::never())->method('registerSubdomain')->with('sub');
  234. $subdomainService->expects(self::never())->method('activateSubdomain');
  235. $this->expectException(\RuntimeException::class);
  236. $this->expectExceptionMessage('This subdomain is already registered');
  237. $subdomainService->addNewSubdomain($organization, 'sub');
  238. }
  239. public function testAddNewSubdomainAndActivate(): void
  240. {
  241. $subdomainService = $this->makeSubdomainServiceMockFor('addNewSubdomain');
  242. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  243. $subdomainService->expects(self::once())->method('isValidSubdomain')->with('sub')->willReturn(true);
  244. $subdomainService->expects(self::once())->method('canRegisterNewSubdomain')->with($organization)->willReturn(true);
  245. $subdomainService->expects(self::once())->method('isReservedSubdomain')->with('sub')->willReturn(false);
  246. $subdomainService->expects(self::once())->method('isRegistered')->with('sub')->willReturn(false);
  247. $subdomainService->expects(self::once())->method('activateSubdomain');
  248. $subdomainService->addNewSubdomain($organization, 'sub', true);
  249. }
  250. public function testActivateSubdomain(): void
  251. {
  252. $subdomainService = $this->makeSubdomainServiceMockFor('activateSubdomain');
  253. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  254. $previousActiveSubdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  255. $previousActiveSubdomain->method('getId')->willReturn(1);
  256. $previousActiveSubdomain->method('isActive')->willReturn(false);
  257. $this->subdomainRepository->method('getActiveSubdomainOf')->with($organization)->willReturn($previousActiveSubdomain);
  258. $initialSubdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  259. $initialSubdomain->method('getId')->willReturn(2);
  260. $initialSubdomain->method('isActive')->willReturn(false);
  261. $initialSubdomain->method('getOrganization')->willReturn($organization);
  262. $activatedSubdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  263. $activatedSubdomain->method('getId')->willReturn(2);
  264. $activatedSubdomain->method('isActive')->willReturn(true);
  265. $activatedSubdomain->method('getOrganization')->willReturn($organization);
  266. $subdomainService
  267. ->expects(self::once())
  268. ->method('setOrganizationActiveSubdomain')
  269. ->with($initialSubdomain)
  270. ->willReturn($activatedSubdomain);
  271. $subdomainService
  272. ->expects(self::once())
  273. ->method('renameAdminUserToMatchSubdomain')
  274. ->with($activatedSubdomain);
  275. $subdomainService
  276. ->expects(self::once())
  277. ->method('updateTypo3Website')
  278. ->with($organization);
  279. $subdomainService
  280. ->expects(self::once())
  281. ->method('sendConfirmationEmail')
  282. ->with($activatedSubdomain);
  283. $result = $subdomainService->activateSubdomain($initialSubdomain);
  284. $this->assertEquals($result, $activatedSubdomain);
  285. }
  286. public function testActivateSubdomainAlreadyActive(): void
  287. {
  288. $subdomainService = $this->makeSubdomainServiceMockFor('activateSubdomain');
  289. $organization = $this->getMockBuilder(Organization::class)->getMock();
  290. $subdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  291. $subdomain->method('getOrganization')->willReturn($organization);
  292. $subdomain->method('getId')->willReturn(1);
  293. $subdomain->method('isActive')->willReturn(true);
  294. $this->subdomainRepository->method('getActiveSubdomainOf')->with($organization)->willReturn($subdomain);
  295. $subdomainService->expects(self::never())->method('setOrganizationActiveSubdomain');
  296. $subdomainService->expects(self::never())->method('renameAdminUserToMatchSubdomain');
  297. $subdomainService->expects(self::never())->method('updateTypo3Website');
  298. $subdomainService->expects(self::never())->method('sendConfirmationEmail');
  299. $this->expectException(\RuntimeException::class);
  300. $this->expectExceptionMessage('The subdomain is already active');
  301. $subdomainService->activateSubdomain($subdomain);
  302. }
  303. public function testActivateSubdomainNotPersisted(): void
  304. {
  305. $subdomainService = $this->makeSubdomainServiceMockFor('activateSubdomain');
  306. $subdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  307. $subdomain->method('getId')->willReturn(null);
  308. $subdomain->method('isActive')->willReturn(false);
  309. $subdomainService->expects(self::never())->method('setOrganizationActiveSubdomain');
  310. $subdomainService->expects(self::never())->method('renameAdminUserToMatchSubdomain');
  311. $subdomainService->expects(self::never())->method('updateTypo3Website');
  312. $subdomainService->expects(self::never())->method('sendConfirmationEmail');
  313. // $parameters->expects(self::once())->method('setSubDomain')->with('sub');
  314. // $parameters->expects(self::once())->method('setOtherWebsite')->with('https://sub.opentalent.fr');
  315. $this->expectException(\RuntimeException::class);
  316. $this->expectExceptionMessage('Can not activate a non-persisted subdomain');
  317. $subdomainService->activateSubdomain($subdomain);
  318. }
  319. public function testSetOrganizationActiveSubdomain(): void
  320. {
  321. $subdomainService = $this->makeSubdomainServiceMockFor('setOrganizationActiveSubdomain');
  322. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  323. $subdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  324. $subdomain->method('getId')->willReturn(1);
  325. $subdomain->method('isActive')->willReturn(false);
  326. $otherSubdomain1 = $this->getMockBuilder(Subdomain::class)->getMock();
  327. $otherSubdomain1->method('getId')->willReturn(2);
  328. $otherSubdomain1->method('isActive')->willReturn(true);
  329. $otherSubdomain2 = $this->getMockBuilder(Subdomain::class)->getMock();
  330. $otherSubdomain2->method('getId')->willReturn(3);
  331. $otherSubdomain2->method('isActive')->willReturn(false);
  332. $organization->method('getSubdomains')->willReturn(new ArrayCollection([$otherSubdomain1, $otherSubdomain2]));
  333. $subdomain->method('getOrganization')->willReturn($organization);
  334. // The active subdomain is deactivated
  335. $otherSubdomain1->expects(self::once())->method('setActive')->with(false);
  336. // The inactive subdomain is not modified
  337. $otherSubdomain2->expects(self::never())->method('setActive');
  338. // The new subdomain is activated
  339. $subdomain->expects(self::once())->method('setActive')->with(true);
  340. $this->entityManager->expects(self::once())->method('flush');
  341. $this->entityManager->expects(self::once())->method('refresh')->with($organization);
  342. $result = $subdomainService->setOrganizationActiveSubdomain($subdomain);
  343. $this->assertEquals($result, $subdomain);
  344. }
  345. public function testRenameAdminUserToMatchSubdomain(): void
  346. {
  347. $subdomainService = $this->makeSubdomainServiceMockFor('renameAdminUserToMatchSubdomain');
  348. $organization = $this->getMockBuilder(Organization::class)->getMock();
  349. $person = $this->getMockBuilder(Person::class)->getMock();
  350. $access = $this->getMockBuilder(Access::class)->getMock();
  351. $subdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  352. $this->accessRepository
  353. ->method('findAdminAccess')
  354. ->with($organization)
  355. ->willReturn($access);
  356. $subdomain->method('getSubdomain')->willReturn('sub');
  357. $subdomain->method('getOrganization')->willReturn($organization);
  358. $access->method('getPerson')->willReturn($person);
  359. $person->expects(self::once())->method('setUsername')->with('adminsub');
  360. $this->entityManager->expects(self::once())->method('flush');
  361. $subdomainService->renameAdminUserToMatchSubdomain($subdomain);
  362. }
  363. public function testUpdateTypo3Website(): void
  364. {
  365. $subdomainService = $this->makeSubdomainServiceMockFor('updateTypo3Website');
  366. $organization = $this->getMockBuilder(Organization::class)->getMock();
  367. $organization->method('getId')->willReturn(1);
  368. $this->messageBus
  369. ->expects(self::once())
  370. ->method('dispatch')
  371. ->with(self::isInstanceOf(Typo3Update::class))
  372. ->willReturn(new Envelope(new Typo3Update(1)));
  373. $subdomainService->updateTypo3Website($organization);
  374. }
  375. public function testGetMailModel(): void
  376. {
  377. $subdomainService = $this->makeSubdomainServiceMockFor('getMailModel');
  378. $access = $this->getMockBuilder(Access::class)->getMock();
  379. $access->method('getId')->willReturn(1);
  380. $organization = $this->getMockBuilder(Organization::class)->getMock();
  381. $organization->method('getId')->willReturn(1);
  382. $subdomain = $this->getMockBuilder(Subdomain::class)->disableOriginalConstructor()->getMock();
  383. $subdomain->method('getOrganization')->willReturn($organization);
  384. $subdomain->method('getId')->willReturn(1);
  385. $this->accessRepository
  386. ->method('findAdminAccess')
  387. ->with($organization)
  388. ->willReturn($access);
  389. $this->organizationUtils
  390. ->expects(self::once())
  391. ->method('getOrganizationWebsite')
  392. ->with($organization)
  393. ->willReturn('mysubdomain.opentalent.fr');
  394. $mailerModel = $subdomainService->getMailModel($subdomain);
  395. $this->assertInstanceOf(SubdomainChangeModel::class, $mailerModel);
  396. $this->assertEquals(1, $mailerModel->getSenderId());
  397. $this->assertEquals(1, $mailerModel->getOrganizationId());
  398. $this->assertEquals(1, $mailerModel->getSubdomainId());
  399. $this->assertEquals('mysubdomain.opentalent.fr', $mailerModel->getUrl());
  400. }
  401. public function testSendConfirmationEmail(): void
  402. {
  403. $subdomainService = $this->makeSubdomainServiceMockFor('sendConfirmationEmail');
  404. $subdomain = $this->getMockBuilder(Subdomain::class)->getMock();
  405. $subdomainChangeModel = $this->getMockBuilder(SubdomainChangeModel::class)->getMock();
  406. $subdomainService->method('getMailModel')->willReturn($subdomainChangeModel);
  407. $this->messageBus
  408. ->expects(self::once())
  409. ->method('dispatch')
  410. ->with(self::isInstanceOf(Mailer::class))
  411. ->willReturn(new Envelope(new Mailer($subdomainChangeModel)));
  412. $subdomainService->sendConfirmationEmail($subdomain);
  413. }
  414. }