|
|
@@ -38,6 +38,7 @@ use App\Repository\Organization\OrganizationRepository;
|
|
|
use App\Repository\Person\PersonRepository;
|
|
|
use App\Service\ApiLegacy\ApiLegacyRequestService;
|
|
|
use App\Service\Dolibarr\DolibarrApiService;
|
|
|
+use App\Service\File\FileManager;
|
|
|
use App\Service\Organization\OrganizationFactory;
|
|
|
use App\Service\Organization\Utils as OrganizationUtils;
|
|
|
use App\Service\Typo3\BindFileService;
|
|
|
@@ -152,34 +153,19 @@ class TestableOrganizationFactory extends OrganizationFactory
|
|
|
return parent::normalizeIdentificationField($value);
|
|
|
}
|
|
|
|
|
|
- public function deleteOrganizationAccesses(Organization $organization): void
|
|
|
+ public function deleteTypo3Website(int $organizationId): void
|
|
|
{
|
|
|
- parent::deleteOrganizationAccesses($organization);
|
|
|
+ parent::deleteTypo3Website($organizationId);
|
|
|
}
|
|
|
|
|
|
- public function deleteTypo3Website(Organization $organization): void
|
|
|
+ public function switchDolibarrSocietyToProspect(int $organizationId): void
|
|
|
{
|
|
|
- parent::deleteTypo3Website($organization);
|
|
|
+ parent::switchDolibarrSocietyToProspect($organizationId);
|
|
|
}
|
|
|
|
|
|
- public function switchDolibarrSocietyToProspect(Organization $organization): void
|
|
|
+ public function getFutureOrphanPersons(Organization $organization): array
|
|
|
{
|
|
|
- parent::switchDolibarrSocietyToProspect($organization);
|
|
|
- }
|
|
|
-
|
|
|
- public function deleteOrganizationFiles(Organization $organization): void
|
|
|
- {
|
|
|
- parent::deleteOrganizationFiles($organization);
|
|
|
- }
|
|
|
-
|
|
|
- public function deleteDirectoriesV1(Organization $organization): void
|
|
|
- {
|
|
|
- parent::deleteDirectoriesV1($organization);
|
|
|
- }
|
|
|
-
|
|
|
- public function deleteDirectories59(Organization $organization): void
|
|
|
- {
|
|
|
- parent::deleteDirectories59($organization);
|
|
|
+ return parent::getFutureOrphanPersons($organization);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -216,6 +202,7 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$this->apiLegacyRequestService = $this->getMockBuilder(ApiLegacyRequestService::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->phoneNumberUtil = $this->getMockBuilder(PhoneNumberUtil::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->functionTypeRepository = $this->getMockBuilder(FunctionTypeRepository::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $this->fileManager = $this->getMockBuilder(FileManager::class)->disableOriginalConstructor()->getMock();
|
|
|
}
|
|
|
|
|
|
public function tearDown(): void
|
|
|
@@ -241,6 +228,7 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$this->organizationIdentificationRepository,
|
|
|
$this->apiLegacyRequestService,
|
|
|
$this->functionTypeRepository,
|
|
|
+ $this->fileManager,
|
|
|
])
|
|
|
->setMethodsExcept(['setLoggerInterface', 'setPhoneNumberUtil', $methodName])
|
|
|
->getMock();
|
|
|
@@ -1019,7 +1007,7 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$organizationFactory->makeOrganizationWithRelations($organizationCreationRequest);
|
|
|
}
|
|
|
|
|
|
- public function testMakeOrganization()
|
|
|
+ public function testMakeOrganization(): void
|
|
|
{
|
|
|
$organizationFactory = $this->getOrganizationFactoryMockFor('makeOrganization');
|
|
|
|
|
|
@@ -1130,7 +1118,7 @@ class OrganizationFactoryTest extends TestCase
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- public function testMakePostalAddressUnexistingCountry(): void
|
|
|
+ public function testMakePostalAddressNonExistingCountry(): void
|
|
|
{
|
|
|
$organizationFactory = $this->getOrganizationFactoryMockFor('makePostalAddress');
|
|
|
|
|
|
@@ -1596,7 +1584,7 @@ class OrganizationFactoryTest extends TestCase
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- public function testMakeAccessPostalAddress()
|
|
|
+ public function testMakeAccessPostalAddress(): void
|
|
|
{
|
|
|
$organizationFactory = $this->getOrganizationFactoryMockFor('makePersonPostalAddress');
|
|
|
|
|
|
@@ -1893,8 +1881,8 @@ class OrganizationFactoryTest extends TestCase
|
|
|
|
|
|
$this->apiLegacyRequestService
|
|
|
->expects(self::once())
|
|
|
- ->method('post')
|
|
|
- ->with('/_internal/secure/organization/creation-event', ['organizationId' => 123])
|
|
|
+ ->method('get')
|
|
|
+ ->with('/_internal/request/adminassos/create/organization/123')
|
|
|
->willReturn($response);
|
|
|
|
|
|
$organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
@@ -1913,8 +1901,8 @@ class OrganizationFactoryTest extends TestCase
|
|
|
|
|
|
$this->apiLegacyRequestService
|
|
|
->expects(self::once())
|
|
|
- ->method('post')
|
|
|
- ->with('/_internal/secure/organization/creation-event', ['organizationId' => 123])
|
|
|
+ ->method('get')
|
|
|
+ ->with('/_internal/request/adminassos/create/organization/123')
|
|
|
->willReturn($response);
|
|
|
|
|
|
$organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
@@ -1935,6 +1923,7 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$organizationFactory->normalizeIdentificationField("C'est une phrase normalisée.")
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
public function testDelete(): void
|
|
|
{
|
|
|
$organizationFactory = $this->getOrganizationFactoryMockFor('delete');
|
|
|
@@ -1959,18 +1948,37 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$this->entityManager->expects(self::once())->method('commit');
|
|
|
$this->entityManager->expects(self::never())->method('rollback');
|
|
|
|
|
|
- $organizationFactory->expects(self::once())->method('deleteOrganizationAccesses')->with($organization);
|
|
|
+ $person1 = $this->getMockBuilder(Person::class)->getMock();
|
|
|
+ $person1->method('getId')->willReturn(1);
|
|
|
+
|
|
|
+ $person2 = $this->getMockBuilder(Person::class)->getMock();
|
|
|
+ $person2->method('getId')->willReturn(2);
|
|
|
+
|
|
|
+ $person3 = $this->getMockBuilder(Person::class)->getMock();
|
|
|
+ $person3->method('getId')->willReturn(3);
|
|
|
|
|
|
- $this->entityManager->expects(self::exactly(2))->method('remove')->withConsecutive(
|
|
|
+ $organizationFactory
|
|
|
+ ->method('getFutureOrphanPersons')
|
|
|
+ ->with($organization)
|
|
|
+ ->willReturn([$person1, $person2, $person3]);
|
|
|
+
|
|
|
+ $this->entityManager->expects(self::exactly(5))->method('remove')->withConsecutive(
|
|
|
[$parameters],
|
|
|
- [$organization]
|
|
|
+ [$organization],
|
|
|
+ [$person1],
|
|
|
+ [$person2],
|
|
|
+ [$person3],
|
|
|
);
|
|
|
|
|
|
- $organizationFactory->expects(self::once())->method('deleteTypo3Website')->with($organization);
|
|
|
- $organizationFactory->expects(self::once())->method('switchDolibarrSocietyToProspect')->with($organization);
|
|
|
- $organizationFactory->expects(self::once())->method('deleteOrganizationFiles')->with($organization);
|
|
|
- $organizationFactory->expects(self::once())->method('deleteDirectoriesV1')->with($organization);
|
|
|
- $organizationFactory->expects(self::once())->method('deleteDirectories59')->with($organization);
|
|
|
+ $organizationFactory->expects(self::once())->method('deleteTypo3Website')->with(123);
|
|
|
+ $organizationFactory->expects(self::once())->method('switchDolibarrSocietyToProspect')->with(123);
|
|
|
+
|
|
|
+ $this->fileManager->expects(self::once())->method('deleteOrganizationFiles')->with(123);
|
|
|
+
|
|
|
+ $this->fileManager
|
|
|
+ ->expects(self::exactly(3))
|
|
|
+ ->method('deletePersonFiles')
|
|
|
+ ->withConsecutive([1], [2], [3]);
|
|
|
|
|
|
$organizationDeletionRequest
|
|
|
->expects(self::once())
|
|
|
@@ -1997,6 +2005,20 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
$organization->method('getParameters')->willReturn($parameters);
|
|
|
|
|
|
+ $person1 = $this->getMockBuilder(Person::class)->getMock();
|
|
|
+ $person1->method('getId')->willReturn(1);
|
|
|
+
|
|
|
+ $person2 = $this->getMockBuilder(Person::class)->getMock();
|
|
|
+ $person2->method('getId')->willReturn(2);
|
|
|
+
|
|
|
+ $person3 = $this->getMockBuilder(Person::class)->getMock();
|
|
|
+ $person3->method('getId')->willReturn(3);
|
|
|
+
|
|
|
+ $organizationFactory
|
|
|
+ ->method('getFutureOrphanPersons')
|
|
|
+ ->with($organization)
|
|
|
+ ->willReturn([$person1, $person2, $person3]);
|
|
|
+
|
|
|
$this->organizationRepository
|
|
|
->expects(self::once())
|
|
|
->method('find')
|
|
|
@@ -2008,15 +2030,10 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$this->entityManager->expects(self::never())->method('commit');
|
|
|
$this->entityManager->expects(self::once())->method('rollback');
|
|
|
|
|
|
- $organizationFactory->expects(self::once())->method('deleteOrganizationAccesses')->with($organization);
|
|
|
-
|
|
|
$this->entityManager->method('remove')->willThrowException(new \Exception('some error'));
|
|
|
|
|
|
$organizationFactory->expects(self::never())->method('deleteTypo3Website');
|
|
|
$organizationFactory->expects(self::never())->method('switchDolibarrSocietyToProspect');
|
|
|
- $organizationFactory->expects(self::never())->method('deleteOrganizationFiles');
|
|
|
- $organizationFactory->expects(self::never())->method('deleteDirectoriesV1');
|
|
|
- $organizationFactory->expects(self::never())->method('deleteDirectories59');
|
|
|
|
|
|
$organizationDeletionRequest
|
|
|
->expects(self::never())
|
|
|
@@ -2047,6 +2064,20 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$organization->method('getId')->willReturn(123);
|
|
|
$organization->method('getParameters')->willReturn($parameters);
|
|
|
|
|
|
+ $person1 = $this->getMockBuilder(Person::class)->getMock();
|
|
|
+ $person1->method('getId')->willReturn(1);
|
|
|
+
|
|
|
+ $person2 = $this->getMockBuilder(Person::class)->getMock();
|
|
|
+ $person2->method('getId')->willReturn(2);
|
|
|
+
|
|
|
+ $person3 = $this->getMockBuilder(Person::class)->getMock();
|
|
|
+ $person3->method('getId')->willReturn(3);
|
|
|
+
|
|
|
+ $organizationFactory
|
|
|
+ ->method('getFutureOrphanPersons')
|
|
|
+ ->with($organization)
|
|
|
+ ->willReturn([$person1, $person2, $person3]);
|
|
|
+
|
|
|
$this->organizationRepository
|
|
|
->expects(self::once())
|
|
|
->method('find')
|
|
|
@@ -2058,33 +2089,44 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$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(
|
|
|
+ $this->entityManager->expects(self::exactly(5))->method('remove')->withConsecutive(
|
|
|
[$parameters],
|
|
|
- [$organization]
|
|
|
+ [$organization],
|
|
|
+ [$person1],
|
|
|
+ [$person2],
|
|
|
+ [$person3],
|
|
|
);
|
|
|
|
|
|
$organizationFactory->expects(self::once())->method('deleteTypo3Website')->willThrowException(new \Exception('some error'));
|
|
|
$organizationFactory->expects(self::once())->method('switchDolibarrSocietyToProspect')->willThrowException(new \Exception('some error'));
|
|
|
- $organizationFactory->expects(self::once())->method('deleteOrganizationFiles')->willThrowException(new \Exception('some error'));
|
|
|
- $organizationFactory->expects(self::once())->method('deleteDirectoriesV1')->willThrowException(new \Exception('some error'));
|
|
|
- $organizationFactory->expects(self::once())->method('deleteDirectories59')->willThrowException(new \Exception('some error'));
|
|
|
|
|
|
$organizationDeletionRequest
|
|
|
->expects(self::once())
|
|
|
->method('setStatus')
|
|
|
->with(OrganizationDeletionRequest::STATUS_OK_WITH_ERRORS);
|
|
|
|
|
|
+ $this->fileManager
|
|
|
+ ->expects(self::once())
|
|
|
+ ->method('deleteOrganizationFiles')
|
|
|
+ ->with(123)
|
|
|
+ ->willThrowException(new \Exception('some error'));
|
|
|
+
|
|
|
+ $this->fileManager
|
|
|
+ ->expects(self::exactly(3))
|
|
|
+ ->method('deletePersonFiles')
|
|
|
+ ->withConsecutive([1], [2], [3])
|
|
|
+ ->willThrowException(new \Exception('some error'));
|
|
|
+
|
|
|
$this->logger
|
|
|
- ->expects(self::exactly(5))
|
|
|
+ ->expects(self::exactly(6))
|
|
|
->method('critical')
|
|
|
->withConsecutive(
|
|
|
['An error happened while deleting the Typo3 website, please proceed manually.'],
|
|
|
['An error happened while updating the Dolibarr society, please proceed manually.'],
|
|
|
- ['An error happened while deleting the local directories, please proceed manually.'],
|
|
|
- ['An error happened while deleting the V1 directories, please proceed manually.'],
|
|
|
- ['An error happened while deleting the 5.9 directories, please proceed manually.'],
|
|
|
+ ["An error happened while deleting the organization's files, please proceed manually."],
|
|
|
+ ["An error happened while deleting the person's files, please proceed manually (id=1)."],
|
|
|
+ ["An error happened while deleting the person's files, please proceed manually (id=2)."],
|
|
|
+ ["An error happened while deleting the person's files, please proceed manually (id=3)."],
|
|
|
);
|
|
|
|
|
|
$result = $organizationFactory->delete($organizationDeletionRequest);
|
|
|
@@ -2095,50 +2137,57 @@ class OrganizationFactoryTest extends TestCase
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- public function testDeleteOrganizationAccesses(): void
|
|
|
+ public function testGetFutureOrphanPersons(): void
|
|
|
{
|
|
|
- $organizationFactory = $this->getOrganizationFactoryMockFor('deleteOrganizationAccesses');
|
|
|
+ $organizationFactory = $this->getOrganizationFactoryMockFor('getFutureOrphanPersons');
|
|
|
|
|
|
$organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
|
|
|
$access1 = $this->getMockBuilder(Access::class)->getMock();
|
|
|
- $access2 = $this->getMockBuilder(Access::class)->getMock();
|
|
|
- $access_other = $this->getMockBuilder(Access::class)->getMock();
|
|
|
-
|
|
|
$person1 = $this->getMockBuilder(Person::class)->getMock();
|
|
|
- $person1->method('getAccesses')->willReturn(new ArrayCollection([$access1]));
|
|
|
$access1->method('getPerson')->willReturn($person1);
|
|
|
|
|
|
+ $access2 = $this->getMockBuilder(Access::class)->getMock();
|
|
|
$person2 = $this->getMockBuilder(Person::class)->getMock();
|
|
|
- $person2->method('getAccesses')->willReturn(new ArrayCollection([$access2, $access_other]));
|
|
|
$access2->method('getPerson')->willReturn($person2);
|
|
|
|
|
|
- $organization->method('getAccesses')->willReturn(new ArrayCollection([$access1, $access2]));
|
|
|
+ $access3 = $this->getMockBuilder(Access::class)->getMock();
|
|
|
+ $person3 = $this->getMockBuilder(Person::class)->getMock();
|
|
|
+ $access3->method('getPerson')->willReturn($person3);
|
|
|
|
|
|
- $this->entityManager
|
|
|
- ->expects(self::exactly(3))
|
|
|
- ->method('remove')
|
|
|
- ->withConsecutive(
|
|
|
- [$person1],
|
|
|
- [$access1],
|
|
|
- [$access2],
|
|
|
- );
|
|
|
+ $otherAccess1 = $this->getMockBuilder(Access::class)->getMock();
|
|
|
+ $otherAccess2 = $this->getMockBuilder(Access::class)->getMock();
|
|
|
+
|
|
|
+ $person1->method('getAccesses')->willReturn(new ArrayCollection([$access1, $otherAccess1]));
|
|
|
+ $person2->method('getAccesses')->willReturn(new ArrayCollection([$access2, $otherAccess2]));
|
|
|
+ $person3->method('getAccesses')->willReturn(new ArrayCollection([$access3]));
|
|
|
|
|
|
- $organizationFactory->deleteOrganizationAccesses($organization);
|
|
|
+ $organization->method('getAccesses')->willReturn(new ArrayCollection([$access1, $access2, $access3]));
|
|
|
+
|
|
|
+ $this->assertEquals(
|
|
|
+ [$person3],
|
|
|
+ $organizationFactory->getFutureOrphanPersons($organization)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testDeleteTypo3Website(): void
|
|
|
+ {
|
|
|
+ $organizationFactory = $this->getOrganizationFactoryMockFor('deleteTypo3Website');
|
|
|
+
|
|
|
+ $this->typo3Service->expects(self::once())->method('hardDeleteSite')->with(123);
|
|
|
+
|
|
|
+ $organizationFactory->deleteTypo3Website(123);
|
|
|
}
|
|
|
|
|
|
public function testSwitchDolibarrSocietyToProspect(): void
|
|
|
{
|
|
|
$organizationFactory = $this->getOrganizationFactoryMockFor('switchDolibarrSocietyToProspect');
|
|
|
|
|
|
- $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
- $organization->method('getId')->willReturn(123);
|
|
|
-
|
|
|
$this->dolibarrApiService
|
|
|
->expects(self::once())
|
|
|
->method('switchSocietyToProspect')
|
|
|
->with(123);
|
|
|
|
|
|
- $organizationFactory->switchDolibarrSocietyToProspect($organization);
|
|
|
+ $organizationFactory->switchDolibarrSocietyToProspect(123);
|
|
|
}
|
|
|
}
|