-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-registry-schema.php
More file actions
131 lines (117 loc) · 4.09 KB
/
Copy pathtest-registry-schema.php
File metadata and controls
131 lines (117 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
* Tests für das deklarative Schema der Feld-Registry (config/dcat-ap-fields.php).
*
* @package OpenDataWizard
*/
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* Validates the structure and invariants of the DCAT-AP field registry so the
* declarative metadata (profile/tier/range/cardinality/entity/vocab) stays
* consistent and backward-compatible with its consumers.
*/
class Test_ODW_Registry_Schema extends TestCase {
/**
* Loaded registry definitions.
*
* @var array<int, array<string, mixed>>
*/
private array $defs;
/**
* Load the registry once per test with __() stubbed.
*/
protected function setUp(): void {
\WP_Mock::setUp();
\WP_Mock::userFunction( '__' )->andReturnArg( 0 );
$this->defs = require ODW_PLUGIN_DIR . 'config/dcat-ap-fields.php';
}
/**
* Tear down WP_Mock.
*/
protected function tearDown(): void {
\WP_Mock::tearDown();
}
/**
* The registry is a non-empty list of array entries.
*/
public function test_registry_is_non_empty_list(): void {
$this->assertIsArray( $this->defs );
$this->assertNotEmpty( $this->defs );
}
/**
* Every entry keeps the base keys consumed by ODW_Quality and ODW_Validation.
*/
public function test_every_entry_has_base_keys(): void {
foreach ( $this->defs as $entry ) {
foreach ( array( 'key', 'meta_key', 'dcat_prop', 'label', 'points', 'required' ) as $base ) {
$this->assertArrayHasKey( $base, $entry, "Missing base key '$base'" );
}
$this->assertIsInt( $entry['points'] );
$this->assertIsBool( $entry['required'] );
}
}
/**
* Every entry carries the declarative schema keys with valid enum values.
*/
public function test_every_entry_has_valid_schema_metadata(): void {
$profiles = array( 'ap', 'ap.de', 'hvd' );
$tiers = array( 'mandatory', 'recommended', 'optional' );
$ranges = array( 'literal', 'literal-lang', 'uri', 'node' );
$cardinalities = array( '0..1', '0..n', '1..1', '1..n' );
$entities = array( 'dataset', 'distribution', 'catalog' );
foreach ( $this->defs as $entry ) {
$this->assertContains( $entry['profile'], $profiles, "Bad profile for {$entry['key']}" );
$this->assertContains( $entry['tier'], $tiers, "Bad tier for {$entry['key']}" );
$this->assertContains( $entry['range'], $ranges, "Bad range for {$entry['key']}" );
$this->assertContains( $entry['cardinality'], $cardinalities, "Bad cardinality for {$entry['key']}" );
$this->assertContains( $entry['entity'], $entities, "Bad entity for {$entry['key']}" );
$this->assertArrayHasKey( 'vocab', $entry );
$this->assertIsString( $entry['vocab'] );
}
}
/**
* The tier and required flag stay consistent: mandatory iff required.
*/
public function test_tier_matches_required_flag(): void {
foreach ( $this->defs as $entry ) {
if ( 'mandatory' === $entry['tier'] ) {
$this->assertTrue( $entry['required'], "Mandatory tier must be required: {$entry['key']}" );
} else {
$this->assertFalse( $entry['required'], "Non-mandatory tier must not be required: {$entry['key']}" );
}
}
}
/**
* The total points still sum to 100 (scoring scale is unchanged).
*/
public function test_points_sum_to_100(): void {
$sum = array_sum( array_column( $this->defs, 'points' ) );
$this->assertSame( 100, $sum );
}
/**
* Keys are unique across the registry.
*/
public function test_keys_are_unique(): void {
$keys = array_column( $this->defs, 'key' );
$this->assertSame( count( $keys ), count( array_unique( $keys ) ) );
}
/**
* Every label carries its DCAT-AP property name so the quality report and
* validation messages stay consistent (regression: description/publisher/
* license previously used the bare form question without the dct/dcat name).
*/
public function test_labels_include_dcat_property_name(): void {
foreach ( $this->defs as $entry ) {
$prop = (string) ( $entry['dcat_prop'] ?? '' );
if ( '' === $prop ) {
continue;
}
$this->assertStringContainsString(
'(' . $prop . ')',
(string) $entry['label'],
"Label for '{$entry['key']}' must include its DCAT-AP property name {$prop}."
);
}
}
}