|
|
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|
|
namespace App\Tests\Unit\Service\Organization;
|
|
|
|
|
|
use App\ApiResources\Organization\OrganizationCreationRequest;
|
|
|
+use App\ApiResources\Organization\OrganizationDeletionRequest;
|
|
|
use App\ApiResources\Organization\OrganizationMemberCreationRequest;
|
|
|
use App\Entity\Access\Access;
|
|
|
use App\Entity\Core\AddressPostal;
|
|
|
@@ -39,6 +40,7 @@ use App\Service\Typo3\SubdomainService;
|
|
|
use App\Service\Typo3\Typo3Service;
|
|
|
use App\Service\Utils\DatesUtils;
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
+use Elastica\Param;
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
@@ -113,6 +115,36 @@ class TestableOrganizationFactory extends OrganizationFactory {
|
|
|
public function createTypo3Website(Organization $organization): ?int {
|
|
|
return parent::createTypo3Website($organization);
|
|
|
}
|
|
|
+
|
|
|
+ public function deleteOrganizationAccesses(Organization $organization): void
|
|
|
+ {
|
|
|
+ parent::deleteOrganizationAccesses($organization);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deleteTypo3Website(Organization $organization): void
|
|
|
+ {
|
|
|
+ parent::deleteTypo3Website($organization);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deleteDolibarrSociety(Organization $organization): void
|
|
|
+ {
|
|
|
+ parent::deleteDolibarrSociety($organization);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deleteLocalDirectories(Organization $organization): void
|
|
|
+ {
|
|
|
+ parent::deleteLocalDirectories($organization);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deleteDirectoriesV1(Organization $organization): void
|
|
|
+ {
|
|
|
+ parent::deleteDirectoriesV1($organization);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deleteDirectories59(Organization $organization): void
|
|
|
+ {
|
|
|
+ parent::deleteDirectories59($organization);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
class OrganizationFactoryTest extends TestCase
|
|
|
@@ -1248,4 +1280,54 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$this->assertNull($result);
|
|
|
}
|
|
|
|
|
|
+ public function testDelete(): void
|
|
|
+ {
|
|
|
+ $organizationFactory = $this->getOrganizationFactoryMockFor('delete');
|
|
|
+
|
|
|
+ $organizationDeletionRequest = $this->getMockBuilder(OrganizationDeletionRequest::class)->getMock();
|
|
|
+
|
|
|
+ $organizationDeletionRequest->method('getOrganizationId')->willReturn(123);
|
|
|
+
|
|
|
+ $parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+ $organization->method('getParameters')->willReturn($parameters);
|
|
|
+
|
|
|
+ $this->organizationRepository
|
|
|
+ ->expects(self::once())
|
|
|
+ ->method('find')
|
|
|
+ ->with(123)
|
|
|
+ ->willReturn($organization);
|
|
|
+
|
|
|
+ $this->entityManager->expects(self::once())->method('beginTransaction');
|
|
|
+ $this->entityManager->expects(self::once())->method('flush');
|
|
|
+ $this->entityManager->expects(self::once())->method('commit');
|
|
|
+ $this->entityManager->expects(self::never())->method('rollback');
|
|
|
+
|
|
|
+ $organizationFactory->expects(self::once())->method('deleteOrganizationAccesses')->with($organization);
|
|
|
+
|
|
|
+ $this->entityManager->expects(self::exactly(2))->method('remove')->withConsecutive(
|
|
|
+ [$parameters],
|
|
|
+ [$organization]
|
|
|
+ );
|
|
|
+
|
|
|
+ $organizationFactory->expects(self::once())->method('deleteTypo3Website')->with($organization);
|
|
|
+ $organizationFactory->expects(self::once())->method('deleteDolibarrSociety')->with($organization);
|
|
|
+ $organizationFactory->expects(self::once())->method('deleteLocalDirectories')->with($organization);
|
|
|
+ $organizationFactory->expects(self::once())->method('deleteDirectoriesV1')->with($organization);
|
|
|
+ $organizationFactory->expects(self::once())->method('deleteDirectories59')->with($organization);
|
|
|
+
|
|
|
+ $organizationDeletionRequest
|
|
|
+ ->expects(self::once())
|
|
|
+ ->method('setStatus')
|
|
|
+ ->with(OrganizationDeletionRequest::STATUS_OK);
|
|
|
+
|
|
|
+ $result = $organizationFactory->delete($organizationDeletionRequest);
|
|
|
+
|
|
|
+ $this->assertEquals(
|
|
|
+ $organizationDeletionRequest,
|
|
|
+ $result
|
|
|
+ );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|