Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fogelito committed Jan 14, 2025
1 parent 8b6b6c4 commit 49943c9
Showing 1 changed file with 78 additions and 78 deletions.
156 changes: 78 additions & 78 deletions tests/e2e/Adapter/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,84 +93,6 @@ public function testCreateExistsDelete(): void
$this->assertEquals(true, static::getDatabase()->create());
}

public function testWidthLimit(): void
{
if (static::getDatabase()->getAdapter()::getDocumentSizeLimit() === 0) {
$this->expectNotToPerformAssertions();
return;
}

$collection = static::getDatabase()->createCollection('width_limit');

$init = static::getDatabase()->getAdapter()->getAttributeWidth($collection);
$this->assertEquals(1067, $init);

$attribute = new Document([
'$id' => ID::custom('varchar_100'),
'type' => Database::VAR_STRING,
'size' => 100,
'required' => false,
'default' => null,
'signed' => true,
'array' => false,
'filters' => [],
]);
$res = static::getDatabase()->getAdapter()->getAttributeWidth($collection->setAttribute('attributes', [$attribute]));
$this->assertEquals(401, $res - $init); // 100 * 4 + 1 (length)

$attribute = new Document([
'$id' => ID::custom('json'),
'type' => Database::VAR_STRING,
'size' => 100,
'required' => false,
'default' => null,
'signed' => true,
'array' => true,
'filters' => [],
]);
$res = static::getDatabase()->getAdapter()->getAttributeWidth($collection->setAttribute('attributes', [$attribute]));
$this->assertEquals(20, $res - $init); // Pointer of Json / Longtext (mariaDB)

$attribute = new Document([
'$id' => ID::custom('text'),
'type' => Database::VAR_STRING,
'size' => 20000,
'required' => false,
'default' => null,
'signed' => true,
'array' => false,
'filters' => [],
]);
$res = static::getDatabase()->getAdapter()->getAttributeWidth($collection->setAttribute('attributes', [$attribute]));
$this->assertEquals(20, $res - $init);

$attribute = new Document([
'$id' => ID::custom('bigint'),
'type' => Database::VAR_INTEGER,
'size' => 8,
'required' => false,
'default' => null,
'signed' => true,
'array' => false,
'filters' => [],
]);
$res = static::getDatabase()->getAdapter()->getAttributeWidth($collection->setAttribute('attributes', [$attribute]));
$this->assertEquals(8, $res - $init);

$attribute = new Document([
'$id' => ID::custom('date'),
'type' => Database::VAR_DATETIME,
'size' => 8,
'required' => false,
'default' => null,
'signed' => true,
'array' => false,
'filters' => [],
]);
$res = static::getDatabase()->getAdapter()->getAttributeWidth($collection->setAttribute('attributes', [$attribute]));
$this->assertEquals(7, $res - $init);
}

/**
* @throws LimitException
* @throws DuplicateException
Expand Down Expand Up @@ -5475,6 +5397,84 @@ public function testNoChangeUpdateDocumentWithRelationWithoutPermission(): void
}
}

public function testWidthLimit(): void
{
if (static::getDatabase()->getAdapter()::getDocumentSizeLimit() === 0) {
$this->expectNotToPerformAssertions();
return;
}

$collection = static::getDatabase()->createCollection('width_limit');

$init = static::getDatabase()->getAdapter()->getAttributeWidth($collection);
$this->assertEquals(1067, $init);

$attribute = new Document([
'$id' => ID::custom('varchar_100'),
'type' => Database::VAR_STRING,
'size' => 100,
'required' => false,
'default' => null,
'signed' => true,
'array' => false,
'filters' => [],
]);
$res = static::getDatabase()->getAdapter()->getAttributeWidth($collection->setAttribute('attributes', [$attribute]));
$this->assertEquals(401, $res - $init); // 100 * 4 + 1 (length)

$attribute = new Document([
'$id' => ID::custom('json'),
'type' => Database::VAR_STRING,
'size' => 100,
'required' => false,
'default' => null,
'signed' => true,
'array' => true,
'filters' => [],
]);
$res = static::getDatabase()->getAdapter()->getAttributeWidth($collection->setAttribute('attributes', [$attribute]));
$this->assertEquals(20, $res - $init); // Pointer of Json / Longtext (mariaDB)

$attribute = new Document([
'$id' => ID::custom('text'),
'type' => Database::VAR_STRING,
'size' => 20000,
'required' => false,
'default' => null,
'signed' => true,
'array' => false,
'filters' => [],
]);
$res = static::getDatabase()->getAdapter()->getAttributeWidth($collection->setAttribute('attributes', [$attribute]));
$this->assertEquals(20, $res - $init);

$attribute = new Document([
'$id' => ID::custom('bigint'),
'type' => Database::VAR_INTEGER,
'size' => 8,
'required' => false,
'default' => null,
'signed' => true,
'array' => false,
'filters' => [],
]);
$res = static::getDatabase()->getAdapter()->getAttributeWidth($collection->setAttribute('attributes', [$attribute]));
$this->assertEquals(8, $res - $init);

$attribute = new Document([
'$id' => ID::custom('date'),
'type' => Database::VAR_DATETIME,
'size' => 8,
'required' => false,
'default' => null,
'signed' => true,
'array' => false,
'filters' => [],
]);
$res = static::getDatabase()->getAdapter()->getAttributeWidth($collection->setAttribute('attributes', [$attribute]));
$this->assertEquals(7, $res - $init);
}

public function testExceptionAttributeLimit(): void
{
if (static::getDatabase()->getAdapter()->getLimitForAttributes() === 0) {
Expand Down

0 comments on commit 49943c9

Please sign in to comment.