|
|
@@ -2,20 +2,27 @@
|
|
|
|
|
|
namespace App\Tests\Service\Dolibarr;
|
|
|
|
|
|
+use App\Entity\Access\Access;
|
|
|
+use App\Entity\Access\FunctionType;
|
|
|
use App\Entity\Core\AddressPostal;
|
|
|
use App\Entity\Core\ContactPoint;
|
|
|
+use App\Entity\Network\Network;
|
|
|
+use App\Entity\Network\NetworkOrganization;
|
|
|
use App\Entity\Organization\Organization;
|
|
|
use App\Entity\Organization\OrganizationAddressPostal;
|
|
|
+use App\Entity\Organization\Settings;
|
|
|
use App\Entity\Person\Person;
|
|
|
use App\Enum\Access\FunctionEnum;
|
|
|
+use App\Enum\Access\RoleEnum;
|
|
|
use App\Enum\Core\ContactPointTypeEnum;
|
|
|
use App\Enum\Organization\AddressPostalOrganizationTypeEnum;
|
|
|
+use App\Enum\Organization\SettingsProductEnum;
|
|
|
use App\Repository\Access\AccessRepository;
|
|
|
use App\Repository\Access\FunctionTypeRepository;
|
|
|
-use App\Repository\Core\ContactPointRepository;
|
|
|
use App\Repository\Organization\OrganizationRepository;
|
|
|
use App\Service\Dolibarr\DolibarrApiService;
|
|
|
use App\Service\Dolibarr\DolibarrSyncService;
|
|
|
+use Doctrine\Common\Collections\ArrayCollection;
|
|
|
use JetBrains\PhpStorm\Pure;
|
|
|
use libphonenumber\PhoneNumber;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
@@ -41,7 +48,6 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
{
|
|
|
private OrganizationRepository $organizationRepository;
|
|
|
private AccessRepository $accessRepository;
|
|
|
- private ContactPointRepository $contactPointRepository;
|
|
|
private FunctionTypeRepository $functionTypeRepository;
|
|
|
private DolibarrApiService $dolibarrApiService;
|
|
|
private TranslatorInterface $translator;
|
|
|
@@ -54,9 +60,6 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
$this->accessRepository = $this->getMockBuilder(AccessRepository::class)
|
|
|
->disableOriginalConstructor()
|
|
|
->getMock();
|
|
|
- $this->contactPointRepository = $this->getMockBuilder(ContactPointRepository::class)
|
|
|
- ->disableOriginalConstructor()
|
|
|
- ->getMock();
|
|
|
$this->functionTypeRepository = $this->getMockBuilder(FunctionTypeRepository::class)
|
|
|
->disableOriginalConstructor()
|
|
|
->getMock();
|
|
|
@@ -69,6 +72,11 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
$this->logger = $this->getMockBuilder(LoggerInterface::class)
|
|
|
->disableOriginalConstructor()
|
|
|
->getMock();
|
|
|
+
|
|
|
+ $this->logger->method('info')->willReturnSelf();
|
|
|
+ $this->logger->method('debug')->willReturnSelf();
|
|
|
+ $this->logger->method('warning')->willReturnSelf();
|
|
|
+ $this->logger->method('error')->willReturnSelf();
|
|
|
}
|
|
|
|
|
|
#[Pure]
|
|
|
@@ -77,7 +85,6 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
return new TestableDolibarrSyncService(
|
|
|
$this->organizationRepository,
|
|
|
$this->accessRepository,
|
|
|
- $this->contactPointRepository,
|
|
|
$this->functionTypeRepository,
|
|
|
$this->dolibarrApiService,
|
|
|
$this->translator,
|
|
|
@@ -90,6 +97,167 @@ class DolibarrSyncServiceTest extends TestCase
|
|
|
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')
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->dolibarrApiService->method('getSociety')->willReturnMap(
|
|
|
+ [
|
|
|
+ [12097, ['id' => 711]],
|
|
|
+ [91295, ['id' => 5086]]
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ $this->accessRepository
|
|
|
+ ->expects($this->once())
|
|
|
+ ->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()],
|
|
|
+ ]
|
|
|
+ );
|
|
|
+
|
|
|
+ // Function types
|
|
|
+ $functionType1 = $this->getMockBuilder(FunctionType::class)->getMock();
|
|
|
+ $functionType1->method('getMission')->willReturn(FunctionEnum::DIRECTOR()->getValue());
|
|
|
+ $functionType2 = $this->getMockBuilder(FunctionType::class)->getMock();
|
|
|
+ $functionType2->method('getMission')->willReturn(FunctionEnum::PRESIDENT()->getValue());
|
|
|
+ $this->functionTypeRepository
|
|
|
+ ->expects($this->once())
|
|
|
+ ->method('findBy')
|
|
|
+ ->with(['roleByDefault' => RoleEnum::ROLE_ADMIN()->getValue()])
|
|
|
+ ->willReturn([$functionType1, $functionType2]);
|
|
|
+
|
|
|
+ // Organization's name
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+ $organization->method('getName')->willReturn("Etablissement d'Enseignement Artistique");
|
|
|
+
|
|
|
+ // 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
|
|
|
+ $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');
|
|
|
+ $contactPoint->method('getTelphone')->willReturn($phoneNumber);
|
|
|
+ $organization->method('getContactPoints')->willReturn(
|
|
|
+ new ArrayCollection([$contactPoint])
|
|
|
+ );
|
|
|
+
|
|
|
+ // Network
|
|
|
+ $network = $this->getMockBuilder(Network::class)->getMock();
|
|
|
+ $network->method('getId')->willReturn(91295);
|
|
|
+ $networkOrganization = $this->getMockBuilder(NetworkOrganization::class)->getMock();
|
|
|
+ $networkOrganization->method('getNetwork')->willReturn($network);
|
|
|
+ $organization->method('getNetworkOrganizations')->willReturn(new ArrayCollection([$networkOrganization]));
|
|
|
+
|
|
|
+ // Product
|
|
|
+ $settings = $this->getMockBuilder(Settings::class)->getMock();
|
|
|
+ $settings->method('getProduct')->willReturn(SettingsProductEnum::SCHOOL()->getValue());
|
|
|
+ $organization->method('getSettings')->willReturn($settings);
|
|
|
+
|
|
|
+ // Get dolibarr contacts
|
|
|
+ $this->dolibarrApiService
|
|
|
+ ->method('getOpentalentContacts')
|
|
|
+ ->with(1726)
|
|
|
+ ->willReturn(
|
|
|
+ array_filter(
|
|
|
+ $this->getJsonContentFromFixture('contacts.json'),
|
|
|
+ function ($c) {
|
|
|
+ return in_array(
|
|
|
+ (int)$c["array_options"]["options_2iopen_person_id"],
|
|
|
+ [108939, 156252, 302117]
|
|
|
+ ); }
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ $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');
|
|
|
+
|
|
|
+ $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');
|
|
|
+ $personContactPoint->method('getTelphone')->willReturn($phoneNumber);
|
|
|
+ $personContactPoint->method('getMobilPhone')->willReturn(null);
|
|
|
+ $person->method('getContactPoints')->willReturn(
|
|
|
+ new ArrayCollection([$personContactPoint])
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $access->method('getPerson')->willReturn($person);
|
|
|
+ $this->accessRepository->method('find')->willReturn($access);
|
|
|
+
|
|
|
+ $syncService = $this->newDolibarrSyncService();
|
|
|
+
|
|
|
+ $operations = $syncService->scan();
|
|
|
+
|
|
|
+ $this->assertCount(4, $operations);
|
|
|
+
|
|
|
+ $this->assertEquals(
|
|
|
+ [
|
|
|
+ '[PUT thirdparties/1726]',
|
|
|
+ 'address : `\n
|
|
|
+217, 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`',
|
|
|
+ 'parent : `` => `5086`',
|
|
|
+ 'array_options.options_2iopeninfoopentalent : `` => ` : 3\n : 1\n : 1`'
|
|
|
+ ],
|
|
|
+ $operations[0]->getChangeLog()
|
|
|
+ );
|
|
|
+ $this->assertEquals(
|
|
|
+ ['PUT contact/5868', ''],
|
|
|
+ $operations[1]->getChangeLog()
|
|
|
+ );
|
|
|
+ $this->assertEquals(
|
|
|
+ ['PUT thirdparty/5869', ''],
|
|
|
+ $operations[2]->getChangeLog()
|
|
|
+ );
|
|
|
+ $this->assertEquals(
|
|
|
+ ['PUT thirdparty/5871', ''],
|
|
|
+ $operations[2]->getChangeLog()
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
public function testGetDolibarrSocietiesIndex() {
|
|
|
$this->dolibarrApiService
|
|
|
->expects($this->once())
|