Files
appwrite/tests/unit/Utopia/Database/Validator/ProjectIdTest.php
Jake Barnby 64a368ba3d Merge remote-tracking branch 'origin/feat-db-tests' into feat-mongodb
# Conflicts:
#	.github/workflows/tests.yml
#	src/Appwrite/Utopia/Response.php
#	src/Appwrite/Utopia/Response/Model/AttributeList.php
#	tests/e2e/Client.php
#	tests/e2e/Scopes/ProjectCustom.php
#	tests/e2e/Services/Databases/DatabasesBase.php
#	tests/e2e/Services/Databases/Legacy/DatabasesCustomClientTest.php
#	tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php
#	tests/e2e/Services/Databases/Legacy/DatabasesStringTypesTest.php
#	tests/e2e/Services/Databases/TablesDB/DatabasesBase.php
#	tests/e2e/Services/Databases/TablesDB/DatabasesCustomClientTest.php
#	tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php
#	tests/e2e/Services/Databases/TablesDB/DatabasesStringTypesTest.php
#	tests/e2e/Services/Databases/Transactions/TransactionsBase.php
#	tests/e2e/Services/GraphQL/Legacy/DatabaseServerTest.php
#	tests/e2e/Services/GraphQL/TablesDB/DatabaseServerTest.php
#	tests/e2e/Services/Messaging/MessagingBase.php
#	tests/e2e/Services/Sites/SitesBase.php
#	tests/e2e/Services/Sites/SitesCustomServerTest.php
2026-02-18 03:27:23 +13:00

57 lines
1.6 KiB
PHP

<?php
namespace Tests\Unit\Utopia\Database\Validator;
use Appwrite\Utopia\Database\Validator\ProjectId;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class ProjectIdTest extends TestCase
{
protected ?ProjectId $object = null;
public function setUp(): void
{
$this->object = new ProjectId();
}
public function tearDown(): void
{
}
public static function provideTest(): array
{
return [
'unique()' => ['unique()', true],
'dashes' => ['as12-df34', true],
'36 chars' => [\str_repeat('a', 36), true],
'uppercase' => ['ABC', false],
'underscore' => ['under_score', false],
'leading dash' => ['-dash', false],
'too long' => [\str_repeat('a', 37), false],
];
}
#[DataProvider('provideTest')]
public function testValues(string $input, bool $expected): void
{
$this->assertEquals($this->object->isValid($input), $expected);
}
public function testCustomMaxLength(): void
{
// Test with MongoDB max length (255)
$validator = new ProjectId(255);
$this->assertTrue($validator->isValid(\str_repeat('a', 255)));
$this->assertFalse($validator->isValid(\str_repeat('a', 256)));
// Test with smaller custom length
$validator = new ProjectId(10);
$this->assertTrue($validator->isValid(\str_repeat('a', 10)));
$this->assertFalse($validator->isValid(\str_repeat('a', 11)));
// Verify description updates
$this->assertStringContainsString('10 chars', $validator->getDescription());
}
}