|
|
@@ -28,59 +28,48 @@ class UtilsTest extends TestCase
|
|
|
{
|
|
|
$organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['isStructure'])->getMock();
|
|
|
|
|
|
- $settings = $this->getMockBuilder(Settings::class)->getMock();
|
|
|
- $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
- $organization->method('getSettings')->willReturn($settings);
|
|
|
-
|
|
|
- // Each cal to 'isStructure' provoke 2 calls on getProduct
|
|
|
- $settings->method('getProduct')->willReturnOnConsecutiveCalls(
|
|
|
- SettingsProductEnum::ARTIST,
|
|
|
- SettingsProductEnum::ARTIST,
|
|
|
- SettingsProductEnum::ARTIST_PREMIUM,
|
|
|
- SettingsProductEnum::ARTIST_PREMIUM,
|
|
|
- SettingsProductEnum::SCHOOL,
|
|
|
- SettingsProductEnum::SCHOOL,
|
|
|
- SettingsProductEnum::SCHOOL_PREMIUM,
|
|
|
- SettingsProductEnum::SCHOOL_PREMIUM,
|
|
|
- SettingsProductEnum::MANAGER,
|
|
|
- SettingsProductEnum::MANAGER,
|
|
|
- SettingsProductEnum::MANAGER_PREMIUM,
|
|
|
- SettingsProductEnum::MANAGER_PREMIUM,
|
|
|
- );
|
|
|
-
|
|
|
+ $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::isStructure()
|
|
|
+ * @see OrganizationUtils::isManager()
|
|
|
*/
|
|
|
public function testIsManager(): void
|
|
|
{
|
|
|
$organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['isManager'])->getMock();
|
|
|
|
|
|
- $settings = $this->getMockBuilder(Settings::class)->getMock();
|
|
|
- $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
- $organization->method('getSettings')->willReturn($settings);
|
|
|
-
|
|
|
- $settings->method('getProduct')->willReturnOnConsecutiveCalls(
|
|
|
- SettingsProductEnum::ARTIST,
|
|
|
- SettingsProductEnum::ARTIST_PREMIUM,
|
|
|
- SettingsProductEnum::SCHOOL,
|
|
|
- SettingsProductEnum::SCHOOL_PREMIUM,
|
|
|
- SettingsProductEnum::MANAGER,
|
|
|
- SettingsProductEnum::MANAGER_PREMIUM,
|
|
|
- );
|
|
|
-
|
|
|
+ $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));
|
|
|
}
|
|
|
|
|
|
@@ -355,4 +344,88 @@ class UtilsTest extends TestCase
|
|
|
|
|
|
$this->assertEquals(null, $organizationUtils->getOrganizationWebsite($organization));
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see OrganizationUtils::isSchool()
|
|
|
+ */
|
|
|
+ public function testIsSchool(): void
|
|
|
+ {
|
|
|
+ $organizationUtils = $this->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['isSchool'])->getMock();
|
|
|
+
|
|
|
+ $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->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['isArtist'])->getMock();
|
|
|
+
|
|
|
+ $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->getMockBuilder(TestableOrganizationUtils::class)->setMethodsExcept(['hasModule'])->getMock();
|
|
|
+
|
|
|
+ $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'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param SettingsProductEnum $product
|
|
|
+ * @return Organization
|
|
|
+ */
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
}
|