mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Feature: Create a base importer for geographical units and add index
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
|
||||
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)))');
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user