diff --git a/lib/Settings/public_space_register.json b/lib/Settings/public_space_register.json index 468546dfe7..4805a9932e 100644 --- a/lib/Settings/public_space_register.json +++ b/lib/Settings/public_space_register.json @@ -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." } @@ -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." } @@ -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." } @@ -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." } diff --git a/tests/Unit/Service/ExampleSet/ZuiddrechtPublicSpaceTest.php b/tests/Unit/Service/ExampleSet/ZuiddrechtPublicSpaceTest.php index 5cd44342e2..5b8af9e463 100644 --- a/tests/Unit/Service/ExampleSet/ZuiddrechtPublicSpaceTest.php +++ b/tests/Unit/Service/ExampleSet/ZuiddrechtPublicSpaceTest.php @@ -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. @@ -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 !== []]; } @@ -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.