File: DisallowTest.php

package info (click to toggle)
php-json-schema 6.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,216 kB
  • sloc: php: 9,403; makefile: 153; python: 28; sh: 13
file content (170 lines) | stat: -rw-r--r-- 5,265 bytes parent folder | download | duplicates (2)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php

/*
 * This file is part of the JsonSchema package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace JsonSchema\Tests\Constraints;

class DisallowTest extends BaseTestCase
{
    // schemas in these tests look like draft-03, but the 'disallow' patterns provided are in
    // violation of the spec - 'disallow' as defined in draft-03 accepts the same values as the
    // 'type' option, and cannot take arbitrary patterns. The implementation in this library is
    // probably deliberate, but noting that it's invalid, schema validation has been disabled
    // for these tests. The 'disallow' option was removed permanently in draft-04.
    protected $schemaSpec = 'http://json-schema.org/draft-03/schema#';
    protected $validateSchema = false;

    public function getInvalidTests(): array
    {
        return [
            [
                '{
                  "value":"The xpto is weird"
                }',
                '{
                  "type":"object",
                  "properties":{
                    "value":{
                      "type":"any",
                      "disallow":{"type":"string","pattern":"xpto"}
                    }
                  }
                }'
            ],
            [
                '{
                  "value":null
                }',
                '{
                  "type":"object",
                  "properties":{
                    "value":{
                      "type":"any",
                      "disallow":{"type":"null"}
                    }
                  }
                }'
            ],
            [
                '{"value": 1}',
                '{
                    "type": "object",
                    "properties": {
                        "value": {"type": "any", "disallow": "integer"}
                    }
                }'
            ],
            [
                '{"value": true}',
                '{
                    "type": "object",
                    "properties": {
                        "value": {"type": "any", "disallow": ["integer", "boolean"]}
                    }
                }'
            ],
            [
                '{"value": "foo"}',
                '{
                    "type": "object",
                    "properties": {
                        "value": {
                            "type": "any",
                            "disallow":
                                ["string", {
                                    "type": "object",
                                    "properties": {
                                        "foo": {"type": "string"}
                                    }
                                }]
                        }
                    }
                }'
            ],
            [
                '{"value": {"foo": "bar"}}',
                '{
                    "type": "object",
                    "properties": {
                        "value": {
                            "type": "any",
                            "disallow":
                                ["string", {
                                    "type": "object",
                                    "properties": {
                                        "foo": {"type": "string"}
                                    }
                                }]
                        }
                    }
                }'
            ]
        ];
    }

    public function getValidTests(): array
    {
        return [
            [
                '{
                  "value":"The xpto is weird"
                }',
                '{
                  "type":"object",
                  "properties":{
                    "value":{
                      "type":"any",
                      "disallow":{"type":"string","pattern":"^xpto"}
                    }
                  }
                }'
            ],
            [
                '{
                  "value":1
                }',
                '{
                  "type":"object",
                  "properties":{
                    "value":{
                      "type":"any",
                      "disallow":{"type":"null"}
                    }
                  }
                }'
            ],
            [
                '{"value": {"foo": 1}}',
                '{
                    "type": "object",
                    "properties": {
                        "value": {
                            "type": "any",
                            "disallow":
                                ["string", {
                                    "type": "object",
                                    "properties": {
                                        "foo": {"type": "string"}
                                    }
                                }]
                        }
                    }
                }'
            ],
            [
                '{"value": true}',
                '{
                    "type": "object",
                    "properties": {
                        "value": {"type": "any", "disallow": "string"}
                    }
                }'
            ]
        ];
    }
}