|
|
@@ -125,6 +125,27 @@ class SubdomainServiceTest extends TestCase
|
|
|
$this->assertFalse($subdomainService->isValidSubdomain(str_repeat('abcdef', 20)));
|
|
|
}
|
|
|
|
|
|
+ public function testIsReservedSubdomain(): void {
|
|
|
+ $subdomainService = $this->makeSubdomainServiceMockFor('isReservedSubdomain');
|
|
|
+
|
|
|
+ $this->parameterBag
|
|
|
+ ->method('get')
|
|
|
+ ->with('opentalent.subdomains')
|
|
|
+ ->willReturn([
|
|
|
+ 'reserved' => [
|
|
|
+ 'abcd',
|
|
|
+ 'abc\d+'
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $this->assertTrue($subdomainService->isReservedSubdomain('abcd'));
|
|
|
+ $this->assertTrue($subdomainService->isReservedSubdomain('abc123'));
|
|
|
+
|
|
|
+ $this->assertFalse($subdomainService->isReservedSubdomain('abcde'));
|
|
|
+ $this->assertFalse($subdomainService->isReservedSubdomain('abc'));
|
|
|
+ $this->assertFalse($subdomainService->isReservedSubdomain('foo'));
|
|
|
+ }
|
|
|
+
|
|
|
public function testAddNewSubdomain(): void {
|
|
|
$subdomainService = $this->makeSubdomainServiceMockFor('addNewSubdomain');
|
|
|
|
|
|
@@ -132,6 +153,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);
|
|
|
|
|
|
$this->entityManager->expects(self::once())->method('persist');
|
|
|
@@ -157,6 +179,7 @@ class SubdomainServiceTest extends TestCase
|
|
|
|
|
|
$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);
|
|
|
|
|
|
$this->entityManager->expects(self::never())->method('persist');
|
|
|
@@ -178,6 +201,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);
|
|
|
|
|
|
$this->entityManager->expects(self::never())->method('persist');
|
|
|
@@ -191,6 +215,28 @@ class SubdomainServiceTest extends TestCase
|
|
|
$subdomainService->addNewSubdomain($organization, '_sub');
|
|
|
}
|
|
|
|
|
|
+ public function testAddNewSubdomainIsReserved(): void
|
|
|
+ {
|
|
|
+ $subdomainService = $this->makeSubdomainServiceMockFor('addNewSubdomain');
|
|
|
+
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
|
|
|
+
|
|
|
+ $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);
|
|
|
+
|
|
|
+ $this->entityManager->expects(self::never())->method('persist');
|
|
|
+ $this->entityManager->expects(self::never())->method('flush');
|
|
|
+ $this->bindFileService->expects(self::never())->method('registerSubdomain')->with('_sub');
|
|
|
+ $subdomainService->expects(self::never())->method('activateSubdomain');
|
|
|
+
|
|
|
+ $this->expectException(\RuntimeException::class);
|
|
|
+ $this->expectExceptionMessage('This subdomain is not available');
|
|
|
+
|
|
|
+ $subdomainService->addNewSubdomain($organization, '_sub');
|
|
|
+ }
|
|
|
+
|
|
|
public function testAddNewSubdomainExisting(): void
|
|
|
{
|
|
|
$subdomainService = $this->makeSubdomainServiceMockFor('addNewSubdomain');
|
|
|
@@ -199,6 +245,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);
|
|
|
|
|
|
$this->entityManager->expects(self::never())->method('persist');
|
|
|
@@ -220,6 +267,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('activateSubdomain');
|