| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717 |
- <?php
- /** @noinspection PhpUnhandledExceptionInspection */
- namespace App\Tests\Unit\Service\Organization;
- use App\Entity\Network\NetworkOrganization;
- use App\Entity\Organization\Organization;
- use App\Entity\Organization\Parameters;
- use App\Entity\Organization\Settings;
- use App\Entity\Organization\Subdomain;
- use App\Enum\Organization\OrganizationIdsEnum;
- use App\Enum\Organization\SettingsProductEnum;
- use App\Repository\Network\NetworkOrganizationRepository;
- use App\Service\Network\Utils as NetworkUtils;
- use App\Service\Organization\Utils as OrganizationUtils;
- use App\Service\Utils\DatesUtils;
- use Doctrine\Common\Collections\ArrayCollection;
- use PHPUnit\Framework\MockObject\MockObject;
- use PHPUnit\Framework\TestCase;
- class UtilsTest extends TestCase
- {
- private MockObject|NetworkOrganizationRepository $networkOrganizationRepository;
- private MockObject|NetworkUtils $networkUtils;
- public function setUp(): void
- {
- $this->networkOrganizationRepository = $this->getMockBuilder(NetworkOrganizationRepository::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->networkUtils = $this->getMockBuilder(NetworkUtils::class)->disableOriginalConstructor()->getMock();
- }
- public function getOrganizationUtilsMockFor(string $methodName): MockObject|OrganizationUtils
- {
- return $this->getMockBuilder(OrganizationUtils::class)
- ->setConstructorArgs([$this->networkOrganizationRepository, $this->networkUtils])
- ->setMethodsExcept([$methodName])
- ->getMock();
- }
- private function createOrganizationWithProductMock(SettingsProductEnum $product): Organization
- {
- $settings = $this->getMockBuilder(Settings::class)->getMock();
- $settings->method('getProduct')->willReturn($product);
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getSettings')->willReturn($settings);
- return $organization;
- }
- /**
- * @see OrganizationUtils::isStructure()
- */
- public function testIsStructure(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('isStructure');
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST);
- $this->assertTrue($organizationUtils->isStructure($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST_PREMIUM);
- $this->assertTrue($organizationUtils->isStructure($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL);
- $this->assertTrue($organizationUtils->isStructure($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL_PREMIUM);
- $this->assertTrue($organizationUtils->isStructure($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER);
- $this->assertFalse($organizationUtils->isStructure($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER_PREMIUM);
- $this->assertFalse($organizationUtils->isStructure($organization));
- }
- /**
- * @see OrganizationUtils::isManager()
- */
- public function testIsManager(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('isManager');
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST);
- $this->assertFalse($organizationUtils->isManager($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST_PREMIUM);
- $this->assertFalse($organizationUtils->isManager($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL);
- $this->assertFalse($organizationUtils->isManager($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL_PREMIUM);
- $this->assertFalse($organizationUtils->isManager($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER);
- $this->assertTrue($organizationUtils->isManager($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER_PREMIUM);
- $this->assertFalse($organizationUtils->isManager($organization));
- }
- /**
- * @see OrganizationUtils::is2iosOrganization()
- */
- public function testIsOrganizationIs2ios(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('is2iosOrganization');
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organizationUtils->expects(self::once())->method('isOrganizationIdEqualTo')->with($organization, OrganizationIdsEnum::_2IOS);
- $organizationUtils->is2iosOrganization($organization);
- }
- /**
- * @see OrganizationUtils::isCMF()
- */
- public function testIsCMF(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('isCMF');
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organizationUtils->expects(self::once())->method('isOrganizationIdEqualTo')->with($organization, OrganizationIdsEnum::CMF);
- $organizationUtils->isCMF($organization);
- }
- /**
- * @see OrganizationUtils::is2iosOrganization()
- */
- public function testIsOrganizationIdEqualTo(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('isOrganizationIdEqualTo');
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getId')->willReturnOnConsecutiveCalls(123, OrganizationIdsEnum::_2IOS->value);
- $this->assertFalse($organizationUtils->isOrganizationIdEqualTo($organization, OrganizationIdsEnum::_2IOS));
- $this->assertTrue($organizationUtils->isOrganizationIdEqualTo($organization, OrganizationIdsEnum::_2IOS));
- }
- /**
- * @see OrganizationUtils::getOrganizationCurrentActivityYear()
- */
- public function testGetOrganizationCurrentActivityYear(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationCurrentActivityYear');
- $parameters = $this->getMockBuilder(Parameters::class)->getMock();
- $parameters->method('getMusicalDate')->willReturnOnConsecutiveCalls(
- null, // default should be '2020-08-31'
- new \DateTime('2020-10-01')
- );
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getParameters')->willReturn($parameters);
- DatesUtils::setFakeDatetime('2020-03-01');
- $this->assertEquals(
- 2019,
- $organizationUtils->getOrganizationCurrentActivityYear($organization)
- );
- DatesUtils::setFakeDatetime('2020-11-01');
- $this->assertEquals(
- 2020,
- $organizationUtils->getOrganizationCurrentActivityYear($organization)
- );
- }
- /**
- * @see OrganizationUtils::getActivityPeriodsSwitchYear()
- */
- public function testGetActivityPeriodsSwitchYear(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('getActivityPeriodsSwitchYear');
- $parameters = $this->getMockBuilder(Parameters::class)->getMock();
- $parameters->method('getMusicalDate')->willReturn(new \DateTime('2020-09-05'));
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getParameters')->willReturn($parameters);
- $periods = $organizationUtils->getActivityPeriodsSwitchYear($organization, 2022);
- $this->assertEquals('2022-09-05', $periods['dateStart']);
- $this->assertEquals('2023-09-04', $periods['dateEnd']);
- }
- /**
- * @see OrganizationUtils::getActivityPeriodsSwitchYear()
- */
- public function testGetActivityPeriodsSwitchYearNoMusicalDate(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('getActivityPeriodsSwitchYear');
- $parameters = $this->getMockBuilder(Parameters::class)->getMock();
- $parameters->method('getMusicalDate')->willReturn(null);
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getParameters')->willReturn($parameters);
- $periods = $organizationUtils->getActivityPeriodsSwitchYear($organization, 2022);
- $this->assertEquals('2022-09-01', $periods['dateStart']);
- $this->assertEquals('2023-08-31', $periods['dateEnd']);
- }
- /**
- * @see OrganizationUtils::getActivityYearSwitchDate()
- */
- public function testGetActivityYearSwitchDate(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('getActivityYearSwitchDate');
- $parameters = $this->getMockBuilder(Parameters::class)->getMock();
- $parameters->method('getMusicalDate')->willReturn(new \DateTime('2020-09-05'));
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getParameters')->willReturn($parameters);
- $this->assertEquals(2022, $organizationUtils->getActivityYearSwitchDate($organization, new \DateTime('2022-09-10')));
- $this->assertEquals(2021, $organizationUtils->getActivityYearSwitchDate($organization, new \DateTime('2022-09-02')));
- }
- /**
- * @see OrganizationUtils::getActivityYearSwitchDate()
- */
- public function testGetActivityYearSwitchDateNoMusicalDate(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('getActivityYearSwitchDate');
- $parameters = $this->getMockBuilder(Parameters::class)->getMock();
- $parameters->method('getMusicalDate')->willReturn(null);
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getParameters')->willReturn($parameters);
- $this->assertEquals(2021, $organizationUtils->getActivityYearSwitchDate($organization, new \DateTime('2022-08-01')));
- $this->assertEquals(2022, $organizationUtils->getActivityYearSwitchDate($organization, new \DateTime('2022-09-02')));
- }
- /**
- * @see OrganizationUtils::getOrganizationActiveSubdomain()
- */
- public function testGetOrganizationActiveSubdomain(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationActiveSubdomain');
- $subdomain1 = $this->getMockBuilder(Subdomain::class)->getMock();
- $subdomain1->method('isActive')->willReturn(false);
- $subdomain2 = $this->getMockBuilder(Subdomain::class)->getMock();
- $subdomain2->method('isActive')->willReturn(false);
- $subdomain3 = $this->getMockBuilder(Subdomain::class)->getMock();
- $subdomain3->method('isActive')->willReturn(true);
- $subdomain3->method('getSubdomain')->willReturn('foo');
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getSubdomains')->willReturn(new ArrayCollection([$subdomain1, $subdomain2, $subdomain3]));
- $this->assertEquals('foo', $organizationUtils->getOrganizationActiveSubdomain($organization));
- }
- /**
- * @see OrganizationUtils::getOrganizationActiveSubdomain()
- */
- public function testGetOrganizationActiveSubdomainNone(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationActiveSubdomain');
- $subdomain1 = $this->getMockBuilder(Subdomain::class)->getMock();
- $subdomain1->method('isActive')->willReturn(false);
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getSubdomains')->willReturn(new ArrayCollection([$subdomain1]));
- $this->assertEquals(null, $organizationUtils->getOrganizationActiveSubdomain($organization));
- }
- /**
- * @see OrganizationUtils::getOrganizationWebsite()
- */
- public function testOrganizationWebsite(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationWebsite');
- $parameters = $this->getMockBuilder(Parameters::class)->getMock();
- $parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
- $parameters->method('getCustomDomain')->willReturn(null);
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getParameters')->willReturn($parameters);
- $organizationUtils->method('getOrganizationActiveSubdomain')->with($organization)->willReturn('foo');
- $this->assertEquals('https://foo.opentalent.fr', $organizationUtils->getOrganizationWebsite($organization));
- }
- /**
- * @see OrganizationUtils::getOrganizationWebsite()
- */
- public function testOrganizationWebsiteDeactivatedWithOther(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationWebsite');
- $parameters = $this->getMockBuilder(Parameters::class)->getMock();
- $parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(true);
- $parameters->method('getWebsite')->willReturn('foo.net');
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getParameters')->willReturn($parameters);
- $this->assertEquals('https://foo.net', $organizationUtils->getOrganizationWebsite($organization));
- }
- /**
- * @see OrganizationUtils::getOrganizationWebsite()
- */
- public function testOrganizationWebsiteDeactivatedNoOther(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationWebsite');
- $parameters = $this->getMockBuilder(Parameters::class)->getMock();
- $parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(true);
- $parameters->method('getWebsite')->willReturn(null);
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getParameters')->willReturn($parameters);
- $this->assertEquals(null, $organizationUtils->getOrganizationWebsite($organization));
- }
- /**
- * @see OrganizationUtils::getOrganizationWebsite()
- */
- public function testOrganizationWebsiteWithCustom(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationWebsite');
- $parameters = $this->getMockBuilder(Parameters::class)->getMock();
- $parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
- $parameters->method('getCustomDomain')->willReturn('bar.net');
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getParameters')->willReturn($parameters);
- $this->assertEquals('https://bar.net', $organizationUtils->getOrganizationWebsite($organization));
- }
- /**
- * @see OrganizationUtils::getOrganizationWebsite()
- */
- public function testOrganizationWebsiteNoSubdomains(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationWebsite');
- $parameters = $this->getMockBuilder(Parameters::class)->getMock();
- $parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
- $parameters->method('getCustomDomain')->willReturn(null);
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getParameters')->willReturn($parameters);
- $organizationUtils->method('getOrganizationActiveSubdomain')->with($organization)->willReturn(null);
- $this->assertEquals(null, $organizationUtils->getOrganizationWebsite($organization));
- }
- /**
- * @see OrganizationUtils::getOrganizationWebsite()
- */
- public function testOrganizationWebsiteOutOfNetSubdomain(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationWebsite');
- $parameters = $this->getMockBuilder(Parameters::class)->getMock();
- $parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
- $parameters->method('getCustomDomain')->willReturn(null);
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getParameters')->willReturn($parameters);
- $organizationUtils->method('getOrganizationActiveSubdomain')->with($organization)->willReturn('outofnet');
- $this->assertEquals('https://opentalent.fr', $organizationUtils->getOrganizationWebsite($organization));
- }
- /**
- * @see Utils::isLastParentAndCMF()
- */
- public function testIsLastParentAndCMF(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('isLastParentAndCMF');
- $organization1 = $this->getMockBuilder(Organization::class)->getMock();
- $organization2 = $this->getMockBuilder(Organization::class)->getMock();
- $organization3 = $this->getMockBuilder(Organization::class)->getMock();
- $organization4 = $this->getMockBuilder(Organization::class)->getMock();
- $this->networkOrganizationRepository
- ->method('isLastParent')
- ->willReturnMap([
- [$organization1, true],
- [$organization2, true],
- [$organization3, false],
- [$organization4, false],
- ]);
- $this->networkUtils
- ->method('isCMF')
- ->willReturnMap([
- [$organization1, true],
- [$organization2, false],
- [$organization3, true],
- [$organization4, false],
- ]);
- $this->assertTrue($organizationUtils->isLastParentAndCMF($organization1));
- $this->assertFalse($organizationUtils->isLastParentAndCMF($organization2));
- $this->assertFalse($organizationUtils->isLastParentAndCMF($organization3));
- $this->assertFalse($organizationUtils->isLastParentAndCMF($organization4));
- }
- /**
- * @see Utils::isStructureAndCMF()
- */
- public function testIsStructureAndCMF(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('isStructureAndCMF');
- $organization1 = $this->getMockBuilder(Organization::class)->getMock();
- $organization2 = $this->getMockBuilder(Organization::class)->getMock();
- $organization3 = $this->getMockBuilder(Organization::class)->getMock();
- $organization4 = $this->getMockBuilder(Organization::class)->getMock();
- $organizationUtils
- ->method('isStructure')
- ->willReturnMap([
- [$organization1, true],
- [$organization2, false],
- [$organization3, true],
- [$organization4, false],
- ]);
- $this->networkUtils
- ->method('isCMF')
- ->with($organization1)
- ->willReturnMap([
- [$organization1, true],
- [$organization2, false],
- [$organization3, false],
- [$organization4, true],
- ]);
- $this->assertTrue($organizationUtils->isStructureAndCMF($organization1));
- $this->assertFalse($organizationUtils->isStructureAndCMF($organization2));
- $this->assertFalse($organizationUtils->isStructureAndCMF($organization3));
- $this->assertFalse($organizationUtils->isStructureAndCMF($organization4));
- }
- /**
- * @see Utils::isManagerAndCMF()
- */
- public function testIsManagerAndCMF(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('isManagerAndCMF');
- $organization1 = $this->getMockBuilder(Organization::class)->getMock();
- $organization2 = $this->getMockBuilder(Organization::class)->getMock();
- $organization3 = $this->getMockBuilder(Organization::class)->getMock();
- $organization4 = $this->getMockBuilder(Organization::class)->getMock();
- $organizationUtils
- ->method('isManager')
- ->willReturnMap([
- [$organization1, true],
- [$organization2, false],
- [$organization3, true],
- [$organization4, false],
- ]);
- $this->networkUtils
- ->method('isCMF')
- ->willReturnMap([
- [$organization1, true],
- [$organization2, false],
- [$organization3, false],
- [$organization4, true],
- ]);
- $this->assertTrue($organizationUtils->isManagerAndCMF($organization1));
- $this->assertFalse($organizationUtils->isManagerAndCMF($organization2));
- $this->assertFalse($organizationUtils->isManagerAndCMF($organization3));
- $this->assertFalse($organizationUtils->isManagerAndCMF($organization4));
- }
- /**
- * @see Utils::isManagerAndNotLastParentAndCMF()
- */
- public function testIsManagerAndLastParentAndCMF(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('isManagerAndLastParentAndCMF');
- $organization1 = $this->getMockBuilder(Organization::class)->getMock();
- $organization2 = $this->getMockBuilder(Organization::class)->getMock();
- $organization3 = $this->getMockBuilder(Organization::class)->getMock();
- $organization4 = $this->getMockBuilder(Organization::class)->getMock();
- $organizationUtils
- ->method('isManager')
- ->willReturnMap([
- [$organization1, true],
- [$organization2, false],
- [$organization3, true],
- [$organization4, false],
- ]);
- $organizationUtils
- ->method('isLastParentAndCMF')
- ->willReturnMap([
- [$organization1, true],
- [$organization2, false],
- [$organization3, false],
- [$organization4, true],
- ]);
- $this->assertTrue($organizationUtils->isManagerAndLastParentAndCMF($organization1));
- $this->assertFalse($organizationUtils->isManagerAndLastParentAndCMF($organization2));
- $this->assertFalse($organizationUtils->isManagerAndLastParentAndCMF($organization3));
- $this->assertFalse($organizationUtils->isManagerAndLastParentAndCMF($organization4));
- }
- /**
- * @see Utils::isManagerAndNotLastParentAndCMF()
- */
- public function testIsManagerAndNotLastParentAndCMF(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('isManagerAndNotLastParentAndCMF');
- $organization1 = $this->getMockBuilder(Organization::class)->getMock();
- $organization2 = $this->getMockBuilder(Organization::class)->getMock();
- $organization3 = $this->getMockBuilder(Organization::class)->getMock();
- $organization4 = $this->getMockBuilder(Organization::class)->getMock();
- $organizationUtils
- ->method('isManager')
- ->willReturnMap([
- [$organization1, true],
- [$organization2, false],
- [$organization3, true],
- [$organization4, true],
- ]);
- $this->networkOrganizationRepository
- ->method('isLastParent')
- ->willReturnMap([
- [$organization1, false],
- [$organization2, false],
- [$organization3, true],
- [$organization4, false],
- ]);
- $this->networkUtils
- ->method('isCMF')
- ->willReturnMap([
- [$organization1, true],
- [$organization2, true],
- [$organization3, true],
- [$organization4, false],
- ]);
- $this->assertTrue($organizationUtils->isManagerAndNotLastParentAndCMF($organization1));
- $this->assertFalse($organizationUtils->isManagerAndNotLastParentAndCMF($organization2));
- $this->assertFalse($organizationUtils->isManagerAndNotLastParentAndCMF($organization3));
- $this->assertFalse($organizationUtils->isManagerAndNotLastParentAndCMF($organization4));
- }
- /**
- * @see OrganizationUtils::isSchool()
- */
- public function testIsSchool(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('isSchool');
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST);
- $this->assertFalse($organizationUtils->isSchool($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST_PREMIUM);
- $this->assertFalse($organizationUtils->isSchool($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL);
- $this->assertTrue($organizationUtils->isSchool($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL_PREMIUM);
- $this->assertTrue($organizationUtils->isSchool($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER);
- $this->assertFalse($organizationUtils->isSchool($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER_PREMIUM);
- $this->assertFalse($organizationUtils->isSchool($organization));
- }
- /**
- * @see OrganizationUtils::isArtist()
- */
- public function testIsArtist(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('isArtist');
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST);
- $this->assertTrue($organizationUtils->isArtist($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST_PREMIUM);
- $this->assertTrue($organizationUtils->isArtist($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL);
- $this->assertFalse($organizationUtils->isArtist($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::SCHOOL_PREMIUM);
- $this->assertFalse($organizationUtils->isArtist($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER);
- $this->assertFalse($organizationUtils->isArtist($organization));
- $organization = $this->createOrganizationWithProductMock(SettingsProductEnum::MANAGER_PREMIUM);
- $this->assertFalse($organizationUtils->isArtist($organization));
- }
- /**
- * @see OrganizationUtils::hasModule()
- */
- public function testHasModule(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('hasModule');
- $settings = $this->getMockBuilder(Settings::class)->getMock();
- $settings->method('getModules')->willReturn(['foo', 'bar']);
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization->method('getSettings')->willReturn($settings);
- $this->assertTrue($organizationUtils->hasModule($organization, 'foo'));
- $this->assertFalse($organizationUtils->hasModule($organization, 'other'));
- }
- /**
- * @see OrganizationUtils::getActiveNetworkOrganization()
- */
- public function testGetActiveNetworkOrganization(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('getActiveNetworkOrganization');
- $networkOrganization1 = $this->getMockBuilder(NetworkOrganization::class)->getMock();
- $networkOrganization2 = $this->getMockBuilder(NetworkOrganization::class)->getMock();
- $networkOrganization3 = $this->getMockBuilder(NetworkOrganization::class)->getMock();
- $this
- ->networkUtils
- ->expects(self::exactly(2))
- ->method('isNetworkOrganizationActiveNow')
- ->willReturnMap([
- [$networkOrganization1, false],
- [$networkOrganization2, true],
- [$networkOrganization3, false],
- ]);
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization
- ->method('getNetworkOrganizations')
- ->willReturn(new ArrayCollection([$networkOrganization1, $networkOrganization2, $networkOrganization3]));
- $result = $organizationUtils->getActiveNetworkOrganization($organization);
- $this->assertEquals($networkOrganization2, $result);
- }
- /**
- * @see OrganizationUtils::getActiveNetworkOrganization()
- */
- public function testGetActiveNetworkOrganizationNoActive(): void
- {
- $organizationUtils = $this->getOrganizationUtilsMockFor('getActiveNetworkOrganization');
- $networkOrganization1 = $this->getMockBuilder(NetworkOrganization::class)->getMock();
- $networkOrganization2 = $this->getMockBuilder(NetworkOrganization::class)->getMock();
- $this
- ->networkUtils
- ->expects(self::exactly(2))
- ->method('isNetworkOrganizationActiveNow')
- ->willReturnMap([
- [$networkOrganization1, false],
- [$networkOrganization2, false],
- ]);
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $organization
- ->method('getNetworkOrganizations')
- ->willReturn(new ArrayCollection([$networkOrganization1, $networkOrganization2]));
- $result = $organizationUtils->getActiveNetworkOrganization($organization);
- $this->assertEquals(null, $result);
- }
- }
|