mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge branch '1.4.x' of https://github.com/appwrite/appwrite into disallow-personal-data
This commit is contained in:
+18
-36
@@ -160,35 +160,21 @@ class Client
|
||||
* @param array $params
|
||||
* @param array $headers
|
||||
* @param bool $decode
|
||||
* @return array|string
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function call(string $method, string $path = '', array $headers = [], array $params = [], bool $decode = true)
|
||||
public function call(string $method, string $path = '', array $headers = [], array $params = [], bool $decode = true): array
|
||||
{
|
||||
$headers = array_merge($this->headers, $headers);
|
||||
$ch = curl_init($this->endpoint . $path . (($method == self::METHOD_GET && !empty($params)) ? '?' . http_build_query($params) : ''));
|
||||
$responseHeaders = [];
|
||||
$responseStatus = -1;
|
||||
$responseType = '';
|
||||
$responseBody = '';
|
||||
|
||||
switch ($headers['content-type']) {
|
||||
case 'application/json':
|
||||
$query = json_encode($params);
|
||||
break;
|
||||
|
||||
case 'multipart/form-data':
|
||||
$query = $this->flatten($params);
|
||||
break;
|
||||
|
||||
case 'application/graphql':
|
||||
$query = $params[0];
|
||||
break;
|
||||
|
||||
default:
|
||||
$query = http_build_query($params);
|
||||
break;
|
||||
}
|
||||
$query = match ($headers['content-type']) {
|
||||
'application/json' => json_encode($params),
|
||||
'multipart/form-data' => $this->flatten($params),
|
||||
'application/graphql' => $params[0],
|
||||
default => http_build_query($params),
|
||||
};
|
||||
|
||||
foreach ($headers as $i => $header) {
|
||||
$headers[] = $i . ':' . $header;
|
||||
@@ -220,7 +206,7 @@ class Client
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
|
||||
}
|
||||
|
||||
// Allow self signed certificates
|
||||
// Allow self-signed certificates
|
||||
if ($this->selfSigned) {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
@@ -230,22 +216,18 @@ class Client
|
||||
$responseType = $responseHeaders['content-type'] ?? '';
|
||||
$responseStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($decode) {
|
||||
switch (substr($responseType, 0, strpos($responseType, ';'))) {
|
||||
case 'application/json':
|
||||
$json = json_decode($responseBody, true);
|
||||
if ($decode && substr($responseType, 0, strpos($responseType, ';')) == 'application/json') {
|
||||
$json = json_decode($responseBody, true);
|
||||
|
||||
if ($json === null) {
|
||||
throw new Exception('Failed to parse response: ' . $responseBody);
|
||||
}
|
||||
|
||||
$responseBody = $json;
|
||||
$json = null;
|
||||
break;
|
||||
if ($json === null) {
|
||||
throw new Exception('Failed to parse response: ' . $responseBody);
|
||||
}
|
||||
|
||||
$responseBody = $json;
|
||||
$json = null;
|
||||
}
|
||||
|
||||
if ((curl_errno($ch)/* || 200 != $responseStatus*/)) {
|
||||
if ((curl_errno($ch))) {
|
||||
throw new Exception(curl_error($ch) . ' with status code ' . $responseStatus, $responseStatus);
|
||||
}
|
||||
|
||||
@@ -273,7 +255,7 @@ class Client
|
||||
{
|
||||
$cookies = [];
|
||||
|
||||
parse_str(strtr($cookie, array('&' => '%26', '+' => '%2B', ';' => '&')), $cookies);
|
||||
parse_str(strtr($cookie, ['&' => '%26', '+' => '%2B', ';' => '&']), $cookies);
|
||||
|
||||
return $cookies;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,12 @@ class HTTPTest extends Scope
|
||||
use ProjectNone;
|
||||
use SideNone;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->client->setEndpoint('http://localhost');
|
||||
}
|
||||
|
||||
public function testOptions()
|
||||
{
|
||||
/**
|
||||
@@ -32,24 +38,6 @@ class HTTPTest extends Scope
|
||||
$this->assertEmpty($response['body']);
|
||||
}
|
||||
|
||||
public function testError()
|
||||
{
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$this->markTestIncomplete('This test needs to be updated for the new console.');
|
||||
// $response = $this->client->call(Client::METHOD_GET, '/error', \array_merge([
|
||||
// 'origin' => 'http://localhost',
|
||||
// 'content-type' => 'application/json',
|
||||
// ]), []);
|
||||
|
||||
// $this->assertEquals(404, $response['headers']['status-code']);
|
||||
// $this->assertEquals('Not Found', $response['body']['message']);
|
||||
// $this->assertEquals(Exception::GENERAL_ROUTE_NOT_FOUND, $response['body']['type']);
|
||||
// $this->assertEquals(404, $response['body']['code']);
|
||||
// $this->assertEquals('dev', $response['body']['version']);
|
||||
}
|
||||
|
||||
public function testHumans()
|
||||
{
|
||||
/**
|
||||
@@ -57,7 +45,7 @@ class HTTPTest extends Scope
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/humans.txt', \array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
]), []);
|
||||
]));
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertStringContainsString('# humanstxt.org/', $response['body']);
|
||||
@@ -70,7 +58,7 @@ class HTTPTest extends Scope
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/robots.txt', \array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
]), []);
|
||||
]));
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertStringContainsString('# robotstxt.org/', $response['body']);
|
||||
@@ -87,18 +75,19 @@ class HTTPTest extends Scope
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/.well-known/acme-challenge/8DdIKX257k6Dih5s_saeVMpTnjPJdKO5Ase0OCiJrIg', \array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
]), []);
|
||||
]));
|
||||
|
||||
$this->assertEquals(404, $response['headers']['status-code']);
|
||||
// 'Unknown path', but validation passed
|
||||
$this->assertEquals(404, $response['headers']['status-code']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/.well-known/acme-challenge/../../../../../../../etc/passwd', \array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
]), []);
|
||||
]));
|
||||
|
||||
// Check for too many path segments
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
|
||||
// Cleanup
|
||||
@@ -171,4 +160,15 @@ class HTTPTest extends Scope
|
||||
$this->assertIsString($body['server-ruby']);
|
||||
$this->assertIsString($body['console-cli']);
|
||||
}
|
||||
|
||||
public function testDefaultOAuth2()
|
||||
{
|
||||
$response = $this->client->call(Client::METHOD_GET, '/auth/oauth2/success', $this->getHeaders());
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/auth/oauth2/failure', $this->getHeaders());
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,7 @@ abstract class Scope extends TestCase
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->client = new Client();
|
||||
|
||||
$this->client
|
||||
->setEndpoint($this->endpoint)
|
||||
;
|
||||
$this->client->setEndpoint($this->endpoint);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
@@ -45,10 +42,10 @@ abstract class Scope extends TestCase
|
||||
{
|
||||
sleep(2);
|
||||
|
||||
$resquest = json_decode(file_get_contents('http://request-catcher:5000/__last_request__'), true);
|
||||
$resquest['data'] = json_decode($resquest['data'], true);
|
||||
$request = json_decode(file_get_contents('http://request-catcher:5000/__last_request__'), true);
|
||||
$request['data'] = json_decode($request['data'], true);
|
||||
|
||||
return $resquest;
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -225,6 +225,8 @@ class AccountCustomClientTest extends Scope
|
||||
]);
|
||||
|
||||
$this->assertEquals($response['headers']['status-code'], 200);
|
||||
$this->assertStringContainsString('a_session_' . $this->getProject()['$id'] . '=deleted', $response['headers']['set-cookie']);
|
||||
$this->assertEquals('[]', $response['headers']['x-fallback-cookies']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
|
||||
@@ -157,6 +157,7 @@ trait DatabasesBase
|
||||
public function testCreateAttributes(array $data): array
|
||||
{
|
||||
$databaseId = $data['databaseId'];
|
||||
|
||||
$title = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/attributes/string', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
@@ -167,6 +168,28 @@ trait DatabasesBase
|
||||
'required' => true,
|
||||
]);
|
||||
|
||||
$description = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/attributes/string', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'key' => 'description',
|
||||
'size' => 512,
|
||||
'required' => false,
|
||||
'default' => '',
|
||||
]);
|
||||
|
||||
$tagline = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/attributes/string', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'key' => 'tagline',
|
||||
'size' => 512,
|
||||
'required' => false,
|
||||
'default' => '',
|
||||
]);
|
||||
|
||||
$releaseYear = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/attributes/integer', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
@@ -226,6 +249,20 @@ trait DatabasesBase
|
||||
$this->assertEquals($title['body']['size'], 256);
|
||||
$this->assertEquals($title['body']['required'], true);
|
||||
|
||||
$this->assertEquals(202, $description['headers']['status-code']);
|
||||
$this->assertEquals($description['body']['key'], 'description');
|
||||
$this->assertEquals($description['body']['type'], 'string');
|
||||
$this->assertEquals($description['body']['size'], 512);
|
||||
$this->assertEquals($description['body']['required'], false);
|
||||
$this->assertEquals($description['body']['default'], '');
|
||||
|
||||
$this->assertEquals(202, $tagline['headers']['status-code']);
|
||||
$this->assertEquals($tagline['body']['key'], 'tagline');
|
||||
$this->assertEquals($tagline['body']['type'], 'string');
|
||||
$this->assertEquals($tagline['body']['size'], 512);
|
||||
$this->assertEquals($tagline['body']['required'], false);
|
||||
$this->assertEquals($tagline['body']['default'], '');
|
||||
|
||||
$this->assertEquals(202, $releaseYear['headers']['status-code']);
|
||||
$this->assertEquals($releaseYear['body']['key'], 'releaseYear');
|
||||
$this->assertEquals($releaseYear['body']['type'], 'integer');
|
||||
@@ -263,16 +300,18 @@ trait DatabasesBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), []);
|
||||
]));
|
||||
|
||||
$this->assertIsArray($movies['body']['attributes']);
|
||||
$this->assertCount(6, $movies['body']['attributes']);
|
||||
$this->assertCount(8, $movies['body']['attributes']);
|
||||
$this->assertEquals($movies['body']['attributes'][0]['key'], $title['body']['key']);
|
||||
$this->assertEquals($movies['body']['attributes'][1]['key'], $releaseYear['body']['key']);
|
||||
$this->assertEquals($movies['body']['attributes'][2]['key'], $duration['body']['key']);
|
||||
$this->assertEquals($movies['body']['attributes'][3]['key'], $actors['body']['key']);
|
||||
$this->assertEquals($movies['body']['attributes'][4]['key'], $datetime['body']['key']);
|
||||
$this->assertEquals($movies['body']['attributes'][5]['key'], $relationship['body']['key']);
|
||||
$this->assertEquals($movies['body']['attributes'][1]['key'], $description['body']['key']);
|
||||
$this->assertEquals($movies['body']['attributes'][2]['key'], $tagline['body']['key']);
|
||||
$this->assertEquals($movies['body']['attributes'][3]['key'], $releaseYear['body']['key']);
|
||||
$this->assertEquals($movies['body']['attributes'][4]['key'], $duration['body']['key']);
|
||||
$this->assertEquals($movies['body']['attributes'][5]['key'], $actors['body']['key']);
|
||||
$this->assertEquals($movies['body']['attributes'][6]['key'], $datetime['body']['key']);
|
||||
$this->assertEquals($movies['body']['attributes'][7]['key'], $relationship['body']['key']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -868,6 +907,7 @@ trait DatabasesBase
|
||||
public function testCreateIndexes(array $data): array
|
||||
{
|
||||
$databaseId = $data['databaseId'];
|
||||
|
||||
$titleIndex = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
@@ -936,7 +976,6 @@ trait DatabasesBase
|
||||
$this->assertEquals('available', $movies['body']['indexes'][1]['status']);
|
||||
$this->assertEquals('available', $movies['body']['indexes'][2]['status']);
|
||||
|
||||
|
||||
$releaseWithDate = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
@@ -953,6 +992,59 @@ trait DatabasesBase
|
||||
$this->assertCount(1, $releaseWithDate['body']['attributes']);
|
||||
$this->assertEquals('birthDay', $releaseWithDate['body']['attributes'][0]);
|
||||
|
||||
// Test for failure
|
||||
$fulltextReleaseYear = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'key' => 'releaseYearDated',
|
||||
'type' => 'fulltext',
|
||||
'attributes' => ['releaseYear'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $fulltextReleaseYear['headers']['status-code']);
|
||||
$this->assertEquals($fulltextReleaseYear['body']['message'], 'Attribute "releaseYear" cannot be part of a FULLTEXT index, must be of type string');
|
||||
|
||||
$noAttributes = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'key' => 'none',
|
||||
'type' => 'key',
|
||||
'attributes' => [],
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $noAttributes['headers']['status-code']);
|
||||
$this->assertEquals($noAttributes['body']['message'], 'No attributes provided for index');
|
||||
|
||||
$duplicates = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'key' => 'duplicate',
|
||||
'type' => 'fulltext',
|
||||
'attributes' => ['releaseYear', 'releaseYear'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $duplicates['headers']['status-code']);
|
||||
$this->assertEquals($duplicates['body']['message'], 'Duplicate attributes provided');
|
||||
|
||||
$tooLong = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
]), [
|
||||
'key' => 'tooLong',
|
||||
'type' => 'key',
|
||||
'attributes' => ['description', 'tagline'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $tooLong['headers']['status-code']);
|
||||
$this->assertStringContainsString('Index length is longer than the maximum', $tooLong['body']['message']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -1086,6 +1178,12 @@ trait DatabasesBase
|
||||
|
||||
$this->assertEquals(400, $document4['headers']['status-code']);
|
||||
|
||||
// Delete document 4 with incomplete path
|
||||
$this->assertEquals(404, $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents/', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()))['headers']['status-code']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -2853,9 +2951,7 @@ trait DatabasesBase
|
||||
]);
|
||||
|
||||
// Current user has no collection permissions and document permissions are disabled
|
||||
$this->assertEquals(200, $documentsUser2['headers']['status-code']);
|
||||
$this->assertEquals(0, $documentsUser2['body']['total']);
|
||||
$this->assertEquals(true, empty($documentsUser2['body']['documents']));
|
||||
$this->assertEquals(404, $documentsUser2['headers']['status-code']);
|
||||
|
||||
// Enable document permissions
|
||||
$collection = $this->client->call(CLient::METHOD_PUT, '/databases/' . $databaseId . '/collections/' . $collectionId, [
|
||||
@@ -3049,7 +3145,7 @@ trait DatabasesBase
|
||||
$databaseId = $database['body']['$id'];
|
||||
|
||||
// Create collection
|
||||
$movies = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/', array_merge([
|
||||
$movies = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
@@ -3339,6 +3435,26 @@ trait DatabasesBase
|
||||
|
||||
$this->assertEquals('Library 1', $person1['body']['library']['libraryName']);
|
||||
|
||||
// Create without nested ID
|
||||
$person2 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $person['body']['$id'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'documentId' => ID::unique(),
|
||||
'data' => [
|
||||
'library' => [
|
||||
'libraryName' => 'Library 2',
|
||||
],
|
||||
],
|
||||
'permissions' => [
|
||||
Permission::read(Role::user($this->getUser()['$id'])),
|
||||
Permission::update(Role::user($this->getUser()['$id'])),
|
||||
Permission::delete(Role::user($this->getUser()['$id'])),
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertEquals('Library 2', $person2['body']['library']['libraryName']);
|
||||
|
||||
// Ensure IDs were set and internal IDs removed
|
||||
$this->assertEquals($databaseId, $person1['body']['$databaseId']);
|
||||
$this->assertEquals($databaseId, $person1['body']['library']['$databaseId']);
|
||||
@@ -3375,7 +3491,7 @@ trait DatabasesBase
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $documents['headers']['status-code']);
|
||||
$this->assertEquals('Query not valid: Cannot query nested attribute on: library', $documents['body']['message']);
|
||||
$this->assertEquals('Invalid query: Cannot query nested attribute on: library', $documents['body']['message']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $person['body']['$id'] . '/attributes/library', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
@@ -3901,7 +4017,7 @@ trait DatabasesBase
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals(1, count($response['body']['documents']));
|
||||
$this->assertEquals(2, count($response['body']['documents']));
|
||||
$this->assertEquals(null, $response['body']['documents'][0]['fullName']);
|
||||
$this->assertArrayNotHasKey("libraries", $response['body']['documents'][0]);
|
||||
}
|
||||
@@ -3950,4 +4066,105 @@ trait DatabasesBase
|
||||
$this->assertArrayHasKey('fullName', $response['body']);
|
||||
$this->assertArrayNotHasKey('libraries', $response['body']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateDatabase
|
||||
* @param array $data
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testUpdateWithExistingRelationships(array $data): void
|
||||
{
|
||||
$databaseId = $data['databaseId'];
|
||||
|
||||
$collection1 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'collectionId' => ID::unique(),
|
||||
'name' => 'Collection1',
|
||||
'documentSecurity' => true,
|
||||
'permissions' => [
|
||||
Permission::create(Role::user($this->getUser()['$id'])),
|
||||
Permission::read(Role::user($this->getUser()['$id'])),
|
||||
],
|
||||
]);
|
||||
|
||||
$collection2 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'collectionId' => ID::unique(),
|
||||
'name' => 'Collection2',
|
||||
'documentSecurity' => true,
|
||||
'permissions' => [
|
||||
Permission::create(Role::user($this->getUser()['$id'])),
|
||||
Permission::read(Role::user($this->getUser()['$id'])),
|
||||
],
|
||||
]);
|
||||
|
||||
$collection1 = $collection1['body']['$id'];
|
||||
$collection2 = $collection2['body']['$id'];
|
||||
|
||||
$this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collection1 . '/attributes/string', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'key' => 'name',
|
||||
'size' => '49',
|
||||
'required' => true,
|
||||
]);
|
||||
|
||||
$this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collection2 . '/attributes/string', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'key' => 'name',
|
||||
'size' => '49',
|
||||
'required' => true,
|
||||
]);
|
||||
|
||||
$this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collection1 . '/attributes/relationship', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'relatedCollectionId' => $collection2,
|
||||
'type' => Database::RELATION_ONE_TO_MANY,
|
||||
'twoWay' => true,
|
||||
'key' => 'collection2'
|
||||
]);
|
||||
|
||||
sleep(1);
|
||||
|
||||
$document = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collection1 . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id']
|
||||
], $this->getHeaders()), [
|
||||
'documentId' => ID::unique(),
|
||||
'data' => [
|
||||
'name' => 'Document 1',
|
||||
'collection2' => [
|
||||
[
|
||||
'name' => 'Document 2',
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$update = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collection1 . '/documents/' . $document['body']['$id'], array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id']
|
||||
], $this->getHeaders()), [
|
||||
'data' => [
|
||||
'name' => 'Document 1 Updated',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $update['headers']['status-code']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@ class DatabasesConsoleClientTest extends Scope
|
||||
$database = $this->client->call(Client::METHOD_POST, '/databases', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
], $this->getHeaders()), [
|
||||
'databaseId' => ID::unique(),
|
||||
'name' => 'invalidDocumentDatabase',
|
||||
]);
|
||||
$this->assertEquals(201, $database['headers']['status-code']);
|
||||
$this->assertEquals('invalidDocumentDatabase', $database['body']['name']);
|
||||
$this->assertTrue($database['body']['enabled']);
|
||||
|
||||
$databaseId = $database['body']['$id'];
|
||||
/**
|
||||
@@ -50,7 +50,129 @@ class DatabasesConsoleClientTest extends Scope
|
||||
$this->assertEquals(201, $movies['headers']['status-code']);
|
||||
$this->assertEquals($movies['body']['name'], 'Movies');
|
||||
|
||||
return ['moviesId' => $movies['body']['$id'], 'databaseId' => $databaseId];
|
||||
/**
|
||||
* Test When database is disabled but can still create collections
|
||||
*/
|
||||
$database = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'name' => 'invalidDocumentDatabase Updated',
|
||||
'enabled' => false,
|
||||
]);
|
||||
|
||||
$this->assertFalse($database['body']['enabled']);
|
||||
|
||||
$tvShows = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'collectionId' => ID::unique(),
|
||||
'name' => 'TvShows',
|
||||
'permissions' => [
|
||||
Permission::read(Role::any()),
|
||||
Permission::create(Role::any()),
|
||||
Permission::update(Role::any()),
|
||||
Permission::delete(Role::any()),
|
||||
],
|
||||
'documentSecurity' => true,
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $tvShows['headers']['status-code']);
|
||||
$this->assertEquals($tvShows['body']['name'], 'TvShows');
|
||||
|
||||
return ['moviesId' => $movies['body']['$id'], 'databaseId' => $databaseId, 'tvShowsId' => $tvShows['body']['$id']];
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateCollection
|
||||
* @param array $data
|
||||
*/
|
||||
public function testListCollection(array $data)
|
||||
{
|
||||
/**
|
||||
* Test When database is disabled but can still call list collections
|
||||
*/
|
||||
$databaseId = $data['databaseId'];
|
||||
|
||||
$collections = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(200, $collections['headers']['status-code']);
|
||||
$this->assertEquals(2, $collections['body']['total']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateCollection
|
||||
* @param array $data
|
||||
*/
|
||||
public function testGetCollection(array $data)
|
||||
{
|
||||
$databaseId = $data['databaseId'];
|
||||
$moviesCollectionId = $data['moviesId'];
|
||||
|
||||
/**
|
||||
* Test When database is disabled but can still call get collection
|
||||
*/
|
||||
$collection = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $moviesCollectionId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(200, $collection['headers']['status-code']);
|
||||
$this->assertEquals('Movies', $collection['body']['name']);
|
||||
$this->assertEquals($moviesCollectionId, $collection['body']['$id']);
|
||||
$this->assertTrue($collection['body']['enabled']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateCollection
|
||||
* @param array $data
|
||||
*/
|
||||
public function testUpdateCollection(array $data)
|
||||
{
|
||||
$databaseId = $data['databaseId'];
|
||||
$moviesCollectionId = $data['moviesId'];
|
||||
|
||||
/**
|
||||
* Test When database is disabled but can still call update collection
|
||||
*/
|
||||
$collection = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/collections/' . $moviesCollectionId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'name' => 'Movies Updated',
|
||||
'enabled' => false
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $collection['headers']['status-code']);
|
||||
$this->assertEquals('Movies Updated', $collection['body']['name']);
|
||||
$this->assertEquals($moviesCollectionId, $collection['body']['$id']);
|
||||
$this->assertFalse($collection['body']['enabled']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateCollection
|
||||
* @param array $data
|
||||
*/
|
||||
public function testDeleteCollection(array $data)
|
||||
{
|
||||
$databaseId = $data['databaseId'];
|
||||
$tvShowsId = $data['tvShowsId'];
|
||||
|
||||
/**
|
||||
* Test When database is disabled but can still call Delete collection
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $tvShowsId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(204, $response['headers']['status-code']);
|
||||
$this->assertEquals($response['body'], "");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,6 +27,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'databaseId' => ID::custom('first'),
|
||||
'name' => 'Test 1',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $test1['headers']['status-code']);
|
||||
$this->assertEquals('Test 1', $test1['body']['name']);
|
||||
|
||||
@@ -56,7 +57,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'limit(1)' ],
|
||||
'queries' => ['limit(1)'],
|
||||
]);
|
||||
$this->assertEquals(200, $databases['headers']['status-code']);
|
||||
$this->assertCount(1, $databases['body']['databases']);
|
||||
@@ -65,7 +66,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'offset(1)' ],
|
||||
'queries' => ['offset(1)'],
|
||||
]);
|
||||
$this->assertEquals(200, $databases['headers']['status-code']);
|
||||
$this->assertCount(1, $databases['body']['databases']);
|
||||
@@ -74,7 +75,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'equal("name", ["Test 1", "Test 2"])' ],
|
||||
'queries' => ['equal("name", ["Test 1", "Test 2"])'],
|
||||
]);
|
||||
$this->assertEquals(200, $databases['headers']['status-code']);
|
||||
$this->assertCount(2, $databases['body']['databases']);
|
||||
@@ -83,7 +84,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'equal("name", "Test 2")' ],
|
||||
'queries' => ['equal("name", "Test 2")'],
|
||||
]);
|
||||
$this->assertEquals(200, $databases['headers']['status-code']);
|
||||
$this->assertCount(1, $databases['body']['databases']);
|
||||
@@ -92,7 +93,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'equal("$id", "first")' ],
|
||||
'queries' => ['equal("$id", "first")'],
|
||||
]);
|
||||
$this->assertEquals(200, $databases['headers']['status-code']);
|
||||
$this->assertCount(1, $databases['body']['databases']);
|
||||
@@ -104,7 +105,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'orderDesc("")' ],
|
||||
'queries' => ['orderDesc("")'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(2, $databases['body']['total']);
|
||||
@@ -123,7 +124,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'cursorAfter("' . $base['body']['databases'][0]['$id'] . '")' ],
|
||||
'queries' => ['cursorAfter("' . $base['body']['databases'][0]['$id'] . '")'],
|
||||
]);
|
||||
|
||||
$this->assertCount(1, $databases['body']['databases']);
|
||||
@@ -133,7 +134,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'cursorAfter("' . $base['body']['databases'][1]['$id'] . '")' ],
|
||||
'queries' => ['cursorAfter("' . $base['body']['databases'][1]['$id'] . '")'],
|
||||
]);
|
||||
|
||||
$this->assertCount(0, $databases['body']['databases']);
|
||||
@@ -151,7 +152,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'cursorBefore("' . $base['body']['databases'][1]['$id'] . '")' ],
|
||||
'queries' => ['cursorBefore("' . $base['body']['databases'][1]['$id'] . '")'],
|
||||
]);
|
||||
|
||||
$this->assertCount(1, $databases['body']['databases']);
|
||||
@@ -161,7 +162,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'cursorBefore("' . $base['body']['databases'][0]['$id'] . '")' ],
|
||||
'queries' => ['cursorBefore("' . $base['body']['databases'][0]['$id'] . '")'],
|
||||
]);
|
||||
|
||||
$this->assertCount(0, $databases['body']['databases']);
|
||||
@@ -207,7 +208,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'cursorAfter("unknown")' ],
|
||||
'queries' => ['cursorAfter("unknown")'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
@@ -244,10 +245,44 @@ class DatabasesCustomServerTest extends Scope
|
||||
$this->assertEquals(200, $database['headers']['status-code']);
|
||||
$this->assertEquals($databaseId, $database['body']['$id']);
|
||||
$this->assertEquals('Test 1', $database['body']['name']);
|
||||
|
||||
$this->assertEquals(true, $database['body']['enabled']);
|
||||
return ['databaseId' => $database['body']['$id']];
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testListDatabases
|
||||
*/
|
||||
public function testUpdateDatabase(array $data)
|
||||
{
|
||||
$databaseId = $data['databaseId'];
|
||||
|
||||
$database = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId, [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
], [
|
||||
'name' => 'Test 1 Updated',
|
||||
'enabled' => false,
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $database['headers']['status-code']);
|
||||
$this->assertEquals('Test 1 Updated', $database['body']['name']);
|
||||
$this->assertFalse($database['body']['enabled']);
|
||||
|
||||
// Now update the database without the passing the enabled parameter
|
||||
$database = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId, [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
], [
|
||||
'name' => 'Test 1'
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $database['headers']['status-code']);
|
||||
$this->assertEquals('Test 1', $database['body']['name']);
|
||||
$this->assertTrue($database['body']['enabled']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testListDatabases
|
||||
*/
|
||||
@@ -273,7 +308,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
$this->assertEquals(404, $response['headers']['status-code']);
|
||||
}
|
||||
|
||||
public function testListCollections()
|
||||
public function testListCollections(): array
|
||||
{
|
||||
$database = $this->client->call(Client::METHOD_POST, '/databases', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
@@ -285,6 +320,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
]);
|
||||
$this->assertEquals(201, $database['headers']['status-code']);
|
||||
$this->assertEquals('invalidDocumentDatabase', $database['body']['name']);
|
||||
$this->assertTrue($database['body']['enabled']);
|
||||
|
||||
$databaseId = $database['body']['$id'];
|
||||
/**
|
||||
@@ -329,7 +365,9 @@ class DatabasesCustomServerTest extends Scope
|
||||
|
||||
$this->assertEquals(2, $collections['body']['total']);
|
||||
$this->assertEquals($test1['body']['$id'], $collections['body']['collections'][0]['$id']);
|
||||
$this->assertEquals($test1['body']['enabled'], $collections['body']['collections'][0]['enabled']);
|
||||
$this->assertEquals($test2['body']['$id'], $collections['body']['collections'][1]['$id']);
|
||||
$this->assertEquals($test1['body']['enabled'], $collections['body']['collections'][0]['enabled']);
|
||||
|
||||
$base = array_reverse($collections['body']['collections']);
|
||||
|
||||
@@ -337,7 +375,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'limit(1)' ]
|
||||
'queries' => ['limit(1)']
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $collections['headers']['status-code']);
|
||||
@@ -347,7 +385,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'offset(1)' ]
|
||||
'queries' => ['offset(1)']
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $collections['headers']['status-code']);
|
||||
@@ -357,7 +395,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'equal("enabled", true)' ]
|
||||
'queries' => ['equal("enabled", true)']
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $collections['headers']['status-code']);
|
||||
@@ -367,7 +405,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'equal("enabled", false)' ]
|
||||
'queries' => ['equal("enabled", false)']
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $collections['headers']['status-code']);
|
||||
@@ -380,7 +418,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'orderDesc("")' ],
|
||||
'queries' => ['orderDesc("")'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(2, $collections['body']['total']);
|
||||
@@ -399,7 +437,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'cursorAfter("' . $base['body']['collections'][0]['$id'] . '")' ],
|
||||
'queries' => ['cursorAfter("' . $base['body']['collections'][0]['$id'] . '")'],
|
||||
]);
|
||||
|
||||
$this->assertCount(1, $collections['body']['collections']);
|
||||
@@ -409,7 +447,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'cursorAfter("' . $base['body']['collections'][1]['$id'] . '")' ],
|
||||
'queries' => ['cursorAfter("' . $base['body']['collections'][1]['$id'] . '")'],
|
||||
]);
|
||||
|
||||
$this->assertCount(0, $collections['body']['collections']);
|
||||
@@ -427,7 +465,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'cursorBefore("' . $base['body']['collections'][1]['$id'] . '")' ],
|
||||
'queries' => ['cursorBefore("' . $base['body']['collections'][1]['$id'] . '")'],
|
||||
]);
|
||||
|
||||
$this->assertCount(1, $collections['body']['collections']);
|
||||
@@ -437,7 +475,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'cursorBefore("' . $base['body']['collections'][0]['$id'] . '")' ],
|
||||
'queries' => ['cursorBefore("' . $base['body']['collections'][0]['$id'] . '")'],
|
||||
]);
|
||||
|
||||
$this->assertCount(0, $collections['body']['collections']);
|
||||
@@ -483,7 +521,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'cursorAfter("unknown")' ],
|
||||
'queries' => ['cursorAfter("unknown")'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
@@ -506,6 +544,53 @@ class DatabasesCustomServerTest extends Scope
|
||||
]);
|
||||
|
||||
$this->assertEquals(409, $response['headers']['status-code']);
|
||||
return [
|
||||
'databaseId' => $databaseId,
|
||||
'collectionId' => $test1['body']['$id'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testListCollections
|
||||
*/
|
||||
public function testGetCollection(array $data): void
|
||||
{
|
||||
$databaseId = $data['databaseId'];
|
||||
$collectionId = $data['collectionId'];
|
||||
|
||||
$collection = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(200, $collection['headers']['status-code']);
|
||||
$this->assertEquals('Test 1', $collection['body']['name']);
|
||||
$this->assertEquals('first', $collection['body']['$id']);
|
||||
$this->assertTrue($collection['body']['enabled']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testListCollections
|
||||
*/
|
||||
public function testUpdateCollection(array $data)
|
||||
{
|
||||
$databaseId = $data['databaseId'];
|
||||
$collectionId = $data['collectionId'];
|
||||
|
||||
$collection = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'name' => 'Test 1 Updated',
|
||||
'enabled' => false
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $collection['headers']['status-code']);
|
||||
$this->assertEquals('Test 1 Updated', $collection['body']['name']);
|
||||
$this->assertEquals('first', $collection['body']['$id']);
|
||||
$this->assertFalse($collection['body']['enabled']);
|
||||
}
|
||||
|
||||
public function testDeleteAttribute(): array
|
||||
@@ -589,7 +674,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'data' => [
|
||||
'firstName' => 'lorem',
|
||||
'lastName' => 'ipsum',
|
||||
'unneeded' => 'dolor'
|
||||
'unneeded' => 'dolor'
|
||||
],
|
||||
'permissions' => [
|
||||
Permission::read(Role::any()),
|
||||
@@ -1432,7 +1517,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$attribute = array_values(array_filter($new['body']['attributes'], fn (array $a) => $a['key'] === $key))[0] ?? null;
|
||||
$attribute = array_values(array_filter($new['body']['attributes'], fn(array $a) => $a['key'] === $key))[0] ?? null;
|
||||
$this->assertNotNull($attribute);
|
||||
$this->assertFalse($attribute['required']);
|
||||
$this->assertEquals('lorem', $attribute['default']);
|
||||
@@ -1574,7 +1659,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$attribute = array_values(array_filter($new['body']['attributes'], fn (array $a) => $a['key'] === $key))[0] ?? null;
|
||||
$attribute = array_values(array_filter($new['body']['attributes'], fn(array $a) => $a['key'] === $key))[0] ?? null;
|
||||
$this->assertNotNull($attribute);
|
||||
$this->assertFalse($attribute['required']);
|
||||
$this->assertEquals('torsten@appwrite.io', $attribute['default']);
|
||||
@@ -1717,7 +1802,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$attribute = array_values(array_filter($new['body']['attributes'], fn (array $a) => $a['key'] === $key))[0] ?? null;
|
||||
$attribute = array_values(array_filter($new['body']['attributes'], fn(array $a) => $a['key'] === $key))[0] ?? null;
|
||||
$this->assertNotNull($attribute);
|
||||
$this->assertFalse($attribute['required']);
|
||||
$this->assertEquals('127.0.0.1', $attribute['default']);
|
||||
@@ -1859,7 +1944,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$attribute = array_values(array_filter($new['body']['attributes'], fn (array $a) => $a['key'] === $key))[0] ?? null;
|
||||
$attribute = array_values(array_filter($new['body']['attributes'], fn(array $a) => $a['key'] === $key))[0] ?? null;
|
||||
$this->assertNotNull($attribute);
|
||||
$this->assertFalse($attribute['required']);
|
||||
$this->assertEquals('http://appwrite.io', $attribute['default']);
|
||||
@@ -2005,7 +2090,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$attribute = array_values(array_filter($new['body']['attributes'], fn (array $a) => $a['key'] === $key))[0] ?? null;
|
||||
$attribute = array_values(array_filter($new['body']['attributes'], fn(array $a) => $a['key'] === $key))[0] ?? null;
|
||||
$this->assertNotNull($attribute);
|
||||
$this->assertFalse($attribute['required']);
|
||||
$this->assertEquals(123, $attribute['default']);
|
||||
@@ -2268,7 +2353,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$attribute = array_values(array_filter($new['body']['attributes'], fn (array $a) => $a['key'] === $key))[0] ?? null;
|
||||
$attribute = array_values(array_filter($new['body']['attributes'], fn(array $a) => $a['key'] === $key))[0] ?? null;
|
||||
$this->assertNotNull($attribute);
|
||||
$this->assertFalse($attribute['required']);
|
||||
$this->assertEquals(123.456, $attribute['default']);
|
||||
@@ -2527,7 +2612,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$attribute = array_values(array_filter($new['body']['attributes'], fn (array $a) => $a['key'] === $key))[0] ?? null;
|
||||
$attribute = array_values(array_filter($new['body']['attributes'], fn(array $a) => $a['key'] === $key))[0] ?? null;
|
||||
$this->assertNotNull($attribute);
|
||||
$this->assertFalse($attribute['required']);
|
||||
$this->assertEquals(true, $attribute['default']);
|
||||
@@ -2669,7 +2754,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$attribute = array_values(array_filter($new['body']['attributes'], fn (array $a) => $a['key'] === $key))[0] ?? null;
|
||||
$attribute = array_values(array_filter($new['body']['attributes'], fn(array $a) => $a['key'] === $key))[0] ?? null;
|
||||
$this->assertNotNull($attribute);
|
||||
$this->assertFalse($attribute['required']);
|
||||
$this->assertEquals('1975-06-12 14:12:55+02:00', $attribute['default']);
|
||||
@@ -2816,7 +2901,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$attribute = array_values(array_filter($new['body']['attributes'], fn (array $a) => $a['key'] === $key))[0] ?? null;
|
||||
$attribute = array_values(array_filter($new['body']['attributes'], fn(array $a) => $a['key'] === $key))[0] ?? null;
|
||||
$this->assertNotNull($attribute);
|
||||
$this->assertFalse($attribute['required']);
|
||||
$this->assertEquals('lorem', $attribute['default']);
|
||||
|
||||
@@ -176,7 +176,7 @@ class DatabasesPermissionsTeamTest extends Scope
|
||||
if ($success) {
|
||||
$this->assertCount(1, $documents['body']['documents']);
|
||||
} else {
|
||||
$this->assertCount(0, $documents['body']['documents']);
|
||||
$this->assertEquals(404, $documents['headers']['status-code']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -119,11 +119,11 @@ class FunctionsCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'limit(0)' ]
|
||||
'queries' => [ 'limit(1)' ]
|
||||
]);
|
||||
|
||||
$this->assertEquals($response['headers']['status-code'], 200);
|
||||
$this->assertCount(0, $response['body']['functions']);
|
||||
$this->assertCount(1, $response['body']['functions']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/functions', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
@@ -675,11 +675,11 @@ class FunctionsCustomServerTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'limit(0)' ]
|
||||
'queries' => [ 'limit(1)' ]
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertCount(0, $response['body']['executions']);
|
||||
$this->assertCount(1, $response['body']['executions']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/executions', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
|
||||
@@ -77,7 +77,7 @@ class StorageServerTest extends Scope
|
||||
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'),
|
||||
];
|
||||
|
||||
$file = $this->client->call(Client::METHOD_POST, '/graphql/upload', \array_merge([
|
||||
$file = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
||||
'content-type' => 'multipart/form-data',
|
||||
'x-appwrite-project' => $projectId,
|
||||
], $this->getHeaders()), $gqlPayload);
|
||||
|
||||
@@ -19,6 +19,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
use ProjectConsole;
|
||||
use SideClient;
|
||||
|
||||
/** @group projectsCRUD */
|
||||
public function testCreateProject(): array
|
||||
{
|
||||
/**
|
||||
@@ -99,12 +100,110 @@ class ProjectsConsoleClientTest extends Scope
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
|
||||
return ['projectId' => $projectId];
|
||||
return [
|
||||
'projectId' => $projectId,
|
||||
'teamId' => $team['body']['$id']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateProject
|
||||
*/
|
||||
public function testCreateDuplicateProject($data)
|
||||
{
|
||||
$teamId = $data['teamId'] ?? '';
|
||||
$projectId = $data['projectId'] ?? '';
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'projectId' => $projectId,
|
||||
'name' => 'Project Duplicate',
|
||||
'teamId' => $teamId,
|
||||
'region' => 'default'
|
||||
]);
|
||||
|
||||
$this->assertEquals(409, $response['headers']['status-code']);
|
||||
$this->assertEquals(409, $response['body']['code']);
|
||||
$this->assertEquals(Exception::PROJECT_ALREADY_EXISTS, $response['body']['type']);
|
||||
$this->assertEquals('Project with the requested ID already exists.', $response['body']['message']);
|
||||
}
|
||||
|
||||
/** @group projectsCRUD */
|
||||
public function testTransferProjectTeam()
|
||||
{
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'teamId' => ID::unique(),
|
||||
'name' => 'Team 1',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $team['headers']['status-code']);
|
||||
$this->assertEquals('Team 1', $team['body']['name']);
|
||||
$this->assertNotEmpty($team['body']['$id']);
|
||||
|
||||
$team1 = $team['body']['$id'];
|
||||
|
||||
$team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'teamId' => ID::unique(),
|
||||
'name' => 'Team 2',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $team['headers']['status-code']);
|
||||
$this->assertEquals('Team 2', $team['body']['name']);
|
||||
$this->assertNotEmpty($team['body']['$id']);
|
||||
|
||||
$team2 = $team['body']['$id'];
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'projectId' => ID::unique(),
|
||||
'name' => 'Team 1 Project',
|
||||
'teamId' => $team1,
|
||||
'region' => 'default',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertEquals('Team 1 Project', $response['body']['name']);
|
||||
$this->assertEquals($team1, $response['body']['teamId']);
|
||||
$this->assertArrayHasKey('platforms', $response['body']);
|
||||
$this->assertArrayHasKey('webhooks', $response['body']);
|
||||
$this->assertArrayHasKey('keys', $response['body']);
|
||||
|
||||
$projectId = $response['body']['$id'];
|
||||
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/team', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'teamId' => $team2,
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertEquals('Team 1 Project', $response['body']['name']);
|
||||
$this->assertEquals($team2, $response['body']['teamId']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group projectsCRUD
|
||||
* @depends testCreateProject
|
||||
*/
|
||||
public function testListProject($data): array
|
||||
{
|
||||
$id = $data['projectId'] ?? '';
|
||||
@@ -134,9 +233,9 @@ class ProjectsConsoleClientTest extends Scope
|
||||
]));
|
||||
|
||||
$this->assertEquals($response['headers']['status-code'], 200);
|
||||
$this->assertEquals($response['body']['total'], 2);
|
||||
$this->assertEquals($response['body']['total'], 3);
|
||||
$this->assertIsArray($response['body']['projects']);
|
||||
$this->assertCount(2, $response['body']['projects']);
|
||||
$this->assertCount(3, $response['body']['projects']);
|
||||
$this->assertEquals($response['body']['projects'][0]['name'], 'Project Test');
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
|
||||
@@ -147,9 +246,9 @@ class ProjectsConsoleClientTest extends Scope
|
||||
]));
|
||||
|
||||
$this->assertEquals($response['headers']['status-code'], 200);
|
||||
$this->assertEquals($response['body']['total'], 2);
|
||||
$this->assertEquals(3, $response['body']['total']);
|
||||
$this->assertIsArray($response['body']['projects']);
|
||||
$this->assertCount(2, $response['body']['projects']);
|
||||
$this->assertCount(3, $response['body']['projects']);
|
||||
$this->assertEquals($response['body']['projects'][0]['$id'], $data['projectId']);
|
||||
|
||||
/**
|
||||
@@ -213,7 +312,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'offset(2)' ],
|
||||
'queries' => [ 'offset(3)' ],
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
@@ -242,9 +341,9 @@ class ProjectsConsoleClientTest extends Scope
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertCount(3, $response['body']['projects']);
|
||||
$this->assertCount(4, $response['body']['projects']);
|
||||
$this->assertEquals('Project Test 2', $response['body']['projects'][0]['name']);
|
||||
$this->assertEquals('Project Test', $response['body']['projects'][1]['name']);
|
||||
$this->assertEquals('Team 1 Project', $response['body']['projects'][1]['name']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
@@ -253,9 +352,9 @@ class ProjectsConsoleClientTest extends Scope
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertCount(3, $response['body']['projects']);
|
||||
$this->assertCount(4, $response['body']['projects']);
|
||||
$this->assertEquals('Project Test', $response['body']['projects'][0]['name']);
|
||||
$this->assertEquals('Project Test 2', $response['body']['projects'][2]['name']);
|
||||
$this->assertEquals('Team 1 Project', $response['body']['projects'][2]['name']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
@@ -266,8 +365,8 @@ class ProjectsConsoleClientTest extends Scope
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertCount(2, $response['body']['projects']);
|
||||
$this->assertEquals('Project Test 2', $response['body']['projects'][1]['name']);
|
||||
$this->assertCount(3, $response['body']['projects']);
|
||||
$this->assertEquals('Team 1 Project', $response['body']['projects'][1]['name']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
@@ -784,11 +883,11 @@ class ProjectsConsoleClientTest extends Scope
|
||||
|
||||
$this->assertEquals($response['headers']['status-code'], 501);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/anonymous', array_merge([
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/anonymous', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $id,
|
||||
]), []);
|
||||
]));
|
||||
|
||||
$this->assertEquals($response['headers']['status-code'], 501);
|
||||
|
||||
@@ -844,6 +943,19 @@ class ProjectsConsoleClientTest extends Scope
|
||||
'name' => $name,
|
||||
]);
|
||||
|
||||
$email = uniqid() . 'user@localhost.test';
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $id,
|
||||
]), [
|
||||
'userId' => ID::unique(),
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'name' => $name,
|
||||
]);
|
||||
|
||||
$this->assertEquals($response['headers']['status-code'], 501);
|
||||
|
||||
/**
|
||||
@@ -859,6 +971,8 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
|
||||
$email = uniqid() . 'user@localhost.test';
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
|
||||
@@ -1294,7 +1294,7 @@ class RealtimeCustomClientTest extends Scope
|
||||
$this->assertNotEmpty($deployment['body']['$id']);
|
||||
|
||||
// Wait for deployment to be built.
|
||||
sleep(5);
|
||||
sleep(10);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/functions/' . $functionId . '/deployments/' . $deploymentId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
|
||||
@@ -57,8 +57,7 @@ trait StorageBase
|
||||
$this->assertEquals('logo.png', $file['body']['name']);
|
||||
$this->assertEquals('image/png', $file['body']['mimeType']);
|
||||
$this->assertEquals(47218, $file['body']['sizeOriginal']);
|
||||
$this->assertTrue(md5_file(realpath(__DIR__ . '/../../../resources/logo.png')) != $file['body']['signature']); // should validate that the file is encrypted
|
||||
|
||||
$this->assertTrue(md5_file(realpath(__DIR__ . '/../../../resources/logo.png')) == $file['body']['signature']);
|
||||
/**
|
||||
* Test for Large File above 20MB
|
||||
* This should also validate the test for when Bucket encryption
|
||||
@@ -289,7 +288,7 @@ trait StorageBase
|
||||
$this->assertEquals('logo.png', $file['body']['name']);
|
||||
$this->assertEquals('image/png', $file['body']['mimeType']);
|
||||
$this->assertEquals(47218, $file['body']['sizeOriginal']);
|
||||
$this->assertTrue(md5_file(realpath(__DIR__ . '/../../../resources/logo.png')) != $file['body']['signature']); // should validate that the file is encrypted
|
||||
$this->assertTrue(md5_file(realpath(__DIR__ . '/../../../resources/logo.png')) == $file['body']['signature']);
|
||||
|
||||
return ['bucketId' => $bucketId];
|
||||
}
|
||||
@@ -314,10 +313,10 @@ trait StorageBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'limit(0)' ]
|
||||
'queries' => [ 'limit(1)' ]
|
||||
]);
|
||||
$this->assertEquals(200, $files['headers']['status-code']);
|
||||
$this->assertEquals(0, count($files['body']['files']));
|
||||
$this->assertEquals(1, count($files['body']['files']));
|
||||
|
||||
$files = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $data['bucketId'] . '/files', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
@@ -706,6 +705,7 @@ trait StorageBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'name' => 'logo_updated.png',
|
||||
'permissions' => [
|
||||
Permission::read(Role::user($this->getUser()['$id'])),
|
||||
Permission::update(Role::user($this->getUser()['$id'])),
|
||||
@@ -717,7 +717,7 @@ trait StorageBase
|
||||
$this->assertNotEmpty($file['body']['$id']);
|
||||
$dateValidator = new DatetimeValidator();
|
||||
$this->assertEquals(true, $dateValidator->isValid($file['body']['$createdAt']));
|
||||
$this->assertEquals('logo.png', $file['body']['name']);
|
||||
$this->assertEquals('logo_updated.png', $file['body']['name']);
|
||||
$this->assertEquals('image/png', $file['body']['mimeType']);
|
||||
$this->assertEquals(47218, $file['body']['sizeOriginal']);
|
||||
//$this->assertEquals(54944, $file['body']['sizeActual']);
|
||||
|
||||
@@ -39,11 +39,11 @@ trait TeamsBaseClient
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [ 'limit(0)' ]
|
||||
'queries' => [ 'limit(1)' ]
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertCount(0, $response['body']['memberships']);
|
||||
$this->assertCount(1, $response['body']['memberships']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
|
||||
Reference in New Issue
Block a user