Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,11 @@ public function getGlobalCollections(): array
return \array_keys($this->globalCollections);
}

public function resetGlobalCollections(): void
{
Comment thread
abnegate marked this conversation as resolved.
$this->globalCollections = [];
}

/**
* Get list of keywords that cannot be used
*
Expand Down
54 changes: 54 additions & 0 deletions tests/e2e/Adapter/Scopes/CollectionTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -1439,4 +1439,58 @@ public function testTransformations(): void

$this->assertTrue($result->isEmpty());
}

public function testSetGlobalCollection(): void
{
$db = static::getDatabase();

$collectionId = 'globalCollection';

// set collection as global
$db->setGlobalCollections([$collectionId]);
Comment thread
ArnabChatterjee20k marked this conversation as resolved.

// metadata collection should not contain tenant in the cache key
[$collectionKey, $documentKey, $hashKey] = $db->getCacheKeys(
Database::METADATA,
$collectionId,
[]
);

$this->assertNotEmpty($collectionKey);
$this->assertNotEmpty($documentKey);
$this->assertNotEmpty($hashKey);

if ($db->getSharedTables()) {
$this->assertStringNotContainsString((string)$db->getAdapter()->getTenant(), $collectionKey);
}

// non global collection should containt tenant in the cache key
$nonGlobalCollectionId = 'nonGlobalCollection';
[$collectionKeyRegular] = $db->getCacheKeys(
Database::METADATA,
$nonGlobalCollectionId
);
if ($db->getSharedTables()) {
$this->assertStringContainsString((string)$db->getAdapter()->getTenant(), $collectionKeyRegular);
}

// Non metadata collection should contain tenant in the cache key
[$collectionKey, $documentKey, $hashKey] = $db->getCacheKeys(
$collectionId,
ID::unique(),
[]
);

$this->assertNotEmpty($collectionKey);
$this->assertNotEmpty($documentKey);
$this->assertNotEmpty($hashKey);

if ($db->getSharedTables()) {
$this->assertStringContainsString((string)$db->getAdapter()->getTenant(), $collectionKey);
}

$db->resetGlobalCollections();
$this->assertEmpty($db->getGlobalCollections());

}
}