|
|
@@ -8,25 +8,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 {
|
|
|
- public function isOrganizationIdEqualTo(Organization $organization, OrganizationIdsEnum $organizationIdsEnum): bool {
|
|
|
- return parent::isOrganizationIdEqualTo($organization, $organizationIdsEnum);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
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) {
|
|
|
+ return $this->getMockBuilder(OrganizationUtils::class)
|
|
|
+ ->setConstructorArgs([$this->networkOrganizationRepository, $this->networkUtils])
|
|
|
+ ->setMethodsExcept([$methodName])
|
|
|
+ ->getMock();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @see OrganizationUtils::isStructure()
|
|
|
*/
|
|
|
public function testIsStructure(): void
|
|
|
{
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['isStructure'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('isStructure');
|
|
|
|
|
|
$settings = $this->getMockBuilder(Settings::class)->getMock();
|
|
|
$organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
@@ -61,7 +77,7 @@ class UtilsTest extends TestCase
|
|
|
*/
|
|
|
public function testIsManager(): void
|
|
|
{
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['isManager'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('isManager');
|
|
|
|
|
|
$settings = $this->getMockBuilder(Settings::class)->getMock();
|
|
|
$organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
@@ -89,7 +105,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();
|
|
|
|
|
|
@@ -99,17 +115,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);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -118,7 +134,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()->getValue());
|
|
|
@@ -132,7 +148,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(
|
|
|
@@ -163,7 +179,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'));
|
|
|
@@ -182,7 +198,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);
|
|
|
@@ -201,7 +217,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'));
|
|
|
@@ -218,7 +234,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);
|
|
|
@@ -234,7 +250,7 @@ class UtilsTest extends TestCase
|
|
|
* @see OrganizationUtils::getOrganizationActiveSubdomain()
|
|
|
*/
|
|
|
public function testGetOrganizationActiveSubdomain(): void {
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['getOrganizationActiveSubdomain'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationActiveSubdomain');
|
|
|
|
|
|
$subdomain1 = $this->getMockBuilder(Subdomain::class)->getMock();
|
|
|
$subdomain1->method('isActive')->willReturn(false);
|
|
|
@@ -256,7 +272,7 @@ class UtilsTest extends TestCase
|
|
|
* @see OrganizationUtils::getOrganizationActiveSubdomain()
|
|
|
*/
|
|
|
public function testGetOrganizationActiveSubdomainNone(): void {
|
|
|
- $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['getOrganizationActiveSubdomain'])->getMock();
|
|
|
+ $organizationUtils = $this->getOrganizationUtilsMockFor('getOrganizationActiveSubdomain');
|
|
|
|
|
|
$subdomain1 = $this->getMockBuilder(Subdomain::class)->getMock();
|
|
|
$subdomain1->method('isActive')->willReturn(false);
|
|
|
@@ -272,7 +288,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);
|
|
|
@@ -291,7 +307,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);
|
|
|
@@ -308,7 +324,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);
|
|
|
@@ -325,7 +341,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);
|
|
|
@@ -342,7 +358,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);
|
|
|
@@ -355,4 +371,194 @@ 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));
|
|
|
+ }
|
|
|
}
|