|
12 | 12 | class FilterTest extends TestCase |
13 | 13 | { |
14 | 14 | protected DocumentsValidator $validator; |
| 15 | + protected int $maxValuesCount = 10; |
15 | 16 |
|
16 | 17 | /** |
17 | 18 | * @throws \Utopia\Database\Exception |
@@ -54,10 +55,13 @@ public function setUp(): void |
54 | 55 | ]); |
55 | 56 |
|
56 | 57 | $context = new QueryContext(); |
57 | | - |
58 | 58 | $context->add($collection); |
59 | 59 |
|
60 | | - $this->validator = new DocumentsValidator($context); |
| 60 | + $this->validator = new DocumentsValidator( |
| 61 | + $context, |
| 62 | + Database::VAR_INTEGER, |
| 63 | + maxValuesCount: $this->maxValuesCount |
| 64 | + ); |
61 | 65 | } |
62 | 66 |
|
63 | 67 | public function testSuccess(): void |
@@ -122,39 +126,39 @@ public function testEmptyValues(): void |
122 | 126 |
|
123 | 127 | public function testMaxValuesCount(): void |
124 | 128 | { |
125 | | - $max = $this->validator->getMaxValuesCount(); |
| 129 | + $max = $this->maxValuesCount; |
126 | 130 | $values = []; |
127 | 131 | for ($i = 1; $i <= $max + 1; $i++) { |
128 | 132 | $values[] = $i; |
129 | 133 | } |
130 | 134 |
|
131 | | - $this->assertFalse($this->validator->isValid(Query::equal('integer', $values))); |
| 135 | + $this->assertFalse($this->validator->isValid([Query::equal('integer', $values)])); |
132 | 136 | $this->assertEquals('Query on attribute has greater than '.$max.' values: integer', $this->validator->getDescription()); |
133 | 137 | } |
134 | 138 |
|
135 | 139 | public function testNotContains(): void |
136 | 140 | { |
137 | 141 | // Test valid notContains queries |
138 | | - $this->assertTrue($this->validator->isValid(Query::notContains('string', ['unwanted']))); |
139 | | - $this->assertTrue($this->validator->isValid(Query::notContains('string_array', ['spam', 'unwanted']))); |
140 | | - $this->assertTrue($this->validator->isValid(Query::notContains('integer_array', [100, 200]))); |
| 142 | + $this->assertTrue($this->validator->isValid([Query::notContains('string', ['unwanted'])])); |
| 143 | + $this->assertTrue($this->validator->isValid([Query::notContains('string_array', ['spam', 'unwanted'])])); |
| 144 | + $this->assertTrue($this->validator->isValid([Query::notContains('integer_array', [100, 200])])); |
141 | 145 |
|
142 | 146 | // Test invalid notContains queries (empty values) |
143 | | - $this->assertFalse($this->validator->isValid(Query::notContains('string', []))); |
| 147 | + $this->assertFalse($this->validator->isValid([Query::notContains('string', [])])); |
144 | 148 | $this->assertEquals('NotContains queries require at least one value.', $this->validator->getDescription()); |
145 | 149 | } |
146 | 150 |
|
147 | 151 | public function testNotSearch(): void |
148 | 152 | { |
149 | 153 | // Test valid notSearch queries |
150 | | - $this->assertTrue($this->validator->isValid(Query::notSearch('string', 'unwanted'))); |
| 154 | + $this->assertTrue($this->validator->isValid([Query::notSearch('string', 'unwanted')])); |
151 | 155 |
|
152 | 156 | // Test that arrays cannot use notSearch |
153 | | - $this->assertFalse($this->validator->isValid(Query::notSearch('string_array', 'unwanted'))); |
| 157 | + $this->assertFalse($this->validator->isValid([Query::notSearch('string_array', 'unwanted')])); |
154 | 158 | $this->assertEquals('Cannot query notSearch on attribute "string_array" because it is an array.', $this->validator->getDescription()); |
155 | 159 |
|
156 | 160 | // Test multiple values not allowed |
157 | | - $this->assertFalse($this->validator->isValid(new Query(Query::TYPE_NOT_SEARCH, 'string', ['word1', 'word2']))); |
| 161 | + $this->assertFalse($this->validator->isValid([new Query(Query::TYPE_NOT_SEARCH, 'string', ['word1', 'word2'])])); |
158 | 162 | $this->assertEquals('NotSearch queries require exactly one value.', $this->validator->getDescription()); |
159 | 163 | } |
160 | 164 |
|
|
0 commit comments