|
|
@@ -146,6 +146,21 @@ class SubdomainServiceTest extends TestCase
|
|
|
$this->assertFalse($subdomainService->isReservedSubdomain('foo'));
|
|
|
}
|
|
|
|
|
|
+ public function testIsRegisteredSubdomain(): void {
|
|
|
+ $subdomainService = $this->makeSubdomainServiceMockFor('isRegistered');
|
|
|
+
|
|
|
+ $this->subdomainRepository->method('findBy')->willReturnCallback(function ($args) {
|
|
|
+ if ($args === ['subdomain' => 'sub']) {
|
|
|
+ $subdomain = $this->getMockBuilder(Subdomain::class)->getMock();
|
|
|
+ return [$subdomain];
|
|
|
+ }
|
|
|
+ return [];
|
|
|
+ });
|
|
|
+
|
|
|
+ $this->assertTrue($subdomainService->isRegistered('sub'));
|
|
|
+ $this->assertFalse($subdomainService->isRegistered('foo'));
|
|
|
+ }
|
|
|
+
|
|
|
public function testAddNewSubdomain(): void {
|
|
|
$subdomainService = $this->makeSubdomainServiceMockFor('addNewSubdomain');
|
|
|
|
|
|
@@ -154,7 +169,7 @@ class SubdomainServiceTest extends TestCase
|
|
|
$subdomainService->expects(self::once())->method('isValidSubdomain')->with('sub')->willReturn(True);
|
|
|
$subdomainService->expects(self::once())->method('canRegisterNewSubdomain')->with($organization)->willReturn(True);
|
|
|
$subdomainService->expects(self::once())->method('isReservedSubdomain')->with('sub')->willReturn(false);
|
|
|
- $this->subdomainRepository->expects(self::once())->method('findBy')->with(['subdomain' => 'sub'])->willReturn(0);
|
|
|
+ $subdomainService->expects(self::once())->method('isRegistered')->with('sub')->willReturn(false);
|
|
|
|
|
|
$this->entityManager->expects(self::once())->method('persist');
|
|
|
$this->entityManager->expects(self::once())->method('flush');
|
|
|
@@ -177,10 +192,10 @@ class SubdomainServiceTest extends TestCase
|
|
|
|
|
|
$organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
- $subdomainService->expects(self::once())->method('isValidSubdomain')->with('_sub')->willReturn(False);
|
|
|
- $subdomainService->expects(self::never())->method('canRegisterNewSubdomain')->with($organization)->willReturn(True);
|
|
|
+ $subdomainService->expects(self::once())->method('isValidSubdomain')->with('_sub')->willReturn(false);
|
|
|
+ $subdomainService->expects(self::never())->method('canRegisterNewSubdomain')->with($organization)->willReturn(true);
|
|
|
$subdomainService->expects(self::never())->method('isReservedSubdomain')->with($organization)->willReturn(false);
|
|
|
- $this->subdomainRepository->expects(self::never())->method('findBy')->with(['subdomain' => '_sub'])->willReturn(0);
|
|
|
+ $subdomainService->expects(self::never())->method('isRegistered')->with('sub')->willReturn(false);
|
|
|
|
|
|
$this->entityManager->expects(self::never())->method('persist');
|
|
|
$this->entityManager->expects(self::never())->method('flush');
|
|
|
@@ -202,7 +217,7 @@ class SubdomainServiceTest extends TestCase
|
|
|
$subdomainService->expects(self::once())->method('isValidSubdomain')->with('_sub')->willReturn(true);
|
|
|
$subdomainService->expects(self::once())->method('canRegisterNewSubdomain')->with($organization)->willReturn(false);
|
|
|
$subdomainService->expects(self::never())->method('isReservedSubdomain')->with($organization)->willReturn(false);
|
|
|
- $this->subdomainRepository->expects(self::never())->method('findBy')->with(['subdomain' => '_sub'])->willReturn(0);
|
|
|
+ $subdomainService->expects(self::never())->method('isRegistered')->with('sub')->willReturn(false);
|
|
|
|
|
|
$this->entityManager->expects(self::never())->method('persist');
|
|
|
$this->entityManager->expects(self::never())->method('flush');
|
|
|
@@ -224,7 +239,7 @@ class SubdomainServiceTest extends TestCase
|
|
|
$subdomainService->expects(self::once())->method('isValidSubdomain')->with('_sub')->willReturn(true);
|
|
|
$subdomainService->expects(self::once())->method('canRegisterNewSubdomain')->with($organization)->willReturn(true);
|
|
|
$subdomainService->expects(self::once())->method('isReservedSubdomain')->with('_sub')->willReturn(true);
|
|
|
- $this->subdomainRepository->expects(self::never())->method('findBy')->with(['subdomain' => '_sub'])->willReturn(0);
|
|
|
+ $subdomainService->expects(self::never())->method('isRegistered')->with('sub')->willReturn(false);
|
|
|
|
|
|
$this->entityManager->expects(self::never())->method('persist');
|
|
|
$this->entityManager->expects(self::never())->method('flush');
|
|
|
@@ -246,7 +261,7 @@ class SubdomainServiceTest extends TestCase
|
|
|
$subdomainService->expects(self::once())->method('isValidSubdomain')->with('sub')->willReturn(true);
|
|
|
$subdomainService->expects(self::once())->method('canRegisterNewSubdomain')->with($organization)->willReturn(true);
|
|
|
$subdomainService->expects(self::once())->method('isReservedSubdomain')->with('sub')->willReturn(false);
|
|
|
- $this->subdomainRepository->expects(self::once())->method('findBy')->with(['subdomain' => 'sub'])->willReturn(1);
|
|
|
+ $subdomainService->expects(self::once())->method('isRegistered')->with('sub')->willReturn(true);
|
|
|
|
|
|
$this->entityManager->expects(self::never())->method('persist');
|
|
|
$this->entityManager->expects(self::never())->method('flush');
|
|
|
@@ -268,7 +283,7 @@ class SubdomainServiceTest extends TestCase
|
|
|
$subdomainService->expects(self::once())->method('isValidSubdomain')->with('sub')->willReturn(true);
|
|
|
$subdomainService->expects(self::once())->method('canRegisterNewSubdomain')->with($organization)->willReturn(true);
|
|
|
$subdomainService->expects(self::once())->method('isReservedSubdomain')->with('sub')->willReturn(false);
|
|
|
- $this->subdomainRepository->expects(self::once())->method('findBy')->with(['subdomain' => 'sub'])->willReturn(0);
|
|
|
+ $subdomainService->expects(self::once())->method('isRegistered')->with('sub')->willReturn(false);
|
|
|
|
|
|
$subdomainService->expects(self::once())->method('activateSubdomain');
|
|
|
|
|
|
@@ -280,12 +295,19 @@ class SubdomainServiceTest extends TestCase
|
|
|
|
|
|
$organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
+ $previousActiveSubdomain = $this->getMockBuilder(Subdomain::class)->getMock();
|
|
|
+ $previousActiveSubdomain->method('getId')->willReturn(1);
|
|
|
+ $previousActiveSubdomain->method('isActive')->willReturn(false);
|
|
|
+
|
|
|
+ $this->subdomainRepository->method('getActiveSubdomainOf')->with($organization)->willReturn($previousActiveSubdomain);
|
|
|
+
|
|
|
$initialSubdomain = $this->getMockBuilder(Subdomain::class)->getMock();
|
|
|
- $initialSubdomain->method('getId')->willReturn(1);
|
|
|
+ $initialSubdomain->method('getId')->willReturn(2);
|
|
|
$initialSubdomain->method('isActive')->willReturn(false);
|
|
|
+ $initialSubdomain->method('getOrganization')->willReturn($organization);
|
|
|
|
|
|
$activatedSubdomain = $this->getMockBuilder(Subdomain::class)->getMock();
|
|
|
- $activatedSubdomain->method('getId')->willReturn(1);
|
|
|
+ $activatedSubdomain->method('getId')->willReturn(2);
|
|
|
$activatedSubdomain->method('isActive')->willReturn(true);
|
|
|
$activatedSubdomain->method('getOrganization')->willReturn($organization);
|
|
|
|
|
|
@@ -319,10 +341,15 @@ class SubdomainServiceTest extends TestCase
|
|
|
{
|
|
|
$subdomainService = $this->makeSubdomainServiceMockFor('activateSubdomain');
|
|
|
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+
|
|
|
$subdomain = $this->getMockBuilder(Subdomain::class)->getMock();
|
|
|
+ $subdomain->method('getOrganization')->willReturn($organization);
|
|
|
$subdomain->method('getId')->willReturn(1);
|
|
|
$subdomain->method('isActive')->willReturn(true);
|
|
|
|
|
|
+ $this->subdomainRepository->method('getActiveSubdomainOf')->with($organization)->willReturn($subdomain);
|
|
|
+
|
|
|
$subdomainService->expects(self::never())->method('setOrganizationActiveSubdomain');
|
|
|
$subdomainService->expects(self::never())->method('renameAdminUserToMatchSubdomain');
|
|
|
$subdomainService->expects(self::never())->method('updateTypo3Website');
|