associate location on ms calendar remote

This commit is contained in:
2022-07-01 12:12:48 +02:00
parent 014e281d13
commit 2a6974610f
18 changed files with 359 additions and 28 deletions

View File

@@ -0,0 +1,67 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\CalendarBundle\Tests\RemoteCalendar\Connector\MSGraph;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\AddressConverter;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Country;
use Chill\MainBundle\Entity\PostalCode;
use Chill\MainBundle\Templating\Entity\AddressRender;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\Templating\EngineInterface;
/**
* @internal
* @coversNothing
*/
final class AddressConverterTest extends TestCase
{
use ProphecyTrait;
public function testConvertAddress()
{
$country = (new Country())->setName(['fr' => 'Belgique']);
$postalCode = (new PostalCode())->setName('Houte-Si-Plout')->setCode('4122')
->setCountry($country);
$address = (new Address())->setPostcode($postalCode)->setStreet("Rue de l'Église")
->setStreetNumber('15B')->setBuildingName('Résidence de la Truite');
$actual = $this->buildAddressConverter()->addressToRemote($address);
$this->assertArrayHasKey('city', $actual);
$this->assertStringContainsString($actual['city'], 'Houte-Si-Plout');
$this->assertArrayHasKey('postalCode', $actual);
$this->assertStringContainsString($actual['postalCode'], '4122');
$this->assertArrayHasKey('countryOrRegion', $actual);
$this->assertStringContainsString('Belgique', $actual['countryOrRegion']);
$this->assertArrayHasKey('street', $actual);
$this->assertStringContainsString('Rue de l\'Église', $actual['street']);
$this->assertStringContainsString('15B', $actual['street']);
$this->assertStringContainsString('Résidence de la Truite', $actual['street']);
}
private function buildAddressConverter(): AddressConverter
{
$engine = $this->prophesize(EngineInterface::class);
$translatableStringHelper = $this->prophesize(TranslatableStringHelperInterface::class);
$translatableStringHelper->localize(Argument::type('array'))->will(static function ($args): string {
return ($args[0] ?? ['fr' => 'not provided'])['fr'] ?? 'not provided';
});
$addressRender = new AddressRender($engine->reveal(), $translatableStringHelper->reveal());
return new AddressConverter($addressRender, $translatableStringHelper->reveal());
}
}

View File

@@ -0,0 +1,79 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\CalendarBundle\Tests\RemoteCalendar\Connector\MSGraph;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\AddressConverter;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\LocationConverter;
use Chill\MainBundle\Doctrine\Model\Point;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\AddressReference;
use Chill\MainBundle\Entity\Location;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
/**
* @internal
* @coversNothing
*/
final class LocationConverterTest extends TestCase
{
use ProphecyTrait;
public function testConvertToRemoteWithAddressWithoutPoint(): void
{
$location = (new Location())->setName('display')->setAddress($address = new Address());
$address->setAddressReference($reference = new AddressReference());
$actual = $this->buildLocationConverter()->locationToRemote($location);
$this->assertArrayHasKey('address', $actual);
$this->assertArrayNotHasKey('coordinates', $actual);
$this->assertArrayHasKey('displayName', $actual);
$this->assertEquals('display', $actual['displayName']);
}
public function testConvertToRemoteWithAddressWithPoint(): void
{
$location = (new Location())->setName('display')->setAddress($address = new Address());
$address->setAddressReference($reference = new AddressReference());
$reference->setPoint($point = Point::fromLonLat(5.3134, 50.3134));
$actual = $this->buildLocationConverter()->locationToRemote($location);
$this->assertArrayHasKey('address', $actual);
$this->assertArrayHasKey('coordinates', $actual);
$this->assertEquals(['latitude' => 50.3134, 'longitude' => 5.3134], $actual['coordinates']);
$this->assertArrayHasKey('displayName', $actual);
$this->assertEquals('display', $actual['displayName']);
}
public function testConvertToRemoteWithoutAddressWithoutPoint(): void
{
$location = (new Location())->setName('display');
$actual = $this->buildLocationConverter()->locationToRemote($location);
$this->assertArrayNotHasKey('address', $actual);
$this->assertArrayNotHasKey('coordinates', $actual);
$this->assertArrayHasKey('displayName', $actual);
$this->assertEquals('display', $actual['displayName']);
}
private function buildLocationConverter(): LocationConverter
{
$addressConverter = $this->prophesize(AddressConverter::class);
$addressConverter->addressToRemote(Argument::type(Address::class))->willReturn(['street' => 'dummy']);
return new LocationConverter($addressConverter->reveal());
}
}