mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Merge branch '111_exports_suite' into calendar/finalization
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
<?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 Services\Import;
|
||||
|
||||
use Chill\MainBundle\Entity\PostalCode;
|
||||
use Chill\MainBundle\Repository\AddressReferenceRepository;
|
||||
use Chill\MainBundle\Repository\PostalCodeRepository;
|
||||
use Chill\MainBundle\Service\Import\AddressReferenceBaseImporter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class AddressReferenceBaseImporterTest extends KernelTestCase
|
||||
{
|
||||
private AddressReferenceRepository $addressReferenceRepository;
|
||||
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
private AddressReferenceBaseImporter $importer;
|
||||
|
||||
private PostalCodeRepository $postalCodeRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
self::bootKernel();
|
||||
|
||||
$this->importer = self::$container->get(AddressReferenceBaseImporter::class);
|
||||
$this->addressReferenceRepository = self::$container->get(AddressReferenceRepository::class);
|
||||
$this->entityManager = self::$container->get(EntityManagerInterface::class);
|
||||
$this->postalCodeRepository = self::$container->get(PostalCodeRepository::class);
|
||||
}
|
||||
|
||||
public function testImportAddress(): void
|
||||
{
|
||||
$postalCode = (new PostalCode())
|
||||
->setRefPostalCodeId($postalCodeId = '1234' . uniqid())
|
||||
->setPostalCodeSource('testing')
|
||||
->setCode('TEST456')
|
||||
->setName('testing');
|
||||
|
||||
$this->entityManager->persist($postalCode);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->importer->importAddress(
|
||||
'0000',
|
||||
$postalCodeId,
|
||||
'TEST456',
|
||||
'Rue test abccc-guessed',
|
||||
'-1',
|
||||
'unit-test',
|
||||
50.0,
|
||||
5.0,
|
||||
4326
|
||||
);
|
||||
|
||||
$this->importer->finalize();
|
||||
|
||||
$addresses = $this->addressReferenceRepository->findByPostalCodePattern(
|
||||
$postalCode,
|
||||
'Rue test abcc guessed'
|
||||
);
|
||||
|
||||
$this->assertCount(1, $addresses);
|
||||
$this->assertEquals('Rue test abccc-guessed', $addresses[0]->getStreet());
|
||||
|
||||
$previousAddressId = $addresses[0]->getId();
|
||||
|
||||
$this->entityManager->clear();
|
||||
|
||||
$this->importer->importAddress(
|
||||
'0000',
|
||||
$postalCodeId,
|
||||
'TEST456',
|
||||
'Rue test abccc guessed fixed',
|
||||
'-1',
|
||||
'unit-test',
|
||||
50.0,
|
||||
5.0,
|
||||
4326
|
||||
);
|
||||
|
||||
$this->importer->finalize();
|
||||
|
||||
$addresses = $this->addressReferenceRepository->findByPostalCodePattern(
|
||||
$postalCode,
|
||||
'abcc guessed fixed'
|
||||
);
|
||||
|
||||
$this->assertCount('1', $addresses);
|
||||
$this->assertEquals('Rue test abccc guessed fixed', $addresses[0]->getStreet());
|
||||
$this->assertEquals($previousAddressId, $addresses[0]->getId());
|
||||
}
|
||||
}
|
@@ -0,0 +1,100 @@
|
||||
<?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 Services\Import;
|
||||
|
||||
use Chill\MainBundle\Service\Import\GeographicalUnitBaseImporter;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class GeographicalUnitBaseImporterTest extends KernelTestCase
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
self::bootKernel();
|
||||
|
||||
$this->connection = self::$container->get(Connection::class);
|
||||
$this->entityManager = self::$container->get(EntityManagerInterface::class);
|
||||
}
|
||||
|
||||
public function testImportUnit(): void
|
||||
{
|
||||
$importer = new GeographicalUnitBaseImporter(
|
||||
$this->connection,
|
||||
new NullLogger()
|
||||
);
|
||||
|
||||
$importer->importUnit(
|
||||
'test',
|
||||
['fr' => 'Test Layer'],
|
||||
'Layer one',
|
||||
'layer_one',
|
||||
'MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))',
|
||||
3812
|
||||
);
|
||||
|
||||
$importer->finalize();
|
||||
|
||||
$unit = $this->connection->executeQuery('
|
||||
SELECT unitname, unitrefid, cmgul.refid AS layerrefid, cmgul.name AS layername, ST_AsText(ST_snapToGrid(ST_Transform(u.geom, 3812), 1)) AS geom
|
||||
FROM chill_main_geographical_unit u JOIN chill_main_geographical_unit_layer cmgul on u.layer_id = cmgul.id
|
||||
WHERE u.unitrefid = ?', ['layer_one']);
|
||||
|
||||
$results = $unit->fetchAssociative();
|
||||
|
||||
$this->assertEquals($results['unitrefid'], 'layer_one');
|
||||
$this->assertEquals($results['unitname'], 'Layer one');
|
||||
$this->assertEquals(json_decode($results['layername'], true), ['fr' => 'Test Layer']);
|
||||
$this->assertEquals($results['layerrefid'], 'test');
|
||||
$this->assertEquals($results['geom'], 'MULTIPOLYGON(((30 20,45 40,10 40,30 20)),((15 5,40 10,10 20,5 10,15 5)))');
|
||||
|
||||
$importer = new GeographicalUnitBaseImporter(
|
||||
$this->connection,
|
||||
new NullLogger()
|
||||
);
|
||||
|
||||
$importer->importUnit(
|
||||
'test',
|
||||
['fr' => 'Test Layer fixed'],
|
||||
'Layer one fixed',
|
||||
'layer_one',
|
||||
'MULTIPOLYGON (((130 120, 45 40, 10 40, 130 120)),((0 0, 15 5, 40 10, 10 20, 0 0)))',
|
||||
3812
|
||||
);
|
||||
|
||||
$importer->finalize();
|
||||
|
||||
$unit = $this->connection->executeQuery('
|
||||
SELECT unitname, unitrefid, cmgul.refid AS layerrefid, cmgul.name AS layername, ST_AsText(ST_snapToGrid(ST_Transform(u.geom, 3812), 1)) AS geom
|
||||
FROM chill_main_geographical_unit u JOIN chill_main_geographical_unit_layer cmgul on u.layer_id = cmgul.id
|
||||
WHERE u.unitrefid = ?', ['layer_one']);
|
||||
|
||||
$results = $unit->fetchAssociative();
|
||||
|
||||
$this->assertEquals($results['unitrefid'], 'layer_one');
|
||||
$this->assertEquals($results['unitname'], 'Layer one fixed');
|
||||
$this->assertEquals(json_decode($results['layername'], true), ['fr' => 'Test Layer fixed']);
|
||||
$this->assertEquals($results['layerrefid'], 'test');
|
||||
$this->assertEquals($results['geom'], 'MULTIPOLYGON(((130 120,45 40,10 40,130 120)),((0 0,15 5,40 10,10 20,0 0)))');
|
||||
}
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
<?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 Services\Import;
|
||||
|
||||
use Chill\MainBundle\Repository\CountryRepository;
|
||||
use Chill\MainBundle\Repository\PostalCodeRepository;
|
||||
use Chill\MainBundle\Service\Import\PostalCodeBaseImporter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class PostalCodeBaseImporterTest extends KernelTestCase
|
||||
{
|
||||
private CountryRepository $countryRepository;
|
||||
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
private PostalCodeBaseImporter $importer;
|
||||
|
||||
private PostalCodeRepository $postalCodeRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
self::bootKernel();
|
||||
|
||||
$this->entityManager = self::$container->get(EntityManagerInterface::class);
|
||||
$this->importer = self::$container->get(PostalCodeBaseImporter::class);
|
||||
$this->postalCodeRepository = self::$container->get(PostalCodeRepository::class);
|
||||
$this->countryRepository = self::$container->get(CountryRepository::class);
|
||||
}
|
||||
|
||||
public function testImportPostalCode(): void
|
||||
{
|
||||
$this->importer->importCode(
|
||||
'BE',
|
||||
'tested with pattern ' . ($uniqid = uniqid()),
|
||||
'12345',
|
||||
$refPostalCodeId = 'test' . uniqid(),
|
||||
'test',
|
||||
50.0,
|
||||
5.0,
|
||||
4326
|
||||
);
|
||||
|
||||
$this->importer->finalize();
|
||||
|
||||
$postalCodes = $this->postalCodeRepository->findByPattern(
|
||||
'with pattern ' . $uniqid,
|
||||
$this->countryRepository->findOneBy(['countryCode' => 'BE'])
|
||||
);
|
||||
|
||||
$this->assertCount(1, $postalCodes);
|
||||
$this->assertStringStartsWith('tested with pattern', $postalCodes[0]->getName());
|
||||
|
||||
$previousId = $postalCodes[0]->getId();
|
||||
|
||||
$this->entityManager->clear();
|
||||
|
||||
$this->importer->importCode(
|
||||
'BE',
|
||||
'tested with adapted pattern ' . ($uniqid = uniqid()),
|
||||
'12345',
|
||||
$refPostalCodeId,
|
||||
'test',
|
||||
50.0,
|
||||
5.0,
|
||||
4326
|
||||
);
|
||||
|
||||
$this->importer->finalize();
|
||||
|
||||
$postalCodes = $this->postalCodeRepository->findByPattern(
|
||||
'with pattern ' . $uniqid,
|
||||
$this->countryRepository->findOneBy(['countryCode' => 'BE'])
|
||||
);
|
||||
|
||||
$this->assertCount(1, $postalCodes);
|
||||
$this->assertStringStartsWith('tested with adapted pattern', $postalCodes[0]->getName());
|
||||
$this->assertEquals($previousId, $postalCodes[0]->getId());
|
||||
}
|
||||
}
|
@@ -0,0 +1,116 @@
|
||||
<?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\MainBundle\Tests\Workflow\EventSubscriber;
|
||||
|
||||
use Chill\MainBundle\Entity\Notification;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStep;
|
||||
use Chill\MainBundle\Workflow\EventSubscriber\NotificationOnTransition;
|
||||
use Chill\MainBundle\Workflow\Helper\MetadataExtractor;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Call\Call;
|
||||
use Prophecy\Exception\Prediction\FailedPredictionException;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use ReflectionClass;
|
||||
use stdClass;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
use Symfony\Component\Workflow\Event\Event;
|
||||
use Symfony\Component\Workflow\Marking;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
use Symfony\Component\Workflow\Transition;
|
||||
use Symfony\Component\Workflow\WorkflowInterface;
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class NotificationOnTransitionTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
public function testOnCompleteSendNotification(): void
|
||||
{
|
||||
$dest = new User();
|
||||
$currentUser = new User();
|
||||
$workflowProphecy = $this->prophesize(WorkflowInterface::class);
|
||||
$workflow = $workflowProphecy->reveal();
|
||||
$entityWorkflow = new EntityWorkflow();
|
||||
$entityWorkflow
|
||||
->setWorkflowName('workflow_name')
|
||||
->setRelatedEntityClass(stdClass::class)
|
||||
->setRelatedEntityId(1);
|
||||
// force an id to entityWorkflow:
|
||||
$reflection = new ReflectionClass($entityWorkflow);
|
||||
$id = $reflection->getProperty('id');
|
||||
$id->setAccessible(true);
|
||||
$id->setValue($entityWorkflow, 1);
|
||||
|
||||
$step = new EntityWorkflowStep();
|
||||
$entityWorkflow->addStep($step);
|
||||
$step->addDestUser($dest)
|
||||
->setCurrentStep('to_state');
|
||||
|
||||
$em = $this->prophesize(EntityManagerInterface::class);
|
||||
$em->persist(Argument::type(Notification::class))->should(
|
||||
static function ($args) use ($dest) {
|
||||
/** @var Call[] $args */
|
||||
if (1 !== count($args)) {
|
||||
throw new FailedPredictionException('no notification sent');
|
||||
}
|
||||
|
||||
$notification = $args[0]->getArguments()[0];
|
||||
|
||||
if (!$notification instanceof Notification) {
|
||||
throw new FailedPredictionException('persist is not a notification');
|
||||
}
|
||||
|
||||
if (!$notification->getAddressees()->contains($dest)) {
|
||||
throw new FailedPredictionException('the dest is not notified');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
$engine = $this->prophesize(EngineInterface::class);
|
||||
$engine->render(Argument::type('string'), Argument::type('array'))
|
||||
->willReturn('dummy text');
|
||||
|
||||
$extractor = $this->prophesize(MetadataExtractor::class);
|
||||
$extractor->buildArrayPresentationForPlace(Argument::type(EntityWorkflow::class), Argument::any())
|
||||
->willReturn([]);
|
||||
$extractor->buildArrayPresentationForWorkflow(Argument::any())
|
||||
->willReturn([]);
|
||||
|
||||
$registry = $this->prophesize(Registry::class);
|
||||
$registry->get(Argument::type(EntityWorkflow::class), Argument::type('string'))
|
||||
->willReturn($workflow);
|
||||
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->getUser()->willReturn($currentUser);
|
||||
|
||||
$notificationOnTransition = new NotificationOnTransition(
|
||||
$em->reveal(),
|
||||
$engine->reveal(),
|
||||
$extractor->reveal(),
|
||||
$security->reveal(),
|
||||
$registry->reveal()
|
||||
);
|
||||
|
||||
$event = new Event($entityWorkflow, new Marking(), new Transition('dummy_transition', ['from_state'], ['to_state']), $workflow);
|
||||
|
||||
$notificationOnTransition->onCompletedSendNotification($event);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user