2022-06-30 12:00:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
2025-05-09 14:34:02 +00:00
|
|
|
namespace Tests\E2E\Services\GraphQL\Collections;
|
2022-06-30 12:00:00 +00:00
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
|
use Tests\E2E\Client;
|
|
|
|
|
use Tests\E2E\Scopes\ProjectCustom;
|
|
|
|
|
use Tests\E2E\Scopes\Scope;
|
|
|
|
|
use Tests\E2E\Scopes\SideServer;
|
2025-05-09 14:34:02 +00:00
|
|
|
use Tests\E2E\Services\GraphQL\Base;
|
2023-03-24 05:08:50 +00:00
|
|
|
use Utopia\Database\Database;
|
2023-01-16 09:25:40 +00:00
|
|
|
use Utopia\Database\Helpers\ID;
|
|
|
|
|
use Utopia\Database\Helpers\Permission;
|
|
|
|
|
use Utopia\Database\Helpers\Role;
|
2022-06-30 12:00:00 +00:00
|
|
|
|
2022-09-22 08:29:42 +00:00
|
|
|
class DatabaseServerTest extends Scope
|
2022-06-30 12:00:00 +00:00
|
|
|
{
|
|
|
|
|
use ProjectCustom;
|
|
|
|
|
use SideServer;
|
2022-09-22 08:29:42 +00:00
|
|
|
use Base;
|
2022-06-30 12:00:00 +00:00
|
|
|
|
2022-07-06 05:12:12 +00:00
|
|
|
public function testCreateDatabase(): array
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
|
$query = $this->getQuery(self::$CREATE_DATABASE);
|
|
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => 'actors',
|
|
|
|
|
'name' => 'Actors',
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$database = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertIsArray($database['body']['data']);
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $database['body']);
|
|
|
|
|
$database = $database['body']['data']['databasesCreate'];
|
|
|
|
|
$this->assertEquals('Actors', $database['name']);
|
|
|
|
|
|
|
|
|
|
return $database;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateDatabase
|
|
|
|
|
*/
|
|
|
|
|
public function testCreateCollection($database): array
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$CREATE_COLLECTION);
|
2022-07-06 05:12:12 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $database['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => 'actors',
|
2022-07-06 05:12:12 +00:00
|
|
|
'name' => 'Actors',
|
2022-09-21 08:17:17 +00:00
|
|
|
'documentSecurity' => false,
|
|
|
|
|
'permissions' => [
|
|
|
|
|
Permission::read(Role::any()),
|
|
|
|
|
Permission::create(Role::users()),
|
|
|
|
|
Permission::update(Role::users()),
|
|
|
|
|
Permission::delete(Role::users()),
|
|
|
|
|
],
|
2022-07-06 05:12:12 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$collection = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertIsArray($collection['body']['data']);
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $collection['body']);
|
2025-05-09 12:08:02 +00:00
|
|
|
$collection = $collection['body']['data']['databasesCreateCollection'];
|
2022-07-06 05:12:12 +00:00
|
|
|
$this->assertEquals('Actors', $collection['name']);
|
|
|
|
|
|
2023-03-24 05:08:50 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $database['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => 'movies',
|
2023-03-24 05:08:50 +00:00
|
|
|
'name' => 'Movies',
|
|
|
|
|
'documentSecurity' => false,
|
|
|
|
|
'permissions' => [
|
|
|
|
|
Permission::read(Role::any()),
|
|
|
|
|
Permission::create(Role::users()),
|
|
|
|
|
Permission::update(Role::users()),
|
|
|
|
|
Permission::delete(Role::users()),
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
2025-05-09 12:08:02 +00:00
|
|
|
$collection2 = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
2023-03-24 05:08:50 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
2025-05-09 12:08:02 +00:00
|
|
|
$this->assertIsArray($collection2['body']['data']);
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $collection2['body']);
|
|
|
|
|
$collection2 = $collection2['body']['data']['databasesCreateCollection'];
|
|
|
|
|
$this->assertEquals('Movies', $collection2['name']);
|
2023-03-24 05:08:50 +00:00
|
|
|
|
2022-07-06 05:12:12 +00:00
|
|
|
return [
|
|
|
|
|
'database' => $database,
|
2025-05-09 12:08:02 +00:00
|
|
|
'collection' => $collection,
|
|
|
|
|
'collection2' => $collection2,
|
2022-07-06 05:12:12 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateCollection
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testCreateStringAttribute($data): array
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$CREATE_STRING_ATTRIBUTE);
|
2022-07-06 05:12:12 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
'key' => 'name',
|
|
|
|
|
'size' => 256,
|
|
|
|
|
'required' => true,
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $attribute['body']);
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsCreateStringAttribute']);
|
2022-07-06 05:12:12 +00:00
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:06:46 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateStringAttribute
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateStringAttribute($data): array
|
|
|
|
|
{
|
|
|
|
|
// Wait for attributes to be available
|
2023-03-31 08:29:02 +00:00
|
|
|
sleep(1);
|
2023-03-10 13:06:46 +00:00
|
|
|
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$UPDATE_STRING_ATTRIBUTE);
|
2023-03-10 13:06:46 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2023-03-10 13:06:46 +00:00
|
|
|
'key' => 'name',
|
|
|
|
|
'required' => false,
|
|
|
|
|
'default' => 'Default Value',
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsUpdateStringAttribute']);
|
|
|
|
|
$this->assertFalse($attribute['body']['data']['collectionsUpdateStringAttribute']['required']);
|
|
|
|
|
$this->assertEquals('Default Value', $attribute['body']['data']['collectionsUpdateStringAttribute']['default']);
|
2023-03-10 13:06:46 +00:00
|
|
|
$this->assertEquals(200, $attribute['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 05:12:12 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateCollection
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testCreateIntegerAttribute($data): array
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$CREATE_INTEGER_ATTRIBUTE);
|
2022-07-06 05:12:12 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
'key' => 'age',
|
|
|
|
|
'min' => 18,
|
|
|
|
|
'max' => 150,
|
|
|
|
|
'required' => true,
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $attribute['body']);
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsCreateIntegerAttribute']);
|
2022-07-06 05:12:12 +00:00
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:06:46 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateIntegerAttribute
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateIntegerAttribute($data): array
|
|
|
|
|
{
|
|
|
|
|
// Wait for attributes to be available
|
2023-03-31 08:29:02 +00:00
|
|
|
sleep(1);
|
2023-03-10 13:06:46 +00:00
|
|
|
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$UPDATE_INTEGER_ATTRIBUTE);
|
2023-03-10 13:06:46 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2023-03-10 13:06:46 +00:00
|
|
|
'key' => 'age',
|
|
|
|
|
'required' => false,
|
|
|
|
|
'min' => 12,
|
|
|
|
|
'max' => 160,
|
|
|
|
|
'default' => 50
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsUpdateIntegerAttribute']);
|
|
|
|
|
$this->assertFalse($attribute['body']['data']['collectionsUpdateIntegerAttribute']['required']);
|
|
|
|
|
$this->assertEquals(12, $attribute['body']['data']['collectionsUpdateIntegerAttribute']['min']);
|
|
|
|
|
$this->assertEquals(160, $attribute['body']['data']['collectionsUpdateIntegerAttribute']['max']);
|
|
|
|
|
$this->assertEquals(50, $attribute['body']['data']['collectionsUpdateIntegerAttribute']['default']);
|
2023-03-10 13:06:46 +00:00
|
|
|
$this->assertEquals(200, $attribute['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 05:12:12 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateCollection
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testCreateBooleanAttribute($data): array
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$CREATE_BOOLEAN_ATTRIBUTE);
|
2022-07-06 05:12:12 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
'key' => 'alive',
|
|
|
|
|
'required' => true,
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $attribute['body']);
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsCreateBooleanAttribute']);
|
2022-07-06 05:12:12 +00:00
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:06:46 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateBooleanAttribute
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateBooleanAttribute($data): array
|
|
|
|
|
{
|
|
|
|
|
// Wait for attributes to be available
|
2023-03-31 08:29:02 +00:00
|
|
|
sleep(1);
|
2023-03-10 13:06:46 +00:00
|
|
|
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$UPDATE_BOOLEAN_ATTRIBUTE);
|
2023-03-10 13:06:46 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2023-03-10 13:06:46 +00:00
|
|
|
'key' => 'alive',
|
|
|
|
|
'required' => false,
|
|
|
|
|
'default' => true
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsUpdateBooleanAttribute']);
|
|
|
|
|
$this->assertFalse($attribute['body']['data']['collectionsUpdateBooleanAttribute']['required']);
|
|
|
|
|
$this->assertTrue($attribute['body']['data']['collectionsUpdateBooleanAttribute']['default']);
|
2023-03-10 13:06:46 +00:00
|
|
|
$this->assertEquals(200, $attribute['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 05:12:12 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateCollection
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testCreateFloatAttribute($data): array
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$CREATE_FLOAT_ATTRIBUTE);
|
2022-07-06 05:12:12 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
'key' => 'salary',
|
|
|
|
|
'min' => 1000.0,
|
|
|
|
|
'max' => 999999.99,
|
|
|
|
|
'default' => 1000.0,
|
|
|
|
|
'required' => false,
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $attribute['body']);
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsCreateFloatAttribute']);
|
2022-07-06 05:12:12 +00:00
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:06:46 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateFloatAttribute
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateFloatAttribute($data): array
|
|
|
|
|
{
|
|
|
|
|
// Wait for attributes to be available
|
2023-03-31 08:29:02 +00:00
|
|
|
sleep(1);
|
2023-03-10 13:06:46 +00:00
|
|
|
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$UPDATE_FLOAT_ATTRIBUTE);
|
2023-03-10 13:06:46 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2023-03-10 13:06:46 +00:00
|
|
|
'key' => 'salary',
|
|
|
|
|
'required' => false,
|
|
|
|
|
'min' => 100.0,
|
|
|
|
|
'max' => 1000000.0,
|
|
|
|
|
'default' => 2500.0
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsUpdateFloatAttribute']);
|
|
|
|
|
$this->assertFalse($attribute['body']['data']['collectionsUpdateFloatAttribute']['required']);
|
|
|
|
|
$this->assertEquals(100.0, $attribute['body']['data']['collectionsUpdateFloatAttribute']['min']);
|
|
|
|
|
$this->assertEquals(1000000.0, $attribute['body']['data']['collectionsUpdateFloatAttribute']['max']);
|
|
|
|
|
$this->assertEquals(2500.0, $attribute['body']['data']['collectionsUpdateFloatAttribute']['default']);
|
2023-03-10 13:06:46 +00:00
|
|
|
$this->assertEquals(200, $attribute['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 05:12:12 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateCollection
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testCreateEmailAttribute($data): array
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$CREATE_EMAIL_ATTRIBUTE);
|
2022-07-06 05:12:12 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
'key' => 'email',
|
|
|
|
|
'required' => true,
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $attribute['body']);
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsCreateEmailAttribute']);
|
2022-07-06 05:12:12 +00:00
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:06:46 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateEmailAttribute
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateEmailAttribute($data): array
|
|
|
|
|
{
|
|
|
|
|
// Wait for attributes to be available
|
2023-03-31 08:29:02 +00:00
|
|
|
sleep(1);
|
2023-03-10 13:06:46 +00:00
|
|
|
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$UPDATE_EMAIL_ATTRIBUTE);
|
2023-03-10 13:06:46 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2023-03-10 13:06:46 +00:00
|
|
|
'key' => 'email',
|
|
|
|
|
'required' => false,
|
|
|
|
|
'default' => 'torsten@appwrite.io',
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsUpdateEmailAttribute']);
|
|
|
|
|
$this->assertFalse($attribute['body']['data']['collectionsUpdateEmailAttribute']['required']);
|
|
|
|
|
$this->assertEquals('torsten@appwrite.io', $attribute['body']['data']['collectionsUpdateEmailAttribute']['default']);
|
2023-03-10 13:06:46 +00:00
|
|
|
$this->assertEquals(200, $attribute['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 05:12:12 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateCollection
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testCreateEnumAttribute($data): array
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$CREATE_ENUM_ATTRIBUTE);
|
2022-07-06 05:12:12 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
'key' => 'role',
|
|
|
|
|
'elements' => [
|
|
|
|
|
'crew',
|
|
|
|
|
'actor',
|
|
|
|
|
'guest',
|
|
|
|
|
],
|
|
|
|
|
'required' => true,
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $attribute['body']);
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsCreateEnumAttribute']);
|
2022-07-06 05:12:12 +00:00
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:06:46 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateEnumAttribute
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateEnumAttribute($data): array
|
|
|
|
|
{
|
|
|
|
|
// Wait for attributes to be available
|
2023-03-31 08:29:02 +00:00
|
|
|
sleep(1);
|
2023-03-10 13:06:46 +00:00
|
|
|
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$UPDATE_ENUM_ATTRIBUTE);
|
2023-03-10 13:06:46 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2023-03-10 13:06:46 +00:00
|
|
|
'key' => 'role',
|
|
|
|
|
'required' => false,
|
|
|
|
|
'elements' => [
|
|
|
|
|
'crew',
|
|
|
|
|
'tech',
|
|
|
|
|
'actor'
|
|
|
|
|
],
|
|
|
|
|
'default' => 'tech'
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsUpdateEnumAttribute']);
|
|
|
|
|
$this->assertFalse($attribute['body']['data']['collectionsUpdateEnumAttribute']['required']);
|
|
|
|
|
$this->assertEquals('tech', $attribute['body']['data']['collectionsUpdateEnumAttribute']['default']);
|
|
|
|
|
$this->assertContains('tech', $attribute['body']['data']['collectionsUpdateEnumAttribute']['elements']);
|
|
|
|
|
$this->assertNotContains('guest', $attribute['body']['data']['collectionsUpdateEnumAttribute']['elements']);
|
2023-03-10 13:06:46 +00:00
|
|
|
$this->assertEquals(200, $attribute['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-21 09:08:20 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateCollection
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testCreateDatetimeAttribute($data): array
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$CREATE_DATETIME_ATTRIBUTE);
|
2022-09-21 09:08:20 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-09-21 09:08:20 +00:00
|
|
|
'key' => 'dob',
|
|
|
|
|
'required' => true,
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $attribute['body']);
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsCreateDatetimeAttribute']);
|
2022-09-21 09:08:20 +00:00
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:06:46 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateDatetimeAttribute
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateDatetimeAttribute($data): array
|
|
|
|
|
{
|
|
|
|
|
// Wait for attributes to be available
|
2023-03-31 08:29:02 +00:00
|
|
|
sleep(1);
|
2023-03-10 13:06:46 +00:00
|
|
|
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$UPDATE_DATETIME_ATTRIBUTE);
|
2023-03-10 13:06:46 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2023-03-10 13:06:46 +00:00
|
|
|
'key' => 'dob',
|
|
|
|
|
'required' => false,
|
|
|
|
|
'default' => '2000-01-01T00:00:00Z'
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsUpdateDatetimeAttribute']);
|
|
|
|
|
$this->assertFalse($attribute['body']['data']['collectionsUpdateDatetimeAttribute']['required']);
|
|
|
|
|
$this->assertEquals('2000-01-01T00:00:00Z', $attribute['body']['data']['collectionsUpdateDatetimeAttribute']['default']);
|
2023-03-10 13:06:46 +00:00
|
|
|
$this->assertEquals(200, $attribute['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-24 05:08:50 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateCollection
|
|
|
|
|
*/
|
|
|
|
|
public function testCreateRelationshipAttribute(array $data): array
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$CREATE_RELATIONSHIP_ATTRIBUTE);
|
2023-03-24 05:08:50 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection2']['_id'], // Movies
|
|
|
|
|
'relatedCollectionId' => $data['collection']['_id'], // Actors
|
2023-03-24 05:08:50 +00:00
|
|
|
'type' => Database::RELATION_ONE_TO_MANY,
|
|
|
|
|
'twoWay' => true,
|
|
|
|
|
'key' => 'actors',
|
|
|
|
|
'twoWayKey' => 'movie'
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $attribute['body']);
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsCreateRelationshipAttribute']);
|
2023-03-24 05:08:50 +00:00
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateRelationshipAttribute
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateRelationshipAttribute(array $data): array
|
|
|
|
|
{
|
2023-03-31 08:29:02 +00:00
|
|
|
sleep(1);
|
2023-03-24 05:08:50 +00:00
|
|
|
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$UPDATE_RELATIONSHIP_ATTRIBUTE);
|
2023-03-24 05:08:50 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection2']['_id'],
|
2023-03-24 05:08:50 +00:00
|
|
|
'key' => 'actors',
|
2023-03-31 08:29:02 +00:00
|
|
|
'onDelete' => Database::RELATION_MUTATE_CASCADE,
|
2023-03-24 05:08:50 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $attribute['body']);
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsUpdateRelationshipAttribute']);
|
2023-03-24 05:08:50 +00:00
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 05:12:12 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateCollection
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testCreateIPAttribute($data): array
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$CREATE_IP_ATTRIBUTE);
|
2022-07-06 05:12:12 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
'key' => 'ip',
|
|
|
|
|
'required' => false,
|
|
|
|
|
'default' => '::1',
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $attribute['body']);
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsCreateIpAttribute']);
|
2022-07-06 05:12:12 +00:00
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:06:46 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateIPAttribute
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateIPAttribute($data): array
|
|
|
|
|
{
|
|
|
|
|
// Wait for attributes to be available
|
|
|
|
|
sleep(3);
|
|
|
|
|
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$UPDATE_IP_ATTRIBUTE);
|
2023-03-10 13:06:46 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2023-03-10 13:06:46 +00:00
|
|
|
'key' => 'ip',
|
|
|
|
|
'required' => false,
|
|
|
|
|
'default' => '127.0.0.1'
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsUpdateIpAttribute']);
|
|
|
|
|
$this->assertFalse($attribute['body']['data']['collectionsUpdateIpAttribute']['required']);
|
|
|
|
|
$this->assertEquals('127.0.0.1', $attribute['body']['data']['collectionsUpdateIpAttribute']['default']);
|
2023-03-10 13:06:46 +00:00
|
|
|
$this->assertEquals(200, $attribute['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 05:12:12 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateCollection
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testCreateURLAttribute($data): array
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$CREATE_URL_ATTRIBUTE);
|
2022-07-06 05:12:12 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
'key' => 'url',
|
|
|
|
|
'required' => false,
|
|
|
|
|
'default' => 'https://appwrite.io',
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $attribute['body']);
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsCreateUrlAttribute']);
|
2022-07-06 05:12:12 +00:00
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-03-10 13:06:46 +00:00
|
|
|
* @depends testCreateURLAttribute
|
2022-07-06 05:12:12 +00:00
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2023-03-10 13:06:46 +00:00
|
|
|
public function testUpdateURLAttribute($data): void
|
2022-07-06 05:12:12 +00:00
|
|
|
{
|
|
|
|
|
// Wait for attributes to be available
|
2022-09-23 03:53:25 +00:00
|
|
|
sleep(3);
|
2022-07-06 05:12:12 +00:00
|
|
|
|
2023-03-10 13:06:46 +00:00
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$UPDATE_URL_ATTRIBUTE);
|
2023-03-10 13:06:46 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2023-03-10 13:06:46 +00:00
|
|
|
'key' => 'url',
|
|
|
|
|
'required' => false,
|
|
|
|
|
'default' => 'https://cloud.appwrite.io'
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsUpdateUrlAttribute']);
|
|
|
|
|
$this->assertFalse($attribute['body']['data']['collectionsUpdateUrlAttribute']['required']);
|
|
|
|
|
$this->assertEquals('https://cloud.appwrite.io', $attribute['body']['data']['collectionsUpdateUrlAttribute']['default']);
|
2023-03-10 13:06:46 +00:00
|
|
|
$this->assertEquals(200, $attribute['headers']['status-code']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testUpdateStringAttribute
|
|
|
|
|
* @depends testUpdateIntegerAttribute
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testCreateIndex($data): array
|
|
|
|
|
{
|
2022-07-06 05:12:12 +00:00
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
|
$query = $this->getQuery(self::$CREATE_INDEX);
|
|
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
'key' => 'index',
|
|
|
|
|
'type' => 'key',
|
2025-05-09 12:08:02 +00:00
|
|
|
'attributes' => [
|
2022-07-06 05:12:12 +00:00
|
|
|
'name',
|
|
|
|
|
'age',
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$index = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $index['body']);
|
|
|
|
|
$this->assertIsArray($index['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($index['body']['data']['collectionsCreateIndex']);
|
2022-07-06 05:12:12 +00:00
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'database' => $data['database'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collection' => $data['collection'],
|
2025-05-09 12:45:17 +00:00
|
|
|
'index' => $index['body']['data']['collectionsCreateIndex'],
|
2022-07-06 05:12:12 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-03-10 13:06:46 +00:00
|
|
|
* @depends testUpdateStringAttribute
|
|
|
|
|
* @depends testUpdateIntegerAttribute
|
|
|
|
|
* @depends testUpdateBooleanAttribute
|
|
|
|
|
* @depends testUpdateEnumAttribute
|
2022-07-06 05:12:12 +00:00
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testCreateDocument($data): array
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$CREATE_DOCUMENT);
|
2022-07-06 05:12:12 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
|
|
|
|
'documentId' => ID::unique(),
|
2022-07-06 05:12:12 +00:00
|
|
|
'data' => [
|
|
|
|
|
'name' => 'John Doe',
|
|
|
|
|
'email' => 'example@appwrite.io',
|
|
|
|
|
'age' => 30,
|
|
|
|
|
'alive' => true,
|
|
|
|
|
'salary' => 9999.9,
|
|
|
|
|
'role' => 'crew',
|
2022-09-21 09:08:20 +00:00
|
|
|
'dob' => '2000-01-01T00:00:00Z',
|
2022-07-06 05:12:12 +00:00
|
|
|
],
|
2022-09-21 08:17:17 +00:00
|
|
|
'permissions' => [
|
|
|
|
|
Permission::read(Role::any()),
|
|
|
|
|
Permission::update(Role::any()),
|
|
|
|
|
Permission::delete(Role::any()),
|
|
|
|
|
],
|
2022-07-06 05:12:12 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
2025-05-09 12:08:02 +00:00
|
|
|
$document = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
2022-07-06 05:12:12 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
2025-05-09 12:08:02 +00:00
|
|
|
$this->assertArrayNotHasKey('errors', $document['body']);
|
|
|
|
|
$this->assertIsArray($document['body']['data']);
|
2022-07-06 05:12:12 +00:00
|
|
|
|
2025-05-09 12:45:17 +00:00
|
|
|
$document = $document['body']['data']['collectionsCreateDocument'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$this->assertIsArray($document);
|
2022-07-06 05:12:12 +00:00
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'database' => $data['database'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collection' => $data['collection'],
|
|
|
|
|
'document' => $document,
|
2022-07-06 05:12:12 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:06:46 +00:00
|
|
|
// /**
|
|
|
|
|
// * @depends testCreateStringAttribute
|
|
|
|
|
// * @depends testCreateIntegerAttribute
|
|
|
|
|
// * @depends testCreateBooleanAttribute
|
|
|
|
|
// * @depends testCreateFloatAttribute
|
|
|
|
|
// * @depends testCreateEmailAttribute
|
|
|
|
|
// * @depends testCreateEnumAttribute
|
|
|
|
|
// * @depends testCreateDatetimeAttribute
|
|
|
|
|
// * @throws Exception
|
|
|
|
|
// */
|
|
|
|
|
// public function testCreateCustomEntity(): array
|
|
|
|
|
// {
|
|
|
|
|
// $projectId = $this->getProject()['$id'];
|
|
|
|
|
// $query = $this->getQuery(self::$CREATE_CUSTOM_ENTITY);
|
|
|
|
|
// $gqlPayload = [
|
|
|
|
|
// 'query' => $query,
|
|
|
|
|
// 'variables' => [
|
|
|
|
|
// 'name' => 'John Doe',
|
|
|
|
|
// 'age' => 35,
|
|
|
|
|
// 'alive' => true,
|
|
|
|
|
// 'salary' => 9999.9,
|
|
|
|
|
// 'email' => 'johndoe@appwrite.io',
|
|
|
|
|
// 'role' => 'crew',
|
|
|
|
|
// 'dob' => '2000-01-01T00:00:00Z',
|
|
|
|
|
// ]
|
|
|
|
|
// ];
|
|
|
|
|
//
|
|
|
|
|
// $actor = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
// 'content-type' => 'application/json',
|
|
|
|
|
// 'x-appwrite-project' => $projectId,
|
|
|
|
|
// ], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
//
|
|
|
|
|
// $this->assertArrayNotHasKey('errors', $actor['body']);
|
|
|
|
|
// $this->assertIsArray($actor['body']['data']);
|
|
|
|
|
// $actor = $actor['body']['data']['actorsCreate'];
|
|
|
|
|
// $this->assertIsArray($actor);
|
|
|
|
|
//
|
|
|
|
|
// return $actor;
|
|
|
|
|
// }
|
2022-07-06 05:12:12 +00:00
|
|
|
|
|
|
|
|
public function testGetDatabases(): void
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
|
$query = $this->getQuery(self::$GET_DATABASES);
|
|
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$databases = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $databases['body']);
|
|
|
|
|
$this->assertIsArray($databases['body']['data']);
|
|
|
|
|
$this->assertIsArray($databases['body']['data']['databasesList']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateDatabase
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testGetDatabase($database): void
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
|
$query = $this->getQuery(self::$GET_DATABASE);
|
|
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $database['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$database = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $database['body']);
|
|
|
|
|
$this->assertIsArray($database['body']['data']);
|
|
|
|
|
$this->assertIsArray($database['body']['data']['databasesGet']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateCollection
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testGetCollections($data): void
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$GET_COLLECTIONS);
|
2022-07-06 05:12:12 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$collections = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $collections['body']);
|
|
|
|
|
$this->assertIsArray($collections['body']['data']);
|
2025-05-09 12:08:02 +00:00
|
|
|
$this->assertIsArray($collections['body']['data']['databasesListCollections']);
|
2022-07-06 05:12:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateCollection
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testGetCollection($data): void
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$GET_COLLECTION);
|
2022-07-06 05:12:12 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$collection = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $collection['body']);
|
|
|
|
|
$this->assertIsArray($collection['body']['data']);
|
2025-05-09 12:08:02 +00:00
|
|
|
$this->assertIsArray($collection['body']['data']['databasesGetCollection']);
|
2022-07-06 05:12:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-03-10 13:06:46 +00:00
|
|
|
* @depends testUpdateStringAttribute
|
|
|
|
|
* @depends testUpdateIntegerAttribute
|
2022-07-06 05:12:12 +00:00
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testGetAttributes($data): void
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$GET_ATTRIBUTES);
|
2022-07-06 05:12:12 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attributes = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $attributes['body']);
|
|
|
|
|
$this->assertIsArray($attributes['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attributes['body']['data']['collectionsListAttributes']);
|
2022-07-06 05:12:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateCollection
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testGetAttribute($data): void
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$GET_ATTRIBUTE);
|
2022-07-06 05:12:12 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
'key' => 'name',
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $attribute['body']);
|
|
|
|
|
$this->assertIsArray($attribute['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($attribute['body']['data']['collectionsGetAttribute']);
|
2022-07-06 05:12:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateIndex
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testGetIndexes($data): void
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
|
$query = $this->getQuery(self::$GET_INDEXES);
|
|
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$indices = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $indices['body']);
|
|
|
|
|
$this->assertIsArray($indices['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($indices['body']['data']['collectionsListIndexes']);
|
2022-07-06 05:12:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateIndex
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testGetIndex($data): void
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
|
$query = $this->getQuery(self::$GET_INDEX);
|
|
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
'key' => $data['index']['key'],
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$index = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $index['body']);
|
|
|
|
|
$this->assertIsArray($index['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($index['body']['data']['collectionsGetIndex']);
|
2022-07-06 05:12:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateCollection
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testGetDocuments($data): void
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$GET_DOCUMENTS);
|
2022-07-06 05:12:12 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$documents = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $documents['body']);
|
|
|
|
|
$this->assertIsArray($documents['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($documents['body']['data']['collectionsListDocuments']);
|
2022-07-06 05:12:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateDocument
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testGetDocument($data): void
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$GET_DOCUMENT);
|
2022-07-06 05:12:12 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
|
|
|
|
'documentId' => $data['document']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$document = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $document['body']);
|
|
|
|
|
$this->assertIsArray($document['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$this->assertIsArray($document['body']['data']['collectionsGetDocument']);
|
2022-07-06 05:12:12 +00:00
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:06:46 +00:00
|
|
|
// /**
|
|
|
|
|
// * @depends testCreateCustomEntity
|
|
|
|
|
// * @throws Exception
|
|
|
|
|
// */
|
|
|
|
|
// public function testGetCustomEntities($data)
|
|
|
|
|
// {
|
|
|
|
|
// $projectId = $this->getProject()['$id'];
|
|
|
|
|
// $query = $this->getQuery(self::$GET_CUSTOM_ENTITIES);
|
|
|
|
|
// $gqlPayload = [
|
|
|
|
|
// 'query' => $query,
|
|
|
|
|
// ];
|
|
|
|
|
//
|
|
|
|
|
// $customEntities = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
// 'content-type' => 'application/json',
|
|
|
|
|
// 'x-appwrite-project' => $projectId,
|
|
|
|
|
// ], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
//
|
|
|
|
|
// $this->assertArrayNotHasKey('errors', $customEntities['body']);
|
|
|
|
|
// $this->assertIsArray($customEntities['body']['data']);
|
|
|
|
|
// $this->assertIsArray($customEntities['body']['data']['actorsList']);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
|
// * @depends testCreateCustomEntity
|
|
|
|
|
// * @throws Exception
|
|
|
|
|
// */
|
|
|
|
|
// public function testGetCustomEntity($data)
|
|
|
|
|
// {
|
|
|
|
|
// $projectId = $this->getProject()['$id'];
|
|
|
|
|
// $query = $this->getQuery(self::$GET_CUSTOM_ENTITY);
|
|
|
|
|
// $gqlPayload = [
|
|
|
|
|
// 'query' => $query,
|
|
|
|
|
// 'variables' => [
|
|
|
|
|
// 'id' => $data['id'],
|
|
|
|
|
// ]
|
|
|
|
|
// ];
|
|
|
|
|
//
|
|
|
|
|
// $entity = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
// 'content-type' => 'application/json',
|
|
|
|
|
// 'x-appwrite-project' => $projectId,
|
|
|
|
|
// ], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
//
|
|
|
|
|
// $this->assertArrayNotHasKey('errors', $entity['body']);
|
|
|
|
|
// $this->assertIsArray($entity['body']['data']);
|
|
|
|
|
// $this->assertIsArray($entity['body']['data']['actorsGet']);
|
|
|
|
|
// }
|
2022-07-06 05:12:12 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateDatabase
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateDatabase($database)
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
|
$query = $this->getQuery(self::$UPDATE_DATABASE);
|
|
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $database['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
'name' => 'New Database Name',
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$database = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $database['body']);
|
|
|
|
|
$this->assertIsArray($database['body']['data']);
|
|
|
|
|
$this->assertIsArray($database['body']['data']['databasesUpdate']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateCollection
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateCollection($data)
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$UPDATE_COLLECTION);
|
2022-07-06 05:12:12 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
'name' => 'New Collection Name',
|
2022-09-21 08:17:17 +00:00
|
|
|
'documentSecurity' => false,
|
2022-07-06 05:12:12 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$collection = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $collection['body']);
|
|
|
|
|
$this->assertIsArray($collection['body']['data']);
|
2025-05-09 12:08:02 +00:00
|
|
|
$this->assertIsArray($collection['body']['data']['databasesUpdateCollection']);
|
2022-07-06 05:12:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateDocument
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateDocument($data): void
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$UPDATE_DOCUMENT);
|
2022-07-06 05:12:12 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
|
|
|
|
'documentId' => $data['document']['_id'],
|
2022-07-06 05:12:12 +00:00
|
|
|
'data' => [
|
|
|
|
|
'name' => 'New Document Name',
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$document = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $document['body']);
|
|
|
|
|
$this->assertIsArray($document['body']['data']);
|
2025-05-09 12:45:17 +00:00
|
|
|
$document = $document['body']['data']['collectionsUpdateDocument'];
|
2022-07-06 05:12:12 +00:00
|
|
|
$this->assertIsArray($document);
|
|
|
|
|
$this->assertStringContainsString('New Document Name', $document['data']);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:06:46 +00:00
|
|
|
// /**
|
|
|
|
|
// * @depends testCreateCustomEntity
|
|
|
|
|
// * @throws Exception
|
|
|
|
|
// */
|
|
|
|
|
// public function testUpdateCustomEntity(array $data)
|
|
|
|
|
// {
|
|
|
|
|
// $projectId = $this->getProject()['$id'];
|
|
|
|
|
// $query = $this->getQuery(self::$UPDATE_CUSTOM_ENTITY);
|
|
|
|
|
// $gqlPayload = [
|
|
|
|
|
// 'query' => $query,
|
|
|
|
|
// 'variables' => [
|
|
|
|
|
// 'id' => $data['id'],
|
|
|
|
|
// 'name' => 'New Custom Entity Name',
|
|
|
|
|
// ]
|
|
|
|
|
// ];
|
|
|
|
|
//
|
|
|
|
|
// $entity = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
// 'content-type' => 'application/json',
|
|
|
|
|
// 'x-appwrite-project' => $projectId,
|
|
|
|
|
// ], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
//
|
|
|
|
|
// $this->assertArrayNotHasKey('errors', $entity['body']);
|
|
|
|
|
// $this->assertIsArray($entity['body']['data']);
|
|
|
|
|
// $entity = $entity['body']['data']['actorsUpdate'];
|
|
|
|
|
// $this->assertIsArray($entity);
|
|
|
|
|
// $this->assertStringContainsString('New Custom Entity Name', $entity['name']);
|
|
|
|
|
// }
|
2022-09-22 08:29:42 +00:00
|
|
|
|
2022-07-07 00:53:58 +00:00
|
|
|
/**
|
|
|
|
|
* @depends testCreateDocument
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testDeleteDocument($data): void
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$DELETE_DOCUMENT);
|
2022-07-07 00:53:58 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
|
|
|
|
'documentId' => $data['document']['_id'],
|
2022-07-07 00:53:58 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$document = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
2022-07-18 09:38:13 +00:00
|
|
|
$this->assertIsNotArray($document['body']);
|
2022-07-13 07:38:44 +00:00
|
|
|
$this->assertEquals(204, $document['headers']['status-code']);
|
2022-07-07 00:53:58 +00:00
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:06:46 +00:00
|
|
|
// /**
|
|
|
|
|
// * @depends testCreateCustomEntity
|
|
|
|
|
// * @throws Exception
|
|
|
|
|
// */
|
|
|
|
|
// public function testDeleteCustomEntity(array $data)
|
|
|
|
|
// {
|
|
|
|
|
// $projectId = $this->getProject()['$id'];
|
|
|
|
|
// $query = $this->getQuery(self::$DELETE_CUSTOM_ENTITY);
|
|
|
|
|
// $gqlPayload = [
|
|
|
|
|
// 'query' => $query,
|
|
|
|
|
// 'variables' => [
|
|
|
|
|
// 'id' => $data['id'],
|
|
|
|
|
// ]
|
|
|
|
|
// ];
|
|
|
|
|
//
|
|
|
|
|
// $entity = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
// 'content-type' => 'application/json',
|
|
|
|
|
// 'x-appwrite-project' => $projectId,
|
|
|
|
|
// ], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
//
|
|
|
|
|
// $this->assertIsNotArray($entity['body']);
|
|
|
|
|
// $this->assertEquals(204, $entity['headers']['status-code']);
|
|
|
|
|
// }
|
2022-09-23 01:46:39 +00:00
|
|
|
|
2022-07-07 00:53:58 +00:00
|
|
|
/**
|
2023-03-10 13:06:46 +00:00
|
|
|
* @depends testUpdateStringAttribute
|
2022-07-07 00:53:58 +00:00
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testDeleteAttribute($data): void
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$DELETE_ATTRIBUTE);
|
2022-07-07 00:53:58 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-07-07 00:53:58 +00:00
|
|
|
'key' => 'name',
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
2022-07-18 09:38:13 +00:00
|
|
|
$this->assertIsNotArray($attribute['body']);
|
2022-07-07 00:53:58 +00:00
|
|
|
$this->assertEquals(204, $attribute['headers']['status-code']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateCollection
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testDeleteCollection($data)
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-05-09 12:08:02 +00:00
|
|
|
$query = $this->getQuery(self::$DELETE_COLLECTION);
|
2022-07-07 00:53:58 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 12:08:02 +00:00
|
|
|
'collectionId' => $data['collection']['_id'],
|
2022-07-07 00:53:58 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$collection = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
2022-07-18 09:38:13 +00:00
|
|
|
$this->assertIsNotArray($collection['body']);
|
2022-07-07 00:53:58 +00:00
|
|
|
$this->assertEquals(204, $collection['headers']['status-code']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testCreateDatabase
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testDeleteDatabase($database)
|
|
|
|
|
{
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
|
$query = $this->getQuery(self::$DELETE_DATABASE);
|
|
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $database['_id'],
|
2022-07-07 00:53:58 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$database = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
2022-07-18 09:38:13 +00:00
|
|
|
$this->assertIsNotArray($database['body']);
|
2022-07-07 00:53:58 +00:00
|
|
|
$this->assertEquals(204, $database['headers']['status-code']);
|
|
|
|
|
}
|
2022-07-01 06:58:03 +00:00
|
|
|
}
|