|
12 | 12 | use Utopia\Database\Helpers\Permission; |
13 | 13 | use Utopia\Database\Helpers\Role; |
14 | 14 | use Utopia\Database\Query; |
| 15 | +use Utopia\Database\Validator\Index; |
15 | 16 |
|
16 | 17 | trait SpatialTests |
17 | 18 | { |
@@ -2546,4 +2547,65 @@ public function testSpatialIndexRequiredToggling(): void |
2546 | 2547 | } |
2547 | 2548 | } |
2548 | 2549 |
|
| 2550 | + public function testSpatialIndexOnNonSpatial(): void |
| 2551 | + { |
| 2552 | + /** @var Database $database */ |
| 2553 | + $database = static::getDatabase(); |
| 2554 | + if (!$database->getAdapter()->getSupportForSpatialAttributes()) { |
| 2555 | + $this->expectNotToPerformAssertions(); |
| 2556 | + return; |
| 2557 | + } |
| 2558 | + |
| 2559 | + try { |
| 2560 | + $collUpdateNull = 'spatial_idx_toggle'; |
| 2561 | + $database->createCollection($collUpdateNull); |
| 2562 | + |
| 2563 | + $database->createAttribute($collUpdateNull, 'loc', Database::VAR_POINT, 0, true); |
| 2564 | + $database->createAttribute($collUpdateNull, 'name', Database::VAR_STRING, 0, true); |
| 2565 | + try { |
| 2566 | + $database->createIndex($collUpdateNull, 'idx_loc', Database::INDEX_SPATIAL, ['name']); |
| 2567 | + $this->fail('Expected exception when creating spatial index on NULL-able attribute'); |
| 2568 | + } catch (\Throwable $e) { |
| 2569 | + $this->assertInstanceOf(IndexException::class, $e); |
| 2570 | + } |
| 2571 | + |
| 2572 | + try { |
| 2573 | + $database->createIndex($collUpdateNull, 'idx_loc', Database::INDEX_KEY, ['loc']); |
| 2574 | + $this->fail('Expected exception when creating non spatial index on spatial attribute'); |
| 2575 | + } catch (\Throwable $e) { |
| 2576 | + $this->assertInstanceOf(IndexException::class, $e); |
| 2577 | + } |
| 2578 | + |
| 2579 | + try { |
| 2580 | + $database->createIndex($collUpdateNull, 'idx_loc', Database::INDEX_KEY, ['loc,name']); |
| 2581 | + $this->fail('Expected exception when creating index'); |
| 2582 | + } catch (\Throwable $e) { |
| 2583 | + $this->assertInstanceOf(IndexException::class, $e); |
| 2584 | + } |
| 2585 | + |
| 2586 | + try { |
| 2587 | + $database->createIndex($collUpdateNull, 'idx_loc', Database::INDEX_KEY, ['name,loc']); |
| 2588 | + $this->fail('Expected exception when creating index'); |
| 2589 | + } catch (\Throwable $e) { |
| 2590 | + $this->assertInstanceOf(IndexException::class, $e); |
| 2591 | + } |
| 2592 | + |
| 2593 | + try { |
| 2594 | + $database->createIndex($collUpdateNull, 'idx_loc', Database::INDEX_SPATIAL, ['name,loc']); |
| 2595 | + $this->fail('Expected exception when creating index'); |
| 2596 | + } catch (\Throwable $e) { |
| 2597 | + $this->assertInstanceOf(IndexException::class, $e); |
| 2598 | + } |
| 2599 | + |
| 2600 | + try { |
| 2601 | + $database->createIndex($collUpdateNull, 'idx_loc', Database::INDEX_SPATIAL, ['loc,name']); |
| 2602 | + $this->fail('Expected exception when creating index'); |
| 2603 | + } catch (\Throwable $e) { |
| 2604 | + $this->assertInstanceOf(IndexException::class, $e); |
| 2605 | + } |
| 2606 | + |
| 2607 | + } finally { |
| 2608 | + $database->deleteCollection($collUpdateNull); |
| 2609 | + } |
| 2610 | + } |
2549 | 2611 | } |
0 commit comments