|
|
@@ -22,12 +22,15 @@ use App\Repository\Access\FunctionTypeRepository;
|
|
|
use App\Repository\Organization\OrganizationRepository;
|
|
|
use App\Service\Dolibarr\DolibarrApiService;
|
|
|
use App\Service\Dolibarr\DolibarrSyncService;
|
|
|
+use App\Service\Rest\ApiRequestService;
|
|
|
+use App\Service\Rest\Operation\CreateOperation;
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
use JetBrains\PhpStorm\Pure;
|
|
|
use libphonenumber\PhoneNumber;
|
|
|
use libphonenumber\PhoneNumberUtil;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
+use Symfony\Contracts\HttpClient\ResponseInterface;
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
|
|
|
|
|
class TestableDolibarrSyncService extends DolibarrSyncService {
|
|
|
@@ -35,7 +38,7 @@ class TestableDolibarrSyncService extends DolibarrSyncService {
|
|
|
public function getDolibarrContactsIndex(int $socId): array { return parent::getDolibarrContactsIndex($socId); }
|
|
|
public function getActiveMembersIndex(): array { return parent::getActiveMembersIndex(); }
|
|
|
public static function sanitizeDolibarrData(?array $data): ?array { return parent::sanitizeDolibarrData($data); }
|
|
|
- public function getOrganizationPostalAddress(Organization $organization): AddressPostal { return parent::getOrganizationPostalAddress($organization); }
|
|
|
+ public function getOrganizationPostalAddress(Organization $organization): ?AddressPostal { return parent::getOrganizationPostalAddress($organization); }
|
|
|
public function getOrganizationPhone(Organization $organization): ?string { return parent::getOrganizationPhone($organization); }
|
|
|
public function getOrganizationEmail(Organization $organization): ?string { return parent::getOrganizationEmail($organization); }
|
|
|
public static function countWithMission(array $missions, array $members): int { return parent::countWithMission($missions, $members); }
|
|
|
@@ -119,12 +122,12 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
->method('getAllActiveMembersAndMissions')
|
|
|
->willReturn(
|
|
|
[
|
|
|
- ['id' => 108939, 'organization_id' => 37306, 'mission' => FunctionEnum::PRESIDENT()->getValue()],
|
|
|
- ['id' => 108939, 'organization_id' => 37306, 'mission' => FunctionEnum::ADHERENT()->getValue()],
|
|
|
- ['id' => 156252, 'organization_id' => 37306, 'mission' => FunctionEnum::TREASURER()->getValue()],
|
|
|
- ['id' => 156252, 'organization_id' => 37306, 'mission' => FunctionEnum::ADHERENT()->getValue()],
|
|
|
- ['id' => 112775, 'organization_id' => 37306, 'mission' => FunctionEnum::STUDENT()->getValue()],
|
|
|
- ['id' => 112775, 'organization_id' => 37306, 'mission' => FunctionEnum::ADHERENT()->getValue()],
|
|
|
+ ['id' => 1, 'organization_id' => 37306, 'mission' => FunctionEnum::PRESIDENT()->getValue()],
|
|
|
+ ['id' => 1, 'organization_id' => 37306, 'mission' => FunctionEnum::ADHERENT()->getValue()],
|
|
|
+ ['id' => 2, 'organization_id' => 37306, 'mission' => FunctionEnum::TREASURER()->getValue()],
|
|
|
+ ['id' => 2, 'organization_id' => 37306, 'mission' => FunctionEnum::ADHERENT()->getValue()],
|
|
|
+ ['id' => 3, 'organization_id' => 37306, 'mission' => FunctionEnum::STUDENT()->getValue()],
|
|
|
+ ['id' => 3, 'organization_id' => 37306, 'mission' => FunctionEnum::ADHERENT()->getValue()],
|
|
|
]
|
|
|
);
|
|
|
|
|
|
@@ -193,35 +196,65 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
function ($c) {
|
|
|
return in_array(
|
|
|
(int)$c["array_options"]["options_2iopen_person_id"],
|
|
|
- [108939, 156252, 302117]
|
|
|
+ [
|
|
|
+ 108939, // existing person, to be updated
|
|
|
+ 156252 // no matching person, to be deleted
|
|
|
+ // a new contact shall be created too
|
|
|
+ ]
|
|
|
); }
|
|
|
)
|
|
|
);
|
|
|
|
|
|
$this->organizationRepository->method('find')->willReturn($organization);
|
|
|
|
|
|
- $access = $this->getMockBuilder(Access::class)->getMock();
|
|
|
- $person = $this->getMockBuilder(Person::class)->getMock();
|
|
|
- $person->method('getId')->willReturn(108939);
|
|
|
- $person->method('getName')->willReturn('Holmes');
|
|
|
- $person->method('getGender')->willReturn('MISTER');
|
|
|
- $person->method('getGivenName')->willReturn('Sherlock');
|
|
|
- $person->method('getGivenName')->willReturn('Sherlock');
|
|
|
+ $access1 = $this->getMockBuilder(Access::class)->getMock();
|
|
|
+ $access1->method('getId')->willReturn(1);
|
|
|
|
|
|
- $personContactPoint = $this->getMockBuilder(ContactPoint::class)->getMock();
|
|
|
- $personContactPoint->method('getContactType')->willReturn(ContactPointTypeEnum::CONTACT()->getValue());
|
|
|
- $personContactPoint->method('getEmail')->willReturn('sherlock@holmes.com');
|
|
|
- $phoneNumber = $phoneUtil->parse('02 98 76 54 32', 'FR');
|
|
|
- $personContactPoint->method('getTelphone')->willReturn($phoneNumber);
|
|
|
- $personContactPoint->method('getMobilPhone')->willReturn(null);
|
|
|
- $person->method('getContactPoints')->willReturn(
|
|
|
- new ArrayCollection([$personContactPoint])
|
|
|
- );
|
|
|
+ $person1 = $this->getMockBuilder(Person::class)->getMock();
|
|
|
+ $person1->method('getId')->willReturn(108939);
|
|
|
+ $person1->method('getName')->willReturn('Holmes');
|
|
|
+ $person1->method('getGender')->willReturn('MISTER');
|
|
|
+ $person1->method('getGivenName')->willReturn('Sherlock');
|
|
|
+ $person1->method('getGivenName')->willReturn('Sherlock');
|
|
|
|
|
|
+ $personContactPoint1 = $this->getMockBuilder(ContactPoint::class)->getMock();
|
|
|
+ $personContactPoint1->method('getContactType')->willReturn(ContactPointTypeEnum::CONTACT()->getValue());
|
|
|
+ $personContactPoint1->method('getEmail')->willReturn('sherlock@holmes.com');
|
|
|
+ $phoneNumber1 = $phoneUtil->parse('02 98 76 54 32', 'FR');
|
|
|
+ $personContactPoint1->method('getTelphone')->willReturn($phoneNumber1);
|
|
|
+ $personContactPoint1->method('getMobilPhone')->willReturn(null);
|
|
|
+ $person1->method('getContactPoints')->willReturn(
|
|
|
+ new ArrayCollection([$personContactPoint1])
|
|
|
+ );
|
|
|
+ $access1->method('getPerson')->willReturn($person1);
|
|
|
|
|
|
+ $access2 = $this->getMockBuilder(Access::class)->getMock();
|
|
|
+ $access2->method('getId')->willReturn(1);
|
|
|
|
|
|
- $access->method('getPerson')->willReturn($person);
|
|
|
- $this->accessRepository->method('find')->willReturn($access);
|
|
|
+ $person2 = $this->getMockBuilder(Person::class)->getMock();
|
|
|
+ $person2->method('getId')->willReturn(1000);
|
|
|
+ $person2->method('getName')->willReturn('Watson');
|
|
|
+ $person2->method('getGender')->willReturn('MISTER');
|
|
|
+ $person2->method('getGivenName')->willReturn('John');
|
|
|
+ $person2->method('getGivenName')->willReturn('John');
|
|
|
+
|
|
|
+ $personContactPoint2 = $this->getMockBuilder(ContactPoint::class)->getMock();
|
|
|
+ $personContactPoint2->method('getContactType')->willReturn(ContactPointTypeEnum::CONTACT()->getValue());
|
|
|
+ $personContactPoint2->method('getEmail')->willReturn('docteur@watson.com');
|
|
|
+ $phoneNumber2 = $phoneUtil->parse('02 10 11 12 13', 'FR');
|
|
|
+ $personContactPoint2->method('getTelphone')->willReturn($phoneNumber2);
|
|
|
+ $personContactPoint2->method('getMobilPhone')->willReturn(null);
|
|
|
+ $person2->method('getContactPoints')->willReturn(
|
|
|
+ new ArrayCollection([$personContactPoint2])
|
|
|
+ );
|
|
|
+ $access2->method('getPerson')->willReturn($person2);
|
|
|
+
|
|
|
+ $this->accessRepository->method('find')->willReturnMap(
|
|
|
+ [
|
|
|
+ [1, null, null, $access1],
|
|
|
+ [2, null, null, $access2],
|
|
|
+ ]
|
|
|
+ );
|
|
|
|
|
|
$this->translator->method('trans')->willReturnMap(
|
|
|
[
|
|
|
@@ -251,19 +284,54 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
$operations[0]->getChangeLog()
|
|
|
);
|
|
|
$this->assertEquals(
|
|
|
- ['PUT contact/5868', ''],
|
|
|
+ [
|
|
|
+ '[PUT contacts/5868]',
|
|
|
+ 'civility_code : `MME` => ``',
|
|
|
+ 'lastname : `DUPONT` => `Holmes`',
|
|
|
+ 'firstname : `Valerie` => `Sherlock`',
|
|
|
+ 'email : `abcd@hotmail.com` => ``',
|
|
|
+ 'phone_pro : `+33478570000` => ``',
|
|
|
+ 'phone_mobile : `+33682980000` => ``',
|
|
|
+ 'poste : `Secrétaire` => ``'
|
|
|
+ ],
|
|
|
$operations[1]->getChangeLog()
|
|
|
);
|
|
|
$this->assertEquals(
|
|
|
- ['PUT thirdparty/5869', ''],
|
|
|
+ [
|
|
|
+ '[POST contacts]',
|
|
|
+ 'civility_code : ``',
|
|
|
+ 'lastname : `Watson`',
|
|
|
+ 'firstname : `John`',
|
|
|
+ 'email : ``',
|
|
|
+ 'phone_pro : ``',
|
|
|
+ 'phone_mobile : ``',
|
|
|
+ 'poste : ``',
|
|
|
+ 'socid : `1726`',
|
|
|
+ 'array_options.options_2iopen_person_id : `1000`'
|
|
|
+ ],
|
|
|
$operations[2]->getChangeLog()
|
|
|
);
|
|
|
$this->assertEquals(
|
|
|
- ['PUT thirdparty/5871', ''],
|
|
|
- $operations[2]->getChangeLog()
|
|
|
+ ['[PUT contacts/5869]', 'statut : `1` => `0`'],
|
|
|
+ $operations[3]->getChangeLog()
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ public function testExecuteOk() {
|
|
|
+
|
|
|
+ $operation = new CreateOperation('operation 1', 'thirdparty', ['data' => 1]);
|
|
|
+ $this->assertEquals($operation->getStatus(), $operation::STATUS_READY);
|
|
|
+
|
|
|
+ $response = $this->getMockBuilder(ResponseInterface::class)->getMock();
|
|
|
+ $response->method('getStatusCode')->willReturn(200);
|
|
|
+ $this->dolibarrApiService->method('request')->willReturn($response);
|
|
|
+
|
|
|
+ $syncService = $this->newDolibarrSyncService();
|
|
|
+ $operations = $syncService->execute([$operation]);
|
|
|
+
|
|
|
+ $this->assertEquals($operation::STATUS_DONE, $operations[0]->getStatus());
|
|
|
+ }
|
|
|
+
|
|
|
public function testGetDolibarrSocietiesIndex() {
|
|
|
$this->dolibarrApiService
|
|
|
->expects($this->once())
|
|
|
@@ -353,7 +421,7 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
$organization->expects($this->once())
|
|
|
->method('getOrganizationAddressPostals')
|
|
|
->willReturn(
|
|
|
- [$organizationAddressPostal1, $organizationAddressPostal2, $organizationAddressPostal3]
|
|
|
+ new ArrayCollection([$organizationAddressPostal1, $organizationAddressPostal2, $organizationAddressPostal3])
|
|
|
);
|
|
|
|
|
|
$syncService = $this->newDolibarrSyncService($organization);
|
|
|
@@ -364,9 +432,9 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
);
|
|
|
|
|
|
$organization2 = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
- $organization->expects($this->once())
|
|
|
+ $organization2->expects($this->once())
|
|
|
->method('getOrganizationAddressPostals')
|
|
|
- ->willReturn([]);
|
|
|
+ ->willReturn(new ArrayCollection([]));
|
|
|
|
|
|
$this->assertEquals(
|
|
|
null,
|
|
|
@@ -385,19 +453,21 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
$contactPoint2->method('getContactType')->willReturn(ContactPointTypeEnum::BILL()->getValue());
|
|
|
$contactPoint3->method('getContactType')->willReturn(ContactPointTypeEnum::PRINCIPAL()->getValue());
|
|
|
|
|
|
- $contactPoint2->expects($this->once())->method('getTelphone')->willReturn('0161626365');
|
|
|
+ $phoneUtil = PhoneNumberUtil::getInstance();
|
|
|
+ $phoneNumber = $phoneUtil->parse('0161626365', "FR");
|
|
|
+ $contactPoint2->method('getTelphone')->willReturn($phoneNumber);
|
|
|
|
|
|
$organization
|
|
|
->expects($this->once())
|
|
|
->method('getContactPoints')
|
|
|
->willReturn(
|
|
|
- [$contactPoint1, $contactPoint2, $contactPoint3]
|
|
|
+ new ArrayCollection([$contactPoint1, $contactPoint2, $contactPoint3])
|
|
|
);
|
|
|
|
|
|
$syncService = $this->newDolibarrSyncService();
|
|
|
|
|
|
$this->assertEquals(
|
|
|
- '+331 61 62 63 65',
|
|
|
+ '+33 1 61 62 63 65',
|
|
|
$syncService->getOrganizationPhone($organization)
|
|
|
);
|
|
|
}
|
|
|
@@ -414,19 +484,22 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
$contactPoint3->method('getContactType')->willReturn(ContactPointTypeEnum::PRINCIPAL()->getValue());
|
|
|
|
|
|
$contactPoint2->expects($this->once())->method('getTelphone')->willReturn(null);
|
|
|
- $contactPoint2->expects($this->once())->method('getMobilPhone')->willReturn('0661626365');
|
|
|
+
|
|
|
+ $phoneUtil = PhoneNumberUtil::getInstance();
|
|
|
+ $phoneNumber = $phoneUtil->parse('0661626365', "FR");
|
|
|
+ $contactPoint2->method('getMobilPhone')->willReturn($phoneNumber);
|
|
|
|
|
|
$organization
|
|
|
->expects($this->once())
|
|
|
->method('getContactPoints')
|
|
|
->willReturn(
|
|
|
- [$contactPoint1, $contactPoint2, $contactPoint3]
|
|
|
+ new ArrayCollection([$contactPoint1, $contactPoint2, $contactPoint3])
|
|
|
);
|
|
|
|
|
|
$syncService = $this->newDolibarrSyncService();
|
|
|
|
|
|
$this->assertEquals(
|
|
|
- '+336 61 62 63 65',
|
|
|
+ '+33 6 61 62 63 65',
|
|
|
$syncService->getOrganizationPhone($organization)
|
|
|
);
|
|
|
}
|
|
|
@@ -436,7 +509,7 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
$organization
|
|
|
->expects($this->once())
|
|
|
->method('getContactPoints')
|
|
|
- ->willReturn([]);
|
|
|
+ ->willReturn(new ArrayCollection([]));
|
|
|
|
|
|
$syncService = $this->newDolibarrSyncService();
|
|
|
|
|
|
@@ -463,7 +536,7 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
->expects($this->once())
|
|
|
->method('getContactPoints')
|
|
|
->willReturn(
|
|
|
- [$contactPoint1, $contactPoint2, $contactPoint3]
|
|
|
+ new ArrayCollection([$contactPoint1, $contactPoint2, $contactPoint3])
|
|
|
);
|
|
|
|
|
|
$syncService = $this->newDolibarrSyncService();
|
|
|
@@ -480,7 +553,7 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
$organization
|
|
|
->expects($this->once())
|
|
|
->method('getContactPoints')
|
|
|
- ->willReturn([]);
|
|
|
+ ->willReturn(new ArrayCollection([]));
|
|
|
|
|
|
$syncService = $this->newDolibarrSyncService();
|
|
|
|
|
|
@@ -531,7 +604,7 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
$contactPoint1->method('getContactType')->willReturn(ContactPointTypeEnum::OTHER()->getValue());
|
|
|
$contactPoint2->method('getContactType')->willReturn(ContactPointTypeEnum::PRINCIPAL()->getValue());
|
|
|
|
|
|
- $person->expects($this->once())->method('getContactPoints')->willReturn([$contactPoint1, $contactPoint2]);
|
|
|
+ $person->expects($this->once())->method('getContactPoints')->willReturn(new ArrayCollection([$contactPoint1, $contactPoint2]));
|
|
|
|
|
|
$syncService = $this->newDolibarrSyncService();
|
|
|
|
|
|
@@ -541,7 +614,7 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
);
|
|
|
|
|
|
$person2 = $this->getMockBuilder(Person::class)->getMock();
|
|
|
- $person2->expects($this->once())->method('getContactPoints')->willReturn([]);
|
|
|
+ $person2->expects($this->once())->method('getContactPoints')->willReturn(new ArrayCollection([]));
|
|
|
$this->assertEquals(null, $syncService->getPersonContact($person2));
|
|
|
}
|
|
|
|