|
|
@@ -10,27 +10,41 @@ 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 TestableOrganizationUtils extends OrganizationUtils
|
|
|
+class UtilsTest extends TestCase
|
|
|
{
|
|
|
- public function isOrganizationIdEqualTo(Organization $organization, OrganizationIdsEnum $organizationIdsEnum): bool
|
|
|
+ private MockObject | NetworkOrganizationRepository $networkOrganizationRepository;
|
|
|
+ private MockObject | NetworkUtils $networkUtils;
|
|
|
+
|
|
|
+ public function setUp(): void
|
|
|
{
|
|
|
- return parent::isOrganizationIdEqualTo($organization, $organizationIdsEnum);
|
|
|
+ $this->networkOrganizationRepository = $this->getMockBuilder(NetworkOrganizationRepository::class)
|
|
|
+ ->disableOriginalConstructor()
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
+ $this->networkUtils = $this->getMockBuilder(NetworkUtils::class)->disableOriginalConstructor()->getMock();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getOrganizationUtilsMockFor(string $methodName) {
|
|
|
+ return $this->getMockBuilder(OrganizationUtils::class)
|
|
|
+ ->setConstructorArgs([$this->networkOrganizationRepository, $this->networkUtils])
|
|
|
+ ->setMethodsExcept([$methodName])
|
|
|
+ ->getMock();
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
-class UtilsTest extends TestCase
|
|
|
-{
|
|
|
/**
|
|
|
* @see OrganizationUtils::isStructure()
|
|
|
*/
|
|
|
public function testIsStructure(): void
|
|
|
{
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['isStructure'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('isStructure');
|
|
|
|
|
|
$organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST);
|
|
|
$this->assertTrue($organizationUtils->isStructure($organization));
|
|
|
@@ -56,7 +70,7 @@ class UtilsTest extends TestCase
|
|
|
*/
|
|
|
public function testIsManager(): void
|
|
|
{
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['isManager'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('isManager');
|
|
|
|
|
|
$organization = $this->createOrganizationWithProductMock(SettingsProductEnum::ARTIST);
|
|
|
$this->assertFalse($organizationUtils->isManager($organization));
|
|
|
@@ -82,7 +96,7 @@ class UtilsTest extends TestCase
|
|
|
*/
|
|
|
public function testIsOrganizationIs2ios(): void
|
|
|
{
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['is2iosOrganization'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('is2iosOrganization');
|
|
|
|
|
|
$organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
|
|
|
@@ -92,17 +106,17 @@ class UtilsTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @see OrganizationUtils::isOrganizationCMF()
|
|
|
+ * @see OrganizationUtils::isCMF()
|
|
|
*/
|
|
|
- public function testIsOrganizationIsCMF(): void
|
|
|
+ public function testIsCMF(): void
|
|
|
{
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['isOrganizationCMF'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('isCMF');
|
|
|
|
|
|
$organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
|
|
|
$organizationUtils->expects(self::once())->method('isOrganizationIdEqualTo')->with($organization, OrganizationIdsEnum::CMF);
|
|
|
|
|
|
- $organizationUtils->isOrganizationCMF($organization);
|
|
|
+ $organizationUtils->isCMF($organization);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -110,7 +124,7 @@ class UtilsTest extends TestCase
|
|
|
*/
|
|
|
public function testIsOrganizationIdEqualTo(): void
|
|
|
{
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['isOrganizationIdEqualTo'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('isOrganizationIdEqualTo');
|
|
|
|
|
|
$organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
$organization->method('getId')->willReturnOnConsecutiveCalls(123, OrganizationIdsEnum::_2IOS->value);
|
|
|
@@ -124,7 +138,7 @@ class UtilsTest extends TestCase
|
|
|
*/
|
|
|
public function testGetOrganizationCurrentActivityYear(): void
|
|
|
{
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['getOrganizationCurrentActivityYear'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationCurrentActivityYear');
|
|
|
|
|
|
$parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$parameters->method('getMusicalDate')->willReturnOnConsecutiveCalls(
|
|
|
@@ -155,7 +169,7 @@ class UtilsTest extends TestCase
|
|
|
*/
|
|
|
public function testGetActivityPeriodsSwitchYear(): void
|
|
|
{
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['getActivityPeriodsSwitchYear'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('getActivityPeriodsSwitchYear');
|
|
|
|
|
|
$parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$parameters->method('getMusicalDate')->willReturn(new \DateTime('2020-09-05'));
|
|
|
@@ -174,7 +188,7 @@ class UtilsTest extends TestCase
|
|
|
*/
|
|
|
public function testGetActivityPeriodsSwitchYearNoMusicalDate(): void
|
|
|
{
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['getActivityPeriodsSwitchYear'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('getActivityPeriodsSwitchYear');
|
|
|
|
|
|
$parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$parameters->method('getMusicalDate')->willReturn(null);
|
|
|
@@ -193,7 +207,7 @@ class UtilsTest extends TestCase
|
|
|
*/
|
|
|
public function testGetActivityYearSwitchDate(): void
|
|
|
{
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['getActivityYearSwitchDate'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('getActivityYearSwitchDate');
|
|
|
|
|
|
$parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$parameters->method('getMusicalDate')->willReturn(new \DateTime('2020-09-05'));
|
|
|
@@ -210,7 +224,7 @@ class UtilsTest extends TestCase
|
|
|
*/
|
|
|
public function testGetActivityYearSwitchDateNoMusicalDate(): void
|
|
|
{
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['getActivityYearSwitchDate'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('getActivityYearSwitchDate');
|
|
|
|
|
|
$parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$parameters->method('getMusicalDate')->willReturn(null);
|
|
|
@@ -225,9 +239,8 @@ class UtilsTest extends TestCase
|
|
|
/**
|
|
|
* @see OrganizationUtils::getOrganizationActiveSubdomain()
|
|
|
*/
|
|
|
- public function testGetOrganizationActiveSubdomain(): void
|
|
|
- {
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['getOrganizationActiveSubdomain'])->getMock();
|
|
|
+ public function testGetOrganizationActiveSubdomain(): void {
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationActiveSubdomain');
|
|
|
|
|
|
$subdomain1 = $this->getMockBuilder(Subdomain::class)->getMock();
|
|
|
$subdomain1->method('isActive')->willReturn(false);
|
|
|
@@ -248,9 +261,8 @@ class UtilsTest extends TestCase
|
|
|
/**
|
|
|
* @see OrganizationUtils::getOrganizationActiveSubdomain()
|
|
|
*/
|
|
|
- public function testGetOrganizationActiveSubdomainNone(): void
|
|
|
- {
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['getOrganizationActiveSubdomain'])->getMock();
|
|
|
+ public function testGetOrganizationActiveSubdomainNone(): void {
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationActiveSubdomain');
|
|
|
|
|
|
$subdomain1 = $this->getMockBuilder(Subdomain::class)->getMock();
|
|
|
$subdomain1->method('isActive')->willReturn(false);
|
|
|
@@ -266,7 +278,7 @@ class UtilsTest extends TestCase
|
|
|
*/
|
|
|
public function testOrganizationWebsite(): void
|
|
|
{
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['getOrganizationWebsite'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationWebsite');
|
|
|
|
|
|
$parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
|
|
|
@@ -285,7 +297,7 @@ class UtilsTest extends TestCase
|
|
|
*/
|
|
|
public function testOrganizationWebsiteDeactivatedWithOther(): void
|
|
|
{
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['getOrganizationWebsite'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationWebsite');
|
|
|
|
|
|
$parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(true);
|
|
|
@@ -302,7 +314,7 @@ class UtilsTest extends TestCase
|
|
|
*/
|
|
|
public function testOrganizationWebsiteDeactivatedNoOther(): void
|
|
|
{
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['getOrganizationWebsite'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationWebsite');
|
|
|
|
|
|
$parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(true);
|
|
|
@@ -319,7 +331,7 @@ class UtilsTest extends TestCase
|
|
|
*/
|
|
|
public function testOrganizationWebsiteWithCustom(): void
|
|
|
{
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['getOrganizationWebsite'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationWebsite');
|
|
|
|
|
|
$parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
|
|
|
@@ -336,7 +348,7 @@ class UtilsTest extends TestCase
|
|
|
*/
|
|
|
public function testOrganizationWebsiteNoSubdomains(): void
|
|
|
{
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['getOrganizationWebsite'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationWebsite');
|
|
|
|
|
|
$parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
$parameters->method('getDesactivateOpentalentSiteWeb')->willReturn(false);
|
|
|
@@ -350,6 +362,196 @@ class UtilsTest extends TestCase
|
|
|
$this->assertEquals(null, $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()
|
|
|
*/
|