Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/Settings/public_space_register.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
"description": "Whether the tree is on the municipal list of monumental trees."
},
"location": {
"type": "geo",
"type": "object",
"format": "geo:point",
"title": "Location",
"description": "Where the object is, as a GeoJSON point in WGS84."
}
Expand Down Expand Up @@ -164,7 +165,8 @@
"description": "Height of the mast in metres."
},
"location": {
"type": "geo",
"type": "object",
"format": "geo:point",
"title": "Location",
"description": "Where the object is, as a GeoJSON point in WGS84."
}
Expand Down Expand Up @@ -250,7 +252,8 @@
"format": "date"
},
"location": {
"type": "geo",
"type": "object",
"format": "geo:point",
"title": "Location",
"description": "Where the object is, as a GeoJSON point in WGS84."
}
Expand Down Expand Up @@ -369,7 +372,8 @@
"description": "The paving, such as asphalt."
},
"location": {
"type": "geo",
"type": "object",
"format": "geo:point",
"title": "Location",
"description": "Where the object is, as a GeoJSON point in WGS84."
}
Expand Down
66 changes: 65 additions & 1 deletion tests/Unit/Service/ExampleSet/ZuiddrechtPublicSpaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@

namespace OCA\OpenRegister\Tests\Unit\Service\ExampleSet;

use OCA\OpenRegister\Db\MagicMapper;
use OCA\OpenRegister\Db\Schema;
use OCA\OpenRegister\Db\SchemaMapper;
use OCA\OpenRegister\Service\Geo\GeoJsonGeometryValidator;
use OCA\OpenRegister\Service\Object\ValidateObject;
use OCP\IAppConfig;
use OCP\IURLGenerator;
use OCP\IUserManager;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;

/**
* Reads the shipped descriptor and cast file from disk.
Expand Down Expand Up @@ -72,7 +81,7 @@ public function testTheSchemasCarryTheCatalogueColumns(): void {

$shape = [];
foreach ($schemas as $slug => $schema) {
$geo = array_filter($schema['properties'], static fn (array $property): bool => $property['type'] === 'geo');
$geo = array_filter($schema['properties'], static fn (array $property): bool => ($property['format'] ?? '') === 'geo:point');
$shape[$slug] = [$schema['title'], count($schema['properties']), $geo !== []];
}

Expand Down Expand Up @@ -120,6 +129,61 @@ public function testEveryObjectFitsItsSchema(): void {
$this->assertSame(expected: $identifications, actual: array_values(array_unique($identifications)));
}//end testEveryObjectFitsItsSchema()

/**
* Every object passes OpenRegister's own validation against its schema:
* the JSON Schema validator (which refuses a type it does not know, such
* as `geo`) and the GeoJSON check of each `geo:point` property.
*
* @return void
*/
public function testEveryObjectPassesTheValidator(): void {
$urls = $this->createMock(originalClassName: IURLGenerator::class);
$urls->method('getBaseUrl')->willReturn('http://localhost:8080');
$validator = new ValidateObject(
config: $this->createMock(originalClassName: IAppConfig::class),
objectMapper: $this->createMock(originalClassName: MagicMapper::class),
schemaMapper: $this->createMock(originalClassName: SchemaMapper::class),
urlGenerator: $urls,
logger: $this->createMock(originalClassName: LoggerInterface::class),
userManager: $this->createMock(originalClassName: IUserManager::class)
);

$schemas = self::read(path: self::DESCRIPTOR_FILE)['components']['schemas'];
$checked = 0;
foreach (self::read(path: self::CAST_FILE)['objects'] as $object) {
if ($object['register'] !== 'public-space') {
continue;
}

$declared = $schemas[$object['schema']];
$schema = new Schema();
$schema->setSlug(slug: $declared['slug']);
$schema->setTitle($declared['title']);
$schema->setProperties($declared['properties']);
$schema->setRequired($declared['required']);

$data = $object['data'];
if (isset($data['lastInspection']) === true) {
$data['lastInspection'] = '2026-09-16';
}

$json = json_decode(json: (string) json_encode(value: $declared), associative: false);
$result = $validator->validateObject(object: $data, schema: $schema, schemaObject: $json);
$this->assertTrue(
condition: $result->isValid(),
message: $object['key'].': '.$validator->generateErrorMessage(result: $result)
);
$this->assertSame(
expected: [],
actual: (new GeoJsonGeometryValidator())->validateObject(object: $data, schema: $schema),
message: $object['key']
);
$checked++;
}

$this->assertSame(expected: 13, actual: $checked);
}//end testEveryObjectPassesTheValidator()

/**
* The three objects the Lindelaan Woo case links: the cycle path in
* management and two masts still to be placed.
Expand Down
Loading