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