|
@@ -0,0 +1,116 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+namespace App\Tests\Service\Typo3;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+use App\Entity\Organization\Organization;
|
|
|
|
|
+use App\Entity\Organization\Subdomain;
|
|
|
|
|
+use App\Repository\Access\AccessRepository;
|
|
|
|
|
+use App\Repository\Organization\SubdomainRepository;
|
|
|
|
|
+use App\Service\Organization\Utils as OrganizationUtils;
|
|
|
|
|
+use App\Service\Typo3\BindFileService;
|
|
|
|
|
+use App\Service\Typo3\SubdomainService;
|
|
|
|
|
+use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
|
+use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
|
+use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
|
+use PHPUnit\Framework\TestCase;
|
|
|
|
|
+use Symfony\Bundle\SecurityBundle\Security;
|
|
|
|
|
+use Symfony\Component\Messenger\MessageBusInterface;
|
|
|
|
|
+
|
|
|
|
|
+class TestableSubdomainService extends SubdomainService {
|
|
|
|
|
+ public function setOrganizationActiveSubdomain(Subdomain $subdomain): Subdomain {
|
|
|
|
|
+ return parent::setOrganizationActiveSubdomain($subdomain);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function renameAdminUserToMatchSubdomain(Subdomain $subdomain): void {
|
|
|
|
|
+ parent::renameAdminUserToMatchSubdomain($subdomain);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function updateTypo3Website($organization) {
|
|
|
|
|
+ parent::updateTypo3Website($organization);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function sendConfirmationEmail(Subdomain $subdomain): void {
|
|
|
|
|
+ parent::sendConfirmationEmail($subdomain);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+class SubdomainServiceTest extends TestCase
|
|
|
|
|
+{
|
|
|
|
|
+ private SubdomainRepository $subdomainRepository;
|
|
|
|
|
+ private OrganizationUtils $organizationUtils;
|
|
|
|
|
+ private Security $security;
|
|
|
|
|
+ private BindFileService $bindFileService;
|
|
|
|
|
+ private MessageBusInterface $messageBus;
|
|
|
|
|
+ private EntityManagerInterface $entityManager;
|
|
|
|
|
+ private AccessRepository $accessRepository;
|
|
|
|
|
+
|
|
|
|
|
+ public function setUp():void
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->subdomainRepository = $this->getMockBuilder(SubdomainRepository::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
+ $this->entityManager = $this->getMockBuilder(EntityManagerInterface::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
+ $this->messageBus = $this->getMockBuilder(MessageBusInterface::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
+ $this->security = $this->getMockBuilder(Security::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
+ $this->organizationUtils = $this->getMockBuilder(OrganizationUtils::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
+ $this->bindFileService = $this->getMockBuilder(BindFileService::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
+ $this->accessRepository = $this->getMockBuilder(AccessRepository::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function makeOnSubdomainChangeMock(string $methodName): MockObject | SubdomainService {
|
|
|
|
|
+ return $this->getMockBuilder(SubdomainService::class)
|
|
|
|
|
+ ->setConstructorArgs([
|
|
|
|
|
+ $this->subdomainRepository,
|
|
|
|
|
+ $this->entityManager,
|
|
|
|
|
+ $this->messageBus,
|
|
|
|
|
+ $this->security,
|
|
|
|
|
+ $this->organizationUtils,
|
|
|
|
|
+ $this->bindFileService,
|
|
|
|
|
+ $this->accessRepository
|
|
|
|
|
+ ])
|
|
|
|
|
+ ->setMethodsExcept([$methodName])
|
|
|
|
|
+ ->getMock();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see SubdomainService::canRegisterNewSubdomain()
|
|
|
|
|
+ */
|
|
|
|
|
+ public function testCanRegisterNewSubdomainTrue(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $subdomainService = $this->makeOnSubdomainChangeMock('canRegisterNewSubdomain');
|
|
|
|
|
+
|
|
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
+ $organization->expects(self::once())->method('getSubdomains')->willReturn(new ArrayCollection([1, 2]));
|
|
|
|
|
+
|
|
|
|
|
+ $this->assertTrue($subdomainService->canRegisterNewSubdomain($organization));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see SubdomainService::canRegisterNewSubdomain()
|
|
|
|
|
+ */
|
|
|
|
|
+ public function testCanRegisterNewSubdomainFalse(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $subdomainService = $this->makeOnSubdomainChangeMock('canRegisterNewSubdomain');
|
|
|
|
|
+
|
|
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
+ $organization->expects(self::once())->method('getSubdomains')->willReturn(new ArrayCollection([1, 2, 3]));
|
|
|
|
|
+
|
|
|
|
|
+ $this->assertFalse($subdomainService->canRegisterNewSubdomain($organization));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see SubdomainService::isValidSubdomain()
|
|
|
|
|
+ */
|
|
|
|
|
+ public function testIsValidSubdomain(): void {
|
|
|
|
|
+ $subdomainService = $this->makeOnSubdomainChangeMock('isValidSubdomain');
|
|
|
|
|
+
|
|
|
|
|
+ $this->assertTrue($subdomainService->isValidSubdomain('abcd'));
|
|
|
|
|
+ $this->assertTrue($subdomainService->isValidSubdomain('abcdefgh'));
|
|
|
|
|
+ $this->assertTrue($subdomainService->isValidSubdomain('abcd-efgh'));
|
|
|
|
|
+ $this->assertTrue($subdomainService->isValidSubdomain('123'));
|
|
|
|
|
+ $this->assertTrue($subdomainService->isValidSubdomain('a'));
|
|
|
|
|
+
|
|
|
|
|
+ $this->assertFalse($subdomainService->isValidSubdomain('_abc'));
|
|
|
|
|
+ $this->assertFalse($subdomainService->isValidSubdomain('abc-'));
|
|
|
|
|
+ $this->assertFalse($subdomainService->isValidSubdomain(str_repeat('abcdef', 20)));
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+}
|