UtilsTest.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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 OrganizationUtils::getOrganizationWebsite()
  288. */
  289. public function testOrganizationWebsiteOutOfNetSubdomain(): void
  290. {
  291. $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationWebsite');
  292. $parameters = $this->getMockBuilder(Parameters::class)->getMock();
  293. $parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
  294. $parameters->method('getCustomDomain')->willReturn(null);
  295. $organization = $this->getMockBuilder(Organization::class)->getMock();
  296. $organization->method('getParameters')->willReturn($parameters);
  297. $organizationUtils->method('getOrganizationActiveSubdomain')->with($organization)->willReturn('outofnet');
  298. $this->assertEquals('https://opentalent.fr', $organizationUtils->getOrganizationWebsite($organization));
  299. }
  300. /**
  301. * @see Utils::isLastParentAndCMF()
  302. */
  303. public function testIsLastParentAndCMF(): void
  304. {
  305. $organizationUtils = $this->getOrganizationUtilsMockFor('isLastParentAndCMF');
  306. $organization1 = $this->getMockBuilder(Organization::class)->getMock();
  307. $organization2 = $this->getMockBuilder(Organization::class)->getMock();
  308. $organization3 = $this->getMockBuilder(Organization::class)->getMock();
  309. $organization4 = $this->getMockBuilder(Organization::class)->getMock();
  310. $this->networkOrganizationRepository
  311. ->method('isLastParent')
  312. ->willReturnMap([
  313. [$organization1, true],
  314. [$organization2, true],
  315. [$organization3, false],
  316. [$organization4, false],
  317. ]);
  318. $this->networkUtils
  319. ->method('isCMF')
  320. ->willReturnMap([
  321. [$organization1, true],
  322. [$organization2, false],
  323. [$organization3, true],
  324. [$organization4, false],
  325. ]);
  326. $this->assertTrue($organizationUtils->isLastParentAndCMF($organization1));
  327. $this->assertFalse($organizationUtils->isLastParentAndCMF($organization2));
  328. $this->assertFalse($organizationUtils->isLastParentAndCMF($organization3));
  329. $this->assertFalse($organizationUtils->isLastParentAndCMF($organization4));
  330. }
  331. /**
  332. * @see Utils::isStructureAndCMF()
  333. */
  334. public function testIsStructureAndCMF(): void
  335. {
  336. $organizationUtils = $this->getOrganizationUtilsMockFor('isStructureAndCMF');
  337. $organization1 = $this->getMockBuilder(Organization::class)->getMock();
  338. $organization2 = $this->getMockBuilder(Organization::class)->getMock();
  339. $organization3 = $this->getMockBuilder(Organization::class)->getMock();
  340. $organization4 = $this->getMockBuilder(Organization::class)->getMock();
  341. $organizationUtils
  342. ->method('isStructure')
  343. ->willReturnMap([
  344. [$organization1, true],
  345. [$organization2, false],
  346. [$organization3, true],
  347. [$organization4, false],
  348. ]);
  349. $this->networkUtils
  350. ->method('isCMF')
  351. ->with($organization1)
  352. ->willReturnMap([
  353. [$organization1, true],
  354. [$organization2, false],
  355. [$organization3, false],
  356. [$organization4, true],
  357. ]);
  358. $this->assertTrue($organizationUtils->isStructureAndCMF($organization1));
  359. $this->assertFalse($organizationUtils->isStructureAndCMF($organization2));
  360. $this->assertFalse($organizationUtils->isStructureAndCMF($organization3));
  361. $this->assertFalse($organizationUtils->isStructureAndCMF($organization4));
  362. }
  363. /**
  364. * @see Utils::isManagerAndCMF()
  365. */
  366. public function testIsManagerAndCMF(): void
  367. {
  368. $organizationUtils = $this->getOrganizationUtilsMockFor('isManagerAndCMF');
  369. $organization1 = $this->getMockBuilder(Organization::class)->getMock();
  370. $organization2 = $this->getMockBuilder(Organization::class)->getMock();
  371. $organization3 = $this->getMockBuilder(Organization::class)->getMock();
  372. $organization4 = $this->getMockBuilder(Organization::class)->getMock();
  373. $organizationUtils
  374. ->method('isManager')
  375. ->willReturnMap([
  376. [$organization1, true],
  377. [$organization2, false],
  378. [$organization3, true],
  379. [$organization4, false],
  380. ]);
  381. $this->networkUtils
  382. ->method('isCMF')
  383. ->willReturnMap([
  384. [$organization1, true],
  385. [$organization2, false],
  386. [$organization3, false],
  387. [$organization4, true],
  388. ]);
  389. $this->assertTrue($organizationUtils->isManagerAndCMF($organization1));
  390. $this->assertFalse($organizationUtils->isManagerAndCMF($organization2));
  391. $this->assertFalse($organizationUtils->isManagerAndCMF($organization3));
  392. $this->assertFalse($organizationUtils->isManagerAndCMF($organization4));
  393. }
  394. /**
  395. * @see Utils::isManagerAndNotLastParentAndCMF()
  396. */
  397. public function testIsManagerAndLastParentAndCMF(): void
  398. {
  399. $organizationUtils = $this->getOrganizationUtilsMockFor('isManagerAndLastParentAndCMF');
  400. $organization1 = $this->getMockBuilder(Organization::class)->getMock();
  401. $organization2 = $this->getMockBuilder(Organization::class)->getMock();
  402. $organization3 = $this->getMockBuilder(Organization::class)->getMock();
  403. $organization4 = $this->getMockBuilder(Organization::class)->getMock();
  404. $organizationUtils
  405. ->method('isManager')
  406. ->willReturnMap([
  407. [$organization1, true],
  408. [$organization2, false],
  409. [$organization3, true],
  410. [$organization4, false],
  411. ]);
  412. $organizationUtils
  413. ->method('isLastParentAndCMF')
  414. ->willReturnMap([
  415. [$organization1, true],
  416. [$organization2, false],
  417. [$organization3, false],
  418. [$organization4, true],
  419. ]);
  420. $this->assertTrue($organizationUtils->isManagerAndLastParentAndCMF($organization1));
  421. $this->assertFalse($organizationUtils->isManagerAndLastParentAndCMF($organization2));
  422. $this->assertFalse($organizationUtils->isManagerAndLastParentAndCMF($organization3));
  423. $this->assertFalse($organizationUtils->isManagerAndLastParentAndCMF($organization4));
  424. }
  425. /**
  426. * @see Utils::isManagerAndNotLastParentAndCMF()
  427. */
  428. public function testIsManagerAndNotLastParentAndCMF(): void
  429. {
  430. $organizationUtils = $this->getOrganizationUtilsMockFor('isManagerAndNotLastParentAndCMF');
  431. $organization1 = $this->getMockBuilder(Organization::class)->getMock();
  432. $organization2 = $this->getMockBuilder(Organization::class)->getMock();
  433. $organization3 = $this->getMockBuilder(Organization::class)->getMock();
  434. $organization4 = $this->getMockBuilder(Organization::class)->getMock();
  435. $organizationUtils
  436. ->method('isManager')
  437. ->willReturnMap([
  438. [$organization1, true],
  439. [$organization2, false],
  440. [$organization3, true],
  441. [$organization4, true],
  442. ]);
  443. $this->networkOrganizationRepository
  444. ->method('isLastParent')
  445. ->willReturnMap([
  446. [$organization1, false],
  447. [$organization2, false],
  448. [$organization3, true],
  449. [$organization4, false],
  450. ]);
  451. $this->networkUtils
  452. ->method('isCMF')
  453. ->willReturnMap([
  454. [$organization1, true],
  455. [$organization2, true],
  456. [$organization3, true],
  457. [$organization4, false],
  458. ]);
  459. $this->assertTrue($organizationUtils->isManagerAndNotLastParentAndCMF($organization1));
  460. $this->assertFalse($organizationUtils->isManagerAndNotLastParentAndCMF($organization2));
  461. $this->assertFalse($organizationUtils->isManagerAndNotLastParentAndCMF($organization3));
  462. $this->assertFalse($organizationUtils->isManagerAndNotLastParentAndCMF($organization4));
  463. }
  464. /**
  465. * @see OrganizationUtils::isSchool()
  466. */
  467. public function testIsSchool(): void
  468. {
  469. $organizationUtils = $this->getOrganizationUtilsMockFor('isSchool');
  470. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST);
  471. $this->assertFalse($organizationUtils->isSchool($organization));
  472. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST_PREMIUM);
  473. $this->assertFalse($organizationUtils->isSchool($organization));
  474. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL);
  475. $this->assertTrue($organizationUtils->isSchool($organization));
  476. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL_PREMIUM);
  477. $this->assertTrue($organizationUtils->isSchool($organization));
  478. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER);
  479. $this->assertFalse($organizationUtils->isSchool($organization));
  480. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER_PREMIUM);
  481. $this->assertFalse($organizationUtils->isSchool($organization));
  482. }
  483. /**
  484. * @see OrganizationUtils::isArtist()
  485. */
  486. public function testIsArtist(): void
  487. {
  488. $organizationUtils = $this->getOrganizationUtilsMockFor('isArtist');
  489. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST);
  490. $this->assertTrue($organizationUtils->isArtist($organization));
  491. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST_PREMIUM);
  492. $this->assertTrue($organizationUtils->isArtist($organization));
  493. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL);
  494. $this->assertFalse($organizationUtils->isArtist($organization));
  495. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL_PREMIUM);
  496. $this->assertFalse($organizationUtils->isArtist($organization));
  497. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER);
  498. $this->assertFalse($organizationUtils->isArtist($organization));
  499. $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER_PREMIUM);
  500. $this->assertFalse($organizationUtils->isArtist($organization));
  501. }
  502. /**
  503. * @see OrganizationUtils::hasModule()
  504. */
  505. public function testHasModule(): void
  506. {
  507. $organizationUtils = $this->getOrganizationUtilsMockFor('hasModule');
  508. $settings = $this->getMockBuilder(Settings::class)->getMock();
  509. $settings->method('getModules')->willReturn(['foo', 'bar']);
  510. $organization = $this->getMockBuilder(Organization::class)->getMock();
  511. $organization->method('getSettings')->willReturn($settings);
  512. $this->assertTrue($organizationUtils->hasModule($organization, 'foo'));
  513. $this->assertFalse($organizationUtils->hasModule($organization, 'other'));
  514. }
  515. }