$version, 'title' => 'Geräte', 'description' => 'Geräteprüfung', 'blocks' => [ ['id' => 'heading', 'type' => 'heading', 'props' => ['text' => 'Geräte', 'level' => 1]], ['id' => 'menu', 'type' => 'menu', 'props' => ['slot' => 'header', 'layout' => 'horizontal']], ]]; } public function testOldDocumentsAndEveryVisibilityAndMenuOptionRemainValid(): void { $validator = new DocumentValidator(); $validator->validate($this->document(21)); foreach (['all', 'desktop', 'tablet', 'mobile', 'hide-desktop', 'hide-tablet', 'hide-mobile', 'hidden'] as $visibility) { foreach (['tablet', 'mobile', 'never'] as $collapse) { $document = $this->document(); $document['blocks'][1]['layout'] = ['visibility' => $visibility]; $document['blocks'][1]['props']['collapse'] = $collapse; $validator->validate($document); self::assertSame($document, json_decode(json_encode($document, JSON_THROW_ON_ERROR), true, 512, JSON_THROW_ON_ERROR)); } } } public function testInvalidValuesAndOlderSchemasRejectNewOptions(): void { foreach ([['visibility', 'desktop', 21], ['collapse', 'tablet', 21], ['visibility', 'injected class', 22], ['collapse', 'sometimes', 22], ['visibility', [], 22], ['collapse', null, 22]] as [$key, $value, $version]) { $document = $this->document($version); $document['blocks'][1]['visibility' === $key ? 'layout' : 'props'][$key] = $value; try { (new DocumentValidator())->validate($document); self::fail('Ungültige Geräteoption wurde akzeptiert.'); } catch (InvalidDocument $error) { self::assertNotEmpty($error->getMessage()); } } } }