|
|
@@ -15,19 +15,22 @@ use App\Entity\Person\Person;
|
|
|
use App\Enum\Access\FunctionEnum;
|
|
|
use App\Enum\Access\RoleEnum;
|
|
|
use App\Enum\Core\ContactPointTypeEnum;
|
|
|
+use App\Enum\Network\NetworkEnum;
|
|
|
use App\Enum\Organization\AddressPostalOrganizationTypeEnum;
|
|
|
use App\Enum\Organization\SettingsProductEnum;
|
|
|
use App\Repository\Access\AccessRepository;
|
|
|
use App\Repository\Access\FunctionTypeRepository;
|
|
|
use App\Repository\Organization\OrganizationRepository;
|
|
|
+use App\Service\Core\AddressPostalUtils;
|
|
|
use App\Service\Dolibarr\DolibarrApiService;
|
|
|
use App\Service\Dolibarr\DolibarrSyncService;
|
|
|
use App\Service\Rest\Operation\CreateOperation;
|
|
|
use App\Service\Rest\Operation\UpdateOperation;
|
|
|
+use App\Service\Utils\ArrayUtils;
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
-use JetBrains\PhpStorm\Pure;
|
|
|
use libphonenumber\PhoneNumber;
|
|
|
use libphonenumber\PhoneNumberUtil;
|
|
|
+use PHPUnit\Framework\MockObject\MockObject;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
use Symfony\Contracts\HttpClient\ResponseInterface;
|
|
|
@@ -35,27 +38,29 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|
|
|
|
|
class TestableDolibarrSyncService extends DolibarrSyncService {
|
|
|
public function getDolibarrSocietiesIndex(): array { return parent::getDolibarrSocietiesIndex(); }
|
|
|
- public static function findDolibarrContactFor(array $dolibarrContacts, Person $person): ?array { return parent::findDolibarrContactFor($dolibarrContacts, $person); }
|
|
|
+ public function findDolibarrContactFor(array $dolibarrContacts, Person $person): ?array { return parent::findDolibarrContactFor($dolibarrContacts, $person); }
|
|
|
public function getActiveMembersIndex(): array { return parent::getActiveMembersIndex(); }
|
|
|
- public static function sanitizeDolibarrData(?array $data): ?array { return parent::sanitizeDolibarrData($data); }
|
|
|
+ public function sanitizeDolibarrData(?array $data): ?array { return parent::sanitizeDolibarrData($data); }
|
|
|
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 function getOrganizationNetworkId(Organization $organization): ?int { return parent::getOrganizationNetworkId($organization); }
|
|
|
- public static function countWithMission(array $missions, array $members): int { return parent::countWithMission($missions, $members); }
|
|
|
+ public function countWithMission(array $missions, array $members): int { return parent::countWithMission($missions, $members); }
|
|
|
public function getPersonContact(Person $person): ?ContactPoint { return parent::getPersonContact($person); }
|
|
|
public function formatContactPosition(array $missions, ?string $gender = 'X'): string { return parent::formatContactPosition($missions, $gender); }
|
|
|
- public static function formatPhoneNumber(PhoneNumber $phoneNumber): string { return parent::formatPhoneNumber($phoneNumber); }
|
|
|
+ public function formatPhoneNumber(PhoneNumber $phoneNumber): string { return parent::formatPhoneNumber($phoneNumber); }
|
|
|
}
|
|
|
|
|
|
class DolibarrSyncServiceTest extends TestCase
|
|
|
{
|
|
|
- private OrganizationRepository $organizationRepository;
|
|
|
- private AccessRepository $accessRepository;
|
|
|
- private FunctionTypeRepository $functionTypeRepository;
|
|
|
- private DolibarrApiService $dolibarrApiService;
|
|
|
- private TranslatorInterface $translator;
|
|
|
- private LoggerInterface $logger;
|
|
|
+ private MockObject | OrganizationRepository $organizationRepository;
|
|
|
+ private MockObject | AccessRepository $accessRepository;
|
|
|
+ private MockObject | FunctionTypeRepository $functionTypeRepository;
|
|
|
+ private MockObject | DolibarrApiService $dolibarrApiService;
|
|
|
+ private MockObject | AddressPostalUtils $addressPostalUtils;
|
|
|
+ private MockObject | ArrayUtils $arrayUtils;
|
|
|
+ private MockObject | TranslatorInterface $translator;
|
|
|
+ private MockObject | LoggerInterface $logger;
|
|
|
|
|
|
public function setUp(): void {
|
|
|
$this->organizationRepository = $this->getMockBuilder(OrganizationRepository::class)
|
|
|
@@ -70,6 +75,12 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
$this->dolibarrApiService = $this->getMockBuilder(DolibarrApiService::class)
|
|
|
->disableOriginalConstructor()
|
|
|
->getMock();
|
|
|
+ $this->addressPostalUtils = $this->getMockBuilder(AddressPostalUtils::class)
|
|
|
+ ->disableOriginalConstructor()
|
|
|
+ ->getMock();
|
|
|
+ $this->arrayUtils = $this->getMockBuilder(ArrayUtils::class)
|
|
|
+ ->disableOriginalConstructor()
|
|
|
+ ->getMock();
|
|
|
$this->translator = $this->getMockBuilder(TranslatorInterface::class)
|
|
|
->disableOriginalConstructor()
|
|
|
->getMock();
|
|
|
@@ -83,53 +94,54 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
$this->logger->method('error')->willReturnSelf();
|
|
|
}
|
|
|
|
|
|
- #[Pure]
|
|
|
- private function newDolibarrSyncService(): TestableDolibarrSyncService
|
|
|
+ public function testScan(): void
|
|
|
{
|
|
|
- return new TestableDolibarrSyncService(
|
|
|
- $this->organizationRepository,
|
|
|
- $this->accessRepository,
|
|
|
- $this->functionTypeRepository,
|
|
|
- $this->dolibarrApiService,
|
|
|
- $this->translator,
|
|
|
- $this->logger
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- private function getJsonContentFromFixture(string $filename): array {
|
|
|
- $filepath = __DIR__ . '/fixtures/' . $filename;
|
|
|
- return json_decode(file_get_contents($filepath), true);
|
|
|
- }
|
|
|
-
|
|
|
- public function testScan() {
|
|
|
-
|
|
|
- // mock services and special methods from repos
|
|
|
- $this->dolibarrApiService
|
|
|
- ->expects($this->once())
|
|
|
- ->method('getAllClients')
|
|
|
- ->willReturn(
|
|
|
- $this->getJsonContentFromFixture('thirdparty.json')
|
|
|
- );
|
|
|
+ $dolibarrSyncService = $this->getMockBuilder(TestableDolibarrSyncService::class)
|
|
|
+ ->setConstructorArgs([$this->organizationRepository, $this->accessRepository, $this->functionTypeRepository,
|
|
|
+ $this->dolibarrApiService, $this->addressPostalUtils, $this->arrayUtils, $this->translator, $this->logger])
|
|
|
+ ->setMethodsExcept(['scan'])
|
|
|
+ ->getMock();
|
|
|
|
|
|
- $this->dolibarrApiService->method('getSociety')->willReturnMap(
|
|
|
- [
|
|
|
- [12097, ['id' => 711]],
|
|
|
- [91295, ['id' => 5086]]
|
|
|
+ $dolibarrSociety1 = [
|
|
|
+ 'id' => 1,
|
|
|
+ 'name' => 'Organization 10',
|
|
|
+ 'address' => '1 Rue Qwerty',
|
|
|
+ 'zip' => '01024',
|
|
|
+ 'town' => 'Ram',
|
|
|
+ 'email' => 'some@email.com',
|
|
|
+ 'phone' => null,
|
|
|
+ 'status' => 0,
|
|
|
+ 'parent' => '0',
|
|
|
+ 'array_options' => [
|
|
|
+ 'options_2iopeninfoopentalent' => '',
|
|
|
+ 'options_2iopen_software_opentalent' => 'Opentalent Artist'
|
|
|
]
|
|
|
- );
|
|
|
- $this->accessRepository
|
|
|
- ->expects($this->once())
|
|
|
- ->method('getAllActiveMembersAndMissions')
|
|
|
- ->willReturn(
|
|
|
- [
|
|
|
- ['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()],
|
|
|
- ]
|
|
|
- );
|
|
|
+ ];
|
|
|
+ $dolibarrSociety2 = ['id' => 2, "array_options" => []];
|
|
|
+ $dolibarrSociety3 = ['id' => 3, "array_options" => []];
|
|
|
+
|
|
|
+ // Get societies
|
|
|
+ $dolibarrSyncService
|
|
|
+ ->expects(self::once())
|
|
|
+ ->method('getDolibarrSocietiesIndex')
|
|
|
+ ->willReturn([
|
|
|
+ 10 => $dolibarrSociety1,
|
|
|
+ 20 => $dolibarrSociety2,
|
|
|
+ 30 => $dolibarrSociety3
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // Get members
|
|
|
+ $activeMembers1 = [11 => [FunctionEnum::PRESIDENT()->getValue()], 12 => [FunctionEnum::STUDENT()->getValue()], 13 => [FunctionEnum::TREASURER()->getValue()]];
|
|
|
+ $activeMembers2 = [21 => [FunctionEnum::PRESIDENT()->getValue()]];
|
|
|
+
|
|
|
+ $dolibarrSyncService
|
|
|
+ ->expects(self::once())
|
|
|
+ ->method('getActiveMembersIndex')
|
|
|
+ ->willReturn([
|
|
|
+ 10 => $activeMembers1,
|
|
|
+ 20 => $activeMembers2,
|
|
|
+ 30 => [],
|
|
|
+ ]);
|
|
|
|
|
|
// Function types
|
|
|
$functionType1 = $this->getMockBuilder(FunctionType::class)->getMock();
|
|
|
@@ -142,182 +154,321 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
->with(['roleByDefault' => RoleEnum::ROLE_ADMIN()->getValue()])
|
|
|
->willReturn([$functionType1, $functionType2]);
|
|
|
|
|
|
- // Organization's name
|
|
|
- $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
- $organization->method('getId')->willReturn(37306);
|
|
|
- $organization->method('getName')->willReturn("Etablissement d'Enseignement Artistique");
|
|
|
+ // Get CMF and FFEC ids
|
|
|
+ $this->dolibarrApiService->method('getSociety')->willReturnMap(
|
|
|
+ [
|
|
|
+ [12097, ['id' => 10]],
|
|
|
+ [91295, ['id' => 20]]
|
|
|
+ ]
|
|
|
+ );
|
|
|
+
|
|
|
+ // -- Loop over organizations --
|
|
|
+ $dolibarrSyncService
|
|
|
+ ->expects(self::exactly(5)) // 3 organizations and 2 contacts
|
|
|
+ ->method('sanitizeDolibarrData')
|
|
|
+ ->willReturnCallback(function ($args) { return $args; });
|
|
|
+
|
|
|
+ $organization1 = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+ $organization1->method('getId')->willReturn(10);
|
|
|
+ $organization1->method('getName')->willReturn('Organization 10');
|
|
|
+
|
|
|
+ $organization2 = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+ $organization2->method('getId')->willReturn(20);
|
|
|
+ $organization2->method('getName')->willReturn('Organization 20');
|
|
|
+
|
|
|
+ $this->organizationRepository->method('find')
|
|
|
+ ->willReturnMap([
|
|
|
+ [10, null, null, $organization1],
|
|
|
+ [20, null, null, $organization2],
|
|
|
+ [30, null, null, null]
|
|
|
+ ]);
|
|
|
|
|
|
- // Postal address
|
|
|
- $organizationAddressPostal = $this->getMockBuilder(OrganizationAddressPostal::class)->getMock();
|
|
|
$addressPostal = $this->getMockBuilder(AddressPostal::class)->getMock();
|
|
|
- $addressPostal->method('getStreetAddress')->willReturn('21b baker street');
|
|
|
- $addressPostal->method('getStreetAddressSecond')->willReturn('');
|
|
|
- $addressPostal->method('getStreetAddressThird')->willReturn('');
|
|
|
- $addressPostal->method('getAddressOwner')->willReturn('');
|
|
|
- $addressPostal->method('getPostalCode')->willReturn('250 329');
|
|
|
- $addressPostal->method('getAddressCity')->willReturn('Londres');
|
|
|
- $organizationAddressPostal->method('getType')->willReturn(AddressPostalOrganizationTypeEnum::ADDRESS_CONTACT()->getValue());
|
|
|
- $organizationAddressPostal->method('getAddressPostal')->willReturn($addressPostal);
|
|
|
- $organization->method('getOrganizationAddressPostals')->willReturn(
|
|
|
- new ArrayCollection([$organizationAddressPostal])
|
|
|
- );
|
|
|
-
|
|
|
- // 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 = $phoneUtil->parse('01 02 03 04 05', 'FR');
|
|
|
- $contactPoint->method('getTelphone')->willReturn($phoneNumber);
|
|
|
- $organization->method('getContactPoints')->willReturn(
|
|
|
- new ArrayCollection([$contactPoint])
|
|
|
- );
|
|
|
+ $dolibarrSyncService
|
|
|
+ ->expects(self::exactly(2))
|
|
|
+ ->method('getOrganizationPostalAddress')
|
|
|
+ ->willReturnMap([
|
|
|
+ [$organization1, $addressPostal],
|
|
|
+ [$organization2, null],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $this->addressPostalUtils
|
|
|
+ ->method('getFullStreetAddress')
|
|
|
+ ->with($addressPostal)
|
|
|
+ ->willReturn('1 Rue Azerty');
|
|
|
+
|
|
|
+ $addressPostal->method('getAddressOwner')->willReturn('Mr Keyboard');
|
|
|
+ $addressPostal->method('getPostalCode')->willReturn('01110');
|
|
|
+ $addressPostal->method('getAddressCity')->willReturn('ByteCity');
|
|
|
+
|
|
|
+ $dolibarrSyncService
|
|
|
+ ->expects(self::exactly(2))
|
|
|
+ ->method('getOrganizationEmail')
|
|
|
+ ->willReturnMap([
|
|
|
+ [$organization1, 'foo@bar.net'],
|
|
|
+ [$organization2, null],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $dolibarrSyncService
|
|
|
+ ->expects(self::exactly(2))
|
|
|
+ ->method('getOrganizationPhone')
|
|
|
+ ->willReturnMap([
|
|
|
+ [$organization1, '0102030405'],
|
|
|
+ [$organization2, null],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $dolibarrSyncService
|
|
|
+ ->expects(self::exactly(2))
|
|
|
+ ->method('getOrganizationNetworkId')
|
|
|
+ ->willReturnMap([
|
|
|
+ [$organization1, NetworkEnum::CMF()->getValue()],
|
|
|
+ [$organization2, null],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $settings1 = $this->getMockBuilder(Settings::class)->getMock();
|
|
|
+ $settings1->method('getProduct')->willReturn(SettingsProductEnum::SCHOOL()->getValue());
|
|
|
+ $organization1->method('getSettings')->willReturn($settings1);
|
|
|
+
|
|
|
+ $settings2 = $this->getMockBuilder(Settings::class)->getMock();
|
|
|
+ $settings1->method('getProduct')->willReturn(SettingsProductEnum::ARTIST()->getValue());
|
|
|
+ $organization2->method('getSettings')->willReturn($settings2);
|
|
|
+
|
|
|
+ $dolibarrSyncService->method('countWithMission')->willReturnMap([
|
|
|
+ [[FunctionEnum::STUDENT()->getValue()], $activeMembers1, 1],
|
|
|
+ [[FunctionEnum::ADHERENT()->getValue()], $activeMembers1, 2],
|
|
|
+ [[FunctionEnum::DIRECTOR()->getValue(), FunctionEnum::PRESIDENT()->getValue()], $activeMembers1, 1],
|
|
|
+ [[FunctionEnum::DIRECTOR()->getValue(), FunctionEnum::PRESIDENT()->getValue()], $activeMembers2, 2]
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $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"],
|
|
|
+ ['school', [], null, null, 'Opentalent School'],
|
|
|
+ ['artist', [], null, null, 'Opentalent Artist'],
|
|
|
+ ['Mr', [], null, null, 'MR'],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $this->arrayUtils
|
|
|
+ ->expects(self::exactly(3))
|
|
|
+ ->method('getChanges')
|
|
|
+ ->willReturnCallback(
|
|
|
+ function (array $initialArray, array $newArray, bool $recursive = false, ?callable $callback = null) {
|
|
|
+ if (in_array('name', $newArray, true)) {
|
|
|
+ // Organization 1 name is already defined and has not been changed
|
|
|
+ unset($newArray['name']);
|
|
|
+ }
|
|
|
+ if (in_array('statut', $newArray, true)) {
|
|
|
+ // Contact 1 statut is already defined and has not been changed
|
|
|
+ unset($newArray['statut']);
|
|
|
+ }
|
|
|
+ return $newArray;
|
|
|
+ }
|
|
|
+ );
|
|
|
|
|
|
- // Network
|
|
|
- $network = $this->getMockBuilder(Network::class)->getMock();
|
|
|
- $network->method('getId')->willReturn(3);
|
|
|
- $networkOrganization = $this->getMockBuilder(NetworkOrganization::class)->getMock();
|
|
|
- $networkOrganization->method('getNetwork')->willReturn($network);
|
|
|
- $organization->method('getNetworkOrganizations')->willReturn(new ArrayCollection([$networkOrganization]));
|
|
|
+ $contactData1 = [
|
|
|
+ 'id' => '1',
|
|
|
+ 'civility_code' => '',
|
|
|
+ 'lastname' => 'Dupond',
|
|
|
+ 'firstname' => 'Bob',
|
|
|
+ 'email' => 'abcd@mail.com',
|
|
|
+ 'phone_pro' => '+33478570000',
|
|
|
+ 'phone_mobile' => '+33682980000',
|
|
|
+ 'poste' => 'Secrétaire',
|
|
|
+ 'statut' => '1',
|
|
|
+ 'array_options' => [
|
|
|
+ 'options_2iopen_person_id' => ''
|
|
|
+ ]
|
|
|
+ ];
|
|
|
|
|
|
- // Product
|
|
|
- $settings = $this->getMockBuilder(Settings::class)->getMock();
|
|
|
- $settings->method('getProduct')->willReturn(SettingsProductEnum::SCHOOL()->getValue());
|
|
|
- $organization->method('getSettings')->willReturn($settings);
|
|
|
+ // An obsolete contact that should be disabled
|
|
|
+ $obsoleteContactData = [
|
|
|
+ 'id' => '4',
|
|
|
+ 'lastname' => 'Doe',
|
|
|
+ 'firstname' => 'John',
|
|
|
+ 'statut' => '1',
|
|
|
+ 'array_options' => [
|
|
|
+ 'options_2iopen_person_id' => 300
|
|
|
+ ]
|
|
|
+ ];
|
|
|
|
|
|
- // Get dolibarr contacts
|
|
|
- $this->dolibarrApiService
|
|
|
- ->method('getContacts')
|
|
|
- ->with(1726)
|
|
|
- ->willReturn(
|
|
|
- array_filter(
|
|
|
- $this->getJsonContentFromFixture('contacts.json'),
|
|
|
- static function ($c) {
|
|
|
- return in_array(
|
|
|
- (int)$c["array_options"]["options_2iopen_person_id"],
|
|
|
- [
|
|
|
- 108939, // existing person, to be updated
|
|
|
- 156252 // no matching person, to be deleted
|
|
|
- // a new contact shall be created too
|
|
|
- ]
|
|
|
- ); }
|
|
|
- )
|
|
|
- );
|
|
|
+ // An obsolete contact that should is already disabled
|
|
|
+ $obsoleteContactData2 = [
|
|
|
+ 'id' => '5',
|
|
|
+ 'lastname' => 'Foo',
|
|
|
+ 'firstname' => 'John',
|
|
|
+ 'statut' => '0',
|
|
|
+ 'array_options' => [
|
|
|
+ 'options_2iopen_person_id' => 400
|
|
|
+ ]
|
|
|
+ ];
|
|
|
|
|
|
- $this->organizationRepository->method('find')->willReturn($organization);
|
|
|
+ $dolibarrSocietyContacts1 = [$contactData1, $obsoleteContactData, $obsoleteContactData2];
|
|
|
+ $dolibarrSocietyContacts2 = [];
|
|
|
|
|
|
- $access1 = $this->getMockBuilder(Access::class)->getMock();
|
|
|
- $access1->method('getId')->willReturn(1);
|
|
|
+ $this->dolibarrApiService->method('getContacts')->willReturnMap([
|
|
|
+ [1, $dolibarrSocietyContacts1],
|
|
|
+ [2, $dolibarrSocietyContacts2]
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // Loop over contacts
|
|
|
+ // NB: Student will be skipped since it has no office role
|
|
|
|
|
|
$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])
|
|
|
- );
|
|
|
+ $person1->method('getId')->willReturn(100);
|
|
|
+ $person1->method('getName')->willReturn('Dupont');
|
|
|
+ $person1->method('getGivenName')->willReturn('Hercules');
|
|
|
+ $person1->method('getGender')->willReturn('Mr');
|
|
|
+
|
|
|
+ $person2 = $this->getMockBuilder(Person::class)->getMock();
|
|
|
+ $person2->method('getId')->willReturn(200);
|
|
|
+ $person2->method('getName')->willReturn('Simpson');
|
|
|
+ $person2->method('getGivenName')->willReturn('Lisa');
|
|
|
+ $person2->method('getGender')->willReturn(null);
|
|
|
+
|
|
|
+ // An invalid person that should be ignored
|
|
|
+ $invalidPerson = $this->getMockBuilder(Person::class)->getMock();
|
|
|
+ $invalidPerson->method('getId')->willReturn(900);
|
|
|
+ $invalidPerson->method('getName')->willReturn('');
|
|
|
+ $invalidPerson->method('getGivenName')->willReturn('');
|
|
|
+
|
|
|
+
|
|
|
+ $access1 = $this->getMockBuilder(Access::class)->getMock();
|
|
|
$access1->method('getPerson')->willReturn($person1);
|
|
|
|
|
|
$access2 = $this->getMockBuilder(Access::class)->getMock();
|
|
|
- $access2->method('getId')->willReturn(1);
|
|
|
-
|
|
|
- $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],
|
|
|
- ]
|
|
|
- );
|
|
|
+ $access3 = $this->getMockBuilder(Access::class)->getMock();
|
|
|
+ $access3->method('getPerson')->willReturn($invalidPerson);
|
|
|
|
|
|
- $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"],
|
|
|
- ['school', [], null, null, "Opentalent School"],
|
|
|
- ]
|
|
|
+ $this->accessRepository->method('find')->willReturnMap([
|
|
|
+ [11, null, null, $access1],
|
|
|
+ [21, null, null, $access2],
|
|
|
+ [13, null, null, $access3],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $dolibarrSyncService->method('findDolibarrContactFor')->willReturnMap([
|
|
|
+ [$dolibarrSocietyContacts1, $person1, $contactData1],
|
|
|
+ [$dolibarrSocietyContacts2, $person2, null]
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $contactPoint1 = $this->getMockBuilder(ContactPoint::class)->getMock();
|
|
|
+ $contactPoint1->method('getEmail')->willReturn('mail@domain.net');
|
|
|
+
|
|
|
+ $phone = $this->getMockBuilder(PhoneNumber::class)->getMock();
|
|
|
+ $contactPoint1->method('getTelphone')->willReturn($phone);
|
|
|
+
|
|
|
+ $mobilePhone = $this->getMockBuilder(PhoneNumber::class)->getMock();
|
|
|
+ $contactPoint1->method('getMobilPhone')->willReturn($mobilePhone);
|
|
|
+
|
|
|
+ $dolibarrSyncService->method('getPersonContact')->willReturnMap([
|
|
|
+ [$person1, $contactPoint1],
|
|
|
+ [$person2, null],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $dolibarrSyncService->method('formatPhoneNumber')->willReturnMap([
|
|
|
+ [$phone, '0102030405'],
|
|
|
+ [$mobilePhone, '0607080910'],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $dolibarrSyncService->method('formatContactPosition')->willReturnMap([
|
|
|
+ [[FunctionEnum::PRESIDENT()->getValue()], 'Mr', 'Président'],
|
|
|
+ [[FunctionEnum::PRESIDENT()->getValue()], null, 'Président(e)'],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $this->logger->expects(self::exactly(2))->method('error')->withConsecutive(
|
|
|
+ ["Person 900 miss a lastname and/or a firstname, ignored."],
|
|
|
+ ["Organization 30 not found in the Opentalent DB"],
|
|
|
);
|
|
|
|
|
|
- $syncService = $this->newDolibarrSyncService();
|
|
|
+ $progressionCallbackExpectedCalls = [[1, 3], [2, 3], [3, 3]];
|
|
|
|
|
|
- $operations = $syncService->scan();
|
|
|
+ $progressionCallback = static function ($i, $total) use (&$progressionCallbackExpectedCalls) {
|
|
|
+ [$expectedI, $expectedTotal] = array_shift($progressionCallbackExpectedCalls);
|
|
|
+ if ($i !== $expectedI || $total !== $expectedTotal) {
|
|
|
+ throw new \AssertionError(
|
|
|
+ 'Progression callback error, expected parameters are (' . $expectedI . ',' . $expectedTotal . ')' .
|
|
|
+ ', got (' . $i . ', ' . $total . ')'
|
|
|
+ );
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
- $this->assertCount(4, $operations);
|
|
|
- $this->assertEquals(
|
|
|
- [
|
|
|
- '[PUT thirdparties/1726]',
|
|
|
- "address : `\n217, rue Raoul Follereau\n` => `21b baker street`",
|
|
|
- 'zip : `74300` => `250 329`',
|
|
|
- 'town : `CLUSES` => `Londres`',
|
|
|
- 'email : `` => `email@email.com`',
|
|
|
- 'phone : `+33678403010` => `+33102030405`',
|
|
|
- 'parent : `` => `711`',
|
|
|
- "array_options.options_2iopen_software_opentalent : `` => `Opentalent School`",
|
|
|
- "array_options.options_2iopeninfoopentalent : `` => `Nombre d'élèves : 1\nNombre d'adhérents : 3\nNombre d'accès admin : 1`"
|
|
|
+ $operations = $dolibarrSyncService->scan($progressionCallback);
|
|
|
+
|
|
|
+ $this->assertCount(5, $operations);
|
|
|
|
|
|
+ $this->assertEqualsCanonicalizing(
|
|
|
+ [
|
|
|
+ '[PUT thirdparties/1]',
|
|
|
+ "address : `1 Rue Qwerty` => `Mr Keyboard\n1 Rue Azerty`",
|
|
|
+ 'zip : `01024` => `01110`',
|
|
|
+ 'town : `Ram` => `ByteCity`',
|
|
|
+ 'email : `some@email.com` => `foo@bar.net`',
|
|
|
+ 'phone : `` => `0102030405`',
|
|
|
+ 'parent : `0` => `10`',
|
|
|
+ "array_options.options_2iopen_software_opentalent : `Opentalent Artist` => `Opentalent School`",
|
|
|
+ "array_options.options_2iopeninfoopentalent : `` => `Nombre d'élèves : 1\nNombre d'adhérents : 2\nNombre d'accès admin : 1`",
|
|
|
+ 'status : `0` => `1`'
|
|
|
],
|
|
|
$operations[0]->getChangeLog()
|
|
|
);
|
|
|
- $this->assertEquals(
|
|
|
+
|
|
|
+ $this->assertEqualsCanonicalizing(
|
|
|
[
|
|
|
- '[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` => ``'
|
|
|
+ '[PUT contacts/1]',
|
|
|
+ 'civility_code : `` => `MR`',
|
|
|
+ 'lastname : `Dupond` => `Dupont`',
|
|
|
+ 'firstname : `Bob` => `Hercules`',
|
|
|
+ 'email : `abcd@mail.com` => `mail@domain.net`',
|
|
|
+ 'phone_pro : `+33478570000` => `0102030405`',
|
|
|
+ 'phone_mobile : `+33682980000` => `0607080910`',
|
|
|
+ 'poste : `Secrétaire` => `Président`',
|
|
|
+ 'array_options.options_2iopen_person_id : `` => `100`'
|
|
|
],
|
|
|
$operations[1]->getChangeLog()
|
|
|
);
|
|
|
- $this->assertEquals(
|
|
|
+
|
|
|
+ $this->assertEqualsCanonicalizing(
|
|
|
+ ['[PUT contacts/4]', 'statut : `1` => `0`'],
|
|
|
+ $operations[2]->getChangeLog()
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->assertEqualsCanonicalizing(
|
|
|
+ [
|
|
|
+ '[PUT thirdparties/2]',
|
|
|
+ 'address : (new) => ``',
|
|
|
+ 'email : (new) => ``',
|
|
|
+ 'name : (new) => `Organization 20`',
|
|
|
+ 'parent : (new) => ``',
|
|
|
+ 'phone : (new) => ``',
|
|
|
+ 'status : (new) => `1`',
|
|
|
+ 'town : (new) => ``',
|
|
|
+ 'zip : (new) => ``',
|
|
|
+ 'array_options.options_2iopeninfoopentalent : (new) => `Nombre d\'accès admin : 2`',
|
|
|
+ ],
|
|
|
+ $operations[3]->getChangeLog()
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->assertEqualsCanonicalizing(
|
|
|
[
|
|
|
'[POST contacts]',
|
|
|
'civility_code : (new) => ``',
|
|
|
- 'lastname : (new) => `Watson`',
|
|
|
- 'firstname : (new) => `John`',
|
|
|
+ 'lastname : (new) => `Simpson`',
|
|
|
+ 'firstname : (new) => `Lisa`',
|
|
|
'email : (new) => ``',
|
|
|
'phone_pro : (new) => ``',
|
|
|
'phone_mobile : (new) => ``',
|
|
|
- 'poste : (new) => ``',
|
|
|
+ 'poste : (new) => `Président(e)`',
|
|
|
'statut : (new) => `1`',
|
|
|
- 'array_options.options_2iopen_person_id : (new) => `1000`',
|
|
|
- 'socid : (new) => `1726`'
|
|
|
+ 'array_options.options_2iopen_person_id : (new) => `200`',
|
|
|
+ 'socid : (new) => `2`'
|
|
|
],
|
|
|
- $operations[2]->getChangeLog()
|
|
|
- );
|
|
|
- $this->assertEquals(
|
|
|
- ['[PUT contacts/5869]', 'statut : `1` => `0`'],
|
|
|
- $operations[3]->getChangeLog()
|
|
|
+ $operations[4]->getChangeLog()
|
|
|
);
|
|
|
+
|
|
|
+ $this->assertCount(0, $progressionCallbackExpectedCalls);
|
|
|
}
|
|
|
|
|
|
public function testExecuteError()
|