|
|
@@ -25,6 +25,7 @@ use App\Service\Dolibarr\DolibarrSyncService;
|
|
|
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\Translation\TranslatorInterface;
|
|
|
@@ -140,6 +141,7 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
|
|
|
// Organization's name
|
|
|
$organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+ $organization->method('getId')->willReturn(37306);
|
|
|
$organization->method('getName')->willReturn("Etablissement d'Enseignement Artistique");
|
|
|
|
|
|
// Postal address
|
|
|
@@ -158,12 +160,12 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
);
|
|
|
|
|
|
// Email and phone
|
|
|
+ $phoneUtil = PhoneNumberUtil::getInstance();
|
|
|
+
|
|
|
$contactPoint = $this->getMockBuilder(ContactPoint::class)->getMock();
|
|
|
$contactPoint->method('getContactType')->willReturn(ContactPointTypeEnum::CONTACT()->getValue());
|
|
|
$contactPoint->method('getEmail')->willReturn('email@email.com');
|
|
|
- $phoneNumber = new PhoneNumber();
|
|
|
- $phoneNumber->setCountryCode(33);
|
|
|
- $phoneNumber->setNationalNumber('1 02 03 04 05');
|
|
|
+ $phoneNumber = $phoneUtil->parse('01 02 03 04 05', 'FR');
|
|
|
$contactPoint->method('getTelphone')->willReturn($phoneNumber);
|
|
|
$organization->method('getContactPoints')->willReturn(
|
|
|
new ArrayCollection([$contactPoint])
|
|
|
@@ -209,9 +211,7 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
$personContactPoint = $this->getMockBuilder(ContactPoint::class)->getMock();
|
|
|
$personContactPoint->method('getContactType')->willReturn(ContactPointTypeEnum::CONTACT()->getValue());
|
|
|
$personContactPoint->method('getEmail')->willReturn('sherlock@holmes.com');
|
|
|
- $phoneNumber = new PhoneNumber();
|
|
|
- $phoneNumber->setCountryCode(33);
|
|
|
- $phoneNumber->setNationalNumber('2 98 76 54 32');
|
|
|
+ $phoneNumber = $phoneUtil->parse('02 98 76 54 32', 'FR');
|
|
|
$personContactPoint->method('getTelphone')->willReturn($phoneNumber);
|
|
|
$personContactPoint->method('getMobilPhone')->willReturn(null);
|
|
|
$person->method('getContactPoints')->willReturn(
|
|
|
@@ -223,6 +223,14 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
$access->method('getPerson')->willReturn($person);
|
|
|
$this->accessRepository->method('find')->willReturn($access);
|
|
|
|
|
|
+ $this->translator->method('trans')->willReturnMap(
|
|
|
+ [
|
|
|
+ ['STUDENTS_COUNT', [], null, null, "Nombre d'élèves"],
|
|
|
+ ['ADHERENTS_COUNT', [], null, null, "Nombre d'adhérents"],
|
|
|
+ ['ADMIN_ACCESS_COUNT', [], null, null, "Nombre d'accès admin"],
|
|
|
+ ]
|
|
|
+ );
|
|
|
+
|
|
|
$syncService = $this->newDolibarrSyncService();
|
|
|
|
|
|
$operations = $syncService->scan();
|
|
|
@@ -232,15 +240,13 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
$this->assertEquals(
|
|
|
[
|
|
|
'[PUT thirdparties/1726]',
|
|
|
- 'address : `\n
|
|
|
-217, rue Raoul Follereau\n
|
|
|
-` => `21b baker street`',
|
|
|
+ "address : `\n217, rue Raoul Follereau\n` => `21b baker street`",
|
|
|
'zip : `74300` => `250 329`',
|
|
|
'town : `CLUSES` => `Londres`',
|
|
|
'email : `` => `email@email.com`',
|
|
|
- 'phone : `+33678403010` => `+331 02 03 04 05`',
|
|
|
+ 'phone : `+33678403010` => `+33 1 02 03 04 05`',
|
|
|
'parent : `` => `5086`',
|
|
|
- 'array_options.options_2iopeninfoopentalent : `` => ` : 3\n : 1\n : 1`'
|
|
|
+ "array_options.options_2iopeninfoopentalent : `` => `Nombre d'élèves : 1\nNombre d'adhérents : 3\nNombre d'accès admin : 1`"
|
|
|
],
|
|
|
$operations[0]->getChangeLog()
|
|
|
);
|
|
|
@@ -540,19 +546,15 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
}
|
|
|
|
|
|
public function testFormatContactPosition() {
|
|
|
- $this->translator->method('trans')->will(
|
|
|
- $this->returnCallback(function($mission, $params) {
|
|
|
- if ($mission == FunctionEnum::PRESIDENT()) {
|
|
|
- if ($params === ['gender' => 'X']) { return 'Président(e)'; }
|
|
|
- elseif ($params === ['gender' => 'M']) { return 'Président'; }
|
|
|
- elseif ($params === ['gender' => 'F']) { return 'Présidente'; }
|
|
|
- } elseif ($mission == FunctionEnum::DIRECTOR()) {
|
|
|
- if ($params === ['gender' => 'X']) { return 'Directeur(ice)'; }
|
|
|
- elseif ($params === ['gender' => 'M']) { return 'Directeur'; }
|
|
|
- elseif ($params === ['gender' => 'F']) { return 'Directrice'; }
|
|
|
- }
|
|
|
- throw new \AssertionError('translator->trans stub has no matching call for arguments ' . json_encode([$mission, $params]));
|
|
|
- })
|
|
|
+ $this->translator->method('trans')->willReturnMap(
|
|
|
+ [
|
|
|
+ [FunctionEnum::PRESIDENT()->getValue(), ['gender' => 'X'], null, null, 'Président(e)'],
|
|
|
+ [FunctionEnum::PRESIDENT()->getValue(), ['gender' => 'M'], null, null, 'Président'],
|
|
|
+ [FunctionEnum::PRESIDENT()->getValue(), ['gender' => 'F'], null, null, 'Présidente'],
|
|
|
+ [FunctionEnum::DIRECTOR()->getValue(), ['gender' => 'X'], null, null, 'Directeur(ice)'],
|
|
|
+ [FunctionEnum::DIRECTOR()->getValue(), ['gender' => 'M'], null, null, 'Directeur'],
|
|
|
+ [FunctionEnum::DIRECTOR()->getValue(), ['gender' => 'F'], null, null, 'Directrice'],
|
|
|
+ ]
|
|
|
);
|
|
|
|
|
|
$syncService = $this->newDolibarrSyncService();
|
|
|
@@ -590,10 +592,8 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
}
|
|
|
|
|
|
public function testFormatPhoneNumber() {
|
|
|
- $phoneNumber = new PhoneNumber();
|
|
|
- $phoneNumber->setCountryCode(33);
|
|
|
- $phoneNumber->setNationalNumber('1 02 03 04 05');
|
|
|
-
|
|
|
+ $phoneUtil = PhoneNumberUtil::getInstance();
|
|
|
+ $phoneNumber = $phoneUtil->parse('01 02 03 04 05', "FR");
|
|
|
$this->assertEquals(
|
|
|
'+33 1 02 03 04 05',
|
|
|
TestableDolibarrSyncService::formatPhoneNumber($phoneNumber)
|