UtilsTest.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <?php
  2. /** @noinspection PhpUnhandledExceptionInspection */
  3. namespace App\Tests\Unit\Service\Organization;
  4. use App\Entity\Organization\Organization;
  5. use App\Entity\Organization\Parameters;
  6. use App\Entity\Organization\Settings;
  7. use App\Entity\Organization\Subdomain;
  8. use App\Enum\Organization\OrganizationIdsEnum;
  9. use App\Enum\Organization\SettingsProductEnum;
  10. use App\Repository\Network\NetworkOrganizationRepository;
  11. use App\Service\Network\Utils as NetworkUtils;
  12. use App\Service\Organization\Utils as OrganizationUtils;
  13. use App\Service\Utils\DatesUtils;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use PHPUnit\Framework\MockObject\MockObject;
  16. use PHPUnit\Framework\TestCase;
  17. class UtilsTest extends TestCase
  18. {
  19. private MockObject|NetworkOrganizationRepository $networkOrganizationRepository;
  20. private MockObject|NetworkUtils $networkUtils;
  21. public function setUp(): void
  22. {
  23. $this->networkOrganizationRepository = $this->getMockBuilder(NetworkOrganizationRepository::class)
  24. ->disableOriginalConstructor()
  25. ->getMock();
  26. $this->networkUtils = $this->getMockBuilder(NetworkUtils::class)->disableOriginalConstructor()->getMock();
  27. }
  28. public function getOrganizationUtilsMockFor(string $methodName): MockObject|OrganizationUtils
  29. {
  30. return $this->getMockBuilder(OrganizationUtils::class)
  31. ->setConstructorArgs([$this->networkOrganizationRepository, $this->networkUtils])
  32. ->setMethodsExcept([$methodName])
  33. ->getMock();
  34. }
  35. private function createOrganizationWithProductMock(SettingsProductEnum $product): Organization
  36. {
  37. $settings = $this->getMockBuilder(Settings::class)->getMock();
  38. $settings->method('getProduct')->willReturn($product);
  39. $organization = $this->getMockBuilder(Organization::class)->getMock();
  40. $organization->method('getSettings')->willReturn($settings);
  41. return $organization;
  42. }
  43. /**
  44. * @see OrganizationUtils::isStructure()
  45. */
  46. public function testIsStructure(): void
  47. {
  48. $organizationUtils = $this->getOrganizationUtilsMockFor('isStructure');
  49. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST);
  50. $this->assertTrue($organizationUtils->isStructure($organization));
  51. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST_PREMIUM);
  52. $this->assertTrue($organizationUtils->isStructure($organization));
  53. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL);
  54. $this->assertTrue($organizationUtils->isStructure($organization));
  55. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL_PREMIUM);
  56. $this->assertTrue($organizationUtils->isStructure($organization));
  57. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER);
  58. $this->assertFalse($organizationUtils->isStructure($organization));
  59. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER_PREMIUM);
  60. $this->assertFalse($organizationUtils->isStructure($organization));
  61. }
  62. /**
  63. * @see OrganizationUtils::isManager()
  64. */
  65. public function testIsManager(): void
  66. {
  67. $organizationUtils = $this->getOrganizationUtilsMockFor('isManager');
  68. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST);
  69. $this->assertFalse($organizationUtils->isManager($organization));
  70. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST_PREMIUM);
  71. $this->assertFalse($organizationUtils->isManager($organization));
  72. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL);
  73. $this->assertFalse($organizationUtils->isManager($organization));
  74. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL_PREMIUM);
  75. $this->assertFalse($organizationUtils->isManager($organization));
  76. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER);
  77. $this->assertTrue($organizationUtils->isManager($organization));
  78. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER_PREMIUM);
  79. $this->assertFalse($organizationUtils->isManager($organization));
  80. }
  81. /**
  82. * @see OrganizationUtils::is2iosOrganization()
  83. */
  84. public function testIsOrganizationIs2ios(): void
  85. {
  86. $organizationUtils = $this->getOrganizationUtilsMockFor('is2iosOrganization');
  87. $organization = $this->getMockBuilder(Organization::class)->getMock();
  88. $organizationUtils->expects(self::once())->method('isOrganizationIdEqualTo')->with($organization, OrganizationIdsEnum::_2IOS);
  89. $organizationUtils->is2iosOrganization($organization);
  90. }
  91. /**
  92. * @see OrganizationUtils::isCMF()
  93. */
  94. public function testIsCMF(): void
  95. {
  96. $organizationUtils = $this->getOrganizationUtilsMockFor('isCMF');
  97. $organization = $this->getMockBuilder(Organization::class)->getMock();
  98. $organizationUtils->expects(self::once())->method('isOrganizationIdEqualTo')->with($organization, OrganizationIdsEnum::CMF);
  99. $organizationUtils->isCMF($organization);
  100. }
  101. /**
  102. * @see OrganizationUtils::is2iosOrganization()
  103. */
  104. public function testIsOrganizationIdEqualTo(): void
  105. {
  106. $organizationUtils = $this->getOrganizationUtilsMockFor('isOrganizationIdEqualTo');
  107. $organization = $this->getMockBuilder(Organization::class)->getMock();
  108. $organization->method('getId')->willReturnOnConsecutiveCalls(123, OrganizationIdsEnum::_2IOS->value);
  109. $this->assertFalse($organizationUtils->isOrganizationIdEqualTo($organization, OrganizationIdsEnum::_2IOS));
  110. $this->assertTrue($organizationUtils->isOrganizationIdEqualTo($organization, OrganizationIdsEnum::_2IOS));
  111. }
  112. /**
  113. * @see OrganizationUtils::getOrganizationCurrentActivityYear()
  114. */
  115. public function testGetOrganizationCurrentActivityYear(): void
  116. {
  117. $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationCurrentActivityYear');
  118. $parameters = $this->getMockBuilder(Parameters::class)->getMock();
  119. $parameters->method('getMusicalDate')->willReturnOnConsecutiveCalls(
  120. null, // default should be '2020-08-31'
  121. new \DateTime('2020-10-01')
  122. );
  123. $organization = $this->getMockBuilder(Organization::class)->getMock();
  124. $organization->method('getParameters')->willReturn($parameters);
  125. DatesUtils::setFakeDatetime('2020-03-01');
  126. $this->assertEquals(
  127. 2019,
  128. $organizationUtils->getOrganizationCurrentActivityYear($organization)
  129. );
  130. DatesUtils::setFakeDatetime('2020-11-01');
  131. $this->assertEquals(
  132. 2020,
  133. $organizationUtils->getOrganizationCurrentActivityYear($organization)
  134. );
  135. }
  136. /**
  137. * @see OrganizationUtils::getActivityPeriodsSwitchYear()
  138. */
  139. public function testGetActivityPeriodsSwitchYear(): void
  140. {
  141. $organizationUtils = $this->getOrganizationUtilsMockFor('getActivityPeriodsSwitchYear');
  142. $parameters = $this->getMockBuilder(Parameters::class)->getMock();
  143. $parameters->method('getMusicalDate')->willReturn(new \DateTime('2020-09-05'));
  144. $organization = $this->getMockBuilder(Organization::class)->getMock();
  145. $organization->method('getParameters')->willReturn($parameters);
  146. $periods = $organizationUtils->getActivityPeriodsSwitchYear($organization, 2022);
  147. $this->assertEquals('2022-09-05', $periods['dateStart']);
  148. $this->assertEquals('2023-09-04', $periods['dateEnd']);
  149. }
  150. /**
  151. * @see OrganizationUtils::getActivityPeriodsSwitchYear()
  152. */
  153. public function testGetActivityPeriodsSwitchYearNoMusicalDate(): void
  154. {
  155. $organizationUtils = $this->getOrganizationUtilsMockFor('getActivityPeriodsSwitchYear');
  156. $parameters = $this->getMockBuilder(Parameters::class)->getMock();
  157. $parameters->method('getMusicalDate')->willReturn(null);
  158. $organization = $this->getMockBuilder(Organization::class)->getMock();
  159. $organization->method('getParameters')->willReturn($parameters);
  160. $periods = $organizationUtils->getActivityPeriodsSwitchYear($organization, 2022);
  161. $this->assertEquals('2022-09-01', $periods['dateStart']);
  162. $this->assertEquals('2023-08-31', $periods['dateEnd']);
  163. }
  164. /**
  165. * @see OrganizationUtils::getActivityYearSwitchDate()
  166. */
  167. public function testGetActivityYearSwitchDate(): void
  168. {
  169. $organizationUtils = $this->getOrganizationUtilsMockFor('getActivityYearSwitchDate');
  170. $parameters = $this->getMockBuilder(Parameters::class)->getMock();
  171. $parameters->method('getMusicalDate')->willReturn(new \DateTime('2020-09-05'));
  172. $organization = $this->getMockBuilder(Organization::class)->getMock();
  173. $organization->method('getParameters')->willReturn($parameters);
  174. $this->assertEquals(2022, $organizationUtils->getActivityYearSwitchDate($organization, new \DateTime('2022-09-10')));
  175. $this->assertEquals(2021, $organizationUtils->getActivityYearSwitchDate($organization, new \DateTime('2022-09-02')));
  176. }
  177. /**
  178. * @see OrganizationUtils::getActivityYearSwitchDate()
  179. */
  180. public function testGetActivityYearSwitchDateNoMusicalDate(): void
  181. {
  182. $organizationUtils = $this->getOrganizationUtilsMockFor('getActivityYearSwitchDate');
  183. $parameters = $this->getMockBuilder(Parameters::class)->getMock();
  184. $parameters->method('getMusicalDate')->willReturn(null);
  185. $organization = $this->getMockBuilder(Organization::class)->getMock();
  186. $organization->method('getParameters')->willReturn($parameters);
  187. $this->assertEquals(2021, $organizationUtils->getActivityYearSwitchDate($organization, new \DateTime('2022-08-01')));
  188. $this->assertEquals(2022, $organizationUtils->getActivityYearSwitchDate($organization, new \DateTime('2022-09-02')));
  189. }
  190. /**
  191. * @see OrganizationUtils::getOrganizationActiveSubdomain()
  192. */
  193. public function testGetOrganizationActiveSubdomain(): void
  194. {
  195. $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationActiveSubdomain');
  196. $subdomain1 = $this->getMockBuilder(Subdomain::class)->getMock();
  197. $subdomain1->method('isActive')->willReturn(false);
  198. $subdomain2 = $this->getMockBuilder(Subdomain::class)->getMock();
  199. $subdomain2->method('isActive')->willReturn(false);
  200. $subdomain3 = $this->getMockBuilder(Subdomain::class)->getMock();
  201. $subdomain3->method('isActive')->willReturn(true);
  202. $subdomain3->method('getSubdomain')->willReturn('foo');
  203. $organization = $this->getMockBuilder(Organization::class)->getMock();
  204. $organization->method('getSubdomains')->willReturn(new ArrayCollection([$subdomain1, $subdomain2, $subdomain3]));
  205. $this->assertEquals('foo', $organizationUtils->getOrganizationActiveSubdomain($organization));
  206. }
  207. /**
  208. * @see OrganizationUtils::getOrganizationActiveSubdomain()
  209. */
  210. public function testGetOrganizationActiveSubdomainNone(): void
  211. {
  212. $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationActiveSubdomain');
  213. $subdomain1 = $this->getMockBuilder(Subdomain::class)->getMock();
  214. $subdomain1->method('isActive')->willReturn(false);
  215. $organization = $this->getMockBuilder(Organization::class)->getMock();
  216. $organization->method('getSubdomains')->willReturn(new ArrayCollection([$subdomain1]));
  217. $this->assertEquals(null, $organizationUtils->getOrganizationActiveSubdomain($organization));
  218. }
  219. /**
  220. * @see OrganizationUtils::getOrganizationWebsite()
  221. */
  222. public function testOrganizationWebsite(): void
  223. {
  224. $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationWebsite');
  225. $parameters = $this->getMockBuilder(Parameters::class)->getMock();
  226. $parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
  227. $parameters->method('getCustomDomain')->willReturn(null);
  228. $organization = $this->getMockBuilder(Organization::class)->getMock();
  229. $organization->method('getParameters')->willReturn($parameters);
  230. $organizationUtils->method('getOrganizationActiveSubdomain')->with($organization)->willReturn('foo');
  231. $this->assertEquals('https://foo.opentalent.fr', $organizationUtils->getOrganizationWebsite($organization));
  232. }
  233. /**
  234. * @see OrganizationUtils::getOrganizationWebsite()
  235. */
  236. public function testOrganizationWebsiteDeactivatedWithOther(): void
  237. {
  238. $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationWebsite');
  239. $parameters = $this->getMockBuilder(Parameters::class)->getMock();
  240. $parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(true);
  241. $parameters->method('getWebsite')->willReturn('foo.net');
  242. $organization = $this->getMockBuilder(Organization::class)->getMock();
  243. $organization->method('getParameters')->willReturn($parameters);
  244. $this->assertEquals('https://foo.net', $organizationUtils->getOrganizationWebsite($organization));
  245. }
  246. /**
  247. * @see OrganizationUtils::getOrganizationWebsite()
  248. */
  249. public function testOrganizationWebsiteDeactivatedNoOther(): void
  250. {
  251. $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationWebsite');
  252. $parameters = $this->getMockBuilder(Parameters::class)->getMock();
  253. $parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(true);
  254. $parameters->method('getWebsite')->willReturn(null);
  255. $organization = $this->getMockBuilder(Organization::class)->getMock();
  256. $organization->method('getParameters')->willReturn($parameters);
  257. $this->assertEquals(null, $organizationUtils->getOrganizationWebsite($organization));
  258. }
  259. /**
  260. * @see OrganizationUtils::getOrganizationWebsite()
  261. */
  262. public function testOrganizationWebsiteWithCustom(): void
  263. {
  264. $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationWebsite');
  265. $parameters = $this->getMockBuilder(Parameters::class)->getMock();
  266. $parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
  267. $parameters->method('getCustomDomain')->willReturn('bar.net');
  268. $organization = $this->getMockBuilder(Organization::class)->getMock();
  269. $organization->method('getParameters')->willReturn($parameters);
  270. $this->assertEquals('https://bar.net', $organizationUtils->getOrganizationWebsite($organization));
  271. }
  272. /**
  273. * @see OrganizationUtils::getOrganizationWebsite()
  274. */
  275. public function testOrganizationWebsiteNoSubdomains(): void
  276. {
  277. $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationWebsite');
  278. $parameters = $this->getMockBuilder(Parameters::class)->getMock();
  279. $parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
  280. $parameters->method('getCustomDomain')->willReturn(null);
  281. $organization = $this->getMockBuilder(Organization::class)->getMock();
  282. $organization->method('getParameters')->willReturn($parameters);
  283. $organizationUtils->method('getOrganizationActiveSubdomain')->with($organization)->willReturn(null);
  284. $this->assertEquals(null, $organizationUtils->getOrganizationWebsite($organization));
  285. }
  286. /**
  287. * @see Utils::isLastParentAndCMF()
  288. */
  289. public function testIsLastParentAndCMF(): void
  290. {
  291. $organizationUtils = $this->getOrganizationUtilsMockFor('isLastParentAndCMF');
  292. $organization1 = $this->getMockBuilder(Organization::class)->getMock();
  293. $organization2 = $this->getMockBuilder(Organization::class)->getMock();
  294. $organization3 = $this->getMockBuilder(Organization::class)->getMock();
  295. $organization4 = $this->getMockBuilder(Organization::class)->getMock();
  296. $this->networkOrganizationRepository
  297. ->method('isLastParent')
  298. ->willReturnMap([
  299. [$organization1, true],
  300. [$organization2, true],
  301. [$organization3, false],
  302. [$organization4, false],
  303. ]);
  304. $this->networkUtils
  305. ->method('isCMF')
  306. ->willReturnMap([
  307. [$organization1, true],
  308. [$organization2, false],
  309. [$organization3, true],
  310. [$organization4, false],
  311. ]);
  312. $this->assertTrue($organizationUtils->isLastParentAndCMF($organization1));
  313. $this->assertFalse($organizationUtils->isLastParentAndCMF($organization2));
  314. $this->assertFalse($organizationUtils->isLastParentAndCMF($organization3));
  315. $this->assertFalse($organizationUtils->isLastParentAndCMF($organization4));
  316. }
  317. /**
  318. * @see Utils::isStructureAndCMF()
  319. */
  320. public function testIsStructureAndCMF(): void
  321. {
  322. $organizationUtils = $this->getOrganizationUtilsMockFor('isStructureAndCMF');
  323. $organization1 = $this->getMockBuilder(Organization::class)->getMock();
  324. $organization2 = $this->getMockBuilder(Organization::class)->getMock();
  325. $organization3 = $this->getMockBuilder(Organization::class)->getMock();
  326. $organization4 = $this->getMockBuilder(Organization::class)->getMock();
  327. $organizationUtils
  328. ->method('isStructure')
  329. ->willReturnMap([
  330. [$organization1, true],
  331. [$organization2, false],
  332. [$organization3, true],
  333. [$organization4, false],
  334. ]);
  335. $this->networkUtils
  336. ->method('isCMF')
  337. ->with($organization1)
  338. ->willReturnMap([
  339. [$organization1, true],
  340. [$organization2, false],
  341. [$organization3, false],
  342. [$organization4, true],
  343. ]);
  344. $this->assertTrue($organizationUtils->isStructureAndCMF($organization1));
  345. $this->assertFalse($organizationUtils->isStructureAndCMF($organization2));
  346. $this->assertFalse($organizationUtils->isStructureAndCMF($organization3));
  347. $this->assertFalse($organizationUtils->isStructureAndCMF($organization4));
  348. }
  349. /**
  350. * @see Utils::isManagerAndCMF()
  351. */
  352. public function testIsManagerAndCMF(): void
  353. {
  354. $organizationUtils = $this->getOrganizationUtilsMockFor('isManagerAndCMF');
  355. $organization1 = $this->getMockBuilder(Organization::class)->getMock();
  356. $organization2 = $this->getMockBuilder(Organization::class)->getMock();
  357. $organization3 = $this->getMockBuilder(Organization::class)->getMock();
  358. $organization4 = $this->getMockBuilder(Organization::class)->getMock();
  359. $organizationUtils
  360. ->method('isManager')
  361. ->willReturnMap([
  362. [$organization1, true],
  363. [$organization2, false],
  364. [$organization3, true],
  365. [$organization4, false],
  366. ]);
  367. $this->networkUtils
  368. ->method('isCMF')
  369. ->willReturnMap([
  370. [$organization1, true],
  371. [$organization2, false],
  372. [$organization3, false],
  373. [$organization4, true],
  374. ]);
  375. $this->assertTrue($organizationUtils->isManagerAndCMF($organization1));
  376. $this->assertFalse($organizationUtils->isManagerAndCMF($organization2));
  377. $this->assertFalse($organizationUtils->isManagerAndCMF($organization3));
  378. $this->assertFalse($organizationUtils->isManagerAndCMF($organization4));
  379. }
  380. /**
  381. * @see Utils::isManagerAndNotLastParentAndCMF()
  382. */
  383. public function testIsManagerAndLastParentAndCMF(): void
  384. {
  385. $organizationUtils = $this->getOrganizationUtilsMockFor('isManagerAndLastParentAndCMF');
  386. $organization1 = $this->getMockBuilder(Organization::class)->getMock();
  387. $organization2 = $this->getMockBuilder(Organization::class)->getMock();
  388. $organization3 = $this->getMockBuilder(Organization::class)->getMock();
  389. $organization4 = $this->getMockBuilder(Organization::class)->getMock();
  390. $organizationUtils
  391. ->method('isManager')
  392. ->willReturnMap([
  393. [$organization1, true],
  394. [$organization2, false],
  395. [$organization3, true],
  396. [$organization4, false],
  397. ]);
  398. $organizationUtils
  399. ->method('isLastParentAndCMF')
  400. ->willReturnMap([
  401. [$organization1, true],
  402. [$organization2, false],
  403. [$organization3, false],
  404. [$organization4, true],
  405. ]);
  406. $this->assertTrue($organizationUtils->isManagerAndLastParentAndCMF($organization1));
  407. $this->assertFalse($organizationUtils->isManagerAndLastParentAndCMF($organization2));
  408. $this->assertFalse($organizationUtils->isManagerAndLastParentAndCMF($organization3));
  409. $this->assertFalse($organizationUtils->isManagerAndLastParentAndCMF($organization4));
  410. }
  411. /**
  412. * @see Utils::isManagerAndNotLastParentAndCMF()
  413. */
  414. public function testIsManagerAndNotLastParentAndCMF(): void
  415. {
  416. $organizationUtils = $this->getOrganizationUtilsMockFor('isManagerAndNotLastParentAndCMF');
  417. $organization1 = $this->getMockBuilder(Organization::class)->getMock();
  418. $organization2 = $this->getMockBuilder(Organization::class)->getMock();
  419. $organization3 = $this->getMockBuilder(Organization::class)->getMock();
  420. $organization4 = $this->getMockBuilder(Organization::class)->getMock();
  421. $organizationUtils
  422. ->method('isManager')
  423. ->willReturnMap([
  424. [$organization1, true],
  425. [$organization2, false],
  426. [$organization3, true],
  427. [$organization4, true],
  428. ]);
  429. $this->networkOrganizationRepository
  430. ->method('isLastParent')
  431. ->willReturnMap([
  432. [$organization1, false],
  433. [$organization2, false],
  434. [$organization3, true],
  435. [$organization4, false],
  436. ]);
  437. $this->networkUtils
  438. ->method('isCMF')
  439. ->willReturnMap([
  440. [$organization1, true],
  441. [$organization2, true],
  442. [$organization3, true],
  443. [$organization4, false],
  444. ]);
  445. $this->assertTrue($organizationUtils->isManagerAndNotLastParentAndCMF($organization1));
  446. $this->assertFalse($organizationUtils->isManagerAndNotLastParentAndCMF($organization2));
  447. $this->assertFalse($organizationUtils->isManagerAndNotLastParentAndCMF($organization3));
  448. $this->assertFalse($organizationUtils->isManagerAndNotLastParentAndCMF($organization4));
  449. }
  450. /**
  451. * @see OrganizationUtils::isSchool()
  452. */
  453. public function testIsSchool(): void
  454. {
  455. $organizationUtils = $this->getOrganizationUtilsMockFor('isSchool');
  456. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST);
  457. $this->assertFalse($organizationUtils->isSchool($organization));
  458. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST_PREMIUM);
  459. $this->assertFalse($organizationUtils->isSchool($organization));
  460. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL);
  461. $this->assertTrue($organizationUtils->isSchool($organization));
  462. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL_PREMIUM);
  463. $this->assertTrue($organizationUtils->isSchool($organization));
  464. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER);
  465. $this->assertFalse($organizationUtils->isSchool($organization));
  466. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER_PREMIUM);
  467. $this->assertFalse($organizationUtils->isSchool($organization));
  468. }
  469. /**
  470. * @see OrganizationUtils::isArtist()
  471. */
  472. public function testIsArtist(): void
  473. {
  474. $organizationUtils = $this->getOrganizationUtilsMockFor('isArtist');
  475. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST);
  476. $this->assertTrue($organizationUtils->isArtist($organization));
  477. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST_PREMIUM);
  478. $this->assertTrue($organizationUtils->isArtist($organization));
  479. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL);
  480. $this->assertFalse($organizationUtils->isArtist($organization));
  481. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL_PREMIUM);
  482. $this->assertFalse($organizationUtils->isArtist($organization));
  483. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER);
  484. $this->assertFalse($organizationUtils->isArtist($organization));
  485. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER_PREMIUM);
  486. $this->assertFalse($organizationUtils->isArtist($organization));
  487. }
  488. /**
  489. * @see OrganizationUtils::hasModule()
  490. */
  491. public function testHasModule(): void
  492. {
  493. $organizationUtils = $this->getOrganizationUtilsMockFor('hasModule');
  494. $settings = $this->getMockBuilder(Settings::class)->getMock();
  495. $settings->method('getModules')->willReturn(['foo', 'bar']);
  496. $organization = $this->getMockBuilder(Organization::class)->getMock();
  497. $organization->method('getSettings')->willReturn($settings);
  498. $this->assertTrue($organizationUtils->hasModule($organization, 'foo'));
  499. $this->assertFalse($organizationUtils->hasModule($organization, 'other'));
  500. }
  501. }