UtilsTest.php 26 KB

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